Lobby2Client_Steam_Impl.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #ifndef __LOBBY_2_CLIENT_STEAM_IMPL_H
  11. #define __LOBBY_2_CLIENT_STEAM_IMPL_H
  12. #include "steam_api.h"
  13. #include "Lobby2Client_Steam.h"
  14. #include "DS_Multilist.h"
  15. #include "SocketLayer.h"
  16. #include "DS_OrderedList.h"
  17. namespace RakNet
  18. {
  19. struct Lobby2Message;
  20. #define STEAM_UNUSED_PORT 1
  21. class RAK_DLL_EXPORT Lobby2Client_Steam_Impl : public Lobby2Client_Steam, public SocketLayerOverride
  22. {
  23. public:
  24. Lobby2Client_Steam_Impl();
  25. virtual ~Lobby2Client_Steam_Impl();
  26. /// Send a command to the server
  27. /// \param[in] msg The message that represents the command
  28. virtual void SendMsg(Lobby2Message *msg);
  29. // Base class implementation
  30. virtual void Update(void);
  31. virtual void OnLobbyMatchListCallback( LobbyMatchList_t *pCallback, bool bIOFailure );
  32. virtual void OnLobbyCreated( LobbyCreated_t *pCallback, bool bIOFailure );
  33. virtual void OnLobbyJoined( LobbyEnter_t *pCallback, bool bIOFailure );
  34. virtual bool IsCommandRunning( Lobby2MessageID msgId );
  35. virtual void GetRoomMembers(DataStructures::OrderedList<uint64_t, uint64_t> &_roomMembers);
  36. virtual const char * GetRoomMemberName(uint64_t memberId);
  37. virtual bool IsRoomOwner(const uint64_t cSteamID);
  38. virtual bool IsInRoom(void) const;
  39. virtual uint64_t GetNumRoomMembers(const uint64_t roomid){return SteamMatchmaking()->GetNumLobbyMembers(roomid);}
  40. virtual uint64_t GetMyUserID(void){return SteamUser()->GetSteamID().ConvertToUint64();}
  41. virtual const char* GetMyUserPersonalName(void) {return SteamFriends()->GetPersonaName();}
  42. virtual void NotifyLeaveRoom(void);
  43. // Returns 0 if none
  44. virtual uint64_t GetRoomID(void) const {return roomId;}
  45. /// Called when SendTo would otherwise occur.
  46. virtual int RakNetSendTo( const char *data, int length, const SystemAddress &systemAddress );
  47. /// Called when RecvFrom would otherwise occur. Return number of bytes read. Write data into dataOut
  48. virtual int RakNetRecvFrom( char dataOut[ MAXIMUM_MTU_SIZE ], SystemAddress *senderOut, bool calledFromMainThread);
  49. virtual void OnRakPeerShutdown(void);
  50. virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
  51. virtual void OnFailedConnectionAttempt(Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason);
  52. virtual void OnAttach(void);
  53. virtual void OnDetach(void);
  54. struct RoomMember
  55. {
  56. SystemAddress systemAddress;
  57. uint64_t steamIDRemote;
  58. };
  59. static int SystemAddressAndRoomMemberComp( const SystemAddress &key, const RoomMember &data );
  60. static int SteamIDAndRoomMemberComp( const uint64_t &key, const RoomMember &data );
  61. protected:
  62. void CallCBWithResultCode(Lobby2Message *msg, Lobby2ResultCode rc);
  63. void PushDeferredCallback(Lobby2Message *msg);
  64. void CallRoomCallbacks(void);
  65. void NotifyNewMember(uint64_t memberId, SystemAddress remoteSystem);
  66. void NotifyDroppedMember(uint64_t memberId, SystemAddress remoteSystem);
  67. void CallCompletedCallbacks(void);
  68. STEAM_CALLBACK( Lobby2Client_Steam_Impl, OnLobbyDataUpdatedCallback, LobbyDataUpdate_t, m_CallbackLobbyDataUpdated );
  69. STEAM_CALLBACK( Lobby2Client_Steam_Impl, OnPersonaStateChange, PersonaStateChange_t, m_CallbackPersonaStateChange );
  70. STEAM_CALLBACK( Lobby2Client_Steam_Impl, OnLobbyDataUpdate, LobbyDataUpdate_t, m_CallbackLobbyDataUpdate );
  71. STEAM_CALLBACK( Lobby2Client_Steam_Impl, OnLobbyChatUpdate, LobbyChatUpdate_t, m_CallbackChatDataUpdate );
  72. STEAM_CALLBACK( Lobby2Client_Steam_Impl, OnLobbyChatMessage, LobbyChatMsg_t, m_CallbackChatMessageUpdate );
  73. STEAM_CALLBACK( Lobby2Client_Steam_Impl, OnP2PSessionRequest, P2PSessionRequest_t, m_CallbackP2PSessionRequest );
  74. STEAM_CALLBACK( Lobby2Client_Steam_Impl, OnP2PSessionConnectFail, P2PSessionConnectFail_t, m_CallbackP2PSessionConnectFail );
  75. DataStructures::Multilist<ML_UNORDERED_LIST, Lobby2Message *, uint64_t > deferredCallbacks;
  76. uint64_t roomId;
  77. DataStructures::OrderedList<SystemAddress, RoomMember, SystemAddressAndRoomMemberComp> roomMembersByAddr;
  78. DataStructures::OrderedList<uint64_t, RoomMember, SteamIDAndRoomMemberComp> roomMembersById;
  79. DataStructures::Multilist<ML_ORDERED_LIST, uint64_t> rooms;
  80. void ClearRoom(void);
  81. uint32_t nextFreeSystemAddress;
  82. };
  83. };
  84. #endif
粤ICP备19079148号