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