Permalink
Browse files

force vital check on essential cl/srv messages and added additional s…

…equence checking
1 parent 7c43b76 commit f457b58d68e72df83128a7bc779d71a5208dfe47 @oy oy committed Mar 19, 2015
@@ -1026,7 +1026,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
if(Sys)
{
// system message
- if(Msg == NETMSG_MAP_CHANGE)
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_MAP_CHANGE)
{
const char *pMap = Unpacker.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
int MapCrc = Unpacker.GetInt();
@@ -1089,7 +1089,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
}
}
}
- else if(Msg == NETMSG_MAP_DATA)
+ else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_MAP_DATA)
{
int Last = Unpacker.GetInt();
int MapCRC = Unpacker.GetInt();
@@ -1143,7 +1143,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
}
}
}
- else if(Msg == NETMSG_CON_READY)
+ else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_CON_READY)
{
GameClient()->OnConnected();
}
@@ -1152,21 +1152,21 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
CMsgPacker Msg(NETMSG_PING_REPLY);
SendMsgEx(&Msg, 0);
}
- else if(Msg == NETMSG_RCON_CMD_ADD)
+ else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_RCON_CMD_ADD)
{
const char *pName = Unpacker.GetString(CUnpacker::SANITIZE_CC);
const char *pHelp = Unpacker.GetString(CUnpacker::SANITIZE_CC);
const char *pParams = Unpacker.GetString(CUnpacker::SANITIZE_CC);
if(Unpacker.Error() == 0)
m_pConsole->RegisterTemp(pName, pParams, CFGFLAG_SERVER, pHelp);
}
- else if(Msg == NETMSG_RCON_CMD_REM)
+ else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_RCON_CMD_REM)
{
const char *pName = Unpacker.GetString(CUnpacker::SANITIZE_CC);
if(Unpacker.Error() == 0)
m_pConsole->DeregisterTemp(pName);
}
- else if(Msg == NETMSG_RCON_AUTH_STATUS)
+ else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_RCON_AUTH_STATUS)
{
int Result = Unpacker.GetInt();
if(Unpacker.Error() == 0)
@@ -1178,7 +1178,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
if(Old != 0 && m_UseTempRconCommands == 0)
m_pConsole->DeregisterTempAll();
}
- else if(Msg == NETMSG_RCON_LINE)
+ else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_RCON_LINE)
{
const char *pLine = Unpacker.GetString();
if(Unpacker.Error() == 0)
@@ -1400,11 +1400,14 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
}
else
{
- // game message
- if(m_DemoRecorder.IsRecording())
- m_DemoRecorder.RecordMessage(pPacket->m_pData, pPacket->m_DataSize);
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0)
+ {
+ // game message
+ if(m_DemoRecorder.IsRecording())
+ m_DemoRecorder.RecordMessage(pPacket->m_pData, pPacket->m_DataSize);
- GameClient()->OnMessage(Msg, &Unpacker);
+ GameClient()->OnMessage(Msg, &Unpacker);
+ }
}
}
@@ -815,7 +815,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
// system message
if(Msg == NETMSG_INFO)
{
- if(m_aClients[ClientID].m_State == CClient::STATE_AUTH)
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && m_aClients[ClientID].m_State == CClient::STATE_AUTH)
{
const char *pVersion = Unpacker.GetString(CUnpacker::SANITIZE_CC);
if(str_comp(pVersion, GameServer()->NetVersion()) != 0)
@@ -841,7 +841,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
}
else if(Msg == NETMSG_REQUEST_MAP_DATA)
{
- if(m_aClients[ClientID].m_State < CClient::STATE_CONNECTING)
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) == 0 || m_aClients[ClientID].m_State < CClient::STATE_CONNECTING)
return;
int Chunk = Unpacker.GetInt();
@@ -878,7 +878,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
}
else if(Msg == NETMSG_READY)
{
- if(m_aClients[ClientID].m_State == CClient::STATE_CONNECTING)
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && m_aClients[ClientID].m_State == CClient::STATE_CONNECTING)
{
char aAddrStr[NETADDR_MAXSTRSIZE];
net_addr_str(m_NetServer.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true);
@@ -893,7 +893,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
}
else if(Msg == NETMSG_ENTERGAME)
{
- if(m_aClients[ClientID].m_State == CClient::STATE_READY && GameServer()->IsClientReady(ClientID))
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && m_aClients[ClientID].m_State == CClient::STATE_READY && GameServer()->IsClientReady(ClientID))
{
char aAddrStr[NETADDR_MAXSTRSIZE];
net_addr_str(m_NetServer.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true);
@@ -961,7 +961,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
{
const char *pCmd = Unpacker.GetString();
- if(Unpacker.Error() == 0 && m_aClients[ClientID].m_Authed)
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Unpacker.Error() == 0 && m_aClients[ClientID].m_Authed)
{
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "ClientID=%d rcon='%s'", ClientID, pCmd);
@@ -981,7 +981,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
Unpacker.GetString(); // login name, not used
pPw = Unpacker.GetString(CUnpacker::SANITIZE_CC);
- if(Unpacker.Error() == 0)
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Unpacker.Error() == 0)
{
if(g_Config.m_SvRconPassword[0] == 0 && g_Config.m_SvRconModPassword[0] == 0)
{
@@ -1069,7 +1069,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
else
{
// game message
- if(m_aClients[ClientID].m_State >= CClient::STATE_READY)
+ if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && m_aClients[ClientID].m_State >= CClient::STATE_READY)
GameServer()->OnMessage(Msg, &Unpacker, ClientID);
}
}
@@ -80,7 +80,7 @@ int CNetRecvUnpacker::FetchChunk(CNetChunk *pChunk)
// fill in the info
pChunk->m_ClientID = m_ClientID;
pChunk->m_Address = m_Addr;
- pChunk->m_Flags = 0;
+ pChunk->m_Flags = Header.m_Flags;
pChunk->m_DataSize = Header.m_Size;
pChunk->m_pData = pData;
return 1;
@@ -138,6 +138,7 @@ class CNetConnection
private:
unsigned short m_Sequence;
unsigned short m_Ack;
+ unsigned short m_PeerAck;
unsigned m_State;
int m_Token;
@@ -13,6 +13,7 @@ void CNetConnection::Reset()
{
m_Sequence = 0;
m_Ack = 0;
+ m_PeerAck = 0;
m_RemoteClosed = 0;
m_State = NET_CONNSTATE_OFFLINE;
@@ -196,6 +197,19 @@ void CNetConnection::Disconnect(const char *pReason)
int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
{
+ // check if actual ack value is valid(own sequence..latest peer ack)
+ if(m_Sequence >= m_PeerAck)
+ {
+ if(pPacket->m_Ack < m_PeerAck || pPacket->m_Ack > m_Sequence)
+ return 0;
+ }
+ else
+ {
+ if(pPacket->m_Ack < m_PeerAck && pPacket->m_Ack > m_Sequence)
+ return 0;
+ }
+ m_PeerAck = pPacket->m_Ack;
+
int64 Now = time_get();
// check if resend is requested
@@ -342,7 +342,7 @@ void CCharacter::FireWeapon()
for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++)
Msg.AddInt(((int *)&p)[i]);
- Server()->SendMsg(&Msg, 0, m_pPlayer->GetCID());
+ Server()->SendMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
GameServer()->CreateSound(m_Pos, SOUND_GUN_FIRE);
} break;
@@ -376,7 +376,7 @@ void CCharacter::FireWeapon()
Msg.AddInt(((int *)&p)[i]);
}
- Server()->SendMsg(&Msg, 0,m_pPlayer->GetCID());
+ Server()->SendMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE);
} break;
@@ -398,7 +398,7 @@ void CCharacter::FireWeapon()
Msg.AddInt(1);
for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++)
Msg.AddInt(((int *)&p)[i]);
- Server()->SendMsg(&Msg, 0, m_pPlayer->GetCID());
+ Server()->SendMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
GameServer()->CreateSound(m_Pos, SOUND_GRENADE_FIRE);
} break;

6 comments on commit f457b58

@pelya
pelya commented on f457b58 Aug 18, 2015

This change breaks map downloading in 0.6 branch because NETMSG_MAP_DATA is never sent with NET_CHUNKFLAG_VITAL.

@east
east commented on f457b58 Aug 19, 2015

Are you sure? I looked at older tags, even on 0.6.0-release NETMSG_MAP_DATA is sent with NET_CHUNKFLAG_VITAL. Forcing VITAL on map data though breaks support with a bunch of modifications online.

@pelya
pelya commented on f457b58 Aug 19, 2015
@east
east commented on f457b58 Aug 19, 2015

Yes, that's because map download is modded there to increase the speed. (fastdl)

Forcing VITAL on map data though breaks support with a bunch of modifications online.

@pelya
pelya commented on f457b58 Aug 19, 2015
@east
east commented on f457b58 Aug 19, 2015

Well, I personally wouldn't do that, it's Oy's choice though.

Please sign in to comment.