AdminUser.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*-------------------------------------------------------------------------
  2. * fedsrv\AdminUser.CPP
  3. *
  4. * Implementation of CAdminUser
  5. *
  6. * Owner:
  7. *
  8. * Copyright 1986-1999 Microsoft Corporation, All Rights Reserved
  9. *-----------------------------------------------------------------------*/
  10. #include "pch.h"
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAdminUser
  13. TC_OBJECT_EXTERN_NON_CREATEABLE_IMPL(CAdminUser)
  14. /////////////////////////////////////////////////////////////////////////////
  15. // ISupportErrorInfo Interface Methods
  16. STDMETHODIMP CAdminUser::InterfaceSupportsErrorInfo(REFIID riid)
  17. {
  18. static const IID* arr[] =
  19. {
  20. &IID_IAdminUser
  21. };
  22. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  23. {
  24. if (InlineIsEqualGUID(*arr[i],riid))
  25. return S_OK;
  26. }
  27. return S_FALSE;
  28. }
  29. /*-------------------------------------------------------------------------
  30. * Init()
  31. *-------------------------------------------------------------------------
  32. * Purpose:
  33. * Finish construction
  34. *
  35. */
  36. // FIX: remove me
  37. void CAdminUser::Init(CFSPlayer *pPlayer)
  38. {
  39. m_pPlayer=pPlayer;
  40. m_pIshipIGC=pPlayer->GetIGCShip();
  41. }
  42. /*-------------------------------------------------------------------------
  43. * get_Name()
  44. *-------------------------------------------------------------------------
  45. * Purpose:
  46. * Return the name (of the user)
  47. *
  48. */
  49. STDMETHODIMP CAdminUser::get_Name(BSTR* pbstr)
  50. {
  51. CComBSTR bstrTemp(m_pPlayer->GetName());
  52. *pbstr = bstrTemp.Copy();
  53. return S_OK;
  54. }
  55. /*-------------------------------------------------------------------------
  56. * get_Ship()
  57. *-------------------------------------------------------------------------
  58. * Purpose:
  59. * Return the ship that the player is piloting
  60. *
  61. */
  62. STDMETHODIMP CAdminUser::get_Ship(/*[out, retval]*/ IAdminShip** ppShip)
  63. {
  64. // CLEAROUT(ppAGCTeam, (IAGCTeam*)NULL);
  65. assert(m_pPlayer);
  66. IshipIGC * pIshipIGC = m_pPlayer->GetIGCShip();
  67. if (pIshipIGC == NULL) // just in case
  68. {
  69. *ppShip = NULL;
  70. return S_OK;
  71. }
  72. return GetAGCGlobal()->GetAGCObject(pIshipIGC, IID_IAdminShip,
  73. (void**)ppShip);
  74. }
  75. /*-------------------------------------------------------------------------
  76. * SendMsg()
  77. *-------------------------------------------------------------------------
  78. * Purpose:
  79. * Send a message to a User (aka player)
  80. *
  81. */
  82. STDMETHODIMP CAdminUser::SendMsg(BSTR bstrMessage)
  83. {
  84. assert(m_pPlayer);
  85. USES_CONVERSION;
  86. m_pPlayer->GetMission()->GetSite()->SendChat(NULL, // no FEDMESSAGE
  87. CHAT_INDIVIDUAL, // send to User
  88. m_pPlayer->GetIGCShip()->GetObjectID(),
  89. NA, //No voiceover
  90. OLE2A(bstrMessage),
  91. c_cidNone,
  92. NA,
  93. NA,
  94. NULL,
  95. true); // true means object model generated
  96. return S_OK;
  97. }
  98. /*-------------------------------------------------------------------------
  99. * get_isReady()
  100. *-------------------------------------------------------------------------
  101. * Purpose:
  102. * Get the value of the CAdminUser property.
  103. *
  104. */
  105. STDMETHODIMP CAdminUser :: get_isReady(VARIANT_BOOL* pVal)
  106. {
  107. assert(m_pPlayer);
  108. *pVal = VARBOOL(m_pPlayer->GetReady());
  109. return S_OK;
  110. }
  111. /*-------------------------------------------------------------------------
  112. * put_isReady()
  113. *-------------------------------------------------------------------------
  114. * Purpose:
  115. * Put the value of the CAdminUser property.
  116. *
  117. */
  118. STDMETHODIMP CAdminUser :: put_isReady(VARIANT_BOOL Val)
  119. {
  120. assert(m_pPlayer);
  121. m_pPlayer->SetReady(!!Val);
  122. return S_OK;
  123. }
  124. /*-------------------------------------------------------------------------
  125. * Boot()
  126. *-------------------------------------------------------------------------
  127. * Purpose:
  128. * Log off user. (atually sends to lobby)
  129. *
  130. * Remarks:
  131. * This will eventually cause this CAdminUser to be deleted
  132. *
  133. */
  134. STDMETHODIMP CAdminUser::Boot()
  135. {
  136. if (m_pPlayer)
  137. {
  138. CFSMission * pfsMission = m_pPlayer->GetMission();
  139. pfsMission->RemovePlayerFromMission(m_pPlayer, QSR_AdminBooted);
  140. m_pPlayer = NULL;
  141. }
  142. return S_OK;
  143. }
  144. /*-------------------------------------------------------------------------
  145. * get_UserID()
  146. *-------------------------------------------------------------------------
  147. * Purpose:
  148. * Returns to ship id.
  149. */
  150. STDMETHODIMP CAdminUser::get_UserID(AdminUserID *userid)
  151. {
  152. *userid = DetermineID(m_pPlayer);
  153. return S_OK;
  154. }
  155. /*-------------------------------------------------------------------------
  156. * get_UniqueID()
  157. *-------------------------------------------------------------------------
  158. * Purpose:
  159. * Returns an AGC unique id.
  160. */
  161. STDMETHODIMP CAdminUser::get_UniqueID(AGCUniqueID *uniqueID)
  162. {
  163. *uniqueID = static_cast<AGCUniqueID>(static_cast<USHORT>(DetermineID(m_pPlayer)) | static_cast<DWORD>(AGC_AdminUser << 16));
  164. return S_OK;
  165. }
  166. /*-------------------------------------------------------------------------
  167. * get_UniqueID()
  168. *-------------------------------------------------------------------------
  169. * Purpose:
  170. * Returns an AGCEvent object used to store the current statistics of the
  171. * player.
  172. */
  173. STDMETHODIMP CAdminUser::get_PlayerStats(IAGCEvent** ppStats)
  174. {
  175. // Create an AGCEvent object to store the named player statistics
  176. IAGCEventCreatePtr spEvent;
  177. RETURN_FAILED(spEvent.CreateInstance(CLSID_AGCEvent));
  178. RETURN_FAILED(spEvent->Init());
  179. // Get the PlayerScoreObject
  180. PlayerScoreObject* ppso = m_pPlayer->GetPlayerScoreObject();
  181. // Populate the event with the (short) named player statistics
  182. CComVariant varShort(static_cast<short>(0));
  183. V_I2(&varShort) = ppso->GetPilotBaseKills();
  184. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"PilotBaseKills"), &varShort));
  185. V_I2(&varShort) = ppso->GetPilotBaseCaptures();
  186. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"PilotBaseCaptures"), &varShort));
  187. V_I2(&varShort) = ppso->GetTechsRecovered();
  188. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"TechsRecovered"), &varShort));
  189. V_I2(&varShort) = ppso->GetFlags();
  190. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"Flags"), &varShort));
  191. V_I2(&varShort) = ppso->GetArtifacts();
  192. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"Artifacts"), &varShort));
  193. V_I2(&varShort) = ppso->GetRescues();
  194. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"Rescues"), &varShort));
  195. V_I2(&varShort) = ppso->GetKills();
  196. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"Kills"), &varShort));
  197. V_I2(&varShort) = ppso->GetAssists();
  198. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"Assists"), &varShort));
  199. V_I2(&varShort) = ppso->GetDeaths();
  200. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"Deaths"), &varShort));
  201. V_I2(&varShort) = ppso->GetEjections();
  202. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"Ejections"), &varShort));
  203. // Populate the event with the (float) named player statistics
  204. CComVariant varFloat(static_cast<float>(0.f));
  205. V_R4(&varFloat) = ppso->GetCombatRating();
  206. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"CombatRating"), &varFloat));
  207. V_R4(&varFloat) = ppso->GetWarpsSpotted();
  208. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"WarpsSpotted"), &varFloat));
  209. V_R4(&varFloat) = ppso->GetAsteroidsSpotted();
  210. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"AsteroidsSpotted"), &varFloat));
  211. V_R4(&varFloat) = ppso->GetMinerKills();
  212. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"MinerKills"), &varFloat));
  213. V_R4(&varFloat) = ppso->GetBuilderKills();
  214. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"BuilderKills"), &varFloat));
  215. V_R4(&varFloat) = ppso->GetLayerKills();
  216. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"LayerKills"), &varFloat));
  217. V_R4(&varFloat) = ppso->GetCarrierKills();
  218. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"CarrierKills"), &varFloat));
  219. V_R4(&varFloat) = ppso->GetPlayerKills();
  220. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"PlayerKills"), &varFloat));
  221. V_R4(&varFloat) = ppso->GetBaseKills();
  222. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"BaseKills"), &varFloat));
  223. V_R4(&varFloat) = ppso->GetBaseCaptures();
  224. RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"BaseCaptures"), &varFloat));
  225. // Return the new object
  226. return spEvent->QueryInterface(IID_IAGCEvent, (void**)ppStats);
  227. }
  228. /*-------------------------------------------------------------------------
  229. * DetermineID()
  230. *-------------------------------------------------------------------------
  231. * Purpose:
  232. * Return a 16 bit unique ID for a User
  233. */
  234. /*static*/AdminUserID CAdminUser::DetermineID(CFSPlayer * pPlayer)
  235. {
  236. int nTemp = (int) pPlayer ^ (int) (pPlayer->GetConnection()->GetID());
  237. return (AdminUserID) nTemp; // return least sig 16 bits
  238. }