diff --git a/src/engine/shared/network.cpp b/src/engine/shared/network.cpp index fb14acdc1..3e66f5500 100644 --- a/src/engine/shared/network.cpp +++ b/src/engine/shared/network.cpp @@ -87,7 +87,7 @@ int CNetRecvUnpacker::FetchChunk(CNetChunk *pChunk) } // packs the data tight and sends it -void CNetBase::SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, int Version, unsigned int Token, unsigned int ResponseToken, const void *pData, int DataSize) +void CNetBase::SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, int Version, TOKEN Token, TOKEN ResponseToken, const void *pData, int DataSize) { unsigned char aBuffer[NET_MAX_PACKETSIZE]; @@ -365,7 +365,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct } -void CNetBase::SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Version, unsigned int Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize) +void CNetBase::SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Version, TOKEN Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize) { CNetPacketConstruct Construct; Construct.m_Version = Version; @@ -382,7 +382,7 @@ void CNetBase::SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Version, uns } -void CNetBase::SendToken(NETSOCKET Socket, NETADDR *pAddr, unsigned int Token, unsigned int ResponseToken) +void CNetBase::SendToken(NETSOCKET Socket, NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken) { char aToken[4]; aToken[0] = (Token>>24)&0xff; diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index 424b25b3e..e4f10d98f 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -103,6 +103,8 @@ enum typedef int (*NETFUNC_DELCLIENT)(int ClientID, const char* pReason, void *pUser); typedef int (*NETFUNC_NEWCLIENT)(int ClientID, void *pUser); +typedef unsigned int TOKEN; + struct CNetChunk { // -1 means that it's a connless packet @@ -141,8 +143,8 @@ class CNetPacketConstruct { public: int m_Version; - unsigned int m_Token; - unsigned int m_ResponseToken; // only used in connless packets + TOKEN m_Token; + TOKEN m_ResponseToken; // only used in connless packets int m_Flags; int m_Ack; int m_NumChunks; @@ -160,11 +162,11 @@ public: int ProcessMessage(const NETADDR *pAddr, const CNetPacketConstruct *pPacket, bool Notify); - bool CheckToken(const NETADDR *pAddr, unsigned int Token, unsigned int ResponseToken, bool Notify); - unsigned int GenerateToken(const NETADDR *pAddr); + bool CheckToken(const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, bool Notify); + TOKEN GenerateToken(const NETADDR *pAddr); private: - static unsigned int GenerateToken(const NETADDR *pAddr, int64 Seed); + static TOKEN GenerateToken(const NETADDR *pAddr, int64 Seed); NETSOCKET m_Socket; @@ -198,8 +200,8 @@ private: CNetPacketConstruct m_Construct; - unsigned int m_Token; - unsigned int m_PeerToken; + TOKEN m_Token; + TOKEN m_PeerToken; NETADDR m_PeerAddr; NETSOCKET m_Socket; @@ -217,14 +219,14 @@ private: void ResendChunk(CNetChunkResend *pResend); void Resend(); - static unsigned int GenerateToken(const NETADDR *pPeerAddr); + static TOKEN GenerateToken(const NETADDR *pPeerAddr); public: void Init(NETSOCKET Socket, bool BlockCloseMsg); int Connect(NETADDR *pAddr); void Disconnect(const char *pReason); - void SetToken(unsigned int Token); + void SetToken(TOKEN Token); int Update(); int Flush(); @@ -327,8 +329,8 @@ public: int Close(); // the token and version parameter are only used for connless packets - int Recv(CNetChunk *pChunk, unsigned int *pResponseToken = 0, int *pVersion = 0); - int Send(CNetChunk *pChunk, unsigned int Token = NET_TOKEN_NONE, int Version = NET_PACKETVERSION); + int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0, int *pVersion = 0); + int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE, int Version = NET_PACKETVERSION); int Update(); // @@ -405,8 +407,8 @@ public: int Connect(NETADDR *Addr); // communication - int Recv(CNetChunk *pChunk, unsigned int *pResponseToken = 0, int *pVersion = 0); - int Send(CNetChunk *pChunk, unsigned int Token = NET_TOKEN_NONE, int Version = NET_PACKETVERSION); + int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0, int *pVersion = 0); + int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE, int Version = NET_PACKETVERSION); // pumping int Update(); @@ -436,9 +438,9 @@ public: static int Compress(const void *pData, int DataSize, void *pOutput, int OutputSize); static int Decompress(const void *pData, int DataSize, void *pOutput, int OutputSize); - static void SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Version, unsigned int Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize); - static void SendToken(NETSOCKET Socket, NETADDR *pAddr, unsigned int Token, unsigned int ResponseToken = NET_TOKEN_NONE); - static void SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, int Version, unsigned int Token, unsigned int ResponseToken, const void *pData, int DataSize); + static void SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Version, TOKEN Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize); + static void SendToken(NETSOCKET Socket, NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken = NET_TOKEN_NONE); + static void SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, int Version, TOKEN Token, TOKEN ResponseToken, const void *pData, int DataSize); static void SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct *pPacket); static int UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket); diff --git a/src/engine/shared/network_client.cpp b/src/engine/shared/network_client.cpp index fd6ee0d9a..54c1d6925 100644 --- a/src/engine/shared/network_client.cpp +++ b/src/engine/shared/network_client.cpp @@ -59,7 +59,7 @@ int CNetClient::ResetErrorString() return 0; } -int CNetClient::Recv(CNetChunk *pChunk, unsigned int *pResponseToken, int *pVersion) +int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) { while(1) { @@ -115,7 +115,7 @@ int CNetClient::Recv(CNetChunk *pChunk, unsigned int *pResponseToken, int *pVers return 0; } -int CNetClient::Send(CNetChunk *pChunk, unsigned int Token, int Version) +int CNetClient::Send(CNetChunk *pChunk, TOKEN Token, int Version) { if(pChunk->m_Flags&NETSENDFLAG_CONNLESS) { diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index fd1afc6eb..2b7aeff2d 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -31,7 +31,7 @@ void CNetConnection::Reset() mem_zero(&m_Construct, sizeof(m_Construct)); } -void CNetConnection::SetToken(unsigned int Token) +void CNetConnection::SetToken(TOKEN Token) { if(State() != NET_CONNSTATE_OFFLINE) return; @@ -39,7 +39,7 @@ void CNetConnection::SetToken(unsigned int Token) m_Token = Token; } -unsigned int CNetConnection::GenerateToken(const NETADDR *pPeerAddr) +TOKEN CNetConnection::GenerateToken(const NETADDR *pPeerAddr) { return ((rand() & 0xffff) << 16) | (rand() & 0xffff); } diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 5fa2dbf1d..75b90b5f7 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -95,7 +95,7 @@ int CNetServer::Update() /* TODO: chopp up this function into smaller working parts */ -int CNetServer::Recv(CNetChunk *pChunk, unsigned int *pResponseToken, int *pVersion) +int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) { while(1) { @@ -231,7 +231,7 @@ int CNetServer::Recv(CNetChunk *pChunk, unsigned int *pResponseToken, int *pVers return 0; } -int CNetServer::Send(CNetChunk *pChunk, unsigned int Token, int Version) +int CNetServer::Send(CNetChunk *pChunk, TOKEN Token, int Version) { if(pChunk->m_Flags&NETSENDFLAG_CONNLESS) { diff --git a/src/engine/shared/network_token.cpp b/src/engine/shared/network_token.cpp index e35f0323a..f3a6ae3bd 100644 --- a/src/engine/shared/network_token.cpp +++ b/src/engine/shared/network_token.cpp @@ -9,10 +9,10 @@ #include "network.h" -static unsigned int Hash(char *pData, int Size) +static TOKEN Hash(char *pData, int Size) { md5_state_t State; - unsigned int Result; + TOKEN Result; md5_byte_t aDigest[sizeof(Result)]; md5_init(&State); @@ -70,12 +70,12 @@ void CNetTokenManager::GenerateSeed() } } -unsigned int CNetTokenManager::GenerateToken(const NETADDR *pAddr) +TOKEN CNetTokenManager::GenerateToken(const NETADDR *pAddr) { return GenerateToken(pAddr, m_Seed); } -unsigned int CNetTokenManager::GenerateToken(const NETADDR *pAddr, int64 Seed) +TOKEN CNetTokenManager::GenerateToken(const NETADDR *pAddr, int64 Seed) { char aBuf[sizeof(NETADDR) + sizeof(int64)]; int Result; @@ -89,9 +89,9 @@ unsigned int CNetTokenManager::GenerateToken(const NETADDR *pAddr, int64 Seed) return Result; } -bool CNetTokenManager::CheckToken(const NETADDR *pAddr, unsigned int Token, unsigned int ResponseToken, bool Notify) +bool CNetTokenManager::CheckToken(const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, bool Notify) { - unsigned int CurrentToken = GenerateToken(pAddr, m_Seed); + TOKEN CurrentToken = GenerateToken(pAddr, m_Seed); if(CurrentToken == Token) return true;