From 4e7137ad48cc61988ac3128965c41c0aae3dd425 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Wed, 3 Oct 2012 13:37:35 +0200 Subject: [PATCH] removed backward compatiblity --- src/engine/shared/network.cpp | 199 +++++++-------------------- src/engine/shared/network.h | 31 ++--- src/engine/shared/network_client.cpp | 20 +-- src/engine/shared/network_conn.cpp | 8 +- src/engine/shared/network_server.cpp | 27 ++-- src/engine/shared/network_token.cpp | 7 +- 6 files changed, 76 insertions(+), 216 deletions(-) diff --git a/src/engine/shared/network.cpp b/src/engine/shared/network.cpp index 7335885d2..9f42b2676 100644 --- a/src/engine/shared/network.cpp +++ b/src/engine/shared/network.cpp @@ -87,46 +87,26 @@ int CNetRecvUnpacker::FetchChunk(CNetChunk *pChunk) } // packs the data tight and sends it -void CNetBase::SendPacketConnless(NETSOCKET Socket, const NETADDR *pAddr, int Version, TOKEN Token, TOKEN ResponseToken, const void *pData, int DataSize) +void CNetBase::SendPacketConnless(NETSOCKET Socket, const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, const void *pData, int DataSize) { unsigned char aBuffer[NET_MAX_PACKETSIZE]; - dbg_assert(NET_PACKETVERSION_LEGACY <= Version && Version <= NET_PACKETVERSION, "CNetBase::SendPacketConnless: packet version out of range"); + dbg_assert(DataSize + 15 <= NET_MAX_PACKETSIZE, "packet data size too high"); + aBuffer[0] = NET_PACKETVERSION; // version + aBuffer[1] = (Token>>24)&0xff; // token + aBuffer[2] = (Token>>16)&0xff; + aBuffer[3] = (Token>>8)&0xff; + aBuffer[4] = (Token)&0xff; + aBuffer[5] = 0xff; // flags and data for not connless packets + aBuffer[6] = 0xff; + aBuffer[7] = 0xff; + aBuffer[8] = (ResponseToken>>24)&0xff; // response token + aBuffer[9] = (ResponseToken>>16)&0xff; + aBuffer[10] = (ResponseToken>>8)&0xff; + aBuffer[11] = (ResponseToken)&0xff; - if(Version == NET_PACKETVERSION_LEGACY) - { - dbg_assert(DataSize + 6 <= NET_MAX_PACKETSIZE, "CNetBase::SendPacketConnless: packet data size too high"); - aBuffer[0] = 0xff; - aBuffer[1] = 0xff; - aBuffer[2] = 0xff; - aBuffer[3] = 0xff; - aBuffer[4] = 0xff; - aBuffer[5] = 0xff; - mem_copy(&aBuffer[6], pData, DataSize); - net_udp_send(Socket, pAddr, aBuffer, 6+DataSize); - } - else - { - dbg_assert(DataSize + 15 <= NET_MAX_PACKETSIZE, "CNetBase::SendPacketConnless: packet data size too high"); - aBuffer[0] = 0x00; // padding - aBuffer[1] = 0x00; - aBuffer[2] = 0x00; - aBuffer[3] = 0x01; // version - aBuffer[4] = (Token>>24)&0xff; // token - aBuffer[5] = (Token>>16)&0xff; - aBuffer[6] = (Token>>8)&0xff; - aBuffer[7] = (Token)&0xff; - aBuffer[8] = 0xff; // flags and data for not connless packets - aBuffer[9] = 0xff; - aBuffer[10] = 0xff; - aBuffer[11] = (ResponseToken>>24)&0xff; // response token - aBuffer[12] = (ResponseToken>>16)&0xff; - aBuffer[13] = (ResponseToken>>8)&0xff; - aBuffer[14] = (ResponseToken)&0xff; - - mem_copy(&aBuffer[15], pData, DataSize); - net_udp_send(Socket, pAddr, aBuffer, 15+DataSize); - } + mem_copy(&aBuffer[15], pData, DataSize); + net_udp_send(Socket, pAddr, aBuffer, 15+DataSize); } void CNetBase::SendPacket(NETSOCKET Socket, const NETADDR *pAddr, CNetPacketConstruct *pPacket) @@ -134,9 +114,6 @@ void CNetBase::SendPacket(NETSOCKET Socket, const NETADDR *pAddr, CNetPacketCons unsigned char aBuffer[NET_MAX_PACKETSIZE]; int CompressedSize = -1; int FinalSize = -1; - int HeaderSize; - - dbg_assert(NET_PACKETVERSION_LEGACY <= pPacket->m_Version && pPacket->m_Version <= NET_PACKETVERSION, "CNetBase::SendPacket: packet version out of range"); // log the data if(ms_DataLogSent) @@ -148,14 +125,9 @@ void CNetBase::SendPacket(NETSOCKET Socket, const NETADDR *pAddr, CNetPacketCons io_flush(ms_DataLogSent); } - if(pPacket->m_Version == NET_PACKETVERSION_LEGACY) - HeaderSize = NET_PACKETHEADERSIZE_LEGACY; - else - HeaderSize = NET_PACKETHEADERSIZE; - // compress if not ctrl msg if(!(pPacket->m_Flags&NET_PACKETFLAG_CONTROL)) - CompressedSize = ms_Huffman.Compress(pPacket->m_aChunkData, pPacket->m_DataSize, &aBuffer[HeaderSize], NET_MAX_PACKETSIZE - HeaderSize - 1); + CompressedSize = ms_Huffman.Compress(pPacket->m_aChunkData, pPacket->m_DataSize, &aBuffer[NET_PACKETHEADERSIZE], NET_MAX_PACKETSIZE - NET_PACKETHEADERSIZE - 1); // check if the compression was enabled, successful and good enough if(CompressedSize > 0 && CompressedSize < pPacket->m_DataSize) @@ -167,34 +139,22 @@ void CNetBase::SendPacket(NETSOCKET Socket, const NETADDR *pAddr, CNetPacketCons { // use uncompressed data FinalSize = pPacket->m_DataSize; - mem_copy(&aBuffer[HeaderSize], pPacket->m_aChunkData, pPacket->m_DataSize); + mem_copy(&aBuffer[NET_PACKETHEADERSIZE], pPacket->m_aChunkData, pPacket->m_DataSize); pPacket->m_Flags &= ~NET_PACKETFLAG_COMPRESSION; } // set header and send the packet if all things are good if(FinalSize >= 0) { - FinalSize += HeaderSize; - if(pPacket->m_Version == NET_PACKETVERSION_LEGACY) - { - aBuffer[0] = ((pPacket->m_Flags<<4)&0xf0)|((pPacket->m_Ack>>8)&0xf); - aBuffer[1] = pPacket->m_Ack&0xff; - aBuffer[2] = pPacket->m_NumChunks; - } - else - { - aBuffer[0] = 0x00; // padding - aBuffer[1] = 0x00; - aBuffer[2] = 0x00; - aBuffer[3] = NET_PACKETVERSION; // version - aBuffer[4] = (pPacket->m_Token>>24)&0xff; // token - aBuffer[5] = (pPacket->m_Token>>16)&0xff; - aBuffer[6] = (pPacket->m_Token>>8)&0xff; - aBuffer[7] = (pPacket->m_Token)&0xff; - aBuffer[8] = ((pPacket->m_Flags<<4)&0xf0)|((pPacket->m_Ack>>8)&0xf); // flags & ack - aBuffer[9] = pPacket->m_Ack&0xff; // ack - aBuffer[10] = pPacket->m_NumChunks; // num_chunks - } + FinalSize += NET_PACKETHEADERSIZE; + aBuffer[0] = NET_PACKETVERSION; // version + aBuffer[1] = (pPacket->m_Token>>24)&0xff; // token + aBuffer[2] = (pPacket->m_Token>>16)&0xff; + aBuffer[3] = (pPacket->m_Token>>8)&0xff; + aBuffer[4] = (pPacket->m_Token)&0xff; + aBuffer[5] = ((pPacket->m_Flags<<4)&0xf0)|((pPacket->m_Ack>>8)&0xf); // flags & ack + aBuffer[6] = pPacket->m_Ack&0xff; // ack + aBuffer[7] = pPacket->m_NumChunks; // num_chunks net_udp_send(Socket, pAddr, aBuffer, FinalSize); @@ -214,7 +174,7 @@ void CNetBase::SendPacket(NETSOCKET Socket, const NETADDR *pAddr, CNetPacketCons int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket) { // check the size - if(Size < NET_PACKETHEADERSIZE_LEGACY || Size > NET_MAX_PACKETSIZE) + if(Size < NET_PACKETHEADERSIZE || Size > NET_MAX_PACKETSIZE) { if(g_Config.m_Debug) dbg_msg("network", "packet too small, size=%d", Size); @@ -231,54 +191,17 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct io_flush(ms_DataLogRecv); } - // determine protocol version - if(pBuffer[0] != 0x00 || pBuffer[1] != 0x00 || pBuffer[2] != 0x00) - { - // legacy packet + if(pBuffer[0] != NET_PACKETVERSION) + return -1; // wrong version, silent ignore - // read the packet - pPacket->m_Version = NET_PACKETVERSION_LEGACY; - pPacket->m_Token = NET_TOKEN_NONE; - pPacket->m_ResponseToken = NET_TOKEN_NONE; + // finally read the packet + pPacket->m_Token = (pBuffer[1]<<24) | (pBuffer[2]<<16) | (pBuffer[3]<<8) | pBuffer[4]; + pPacket->m_ResponseToken = NET_TOKEN_NONE; - pPacket->m_Flags = pBuffer[0]>>4; - pPacket->m_Ack = ((pBuffer[0]&0xf)<<8) | pBuffer[1]; - pPacket->m_NumChunks = pBuffer[2]; - pPacket->m_DataSize = Size - NET_PACKETHEADERSIZE_LEGACY; - } - else - { - // new-style packet - - // check size first - if(Size < NET_PACKETHEADERSIZE_LEGACY + 1) - { - if(g_Config.m_Debug) - dbg_msg("network", "new-style packet too small for version checking, size=%d", Size); - return -1; - } - - if(pBuffer[3] != NET_PACKETVERSION) - return -1; // wrong version, silent ignore - - // check size again - if(Size < NET_PACKETHEADERSIZE) - { - if(g_Config.m_Debug) - dbg_msg("network", "packet too small, size=%d", Size); - return -1; - } - - // finally read the packet - pPacket->m_Version = NET_PACKETVERSION; - pPacket->m_Token = (pBuffer[4]<<24) | (pBuffer[5]<<16) | (pBuffer[6]<<8) | pBuffer[7]; - pPacket->m_ResponseToken = NET_TOKEN_NONE; - - pPacket->m_Flags = pBuffer[8]>>4; - pPacket->m_Ack = ((pBuffer[8]&0xf)<<8) | pBuffer[9]; - pPacket->m_NumChunks = pBuffer[10]; - pPacket->m_DataSize = Size - NET_PACKETHEADERSIZE; - } + pPacket->m_Flags = pBuffer[5]>>4; + pPacket->m_Ack = ((pBuffer[5]&0xf)<<8) | pBuffer[6]; + pPacket->m_NumChunks = pBuffer[7]; + pPacket->m_DataSize = Size - NET_PACKETHEADERSIZE; if(pPacket->m_Flags&NET_PACKETFLAG_CONNLESS) @@ -286,41 +209,20 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct pPacket->m_Flags = NET_PACKETFLAG_CONNLESS; pPacket->m_Ack = 0; pPacket->m_NumChunks = 0; - if(pPacket->m_Version == NET_PACKETVERSION_LEGACY) + if(Size < NET_PACKETHEADERSIZE_CONNLESS) { - if(Size < 6) - { - if(g_Config.m_Debug) - dbg_msg("net", "connless packet too small, size=%d", Size); - return -1; - } - - pPacket->m_DataSize = Size - 6; - mem_copy(pPacket->m_aChunkData, &pBuffer[6], pPacket->m_DataSize); + if(g_Config.m_Debug) + dbg_msg("net", "connless packet too small, size=%d", Size); + return -1; } - else - { - if(Size < 15) - { - if(g_Config.m_Debug) - dbg_msg("net", "new-style connless packet too small, size=%d", Size); - return -1; - } - pPacket->m_DataSize = Size - 15; - pPacket->m_ResponseToken = (pBuffer[11]<<24) | (pBuffer[12]<<16) | (pBuffer[13]<<8) | pBuffer[14]; - mem_copy(pPacket->m_aChunkData, &pBuffer[15], pPacket->m_DataSize); - } + pPacket->m_DataSize = Size - NET_PACKETHEADERSIZE_CONNLESS; + pPacket->m_ResponseToken = (pBuffer[8]<<24) | (pBuffer[9]<<16) | (pBuffer[10]<<8) | pBuffer[11]; + mem_copy(pPacket->m_aChunkData, &pBuffer[NET_PACKETHEADERSIZE_CONNLESS], pPacket->m_DataSize); } else { - int DataStart; - if(pPacket->m_Version == NET_PACKETVERSION_LEGACY) - DataStart = NET_PACKETHEADERSIZE_LEGACY; - else - DataStart = NET_PACKETHEADERSIZE; - - if(Size - DataStart > NET_MAX_PAYLOAD) + if(Size - NET_PACKETHEADERSIZE > NET_MAX_PAYLOAD) { if(g_Config.m_Debug) dbg_msg("network", "packet payload too big, size=%d", Size); @@ -328,9 +230,9 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct } if(pPacket->m_Flags&NET_PACKETFLAG_COMPRESSION) - pPacket->m_DataSize = ms_Huffman.Decompress(&pBuffer[DataStart], pPacket->m_DataSize, pPacket->m_aChunkData, sizeof(pPacket->m_aChunkData)); + pPacket->m_DataSize = ms_Huffman.Decompress(&pBuffer[NET_PACKETHEADERSIZE], pPacket->m_DataSize, pPacket->m_aChunkData, sizeof(pPacket->m_aChunkData)); else - mem_copy(pPacket->m_aChunkData, &pBuffer[DataStart], pPacket->m_DataSize); + mem_copy(pPacket->m_aChunkData, &pBuffer[NET_PACKETHEADERSIZE], pPacket->m_DataSize); } // check for errors @@ -342,7 +244,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct } // set the response token (a bit hacky because this function doesn't know about control packets) - if(pPacket->m_Version == NET_PACKETVERSION && (pPacket->m_Flags&NET_PACKETFLAG_CONTROL)) + if(pPacket->m_Flags&NET_PACKETFLAG_CONTROL) { if(pPacket->m_DataSize >= 5) // control byte + token { @@ -370,10 +272,9 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct } -void CNetBase::SendControlMsg(NETSOCKET Socket, const NETADDR *pAddr, int Version, TOKEN Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize) +void CNetBase::SendControlMsg(NETSOCKET Socket, const NETADDR *pAddr, TOKEN Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize) { CNetPacketConstruct Construct; - Construct.m_Version = Version; Construct.m_Token = Token; Construct.m_Flags = NET_PACKETFLAG_CONTROL; Construct.m_Ack = Ack; @@ -395,7 +296,7 @@ void CNetBase::SendControlMsgWithToken(NETSOCKET Socket, const NETADDR *pAddr, T aToken[2] = (MyToken>>8)&0xff; aToken[3] = (MyToken)&0xff; - SendControlMsg(Socket, pAddr, NET_PACKETVERSION, Token, 0, ControlMsg, aToken, sizeof(aToken)); + SendControlMsg(Socket, pAddr, Token, 0, ControlMsg, aToken, sizeof(aToken)); } unsigned char *CNetChunkHeader::Pack(unsigned char *pData) diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index 473a4b9c4..8f8f9f317 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -9,8 +9,7 @@ /* CURRENT: - packet header: 11 bytes (15 bytes for connless) - unsigned char padding[3]; // 24bit extra (must be 0x000000) to ensure compatiblity with the 0.5/0.6 protocol + packet header: 8 bytes (12 bytes for connless) unsigned char version; // 8bit version (must be 0x01) unsigned char token[4]; // 32bit token (0xffffffff means none) unsigned char flags_ack; // 4bit flags, 4bit ack (0xff for connless packets) @@ -19,15 +18,6 @@ CURRENT: (unsigned char response_token[4];) // 32bit response token (only in case it's a connless packet) - legacy packet header: 3 bytes (6 bytes for connless) - unsigned char flags_ack; // 4bit flags, 4bit ack - unsigned char ack; // 8bit ack - unsigned char num_chunks; // 8bit chunks - - (unsigned char padding[3];) // 24bit extra incase it's a connection less packet - // this is to make sure that it's compatible with the - // old protocol - chunk header: 2-3 bytes unsigned char flags_size; // 2bit flags, 6 bit size unsigned char size_seq; // 6bit size, 2bit seq @@ -37,7 +27,6 @@ CURRENT: enum { NETFLAG_ALLOWSTATELESS=1, - NETFLAG_ALLOWOLDSTYLE=2, NETSENDFLAG_VITAL=1, NETSENDFLAG_CONNLESS=2, NETSENDFLAG_FLUSH=4, @@ -62,8 +51,8 @@ enum NET_MAX_PACKETSIZE = 1400, NET_MAX_PAYLOAD = NET_MAX_PACKETSIZE-15, NET_MAX_CHUNKHEADERSIZE = 3, - NET_PACKETHEADERSIZE = 11, - NET_PACKETHEADERSIZE_LEGACY = 3, + NET_PACKETHEADERSIZE = 8, + NET_PACKETHEADERSIZE_CONNLESS = NET_PACKETHEADERSIZE + 4, NET_TOKENCACHE_SIZE = 16, NET_TOKENCACHE_ADDRESSEXPIRY = NET_SEEDTIME/2, NET_TOKENCACHE_PACKETEXPIRY = NET_TOKENCACHE_ADDRESSEXPIRY, @@ -80,7 +69,6 @@ enum NET_CONNSTATE_ONLINE=4, NET_CONNSTATE_ERROR=5, - NET_PACKETVERSION_LEGACY=0, NET_PACKETVERSION=1, NET_PACKETFLAG_CONTROL=1, @@ -146,7 +134,6 @@ public: class CNetPacketConstruct { public: - int m_Version; TOKEN m_Token; TOKEN m_ResponseToken; // only used in connless packets int m_Flags; @@ -386,8 +373,8 @@ public: int Close(); // the token and version parameter are only used for connless packets - int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0, int *pVersion = 0); - int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE, int Version = NET_PACKETVERSION); + int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0); + int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE); int Update(); // @@ -465,8 +452,8 @@ public: int Connect(NETADDR *Addr); // communication - int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0, int *pVersion = 0); - int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE, int Version = NET_PACKETVERSION); + int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0); + int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE); // pumping int Update(); @@ -496,9 +483,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, const NETADDR *pAddr, int Version, TOKEN Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize); + static void SendControlMsg(NETSOCKET Socket, const NETADDR *pAddr, TOKEN Token, int Ack, int ControlMsg, const void *pExtra, int ExtraSize); static void SendControlMsgWithToken(NETSOCKET Socket, const NETADDR *pAddr, TOKEN Token, int Ack, int ControlMsg, TOKEN MyToken); - static void SendPacketConnless(NETSOCKET Socket, const NETADDR *pAddr, int Version, TOKEN Token, TOKEN ResponseToken, const void *pData, int DataSize); + static void SendPacketConnless(NETSOCKET Socket, const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, const void *pData, int DataSize); static void SendPacket(NETSOCKET Socket, const 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 18f5d9b3c..24f990bb3 100644 --- a/src/engine/shared/network_client.cpp +++ b/src/engine/shared/network_client.cpp @@ -61,7 +61,7 @@ int CNetClient::ResetErrorString() return 0; } -int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) +int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken) { while(1) { @@ -97,7 +97,6 @@ int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) } else { - int Accept = m_TokenManager.ProcessMessage(&Addr, &m_RecvUnpacker.m_Data, false); if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL) { if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN) @@ -105,9 +104,7 @@ int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) } else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS) { - if(!(m_Flags&NETFLAG_ALLOWOLDSTYLE) && m_RecvUnpacker.m_Data.m_Version != NET_PACKETVERSION) - continue; - + int Accept = m_TokenManager.ProcessMessage(&Addr, &m_RecvUnpacker.m_Data, false); if(!Accept) continue; @@ -124,8 +121,6 @@ int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) pChunk->m_DataSize = m_RecvUnpacker.m_Data.m_DataSize; pChunk->m_pData = m_RecvUnpacker.m_Data.m_aChunkData; - if(pVersion) - *pVersion = m_RecvUnpacker.m_Data.m_Version; if(pResponseToken) *pResponseToken = m_RecvUnpacker.m_Data.m_ResponseToken; return 1; @@ -136,15 +131,8 @@ int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) return 0; } -int CNetClient::Send(CNetChunk *pChunk, TOKEN Token, int Version) +int CNetClient::Send(CNetChunk *pChunk, TOKEN Token) { - if(Version != NET_PACKETVERSION) - { - dbg_assert(m_Flags&NETFLAG_ALLOWOLDSTYLE && m_Flags&NETFLAG_ALLOWSTATELESS, "oldstyle packet sending not enabled"); - dbg_assert(pChunk->m_Flags&NETSENDFLAG_CONNLESS && pChunk->m_ClientID == -1, "only connless packets allowed for oldstyle network"); - dbg_assert(pChunk->m_Flags&NETSENDFLAG_STATELESS && Token == NET_TOKEN_NONE, "tokens can't be used in oldstyle packets"); - } - if(pChunk->m_Flags&NETSENDFLAG_CONNLESS) { if(pChunk->m_DataSize >= NET_MAX_PAYLOAD) @@ -160,7 +148,7 @@ int CNetClient::Send(CNetChunk *pChunk, TOKEN Token, int Version) dbg_assert(pChunk->m_ClientID == -1, "errornous client id, connless packets can only be sent to cid=-1"); dbg_assert(Token == NET_TOKEN_NONE, "stateless packets can't have a token"); } - CNetBase::SendPacketConnless(m_Socket, &pChunk->m_Address, Version, Token, m_TokenManager.GenerateToken(&pChunk->m_Address), pChunk->m_pData, pChunk->m_DataSize); + CNetBase::SendPacketConnless(m_Socket, &pChunk->m_Address, Token, m_TokenManager.GenerateToken(&pChunk->m_Address), pChunk->m_pData, pChunk->m_DataSize); } else { diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index 53d7ad1c4..7d94d5217 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -93,7 +93,6 @@ int CNetConnection::Flush() // send of the packets m_Construct.m_Ack = m_Ack; m_Construct.m_Token = m_PeerToken; - m_Construct.m_Version = NET_PACKETVERSION; CNetBase::SendPacket(m_Socket, &m_PeerAddr, &m_Construct); // update send times @@ -164,12 +163,12 @@ void CNetConnection::SendControl(int ControlMsg, const void *pExtra, int ExtraSi { // send the control message m_LastSendTime = time_get(); - CNetBase::SendControlMsg(m_Socket, &m_PeerAddr, NET_PACKETVERSION, m_PeerToken, m_Ack, ControlMsg, pExtra, ExtraSize); + CNetBase::SendControlMsg(m_Socket, &m_PeerAddr, m_PeerToken, m_Ack, ControlMsg, pExtra, ExtraSize); } void CNetConnection::SendPacketConnless(const char *pData, int DataSize) { - CNetBase::SendPacketConnless(m_Socket, &m_PeerAddr, NET_PACKETVERSION, m_PeerToken, m_Token, pData, DataSize); + CNetBase::SendPacketConnless(m_Socket, &m_PeerAddr, m_PeerToken, m_Token, pData, DataSize); } void CNetConnection::SendControlWithToken(int ControlMsg) @@ -247,9 +246,6 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr) int64 Now = time_get(); - if(pPacket->m_Version != NET_PACKETVERSION) - return 0; - if(pPacket->m_Token == NET_TOKEN_NONE || pPacket->m_Token != m_Token) return 0; diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index cf3f852a9..0b9aca0ef 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -99,7 +99,7 @@ int CNetServer::Update() /* TODO: chopp up this function into smaller working parts */ -int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) +int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken) { while(1) { @@ -150,7 +150,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf))) { // banned, reply with a message - CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_Version, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf)+1); + CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf)+1); continue; } @@ -181,7 +181,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "Only %d players with the same IP are allowed", m_MaxClientsPerIP); - CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_Version, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, aBuf, sizeof(aBuf)); + CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, aBuf, sizeof(aBuf)); return 0; } } @@ -204,7 +204,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) if(!Found) { const char FullMsg[] = "This server is full"; - CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_Version, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, FullMsg, sizeof(FullMsg)); + CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, FullMsg, sizeof(FullMsg)); } } else if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN) @@ -212,8 +212,6 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) } else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS) { - if(!(m_Flags&NETFLAG_ALLOWOLDSTYLE) && m_RecvUnpacker.m_Data.m_Version != NET_PACKETVERSION) - continue; pChunk->m_Flags = NETSENDFLAG_CONNLESS; if(Accept < 0) { @@ -225,8 +223,6 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) pChunk->m_Address = Addr; pChunk->m_DataSize = m_RecvUnpacker.m_Data.m_DataSize; pChunk->m_pData = m_RecvUnpacker.m_Data.m_aChunkData; - if(pVersion) - *pVersion = m_RecvUnpacker.m_Data.m_Version; if(pResponseToken) *pResponseToken = m_RecvUnpacker.m_Data.m_ResponseToken; return 1; @@ -255,7 +251,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "Only %d players with the same IP are allowed", m_MaxClientsPerIP); - CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_Version, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, aBuf, sizeof(aBuf)); + CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, aBuf, sizeof(aBuf)); return 0; } } @@ -278,7 +274,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) if(!Found) { const char FullMsg[] = "This server is full"; - CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_Version, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, FullMsg, sizeof(FullMsg)); + CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, FullMsg, sizeof(FullMsg)); } } } @@ -287,15 +283,8 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken, int *pVersion) return 0; } -int CNetServer::Send(CNetChunk *pChunk, TOKEN Token, int Version) +int CNetServer::Send(CNetChunk *pChunk, TOKEN Token) { - if(Version != NET_PACKETVERSION) - { - dbg_assert(m_Flags&NETFLAG_ALLOWOLDSTYLE && m_Flags&NETFLAG_ALLOWSTATELESS, "oldstyle packet sending not enabled"); - dbg_assert(pChunk->m_Flags&NETSENDFLAG_CONNLESS && pChunk->m_ClientID == -1, "only connless packets allowed for oldstyle network"); - dbg_assert(pChunk->m_Flags&NETSENDFLAG_STATELESS && Token == NET_TOKEN_NONE, "tokens can't be used in oldstyle packets"); - } - if(pChunk->m_Flags&NETSENDFLAG_CONNLESS) { if(pChunk->m_DataSize >= NET_MAX_PAYLOAD) @@ -311,7 +300,7 @@ int CNetServer::Send(CNetChunk *pChunk, TOKEN Token, int Version) dbg_assert(pChunk->m_ClientID == -1, "errornous client id, connless packets can only be sent to cid=-1"); dbg_assert(Token == NET_TOKEN_NONE, "stateless packets can't have a token"); } - CNetBase::SendPacketConnless(m_Socket, &pChunk->m_Address, Version, Token, m_TokenManager.GenerateToken(&pChunk->m_Address), pChunk->m_pData, pChunk->m_DataSize); + CNetBase::SendPacketConnless(m_Socket, &pChunk->m_Address, Token, m_TokenManager.GenerateToken(&pChunk->m_Address), pChunk->m_pData, pChunk->m_DataSize); } else { diff --git a/src/engine/shared/network_token.cpp b/src/engine/shared/network_token.cpp index 457d13763..6e60db2d9 100644 --- a/src/engine/shared/network_token.cpp +++ b/src/engine/shared/network_token.cpp @@ -174,8 +174,8 @@ void CNetTokenCache::SendPacketConnless(const NETADDR *pAddr, const void *pData, TOKEN Token = GetToken(pAddr); if(Token != NET_TOKEN_NONE) { - CNetBase::SendPacketConnless(m_Socket, pAddr, NET_PACKETVERSION, - Token, m_pTokenManager->GenerateToken(pAddr), pData, DataSize); + CNetBase::SendPacketConnless(m_Socket, pAddr, Token, + m_pTokenManager->GenerateToken(pAddr), pData, DataSize); } else { @@ -232,8 +232,7 @@ void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token) { if(net_addr_comp(&pInfo->m_Addr, pAddr) == 0) { - CNetBase::SendPacketConnless(m_Socket, pAddr, - NET_PACKETVERSION, Token, + CNetBase::SendPacketConnless(m_Socket, pAddr, Token, m_pTokenManager->GenerateToken(pAddr), pInfo->m_aData, pInfo->m_DataSize); *ppPrevNext = pInfo->m_pNext;