From caa1f15d1293ff4cb6f9bc0fa2de450155d240b7 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 30 Jan 2014 16:54:58 +0100 Subject: [PATCH] Fix possible crashes --- src/engine/server/server.cpp | 6 ++++-- src/game/server/gamecontext.cpp | 6 +++--- src/game/server/gameworld.cpp | 3 ++- src/game/server/player.cpp | 3 ++- src/game/server/teams.cpp | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index e811f5b08..a1099ce9b 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -478,7 +478,8 @@ int CServer::GetClientInfo(int ClientID, CClientInfo *pInfo) pInfo->m_pName = m_aClients[ClientID].m_aName; pInfo->m_Latency = m_aClients[ClientID].m_Latency; CGameContext *GameServer = (CGameContext *) m_pGameServer; - pInfo->m_ClientVersion = GameServer->m_apPlayers[ClientID]->m_ClientVersion; + if (GameServer->m_apPlayers[ClientID]) + pInfo->m_ClientVersion = GameServer->m_apPlayers[ClientID]->m_ClientVersion; return 1; } return 0; @@ -1041,7 +1042,8 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) if(Unpacker.Error() == 0 && !str_comp(pCmd, "crashmeplx")) { CGameContext *GameServer = (CGameContext *) m_pGameServer; - GameServer->m_apPlayers[ClientID]->m_ClientVersion = VERSION_DDNET_OLD; + if (GameServer->m_apPlayers[ClientID]) + GameServer->m_apPlayers[ClientID]->m_ClientVersion = VERSION_DDNET_OLD; } else if(Unpacker.Error() == 0 && m_aClients[ClientID].m_Authed) { diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index f6426451a..ed8d6046e 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -406,7 +406,7 @@ void CGameContext::SendVoteSet(int ClientID) void CGameContext::SendVoteStatus(int ClientID, int Total, int Yes, int No) { - if (Total > VANILLA_MAX_CLIENTS && m_apPlayers[ClientID]->m_ClientVersion <= VERSION_DDRACE) + if (Total > VANILLA_MAX_CLIENTS && m_apPlayers[ClientID] && m_apPlayers[ClientID]->m_ClientVersion <= VERSION_DDRACE) { Yes = float(Yes) * VANILLA_MAX_CLIENTS / float(Total); No = float(No) * VANILLA_MAX_CLIENTS / float(Total); @@ -2519,7 +2519,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, char *pMessage) char aBuf[256]; - if (m_apPlayers[ClientID]->m_ClientVersion >= VERSION_DDNET_WHISPER) + if (m_apPlayers[ClientID] && m_apPlayers[ClientID]->m_ClientVersion >= VERSION_DDNET_WHISPER) { CNetMsg_Sv_Chat Msg; Msg.m_Team = CHAT_WHISPER_SEND; @@ -2532,7 +2532,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, char *pMessage) SendChatTarget(ClientID, aBuf); } - if (m_apPlayers[VictimID]->m_ClientVersion >= VERSION_DDNET_WHISPER) + if (m_apPlayers[VictimID] && m_apPlayers[VictimID]->m_ClientVersion >= VERSION_DDNET_WHISPER) { CNetMsg_Sv_Chat Msg2; Msg2.m_Team = CHAT_WHISPER_RECV; diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 47102b45f..9f6ebdff6 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -186,7 +186,8 @@ void CGameWorld::UpdatePlayerMaps() if(SnapChar && !SnapChar->m_Super && GameServer()->m_apPlayers[SnappingClient]->GetTeam() != -1 && !ch->CanCollide(SnappingClient) && - (GameServer()->m_apPlayers[SnappingClient]->m_ClientVersion == VERSION_VANILLA || + (!GameServer()->m_apPlayers[SnappingClient] || + GameServer()->m_apPlayers[SnappingClient]->m_ClientVersion == VERSION_VANILLA || (GameServer()->m_apPlayers[SnappingClient]->m_ClientVersion >= VERSION_DDRACE && !GameServer()->m_apPlayers[SnappingClient]->m_ShowOthers ) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 881ad0203..44e05c49d 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -266,7 +266,8 @@ void CPlayer::FakeSnap(int SnappingClient) { IServer::CClientInfo info; Server()->GetClientInfo(SnappingClient, &info); - if (((CGameContext *) GameServer())->m_apPlayers[SnappingClient]->m_ClientVersion >= VERSION_DDNET_OLD) + CGameContext *GameContext = (CGameContext *) GameServer(); + if (GameContext->m_apPlayers[SnappingClient] && GameContext->m_apPlayers[SnappingClient]->m_ClientVersion >= VERSION_DDNET_OLD) return; int id = VANILLA_MAX_CLIENTS - 1; diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index 699a86289..f50eefdd6 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -314,7 +314,7 @@ void CGameTeams::SendTeamsState(int ClientID) if (g_Config.m_SvTeam == 3) return; - if (m_pGameContext->m_apPlayers[ClientID]->m_ClientVersion <= VERSION_DDRACE) + if (m_pGameContext->m_apPlayers[ClientID] && m_pGameContext->m_apPlayers[ClientID]->m_ClientVersion <= VERSION_DDRACE) return; CMsgPacker Msg(NETMSGTYPE_SV_TEAMSSTATE);