1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #ifndef __CRYSHAREDLOBBYPACKET_H__
4 #define __CRYSHAREDLOBBYPACKET_H__
8 #include <CryLobby/CryLobbyPacket.h>
9 #include "CryMatchMaking.h"
11 const uint32 CryLobbyPacketErrorSize
= CryLobbyPacketUINT16Size
;
12 const uint32 CryLobbyPacketLobbySessionHandleSize
= CryLobbyPacketUINT8Size
;
14 class CCrySharedLobbyPacket
: public CCryLobbyPacket
17 void WritePacketHeader()
19 CCryLobby
* pLobby
= (CCryLobby
*)CCryLobby::GetLobby();
21 WriteUINT8(pLobby
->GetLobbyPacketID());
23 if (pLobby
->GetLobbyServiceType() == eCLS_Online
)
25 // Online use WriteData since if there is no cross platform WriteData or WriteUINT64 can both be used but WriteData is faster.
26 // Also if we want to support cross platform with games for windows live and xbox live WriteData must be used.
27 WriteData(&m_packetHeader
.fromUID
.m_sid
, CryLobbyPacketUINT64Size
);
31 // LAN always needs to use WriteUINT64 to keep cross platform compatibility.
32 WriteUINT64(m_packetHeader
.fromUID
.m_sid
);
35 WriteUINT16(m_packetHeader
.fromUID
.m_uid
);
36 WriteBool(m_packetHeader
.reliable
);
38 if (m_packetHeader
.reliable
)
40 WriteUINT8(m_packetHeader
.counterOut
);
41 WriteUINT8(m_packetHeader
.counterIn
);
45 void ReadPacketHeader()
49 if (CCryLobby::GetLobby()->GetLobbyServiceType() == eCLS_Online
)
51 // Online use ReadData since if there is no cross platform ReadData or ReadUINT64 can both be used but ReadData is faster.
52 // Also if we want to support cross platform with games for windows live and xbox live ReadData must be used.
53 ReadData(&m_packetHeader
.fromUID
.m_sid
, CryLobbyPacketUINT64Size
);
57 // LAN always needs to use ReadUINT64 to keep cross platform compatibility.
58 m_packetHeader
.fromUID
.m_sid
= ReadUINT64();
61 m_packetHeader
.fromUID
.m_uid
= ReadUINT16();
62 m_packetHeader
.reliable
= ReadBool();
64 if (m_packetHeader
.reliable
)
66 m_packetHeader
.counterOut
= ReadUINT8();
67 m_packetHeader
.counterIn
= ReadUINT8();
71 void WriteDataHeader()
73 WriteUINT8(m_dataHeader
.lobbyPacketType
);
75 if (m_packetHeader
.reliable
)
77 WriteUINT16(m_dataHeader
.dataSize
);
83 m_dataHeader
.lobbyPacketType
= ReadUINT8();
85 if (m_packetHeader
.reliable
)
87 m_dataHeader
.dataSize
= ReadUINT16();
91 void WriteError(ECryLobbyError data
)
93 WriteUINT16((uint16
)data
);
96 ECryLobbyError
ReadError()
98 return (ECryLobbyError
)ReadUINT16();
101 void WriteLobbySessionHandle(CryLobbySessionHandle h
)
103 WriteUINT8(h
.GetID());
106 CryLobbySessionHandle
ReadLobbySessionHandle()
108 return CryLobbySessionHandle(ReadUINT8());
111 void SetFromSessionSID(uint64 sid
)
113 m_packetHeader
.fromUID
.m_sid
= sid
;
116 uint64
GetFromSessionSID()
118 return m_packetHeader
.fromUID
.m_sid
;
121 void SetFromConnectionUID(SCryMatchMakingConnectionUID uid
)
123 m_packetHeader
.fromUID
= uid
;
126 SCryMatchMakingConnectionUID
GetFromConnectionUID()
128 return m_packetHeader
.fromUID
;
131 SCryLobbyPacketHeader
* GetLobbyPacketHeader() { return &m_packetHeader
; }
132 SCryLobbyPacketDataHeader
* GetLobbyPacketDataHeader() { return &m_dataHeader
; }
137 m_pWriteBuffer
= NULL
;
141 #endif // __CRYSHAREDLOBBYPACKET_H__