From d29f2306ef345704e973ac9157d8ebf5e6b5bcc1 Mon Sep 17 00:00:00 2001 From: Learath Date: Tue, 11 Apr 2017 21:18:26 +0200 Subject: [PATCH 1/3] Tees must be teamed up before loading --- src/engine/server.h | 1 + src/engine/server/server.cpp | 8 +++ src/engine/server/server.h | 1 + src/game/server/save.cpp | 51 ++++------------- src/game/server/save.h | 9 ++- src/game/server/score/sql_score.cpp | 88 ++++++++++++++--------------- 6 files changed, 68 insertions(+), 90 deletions(-) diff --git a/src/engine/server.h b/src/engine/server.h index 3d21ddf7c..adeaebb4b 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -36,6 +36,7 @@ public: virtual int GetClientInfo(int ClientID, CClientInfo *pInfo) = 0; virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) = 0; virtual void RestrictRconOutput(int ClientID) = 0; + virtual int GetClientID(const char *pName) = 0; virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) = 0; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index c104535a7..310207ca3 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -555,6 +555,14 @@ int CServer::MaxClients() const return m_NetServer.MaxClients(); } +int CServer::GetClientID(const char *pName) +{ + for(int i = 0; i < MAX_CLIENTS; i++) + if(!str_comp(pName, m_aClients[i].m_aName)) + return i; + return -1; +} + int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) { return SendMsgEx(pMsg, Flags, ClientID, false); diff --git a/src/engine/server/server.h b/src/engine/server/server.h index e393eb463..8d7c4431a 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -244,6 +244,7 @@ public: int ClientCountry(int ClientID); bool ClientIngame(int ClientID); int MaxClients() const; + int GetClientID(const char *pName); virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID); int SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System); diff --git a/src/game/server/save.cpp b/src/game/server/save.cpp index b1cb8a583..ed3b88092 100644 --- a/src/game/server/save.cpp +++ b/src/game/server/save.cpp @@ -17,7 +17,7 @@ CSaveTee::~CSaveTee() ; } -void CSaveTee::save(CCharacter *pChr) +void CSaveTee::Save(CCharacter *pChr) { str_copy(m_name, pChr->m_pPlayer->Server()->ClientName(pChr->m_pPlayer->GetCID()), sizeof(m_name)); @@ -88,7 +88,7 @@ void CSaveTee::save(CCharacter *pChr) m_HookState = pChr->m_Core.m_HookState; } -void CSaveTee::load(CCharacter *pChr, int Team) +void CSaveTee::Load(CCharacter *pChr, int Team) { pChr->m_pPlayer->m_Paused = m_Paused; pChr->m_pPlayer->ProcessPause(); @@ -204,7 +204,7 @@ CSaveTeam::~CSaveTeam() delete[] SavedTees; } -int CSaveTeam::save(int Team) +int CSaveTeam::Save(int Team) { if(g_Config.m_SvTeam == 3 || (Team > 0 && Team < MAX_CLIENTS)) { @@ -233,7 +233,7 @@ int CSaveTeam::save(int Team) if(Teams->m_Core.Team(i) == Team) { if(m_pController->GameServer()->m_apPlayers[i] && m_pController->GameServer()->m_apPlayers[i]->GetCharacter()) - SavedTees[j].save(m_pController->GameServer()->m_apPlayers[i]->GetCharacter()); + SavedTees[j].Save(m_pController->GameServer()->m_apPlayers[i]->GetCharacter()); else return 3; j++; @@ -260,41 +260,22 @@ int CSaveTeam::save(int Team) return 1; } -int CSaveTeam::load(int Team) +int CSaveTeam::Load(int Team) { - if(Team <= 0 || Team >= MAX_CLIENTS) - return 1; - CGameTeams* Teams = &(((CGameControllerDDRace*)m_pController)->m_Teams); Teams->ChangeTeamState(Team, m_TeamState); Teams->SetTeamLock(Team, m_TeamLocked); - CCharacter *pChr; - for (int i = 0; iGameServer()->m_apPlayers[ID] && m_pController->GameServer()->m_apPlayers[ID]->GetCharacter() && m_pController->GameServer()->m_apPlayers[ID]->GetCharacter()->m_DDRaceState) - { - return i+100; // +100 to let space for other return-values - } - } - - for (int i = 0; iGameServer()->Collision()->m_NumSwitchers) + { for(int i=1; i < m_pController->GameServer()->Collision()->m_NumSwitchers+1; i++) { m_pController->GameServer()->Collision()->m_pSwitchers[i].m_Status[Team] = m_Switchers[i].m_Status; @@ -302,24 +283,14 @@ int CSaveTeam::load(int Team) m_pController->GameServer()->Collision()->m_pSwitchers[i].m_EndTick[Team] = m_pController->Server()->Tick() - m_Switchers[i].m_EndTime; m_pController->GameServer()->Collision()->m_pSwitchers[i].m_Type[Team] = m_Switchers[i].m_Type; } - return 0; -} - -int CSaveTeam::MatchPlayer(char name[16]) -{ - for (int i = 0; i < MAX_CLIENTS; i++) - { - if(str_comp(m_pController->Server()->ClientName(i), name) == 0) - { - return i; - } } - return -1; + + return 0; } CCharacter* CSaveTeam::MatchCharacter(char name[16], int SaveID) { - int ID = MatchPlayer(name); + int ID = m_pController->Server()->GetClientID(name); if(ID >= 0 && m_pController->GameServer()->m_apPlayers[ID]) { if(m_pController->GameServer()->m_apPlayers[ID]->GetCharacter()) diff --git a/src/game/server/save.h b/src/game/server/save.h index 6c3008ef6..c20d7a322 100644 --- a/src/game/server/save.h +++ b/src/game/server/save.h @@ -9,8 +9,8 @@ class CSaveTee public: CSaveTee(); ~CSaveTee(); - void save(CCharacter* pchr); - void load(CCharacter* pchr, int Team); + void Save(CCharacter* pchr); + void Load(CCharacter* pchr, int Team); char* GetString(); int LoadString(char* String); vec2 GetPos() { return m_Pos; } @@ -88,12 +88,11 @@ public: char* GetString(); int GetMembersCount() {return m_MembersCount;} int LoadString(const char* String); - int save(int Team); - int load(int Team); + int Save(int Team); + int Load(int Team); CSaveTee* SavedTees; private: - int MatchPlayer(char name[16]); CCharacter* MatchCharacter(char name[16], int SaveID); IGameController* m_pController; diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index 5d8496963..a0270f584 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -1471,6 +1471,7 @@ void CSqlScore::LoadTeam(const char* Code, int ClientID) bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData, bool HandleFailure) { const CSqlTeamLoad *pData = dynamic_cast(pGameData); + CGameControllerDDRace *pController = (CGameControllerDDRace *)pData->m_pController; if (HandleFailure) return true; @@ -1511,55 +1512,52 @@ bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData pData->GameServer()->SendChatTarget(pData->m_ClientID, "Unable to load savegame: data corrupted"); else { - - bool Found = false; - for (int i = 0; i < SavedTeam.GetMembersCount(); i++) + int Team = pController->m_Teams.m_Core.Team(pData->m_ClientID); + if(Team == TEAM_FLOCK || Team == TEAM_SUPER) { - if(str_comp(SavedTeam.SavedTees[i].GetName(), pData->Server()->ClientName(pData->m_ClientID)) == 0) - { Found = true; break; } + pData->GameServer()->SendChatTarget(pData->m_ClientID, "You must be in a team to load"); + goto end; + } + if(pController->m_Teams.GetTeamState(Team) == CGameTeams::TEAMSTATE_STARTED) + { + pData->GameServer()->SendChatTarget(pData->m_ClientID, "Can't load while racing"); + goto end; + } + + int TeamCount = pController->m_Teams.Count(Team); + if(TeamCount != SavedTeam.GetMembersCount()) + { + pData->GameServer()->SendChatTarget(pData->m_ClientID, "All saved tees must be present to load."); // Also list the missing tees I guess + goto end; + } + + int64_t TeamMask = pController->m_Teams.TeamMask(Team); + + int Found = 0; + for(int i = 0; i < SavedTeam.GetMembersCount(); i++) + { + int CID = pData->Server()->GetClientID(SavedTeam.SavedTees[i]); + if(CID >= 0 && pController->m_Teams.m_Core.Team(CID) == Team) + Found++; + else + break; + } + if(Found != SavedTeam.GetMembersCount()) + { + pData->GameServer()->SendChatTarget(pData->m_ClientID, "All saved tees must be present to load."); // Also list the missing tees I guess + goto end; + } + + if(!SavedTeam.load(Team)) + { + pData->GameServer()->SendChatTeam(Team, "Loading successfully done"); + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "DELETE from %s_saves where Code='%s' and Map='%s';", pSqlServer->GetPrefix(), pData->m_Code.ClrStr(), pData->m_Map.ClrStr()); + pSqlServer->executeSql(aBuf); } - if (!Found) - pData->GameServer()->SendChatTarget(pData->m_ClientID, "You don't belong to this team"); else { - - int n; - for(n = 1; n<64; n++) - { - if(((CGameControllerDDRace*)(pData->GameServer()->m_pController))->m_Teams.Count(n) == 0) - break; - } - - if(((CGameControllerDDRace*)(pData->GameServer()->m_pController))->m_Teams.Count(n) > 0) - { - n = ((CGameControllerDDRace*)(pData->GameServer()->m_pController))->m_Teams.m_Core.Team(pData->m_ClientID); // if all Teams are full your the only one in your team - } - - Num = SavedTeam.load(n); - - if(Num == 1) - { - pData->GameServer()->SendChatTarget(pData->m_ClientID, "You have to be in a team (from 1-63)"); - } - else if(Num >= 10 && Num < 100) - { - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "Unable to find player: '%s'", SavedTeam.SavedTees[Num-10].GetName()); - pData->GameServer()->SendChatTarget(pData->m_ClientID, aBuf); - } - else if(Num >= 100) - { - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "%s is racing right now, Team can't be loaded if a Tee is racing already", SavedTeam.SavedTees[Num-100].GetName()); - pData->GameServer()->SendChatTarget(pData->m_ClientID, aBuf); - } - else - { - pData->GameServer()->SendChatTeam(n, "Loading successfully done"); - char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "DELETE from %s_saves where Code='%s' and Map='%s';", pSqlServer->GetPrefix(), pData->m_Code.ClrStr(), pData->m_Map.ClrStr()); - pSqlServer->executeSql(aBuf); - } + pData->GameServer()->SendChatTeam(Team, "Loading failed, report this incident"); } } } From 47f405e1607f341d6883b4f1e613fb3adab93db6 Mon Sep 17 00:00:00 2001 From: Learath Date: Wed, 12 Apr 2017 10:33:02 +0200 Subject: [PATCH 2/3] Remove tees that don't belong --- src/game/server/score/sql_score.cpp | 45 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index a0270f584..8e309dce5 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -1525,29 +1525,40 @@ bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData } int TeamCount = pController->m_Teams.Count(Team); - if(TeamCount != SavedTeam.GetMembersCount()) + if(TeamCount < SavedTeam.GetMembersCount()) // Not enough { - pData->GameServer()->SendChatTarget(pData->m_ClientID, "All saved tees must be present to load."); // Also list the missing tees I guess + pData->GameServer()->SendChatTarget(pData->m_ClientID, "All saved tees must be present to load"); // Also list the missing tees I guess goto end; } - int64_t TeamMask = pController->m_Teams.TeamMask(Team); - - int Found = 0; - for(int i = 0; i < SavedTeam.GetMembersCount(); i++) { - int CID = pData->Server()->GetClientID(SavedTeam.SavedTees[i]); - if(CID >= 0 && pController->m_Teams.m_Core.Team(CID) == Team) - Found++; - else - break; - } - if(Found != SavedTeam.GetMembersCount()) - { - pData->GameServer()->SendChatTarget(pData->m_ClientID, "All saved tees must be present to load."); // Also list the missing tees I guess - goto end; - } + int Found = 0; + bool Removed = false; + for (int i = 0; i < MAX_CLIENTS; ++i) + { + if(pController->m_Teams.m_Core.Team(i) == Team) + { + bool Allowed = false; + for(int j = 0; !Allowed && j < SavedTeam.GetMembersCount(); i++) + if(!str_comp(pData->Server()->ClientName(i), SavedTeam.SavedTees[j])) + Allowed = true; + if(!Allowed) + pController->m_Teams.SetForceCharacterTeam(i, TEAM_FLOCK); + + Found += Allowed; + Removed |= !Allowed; + } + } + if(Found != SavedTeam.GetMembersCount()) + { + pData->GameServer()->SendChatTarget(pData->m_ClientID, "All saved tees must be present to load"); // Also list the missing tees I guess + goto end; + } + if(Removed) + pData->GameServer()->SendChatTarget(pData->m_ClientID, "Tees that don't belong to the save have been removed"); + } + if(!SavedTeam.load(Team)) { pData->GameServer()->SendChatTeam(Team, "Loading successfully done"); From 0cafa8b813a9eedbb2be7fcc1fff0bc09dc4db20 Mon Sep 17 00:00:00 2001 From: Learath Date: Wed, 12 Apr 2017 16:59:46 +0200 Subject: [PATCH 3/3] Random tees can't load saves --- src/game/server/score/sql_score.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index 8e309dce5..a731f6bd0 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -1534,14 +1534,21 @@ bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData { int Found = 0; bool Removed = false; + bool Belongs = false; for (int i = 0; i < MAX_CLIENTS; ++i) { if(pController->m_Teams.m_Core.Team(i) == Team) { bool Allowed = false; for(int j = 0; !Allowed && j < SavedTeam.GetMembersCount(); i++) + { if(!str_comp(pData->Server()->ClientName(i), SavedTeam.SavedTees[j])) + { + if(i == pData->m_ClientID) + Belongs = true; Allowed = true; + } + } if(!Allowed) pController->m_Teams.SetForceCharacterTeam(i, TEAM_FLOCK); @@ -1557,6 +1564,11 @@ bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData } if(Removed) pData->GameServer()->SendChatTarget(pData->m_ClientID, "Tees that don't belong to the save have been removed"); + if(!Belongs) + { + pData->GameServer()->SendChatTarget(pData->m_ClientID, "You don't belong to this save"); // Also list the missing tees I guess + goto end; + } } if(!SavedTeam.load(Team))