the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 582 lines 23 kB view raw
1#pragma once 2 3#include "DQRNetworkPlayer.h" 4#include "..\Minecraft.World\C4JThread.h" 5#include <collection.h> 6 7class IDQRNetworkManagerListener; 8class PartyController; 9 10class DQRNetworkManager; 11class ChatIntegrationLayer; 12 13namespace MXS = Microsoft::Xbox::Services; 14namespace MXSM = Microsoft::Xbox::Services::Multiplayer; 15namespace MXSS = Microsoft::Xbox::Services::Social; 16namespace WXM = Windows::Xbox::Multiplayer; 17namespace WXN = Windows::Xbox::Networking; 18namespace WXNRs = Windows::Xbox::Networking::RealtimeSession; 19namespace WFC = Windows::Foundation::Collections; 20 21#define MATCH_SESSION_TEMPLATE_NAME L"PeerToHostTemplate" 22#define MAX_PLAYERS_IN_TEMPLATE 8 23 24using namespace std; 25 26ref class DQRNetworkManagerEventHandlers sealed 27{ 28internal: 29 DQRNetworkManagerEventHandlers(DQRNetworkManager *pDQRNet); 30public: 31 void Setup(WXNRs::Session^ session); 32 void Pulldown(WXNRs::Session^ session); 33 34 void DataReceivedHandler(Platform::Object^ session, WXNRs::DataReceivedEventArgs^ args); 35 void SessionAddressDataChangedHandler(Platform::Object^ session, WXNRs::SessionAddressDataChangedEventArgs^ args); 36 void SessionStatusUpdateHandler(Platform::Object^ session, WXNRs::SessionStatusUpdateEventArgs^ args); 37 void AddedSessionAddressHandler(Platform::Object^ session, WXNRs::AddedSessionAddressEventArgs^ args); 38 void RemovedSessionAddressHandler(Platform::Object^ session, WXNRs::RemovedSessionAddressEventArgs^ args); 39 void GlobalSessionDataChangedHandler(Platform::Object^ session, WXNRs::GlobalSessionDataChangedEventArgs^ args); 40 41private: 42 Windows::Foundation::EventRegistrationToken m_dataReceivedToken; 43 Windows::Foundation::EventRegistrationToken m_sessionStatusToken; 44 Windows::Foundation::EventRegistrationToken m_sessionAddressToken; 45 Windows::Foundation::EventRegistrationToken m_addedSessionToken; 46 Windows::Foundation::EventRegistrationToken m_removedSessionToken; 47 Windows::Foundation::EventRegistrationToken m_globalDataToken; 48 49 DQRNetworkManager *m_pDQRNet; 50}; 51 52typedef enum 53{ 54 DQR_INTERNAL_ASSIGN_SMALL_IDS, 55 DQR_INTERNAL_UNASSIGN_SMALL_ID, 56 DQR_INTERNAL_PLAYER_TABLE, 57 DQR_INTERNAL_ADD_PLAYER_FAILED, 58}; 59 60class DQRConnectionInfo 61{ 62public: 63 typedef enum 64 { 65 ConnectionState_HeaderByte0, 66 ConnectionState_HeaderByte1, 67 ConnectionState_ReadBytes 68 } eDQRConnectionState; 69 70 typedef enum 71 { 72 ConnectionState_InternalHeaderByte, 73 ConnectionState_InternalAssignSmallIdMask, 74 ConnectionState_InternalAssignSmallId0, 75 ConnectionState_InternalAssignSmallId1, 76 ConnectionState_InternalAssignSmallId2, 77 ConnectionState_InternalAssignSmallId3, 78 ConnectionState_InternalRoomSyncData, 79 ConnectionState_InternalAddPlayerFailedData, 80 } eDQRInternalDataState; 81 82 DQRConnectionInfo(); 83 void Reset(); 84 85 eDQRConnectionState m_state; 86 eDQRInternalDataState m_internalDataState; 87 88 int m_currentChannel; 89 bool m_internalFlag; 90 int m_bytesRemaining; 91 int m_roomSyncDataBytesRead; 92 int m_roomSyncDataBytesToRead; 93 unsigned char * m_pucRoomSyncData; 94 int m_addFailedPlayerDataBytesRead; 95 int m_addFailedPlayerDataBytesToRead; 96 unsigned char * m_pucAddFailedPlayerData; 97 unsigned char m_smallId[4]; 98 bool m_channelActive[4]; 99 unsigned char m_smallIdReadMask; 100 unsigned char *m_pucsmallIdReadMaskResolved; 101 bool m_initialPacketReceived; 102}; 103 104 105class DQRNetworkManager 106{ 107 friend class PartyController; 108 friend ref class DQRNetworkManagerEventHandlers; 109 friend class DQRNetworkPlayer; 110 friend class ChatIntegrationLayer; 111public: 112 static const int JOIN_PACKET_RESEND_DELAY_MS = 200; 113 static const int JOIN_PACKET_RESEND_TIMEOUT_MS = 20000; 114 static const int JOIN_RESERVATION_WAIT_TIME = 30000; 115 static const int JOIN_CREATE_SESSION_MAX_ATTEMPTS = 5; 116 117 static const int PRIMARY_PLAYER_LEAVING_PARTY_WAIT_MS = 20000; // Time between primary player leaving and when we should respond to it, to allow time for us to receive a new party for them to be going to if they are just changing party rather than leaving altogether 118 119 class SessionInfo 120 { 121 public: 122 SessionInfo(wstring& sessionName, wstring& serviceConfig, wstring& sessionTemplate); 123 SessionInfo(); 124 bool m_detailsValid; 125 wstring m_sessionName; 126 wstring m_serviceConfig; 127 wstring m_sessionTemplate; 128 }; 129 130 static const int MAX_LOCAL_PLAYER_COUNT = 4; 131 static const int MAX_ONLINE_PLAYER_COUNT = 8; 132 static const int MAX_ONLINE_PLAYER_NAME_LENGTH = 21; 133 134 // This class stores everything about a player that must be synchronised between machines. 135 class PlayerSyncData 136 { 137 public: 138 wchar_t *m_XUID; // XUID / XboxUserIds are passed round as decimal strings on Xbox 1 139 uint32_t m_sessionAddress; // XRNS session address for this player, ie can identify which machine this player is on 140 uint8_t m_smallId; // Assigned by DQRNetworkManager, to attach a permanent id to this player (until we have to wrap round), to match a similar concept in qnet 141 uint8_t m_channel; // Local index / communication channel within session address, of player on this machine 142 wchar_t m_name[MAX_ONLINE_PLAYER_NAME_LENGTH]; 143 }; 144 145 class RoomSyncData 146 { 147 public: 148 int playerCount; 149 PlayerSyncData players[MAX_ONLINE_PLAYER_COUNT]; 150 }; 151 152 class HostGamertagResolveDetails 153 { 154 public:; 155 DQRNetworkPlayer* m_pPlayer; 156 wstring m_name; 157 unsigned int m_sessionAddress; 158 int m_channel; 159 bool m_sync; 160 }; 161 162 DQRNetworkManager(IDQRNetworkManagerListener *listener); 163 void Initialise(); 164 void EnableDebugXBLContext(MXS::XboxLiveContext^ XBLContext); 165 166 void CreateAndJoinSession(int userMask, unsigned char *customSessionData, unsigned int customSessionDataSize, bool offline); 167 void JoinSession(int playerMask); 168 void JoinSessionFromInviteInfo(int playerMask); 169 bool AddUsersToSession(int playerMask, MXSM::MultiplayerSessionReference^ sessionRef ); 170 void UpdateCustomSessionData(); 171 172 bool AddLocalPlayerByUserIndex(int userIndex); 173 bool RemoveLocalPlayerByUserIndex(int userIndex); 174 175 bool IsHost(); 176 bool IsInSession(); 177 178 // Player retrieval 179 int GetPlayerCount(); 180 int GetOnlinePlayerCount(); 181 DQRNetworkPlayer *GetPlayerByIndex(int idx); 182 DQRNetworkPlayer *GetPlayerBySmallId(int idx); 183 DQRNetworkPlayer *GetPlayerByXuid(PlayerUID xuid); 184 wstring GetDisplayNameByGamertag(wstring gamertag); 185 DQRNetworkPlayer *GetLocalPlayerByUserIndex(int idx); 186 DQRNetworkPlayer *GetHostPlayer(); 187 int GetSessionIndex(DQRNetworkPlayer *player); 188 void Tick(); 189 void Tick_XRNS(); 190 void Tick_VoiceChat(); 191 void Tick_Party(); 192 void Tick_CustomSessionData(); 193 void Tick_AddAndRemoveLocalPlayers(); 194 void Tick_ResolveGamertags(); 195 void Tick_PartyProcess(); 196 void Tick_StateMachine(); 197 void Tick_CheckInviteParty(); 198 199 bool ShouldMessageForFullSession(); 200 void FlagInvitedToFullSession(); 201 void UnflagInvitedToFullSession(); 202 // Externally exposed state. All internal states are mapped to one of these broader states. 203 typedef enum 204 { 205 DNM_STATE_INITIALISING, 206 DNM_STATE_INITIALISE_FAILED, 207 DNM_STATE_IDLE, 208 209 DNM_STATE_HOSTING, 210 DNM_STATE_JOINING, 211 212 DNM_STATE_STARTING, 213 DNM_STATE_PLAYING, 214 215 DNM_STATE_LEAVING, 216 DNM_STATE_ENDING, 217 } eDQRNetworkManagerState; 218 219 eDQRNetworkManagerState GetState(); 220 221 class SessionSearchResult 222 { 223 public: 224 SessionSearchResult() { m_extData = NULL; } 225 ~SessionSearchResult() { free(m_extData); } 226 wstring m_partyId; 227 wstring m_sessionName; 228 229 // These names/xuids reflect the server controlled list of who is actually in the game 230 wstring m_playerNames[MAX_ONLINE_PLAYER_COUNT]; 231 PlayerUID m_playerXuids[MAX_ONLINE_PLAYER_COUNT]; 232 int m_playerCount; 233 234 // This count & set of xuids reflects the session document list of who is in the game 235 wstring m_sessionXuids[MAX_ONLINE_PLAYER_COUNT]; 236 int m_usedSlotCount; 237 238 void *m_extData; 239 }; 240 241protected: 242 // NOTE: If anything changes in here, then the mapping from internal -> external state needs to be updated (m_INTtoEXTStateMappings, defined in the cpp file) 243 typedef enum 244 { 245 DNM_INT_STATE_INITIALISING, 246 DNM_INT_STATE_INITIALISE_FAILED, 247 DNM_INT_STATE_IDLE, 248 DNM_INT_STATE_HOSTING, 249 DNM_INT_STATE_HOSTING_WAITING_TO_PLAY, 250 DNM_INT_STATE_HOSTING_FAILED, 251 DNM_INT_STATE_JOINING, 252 DNM_INT_STATE_JOINING_WAITING_FOR_RESERVATIONS, 253 DNM_INT_STATE_JOINING_GET_SDA, 254 DNM_INT_STATE_JOINING_WAITING_FOR_SDA, 255 DNM_INT_STATE_JOINING_CREATE_SESSION, 256 DNM_INT_STATE_JOINING_WAITING_FOR_ACTIVE_SESSION, 257 DNM_INT_STATE_JOINING_SENDING_UNRELIABLE, 258 DNM_INT_STATE_JOINING_FAILED_TIDY_UP, 259 DNM_INT_STATE_JOINING_FAILED, 260 DNM_INT_STATE_STARTING, 261 DNM_INT_STATE_PLAYING, 262 DNM_INT_STATE_LEAVING, 263 DNM_INT_STATE_LEAVING_FAILED, 264 DNM_INT_STATE_ENDING, 265 DNM_INT_STATE_COUNT 266 } eDQRNetworkManagerInternalState; 267 268 typedef enum 269 { 270 DNM_ADD_PLAYER_STATE_IDLE, 271 DNM_ADD_PLAYER_STATE_PROCESSING, 272 DNM_ADD_PLAYER_STATE_COMPLETE_SUCCESS, 273 DNM_ADD_PLAYER_STATE_COMPLETE_FAIL, 274 DNM_ADD_PLAYER_STATE_COMPLETE_FAIL_FULL, 275 } eDQRAddLocalPlayerState; 276 277 typedef enum 278 { 279 DNM_REMOVE_PLAYER_STATE_IDLE, 280 DNM_REMOVE_PLAYER_STATE_PROCESSING, 281 DNM_REMOVE_PLAYER_STATE_COMPLETE_SUCCESS, 282 DNM_REMOVE_PLAYER_STATE_COMPLETE_FAIL, 283 } eDQRRemoveLocalPlayerState; 284 285 class StateChangeInfo 286 { 287 public: 288 eDQRNetworkManagerState m_oldState; 289 eDQRNetworkManagerState m_newState; 290 StateChangeInfo(eDQRNetworkManagerState oldState, eDQRNetworkManagerState newState) : m_oldState(oldState), m_newState(newState) {} 291 }; 292 293 typedef enum 294 { 295 // Incoming messages 296 RTS_MESSAGE_DATA_RECEIVED, 297 RTS_MESSAGE_DATA_RECEIVED_CHAT, 298 RTS_MESSAGE_ADDED_SESSION_ADDRESS, 299 RTS_MESSAGE_REMOVED_SESSION_ADDRESS, 300 RTS_MESSAGE_STATUS_ACTIVE, 301 RTS_MESSAGE_STATUS_TERMINATED, 302 303 // Outgoing messages 304 RTS_MESSAGE_START_CLIENT, 305 RTS_MESSAGE_START_HOST, 306 RTS_MESSAGE_TERMINATE, 307 RTS_MESSAGE_SEND_DATA, 308 } eRTSMessageType; 309 310 typedef enum 311 { 312 RTS_MESSAGE_FLAG_BROADCAST_MODE = 1, 313 RTS_MESSAGE_FLAG_RELIABLE = 2, 314 RTS_MESSAGE_FLAG_SEQUENTIAL = 4, 315 RTS_MESSAGE_FLAG_COALESCE = 8, 316 RTS_MESSAGE_FLAG_GAME_CHANNEL = 16, 317 } eRTSFlags; 318 319 class RTS_Message 320 { 321 public: 322 eRTSMessageType m_eType; 323 unsigned int m_sessionAddress; 324 unsigned char *m_pucData; 325 unsigned int m_dataSize; 326 unsigned int m_flags; 327 }; 328 329 std::queue<StateChangeInfo> m_stateChangeQueue; 330 CRITICAL_SECTION m_csStateChangeQueue; 331 CRITICAL_SECTION m_csSendBytes; 332 CRITICAL_SECTION m_csPartyViewVector; 333 std::queue<RTS_Message> m_RTSMessageQueueIncoming; 334 CRITICAL_SECTION m_csRTSMessageQueueIncoming; 335 std::queue<RTS_Message> m_RTSMessageQueueOutgoing; 336 CRITICAL_SECTION m_csRTSMessageQueueOutgoing; 337private: 338 void SetState(DQRNetworkManager::eDQRNetworkManagerInternalState state); 339 static const eDQRNetworkManagerState m_INTtoEXTStateMappings[DNM_INT_STATE_COUNT]; 340 eDQRNetworkManagerInternalState m_state; 341 eDQRNetworkManagerState m_stateExternal; 342 __int64 m_lastUnreliableSendTime; 343 __int64 m_firstUnreliableSendTime; 344 __int64 m_startedWaitingForReservationsTime; 345 unsigned char *m_customSessionData; 346 unsigned int m_customSessionDataSize; 347 int m_customDataDirtyUpdateTicks; 348 std::shared_ptr<ChatIntegrationLayer> m_chat; 349 350 eDQRAddLocalPlayerState m_addLocalPlayerState; 351 DQRNetworkPlayer *m_addLocalPlayerSuccessPlayer; 352 int m_addLocalPlayerSuccessIndex; 353 int m_addLocalPlayerFailedIndex; 354 355 eDQRRemoveLocalPlayerState m_removeLocalPlayerState; 356 int m_removeLocalPlayerIndex; 357 358 Windows::Xbox::System::User^ m_primaryUser; 359 MXS::XboxLiveContext^ m_primaryUserXboxLiveContext; 360 WXN::SecureDeviceAssociationTemplate^ m_associationTemplate; 361 362 CRITICAL_SECTION m_csRoomSyncData; 363 RoomSyncData m_roomSyncData; 364 DQRNetworkPlayer *m_players[MAX_ONLINE_PLAYER_COUNT]; 365 366 IDQRNetworkManagerListener *m_listener; 367 PartyController *m_partyController; 368 DQRNetworkManagerEventHandlers^ m_eventHandlers; 369 WXNRs::Session^ m_XRNS_Session; 370 unsigned int m_XRNS_LocalAddress; 371 unsigned int m_XRNS_OldestAddress; 372 MXSM::MultiplayerSession^ m_multiplayerSession; 373 WXN::SecureDeviceAssociation^ m_sda; 374 Platform::String^ m_secureDeviceAddressBase64; 375 unsigned char m_currentSmallId; 376 unsigned char m_hostSmallId; 377 bool m_isHosting; 378 bool m_isInSession; 379 bool m_isOfflineGame; 380public: 381 int m_currentUserMask; 382private: 383 int m_joinSessionUserMask; 384 Platform::Array<Platform::String^>^ m_joinSessionXUIDs; 385 int m_joinSmallIdMask; 386 387 Platform::Array<BYTE>^ m_remoteSocketAddress; 388 Platform::Array<BYTE>^ m_localSocketAddress; 389 int m_joinCreateSessionAttempts; 390 391 C4JThread *m_CreateSessionThread; 392 C4JThread *m_LeaveRoomThread; 393 C4JThread *m_TidyUpJoinThread; 394 C4JThread *m_UpdateCustomSessionDataThread; 395 C4JThread *m_RTS_DoWorkThread; 396 C4JThread *m_CheckPartyInviteThread; 397 398 bool m_notifyForFullParty; 399 400 unordered_map<unsigned int,DQRConnectionInfo *> m_sessionAddressToConnectionInfoMapHost; // For host - there may be more than one remote session attached to this listening session 401 unsigned int m_sessionAddressFromSmallId[256]; // For host - for mapping back from small Id, to session address 402 unsigned char m_channelFromSmallId[256]; // For host and client, for mapping back from small Id, to channel 403 DQRConnectionInfo m_connectionInfoClient; // For client 404 unsigned int m_hostSessionAddress; // For client 405 406 CRITICAL_SECTION m_csHostGamertagResolveResults; 407 queue<HostGamertagResolveDetails *> m_hostGamertagResolveResults; 408 409 void AddPlayerFailed(Platform::String ^xuid); 410 Platform::String^ RemoveBracesFromGuidString(__in Platform::String^ guid ); 411 void HandleSessionChange( MXSM::MultiplayerSession^ session ); 412 MXSM::MultiplayerSession^ WriteSessionHelper( MXS::XboxLiveContext^ xboxLiveContext, 413 MXSM::MultiplayerSession^ multiplayerSession, 414 MXSM::MultiplayerSessionWriteMode writeMode, 415 HRESULT& hr); 416 MXSM::MultiplayerSessionMember^ GetUserMemberInSession( Windows::Xbox::System::User^ user, MXSM::MultiplayerSession^ session); 417 bool IsPlayerInSession( Platform::String^ xboxUserId, MXSM::MultiplayerSession^ session, int *smallId ); 418 419 WXM::MultiplayerSessionReference^ ConvertToWindowsXboxMultiplayerSessionReference( MXSM::MultiplayerSessionReference^ sessionRef); 420 MXSM::MultiplayerSessionReference^ ConvertToMicrosoftXboxServicesMultiplayerSessionReference( WXM::MultiplayerSessionReference^ sessionRef ); 421 422 void BytesReceived(int smallId, BYTE *bytes, int byteCount); 423 void BytesReceivedInternal(DQRConnectionInfo *connectionInfo, unsigned int sessionAddress, BYTE *bytes, int byteCount); 424 void SendBytes(int smallId, BYTE *bytes, int byteCount); 425 int GetQueueSizeBytes(); 426 int GetQueueSizeMessages(); 427 void SendBytesRaw(int smallId, BYTE *bytes, int byteCount, bool reliableAndSequential); 428 void SendBytesChat(unsigned int address, BYTE *bytes, int byteCount, bool reliable, bool sequential, bool broadcast); 429 430 bool AddRoomSyncPlayer(DQRNetworkPlayer *pPlayer, unsigned int sessionAddress, int channel); 431 void RemoveRoomSyncPlayersWithSessionAddress(unsigned int sessionAddress); 432 void RemoveRoomSyncPlayer(DQRNetworkPlayer *pPlayer); 433 void UpdateRoomSyncPlayers(RoomSyncData *pNewSyncData); 434 void SendRoomSyncInfo(); 435 void SendAddPlayerFailed(Platform::String^ xuid); 436 void SendSmallId(bool reliableAndSequential, int playerMask); 437 void SendUnassignSmallId(int playerIndex); 438 int GetSessionIndexForSmallId(unsigned char smallId); 439 int GetSessionIndexAndSmallIdForHost(unsigned char *smallId); 440 441 static void LogComment( Platform::String^ strText ); 442 static void LogCommentFormat( LPCWSTR strMsg, ... ); 443 static void LogCommentWithError( Platform::String^ strTest, HRESULT hr ); 444 445 static Platform::String^ GetErrorString( HRESULT hr ); 446 static Platform::String^ FormatString( LPCWSTR strMsg, ... ); 447 static Platform::String^ ConvertHResultToErrorName( HRESULT hr ); 448 449 Platform::String^ GetNextSmallIdAsJsonString(); 450 static int _HostGameThreadProc( void* lpParameter ); 451 int HostGameThreadProc(); 452 static int _LeaveRoomThreadProc( void* lpParameter ); 453 int LeaveRoomThreadProc(); 454 static int _TidyUpJoinThreadProc( void* lpParameter ); 455 int TidyUpJoinThreadProc(); 456 static int _UpdateCustomSessionDataThreadProc( void* lpParameter ); 457 int UpdateCustomSessionDataThreadProc(); 458 static int _CheckInviteThreadProc(void *lpParameter); 459 int CheckInviteThreadProc(); 460 static int _RTSDoWorkThread(void* lpParameter); 461 int RTSDoWorkThread(); 462 463 CRITICAL_SECTION m_csVecChatPlayers; 464 vector<int> m_vecChatPlayersJoined; 465public: 466 void HandleNewPartyFoundForPlayer(); 467 void HandlePlayerRemovedFromParty(int playerMask); 468 469 void ChatPlayerJoined(int idx); 470 bool IsReadyToPlayOrIdle(); 471 void StartGame(); 472 void LeaveRoom(); 473 void TidyUpFailedJoin(); 474 475 static void SetInviteReceivedFlag(); 476 static void SetPartyProcessJoinParty(); 477 static void SetPartyProcessJoinSession(int bootUserIndex, Platform::String^ bootSessionName, Platform::String^ bootServiceConfig, Platform::String^ bootSessionTemplate); 478 479 void SendInviteGUI(int quadrant); 480 bool IsAddingPlayer(); 481 482 bool FriendPartyManagerIsBusy(); 483 int FriendPartyManagerGetCount(); 484 bool FriendPartyManagerSearch(); 485 void FriendPartyManagerGetSessionInfo(int idx, SessionSearchResult *searchResult); 486 WFC::IVectorView<WXM::UserPartyAssociation^>^ FilterPartiesByPermission(MXS::XboxLiveContext ^context, WFC::IVectorView<WXM::UserPartyAssociation^>^ partyResults); 487 488 bool JoinPartyFromSearchResult(SessionSearchResult *searchResult, int playerMask); 489 void CancelJoinPartyFromSearchResult(); 490 void RequestDisplayName(DQRNetworkPlayer *player); 491 void SetDisplayName(PlayerUID xuid, wstring displayName); 492 493private: 494 __int64 m_playersLeftPartyTime; 495 int m_playersLeftParty; 496 497 bool GetBestPartyUserIndex(); 498 C4JThread *m_GetFriendPartyThread; 499 static int _GetFriendsThreadProc( void* lpParameter ); 500 int GetFriendsThreadProc(); 501 bool IsSessionFriendsOfFriends(MXSM::MultiplayerSession^ session); 502 bool GetGameSessionData(MXSM::MultiplayerSession^ session, void *gameSessionData); 503 504public: 505 static Platform::Collections::Vector<Platform::String^>^ GetFriends(); 506 507private: 508 SessionSearchResult *m_sessionSearchResults; 509 int m_sessionResultCount; 510 bool m_cancelJoinFromSearchResult; 511 512 map<wstring, wstring> m_displayNames; // Player display names by gamertag 513 514 515 516 typedef enum 517 { 518 DNM_PARTY_PROCESS_NONE, 519 DNM_PARTY_PROCESS_JOIN_PARTY, 520 DNM_PARTY_PROCESS_JOIN_SPECIFIED 521 } ePartyProcessType; 522 static int m_bootUserIndex; 523 static ePartyProcessType m_partyProcess; 524 static wstring m_bootSessionName; 525 static wstring m_bootServiceConfig; 526 static wstring m_bootSessionTemplate; 527 static bool m_inviteReceived; 528 529 static DQRNetworkManager *s_pDQRManager; 530 531 static void GetProfileCallback(LPVOID pParam, Microsoft::Xbox::Services::Social::XboxUserProfile^ profile); 532 533 // Forced signout 534 bool m_handleForcedSignOut; 535 536 void CheckForcedSignOut(); 537 void HandleForcedSignOut(); 538 539 unsigned int m_RTS_Stat_totalBytes; 540 unsigned int m_RTS_Stat_totalSends; 541 542 void UpdateRTSStats(); 543 544 // Incoming messages - to be called from the main thread, to get incoming messages from the RTS work thread 545 void ProcessRTSMessagesIncoming(); 546 void Process_RTS_MESSAGE_DATA_RECEIVED(RTS_Message &message); 547 void Process_RTS_MESSAGE_DATA_RECEIVED_CHAT(RTS_Message &message); 548 void Process_RTS_MESSAGE_ADDED_SESSION_ADDRESS(RTS_Message &message); 549 void Process_RTS_MESSAGE_REMOVED_SESSION_ADDRESS(RTS_Message &message); 550 void Process_RTS_MESSAGE_STATUS_ACTIVE(RTS_Message &message); 551 void Process_RTS_MESSAGE_STATUS_TERMINATED(RTS_Message &message); 552 553 // Outgoing messages - to be called from the RTS work thread, to process requests from the main thread 554 555 void ProcessRTSMessagesOutgoing(); 556 void Process_RTS_MESSAGE_START_CLIENT(RTS_Message &message); 557 void Process_RTS_MESSAGE_START_HOST(RTS_Message &message); 558 void Process_RTS_MESSAGE_TERMINATE(RTS_Message &message); 559 void Process_RTS_MESSAGE_SEND_DATA(RTS_Message &message); 560 561 // These methods are called from the main thread, to put an outgoing message onto the queue to be processed by these previous methods 562 void RTS_StartCient(); 563 void RTS_StartHost(); 564 void RTS_Terminate(); 565 void RTS_SendData(unsigned char *pucData, unsigned int dataSize, unsigned int sessionAddress, bool reliable, bool sequential, bool coalesce, bool includeMode, bool gameChannel ); 566 567}; 568 569// Class defining interface to be implemented for class that handles callbacks 570class IDQRNetworkManagerListener 571{ 572public: 573 virtual void HandleDataReceived(DQRNetworkPlayer *playerFrom, DQRNetworkPlayer *playerTo, unsigned char *data, unsigned int dataSize) = 0; 574 virtual void HandlePlayerJoined(DQRNetworkPlayer *player) = 0; 575 virtual void HandlePlayerLeaving(DQRNetworkPlayer *player) = 0; 576 virtual void HandleStateChange(DQRNetworkManager::eDQRNetworkManagerState oldState, DQRNetworkManager::eDQRNetworkManagerState newState) = 0; 577// virtual void HandleResyncPlayerRequest(DQRNetworkPlayer **aPlayers) = 0; 578 virtual void HandleAddLocalPlayerFailed(int idx, bool serverFull) = 0; 579 virtual void HandleDisconnect(bool bLostRoomOnly) = 0; 580 virtual void HandleInviteReceived(int playerIndex, DQRNetworkManager::SessionInfo *pInviteInfo) = 0; 581 virtual bool IsSessionJoinable() = 0; 582};