From 4c524291723dfc0fd92e9f7c5fa6771c5c1568cc Mon Sep 17 00:00:00 2001 From: btd Date: Fri, 20 Aug 2010 21:06:49 +0400 Subject: [PATCH 1/2] Fix not safe getting character --- src/game/server/gamecontext.cpp | 72 +++++++++++++++------------------ 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 87751c2d0..53548145d 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1232,7 +1232,7 @@ void CGameContext::ConNinjaMe(IConsole::IResult *pResult, void *pUserData, int c CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; - CCharacter* chr = pSelf->m_apPlayers[cid]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid); if(chr) { chr->GiveNinja(); if(!g_Config.m_SvCheatTime) @@ -1244,7 +1244,7 @@ void CGameContext::ConNinja(IConsole::IResult *pResult, void *pUserData, int cid CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); - CCharacter* chr = pSelf->m_apPlayers[cid1]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid1); if(chr) { chr->GiveNinja(); if(!g_Config.m_SvCheatTime) @@ -1261,7 +1261,7 @@ void CGameContext::ConHammer(IConsole::IResult *pResult, void *pUserData, int ci int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int type = pResult->GetInteger(1); - CCharacter* chr = pSelf->m_apPlayers[cid1]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid1); if (!chr) return; CServer* serv = (CServer*)pSelf->Server(); @@ -1285,7 +1285,7 @@ void CGameContext::ConHammerMe(IConsole::IResult *pResult, void *pUserData, int if(!pSelf->CheatsAvailable(cid)) return; char buf[128]; int type = pResult->GetInteger(0); - CCharacter* chr = pSelf->m_apPlayers[cid]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid); if (!chr) return; CServer* serv = (CServer*)pSelf->Server(); @@ -1311,7 +1311,7 @@ void CGameContext::ConSuper(IConsole::IResult *pResult, void *pUserData, int cid int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); if (pSelf->m_apPlayers[cid1] && compare_players(pSelf->m_apPlayers[cid],pSelf->m_apPlayers[cid1])) { - CCharacter* chr = pSelf->m_apPlayers[cid1]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid1); if(chr) { chr->m_Super = true; @@ -1328,7 +1328,7 @@ void CGameContext::ConUnSuper(IConsole::IResult *pResult, void *pUserData, int c int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); if (pSelf->m_apPlayers[cid1] && compare_players(pSelf->m_apPlayers[cid],pSelf->m_apPlayers[cid1])) { - CCharacter* chr = pSelf->m_apPlayers[cid1]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid1); if(chr) { chr->m_Super = false; @@ -1342,7 +1342,7 @@ void CGameContext::ConSuperMe(IConsole::IResult *pResult, void *pUserData, int c if(!pSelf->CheatsAvailable(cid)) return; if (pSelf->m_apPlayers[cid]) { - CCharacter* chr = pSelf->m_apPlayers[cid]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid); if(chr) { chr->m_Super = true; @@ -1358,7 +1358,7 @@ void CGameContext::ConUnSuperMe(IConsole::IResult *pResult, void *pUserData, int if(!pSelf->CheatsAvailable(cid)) return; if (pSelf->m_apPlayers[cid]) { - CCharacter* chr = pSelf->m_apPlayers[cid]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid); if(chr) { chr->m_Super = false; @@ -1373,7 +1373,7 @@ void CGameContext::ConWeapons(IConsole::IResult *pResult, void *pUserData, int c int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); if (pSelf->m_apPlayers[cid1] && compare_players(pSelf->m_apPlayers[cid],pSelf->m_apPlayers[cid1])) { - CCharacter* chr = pSelf->m_apPlayers[cid1]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid1); if(chr) { chr->GiveAllWeapons(); @@ -1387,15 +1387,12 @@ void CGameContext::ConWeaponsMe(IConsole::IResult *pResult, void *pUserData, int { CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; - if (pSelf->m_apPlayers[cid]) + CCharacter* chr = pSelf->GetPlayerChar(cid); + if(chr) { - CCharacter* chr = pSelf->m_apPlayers[cid]->GetCharacter(); - if(chr) - { - chr->GiveAllWeapons(); - if(!g_Config.m_SvCheatTime) - chr->m_RaceState = RACE_CHEAT; - } + chr->GiveAllWeapons(); + if(!g_Config.m_SvCheatTime) + chr->m_RaceState = RACE_CHEAT; } } @@ -1410,7 +1407,7 @@ void CGameContext::ConTeleport(IConsole::IResult *pResult, void *pUserData, int || (compare_players(pSelf->m_apPlayers[cid],pSelf->m_apPlayers[cid1]) && compare_players(pSelf->m_apPlayers[cid],pSelf->m_apPlayers[cid2])) || (compare_players(pSelf->m_apPlayers[cid],pSelf->m_apPlayers[cid1]) && cid2==cid)) { - CCharacter* chr = pSelf->m_apPlayers[cid1]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid1); if(chr) { chr->m_Core.m_Pos = pSelf->m_apPlayers[cid2]->m_ViewPos; @@ -1431,29 +1428,26 @@ void CGameContext::ConTimer(IConsole::IResult *pResult, void *pUserData, int cid int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int type = pResult->GetInteger(1); - CPlayer* pl = pSelf->m_apPlayers[cid1]; - if(pl != 0) { - CCharacter* chr = pl->GetCharacter(); - if (!chr) - return; - if (type>1 || type<0) + CCharacter* chr = pSelf->GetPlayerChar(cid1); + if (!chr) + return; + if (type>1 || type<0) + { + serv->SendRconLine(cid, "Select 0 for no time & 1 for with time"); + } + else + { + if(type) { - serv->SendRconLine(cid, "Select 0 for no time & 1 for with time"); + chr->m_RaceState = RACE_STARTED; + str_format(buf, sizeof(buf), "Cid=%d Has time now",cid1); } - else - { - if(type) - { - chr->m_RaceState = RACE_STARTED; - str_format(buf, sizeof(buf), "Cid=%d Has time now",cid1); - } - else if(!type) - { - chr->m_RaceState=RACE_CHEAT; - str_format(buf, sizeof(buf), "Cid=%d Hasn't time now",cid1); - } - serv->SendRconLine(cid1, buf); + else if(!type) + { + chr->m_RaceState=RACE_CHEAT; + str_format(buf, sizeof(buf), "Cid=%d Hasn't time now",cid1); } + serv->SendRconLine(cid1, buf); } } else { @@ -1469,7 +1463,7 @@ void CGameContext::ConTimerReset(IConsole::IResult *pResult, void *pUserData, in int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); - CCharacter* chr = pSelf->m_apPlayers[cid1]->GetCharacter(); + CCharacter* chr = pSelf->GetPlayerChar(cid1); if (!chr) return; chr->m_StartTime = pSelf->Server()->Tick(); From d22052d800404e75eadfdcca898a1f3177fa210d Mon Sep 17 00:00:00 2001 From: btd Date: Fri, 20 Aug 2010 22:03:51 +0400 Subject: [PATCH 2/2] Small improvements --- src/game/server/gamecontext.cpp | 5 +---- src/game/server/score.cpp | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index a2379a488..8eeb26585 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -705,10 +705,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) number = number*10+(*pt-'0'); pt++; } - if(number) - s=((CGameControllerDDRace*)m_pController)->m_Score.Top5Draw(ClientId, number); - else - s=((CGameControllerDDRace*)m_pController)->m_Score.Top5Draw(ClientId, 0); + s=((CGameControllerDDRace*)m_pController)->m_Score.Top5Draw(ClientId, number ? number : 0); for(i=s.begin(); i != s.end(); ++i) { str_format(buf, sizeof(buf), "%s",*i); diff --git a/src/game/server/score.cpp b/src/game/server/score.cpp index 2500275f7..7c11e4197 100644 --- a/src/game/server/score.cpp +++ b/src/game/server/score.cpp @@ -146,7 +146,7 @@ std::list CScore::Top5Draw(int id, int debut) //Thanks nevi if (i->m_Score-((int)i->m_Score/60)*60 != 0) oss << i->m_Score-((int)i->m_Score/60)*60 <<" "; - res.push_back(oss.str().c_str()); + res.push_back(oss.str()); } pos++; }