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