RoomsPlugin.cpp 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "RoomsPlugin.h"
  11. #include "BitStream.h"
  12. #include "RoomsErrorCodes.h"
  13. #include "TableSerializer.h"
  14. #include "RakAssert.h"
  15. #include "MessageIdentifiers.h"
  16. #include "RakPeerInterface.h"
  17. #include "ProfanityFilter.h"
  18. #include "GetTime.h"
  19. using namespace RakNet;
  20. int RoomsPlugin::RoomsPluginParticipantCompByRakString( const RakNet::RakString &key, RoomsPluginParticipant* const &data )
  21. {
  22. return strcmp(key.C_String(), data->GetName().C_String());
  23. }
  24. void RoomsPluginFunc::PrintResult(void)
  25. {
  26. printf("Result for user %s: %s\n", userName.C_String(), RoomsErrorCodeDescription::ToEnglish(resultCode));
  27. }
  28. void CreateRoom_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  29. {
  30. MessageID messageId = RPO_CREATE_ROOM;
  31. bitStream->Serialize(writeToBitstream, messageId);
  32. networkedRoomCreationParameters.Serialize(writeToBitstream, bitStream);
  33. bitStream->Serialize(writeToBitstream, userName);
  34. bitStream->Serialize(writeToBitstream, gameIdentifier);
  35. if (writeToBitstream)
  36. TableSerializer::SerializeTable(&initialRoomProperties, bitStream);
  37. else
  38. TableSerializer::DeserializeTable(bitStream, &initialRoomProperties);
  39. }
  40. void CreateRoom_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  41. {
  42. SerializeIn( writeToBitstream, bitStream );
  43. bitStream->Serialize( writeToBitstream, resultCode );
  44. bitStream->Serialize( writeToBitstream, roomId );
  45. roomDescriptor.Serialize(writeToBitstream,bitStream);
  46. }
  47. void EnterRoom_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  48. {
  49. MessageID messageId = RPO_ENTER_ROOM;
  50. bitStream->Serialize(writeToBitstream, messageId);
  51. networkedRoomCreationParameters.Serialize(writeToBitstream, bitStream);
  52. bitStream->Serialize(writeToBitstream, roomMemberMode);
  53. query.Serialize(writeToBitstream, bitStream);
  54. bitStream->Serialize(writeToBitstream, userName);
  55. bitStream->Serialize(writeToBitstream, gameIdentifier);
  56. }
  57. void EnterRoom_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  58. {
  59. SerializeIn( writeToBitstream, bitStream );
  60. bitStream->Serialize( writeToBitstream, resultCode );
  61. bitStream->Serialize( writeToBitstream, createdRoom );
  62. joinedRoomResult.Serialize(writeToBitstream, bitStream);
  63. bitStream->Serialize( writeToBitstream, roomId );
  64. }
  65. void JoinByFilter_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  66. {
  67. MessageID messageId = RPO_JOIN_BY_FILTER;
  68. bitStream->Serialize(writeToBitstream, messageId);
  69. bitStream->Serialize(writeToBitstream, gameIdentifier);
  70. bitStream->Serialize(writeToBitstream, roomMemberMode);
  71. bitStream->Serialize(writeToBitstream, userName);
  72. query.Serialize(writeToBitstream, bitStream);
  73. }
  74. void JoinByFilter_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  75. {
  76. SerializeIn( writeToBitstream, bitStream );
  77. bitStream->Serialize( writeToBitstream, resultCode );
  78. joinedRoomResult.Serialize(writeToBitstream, bitStream);
  79. }
  80. void LeaveRoom_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  81. {
  82. MessageID messageId = RPO_LEAVE_ROOM;
  83. bitStream->Serialize(writeToBitstream, messageId);
  84. bitStream->Serialize(writeToBitstream,userName);
  85. }
  86. void LeaveRoom_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  87. {
  88. SerializeIn( writeToBitstream, bitStream );
  89. bitStream->Serialize( writeToBitstream, resultCode );
  90. removeUserResult.Serialize(writeToBitstream, bitStream);
  91. }
  92. void GetInvitesToParticipant_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  93. {
  94. MessageID messageId = RPO_GET_INVITES_TO_PARTICIPANT;
  95. bitStream->Serialize(writeToBitstream, messageId);
  96. bitStream->Serialize(writeToBitstream, userName);
  97. }
  98. void GetInvitesToParticipant_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  99. {
  100. SerializeIn( writeToBitstream, bitStream );
  101. bitStream->Serialize( writeToBitstream, resultCode );
  102. unsigned int i;
  103. unsigned int listSize;
  104. listSize=invitedUsers.Size();
  105. bitStream->Serialize(writeToBitstream, listSize);
  106. for (i=0; i < listSize; i++)
  107. {
  108. if (writeToBitstream)
  109. invitedUsers[i].Serialize(true,bitStream);
  110. else
  111. {
  112. InvitedUser invitedUser;
  113. invitedUser.Serialize(false,bitStream);
  114. invitedUsers.Insert(invitedUser, _FILE_AND_LINE_ );
  115. }
  116. }
  117. }
  118. void SendInvite_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  119. {
  120. MessageID messageId = RPO_SEND_INVITE;
  121. bitStream->Serialize(writeToBitstream, messageId);
  122. bitStream->Serialize(writeToBitstream, userName);
  123. bitStream->Serialize(writeToBitstream, inviteeName);
  124. bitStream->Serialize(writeToBitstream, inviteToSpectatorSlot);
  125. bitStream->Serialize(writeToBitstream, subject);
  126. bitStream->Serialize(writeToBitstream, body);
  127. }
  128. void SendInvite_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  129. {
  130. SerializeIn( writeToBitstream, bitStream );
  131. bitStream->Serialize( writeToBitstream, resultCode );
  132. }
  133. void AcceptInvite_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  134. {
  135. MessageID messageId = RPO_ACCEPT_INVITE;
  136. bitStream->Serialize(writeToBitstream, messageId);
  137. bitStream->Serialize(writeToBitstream, userName);
  138. bitStream->Serialize(writeToBitstream, inviteSender);
  139. bitStream->Serialize(writeToBitstream, roomId);
  140. }
  141. void AcceptInvite_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  142. {
  143. SerializeIn( writeToBitstream, bitStream );
  144. bitStream->Serialize( writeToBitstream, resultCode );
  145. }
  146. void StartSpectating_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  147. {
  148. MessageID messageId = RPO_START_SPECTATING;
  149. bitStream->Serialize(writeToBitstream, messageId);
  150. bitStream->Serialize(writeToBitstream, userName);
  151. }
  152. void StartSpectating_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  153. {
  154. SerializeIn( writeToBitstream, bitStream );
  155. bitStream->Serialize( writeToBitstream, resultCode );
  156. }
  157. void StopSpectating_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  158. {
  159. MessageID messageId = RPO_STOP_SPECTATING;
  160. bitStream->Serialize(writeToBitstream, messageId);
  161. bitStream->Serialize(writeToBitstream, userName);
  162. }
  163. void StopSpectating_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  164. {
  165. SerializeIn( writeToBitstream, bitStream );
  166. bitStream->Serialize( writeToBitstream, resultCode );
  167. }
  168. void GrantModerator_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  169. {
  170. MessageID messageId = RPO_GRANT_MODERATOR;
  171. bitStream->Serialize(writeToBitstream, messageId);
  172. bitStream->Serialize(writeToBitstream, userName);
  173. bitStream->Serialize(writeToBitstream, newModerator);
  174. }
  175. void GrantModerator_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  176. {
  177. SerializeIn( writeToBitstream, bitStream );
  178. bitStream->Serialize( writeToBitstream, resultCode );
  179. }
  180. void ChangeSlotCounts_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  181. {
  182. MessageID messageId = RPO_CHANGE_SLOT_COUNTS;
  183. bitStream->Serialize(writeToBitstream, messageId);
  184. bitStream->Serialize(writeToBitstream, userName);
  185. slots.Serialize(writeToBitstream, bitStream);
  186. }
  187. void ChangeSlotCounts_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  188. {
  189. SerializeIn( writeToBitstream, bitStream );
  190. bitStream->Serialize( writeToBitstream, resultCode );
  191. }
  192. void SetCustomRoomProperties_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  193. {
  194. MessageID messageId = RPO_SET_CUSTOM_ROOM_PROPERTIES;
  195. bitStream->Serialize(writeToBitstream, messageId);
  196. bitStream->Serialize(writeToBitstream, userName);
  197. if (writeToBitstream)
  198. TableSerializer::SerializeTable(&table, bitStream);
  199. else
  200. TableSerializer::DeserializeTable(bitStream, &table);
  201. }
  202. void SetCustomRoomProperties_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  203. {
  204. SerializeIn( writeToBitstream, bitStream );
  205. bitStream->Serialize( writeToBitstream, resultCode );
  206. }
  207. void GetRoomProperties_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  208. {
  209. MessageID messageId = RPO_GET_ROOM_PROPERTIES;
  210. bitStream->Serialize(writeToBitstream, messageId);
  211. bitStream->Serialize(writeToBitstream, userName);
  212. bitStream->Serialize(writeToBitstream, roomName);
  213. }
  214. void GetRoomProperties_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  215. {
  216. SerializeIn( writeToBitstream, bitStream );
  217. bitStream->Serialize( writeToBitstream, resultCode );
  218. roomDescriptor.Serialize(writeToBitstream,bitStream);
  219. }
  220. void ChangeRoomName_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  221. {
  222. MessageID messageId = RPO_CHANGE_ROOM_NAME;
  223. bitStream->Serialize(writeToBitstream, messageId);
  224. bitStream->Serialize(writeToBitstream, userName);
  225. bitStream->Serialize(writeToBitstream, newRoomName);
  226. }
  227. void ChangeRoomName_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  228. {
  229. SerializeIn( writeToBitstream, bitStream );
  230. bitStream->Serialize( writeToBitstream, resultCode );
  231. }
  232. void SetHiddenFromSearches_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  233. {
  234. MessageID messageId = RPO_SET_HIDDEN_FROM_SEARCHES;
  235. bitStream->Serialize(writeToBitstream, messageId);
  236. bitStream->Serialize(writeToBitstream, userName);
  237. bitStream->Serialize(writeToBitstream, hiddenFromSearches);
  238. }
  239. void SetHiddenFromSearches_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  240. {
  241. SerializeIn( writeToBitstream, bitStream );
  242. bitStream->Serialize( writeToBitstream, resultCode );
  243. }
  244. void SetDestroyOnModeratorLeave_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  245. {
  246. MessageID messageId = RPO_SET_DESTROY_ON_MODERATOR_LEAVE;
  247. bitStream->Serialize(writeToBitstream, messageId);
  248. bitStream->Serialize(writeToBitstream, userName);
  249. bitStream->Serialize(writeToBitstream, destroyOnModeratorLeave);
  250. }
  251. void SetDestroyOnModeratorLeave_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  252. {
  253. SerializeIn( writeToBitstream, bitStream );
  254. bitStream->Serialize( writeToBitstream, resultCode );
  255. }
  256. void SetReadyStatus_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  257. {
  258. MessageID messageId = RPO_SET_READY_STATUS;
  259. bitStream->Serialize(writeToBitstream, messageId);
  260. bitStream->Serialize(writeToBitstream, userName);
  261. bitStream->Serialize(writeToBitstream, isReady);
  262. }
  263. void SetReadyStatus_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  264. {
  265. SerializeIn( writeToBitstream, bitStream );
  266. bitStream->Serialize( writeToBitstream, resultCode );
  267. unsigned int listSize;
  268. unsigned int i;
  269. RakNet::RakString name;
  270. listSize=readyUsers.Size();
  271. bitStream->Serialize(writeToBitstream, listSize);
  272. if (writeToBitstream)
  273. {
  274. for (i=0; i < listSize; i++)
  275. bitStream->Serialize(writeToBitstream, readyUsers[i]);
  276. }
  277. else
  278. {
  279. for (i=0; i < listSize; i++)
  280. {
  281. bitStream->Serialize(writeToBitstream, name);
  282. readyUsers.Insert(name, _FILE_AND_LINE_ );
  283. }
  284. }
  285. listSize=unreadyUsers.Size();
  286. bitStream->Serialize(writeToBitstream, listSize);
  287. if (writeToBitstream)
  288. {
  289. for (i=0; i < listSize; i++)
  290. bitStream->Serialize(writeToBitstream, unreadyUsers[i]);
  291. }
  292. else
  293. {
  294. for (i=0; i < listSize; i++)
  295. {
  296. bitStream->Serialize(writeToBitstream, name);
  297. unreadyUsers.Insert(name, _FILE_AND_LINE_ );
  298. }
  299. }
  300. }
  301. void GetReadyStatus_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  302. {
  303. MessageID messageId = RPO_GET_READY_STATUS;
  304. bitStream->Serialize(writeToBitstream, messageId);
  305. bitStream->Serialize(writeToBitstream, userName);
  306. unsigned int listSize;
  307. RakNet::RakString name;
  308. unsigned int i;
  309. listSize=readyUsers.Size();
  310. bitStream->Serialize(writeToBitstream, listSize);
  311. if (writeToBitstream)
  312. {
  313. for (i=0; i < listSize; i++)
  314. bitStream->Serialize(writeToBitstream, readyUsers[i]);
  315. }
  316. else
  317. {
  318. for (i=0; i < listSize; i++)
  319. {
  320. bitStream->Serialize(writeToBitstream, name);
  321. readyUsers.Insert(name, _FILE_AND_LINE_ );
  322. }
  323. }
  324. listSize=unreadyUsers.Size();
  325. bitStream->Serialize(writeToBitstream, listSize);
  326. if (writeToBitstream)
  327. {
  328. for (i=0; i < listSize; i++)
  329. bitStream->Serialize(writeToBitstream, unreadyUsers[i]);
  330. }
  331. else
  332. {
  333. for (i=0; i < listSize; i++)
  334. {
  335. bitStream->Serialize(writeToBitstream, name);
  336. unreadyUsers.Insert(name, _FILE_AND_LINE_ );
  337. }
  338. }
  339. }
  340. void GetReadyStatus_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  341. {
  342. SerializeIn( writeToBitstream, bitStream );
  343. bitStream->Serialize( writeToBitstream, resultCode );
  344. }
  345. void SetRoomLockState_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  346. {
  347. MessageID messageId = RPO_SET_ROOM_LOCK_STATE;
  348. bitStream->Serialize(writeToBitstream, messageId);
  349. bitStream->Serialize(writeToBitstream, userName);
  350. bitStream->Serialize(writeToBitstream, roomLockState);
  351. }
  352. void SetRoomLockState_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  353. {
  354. SerializeIn( writeToBitstream, bitStream );
  355. bitStream->Serialize( writeToBitstream, resultCode );
  356. }
  357. void GetRoomLockState_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  358. {
  359. MessageID messageId = RPO_GET_ROOM_LOCK_STATE;
  360. bitStream->Serialize(writeToBitstream, messageId);
  361. bitStream->Serialize(writeToBitstream, userName);
  362. }
  363. void GetRoomLockState_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  364. {
  365. SerializeIn( writeToBitstream, bitStream );
  366. bitStream->Serialize( writeToBitstream, resultCode );
  367. bitStream->Serialize(writeToBitstream, roomLockState);
  368. }
  369. void AreAllMembersReady_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  370. {
  371. MessageID messageId = RPO_ARE_ALL_MEMBERS_READY;
  372. bitStream->Serialize(writeToBitstream, messageId);
  373. bitStream->Serialize(writeToBitstream, userName);
  374. bitStream->Serialize(writeToBitstream, allReady);
  375. }
  376. void AreAllMembersReady_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  377. {
  378. SerializeIn( writeToBitstream, bitStream );
  379. bitStream->Serialize( writeToBitstream, resultCode );
  380. }
  381. void KickMember_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  382. {
  383. MessageID messageId = RPO_KICK_MEMBER;
  384. bitStream->Serialize(writeToBitstream, messageId);
  385. bitStream->Serialize(writeToBitstream, userName);
  386. bitStream->Serialize(writeToBitstream, kickedMember);
  387. bitStream->Serialize(writeToBitstream, reason);
  388. }
  389. void KickMember_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  390. {
  391. SerializeIn( writeToBitstream, bitStream );
  392. bitStream->Serialize( writeToBitstream, resultCode );
  393. }
  394. void UnbanMember_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  395. {
  396. MessageID messageId = RPO_UNBAN_MEMBER;
  397. bitStream->Serialize(writeToBitstream, messageId);
  398. bitStream->Serialize(writeToBitstream, userName);
  399. bitStream->Serialize(writeToBitstream, bannedMemberName);
  400. }
  401. void UnbanMember_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  402. {
  403. SerializeIn( writeToBitstream, bitStream );
  404. bitStream->Serialize( writeToBitstream, resultCode );
  405. }
  406. void GetBanReason_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  407. {
  408. MessageID messageId = RPO_GET_BAN_REASON;
  409. bitStream->Serialize(writeToBitstream, messageId);
  410. bitStream->Serialize(writeToBitstream, roomId);
  411. bitStream->Serialize(writeToBitstream, userName);
  412. bitStream->Serialize(writeToBitstream, reason);
  413. }
  414. void GetBanReason_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  415. {
  416. SerializeIn( writeToBitstream, bitStream );
  417. bitStream->Serialize( writeToBitstream, resultCode );
  418. }
  419. void AddUserToQuickJoin_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  420. {
  421. MessageID messageId = RPO_ADD_USER_TO_QUICK_JOIN;
  422. bitStream->Serialize(writeToBitstream, messageId);
  423. bitStream->Serialize(writeToBitstream, userName);
  424. bitStream->Serialize(writeToBitstream, gameIdentifier);
  425. networkedQuickJoinUser.Serialize(writeToBitstream, bitStream);
  426. }
  427. void AddUserToQuickJoin_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  428. {
  429. SerializeIn( writeToBitstream, bitStream );
  430. bitStream->Serialize( writeToBitstream, resultCode );
  431. }
  432. void RemoveUserFromQuickJoin_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  433. {
  434. MessageID messageId = RPO_REMOVE_USER_FROM_QUICK_JOIN;
  435. bitStream->Serialize(writeToBitstream, messageId);
  436. bitStream->Serialize(writeToBitstream, userName);
  437. }
  438. void RemoveUserFromQuickJoin_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  439. {
  440. SerializeIn( writeToBitstream, bitStream );
  441. bitStream->Serialize( writeToBitstream, resultCode );
  442. }
  443. void IsInQuickJoin_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  444. {
  445. MessageID messageId = RPO_IS_IN_QUICK_JOIN;
  446. bitStream->Serialize(writeToBitstream, messageId);
  447. bitStream->Serialize(writeToBitstream, userName);
  448. bitStream->Serialize(writeToBitstream, isInQuickJoin);
  449. }
  450. void IsInQuickJoin_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  451. {
  452. SerializeIn( writeToBitstream, bitStream );
  453. bitStream->Serialize( writeToBitstream, resultCode );
  454. }
  455. SearchByFilter_Func::~SearchByFilter_Func()
  456. {
  457. for (unsigned int i=0; i < roomsOutput.Size(); i++)
  458. RakNet::OP_DELETE(roomsOutput[i], _FILE_AND_LINE_);
  459. }
  460. void SearchByFilter_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  461. {
  462. MessageID messageId = RPO_SEARCH_BY_FILTER;
  463. bitStream->Serialize(writeToBitstream, messageId);
  464. bitStream->Serialize(writeToBitstream, userName);
  465. bitStream->Serialize(writeToBitstream, gameIdentifier);
  466. bitStream->Serialize(writeToBitstream, onlyJoinable);
  467. roomQuery.Serialize(writeToBitstream, bitStream);
  468. }
  469. void SearchByFilter_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  470. {
  471. SerializeIn( writeToBitstream, bitStream );
  472. bitStream->Serialize( writeToBitstream, resultCode );
  473. unsigned int i;
  474. unsigned int listSize;
  475. listSize=roomsOutput.Size();
  476. bitStream->Serialize(writeToBitstream, listSize);
  477. for (i=0; i < listSize; i++)
  478. {
  479. if (writeToBitstream)
  480. roomsOutput[i]->Serialize(true,bitStream);
  481. else
  482. {
  483. RoomDescriptor *desc = RakNet::OP_NEW<RoomDescriptor>( _FILE_AND_LINE_ );
  484. desc->Serialize(false,bitStream);
  485. roomsOutput.Insert(desc, _FILE_AND_LINE_ );
  486. }
  487. }
  488. }
  489. void ChangeHandle_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  490. {
  491. MessageID messageId = RPO_CHANGE_HANDLE;
  492. bitStream->Serialize(writeToBitstream, messageId);
  493. bitStream->Serialize(writeToBitstream, userName);
  494. bitStream->Serialize(writeToBitstream, newHandle);
  495. }
  496. void ChangeHandle_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  497. {
  498. SerializeIn( writeToBitstream, bitStream );
  499. bitStream->Serialize( writeToBitstream, resultCode );
  500. }
  501. void Chat_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  502. {
  503. MessageID messageId = RPO_CHAT;
  504. bitStream->Serialize(writeToBitstream, messageId);
  505. bitStream->Serialize(writeToBitstream, userName);
  506. bitStream->Serialize(writeToBitstream, chatMessage);
  507. bitStream->Serialize(writeToBitstream, privateMessageRecipient);
  508. bitStream->Serialize(writeToBitstream, chatDirectedToRoom);
  509. }
  510. void Chat_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  511. {
  512. SerializeIn( writeToBitstream, bitStream );
  513. bitStream->Serialize( writeToBitstream, resultCode );
  514. }
  515. void Bitstream_Func::SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)
  516. {
  517. MessageID messageId = RPO_BITSTREAM;
  518. bitStream->Serialize(writeToBitstream, messageId);
  519. bitStream->Serialize(writeToBitstream, userName);
  520. BitSize_t numBits = bsToSend.GetNumberOfBitsUsed();
  521. bitStream->Serialize(writeToBitstream, numBits);
  522. if (writeToBitstream==false)
  523. bsToSend.AddBitsAndReallocate(numBits);
  524. bitStream->SerializeBits(writeToBitstream, bsToSend.GetData(), numBits, true);
  525. bsToSend.SetWriteOffset(numBits);
  526. bitStream->Serialize(writeToBitstream, privateMessageRecipient);
  527. bitStream->Serialize(writeToBitstream, directedToRoom);
  528. }
  529. void Bitstream_Func::SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)
  530. {
  531. SerializeIn( writeToBitstream, bitStream );
  532. bitStream->Serialize( writeToBitstream, resultCode );
  533. }
  534. void QuickJoinExpired_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  535. {
  536. MessageID messageId = RPN_QUICK_JOIN_EXPIRED;
  537. bitStream->Serialize(writeToBitstream, messageId);
  538. bitStream->Serialize(writeToBitstream, recipient);
  539. networkedQuickJoinUser.Serialize(writeToBitstream, bitStream);
  540. }
  541. void QuickJoinEnteredRoom_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  542. {
  543. MessageID messageId = RPN_QUICK_JOIN_ENTERED_ROOM;
  544. bitStream->Serialize(writeToBitstream, messageId);
  545. bitStream->Serialize(writeToBitstream, recipient);
  546. joinedRoomResult.Serialize(writeToBitstream, bitStream);
  547. }
  548. void RoomMemberStartedSpectating_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  549. {
  550. MessageID messageId = RPN_ROOM_MEMBER_STARTED_SPECTATING;
  551. bitStream->Serialize(writeToBitstream, messageId);
  552. bitStream->Serialize(writeToBitstream, recipient);
  553. bitStream->Serialize(writeToBitstream, userName);
  554. bitStream->Serialize(writeToBitstream, roomId);
  555. }
  556. void RoomMemberStoppedSpectating_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  557. {
  558. MessageID messageId = RPN_ROOM_MEMBER_STARTED_SPECTATING;
  559. bitStream->Serialize(writeToBitstream, messageId);
  560. bitStream->Serialize(writeToBitstream, recipient);
  561. bitStream->Serialize(writeToBitstream, userName);
  562. bitStream->Serialize(writeToBitstream, roomId);
  563. }
  564. void ModeratorChanged_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  565. {
  566. MessageID messageId = RPN_MODERATOR_CHANGED;
  567. bitStream->Serialize(writeToBitstream, messageId);
  568. bitStream->Serialize(writeToBitstream, recipient);
  569. bitStream->Serialize(writeToBitstream, newModerator);
  570. bitStream->Serialize(writeToBitstream, oldModerator);
  571. bitStream->Serialize(writeToBitstream, roomId);
  572. }
  573. void SlotCountsSet_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  574. {
  575. MessageID messageId = RPN_SLOT_COUNTS_SET;
  576. bitStream->Serialize(writeToBitstream, messageId);
  577. bitStream->Serialize(writeToBitstream, recipient);
  578. slots.Serialize(writeToBitstream, bitStream);
  579. bitStream->Serialize(writeToBitstream, roomId);
  580. }
  581. void CustomRoomPropertiesSet_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  582. {
  583. MessageID messageId = RPN_CUSTOM_ROOM_PROPERTIES_SET;
  584. bitStream->Serialize(writeToBitstream, messageId);
  585. bitStream->Serialize(writeToBitstream, recipient);
  586. bitStream->Serialize(writeToBitstream, roomId);
  587. if (writeToBitstream)
  588. {
  589. if (tablePtr==0)
  590. tablePtr=&table;
  591. TableSerializer::SerializeTable(tablePtr, bitStream);
  592. }
  593. else
  594. {
  595. TableSerializer::DeserializeTable(bitStream, &table);
  596. tablePtr=&table;
  597. }
  598. }
  599. void RoomNameSet_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  600. {
  601. MessageID messageId = RPN_ROOM_NAME_SET;
  602. bitStream->Serialize(writeToBitstream, messageId);
  603. bitStream->Serialize(writeToBitstream, recipient);
  604. bitStream->Serialize(writeToBitstream, oldName);
  605. bitStream->Serialize(writeToBitstream, newName);
  606. bitStream->Serialize(writeToBitstream, roomId);
  607. }
  608. void HiddenFromSearchesSet_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  609. {
  610. MessageID messageId = RPN_HIDDEN_FROM_SEARCHES_SET;
  611. bitStream->Serialize(writeToBitstream, messageId);
  612. bitStream->Serialize(writeToBitstream, recipient);
  613. bitStream->Serialize(writeToBitstream, roomId);
  614. bitStream->Serialize(writeToBitstream, hiddenFromSearches);
  615. }
  616. void RoomMemberReadyStatusSet_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  617. {
  618. MessageID messageId = RPN_ROOM_MEMBER_READY_STATUS_SET;
  619. bitStream->Serialize(writeToBitstream, messageId);
  620. bitStream->Serialize(writeToBitstream, recipient);
  621. bitStream->Serialize(writeToBitstream, roomId);
  622. bitStream->Serialize(writeToBitstream, isReady);
  623. bitStream->Serialize(writeToBitstream, roomMember);
  624. unsigned int listSize;
  625. unsigned int i;
  626. RakNet::RakString name;
  627. listSize=readyUsers.Size();
  628. bitStream->Serialize(writeToBitstream, listSize);
  629. if (writeToBitstream)
  630. {
  631. for (i=0; i < listSize; i++)
  632. bitStream->Serialize(writeToBitstream, readyUsers[i]);
  633. }
  634. else
  635. {
  636. for (i=0; i < listSize; i++)
  637. {
  638. bitStream->Serialize(writeToBitstream, name);
  639. readyUsers.Insert(name, _FILE_AND_LINE_ );
  640. }
  641. }
  642. listSize=unreadyUsers.Size();
  643. bitStream->Serialize(writeToBitstream, listSize);
  644. if (writeToBitstream)
  645. {
  646. for (i=0; i < listSize; i++)
  647. bitStream->Serialize(writeToBitstream, unreadyUsers[i]);
  648. }
  649. else
  650. {
  651. for (i=0; i < listSize; i++)
  652. {
  653. bitStream->Serialize(writeToBitstream, name);
  654. unreadyUsers.Insert(name, _FILE_AND_LINE_ );
  655. }
  656. }
  657. }
  658. void RoomLockStateSet_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  659. {
  660. MessageID messageId = RPN_ROOM_LOCK_STATE_SET;
  661. bitStream->Serialize(writeToBitstream, messageId);
  662. bitStream->Serialize(writeToBitstream, recipient);
  663. bitStream->Serialize(writeToBitstream, roomId);
  664. bitStream->Serialize(writeToBitstream, roomLockState);
  665. }
  666. void RoomMemberKicked_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  667. {
  668. MessageID messageId = RPN_ROOM_MEMBER_KICKED;
  669. bitStream->Serialize(writeToBitstream, messageId);
  670. bitStream->Serialize(writeToBitstream, recipient);
  671. bitStream->Serialize(writeToBitstream, roomId);
  672. bitStream->Serialize(writeToBitstream, kickedMember);
  673. bitStream->Serialize(writeToBitstream, moderator);
  674. bitStream->Serialize(writeToBitstream, reason);
  675. }
  676. void RoomMemberHandleSet_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  677. {
  678. MessageID messageId = RPN_ROOM_MEMBER_HANDLE_SET;
  679. bitStream->Serialize(writeToBitstream, messageId);
  680. bitStream->Serialize(writeToBitstream, recipient);
  681. bitStream->Serialize(writeToBitstream, oldName);
  682. bitStream->Serialize(writeToBitstream, newName);
  683. bitStream->Serialize(writeToBitstream, roomId);
  684. }
  685. void RoomMemberLeftRoom_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  686. {
  687. MessageID messageId = RPN_ROOM_MEMBER_LEFT_ROOM;
  688. bitStream->Serialize(writeToBitstream, messageId);
  689. bitStream->Serialize(writeToBitstream, recipient);
  690. bitStream->Serialize(writeToBitstream, roomMember);
  691. bitStream->Serialize(writeToBitstream, roomId);
  692. }
  693. void RoomMemberJoinedRoom_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  694. {
  695. MessageID messageId = RPN_ROOM_MEMBER_JOINED_ROOM;
  696. bitStream->Serialize(writeToBitstream, messageId);
  697. bitStream->Serialize(writeToBitstream, recipient);
  698. bitStream->Serialize(writeToBitstream, roomId);
  699. if (joinedRoomResult==0 && writeToBitstream==false)
  700. joinedRoomResult = RakNet::OP_NEW<JoinedRoomResult>( _FILE_AND_LINE_ );
  701. joinedRoomResult->Serialize(writeToBitstream, bitStream);
  702. }
  703. void RoomInvitationSent_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  704. {
  705. MessageID messageId = RPN_ROOM_INVITATION_SENT;
  706. bitStream->Serialize(writeToBitstream, messageId);
  707. bitStream->Serialize(writeToBitstream, recipient);
  708. bitStream->Serialize(writeToBitstream, invitorName);
  709. bitStream->Serialize(writeToBitstream, inviteeName);
  710. bitStream->Serialize(writeToBitstream, inviteToSpectatorSlot);
  711. bitStream->Serialize(writeToBitstream, subject);
  712. bitStream->Serialize(writeToBitstream, body);
  713. bitStream->Serialize(writeToBitstream, roomId);
  714. }
  715. void RoomInvitationWithdrawn_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  716. {
  717. MessageID messageId = RPN_ROOM_INVITATION_WITHDRAWN;
  718. bitStream->Serialize(writeToBitstream, messageId);
  719. bitStream->Serialize(writeToBitstream, recipient);
  720. invitedUser.Serialize(writeToBitstream, bitStream);
  721. }
  722. void RoomDestroyedOnModeratorLeft_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  723. {
  724. MessageID messageId = RPN_ROOM_DESTROYED_ON_MODERATOR_LEFT;
  725. bitStream->Serialize(writeToBitstream, messageId);
  726. bitStream->Serialize(writeToBitstream, recipient);
  727. bitStream->Serialize(writeToBitstream, roomId);
  728. bitStream->Serialize(writeToBitstream, oldModerator);
  729. roomDescriptor.Serialize(writeToBitstream, bitStream);
  730. }
  731. void Chat_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  732. {
  733. MessageID messageId = RPN_CHAT_NOTIFICATION;
  734. bitStream->Serialize(writeToBitstream, messageId);
  735. bitStream->Serialize(writeToBitstream, recipient);
  736. bitStream->Serialize(writeToBitstream, sender);
  737. bitStream->Serialize(writeToBitstream, privateMessageRecipient);
  738. bitStream->Serialize(writeToBitstream, chatMessage);
  739. bitStream->Serialize(writeToBitstream, filteredChatMessage);
  740. }
  741. void Bitstream_Notification::Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)
  742. {
  743. MessageID messageId = RPN_BITSTREAM_NOTIFICATION;
  744. bitStream->Serialize(writeToBitstream, messageId);
  745. bitStream->Serialize(writeToBitstream, recipient);
  746. bitStream->Serialize(writeToBitstream, sender);
  747. bitStream->Serialize(writeToBitstream, privateMessageRecipient);
  748. BitSize_t numBits = bitStreamReceived.GetNumberOfBitsUsed();
  749. bitStream->Serialize(writeToBitstream, numBits);
  750. if (writeToBitstream==false)
  751. bitStreamReceived.AddBitsAndReallocate(numBits);
  752. bitStream->SerializeBits(writeToBitstream, bitStreamReceived.GetData(), numBits, true);
  753. bitStreamReceived.SetWriteOffset(numBits);
  754. }
  755. RoomsPlugin::RoomsPlugin()
  756. {
  757. lastUpdateTime=0;
  758. orderingChannel=0;
  759. profanityFilter=0;
  760. packetPriority=HIGH_PRIORITY;
  761. serverAddress=RakNet::UNASSIGNED_SYSTEM_ADDRESS;
  762. SetRoomsCallback(this);
  763. }
  764. RoomsPlugin::~RoomsPlugin()
  765. {
  766. Clear();
  767. }
  768. void RoomsPlugin::SetOrderingChannel(char oc)
  769. {
  770. orderingChannel=oc;
  771. }
  772. void RoomsPlugin::SetSendPriority(PacketPriority pp)
  773. {
  774. packetPriority=pp;
  775. }
  776. void RoomsPlugin::SetRoomsCallback(RoomsCallback *_roomsCallback)
  777. {
  778. roomsCallback.Clear(true,_FILE_AND_LINE_);
  779. roomsCallback.Push(_roomsCallback,_FILE_AND_LINE_);
  780. }
  781. void RoomsPlugin::AddRoomsCallback(RoomsCallback *_roomsCallback)
  782. {
  783. if (roomsCallback.GetIndexOf(_roomsCallback)==(unsigned int) -1)
  784. roomsCallback.Push(_roomsCallback,_FILE_AND_LINE_);
  785. }
  786. void RoomsPlugin::RemoveRoomsCallback(RoomsCallback *_roomsCallback)
  787. {
  788. unsigned int idx = roomsCallback.GetIndexOf(_roomsCallback);
  789. if (idx!=(unsigned int) -1)
  790. roomsCallback.RemoveAtIndex(idx);
  791. }
  792. void RoomsPlugin::ExecuteFunc(RoomsPluginFunc *func)
  793. {
  794. ExecuteFunc(func,serverAddress);
  795. }
  796. void RoomsPlugin::ExecuteFunc(RoomsPluginFunc *func, SystemAddress remoteAddress)
  797. {
  798. RakNet::BitStream bs;
  799. bs.Write((MessageID)ID_ROOMS_EXECUTE_FUNC);
  800. if (IsServer())
  801. func->SerializeOut(true, &bs);
  802. else
  803. func->SerializeIn(true, &bs);
  804. SendUnified(&bs, packetPriority, RELIABLE_ORDERED, orderingChannel, remoteAddress, false);
  805. }
  806. void RoomsPlugin::ExecuteNotification(RoomsPluginNotification *func, RoomsPluginParticipant *recipient)
  807. {
  808. RakNet::BitStream bs;
  809. bs.Write((MessageID)ID_ROOMS_EXECUTE_FUNC);
  810. func->recipient=recipient->GetName();
  811. func->Serialize(true, &bs);
  812. SendUnified(&bs, packetPriority, RELIABLE_ORDERED, orderingChannel, recipient->GetSystemAddress(), false);
  813. }
  814. void RoomsPlugin::SetServerAddress( SystemAddress systemAddress )
  815. {
  816. serverAddress=systemAddress;
  817. if (serverAddress!=RakNet::UNASSIGNED_SYSTEM_ADDRESS)
  818. {
  819. RemoveRoomsCallback(this);
  820. }
  821. }
  822. bool RoomsPlugin::LoginRoomsParticipant(RakNet::RakString userName, SystemAddress roomsParticipantAddress, RakNetGUID guid, SystemAddress loginServerAddress)
  823. {
  824. if (loginServerAddress!=RakNet::UNASSIGNED_SYSTEM_ADDRESS && loginServers.GetIndexOf(loginServerAddress)==(unsigned int) -1)
  825. return false;
  826. bool objectExists;
  827. unsigned int index;
  828. index=roomsParticipants.GetIndexFromKey(userName, &objectExists);
  829. if (objectExists==false)
  830. {
  831. RoomsPluginParticipant *rpp = RakNet::OP_NEW<RoomsPluginParticipant>( _FILE_AND_LINE_ );
  832. rpp->SetSystemAddress(roomsParticipantAddress);
  833. rpp->SetGUID(guid);
  834. rpp->SetName(userName);
  835. roomsParticipants.InsertAtIndex(rpp, index, _FILE_AND_LINE_ );
  836. return true;
  837. }
  838. return false;
  839. }
  840. bool RoomsPlugin::LogoffRoomsParticipant(RakNet::RakString userName, SystemAddress loginServerAddress)
  841. {
  842. if (loginServerAddress!=RakNet::UNASSIGNED_SYSTEM_ADDRESS && loginServers.GetIndexOf(loginServerAddress)==(unsigned int) -1)
  843. return false;
  844. bool objectExists;
  845. unsigned int index;
  846. index=roomsParticipants.GetIndexFromKey(userName, &objectExists);
  847. if (objectExists==true)
  848. {
  849. RemoveUserResult removeUserResult;
  850. roomsContainer.RemoveUser(roomsParticipants[index], &removeUserResult);
  851. ProcessRemoveUserResult(&removeUserResult);
  852. RakNet::OP_DELETE(roomsParticipants[index], _FILE_AND_LINE_);
  853. roomsParticipants.RemoveAtIndex(index);
  854. return true;
  855. }
  856. return false;
  857. }
  858. void RoomsPlugin::ClearRoomMembers(void)
  859. {
  860. unsigned int i;
  861. for (i=0; i < roomsParticipants.Size(); i++)
  862. RakNet::OP_DELETE(roomsParticipants[i], _FILE_AND_LINE_);
  863. roomsParticipants.Clear(false, _FILE_AND_LINE_);
  864. }
  865. void RoomsPlugin::SerializeLogin(RakNet::RakString userName, SystemAddress userAddress, RakNetGUID guid, RakNet::BitStream *bs)
  866. {
  867. bs->Write((MessageID)ID_ROOMS_LOGON_STATUS);
  868. bs->Write(userName);
  869. bs->Write(true);
  870. bs->Write(userAddress);
  871. bs->Write(guid);
  872. }
  873. void RoomsPlugin::SerializeLogoff(RakNet::RakString userName, RakNet::BitStream *bs)
  874. {
  875. bs->Write((MessageID)ID_ROOMS_LOGON_STATUS);
  876. bs->Write(userName);
  877. bs->Write(false);
  878. }
  879. void RoomsPlugin::SerializeChangeHandle(RakNet::RakString oldHandle, RakNet::RakString newHandle, RakNet::BitStream *bs)
  880. {
  881. bs->Write((MessageID)ID_ROOMS_HANDLE_CHANGE);
  882. bs->Write(oldHandle);
  883. bs->Write(newHandle);
  884. }
  885. void RoomsPlugin::ChangeHandle(RakNet::RakString oldHandle, RakNet::RakString newHandle)
  886. {
  887. RoomMemberHandleSet_Notification notification;
  888. notification.oldName=oldHandle;
  889. notification.newName=newHandle;
  890. roomsContainer.ChangeHandle( oldHandle, newHandle );
  891. RoomsPluginParticipant* roomsPluginParticipant = GetParticipantByHandle( newHandle, RakNet::UNASSIGNED_SYSTEM_ADDRESS);
  892. if (roomsPluginParticipant && roomsPluginParticipant->GetRoom())
  893. {
  894. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  895. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  896. }
  897. }
  898. void RoomsPlugin::AddLoginServerAddress(SystemAddress systemAddress)
  899. {
  900. unsigned int index = loginServers.GetIndexOf(systemAddress);
  901. if (index==(unsigned int) -1)
  902. loginServers.Push(systemAddress, _FILE_AND_LINE_ );
  903. }
  904. void RoomsPlugin::RemoveLoginServerAddress(SystemAddress systemAddress)
  905. {
  906. unsigned int index = loginServers.GetIndexOf(systemAddress);
  907. if (index!=(unsigned int) -1)
  908. loginServers.RemoveAtIndexFast(index);
  909. }
  910. void RoomsPlugin::ClearLoginServerAdddresses(void)
  911. {
  912. loginServers.Clear(false, _FILE_AND_LINE_);
  913. }
  914. void RoomsPlugin::SetProfanityFilter(ProfanityFilter *pf)
  915. {
  916. profanityFilter=pf;
  917. }
  918. void RoomsPlugin::OnDetach(void)
  919. {
  920. Clear();
  921. }
  922. void RoomsPlugin::OnShutdown(void)
  923. {
  924. Clear();
  925. }
  926. void RoomsPlugin::Update(void)
  927. {
  928. if (IsServer()==false)
  929. return;
  930. DataStructures::List<QuickJoinUser*> timeoutExpired;
  931. DataStructures::List<QuickJoinUser*> dereferencedPointers;
  932. DataStructures::List<JoinedRoomResult> joinedRoomMembers;
  933. RakNet::TimeMS curTime = RakNet::GetTimeMS();
  934. if (lastUpdateTime!=0)
  935. {
  936. RakNet::TimeMS elapsedTime = curTime-lastUpdateTime;
  937. roomsContainer.ProcessQuickJoins( timeoutExpired, joinedRoomMembers, dereferencedPointers, elapsedTime );
  938. unsigned int i;
  939. for (i=0; i < timeoutExpired.Size(); i++)
  940. {
  941. QuickJoinExpired_Notification notification;
  942. notification.networkedQuickJoinUser=timeoutExpired[i]->networkedQuickJoinUser;
  943. ExecuteNotification(&notification, ((RoomsPluginParticipant*)timeoutExpired[i]->roomsParticipant));
  944. }
  945. for (i=0; i < joinedRoomMembers.Size(); i++)
  946. {
  947. ((RoomsPluginParticipant*)joinedRoomMembers[i].joiningMember)->lastRoomJoined=joinedRoomMembers[i].roomOutput->GetID();
  948. QuickJoinEnteredRoom_Notification notificationToTarget;
  949. notificationToTarget.joinedRoomResult=joinedRoomMembers[i];
  950. notificationToTarget.joinedRoomResult.agrc=&roomsContainer;
  951. ExecuteNotification(&notificationToTarget, ((RoomsPluginParticipant*)joinedRoomMembers[i].joiningMember));
  952. }
  953. for (i=0; i < joinedRoomMembers.Size(); i++)
  954. {
  955. RoomMemberJoinedRoom_Notification notificationToRoom;
  956. notificationToRoom.joinedRoomResult=&joinedRoomMembers[i];
  957. notificationToRoom.joinedRoomResult->agrc=&roomsContainer;
  958. notificationToRoom.roomId=notificationToRoom.joinedRoomResult->roomDescriptor.lobbyRoomId;
  959. ExecuteNotificationToOtherRoomMembers(joinedRoomMembers[i].joiningMember->GetRoom(), (RoomsPluginParticipant*)joinedRoomMembers[i].joiningMember, &notificationToRoom);
  960. notificationToRoom.joinedRoomResult=0;
  961. }
  962. for (i=0; i < dereferencedPointers.Size(); i++)
  963. RakNet::OP_DELETE(dereferencedPointers[i], _FILE_AND_LINE_);
  964. }
  965. lastUpdateTime=curTime;
  966. }
  967. PluginReceiveResult RoomsPlugin::OnReceive(Packet *packet)
  968. {
  969. switch (packet->data[0])
  970. {
  971. case ID_ROOMS_EXECUTE_FUNC:
  972. OnRoomsExecuteFunc(packet);
  973. break;
  974. case ID_ROOMS_LOGON_STATUS:
  975. OnLoginStatus(packet);
  976. break;
  977. case ID_ROOMS_HANDLE_CHANGE:
  978. OnHandleChange(packet);
  979. break;
  980. }
  981. return RR_CONTINUE_PROCESSING;
  982. }
  983. void RoomsPlugin::OnLoginStatus(Packet *packet)
  984. {
  985. unsigned int i;
  986. for (i=0; i < loginServers.Size(); i++)
  987. {
  988. if (loginServers[i]==packet->systemAddress)
  989. {
  990. RakNet::BitStream bs(packet->data, packet->length, false);
  991. bs.IgnoreBytes(1);
  992. RakNet::RakString name;
  993. bs.Read(name);
  994. bool loggedOn;
  995. bs.Read(loggedOn);
  996. SystemAddress userAddress;
  997. RakNetGUID guid;
  998. if (loggedOn)
  999. {
  1000. bs.Read(userAddress);
  1001. bs.Read(guid);
  1002. LoginRoomsParticipant(name, userAddress, guid, packet->systemAddress);
  1003. }
  1004. else
  1005. {
  1006. LogoffRoomsParticipant(name, packet->systemAddress);
  1007. }
  1008. break;
  1009. }
  1010. }
  1011. }
  1012. void RoomsPlugin::OnHandleChange(Packet *packet)
  1013. {
  1014. unsigned int i;
  1015. for (i=0; i < loginServers.Size(); i++)
  1016. {
  1017. if (loginServers[i]==packet->systemAddress)
  1018. {
  1019. RakNet::BitStream bs(packet->data, packet->length, false);
  1020. bs.IgnoreBytes(1);
  1021. RakNet::RakString oldHandle, newHandle;
  1022. bs.Read(oldHandle);
  1023. bs.Read(newHandle);
  1024. ChangeHandle(oldHandle, newHandle);
  1025. break;
  1026. }
  1027. }
  1028. }
  1029. void RoomsPlugin::OnRoomsExecuteFunc(Packet *packet)
  1030. {
  1031. RakNet::BitStream bs(packet->data, packet->length, false);
  1032. bs.IgnoreBytes(1);
  1033. if (packet->length<2)
  1034. return;
  1035. if (roomsCallback.Size()==0)
  1036. return;
  1037. switch (packet->data[1])
  1038. {
  1039. case RPO_CREATE_ROOM:
  1040. {
  1041. CreateRoom_Func func;
  1042. if (IsServer()==false)
  1043. func.SerializeOut(false,&bs);
  1044. else
  1045. func.SerializeIn(false,&bs);
  1046. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1047. roomsCallback[rci]->CreateRoom_Callback(packet->systemAddress,&func);
  1048. }
  1049. break;
  1050. case RPO_ENTER_ROOM:
  1051. {
  1052. EnterRoom_Func func;
  1053. func.joinedRoomResult.agrc=&roomsContainer;
  1054. if (IsServer()==false)
  1055. func.SerializeOut(false,&bs);
  1056. else
  1057. func.SerializeIn(false,&bs);
  1058. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1059. roomsCallback[rci]->EnterRoom_Callback(packet->systemAddress,&func);
  1060. }
  1061. break;
  1062. case RPO_JOIN_BY_FILTER:
  1063. {
  1064. JoinByFilter_Func func;
  1065. if (IsServer()==false)
  1066. func.SerializeOut(false,&bs);
  1067. else
  1068. func.SerializeIn(false,&bs);
  1069. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1070. roomsCallback[rci]->JoinByFilter_Callback(packet->systemAddress,&func);
  1071. }
  1072. break;
  1073. case RPO_LEAVE_ROOM:
  1074. {
  1075. LeaveRoom_Func func;
  1076. if (IsServer()==false)
  1077. func.SerializeOut(false,&bs);
  1078. else
  1079. func.SerializeIn(false,&bs);
  1080. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1081. roomsCallback[rci]->LeaveRoom_Callback(packet->systemAddress,&func);
  1082. }
  1083. break;
  1084. case RPO_GET_INVITES_TO_PARTICIPANT:
  1085. {
  1086. GetInvitesToParticipant_Func func;
  1087. if (IsServer()==false)
  1088. func.SerializeOut(false,&bs);
  1089. else
  1090. func.SerializeIn(false,&bs);
  1091. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1092. roomsCallback[rci]->GetInvitesToParticipant_Callback(packet->systemAddress,&func);
  1093. }
  1094. break;
  1095. case RPO_SEND_INVITE:
  1096. {
  1097. SendInvite_Func func;
  1098. if (IsServer()==false)
  1099. func.SerializeOut(false,&bs);
  1100. else
  1101. func.SerializeIn(false,&bs);
  1102. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1103. roomsCallback[rci]->SendInvite_Callback(packet->systemAddress,&func);
  1104. }
  1105. break;
  1106. case RPO_ACCEPT_INVITE:
  1107. {
  1108. AcceptInvite_Func func;
  1109. if (IsServer()==false)
  1110. func.SerializeOut(false,&bs);
  1111. else
  1112. func.SerializeIn(false,&bs);
  1113. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1114. roomsCallback[rci]->AcceptInvite_Callback(packet->systemAddress,&func);
  1115. }
  1116. break;
  1117. case RPO_START_SPECTATING:
  1118. {
  1119. StartSpectating_Func func;
  1120. if (IsServer()==false)
  1121. func.SerializeOut(false,&bs);
  1122. else
  1123. func.SerializeIn(false,&bs);
  1124. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1125. roomsCallback[rci]->StartSpectating_Callback(packet->systemAddress,&func);
  1126. }
  1127. break;
  1128. case RPO_STOP_SPECTATING:
  1129. {
  1130. StopSpectating_Func func;
  1131. if (IsServer()==false)
  1132. func.SerializeOut(false,&bs);
  1133. else
  1134. func.SerializeIn(false,&bs);
  1135. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1136. roomsCallback[rci]->StopSpectating_Callback(packet->systemAddress,&func);
  1137. }
  1138. break;
  1139. case RPO_GRANT_MODERATOR:
  1140. {
  1141. GrantModerator_Func func;
  1142. if (IsServer()==false)
  1143. func.SerializeOut(false,&bs);
  1144. else
  1145. func.SerializeIn(false,&bs);
  1146. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1147. roomsCallback[rci]->GrantModerator_Callback(packet->systemAddress,&func);
  1148. }
  1149. break;
  1150. case RPO_CHANGE_SLOT_COUNTS:
  1151. {
  1152. ChangeSlotCounts_Func func;
  1153. if (IsServer()==false)
  1154. func.SerializeOut(false,&bs);
  1155. else
  1156. func.SerializeIn(false,&bs);
  1157. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1158. roomsCallback[rci]->ChangeSlotCounts_Callback(packet->systemAddress,&func);
  1159. }
  1160. break;
  1161. case RPO_SET_CUSTOM_ROOM_PROPERTIES:
  1162. {
  1163. SetCustomRoomProperties_Func func;
  1164. if (IsServer()==false)
  1165. func.SerializeOut(false,&bs);
  1166. else
  1167. func.SerializeIn(false,&bs);
  1168. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1169. roomsCallback[rci]->SetCustomRoomProperties_Callback(packet->systemAddress,&func);
  1170. }
  1171. break;
  1172. case RPO_GET_ROOM_PROPERTIES:
  1173. {
  1174. GetRoomProperties_Func func;
  1175. if (IsServer()==false)
  1176. func.SerializeOut(false,&bs);
  1177. else
  1178. func.SerializeIn(false,&bs);
  1179. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1180. roomsCallback[rci]->GetRoomProperties_Callback(packet->systemAddress,&func);
  1181. }
  1182. break;
  1183. case RPO_CHANGE_ROOM_NAME:
  1184. {
  1185. ChangeRoomName_Func func;
  1186. if (IsServer()==false)
  1187. func.SerializeOut(false,&bs);
  1188. else
  1189. func.SerializeIn(false,&bs);
  1190. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1191. roomsCallback[rci]->ChangeRoomName_Callback(packet->systemAddress,&func);
  1192. }
  1193. break;
  1194. case RPO_SET_HIDDEN_FROM_SEARCHES:
  1195. {
  1196. SetHiddenFromSearches_Func func;
  1197. if (IsServer()==false)
  1198. func.SerializeOut(false,&bs);
  1199. else
  1200. func.SerializeIn(false,&bs);
  1201. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1202. roomsCallback[rci]->SetHiddenFromSearches_Callback(packet->systemAddress,&func);
  1203. }
  1204. break;
  1205. case RPO_SET_DESTROY_ON_MODERATOR_LEAVE:
  1206. {
  1207. SetDestroyOnModeratorLeave_Func func;
  1208. if (IsServer()==false)
  1209. func.SerializeOut(false,&bs);
  1210. else
  1211. func.SerializeIn(false,&bs);
  1212. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1213. roomsCallback[rci]->SetDestroyOnModeratorLeave_Callback(packet->systemAddress,&func);
  1214. }
  1215. break;
  1216. case RPO_SET_READY_STATUS:
  1217. {
  1218. SetReadyStatus_Func func;
  1219. if (IsServer()==false)
  1220. func.SerializeOut(false,&bs);
  1221. else
  1222. func.SerializeIn(false,&bs);
  1223. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1224. roomsCallback[rci]->SetReadyStatus_Callback(packet->systemAddress,&func);
  1225. }
  1226. break;
  1227. case RPO_GET_READY_STATUS:
  1228. {
  1229. GetReadyStatus_Func func;
  1230. if (IsServer()==false)
  1231. func.SerializeOut(false,&bs);
  1232. else
  1233. func.SerializeIn(false,&bs);
  1234. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1235. roomsCallback[rci]->GetReadyStatus_Callback(packet->systemAddress,&func);
  1236. }
  1237. break;
  1238. case RPO_SET_ROOM_LOCK_STATE:
  1239. {
  1240. SetRoomLockState_Func func;
  1241. if (IsServer()==false)
  1242. func.SerializeOut(false,&bs);
  1243. else
  1244. func.SerializeIn(false,&bs);
  1245. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1246. roomsCallback[rci]->SetRoomLockState_Callback(packet->systemAddress,&func);
  1247. }
  1248. break;
  1249. case RPO_GET_ROOM_LOCK_STATE:
  1250. {
  1251. GetRoomLockState_Func func;
  1252. if (IsServer()==false)
  1253. func.SerializeOut(false,&bs);
  1254. else
  1255. func.SerializeIn(false,&bs);
  1256. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1257. roomsCallback[rci]->GetRoomLockState_Callback(packet->systemAddress,&func);
  1258. }
  1259. break;
  1260. case RPO_ARE_ALL_MEMBERS_READY:
  1261. {
  1262. AreAllMembersReady_Func func;
  1263. if (IsServer()==false)
  1264. func.SerializeOut(false,&bs);
  1265. else
  1266. func.SerializeIn(false,&bs);
  1267. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1268. roomsCallback[rci]->AreAllMembersReady_Callback(packet->systemAddress,&func);
  1269. }
  1270. break;
  1271. case RPO_KICK_MEMBER:
  1272. {
  1273. KickMember_Func func;
  1274. if (IsServer()==false)
  1275. func.SerializeOut(false,&bs);
  1276. else
  1277. func.SerializeIn(false,&bs);
  1278. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1279. roomsCallback[rci]->KickMember_Callback(packet->systemAddress,&func);
  1280. }
  1281. break;
  1282. case RPO_UNBAN_MEMBER:
  1283. {
  1284. UnbanMember_Func func;
  1285. if (IsServer()==false)
  1286. func.SerializeOut(false,&bs);
  1287. else
  1288. func.SerializeIn(false,&bs);
  1289. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1290. roomsCallback[rci]->UnbanMember_Callback(packet->systemAddress,&func);
  1291. }
  1292. break;
  1293. case RPO_GET_BAN_REASON:
  1294. {
  1295. GetBanReason_Func func;
  1296. if (IsServer()==false)
  1297. func.SerializeOut(false,&bs);
  1298. else
  1299. func.SerializeIn(false,&bs);
  1300. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1301. roomsCallback[rci]->GetBanReason_Callback(packet->systemAddress,&func);
  1302. }
  1303. break;
  1304. case RPO_ADD_USER_TO_QUICK_JOIN:
  1305. {
  1306. AddUserToQuickJoin_Func func;
  1307. if (IsServer()==false)
  1308. func.SerializeOut(false,&bs);
  1309. else
  1310. func.SerializeIn(false,&bs);
  1311. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1312. roomsCallback[rci]->AddUserToQuickJoin_Callback(packet->systemAddress,&func);
  1313. }
  1314. break;
  1315. case RPO_REMOVE_USER_FROM_QUICK_JOIN:
  1316. {
  1317. RemoveUserFromQuickJoin_Func func;
  1318. if (IsServer()==false)
  1319. func.SerializeOut(false,&bs);
  1320. else
  1321. func.SerializeIn(false,&bs);
  1322. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1323. roomsCallback[rci]->RemoveUserFromQuickJoin_Callback(packet->systemAddress,&func);
  1324. }
  1325. break;
  1326. case RPO_IS_IN_QUICK_JOIN:
  1327. {
  1328. IsInQuickJoin_Func func;
  1329. if (IsServer()==false)
  1330. func.SerializeOut(false,&bs);
  1331. else
  1332. func.SerializeIn(false,&bs);
  1333. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1334. roomsCallback[rci]->IsInQuickJoin_Callback(packet->systemAddress,&func);
  1335. }
  1336. break;
  1337. case RPO_SEARCH_BY_FILTER:
  1338. {
  1339. SearchByFilter_Func func;
  1340. if (IsServer()==false)
  1341. func.SerializeOut(false,&bs);
  1342. else
  1343. func.SerializeIn(false,&bs);
  1344. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1345. roomsCallback[rci]->SearchByFilter_Callback(packet->systemAddress,&func);
  1346. }
  1347. break;
  1348. case RPO_CHANGE_HANDLE:
  1349. {
  1350. ChangeHandle_Func func;
  1351. if (IsServer()==false)
  1352. func.SerializeOut(false,&bs);
  1353. else
  1354. func.SerializeIn(false,&bs);
  1355. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1356. roomsCallback[rci]->ChangeHandle_Callback(packet->systemAddress,&func);
  1357. }
  1358. break;
  1359. case RPO_CHAT:
  1360. {
  1361. Chat_Func func;
  1362. if (IsServer()==false)
  1363. func.SerializeOut(false,&bs);
  1364. else
  1365. func.SerializeIn(false,&bs);
  1366. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1367. roomsCallback[rci]->Chat_Callback(packet->systemAddress,&func);
  1368. }
  1369. break;
  1370. case RPO_BITSTREAM:
  1371. {
  1372. Bitstream_Func func;
  1373. if (IsServer()==false)
  1374. func.SerializeOut(false,&bs);
  1375. else
  1376. func.SerializeIn(false,&bs);
  1377. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1378. roomsCallback[rci]->Bitstream_Callback(packet->systemAddress,&func);
  1379. }
  1380. break;
  1381. case RPN_QUICK_JOIN_EXPIRED:
  1382. {
  1383. QuickJoinExpired_Notification func;
  1384. func.Serialize(IsServer(),&bs);
  1385. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1386. roomsCallback[rci]->QuickJoinExpired_Callback(packet->systemAddress,&func);
  1387. }
  1388. break;
  1389. case RPN_QUICK_JOIN_ENTERED_ROOM:
  1390. {
  1391. QuickJoinEnteredRoom_Notification func;
  1392. func.Serialize(IsServer(),&bs);
  1393. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1394. roomsCallback[rci]->QuickJoinEnteredRoom_Callback(packet->systemAddress,&func);
  1395. }
  1396. break;
  1397. case RPN_ROOM_MEMBER_STARTED_SPECTATING:
  1398. {
  1399. RoomMemberStartedSpectating_Notification func;
  1400. func.Serialize(IsServer(),&bs);
  1401. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1402. roomsCallback[rci]->RoomMemberStartedSpectating_Callback(packet->systemAddress,&func);
  1403. }
  1404. break;
  1405. case RPN_ROOM_MEMBER_STOPPED_SPECTATING:
  1406. {
  1407. RoomMemberStoppedSpectating_Notification func;
  1408. func.Serialize(IsServer(),&bs);
  1409. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1410. roomsCallback[rci]->RoomMemberStoppedSpectating_Callback(packet->systemAddress,&func);
  1411. }
  1412. break;
  1413. case RPN_MODERATOR_CHANGED:
  1414. {
  1415. ModeratorChanged_Notification func;
  1416. func.Serialize(IsServer(),&bs);
  1417. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1418. roomsCallback[rci]->ModeratorChanged_Callback(packet->systemAddress,&func);
  1419. }
  1420. break;
  1421. case RPN_SLOT_COUNTS_SET:
  1422. {
  1423. SlotCountsSet_Notification func;
  1424. func.Serialize(IsServer(),&bs);
  1425. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1426. roomsCallback[rci]->SlotCountsSet_Callback(packet->systemAddress,&func);
  1427. }
  1428. break;
  1429. case RPN_CUSTOM_ROOM_PROPERTIES_SET:
  1430. {
  1431. CustomRoomPropertiesSet_Notification func;
  1432. func.Serialize(IsServer(),&bs);
  1433. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1434. roomsCallback[rci]->CustomRoomPropertiesSet_Callback(packet->systemAddress,&func);
  1435. }
  1436. break;
  1437. case RPN_ROOM_NAME_SET:
  1438. {
  1439. RoomNameSet_Notification func;
  1440. func.Serialize(IsServer(),&bs);
  1441. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1442. roomsCallback[rci]->RoomNameSet_Callback(packet->systemAddress,&func);
  1443. }
  1444. break;
  1445. case RPN_HIDDEN_FROM_SEARCHES_SET:
  1446. {
  1447. HiddenFromSearchesSet_Notification func;
  1448. func.Serialize(IsServer(),&bs);
  1449. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1450. roomsCallback[rci]->HiddenFromSearchesSet_Callback(packet->systemAddress,&func);
  1451. }
  1452. break;
  1453. case RPN_ROOM_MEMBER_READY_STATUS_SET:
  1454. {
  1455. RoomMemberReadyStatusSet_Notification func;
  1456. func.Serialize(IsServer(),&bs);
  1457. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1458. roomsCallback[rci]->RoomMemberReadyStatusSet_Callback(packet->systemAddress,&func);
  1459. }
  1460. break;
  1461. case RPN_ROOM_LOCK_STATE_SET:
  1462. {
  1463. RoomLockStateSet_Notification func;
  1464. func.Serialize(IsServer(),&bs);
  1465. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1466. roomsCallback[rci]->RoomLockStateSet_Callback(packet->systemAddress,&func);
  1467. }
  1468. break;
  1469. case RPN_ROOM_MEMBER_KICKED:
  1470. {
  1471. RoomMemberKicked_Notification func;
  1472. func.Serialize(IsServer(),&bs);
  1473. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1474. roomsCallback[rci]->RoomMemberKicked_Callback(packet->systemAddress,&func);
  1475. }
  1476. break;
  1477. case RPN_ROOM_MEMBER_HANDLE_SET:
  1478. {
  1479. RoomMemberHandleSet_Notification func;
  1480. func.Serialize(IsServer(),&bs);
  1481. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1482. roomsCallback[rci]->RoomMemberHandleSet_Callback(packet->systemAddress,&func);
  1483. }
  1484. break;
  1485. case RPN_ROOM_MEMBER_LEFT_ROOM:
  1486. {
  1487. RoomMemberLeftRoom_Notification func;
  1488. func.Serialize(IsServer(),&bs);
  1489. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1490. roomsCallback[rci]->RoomMemberLeftRoom_Callback(packet->systemAddress,&func);
  1491. }
  1492. break;
  1493. case RPN_ROOM_MEMBER_JOINED_ROOM:
  1494. {
  1495. RoomMemberJoinedRoom_Notification func;
  1496. func.Serialize(IsServer(),&bs);
  1497. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1498. roomsCallback[rci]->RoomMemberJoinedRoom_Callback(packet->systemAddress,&func);
  1499. }
  1500. break;
  1501. case RPN_ROOM_INVITATION_SENT:
  1502. {
  1503. RoomInvitationSent_Notification func;
  1504. func.Serialize(IsServer(),&bs);
  1505. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1506. roomsCallback[rci]->RoomInvitationSent_Callback(packet->systemAddress,&func);
  1507. }
  1508. break;
  1509. case RPN_ROOM_INVITATION_WITHDRAWN:
  1510. {
  1511. RoomInvitationWithdrawn_Notification func;
  1512. func.Serialize(IsServer(),&bs);
  1513. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1514. roomsCallback[rci]->RoomInvitationWithdrawn_Callback(packet->systemAddress,&func);
  1515. }
  1516. break;
  1517. case RPN_ROOM_DESTROYED_ON_MODERATOR_LEFT:
  1518. {
  1519. RoomDestroyedOnModeratorLeft_Notification func;
  1520. func.Serialize(IsServer(),&bs);
  1521. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1522. roomsCallback[rci]->RoomDestroyedOnModeratorLeft_Callback(packet->systemAddress,&func);
  1523. }
  1524. break;
  1525. case RPN_CHAT_NOTIFICATION:
  1526. {
  1527. Chat_Notification func;
  1528. func.Serialize(IsServer(),&bs);
  1529. // When the filtered chat message is empty, that means the original chat message didn't have profanity anyway.
  1530. if (func.filteredChatMessage.IsEmpty())
  1531. func.filteredChatMessage=func.chatMessage;
  1532. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1533. roomsCallback[rci]->Chat_Callback(packet->systemAddress,&func);
  1534. }
  1535. break;
  1536. case RPN_BITSTREAM_NOTIFICATION:
  1537. {
  1538. Bitstream_Notification func;
  1539. func.Serialize(IsServer(),&bs);
  1540. for (unsigned int rci=0; rci < roomsCallback.Size(); rci++)
  1541. roomsCallback[rci]->Bitstream_Callback(packet->systemAddress,&func);
  1542. }
  1543. break;
  1544. }
  1545. }
  1546. void RoomsPlugin::OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason )
  1547. {
  1548. (void) lostConnectionReason;
  1549. (void) rakNetGUID;
  1550. RemoveUserResult removeUserResult;
  1551. unsigned i;
  1552. i=0;
  1553. while (i < roomsParticipants.Size())
  1554. {
  1555. if (roomsParticipants[i]->GetSystemAddress()==systemAddress)
  1556. {
  1557. roomsContainer.RemoveUser(roomsParticipants[i], &removeUserResult);
  1558. ProcessRemoveUserResult(&removeUserResult);
  1559. RakNet::OP_DELETE(roomsParticipants[i], _FILE_AND_LINE_);
  1560. roomsParticipants.RemoveAtIndex(i);
  1561. }
  1562. else
  1563. {
  1564. i++;
  1565. }
  1566. }
  1567. }
  1568. void RoomsPlugin::Clear(void)
  1569. {
  1570. ClearRoomMembers();
  1571. ClearLoginServerAdddresses();
  1572. }
  1573. bool RoomsPlugin::IsServer(void) const
  1574. {
  1575. RoomsCallback *rc=(RoomsCallback *) this;
  1576. return roomsCallback.GetIndexOf(rc)!=(unsigned int) -1;
  1577. }
  1578. RoomsPlugin::RoomsPluginParticipant* RoomsPlugin::GetParticipantByHandle(RakNet::RakString handle, const SystemAddress &senderAddress)
  1579. {
  1580. (void) senderAddress;
  1581. if (roomsParticipants.HasData(handle))
  1582. {
  1583. RoomsPluginParticipant *rp = roomsParticipants.GetElementFromKey(handle);
  1584. RakAssert(IsServer());
  1585. // 08/21/2012 - Uncommented: This was a bug with SendInvite_Func checking the sender's address against the invitees address
  1586. // 10/27/2010 - what was this for? Caused the bug http://www.jenkinssoftware.com/forum/index.php?topic=3720.0;topicseen
  1587. // This apparently validates the systemAddress to match the one in the function call
  1588. if (senderAddress==RakNet::UNASSIGNED_SYSTEM_ADDRESS || senderAddress==serverAddress)
  1589. return rp;
  1590. if (rp->GetSystemAddress()!=senderAddress)
  1591. return 0;
  1592. return rp;
  1593. }
  1594. return 0;
  1595. }
  1596. RoomsPlugin::RoomsPluginParticipant* RoomsPlugin::ValidateUserHandle(RoomsPluginFunc* func, const SystemAddress &systemAddress)
  1597. {
  1598. if (func->userName.IsEmpty())
  1599. {
  1600. func->resultCode=REC_USERNAME_IS_EMPTY;
  1601. ExecuteFunc(func, systemAddress);
  1602. return 0;
  1603. }
  1604. RoomsPluginParticipant* roomsPluginParticipant = GetParticipantByHandle(func->userName, systemAddress);
  1605. if (roomsPluginParticipant==0)
  1606. {
  1607. func->resultCode=REC_NOT_LOGGED_IN;
  1608. ExecuteFunc(func, systemAddress);
  1609. }
  1610. return roomsPluginParticipant;
  1611. }
  1612. void RoomsPlugin::CreateRoom_Callback( const SystemAddress &senderAddress, CreateRoom_Func *callResult)
  1613. {
  1614. RoomCreationParameters rcp;
  1615. rcp.networkedRoomCreationParameters=callResult->networkedRoomCreationParameters;
  1616. rcp.gameIdentifier=callResult->gameIdentifier;
  1617. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1618. if (roomsPluginParticipant==0)
  1619. return;
  1620. rcp.firstUser=roomsPluginParticipant;
  1621. callResult->resultCode=roomsContainer.CreateRoom(&rcp, profanityFilter);
  1622. if (callResult->resultCode==REC_SUCCESS)
  1623. {
  1624. roomsPluginParticipant->lastRoomJoined=roomsPluginParticipant->GetRoom()->GetID();
  1625. callResult->roomId=roomsPluginParticipant->lastRoomJoined;
  1626. if (callResult->initialRoomProperties.GetRowCount()>0)
  1627. callResult->resultCode=roomsContainer.SetCustomRoomProperties( roomsPluginParticipant, &callResult->initialRoomProperties );
  1628. callResult->roomDescriptor.FromRoom(roomsPluginParticipant->GetRoom(), &roomsContainer);
  1629. }
  1630. ExecuteFunc(callResult, senderAddress);
  1631. }
  1632. void RoomsPlugin::EnterRoom_Callback( const SystemAddress &senderAddress, EnterRoom_Func *callResult)
  1633. {
  1634. RoomCreationParameters rcp;
  1635. rcp.networkedRoomCreationParameters=callResult->networkedRoomCreationParameters;
  1636. rcp.gameIdentifier=callResult->gameIdentifier;
  1637. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1638. if (roomsPluginParticipant==0)
  1639. return;
  1640. rcp.firstUser=roomsPluginParticipant;
  1641. callResult->resultCode=roomsContainer.EnterRoom(&rcp, callResult->roomMemberMode, profanityFilter, &callResult->query, &callResult->joinedRoomResult);
  1642. callResult->createdRoom=rcp.createdRoom;
  1643. if (callResult->resultCode==REC_SUCCESS)
  1644. {
  1645. roomsPluginParticipant->lastRoomJoined=roomsPluginParticipant->GetRoom()->GetID();
  1646. callResult->roomId=roomsPluginParticipant->lastRoomJoined;
  1647. if (callResult->joinedRoomResult.roomOutput)
  1648. {
  1649. RoomMemberJoinedRoom_Notification notificationToRoom;
  1650. notificationToRoom.joinedRoomResult=&callResult->joinedRoomResult;
  1651. notificationToRoom.roomId=notificationToRoom.joinedRoomResult->roomDescriptor.lobbyRoomId;
  1652. ExecuteNotificationToOtherRoomMembers(callResult->joinedRoomResult.roomOutput, roomsPluginParticipant, &notificationToRoom);
  1653. notificationToRoom.joinedRoomResult=0;
  1654. }
  1655. }
  1656. ExecuteFunc(callResult, senderAddress);
  1657. }
  1658. void RoomsPlugin::JoinByFilter_Callback( const SystemAddress &senderAddress, JoinByFilter_Func *callResult)
  1659. {
  1660. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1661. if (roomsPluginParticipant==0)
  1662. return;
  1663. callResult->resultCode=roomsContainer.JoinByFilter(callResult->gameIdentifier, callResult->roomMemberMode, roomsPluginParticipant, roomsPluginParticipant->lastRoomJoined, &callResult->query, &callResult->joinedRoomResult );
  1664. if (callResult->resultCode==REC_SUCCESS)
  1665. {
  1666. RakAssert(callResult->joinedRoomResult.roomOutput->GetNumericProperty(DefaultRoomColumns::TC_USED_SLOTS)==callResult->joinedRoomResult.roomOutput->roomMemberList.Size()-1);
  1667. roomsPluginParticipant->lastRoomJoined=roomsPluginParticipant->GetRoom()->GetID();
  1668. RoomMemberJoinedRoom_Notification notificationToRoom;
  1669. notificationToRoom.joinedRoomResult=&callResult->joinedRoomResult;
  1670. notificationToRoom.roomId=notificationToRoom.joinedRoomResult->roomDescriptor.lobbyRoomId;
  1671. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notificationToRoom);
  1672. notificationToRoom.joinedRoomResult=0;
  1673. }
  1674. ExecuteFunc(callResult, senderAddress);
  1675. }
  1676. void RoomsPlugin::LeaveRoom_Callback( const SystemAddress &senderAddress, LeaveRoom_Func *callResult)
  1677. {
  1678. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1679. if (roomsPluginParticipant==0)
  1680. return;
  1681. callResult->resultCode=roomsContainer.LeaveRoom( roomsPluginParticipant, &callResult->removeUserResult );
  1682. ProcessRemoveUserResult(&callResult->removeUserResult);
  1683. ExecuteFunc(callResult, senderAddress);
  1684. }
  1685. void RoomsPlugin::GetInvitesToParticipant_Callback( const SystemAddress &senderAddress, GetInvitesToParticipant_Func *callResult)
  1686. {
  1687. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1688. if (roomsPluginParticipant==0)
  1689. return;
  1690. DataStructures::List<InvitedUser*> invitedUsers;
  1691. callResult->resultCode=roomsContainer.GetInvitesToParticipant( roomsPluginParticipant, invitedUsers );
  1692. unsigned int i;
  1693. for (i=0; i < invitedUsers.Size(); i++)
  1694. callResult->invitedUsers.Insert(* (invitedUsers[i]), _FILE_AND_LINE_ );
  1695. ExecuteFunc(callResult, senderAddress);
  1696. }
  1697. void RoomsPlugin::SendInvite_Callback( const SystemAddress &senderAddress, SendInvite_Func *callResult)
  1698. {
  1699. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1700. if (roomsPluginParticipant==0)
  1701. return;
  1702. RoomsPluginParticipant* inviteeId = GetParticipantByHandle( callResult->inviteeName, UNASSIGNED_SYSTEM_ADDRESS );
  1703. if (inviteeId==0)
  1704. {
  1705. callResult->resultCode=REC_SEND_INVITE_RECIPIENT_NOT_ONLINE;
  1706. ExecuteFunc(callResult, senderAddress);
  1707. return;
  1708. }
  1709. callResult->resultCode=roomsContainer.SendInvite( roomsPluginParticipant, inviteeId, callResult->inviteToSpectatorSlot, callResult->subject, callResult->body );
  1710. if (callResult->resultCode==REC_SUCCESS)
  1711. {
  1712. RoomInvitationSent_Notification notification;
  1713. notification.invitorName=roomsPluginParticipant->GetName();
  1714. notification.inviteeName=inviteeId->GetName();
  1715. notification.inviteToSpectatorSlot=callResult->inviteToSpectatorSlot;
  1716. notification.subject=callResult->subject;
  1717. notification.body=callResult->body;
  1718. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1719. ExecuteNotification(&notification, inviteeId);
  1720. }
  1721. ExecuteFunc(callResult, senderAddress);
  1722. }
  1723. void RoomsPlugin::AcceptInvite_Callback( const SystemAddress &senderAddress, AcceptInvite_Func *callResult)
  1724. {
  1725. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1726. if (roomsPluginParticipant==0)
  1727. return;
  1728. Room *room;
  1729. callResult->resultCode=roomsContainer.AcceptInvite( callResult->roomId, &room, roomsPluginParticipant, callResult->inviteSender );
  1730. if (callResult->resultCode==REC_SUCCESS)
  1731. {
  1732. RoomMemberJoinedRoom_Notification notificationToRoom;
  1733. notificationToRoom.joinedRoomResult=RakNet::OP_NEW<JoinedRoomResult>( _FILE_AND_LINE_ );
  1734. notificationToRoom.joinedRoomResult->acceptedInvitor=0;
  1735. notificationToRoom.joinedRoomResult->acceptedInvitorName=callResult->inviteSender;
  1736. notificationToRoom.joinedRoomResult->joiningMember=roomsPluginParticipant;
  1737. notificationToRoom.joinedRoomResult->joiningMemberName=roomsPluginParticipant->GetName();
  1738. notificationToRoom.joinedRoomResult->roomDescriptor.FromRoom(roomsPluginParticipant->GetRoom(), &roomsContainer);
  1739. notificationToRoom.joinedRoomResult->roomOutput=roomsPluginParticipant->GetRoom();
  1740. notificationToRoom.joinedRoomResult->agrc=&roomsContainer;
  1741. notificationToRoom.roomId=notificationToRoom.joinedRoomResult->roomDescriptor.lobbyRoomId;
  1742. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notificationToRoom);
  1743. }
  1744. ExecuteFunc(callResult, senderAddress);
  1745. }
  1746. void RoomsPlugin::StartSpectating_Callback( const SystemAddress &senderAddress, StartSpectating_Func *callResult)
  1747. {
  1748. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1749. if (roomsPluginParticipant==0)
  1750. return;
  1751. callResult->resultCode=roomsContainer.StartSpectating( roomsPluginParticipant );
  1752. if (callResult->resultCode==REC_SUCCESS)
  1753. {
  1754. RoomMemberStartedSpectating_Notification notification;
  1755. //notification.userName=roomsPluginParticipant->GetName();
  1756. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1757. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1758. }
  1759. ExecuteFunc(callResult, senderAddress);
  1760. }
  1761. void RoomsPlugin::StopSpectating_Callback( const SystemAddress &senderAddress, StopSpectating_Func *callResult)
  1762. {
  1763. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1764. if (roomsPluginParticipant==0)
  1765. return;
  1766. callResult->resultCode=roomsContainer.StopSpectating( roomsPluginParticipant );
  1767. if (callResult->resultCode==REC_SUCCESS)
  1768. {
  1769. RoomMemberStoppedSpectating_Notification notification;
  1770. //notification.userName=roomsPluginParticipant->GetName();
  1771. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1772. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1773. }
  1774. ExecuteFunc(callResult, senderAddress);
  1775. }
  1776. void RoomsPlugin::GrantModerator_Callback( const SystemAddress &senderAddress, GrantModerator_Func *callResult)
  1777. {
  1778. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1779. if (roomsPluginParticipant==0)
  1780. return;
  1781. RoomsPluginParticipant* newModerator = GetParticipantByHandle( callResult->newModerator, UNASSIGNED_SYSTEM_ADDRESS );
  1782. if (newModerator==0)
  1783. {
  1784. callResult->resultCode=REC_GRANT_MODERATOR_NEW_MODERATOR_NOT_ONLINE;
  1785. ExecuteFunc(callResult, senderAddress);
  1786. return;
  1787. }
  1788. DataStructures::List<InvitedUser> clearedInvites;
  1789. callResult->resultCode=roomsContainer.GrantModerator( roomsPluginParticipant, newModerator, clearedInvites );
  1790. if (callResult->resultCode==REC_SUCCESS)
  1791. {
  1792. ModeratorChanged_Notification notification;
  1793. notification.oldModerator=roomsPluginParticipant->GetName();
  1794. notification.newModerator=newModerator->GetName();
  1795. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1796. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1797. for (unsigned int i=0; i < clearedInvites.Size(); i++)
  1798. {
  1799. // Room *room = newModerator->GetRoom();
  1800. RoomInvitationWithdrawn_Notification notification;
  1801. notification.invitedUser=clearedInvites[i];
  1802. ExecuteNotification(&notification, GetParticipantByHandle(clearedInvites[i].target, RakNet::UNASSIGNED_SYSTEM_ADDRESS));
  1803. }
  1804. }
  1805. ExecuteFunc(callResult, senderAddress);
  1806. }
  1807. void RoomsPlugin::ChangeSlotCounts_Callback( const SystemAddress &senderAddress, ChangeSlotCounts_Func *callResult)
  1808. {
  1809. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1810. if (roomsPluginParticipant==0)
  1811. return;
  1812. callResult->resultCode=roomsContainer.ChangeSlotCounts( roomsPluginParticipant, callResult->slots );
  1813. if (callResult->resultCode==REC_SUCCESS)
  1814. {
  1815. SlotCountsSet_Notification notification;
  1816. notification.slots=callResult->slots;
  1817. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1818. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1819. }
  1820. ExecuteFunc(callResult, senderAddress);
  1821. }
  1822. void RoomsPlugin::SetCustomRoomProperties_Callback( const SystemAddress &senderAddress, SetCustomRoomProperties_Func *callResult)
  1823. {
  1824. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1825. if (roomsPluginParticipant==0)
  1826. return;
  1827. callResult->resultCode=roomsContainer.SetCustomRoomProperties( roomsPluginParticipant, &callResult->table );
  1828. if (callResult->resultCode==REC_SUCCESS)
  1829. {
  1830. CustomRoomPropertiesSet_Notification notification;
  1831. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1832. notification.tablePtr=&callResult->table;
  1833. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1834. }
  1835. ExecuteFunc(callResult, senderAddress);
  1836. }
  1837. void RoomsPlugin::GetRoomProperties_Callback( const SystemAddress &senderAddress, GetRoomProperties_Func *callResult)
  1838. {
  1839. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1840. if (roomsPluginParticipant==0)
  1841. return;
  1842. Room *room;
  1843. if (callResult->roomName.IsEmpty())
  1844. {
  1845. room=roomsPluginParticipant->GetRoom();
  1846. if (room==0)
  1847. {
  1848. callResult->resultCode=REC_GET_ROOM_PROPERTIES_EMPTY_ROOM_NAME_AND_NOT_IN_A_ROOM;
  1849. ExecuteFunc(callResult, senderAddress);
  1850. return;
  1851. }
  1852. callResult->roomName=roomsPluginParticipant->GetRoom()->GetStringProperty(DefaultRoomColumns::TC_ROOM_NAME);
  1853. }
  1854. else
  1855. {
  1856. room = roomsContainer.GetRoomByName(callResult->roomName);
  1857. if (room==0)
  1858. {
  1859. callResult->resultCode=REC_GET_ROOM_PROPERTIES_UNKNOWN_ROOM_NAME;
  1860. ExecuteFunc(callResult, senderAddress);
  1861. return;
  1862. }
  1863. }
  1864. callResult->roomDescriptor.FromRoom(room, &roomsContainer);
  1865. callResult->resultCode=REC_SUCCESS;
  1866. ExecuteFunc(callResult, senderAddress);
  1867. }
  1868. void RoomsPlugin::ChangeRoomName_Callback( const SystemAddress &senderAddress, ChangeRoomName_Func *callResult)
  1869. {
  1870. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1871. if (roomsPluginParticipant==0)
  1872. return;
  1873. RoomNameSet_Notification notification;
  1874. if (roomsPluginParticipant->GetRoom())
  1875. notification.oldName=roomsPluginParticipant->GetRoom()->GetStringProperty(DefaultRoomColumns::TC_ROOM_NAME);
  1876. callResult->resultCode=roomsContainer.ChangeRoomName( roomsPluginParticipant, callResult->newRoomName, profanityFilter );
  1877. if (callResult->resultCode==REC_SUCCESS)
  1878. {
  1879. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1880. notification.newName=callResult->newRoomName;
  1881. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1882. }
  1883. ExecuteFunc(callResult, senderAddress);
  1884. }
  1885. void RoomsPlugin::SetHiddenFromSearches_Callback( const SystemAddress &senderAddress, SetHiddenFromSearches_Func *callResult)
  1886. {
  1887. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1888. if (roomsPluginParticipant==0)
  1889. return;
  1890. callResult->resultCode=roomsContainer.SetHiddenFromSearches( roomsPluginParticipant, callResult->hiddenFromSearches );
  1891. if (callResult->resultCode==REC_SUCCESS)
  1892. {
  1893. HiddenFromSearchesSet_Notification notification;
  1894. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1895. notification.hiddenFromSearches=callResult->hiddenFromSearches;
  1896. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1897. }
  1898. ExecuteFunc(callResult, senderAddress);
  1899. }
  1900. void RoomsPlugin::SetDestroyOnModeratorLeave_Callback( const SystemAddress &senderAddress, SetDestroyOnModeratorLeave_Func *callResult)
  1901. {
  1902. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1903. if (roomsPluginParticipant==0)
  1904. return;
  1905. callResult->resultCode=roomsContainer.SetDestroyOnModeratorLeave( roomsPluginParticipant, callResult->destroyOnModeratorLeave );
  1906. ExecuteFunc(callResult, senderAddress);
  1907. }
  1908. void RoomsPlugin::SetReadyStatus_Callback( const SystemAddress &senderAddress, SetReadyStatus_Func *callResult)
  1909. {
  1910. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1911. if (roomsPluginParticipant==0)
  1912. return;
  1913. callResult->resultCode=roomsContainer.SetReadyStatus( roomsPluginParticipant, callResult->isReady );
  1914. DataStructures::List<RoomsParticipant*> readyUsers;
  1915. DataStructures::List<RoomsParticipant*> unreadyUsers;
  1916. unsigned int i;
  1917. roomsPluginParticipant->GetRoom()->GetReadyStatus(readyUsers, unreadyUsers);
  1918. if (callResult->resultCode==REC_SUCCESS)
  1919. {
  1920. RoomMemberReadyStatusSet_Notification notification;
  1921. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1922. notification.isReady=callResult->isReady;
  1923. notification.roomMember=roomsPluginParticipant->GetName();
  1924. for (i=0; i < readyUsers.Size(); i++)
  1925. notification.readyUsers.Insert(readyUsers[i]->GetName(), _FILE_AND_LINE_ );
  1926. for (i=0; i < unreadyUsers.Size(); i++)
  1927. notification.unreadyUsers.Insert(unreadyUsers[i]->GetName(), _FILE_AND_LINE_ );
  1928. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1929. }
  1930. for (i=0; i < readyUsers.Size(); i++)
  1931. callResult->readyUsers.Insert(readyUsers[i]->GetName(), _FILE_AND_LINE_ );
  1932. for (i=0; i < unreadyUsers.Size(); i++)
  1933. callResult->unreadyUsers.Insert(unreadyUsers[i]->GetName(), _FILE_AND_LINE_ );
  1934. ExecuteFunc(callResult, senderAddress);
  1935. }
  1936. void RoomsPlugin::GetReadyStatus_Callback( const SystemAddress &senderAddress, GetReadyStatus_Func *callResult)
  1937. {
  1938. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1939. if (roomsPluginParticipant==0)
  1940. return;
  1941. if (roomsPluginParticipant->GetRoom()==0)
  1942. {
  1943. callResult->resultCode=REC_GET_READY_STATUS_NOT_IN_ROOM;
  1944. ExecuteFunc(callResult, senderAddress);
  1945. return;
  1946. }
  1947. Room *room;
  1948. DataStructures::List<RoomsParticipant*> readyUsers;
  1949. DataStructures::List<RoomsParticipant*> unreadyUsers;
  1950. callResult->resultCode=roomsContainer.GetReadyStatus( roomsPluginParticipant->GetRoom()->GetID(), &room, readyUsers, unreadyUsers );
  1951. unsigned int i;
  1952. for (i=0; i < readyUsers.Size(); i++)
  1953. callResult->readyUsers.Insert(readyUsers[i]->GetName(), _FILE_AND_LINE_ );
  1954. for (i=0; i < unreadyUsers.Size(); i++)
  1955. callResult->unreadyUsers.Insert(unreadyUsers[i]->GetName(), _FILE_AND_LINE_ );
  1956. ExecuteFunc(callResult, senderAddress);
  1957. }
  1958. void RoomsPlugin::SetRoomLockState_Callback( const SystemAddress &senderAddress, SetRoomLockState_Func *callResult)
  1959. {
  1960. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1961. if (roomsPluginParticipant==0)
  1962. return;
  1963. callResult->resultCode=roomsContainer.SetRoomLockState( roomsPluginParticipant, callResult->roomLockState );
  1964. if (callResult->resultCode==REC_SUCCESS)
  1965. {
  1966. RoomLockStateSet_Notification notification;
  1967. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  1968. notification.roomLockState=callResult->roomLockState;
  1969. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  1970. }
  1971. ExecuteFunc(callResult, senderAddress);
  1972. }
  1973. void RoomsPlugin::GetRoomLockState_Callback( const SystemAddress &senderAddress, GetRoomLockState_Func *callResult)
  1974. {
  1975. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1976. if (roomsPluginParticipant==0)
  1977. return;
  1978. if (roomsPluginParticipant->GetRoom()==0)
  1979. {
  1980. callResult->resultCode=REC_GET_ROOM_LOCK_STATE_NOT_IN_ROOM;
  1981. ExecuteFunc(callResult, senderAddress);
  1982. return;
  1983. }
  1984. Room *room;
  1985. callResult->resultCode=roomsContainer.GetRoomLockState( roomsPluginParticipant->GetRoom()->GetID(), &room, &callResult->roomLockState );
  1986. ExecuteFunc(callResult, senderAddress);
  1987. }
  1988. void RoomsPlugin::AreAllMembersReady_Callback( const SystemAddress &senderAddress, AreAllMembersReady_Func *callResult)
  1989. {
  1990. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  1991. if (roomsPluginParticipant==0)
  1992. return;
  1993. if (roomsPluginParticipant->GetRoom()==0)
  1994. {
  1995. callResult->resultCode=REC_ARE_ALL_MEMBERS_READY_NOT_IN_ROOM;
  1996. ExecuteFunc(callResult, senderAddress);
  1997. return;
  1998. }
  1999. Room *room;
  2000. callResult->resultCode=roomsContainer.AreAllMembersReady( roomsPluginParticipant->GetRoom()->GetID(), &room, &callResult->allReady );
  2001. ExecuteFunc(callResult, senderAddress);
  2002. }
  2003. void RoomsPlugin::KickMember_Callback( const SystemAddress &senderAddress, KickMember_Func *callResult)
  2004. {
  2005. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2006. if (roomsPluginParticipant==0)
  2007. return;
  2008. RoomsPluginParticipant* kickedMember = GetParticipantByHandle(callResult->kickedMember, RakNet::UNASSIGNED_SYSTEM_ADDRESS);
  2009. if (kickedMember==0)
  2010. {
  2011. callResult->resultCode=REC_KICK_MEMBER_TARGET_NOT_ONLINE;
  2012. ExecuteFunc(callResult, senderAddress);
  2013. return;
  2014. }
  2015. callResult->resultCode=roomsContainer.KickMember( roomsPluginParticipant, kickedMember, callResult->reason );
  2016. if (callResult->resultCode==REC_SUCCESS)
  2017. {
  2018. RoomMemberKicked_Notification notification;
  2019. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  2020. notification.moderator=roomsPluginParticipant->GetName();
  2021. notification.kickedMember=callResult->kickedMember;
  2022. notification.reason=callResult->reason;
  2023. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  2024. // Also send notification to the guy kicked
  2025. ExecuteNotification(&notification, kickedMember);
  2026. }
  2027. ExecuteFunc(callResult, senderAddress);
  2028. }
  2029. void RoomsPlugin::UnbanMember_Callback( const SystemAddress &senderAddress, UnbanMember_Func *callResult)
  2030. {
  2031. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2032. if (roomsPluginParticipant==0)
  2033. return;
  2034. callResult->resultCode=roomsContainer.UnbanMember( roomsPluginParticipant, callResult->bannedMemberName );
  2035. ExecuteFunc(callResult, senderAddress);
  2036. }
  2037. void RoomsPlugin::GetBanReason_Callback( const SystemAddress &senderAddress, GetBanReason_Func *callResult)
  2038. {
  2039. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2040. if (roomsPluginParticipant==0)
  2041. return;
  2042. Room *room;
  2043. callResult->resultCode=roomsContainer.GetBanReason( callResult->roomId, &room, callResult->userName, &callResult->reason );
  2044. ExecuteFunc(callResult, senderAddress);
  2045. }
  2046. void RoomsPlugin::AddUserToQuickJoin_Callback( const SystemAddress &senderAddress, AddUserToQuickJoin_Func *callResult)
  2047. {
  2048. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2049. if (roomsPluginParticipant==0)
  2050. return;
  2051. QuickJoinUser *qju = RakNet::OP_NEW<QuickJoinUser>( _FILE_AND_LINE_ );
  2052. qju->networkedQuickJoinUser=callResult->networkedQuickJoinUser;
  2053. qju->roomsParticipant=roomsPluginParticipant;
  2054. callResult->resultCode=roomsContainer.AddUserToQuickJoin( callResult->gameIdentifier, qju );
  2055. ExecuteFunc(callResult, senderAddress);
  2056. }
  2057. void RoomsPlugin::RemoveUserFromQuickJoin_Callback( const SystemAddress &senderAddress, RemoveUserFromQuickJoin_Func *callResult)
  2058. {
  2059. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2060. if (roomsPluginParticipant==0)
  2061. return;
  2062. QuickJoinUser *qju;
  2063. callResult->resultCode=roomsContainer.RemoveUserFromQuickJoin( roomsPluginParticipant, &qju );
  2064. if (qju)
  2065. RakNet::OP_DELETE(qju, _FILE_AND_LINE_);
  2066. ExecuteFunc(callResult, senderAddress);
  2067. }
  2068. void RoomsPlugin::IsInQuickJoin_Callback( const SystemAddress &senderAddress, IsInQuickJoin_Func *callResult)
  2069. {
  2070. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2071. if (roomsPluginParticipant==0)
  2072. return;
  2073. callResult->resultCode=REC_SUCCESS;
  2074. callResult->isInQuickJoin=roomsContainer.IsInQuickJoin( roomsPluginParticipant );
  2075. ExecuteFunc(callResult, senderAddress);
  2076. }
  2077. void RoomsPlugin::SearchByFilter_Callback( const SystemAddress &senderAddress, SearchByFilter_Func *callResult)
  2078. {
  2079. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2080. if (roomsPluginParticipant==0)
  2081. return;
  2082. DataStructures::OrderedList<Room*, Room*, AllGamesRoomsContainer::RoomsSortByName> roomsOutput;
  2083. callResult->resultCode=roomsContainer.SearchByFilter( callResult->gameIdentifier, roomsPluginParticipant, &callResult->roomQuery, roomsOutput, callResult->onlyJoinable);
  2084. unsigned i;
  2085. RoomDescriptor *desc;
  2086. for (i=0; i < roomsOutput.Size(); i++)
  2087. {
  2088. desc = RakNet::OP_NEW<RoomDescriptor>( _FILE_AND_LINE_ );
  2089. desc->FromRoom(roomsOutput[i], &roomsContainer);
  2090. callResult->roomsOutput.Insert(desc, _FILE_AND_LINE_ );
  2091. }
  2092. ExecuteFunc(callResult, senderAddress);
  2093. }
  2094. void RoomsPlugin::ChangeHandle_Callback( const SystemAddress &senderAddress, ChangeHandle_Func *callResult)
  2095. {
  2096. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2097. if (roomsPluginParticipant==0)
  2098. return;
  2099. if (profanityFilter->HasProfanity(callResult->newHandle.C_String()))
  2100. {
  2101. callResult->resultCode=REC_CHANGE_HANDLE_CONTAINS_PROFANITY;
  2102. ExecuteFunc(callResult, senderAddress);
  2103. return;
  2104. }
  2105. RoomMemberHandleSet_Notification notification;
  2106. if (roomsPluginParticipant)
  2107. notification.oldName=roomsPluginParticipant->GetName();
  2108. if (GetParticipantByHandle(callResult->newHandle, RakNet::UNASSIGNED_SYSTEM_ADDRESS))
  2109. {
  2110. callResult->resultCode=REC_CHANGE_HANDLE_NEW_HANDLE_IN_USE;
  2111. ExecuteFunc(callResult, senderAddress);
  2112. return;
  2113. }
  2114. callResult->resultCode=REC_SUCCESS;
  2115. roomsContainer.ChangeHandle( roomsPluginParticipant->GetName(), callResult->newHandle );
  2116. if (roomsPluginParticipant->GetRoom())
  2117. {
  2118. notification.roomId=roomsPluginParticipant->GetRoom()->GetID();
  2119. notification.newName=callResult->newHandle;
  2120. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  2121. }
  2122. ExecuteFunc(callResult, senderAddress);
  2123. }
  2124. void RoomsPlugin::Chat_Callback( const SystemAddress &senderAddress, Chat_Func *callResult)
  2125. {
  2126. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2127. if (roomsPluginParticipant==0)
  2128. return;
  2129. if (roomsPluginParticipant->GetRoom()==0 && callResult->chatDirectedToRoom)
  2130. {
  2131. callResult->resultCode=REC_CHAT_USER_NOT_IN_ROOM;
  2132. ExecuteFunc(callResult, senderAddress);
  2133. return;
  2134. }
  2135. Chat_Notification notification;
  2136. notification.sender=roomsPluginParticipant->GetName();
  2137. notification.privateMessageRecipient=callResult->privateMessageRecipient;
  2138. notification.chatMessage=callResult->chatMessage;
  2139. notification.filteredChatMessage=callResult->chatMessage;
  2140. if (profanityFilter)
  2141. profanityFilter->FilterProfanity(notification.filteredChatMessage.C_String(), notification.filteredChatMessage.C_StringUnsafe(), true);
  2142. if (notification.filteredChatMessage==notification.chatMessage)
  2143. notification.filteredChatMessage.Clear(); // Save bandwidth
  2144. if (callResult->privateMessageRecipient.IsEmpty()==false)
  2145. {
  2146. RoomsPluginParticipant* recipient = GetParticipantByHandle(callResult->privateMessageRecipient, RakNet::UNASSIGNED_SYSTEM_ADDRESS);
  2147. if (recipient==0)
  2148. {
  2149. callResult->resultCode=REC_CHAT_RECIPIENT_NOT_ONLINE;
  2150. ExecuteFunc(callResult, senderAddress);
  2151. return;
  2152. }
  2153. if (callResult->chatDirectedToRoom)
  2154. {
  2155. if (recipient->GetRoom()==0)
  2156. {
  2157. callResult->resultCode=REC_CHAT_RECIPIENT_NOT_IN_ANY_ROOM;
  2158. ExecuteFunc(callResult, senderAddress);
  2159. return;
  2160. }
  2161. if (recipient->GetRoom()!=roomsPluginParticipant->GetRoom())
  2162. {
  2163. callResult->resultCode=REC_CHAT_RECIPIENT_NOT_IN_YOUR_ROOM;
  2164. ExecuteFunc(callResult, senderAddress);
  2165. return;
  2166. }
  2167. }
  2168. callResult->resultCode=REC_SUCCESS;
  2169. ExecuteNotification(&notification, recipient);
  2170. ExecuteFunc(callResult, senderAddress);
  2171. return;
  2172. }
  2173. else
  2174. {
  2175. if (callResult->chatDirectedToRoom==false)
  2176. {
  2177. // Chat not directed to room, and no recipients.
  2178. callResult->resultCode=REC_CHAT_RECIPIENT_NOT_ONLINE;
  2179. ExecuteFunc(callResult, senderAddress);
  2180. return;
  2181. }
  2182. }
  2183. callResult->resultCode=REC_SUCCESS;
  2184. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  2185. ExecuteFunc(callResult, senderAddress);
  2186. }
  2187. void RoomsPlugin::Bitstream_Callback( const SystemAddress &senderAddress, Bitstream_Func *callResult)
  2188. {
  2189. RoomsPluginParticipant* roomsPluginParticipant = ValidateUserHandle(callResult, senderAddress);
  2190. if (roomsPluginParticipant==0)
  2191. return;
  2192. if (roomsPluginParticipant->GetRoom()==0 && callResult->directedToRoom)
  2193. {
  2194. callResult->resultCode=REC_BITSTREAM_USER_NOT_IN_ROOM;
  2195. ExecuteFunc(callResult, senderAddress);
  2196. return;
  2197. }
  2198. Bitstream_Notification notification;
  2199. notification.sender=roomsPluginParticipant->GetName();
  2200. notification.privateMessageRecipient=callResult->privateMessageRecipient;
  2201. notification.bitStreamReceived.Write(callResult->bsToSend);
  2202. if (callResult->privateMessageRecipient.IsEmpty()==false)
  2203. {
  2204. RoomsPluginParticipant* recipient = GetParticipantByHandle(callResult->privateMessageRecipient, RakNet::UNASSIGNED_SYSTEM_ADDRESS);
  2205. if (recipient==0)
  2206. {
  2207. callResult->resultCode=REC_BITSTREAM_RECIPIENT_NOT_ONLINE;
  2208. ExecuteFunc(callResult, senderAddress);
  2209. return;
  2210. }
  2211. if (callResult->directedToRoom)
  2212. {
  2213. if (recipient->GetRoom()==0)
  2214. {
  2215. callResult->resultCode=REC_BITSTREAM_RECIPIENT_NOT_IN_ANY_ROOM;
  2216. ExecuteFunc(callResult, senderAddress);
  2217. return;
  2218. }
  2219. if (recipient->GetRoom()!=roomsPluginParticipant->GetRoom())
  2220. {
  2221. callResult->resultCode=REC_BITSTREAM_RECIPIENT_NOT_IN_YOUR_ROOM;
  2222. ExecuteFunc(callResult, senderAddress);
  2223. return;
  2224. }
  2225. }
  2226. callResult->resultCode=REC_SUCCESS;
  2227. ExecuteNotification(&notification, recipient);
  2228. ExecuteFunc(callResult, senderAddress);
  2229. return;
  2230. }
  2231. else
  2232. {
  2233. if (callResult->directedToRoom==false)
  2234. {
  2235. // Chat not directed to room, and no recipients.
  2236. callResult->resultCode=REC_BITSTREAM_RECIPIENT_NOT_ONLINE;
  2237. ExecuteFunc(callResult, senderAddress);
  2238. return;
  2239. }
  2240. }
  2241. callResult->resultCode=REC_SUCCESS;
  2242. ExecuteNotificationToOtherRoomMembers(roomsPluginParticipant->GetRoom(), roomsPluginParticipant, &notification);
  2243. ExecuteFunc(callResult, senderAddress);
  2244. }
  2245. void RoomsPlugin::ProcessRemoveUserResult(RemoveUserResult *removeUserResult)
  2246. {
  2247. unsigned int j;
  2248. for (j=0; j < removeUserResult->clearedInvitations.Size(); j++)
  2249. {
  2250. RoomsPluginParticipant* invitationRecipient = GetParticipantByHandle(removeUserResult->clearedInvitations[j].target, RakNet::UNASSIGNED_SYSTEM_ADDRESS);
  2251. if (invitationRecipient)
  2252. {
  2253. RoomInvitationWithdrawn_Notification notification;
  2254. notification.invitedUser=removeUserResult->clearedInvitations[j];
  2255. ExecuteNotification(&notification, invitationRecipient);
  2256. }
  2257. }
  2258. if (removeUserResult->removedFromRoom)
  2259. {
  2260. if (removeUserResult->room)
  2261. {
  2262. if (removeUserResult->roomDestroyed==false)
  2263. {
  2264. if (removeUserResult->gotNewModerator)
  2265. {
  2266. ModeratorChanged_Notification notification;
  2267. notification.oldModerator=removeUserResult->removedUserName;
  2268. notification.newModerator=removeUserResult->room->GetModerator()->GetName();
  2269. ExecuteNotificationToOtherRoomMembers(removeUserResult->room, 0, &notification);
  2270. }
  2271. RoomMemberLeftRoom_Notification notification;
  2272. notification.roomId=removeUserResult->room->GetID();
  2273. notification.roomMember=removeUserResult->removedUserName;
  2274. ExecuteNotificationToOtherRoomMembers(removeUserResult->room, 0, &notification);
  2275. }
  2276. else
  2277. {
  2278. RoomDestroyedOnModeratorLeft_Notification notification;
  2279. notification.oldModerator=removeUserResult->removedUserName;
  2280. notification.roomId=removeUserResult->room->GetID();
  2281. notification.roomDescriptor.FromRoom(removeUserResult->room, &roomsContainer);
  2282. ExecuteNotificationToOtherRoomMembers(removeUserResult->room, 0, &notification);
  2283. }
  2284. }
  2285. }
  2286. if (removeUserResult->removedFromQuickJoin)
  2287. {
  2288. if (removeUserResult->qju)
  2289. RakNet::OP_DELETE(removeUserResult->qju, _FILE_AND_LINE_);
  2290. }
  2291. roomsContainer.DestroyRoomIfDead(removeUserResult->room);
  2292. }
  2293. void RoomsPlugin::ExecuteNotificationToOtherRoomMembers(Room *room, RoomsPluginParticipant* roomsPluginParticipant, RoomsPluginNotification *notification)
  2294. {
  2295. unsigned roomMemberIndex;
  2296. for (roomMemberIndex=0; roomMemberIndex < room->roomMemberList.Size(); roomMemberIndex++)
  2297. {
  2298. if (room->roomMemberList[roomMemberIndex]->roomsParticipant!=roomsPluginParticipant )
  2299. ExecuteNotification(notification, ((RoomsPluginParticipant*)room->roomMemberList[roomMemberIndex]->roomsParticipant));
  2300. }
  2301. }
粤ICP备19079148号