Revert "Tees must be teamed up before loading"

This reverts commit d29f2306ef.
This commit is contained in:
def 2017-05-14 22:36:44 +02:00
parent f57f1d0d17
commit f4112e3bcb
6 changed files with 89 additions and 91 deletions

View file

@ -36,7 +36,6 @@ 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;

View file

@ -555,14 +555,6 @@ 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);

View file

@ -244,7 +244,6 @@ 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);

View file

@ -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->Pause(m_Paused, true);
@ -203,7 +203,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))
{
@ -232,7 +232,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++;
@ -259,22 +259,41 @@ 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; i<m_MembersCount; i++)
{
CCharacter *pChr = MatchCharacter(SavedTees[i].GetName(), i);
int ID = MatchPlayer(SavedTees[i].GetName());
if(ID == -1) // first check if team can be loaded / do not load half teams
{
return i+10; // +10 to let space for other return-values
}
else if (m_pController->GameServer()->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; i<m_MembersCount; i++)
{
pChr = MatchCharacter(SavedTees[i].GetName(), i);
if(pChr)
SavedTees[i].Load(pChr, Team);
{
SavedTees[i].load(pChr, Team);
}
}
if(m_pController->GameServer()->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;
@ -282,14 +301,24 @@ 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;
}
CCharacter* CSaveTeam::MatchCharacter(char name[16], int SaveID)
{
int ID = m_pController->Server()->GetClientID(name);
int ID = MatchPlayer(name);
if(ID >= 0 && m_pController->GameServer()->m_apPlayers[ID])
{
if(m_pController->GameServer()->m_apPlayers[ID]->GetCharacter())

View file

@ -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,11 +88,12 @@ 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;

View file

@ -1400,7 +1400,7 @@ bool CSqlScore::SaveTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData
if((g_Config.m_SvTeam == 3 || (Team > 0 && Team < MAX_CLIENTS)) && ((CGameControllerDDRace*)(pData->GameServer()->m_pController))->m_Teams.Count(Team) > 0)
{
CSaveTeam SavedTeam(pData->GameServer()->m_pController);
Num = SavedTeam.Save(Team);
Num = SavedTeam.save(Team);
switch (Num)
{
case 1:
@ -1488,7 +1488,6 @@ void CSqlScore::LoadTeam(const char* Code, int ClientID)
bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData, bool HandleFailure)
{
const CSqlTeamLoad *pData = dynamic_cast<const CSqlTeamLoad *>(pGameData);
CGameControllerDDRace *pController = (CGameControllerDDRace *)pData->GameServer()->m_pController;
if (HandleFailure)
return true;
@ -1529,75 +1528,54 @@ bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData
pData->GameServer()->SendChatTarget(pData->m_ClientID, "Unable to load savegame: data corrupted");
else
{
int Team = pController->m_Teams.m_Core.Team(pData->m_ClientID);
if(Team == TEAM_FLOCK || Team == TEAM_SUPER)
{
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()) // Not enough
bool Found = false;
for (int i = 0; i < SavedTeam.GetMembersCount(); i++)
{
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;
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].GetName()))
{
if(i == pData->m_ClientID)
Belongs = true;
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(!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))
{
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(str_comp(SavedTeam.SavedTees[i].GetName(), pData->Server()->ClientName(pData->m_ClientID)) == 0)
{ Found = true; break; }
}
if (!Found)
pData->GameServer()->SendChatTarget(pData->m_ClientID, "You don't belong to this team");
else
{
pData->GameServer()->SendChatTeam(Team, "Loading failed, report this incident");
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);
}
}
}
}