RoomsPlugin.h 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief Adds networking to AllGamesRoomsContainer. Lets you create, join, search, and destroy matchmaking rooms for players
  12. /// \sa TeamManager TeamManager performs some of the same functions as RoomsPlugin in a more flexible way
  13. ///
  14. #ifndef __ROOMS_PLUGIN_H
  15. #define __ROOMS_PLUGIN_H
  16. #include "RakNetTypes.h"
  17. #include "PluginInterface2.h"
  18. #include "DS_OrderedList.h"
  19. #include "Export.h"
  20. #include "RoomsContainer.h"
  21. #include "PacketPriority.h"
  22. #include "BitStream.h"
  23. /// \defgroup ROOMS_GROUP RoomsPlugin
  24. /// \brief Networked implementation of a rooms system, where members join and leave rooms.
  25. /// \details
  26. /// \ingroup PLUGINS_GROUP
  27. /// \defgroup ROOMS_COMMANDS RoomsCommands
  28. /// \brief Commands that can be sent to RoomsPlugin
  29. /// \details
  30. /// \ingroup ROOMS_GROUP
  31. /// \defgroup ROOMS_NOTIFICATIONS RoomsNotifications
  32. /// \brief Notifications that RoomsPlugin sends to you
  33. /// \details
  34. /// \ingroup ROOMS_GROUP
  35. namespace RakNet
  36. {
  37. class RakPeerInterface;
  38. /// \brief Base class for rooms functionality
  39. /// \details Operations performed on rooms are not in the RoomsPlugin - instead, each structure encapsulates one operation
  40. /// \ingroup ROOMS_COMMANDS
  41. struct RoomsPluginFunc {
  42. RoomsPluginFunc() {}
  43. virtual ~RoomsPluginFunc() {}
  44. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream)=0;
  45. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream)=0;
  46. void PrintResult(void);
  47. /// \param[in] userName Who is performing this operation. Input parameter
  48. RakNet::RakString userName;
  49. /// \param[out] resultCode Result of this operation
  50. RoomsErrorCode resultCode;
  51. };
  52. /// \brief Create a room. Each user can be in at most one room, so will fail if the user is already in a room
  53. /// \ingroup ROOMS_COMMANDS
  54. struct CreateRoom_Func : public RoomsPluginFunc {
  55. // Input parameters
  56. NetworkedRoomCreationParameters networkedRoomCreationParameters;
  57. GameIdentifier gameIdentifier;
  58. // If initialRoomProperties is not empty, then SetCustomRoomProperties_Func will be run after the room is created successfully
  59. DataStructures::Table initialRoomProperties;
  60. // Output parameters
  61. RoomID roomId;
  62. RoomDescriptor roomDescriptor;
  63. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  64. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  65. };
  66. /// \brief Joins a room if possible. If not, creates a room.
  67. /// \ingroup ROOMS_COMMANDS
  68. struct EnterRoom_Func : public RoomsPluginFunc {
  69. // Input parameters
  70. NetworkedRoomCreationParameters networkedRoomCreationParameters;
  71. RoomMemberMode roomMemberMode;
  72. RoomQuery query;
  73. GameIdentifier gameIdentifier;
  74. // Output parameters
  75. JoinedRoomResult joinedRoomResult;
  76. bool createdRoom;
  77. RoomID roomId;
  78. void PrintResult(void)
  79. {
  80. if (resultCode!=REC_SUCCESS)
  81. printf("Result for user %s: %s\n", userName.C_String(), RoomsErrorCodeDescription::ToEnglish(resultCode));
  82. else if (createdRoom)
  83. printf("%s created a new room\n", userName.C_String());
  84. else
  85. printf("%s entered room with %i members\n", userName.C_String(), joinedRoomResult.roomDescriptor.roomMemberList.Size());
  86. }
  87. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  88. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  89. };
  90. /// \brief Joins a room given the filter parameters and desired room member mode.
  91. /// \details Room joins may fail if the room is locked, or does not have slots of the particular type
  92. /// Room joins may succeed where they would otherwise fail if the user has an invitation to the room
  93. /// \ingroup ROOMS_COMMANDS
  94. struct JoinByFilter_Func : public RoomsPluginFunc {
  95. // Input parameters
  96. GameIdentifier gameIdentifier;
  97. RoomMemberMode roomMemberMode;
  98. RoomQuery query;
  99. // Output parameters
  100. JoinedRoomResult joinedRoomResult;
  101. void PrintResult(void)
  102. {
  103. if (resultCode!=REC_SUCCESS)
  104. printf("Result for user %s: %s\n", userName.C_String(), RoomsErrorCodeDescription::ToEnglish(resultCode));
  105. else
  106. {
  107. printf("Joined room %s with id %i and %.0f used slots\n",
  108. joinedRoomResult.roomDescriptor.GetProperty(DefaultRoomColumns::TC_ROOM_NAME)->c, joinedRoomResult.roomDescriptor.lobbyRoomId,
  109. joinedRoomResult.roomDescriptor.GetProperty(DefaultRoomColumns::TC_USED_SLOTS)->i);
  110. for (unsigned int i=0; i < joinedRoomResult.roomDescriptor.roomMemberList.Size(); i++)
  111. {
  112. printf("%i. %s (%s)\n", i+1, joinedRoomResult.roomDescriptor.roomMemberList[i].name.C_String(), joinedRoomResult.roomDescriptor.roomMemberList[i].systemAddress.ToString());
  113. }
  114. }
  115. }
  116. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  117. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  118. };
  119. /// \brief Leaves a room. You can leave at any time, even if the room is locked.
  120. /// \ingroup ROOMS_COMMANDS
  121. struct LeaveRoom_Func : public RoomsPluginFunc {
  122. // Input parameters
  123. // Output parameters
  124. RemoveUserResult removeUserResult;
  125. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  126. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  127. };
  128. /// Gets all invitations to you to various rooms.
  129. /// \ingroup ROOMS_COMMANDS
  130. struct GetInvitesToParticipant_Func : public RoomsPluginFunc {
  131. // Input parameters
  132. // Output parameters
  133. DataStructures::List<InvitedUser> invitedUsers;
  134. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  135. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  136. };
  137. /// \brief Sends an invitation to someone.
  138. /// \details Each user may have at most one invitation to the same room, although they have have invitations to multiple rooms.<BR>
  139. /// This may fail depending on the room settings - the moderator may not allow other users to send invitations.<BR>
  140. /// Invitations may be cleared when the moderator changes, depending on the room settings
  141. /// \ingroup ROOMS_COMMANDS
  142. struct SendInvite_Func : public RoomsPluginFunc {
  143. // Input parameters
  144. RakNet::RakString inviteeName;
  145. bool inviteToSpectatorSlot;
  146. RakNet::RakString subject;
  147. RakNet::RakString body;
  148. // Output parameters
  149. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  150. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  151. };
  152. /// \brief Accept an invitation from a user to a room.
  153. /// \details Invitations are the only way to join reserved slots. If all reserved slots are full, will join a public slot if possible.
  154. /// \ingroup ROOMS_COMMANDS
  155. struct AcceptInvite_Func : public RoomsPluginFunc {
  156. // Input parameters
  157. RakNet::RakString inviteSender;
  158. RoomID roomId;
  159. // Output parameters
  160. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  161. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  162. };
  163. /// \brief Begin spectating. Spectators are considered room members that are not playing the game, only watching
  164. /// \details Spectators do not count towards room ready states. The moderator can lock the room, preventing users from spectating, or not allow spectators at all
  165. /// \ingroup ROOMS_COMMANDS
  166. struct StartSpectating_Func : public RoomsPluginFunc {
  167. // Input parameters
  168. // Output parameters
  169. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  170. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  171. };
  172. /// \brief Stop spectating. This will rejoin the room as a player, using a reserved slot if we were invited, and a public slot if not or if there are no reserved slots
  173. /// \details This may fail if the moderator locked the room, or if no slots are available.
  174. /// \ingroup ROOMS_COMMANDS
  175. struct StopSpectating_Func : public RoomsPluginFunc {
  176. // Input parameters
  177. // Output parameters
  178. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  179. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  180. };
  181. /// \brief Give moderator to another player. Moderators cannot be spectators.
  182. /// \ingroup ROOMS_COMMANDS
  183. struct GrantModerator_Func : public RoomsPluginFunc {
  184. // Input parameters
  185. RakNet::RakString newModerator;
  186. // Output parameters
  187. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  188. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  189. };
  190. /// \brief Change the allowed slot counts for the room. Setting fewer slot counts than the number of players does not kick out players, though it may prevent changing spectator status
  191. /// \ingroup ROOMS_COMMANDS
  192. struct ChangeSlotCounts_Func : public RoomsPluginFunc {
  193. // Input parameters
  194. Slots slots;
  195. // Output parameters
  196. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  197. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  198. };
  199. /// \brief Sets a table of user-defined room properties
  200. /// \details Fill out the table with the column name, type, and value.<BR>
  201. /// These properties are read when searching for rooms, and can be used as query filters to only join rooms with specified properties<BR>
  202. /// See RoomTypes.h for default room properties.
  203. /// \ingroup ROOMS_COMMANDS
  204. struct SetCustomRoomProperties_Func : public RoomsPluginFunc {
  205. // Input parameters
  206. DataStructures::Table table;
  207. // Output parameters
  208. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  209. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  210. };
  211. /// \brief Given a named room, return the properties of that room, including member list
  212. /// \ingroup ROOMS_COMMANDS
  213. struct GetRoomProperties_Func : public RoomsPluginFunc {
  214. // Input parameters
  215. // If blank, uses the room the user is currently in.
  216. RakNet::RakString roomName;
  217. // Output parameters
  218. RoomDescriptor roomDescriptor;
  219. void PrintResult(void)
  220. {
  221. if (resultCode!=REC_SUCCESS)
  222. {
  223. printf("Result for user %s: %s\n", userName.C_String(), RoomsErrorCodeDescription::ToEnglish(resultCode));
  224. }
  225. else
  226. {
  227. // char out[8096];
  228. printf("room %s has %i columns and %i used slots\n", roomName.C_String(),
  229. roomDescriptor.roomProperties.GetColumnCount(), roomDescriptor.roomMemberList.Size());
  230. RakAssert(roomDescriptor.GetProperty(DefaultRoomColumns::TC_USED_SLOTS)->i==roomDescriptor.roomMemberList.Size()-1);
  231. // roomDescriptor.roomProperties.PrintColumnHeaders(out,8096,',');
  232. // printf(out);
  233. // roomDescriptor.roomProperties.PrintRow(out,8096,',',false,roomDescriptor.roomProperties.GetRowByIndex(0,0));
  234. // printf(out);
  235. }
  236. }
  237. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  238. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  239. };
  240. /// \brief Change the name of the room
  241. /// \ingroup ROOMS_COMMANDS
  242. struct ChangeRoomName_Func : public RoomsPluginFunc {
  243. // Input parameters
  244. RakNet::RakString newRoomName;
  245. // Output parameters
  246. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  247. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  248. };
  249. /// \brief Set or unset the room hidden from searches. If a room is hidden from searches, it can only be joined through invitations
  250. /// \ingroup ROOMS_COMMANDS
  251. struct SetHiddenFromSearches_Func : public RoomsPluginFunc {
  252. // Input parameters
  253. bool hiddenFromSearches;
  254. // Output parameters
  255. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  256. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  257. };
  258. /// \brief Sets or unsets to destroy the room when the moderator leaves the room
  259. /// \details If false, the next moderator will be the oldest member that is not a spectator.
  260. /// \ingroup ROOMS_COMMANDS
  261. struct SetDestroyOnModeratorLeave_Func : public RoomsPluginFunc {
  262. // Input parameters
  263. bool destroyOnModeratorLeave;
  264. // Output parameters
  265. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  266. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  267. };
  268. /// \brief Sets or unsets the user as flagged 'ready'
  269. /// \details Ready means ready to play the game. This flag can be set or unset by each room member.BR>
  270. /// When all players are ready, the can will presumably start (although you can use this flag however you want).
  271. /// \ingroup ROOMS_COMMANDS
  272. struct SetReadyStatus_Func : public RoomsPluginFunc {
  273. // Input parameters
  274. bool isReady;
  275. // Output parameters
  276. DataStructures::List<RakNet::RakString> readyUsers;
  277. DataStructures::List<RakNet::RakString> unreadyUsers;
  278. void PrintResult(void)
  279. {
  280. if (resultCode!=REC_SUCCESS)
  281. {
  282. printf("Result for user %s: %s\n", userName.C_String(), RoomsErrorCodeDescription::ToEnglish(resultCode));
  283. }
  284. else
  285. {
  286. printf("SetReadyStatus_Func member ready states:\n");
  287. if (readyUsers.Size()>0)
  288. {
  289. printf("Ready: ");
  290. for (unsigned int i=0; i < readyUsers.Size(); i++)
  291. {
  292. printf("%s ", readyUsers[i].C_String());
  293. }
  294. printf("\n");
  295. }
  296. if (unreadyUsers.Size()>0)
  297. {
  298. printf("Unready: ");
  299. for (unsigned int i=0; i < unreadyUsers.Size(); i++)
  300. {
  301. printf("%s ", unreadyUsers[i].C_String());
  302. }
  303. printf("\n");
  304. }
  305. }
  306. }
  307. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  308. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  309. };
  310. /// \brief Gets the ready states for every user in the room, excluding spectators
  311. /// \ingroup ROOMS_COMMANDS
  312. struct GetReadyStatus_Func : public RoomsPluginFunc {
  313. // Input parameters
  314. // Output parameters
  315. DataStructures::List<RakNet::RakString> readyUsers;
  316. DataStructures::List<RakNet::RakString> unreadyUsers;
  317. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  318. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  319. };
  320. /// \brief Lock or unlock the room
  321. /// \details If the room is locked, no further players can join regardless of the available room slots. This includes invited players.<BR>
  322. /// Rooms default to unlocked
  323. /// \ingroup ROOMS_COMMANDS
  324. struct SetRoomLockState_Func : public RoomsPluginFunc {
  325. // Input parameters
  326. RoomLockState roomLockState;
  327. // Output parameters
  328. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  329. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  330. };
  331. /// \brief Gets the lock state of the room
  332. /// \ingroup ROOMS_COMMANDS
  333. struct GetRoomLockState_Func : public RoomsPluginFunc {
  334. // Input parameters
  335. // Output parameters
  336. RoomLockState roomLockState;
  337. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  338. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  339. };
  340. /// \brief If all members have been set to ready using SetReadyStatus_Func, this operation will set allReady to true.
  341. /// \ingroup ROOMS_COMMANDS
  342. struct AreAllMembersReady_Func : public RoomsPluginFunc {
  343. // Input parameters
  344. // Output parameters
  345. bool allReady;
  346. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  347. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  348. };
  349. /// \brief Kick a member out of the room. This will also automatically ban that member from rejoining as long as the moderator does not change, or the member is unbanned
  350. /// \ingroup ROOMS_COMMANDS
  351. struct KickMember_Func : public RoomsPluginFunc {
  352. // Input parameters
  353. RakNet::RakString kickedMember;
  354. RakNet::RakString reason;
  355. // Output parameters
  356. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  357. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  358. };
  359. /// \brief Allow a member previously kicked out of the room to rejoin.
  360. /// \ingroup ROOMS_COMMANDS
  361. struct UnbanMember_Func : public RoomsPluginFunc {
  362. // Input parameters
  363. RakNet::RakString bannedMemberName;
  364. // Output parameters
  365. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  366. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  367. };
  368. /// \brief For a given room, get the \a reason parameter of KickMember_Func when we were kicked out.
  369. /// \ingroup ROOMS_COMMANDS
  370. struct GetBanReason_Func : public RoomsPluginFunc {
  371. // Input parameters
  372. RoomID roomId;
  373. // Output parameters
  374. RakNet::RakString reason;
  375. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  376. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  377. };
  378. /// \brief Enter quick join mode
  379. /// \details Quick join mode will wait until the specified timeout to try to automatically join a room each second.<BR>
  380. /// A room will only be joined if enough quick join members can join at once to fill all playable slots in the room.<BR>
  381. /// Older rooms are given priority to quick join.<BR>
  382. /// If no rooms are available to join, but enough quick join members are present to create a room instead, this will be done. The room custom properties will be any equality comparisons with networkedQuickJoinUser.query
  383. /// \ingroup ROOMS_COMMANDS
  384. struct AddUserToQuickJoin_Func : public RoomsPluginFunc {
  385. // Input parameters
  386. NetworkedQuickJoinUser networkedQuickJoinUser;
  387. GameIdentifier gameIdentifier;
  388. // Output parameters
  389. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  390. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  391. };
  392. /// \brief Leave quick join mode
  393. /// \ingroup ROOMS_COMMANDS
  394. struct RemoveUserFromQuickJoin_Func : public RoomsPluginFunc {
  395. // Input parameters
  396. // Output parameters
  397. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  398. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  399. };
  400. /// \brief Returns if you are waiting in quick join mode
  401. /// \ingroup ROOMS_COMMANDS
  402. struct IsInQuickJoin_Func : public RoomsPluginFunc {
  403. // Input parameters
  404. // Output parameters
  405. bool isInQuickJoin;
  406. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  407. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  408. };
  409. /// \brief Return all rooms that pass the \a roomQuery filter
  410. /// \details Use onlyJoinable to further filter by rooms that you can join (not locked, not banned, public or invited slots)
  411. /// \ingroup ROOMS_COMMANDS
  412. struct SearchByFilter_Func : public RoomsPluginFunc {
  413. SearchByFilter_Func() {}
  414. ~SearchByFilter_Func();
  415. // Input parameters
  416. GameIdentifier gameIdentifier;
  417. RoomQuery roomQuery;
  418. bool onlyJoinable;
  419. // Output parameters
  420. DataStructures::List<RoomDescriptor*> roomsOutput;
  421. void PrintResult(void)
  422. {
  423. if (resultCode!=REC_SUCCESS)
  424. {
  425. printf("Result for user %s: %s\n", userName.C_String(), RoomsErrorCodeDescription::ToEnglish(resultCode));
  426. }
  427. else
  428. {
  429. printf("Found %i rooms\n", roomsOutput.Size());
  430. for (unsigned int i=0; i < roomsOutput.Size(); i++)
  431. {
  432. // Default types such as room name are in RoomTypes.cpp see defaultRoomColumns
  433. // Also can be user defined
  434. printf("%i. %s\n", i+1,roomsOutput[i]->GetProperty(DefaultRoomColumns::TC_ROOM_NAME)->c);
  435. }
  436. }
  437. }
  438. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  439. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  440. };
  441. /// \brief Change your handle
  442. /// \ingroup ROOMS_COMMANDS
  443. struct ChangeHandle_Func : public RoomsPluginFunc {
  444. // Input parameters
  445. RakNet::RakString newHandle;
  446. // Output parameters
  447. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  448. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  449. };
  450. /// \brief Send a chat message
  451. /// \ingroup ROOMS_COMMANDS
  452. struct Chat_Func : public RoomsPluginFunc {
  453. // Input parameters
  454. RakNet::RakString chatMessage;
  455. // Leave recipient blank for all in room
  456. RakNet::RakString privateMessageRecipient;
  457. /// If true, only sends the chat message if the user is in the same room.
  458. /// If false, privateMessageRecipient must also be filled out
  459. bool chatDirectedToRoom;
  460. // Output parameters
  461. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  462. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  463. };
  464. /// \brief Send an arbitrary binary message
  465. /// \ingroup ROOMS_COMMANDS
  466. struct Bitstream_Func : public RoomsPluginFunc {
  467. // Input parameters
  468. RakNet::BitStream bsToSend;
  469. // Leave recipient blank for all in room
  470. RakNet::RakString privateMessageRecipient;
  471. /// If true, only sends the bitstream if the user is in the same room.
  472. /// If false, privateMessageRecipient must also be filled out
  473. bool directedToRoom;
  474. // Output parameters
  475. virtual void SerializeIn(bool writeToBitstream, RakNet::BitStream *bitStream);
  476. virtual void SerializeOut(bool writeToBitstream, RakNet::BitStream *bitStream);
  477. };
  478. /// \brief Base class for notification callbacks
  479. /// \ingroup ROOMS_GROUP
  480. struct RoomsPluginNotification {
  481. virtual ~RoomsPluginNotification() {}
  482. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream)=0;
  483. virtual void PrintResult(void)=0;
  484. /// Always filled out so you know which user this callback applies to
  485. RakNet::RakString recipient;
  486. };
  487. /// \brief The quick join duration has expired without joining or creating any rooms
  488. /// \ingroup ROOMS_NOTIFICATIONS
  489. struct QuickJoinExpired_Notification : public RoomsPluginNotification {
  490. NetworkedQuickJoinUser networkedQuickJoinUser;
  491. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  492. virtual void PrintResult(void) {printf("QuickJoinExpired_Notification to %s\n", recipient.C_String());}
  493. };
  494. /// \brief Quick join succeeded, and you are now in a room
  495. /// \ingroup ROOMS_NOTIFICATIONS
  496. struct QuickJoinEnteredRoom_Notification : public RoomsPluginNotification {
  497. JoinedRoomResult joinedRoomResult;
  498. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  499. virtual void PrintResult(void) {printf("QuickJoinEnteredRoom_Notification to %s. roomId=%i\n", recipient.C_String(), joinedRoomResult.roomDescriptor.lobbyRoomId);}
  500. };
  501. /// \brief Another room member has started spectating
  502. /// \ingroup ROOMS_NOTIFICATIONS
  503. struct RoomMemberStartedSpectating_Notification : public RoomsPluginNotification {
  504. RoomID roomId;
  505. RakNet::RakString userName;
  506. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  507. virtual void PrintResult(void) {printf("RoomMemberStartedSpectating_Notification to %s\n", recipient.C_String());}
  508. };
  509. /// \brief Another room member has stopped spectating
  510. /// \ingroup ROOMS_NOTIFICATIONS
  511. struct RoomMemberStoppedSpectating_Notification : public RoomsPluginNotification {
  512. RakNet::RakString userName;
  513. RoomID roomId;
  514. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  515. virtual void PrintResult(void) {printf("RoomMemberStoppedSpectating_Notification to %s\n", recipient.C_String());}
  516. };
  517. /// \brief The room has a new moderator (possibly you)
  518. /// \ingroup ROOMS_NOTIFICATIONS
  519. struct ModeratorChanged_Notification : public RoomsPluginNotification {
  520. RakNet::RakString newModerator;
  521. RakNet::RakString oldModerator;
  522. RoomID roomId;
  523. virtual void PrintResult(void) {printf("ModeratorChanged_Notification to %s\n", recipient.C_String());}
  524. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  525. };
  526. /// \brief The slot counts in the room has changed
  527. /// \ingroup ROOMS_NOTIFICATIONS
  528. struct SlotCountsSet_Notification : public RoomsPluginNotification {
  529. Slots slots;
  530. RoomID roomId;
  531. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  532. virtual void PrintResult(void) {printf("SlotCountsSet_Notification to %s\n", recipient.C_String());}
  533. };
  534. /// \brief The custom properties for the room has changed
  535. /// \ingroup ROOMS_NOTIFICATIONS
  536. struct CustomRoomPropertiesSet_Notification : public RoomsPluginNotification {
  537. RoomID roomId;
  538. // If tablePtr is set, that will be serialized. Otherwise, table will be serialized.
  539. // Deserialization is written to table
  540. DataStructures::Table *tablePtr;
  541. DataStructures::Table table;
  542. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  543. virtual void PrintResult(void) {printf("CustomRoomPropertiesSet_Notification to %s\n", recipient.C_String());}
  544. };
  545. /// \brief The name of the room has been changed
  546. /// \ingroup ROOMS_NOTIFICATIONS
  547. struct RoomNameSet_Notification : public RoomsPluginNotification {
  548. RoomID roomId;
  549. RakNet::RakString oldName;
  550. RakNet::RakString newName;
  551. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  552. virtual void PrintResult(void) {printf("RoomNameSet_Notification to %s\n", recipient.C_String());}
  553. };
  554. /// \brief The room is now hidden, or no longer hidden, from searches
  555. /// \ingroup ROOMS_NOTIFICATIONS
  556. struct HiddenFromSearchesSet_Notification : public RoomsPluginNotification {
  557. RoomID roomId;
  558. bool hiddenFromSearches;
  559. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  560. virtual void PrintResult(void) {printf("HiddenFromSearchesSet_Notification to %s\n", recipient.C_String());}
  561. };
  562. /// \brief Another room member has changed their ready status
  563. /// \ingroup ROOMS_NOTIFICATIONS
  564. struct RoomMemberReadyStatusSet_Notification : public RoomsPluginNotification {
  565. RoomID roomId;
  566. bool isReady;
  567. RakNet::RakString roomMember;
  568. // Current status of all room members
  569. DataStructures::List<RakNet::RakString> readyUsers;
  570. DataStructures::List<RakNet::RakString> unreadyUsers;
  571. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  572. virtual void PrintResult(void) {printf("RoomMemberReadyStatusSet_Notification to %s\n", recipient.C_String());}
  573. };
  574. /// \brief The room is now, or is no longer, locked
  575. /// \ingroup ROOMS_NOTIFICATIONS
  576. struct RoomLockStateSet_Notification : public RoomsPluginNotification {
  577. RoomID roomId;
  578. RoomLockState roomLockState;
  579. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  580. virtual void PrintResult(void) {printf("RoomLockStateSet_Notification to %s\n", recipient.C_String());}
  581. };
  582. /// \brief A room member has been kicked out of the room (possibly you)
  583. /// \ingroup ROOMS_NOTIFICATIONS
  584. struct RoomMemberKicked_Notification : public RoomsPluginNotification {
  585. RoomID roomId;
  586. RakNet::RakString kickedMember;
  587. RakNet::RakString moderator;
  588. RakNet::RakString reason;
  589. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  590. virtual void PrintResult(void) {printf("RoomMemberKicked_Notification to %s\n", recipient.C_String());}
  591. };
  592. /// \brief A room member has changed their handle
  593. /// \ingroup ROOMS_NOTIFICATIONS
  594. struct RoomMemberHandleSet_Notification : public RoomsPluginNotification {
  595. RoomID roomId;
  596. RakNet::RakString oldName;
  597. RakNet::RakString newName;
  598. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  599. virtual void PrintResult(void) {printf("RoomMemberHandleSet_Notification to %s\n", recipient.C_String());}
  600. };
  601. /// A room member has left the room
  602. /// \ingroup ROOMS_NOTIFICATIONS
  603. struct RoomMemberLeftRoom_Notification : public RoomsPluginNotification {
  604. RoomID roomId;
  605. RakNet::RakString roomMember;
  606. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  607. virtual void PrintResult(void) {printf("RoomMemberLeftRoom_Notification to %s\n", recipient.C_String());}
  608. };
  609. /// \brief A room member has joined the room
  610. /// \ingroup ROOMS_NOTIFICATIONS
  611. struct RoomMemberJoinedRoom_Notification : public RoomsPluginNotification {
  612. RoomMemberJoinedRoom_Notification() {joinedRoomResult=0;}
  613. ~RoomMemberJoinedRoom_Notification() {if (joinedRoomResult!=0) RakNet::OP_DELETE(joinedRoomResult, _FILE_AND_LINE_);}
  614. RoomID roomId;
  615. JoinedRoomResult *joinedRoomResult;
  616. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  617. virtual void PrintResult(void)
  618. {
  619. printf("RoomMemberJoinedRoom_Notification to %s: %s (%s) has joined the room.\n", recipient.C_String(), joinedRoomResult->joiningMemberName.C_String(), joinedRoomResult->joiningMemberAddress.ToString());
  620. }
  621. };
  622. /// \brief You have received an invitation to a room
  623. /// \ingroup ROOMS_NOTIFICATIONS
  624. struct RoomInvitationSent_Notification : public RoomsPluginNotification {
  625. RakNet::RakString invitorName;
  626. RakNet::RakString inviteeName;
  627. bool inviteToSpectatorSlot;
  628. RakNet::RakString subject;
  629. RakNet::RakString body;
  630. RoomID roomId;
  631. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  632. virtual void PrintResult(void) {printf("RoomInvitationSent_Notification to %s\n", recipient.C_String());}
  633. };
  634. /// \brief A previous room invitation is no longer valid (possibly due to moderator change, or the room no longer exists)
  635. /// \ingroup ROOMS_NOTIFICATIONS
  636. struct RoomInvitationWithdrawn_Notification : public RoomsPluginNotification {
  637. InvitedUser invitedUser;
  638. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  639. virtual void PrintResult(void) {printf("RoomInvitationWithdrawn_Notification to %s\n", recipient.C_String());}
  640. };
  641. /// \brief The moderator has left the room, and everyone left is a spectator, or the room was set to be destroyed when the moderator left
  642. /// \ingroup ROOMS_NOTIFICATIONS
  643. /// You are no longer in the room
  644. struct RoomDestroyedOnModeratorLeft_Notification : public RoomsPluginNotification {
  645. RakNet::RakString oldModerator;
  646. RoomID roomId;
  647. RoomDescriptor roomDescriptor;
  648. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  649. virtual void PrintResult(void) {printf("RoomDestroyedOnModeratorLeft_Notification to %s\n", recipient.C_String());}
  650. };
  651. /// \brief You got a chat message from another user.
  652. /// \details If you want to support ignoring chat messages from specific users, use Lobby2Client_PC::IsInIgnoreList
  653. /// \ingroup ROOMS_NOTIFICATIONS
  654. struct Chat_Notification : public RoomsPluginNotification {
  655. RakNet::RakString sender;
  656. // If filled in, this was directed to you. Otherwise it was directed to the room
  657. RakNet::RakString privateMessageRecipient;
  658. // The chat message
  659. RakNet::RakString chatMessage;
  660. // The chat message with profanity filtered, if you want that instead
  661. RakNet::RakString filteredChatMessage;
  662. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  663. virtual void PrintResult(void) {printf("Chat_Notification to %s\n", recipient.C_String());}
  664. };
  665. /// \brief You got a generic bitstream message from another user.
  666. /// \ingroup ROOMS_NOTIFICATIONS
  667. struct Bitstream_Notification : public RoomsPluginNotification {
  668. RakNet::RakString sender;
  669. // If filled in, this was directed to you. Otherwise it was directed to the room
  670. RakNet::RakString privateMessageRecipient;
  671. // The chat message
  672. RakNet::BitStream bitStreamReceived;
  673. virtual void Serialize(bool writeToBitstream, RakNet::BitStream *bitStream);
  674. virtual void PrintResult(void) {printf("Bitstream_Notification to %s\n", recipient.C_String());}
  675. };
  676. /// \ingroup ROOMS_GROUP
  677. struct RoomsCallback
  678. {
  679. // Results of calls
  680. RoomsCallback() {}
  681. virtual ~RoomsCallback() {}
  682. virtual void CreateRoom_Callback( const SystemAddress &senderAddress, CreateRoom_Func *callResult) {(void) senderAddress; (void) callResult;}
  683. virtual void EnterRoom_Callback( const SystemAddress &senderAddress, EnterRoom_Func *callResult) {(void) senderAddress; (void) callResult;}
  684. virtual void JoinByFilter_Callback( const SystemAddress &senderAddress, JoinByFilter_Func *callResult) {(void) senderAddress; (void) callResult;}
  685. virtual void LeaveRoom_Callback( const SystemAddress &senderAddress, LeaveRoom_Func *callResult) {(void) senderAddress; (void) callResult;}
  686. virtual void GetInvitesToParticipant_Callback( const SystemAddress &senderAddress, GetInvitesToParticipant_Func *callResult) {(void) senderAddress; (void) callResult;}
  687. virtual void SendInvite_Callback( const SystemAddress &senderAddress, SendInvite_Func *callResult) {(void) senderAddress; (void) callResult;}
  688. virtual void AcceptInvite_Callback( const SystemAddress &senderAddress, AcceptInvite_Func *callResult) {(void) senderAddress; (void) callResult;}
  689. virtual void StartSpectating_Callback( const SystemAddress &senderAddress, StartSpectating_Func *callResult) {(void) senderAddress; (void) callResult;}
  690. virtual void StopSpectating_Callback( const SystemAddress &senderAddress, StopSpectating_Func *callResult) {(void) senderAddress; (void) callResult;}
  691. virtual void GrantModerator_Callback( const SystemAddress &senderAddress, GrantModerator_Func *callResult) {(void) senderAddress; (void) callResult;}
  692. virtual void ChangeSlotCounts_Callback( const SystemAddress &senderAddress, ChangeSlotCounts_Func *callResult) {(void) senderAddress; (void) callResult;}
  693. virtual void SetCustomRoomProperties_Callback( const SystemAddress &senderAddress, SetCustomRoomProperties_Func *callResult) {(void) senderAddress; (void) callResult;}
  694. virtual void GetRoomProperties_Callback( const SystemAddress &senderAddress, GetRoomProperties_Func *callResult) {(void) senderAddress; (void) callResult;}
  695. virtual void ChangeRoomName_Callback( const SystemAddress &senderAddress, ChangeRoomName_Func *callResult) {(void) senderAddress; (void) callResult;}
  696. virtual void SetHiddenFromSearches_Callback( const SystemAddress &senderAddress, SetHiddenFromSearches_Func *callResult) {(void) senderAddress; (void) callResult;}
  697. virtual void SetDestroyOnModeratorLeave_Callback( const SystemAddress &senderAddress, SetDestroyOnModeratorLeave_Func *callResult) {(void) senderAddress; (void) callResult;}
  698. virtual void SetReadyStatus_Callback( const SystemAddress &senderAddress, SetReadyStatus_Func *callResult) {(void) senderAddress; (void) callResult;}
  699. virtual void GetReadyStatus_Callback( const SystemAddress &senderAddress, GetReadyStatus_Func *callResult) {(void) senderAddress; (void) callResult;}
  700. virtual void SetRoomLockState_Callback( const SystemAddress &senderAddress, SetRoomLockState_Func *callResult) {(void) senderAddress; (void) callResult;}
  701. virtual void GetRoomLockState_Callback( const SystemAddress &senderAddress, GetRoomLockState_Func *callResult) {(void) senderAddress; (void) callResult;}
  702. virtual void AreAllMembersReady_Callback( const SystemAddress &senderAddress, AreAllMembersReady_Func *callResult) {(void) senderAddress; (void) callResult;}
  703. virtual void KickMember_Callback( const SystemAddress &senderAddress, KickMember_Func *callResult) {(void) senderAddress; (void) callResult;}
  704. virtual void UnbanMember_Callback( const SystemAddress &senderAddress, UnbanMember_Func *callResult) {(void) senderAddress; (void) callResult;}
  705. virtual void GetBanReason_Callback( const SystemAddress &senderAddress, GetBanReason_Func *callResult) {(void) senderAddress; (void) callResult;}
  706. virtual void AddUserToQuickJoin_Callback( const SystemAddress &senderAddress, AddUserToQuickJoin_Func *callResult) {(void) senderAddress; (void) callResult;}
  707. virtual void RemoveUserFromQuickJoin_Callback( const SystemAddress &senderAddress, RemoveUserFromQuickJoin_Func *callResult) {(void) senderAddress; (void) callResult;}
  708. virtual void IsInQuickJoin_Callback( const SystemAddress &senderAddress, IsInQuickJoin_Func *callResult) {(void) senderAddress; (void) callResult;}
  709. virtual void SearchByFilter_Callback( const SystemAddress &senderAddress, SearchByFilter_Func *callResult) {(void) senderAddress; (void) callResult;}
  710. virtual void ChangeHandle_Callback( const SystemAddress &senderAddress, ChangeHandle_Func *callResult) {(void) senderAddress; (void) callResult;}
  711. virtual void Chat_Callback( const SystemAddress &senderAddress, Chat_Func *callResult) {(void) senderAddress; (void) callResult;}
  712. virtual void Bitstream_Callback( const SystemAddress &senderAddress, Bitstream_Func *callResult) {(void) senderAddress; (void) callResult;}
  713. // Notifications due to other room members
  714. virtual void QuickJoinExpired_Callback( const SystemAddress &senderAddress, QuickJoinExpired_Notification *notification) {(void) senderAddress; (void) notification;}
  715. virtual void QuickJoinEnteredRoom_Callback( const SystemAddress &senderAddress, QuickJoinEnteredRoom_Notification *notification) {(void) senderAddress; (void) notification;}
  716. virtual void RoomMemberStartedSpectating_Callback( const SystemAddress &senderAddress, RoomMemberStartedSpectating_Notification *notification) {(void) senderAddress; (void) notification;}
  717. virtual void RoomMemberStoppedSpectating_Callback( const SystemAddress &senderAddress, RoomMemberStoppedSpectating_Notification *notification) {(void) senderAddress; (void) notification;}
  718. virtual void ModeratorChanged_Callback( const SystemAddress &senderAddress, ModeratorChanged_Notification *notification) {(void) senderAddress; (void) notification;}
  719. virtual void SlotCountsSet_Callback( const SystemAddress &senderAddress, SlotCountsSet_Notification *notification) {(void) senderAddress; (void) notification;}
  720. virtual void CustomRoomPropertiesSet_Callback( const SystemAddress &senderAddress, CustomRoomPropertiesSet_Notification *notification) {(void) senderAddress; (void) notification;}
  721. virtual void RoomNameSet_Callback( const SystemAddress &senderAddress, RoomNameSet_Notification *notification) {(void) senderAddress; (void) notification;}
  722. virtual void HiddenFromSearchesSet_Callback( const SystemAddress &senderAddress, HiddenFromSearchesSet_Notification *notification) {(void) senderAddress; (void) notification;}
  723. virtual void RoomMemberReadyStatusSet_Callback( const SystemAddress &senderAddress, RoomMemberReadyStatusSet_Notification *notification) {(void) senderAddress; (void) notification;}
  724. virtual void RoomLockStateSet_Callback( const SystemAddress &senderAddress, RoomLockStateSet_Notification *notification) {(void) senderAddress; (void) notification;}
  725. virtual void RoomMemberKicked_Callback( const SystemAddress &senderAddress, RoomMemberKicked_Notification *notification) {(void) senderAddress; (void) notification;}
  726. virtual void RoomMemberHandleSet_Callback( const SystemAddress &senderAddress, RoomMemberHandleSet_Notification *notification) {(void) senderAddress; (void) notification;}
  727. virtual void RoomMemberLeftRoom_Callback( const SystemAddress &senderAddress, RoomMemberLeftRoom_Notification *notification) {(void) senderAddress; (void) notification;}
  728. virtual void RoomMemberJoinedRoom_Callback( const SystemAddress &senderAddress, RoomMemberJoinedRoom_Notification *notification) {(void) senderAddress; (void) notification;}
  729. virtual void RoomInvitationSent_Callback( const SystemAddress &senderAddress, RoomInvitationSent_Notification *notification) {(void) senderAddress; (void) notification;}
  730. virtual void RoomInvitationWithdrawn_Callback( const SystemAddress &senderAddress, RoomInvitationWithdrawn_Notification *notification) {(void) senderAddress; (void) notification;}
  731. virtual void RoomDestroyedOnModeratorLeft_Callback( const SystemAddress &senderAddress, RoomDestroyedOnModeratorLeft_Notification *notification) {(void) senderAddress; (void) notification;}
  732. virtual void Chat_Callback( const SystemAddress &senderAddress, Chat_Notification *notification) {(void) senderAddress; (void) notification;}
  733. virtual void Bitstream_Callback( const SystemAddress &senderAddress, Bitstream_Notification *notification) {(void) senderAddress; (void) notification;}
  734. };
  735. /// \brief Used to create rooms for players where they can matchmake
  736. /// \details A room is similar to the rooms you see in other lobby systems, where groups of players can join together in order to start a game match<BR>
  737. /// Each player can be in at most one room.<BR>
  738. /// Each player name must be unique.<BR>
  739. /// Each room has one moderator, which can perform operations on the room such as kicking out members.<BR>
  740. /// This plugin networks the AllGamesRoomsContainer class, which performs the actual functionality.<BR>
  741. /// <BR>
  742. /// To use as a client:<BR>
  743. /// <OL>
  744. /// <LI>Connect to the server and attach the plugin as normal.
  745. /// <LI>Call SetServerAddress to tell the system where the server is.
  746. /// <LI>Call RoomsPlugin::SetRoomsCallback() with a pointer to a callback structure
  747. /// <LI>Fill in the input parameters of the desired structure(s)
  748. /// <LI>Call RoomsPlugin::ExecuteFunc with a pointer to the structure.
  749. /// <LI>Process the callback, which will contain the original input parameters, plus the new output parameters. All structures contain resultCode, which indicates if the operation was successful (REC_SUCCESS) or not (Anything else)
  750. /// </OL>
  751. /// <BR>
  752. /// To use as a server:
  753. /// <OL>
  754. /// <LI>Start RakNet as usual, accepting connections and attaching the plugin
  755. /// <LI>Call RoomsPlugin::SetProfanityFilter() with the ProfanityFilter class, if desired
  756. /// <LI>Call RoomsPlugin::AddTitle() for each title (game) you want to support
  757. /// <LI>If you want other systems to be able to call RoomsPlugin::LoginRoomsParticipant(), call RoomsPlugin::AddLoginServerAddress() with the addresses of those systems
  758. /// <LI>As users go online, call RoomsPlugin::LoginRoomsParticipant(). Login and Logoff is up to you to implement (or rely on other systems, such as Lobby2)
  759. /// <LI>As users go offline, call RoomsPlugin::LogoffRoomsParticipant();
  760. /// </OL>
  761. /// \sa AllGamesRoomsContainer
  762. /// \sa TeamManager TeamManager performs some of the same functions as RoomsPlugin in a more flexible way
  763. /// \sa
  764. /// \ingroup ROOMS_GROUP
  765. class RAK_DLL_EXPORT RoomsPlugin : public PluginInterface2, public RoomsCallback
  766. {
  767. public:
  768. RoomsPlugin();
  769. virtual ~RoomsPlugin();
  770. /// \brief Ordering channel to send messages on
  771. /// \param[in] oc The ordering channel
  772. void SetOrderingChannel(char oc);
  773. /// \brief Send priority to send messages on
  774. /// \param[in] pp The packet priority
  775. void SetSendPriority(PacketPriority pp);
  776. // --------------------------------------------------------------------------------------------
  777. // Client room functions. Will transmit the command to the server specified with SetServerAddress();
  778. // --------------------------------------------------------------------------------------------
  779. /// \brief Set the callback to get notification and ExecuteFunc() results
  780. /// \param[in] _roomsCallback Class instance to get callbacks on. Should remain a valid pointer for the duration of the plugin execution.
  781. void SetRoomsCallback(RoomsCallback *_roomsCallback);
  782. /// \brief Add a callback to get notification and ExecuteFunc() results
  783. /// \param[in] _roomsCallback Class instance to get callbacks on. Should remain a valid pointer for the duration of the plugin execution.
  784. void AddRoomsCallback(RoomsCallback *_roomsCallback);
  785. /// \brief Remove a callback to get notification and ExecuteFunc() results
  786. /// \param[in] _roomsCallback Class instance to no longer get callbacks on.
  787. void RemoveRoomsCallback(RoomsCallback *_roomsCallback);
  788. /// \brief Execute a function, using the system address passed to SetServerAddress();
  789. /// \param[in] func Pointer to a base class of RoomsPluginFunc to execute
  790. void ExecuteFunc(RoomsPluginFunc *func);
  791. /// \brief Execute a function, with a specific address
  792. /// \param[in] func Pointer to a base class of RoomsPluginFunc to execute
  793. /// \param[in] remoteAddress Address to send the command to. The remote system should also be running RoomsPlugin
  794. void ExecuteFunc(RoomsPluginFunc *func, SystemAddress remoteAddress);
  795. /// \brief Sets the remote server address that is running RoomsPlugin. Send calls will go to this function
  796. /// \param[in] systemAddress The remote system, which should be connected while calling client functions
  797. void SetServerAddress( SystemAddress systemAddress );
  798. // --------------------------------------------------------------------------------------------
  799. // Server functions.
  800. // --------------------------------------------------------------------------------------------
  801. /// \brief Add a participant to the system
  802. /// \details Only participants can perform operations
  803. /// \param[in] userName A unique string identifying the user
  804. /// \param[in] roomsParticipantAddress The address of the user
  805. /// \param[in] guid The guid of the user
  806. /// \param[in] loginServerAddress The server adding this user. Use RakNet::UNASSIGNED_SYSTEM_ADDRESS for not applicable. Otherwise, the address must previously have been added using AddLoginServerAddress() or the function will fail.
  807. bool LoginRoomsParticipant(RakNet::RakString userName, SystemAddress roomsParticipantAddress, RakNetGUID guid, SystemAddress loginServerAddress);
  808. /// \brief Removes a participant from the system
  809. /// \param[in] userName A unique string identifying the user
  810. /// \param[in] loginServerAddress The server removing. Use RakNet::UNASSIGNED_SYSTEM_ADDRESS for not applicable. Otherwise, the address must previously have been added using AddLoginServerAddress() or the function will fail.
  811. bool LogoffRoomsParticipant(RakNet::RakString userName, SystemAddress loginServerAddress);
  812. /// \brief Clear all users
  813. void ClearRoomMembers();
  814. /// \brief Used for Lobby2. Serializes the same data that the plugin itself uses to login
  815. /// \internal
  816. static void SerializeLogin(RakNet::RakString userName, SystemAddress userAddress, RakNetGUID guid, RakNet::BitStream *bs);
  817. /// \brief Used for Lobby2. Serializes the same data that the plugin itself uses to logoff
  818. /// \internal
  819. static void SerializeLogoff(RakNet::RakString userName, RakNet::BitStream *bs);
  820. /// \brief Used for Lobby2. Serializes the same data that the plugin itself uses to change handles
  821. /// \internal
  822. static void SerializeChangeHandle(RakNet::RakString oldHandle, RakNet::RakString newHandle, RakNet::BitStream *bs);
  823. /// \brief Change the handle a user
  824. /// \param[in] oldHandle The handle previously known by the system
  825. /// \param[in] newHandle The new handle to use
  826. void ChangeHandle(RakNet::RakString oldHandle, RakNet::RakString newHandle);
  827. /// \brief Add a SystemAddress to a list that will be checked when LoginRoomsParticipant() and LogoffRoomsParticipant() is called
  828. /// \param[in] systemAddress The address to add
  829. void AddLoginServerAddress(SystemAddress systemAddress);
  830. /// \brief Remove a SystemAddress from a list that will be checked when LoginRoomsParticipant() and LogoffRoomsParticipant() is called
  831. /// \param[in] systemAddress The address to remove
  832. void RemoveLoginServerAddress(SystemAddress systemAddress);
  833. /// \brief Remove all addresses added with AddLoginServerAddress()
  834. void ClearLoginServerAdddresses(void);
  835. /// \brief Sets the profanity filter for the system to use (optional)
  836. /// \details If set, room names and player handles will be checked for profanity.
  837. /// Room invitations and other messages are not checked.
  838. /// \param[in] pf An instance of a profanity filter
  839. void SetProfanityFilter(ProfanityFilter *pf);
  840. /// \brief Only used on the server. Locally perform any desired functions, such as logging off players
  841. /// \note Use AllGamesRoomsContainer::AddTitle() to add titles
  842. AllGamesRoomsContainer roomsContainer;
  843. // --------------------------------------------------------------------------------------------
  844. // Packet handling functions
  845. // --------------------------------------------------------------------------------------------
  846. /// \internal
  847. virtual void OnDetach(void);
  848. /// \internal
  849. virtual void OnShutdown(void);
  850. /// \internal
  851. virtual void Update(void);
  852. /// \internal
  853. virtual PluginReceiveResult OnReceive(Packet *packet);
  854. /// \internal
  855. virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
  856. protected:
  857. void Clear(void);
  858. bool IsServer(void) const;
  859. void OnRoomsExecuteFunc(Packet *packet);
  860. void OnLoginStatus(Packet *packet);
  861. void OnHandleChange(Packet *packet);
  862. // Client and server data
  863. char orderingChannel;
  864. DataStructures::List<RoomsCallback *> roomsCallback;
  865. PacketPriority packetPriority;
  866. ProfanityFilter *profanityFilter;
  867. RakNet::TimeMS lastUpdateTime;
  868. // Client data
  869. SystemAddress serverAddress;
  870. // Server data
  871. // Servers that can remotely trigger LoginRoomMember and LogoffRoomMember
  872. DataStructures::List<SystemAddress> loginServers;
  873. // Logged in room members
  874. struct RoomsPluginParticipant : public RoomsParticipant
  875. {
  876. RoomsPluginParticipant() {lastRoomJoined=(RoomID)-1;}
  877. RoomID lastRoomJoined;
  878. };
  879. static int RoomsPluginParticipantCompByRakString( const RakNet::RakString &key, RoomsPluginParticipant* const &data );
  880. DataStructures::OrderedList<RakNet::RakString, RoomsPluginParticipant*, RoomsPluginParticipantCompByRakString> roomsParticipants;
  881. RoomsPluginParticipant* GetParticipantByHandle(RakNet::RakString handle, const SystemAddress &systemAddress);
  882. RoomsPluginParticipant* ValidateUserHandle(RoomsPluginFunc* func, const SystemAddress &systemAddress);
  883. void ProcessRemoveUserResult(RemoveUserResult *removeUserResult);
  884. virtual void CreateRoom_Callback( const SystemAddress &senderAddress, CreateRoom_Func *callResult);
  885. virtual void EnterRoom_Callback( const SystemAddress &senderAddress, EnterRoom_Func *callResult);
  886. virtual void JoinByFilter_Callback( const SystemAddress &senderAddress, JoinByFilter_Func *callResult);
  887. virtual void LeaveRoom_Callback( const SystemAddress &senderAddress, LeaveRoom_Func *callResult);
  888. virtual void GetInvitesToParticipant_Callback( const SystemAddress &senderAddress, GetInvitesToParticipant_Func *callResult);
  889. virtual void SendInvite_Callback( const SystemAddress &senderAddress, SendInvite_Func *callResult);
  890. virtual void AcceptInvite_Callback( const SystemAddress &senderAddress, AcceptInvite_Func *callResult);
  891. virtual void StartSpectating_Callback( const SystemAddress &senderAddress, StartSpectating_Func *callResult);
  892. virtual void StopSpectating_Callback( const SystemAddress &senderAddress, StopSpectating_Func *callResult);
  893. virtual void GrantModerator_Callback( const SystemAddress &senderAddress, GrantModerator_Func *callResult);
  894. virtual void ChangeSlotCounts_Callback( const SystemAddress &senderAddress, ChangeSlotCounts_Func *callResult);
  895. virtual void SetCustomRoomProperties_Callback( const SystemAddress &senderAddress, SetCustomRoomProperties_Func *callResult);
  896. virtual void GetRoomProperties_Callback( const SystemAddress &senderAddress, GetRoomProperties_Func *callResult);
  897. virtual void ChangeRoomName_Callback( const SystemAddress &senderAddress, ChangeRoomName_Func *callResult);
  898. virtual void SetHiddenFromSearches_Callback( const SystemAddress &senderAddress, SetHiddenFromSearches_Func *callResult);
  899. virtual void SetDestroyOnModeratorLeave_Callback( const SystemAddress &senderAddress, SetDestroyOnModeratorLeave_Func *callResult);
  900. virtual void SetReadyStatus_Callback( const SystemAddress &senderAddress, SetReadyStatus_Func *callResult);
  901. virtual void GetReadyStatus_Callback( const SystemAddress &senderAddress, GetReadyStatus_Func *callResult);
  902. virtual void SetRoomLockState_Callback( const SystemAddress &senderAddress, SetRoomLockState_Func *callResult);
  903. virtual void GetRoomLockState_Callback( const SystemAddress &senderAddress, GetRoomLockState_Func *callResult);
  904. virtual void AreAllMembersReady_Callback( const SystemAddress &senderAddress, AreAllMembersReady_Func *callResult);
  905. virtual void KickMember_Callback( const SystemAddress &senderAddress, KickMember_Func *callResult);
  906. virtual void UnbanMember_Callback( const SystemAddress &senderAddress, UnbanMember_Func *callResult);
  907. virtual void GetBanReason_Callback( const SystemAddress &senderAddress, GetBanReason_Func *callResult);
  908. virtual void AddUserToQuickJoin_Callback( const SystemAddress &senderAddress, AddUserToQuickJoin_Func *callResult);
  909. virtual void RemoveUserFromQuickJoin_Callback( const SystemAddress &senderAddress, RemoveUserFromQuickJoin_Func *callResult);
  910. virtual void IsInQuickJoin_Callback( const SystemAddress &senderAddress, IsInQuickJoin_Func *callResult);
  911. virtual void SearchByFilter_Callback( const SystemAddress &senderAddress, SearchByFilter_Func *callResult);
  912. virtual void ChangeHandle_Callback( const SystemAddress &senderAddress, ChangeHandle_Func *callResult);
  913. virtual void Chat_Callback( const SystemAddress &senderAddress, Chat_Func *callResult);
  914. virtual void Bitstream_Callback( const SystemAddress &senderAddress, Bitstream_Func *callResult);
  915. void ExecuteNotification(RoomsPluginNotification *func, RoomsPluginParticipant *recipient);
  916. void ExecuteNotificationToOtherRoomMembers(Room *room, RoomsPluginParticipant* roomsPluginParticipant, RoomsPluginNotification *notification);
  917. };
  918. /// \ingroup ROOMS_GROUP
  919. enum RoomsPluginOperations
  920. {
  921. RPO_CREATE_ROOM,
  922. RPO_ENTER_ROOM,
  923. RPO_JOIN_BY_FILTER,
  924. RPO_LEAVE_ROOM,
  925. RPO_GET_INVITES_TO_PARTICIPANT,
  926. RPO_SEND_INVITE,
  927. RPO_ACCEPT_INVITE,
  928. RPO_START_SPECTATING,
  929. RPO_STOP_SPECTATING,
  930. RPO_GRANT_MODERATOR,
  931. RPO_CHANGE_SLOT_COUNTS,
  932. RPO_SET_CUSTOM_ROOM_PROPERTIES,
  933. RPO_GET_ROOM_PROPERTIES,
  934. RPO_CHANGE_ROOM_NAME,
  935. RPO_SET_HIDDEN_FROM_SEARCHES,
  936. RPO_SET_DESTROY_ON_MODERATOR_LEAVE,
  937. RPO_SET_READY_STATUS,
  938. RPO_GET_READY_STATUS,
  939. RPO_SET_ROOM_LOCK_STATE,
  940. RPO_GET_ROOM_LOCK_STATE,
  941. RPO_ARE_ALL_MEMBERS_READY,
  942. RPO_KICK_MEMBER,
  943. RPO_UNBAN_MEMBER,
  944. RPO_GET_BAN_REASON,
  945. RPO_ADD_USER_TO_QUICK_JOIN,
  946. RPO_REMOVE_USER_FROM_QUICK_JOIN,
  947. RPO_IS_IN_QUICK_JOIN,
  948. RPO_SEARCH_BY_FILTER,
  949. RPO_CHANGE_HANDLE,
  950. RPO_CHAT,
  951. RPO_BITSTREAM,
  952. RPN_QUICK_JOIN_EXPIRED,
  953. RPN_QUICK_JOIN_ENTERED_ROOM,
  954. RPN_ROOM_MEMBER_STARTED_SPECTATING,
  955. RPN_ROOM_MEMBER_STOPPED_SPECTATING,
  956. RPN_MODERATOR_CHANGED,
  957. RPN_SLOT_COUNTS_SET,
  958. RPN_CUSTOM_ROOM_PROPERTIES_SET,
  959. RPN_ROOM_NAME_SET,
  960. RPN_HIDDEN_FROM_SEARCHES_SET,
  961. RPN_ROOM_MEMBER_READY_STATUS_SET,
  962. RPN_ROOM_LOCK_STATE_SET,
  963. RPN_ROOM_MEMBER_KICKED,
  964. RPN_ROOM_MEMBER_HANDLE_SET,
  965. RPN_ROOM_MEMBER_LEFT_ROOM,
  966. RPN_ROOM_MEMBER_JOINED_ROOM,
  967. RPN_ROOM_INVITATION_SENT,
  968. RPN_ROOM_INVITATION_WITHDRAWN,
  969. RPN_ROOM_DESTROYED_ON_MODERATOR_LEFT,
  970. RPN_CHAT_NOTIFICATION,
  971. RPN_BITSTREAM_NOTIFICATION,
  972. };
  973. } // namespace RakNet
  974. #endif
粤ICP备19079148号