diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index fae575f38..eeeb25075 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -367,6 +367,23 @@ CClient::CClient() : m_DemoPlayer(&m_SnapshotDelta) } // ----- send functions ----- +static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer) +{ + Packer.Reset(); + if(pMsg->m_MsgID < OFFSET_UUID) + { + Packer.AddInt((pMsg->m_MsgID<<1)|(pMsg->m_System?1:0)); + } + else + { + Packer.AddInt((0<<1)|(pMsg->m_System?1:0)); // NETMSG_EX, NETMSGTYPE_EX + g_UuidManager.PackUuid(pMsg->m_MsgID, &Packer); + } + Packer.AddRaw(pMsg->Data(), pMsg->Size()); + + return false; +} + int CClient::SendMsg(CMsgPacker *pMsg, int Flags) { CNetChunk Packet; @@ -374,10 +391,15 @@ int CClient::SendMsg(CMsgPacker *pMsg, int Flags) if(State() == IClient::STATE_OFFLINE) return 0; + // repack message (inefficient) + CPacker Pack; + if(RepackMsg(pMsg, Pack)) + return 0; + mem_zero(&Packet, sizeof(CNetChunk)); Packet.m_ClientID = 0; - Packet.m_pData = pMsg->Data(); - Packet.m_DataSize = pMsg->Size(); + Packet.m_pData = Pack.Data(); + Packet.m_DataSize = Pack.Size(); if(Flags&MSGFLAG_VITAL) Packet.m_Flags |= NETSENDFLAG_VITAL; @@ -841,11 +863,15 @@ int CClient::SendMsgY(CMsgPacker *pMsg, int Flags, int NetClient) { CNetChunk Packet; - mem_zero(&Packet, sizeof(CNetChunk)); + // repack message (inefficient) + CPacker Pack; + if(RepackMsg(pMsg, Pack)) + return 0; + mem_zero(&Packet, sizeof(CNetChunk)); Packet.m_ClientID = 0; - Packet.m_pData = pMsg->Data(); - Packet.m_DataSize = pMsg->Size(); + Packet.m_pData = Pack.Data(); + Packet.m_DataSize = Pack.Size(); if(Flags&MSGFLAG_VITAL) Packet.m_Flags |= NETSENDFLAG_VITAL; diff --git a/src/engine/message.h b/src/engine/message.h index 75454c232..55d800bf2 100644 --- a/src/engine/message.h +++ b/src/engine/message.h @@ -9,18 +9,11 @@ class CMsgPacker : public CPacker { public: - CMsgPacker(int Type, bool System=false) + int m_MsgID; + bool m_System; + CMsgPacker(int Type, bool System=false) : m_MsgID(Type), m_System(System) { Reset(); - if(Type < OFFSET_UUID) - { - AddInt((Type<<1)|(System?1:0)); - } - else - { - AddInt((0<<1)|(System?1:0)); // NETMSG_EX, NETMSGTYPE_EX - g_UuidManager.PackUuid(Type, this); - } } }; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 89c4919fd..e76604567 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -646,16 +646,77 @@ int CServer::DistinctClientCount() return ClientCount; } +static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer, bool Sixup) +{ + int MsgId = pMsg->m_MsgID; + Packer.Reset(); + if(MsgId < OFFSET_UUID) + { + if(Sixup) + { + if(pMsg->m_System) + { + if(MsgId >= NETMSG_MAP_CHANGE && MsgId <= NETMSG_MAP_DATA) + ; + else if(MsgId >= NETMSG_CON_READY && MsgId <= NETMSG_INPUTTIMING) + MsgId += 1; + else if(MsgId >= NETMSG_AUTH_CHALLANGE && MsgId <= NETMSG_AUTH_RESULT) + MsgId += 4; + else if(MsgId >= NETMSG_PING && MsgId <= NETMSG_ERROR) + MsgId += 4; + else if(MsgId > 24) + MsgId -= 24; + else + { + dbg_msg("net", "DROP send sys %d", MsgId); + return true; + } + } + else + { + if(MsgId >= NETMSGTYPE_SV_MOTD && MsgId <= NETMSGTYPE_SV_CHAT) + ; + else if(MsgId == NETMSGTYPE_SV_KILLMSG) + MsgId += 1; + else if(MsgId >= NETMSGTYPE_SV_TUNEPARAMS && MsgId <= NETMSGTYPE_SV_VOTESTATUS) + ; + else if(MsgId > 24) + MsgId -= 24; + else + { + dbg_msg("net", "DROP send game %d", MsgId); + return true; + } + } + } + + Packer.AddInt((MsgId<<1)|(pMsg->m_System?1:0)); + } + else if(!Sixup) + { + Packer.AddInt((0<<1)|(pMsg->m_System?1:0)); // NETMSG_EX, NETMSGTYPE_EX + g_UuidManager.PackUuid(MsgId, &Packer); + } + Packer.AddRaw(pMsg->Data(), pMsg->Size()); + + return false; +} + int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) { CNetChunk Packet; if(!pMsg) return -1; + // repack message (inefficient) + CPacker Pack; + if(RepackMsg(pMsg, Pack, m_aClients[ClientID].m_Sixup)) + return 0; + mem_zero(&Packet, sizeof(CNetChunk)); Packet.m_ClientID = ClientID; - Packet.m_pData = pMsg->Data(); - Packet.m_DataSize = pMsg->Size(); + Packet.m_pData = Pack.Data(); + Packet.m_DataSize = Pack.Size(); if(Flags&MSGFLAG_VITAL) Packet.m_Flags |= NETSENDFLAG_VITAL; @@ -666,8 +727,8 @@ int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) if(!(Flags&MSGFLAG_NORECORD)) { if(ClientID > -1) - m_aDemoRecorder[ClientID].RecordMessage(pMsg->Data(), pMsg->Size()); - m_aDemoRecorder[MAX_CLIENTS].RecordMessage(pMsg->Data(), pMsg->Size()); + m_aDemoRecorder[ClientID].RecordMessage(Pack.Data(), Pack.Size()); + m_aDemoRecorder[MAX_CLIENTS].RecordMessage(Pack.Data(), Pack.Size()); } if(!(Flags&MSGFLAG_NOSEND)) diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index bf18a7dd2..69c8807e4 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -77,49 +77,6 @@ static unsigned char MsgTypeFromSixup(unsigned char Byte) return (Msg<<1) | (Byte&1); } -static unsigned char MsgTypeToSixup(unsigned char Byte) -{ - unsigned char Msg = Byte>>1; - unsigned char Six; - if (Byte&1) - { - if(Msg >= NETMSG_MAP_CHANGE && Msg <= NETMSG_MAP_DATA) - Six = Msg; - else if(Msg >= NETMSG_CON_READY && Msg <= NETMSG_INPUTTIMING) - Six = Msg + 1; - else if(Msg >= NETMSG_AUTH_CHALLANGE && Msg <= NETMSG_AUTH_RESULT) - Six = Msg + 4; - else if(Msg >= NETMSG_PING && Msg <= NETMSG_ERROR) - Six = Msg + 4; - else if(Msg > 24) - Six = Msg - 24; - else - { - dbg_msg("net", "DROP send sys %d", Msg); - return 0; - } - //dbg_msg("net", "send sys %d -> %d", Msg, Six); - } - else - { - if(Msg >= NETMSGTYPE_SV_MOTD && Msg <= NETMSGTYPE_SV_CHAT) - Six = Msg; - else if(Msg == NETMSGTYPE_SV_KILLMSG) - Six = Msg + 1; - else if(Msg >= NETMSGTYPE_SV_TUNEPARAMS && Msg <= NETMSGTYPE_SV_VOTESTATUS) - Six = Msg; - else if(Msg > 24) - Six = Msg - 24; - else - { - dbg_msg("net", "DROP send msg %d", Msg); - return 0; - } - //dbg_msg("net", "send msg %d -> %d", Msg, Six); - } - return (Six<<1) | (Byte&1); -} - static SECURITY_TOKEN ToSecurityToken(const unsigned char *pData) { return (int)pData[0] | (pData[1] << 8) | (pData[2] << 16) | (pData[3] << 24); @@ -813,13 +770,6 @@ int CNetServer::Send(CNetChunk *pChunk) dbg_assert(pChunk->m_ClientID >= 0, "errornous client id"); dbg_assert(pChunk->m_ClientID < MaxClients(), "errornous client id"); - if(m_aSlots[pChunk->m_ClientID].m_Connection.m_Sixup) - { - unsigned int MsgType = MsgTypeToSixup(*(unsigned char*)pChunk->m_pData); - if (MsgType == 0) return 0; - *(unsigned char*)pChunk->m_pData = MsgType; - } - if(pChunk->m_Flags&NETSENDFLAG_VITAL) Flags = NET_CHUNKFLAG_VITAL; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index e53f1ddb7..107bb4bb1 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1111,6 +1111,7 @@ void CGameContext::OnClientEnter(int ClientID) Server()->ExpireServerInfo(); // update client infos (others before local) + dbg_msg("debug", "sending info"); for(int i = 0; i < MAX_CLIENTS; ++i) { if(i == ClientID || !m_apPlayers[i] || !Server()->ClientIngame(i))