mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Merge pull request #726 from Learath2/dd_pr_load
Tees must be teamed up before loading
This commit is contained in:
commit
58207926ac
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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; i<m_MembersCount; 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);
|
||||
CCharacter *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;
|
||||
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1488,6 +1488,7 @@ 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->m_pController;
|
||||
|
||||
if (HandleFailure)
|
||||
return true;
|
||||
|
@ -1528,55 +1529,75 @@ 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()) // Not enough
|
||||
{
|
||||
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]))
|
||||
{
|
||||
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 (!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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue