Skip to content

Commit

Permalink
Merge pull request ddnet#7464 from ChillerDragon/pr_use_ddr_wrapper
Browse files Browse the repository at this point in the history
Use GetDDRaceTeam() and move m_Teams to igamecontroller
  • Loading branch information
heinrich5991 authored Nov 18, 2023
2 parents 8ab9e72 + 83af6c0 commit 2dbfc72
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 87 deletions.
52 changes: 26 additions & 26 deletions src/game/server/ddracechat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void CGameContext::ConPractice(IConsole::IResult *pResult, void *pUserData)
return;
}

CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
CGameTeams &Teams = pSelf->m_pController->Teams();

int Team = Teams.m_Core.Team(pResult->m_ClientID);

Expand Down Expand Up @@ -698,7 +698,7 @@ void CGameContext::ConSwap(IConsole::IResult *pResult, void *pUserData)
return;
}

CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
CGameTeams &Teams = pSelf->m_pController->Teams();

int Team = Teams.m_Core.Team(pResult->m_ClientID);

Expand Down Expand Up @@ -884,9 +884,9 @@ void CGameContext::ConLockTeam(IConsole::IResult *pResult, void *pUserData)
return;
}

int Team = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams.m_Core.Team(pResult->m_ClientID);
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientID);

bool Lock = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams.TeamLocked(Team);
bool Lock = pSelf->m_pController->Teams().TeamLocked(Team);

if(pResult->NumArguments() > 0)
Lock = !pResult->GetInteger(0);
Expand All @@ -910,7 +910,7 @@ void CGameContext::ConLockTeam(IConsole::IResult *pResult, void *pUserData)
}
else
{
((CGameControllerDDRace *)pSelf->m_pController)->m_Teams.SetTeamLock(Team, true);
pSelf->m_pController->Teams().SetTeamLock(Team, true);

str_format(aBuf, sizeof(aBuf), "'%s' locked your team. After the race starts, killing will kill everyone in your team.", pSelf->Server()->ClientName(pResult->m_ClientID));
pSelf->SendChatTeam(Team, aBuf);
Expand All @@ -930,7 +930,7 @@ void CGameContext::ConUnlockTeam(IConsole::IResult *pResult, void *pUserData)
return;
}

int Team = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams.m_Core.Team(pResult->m_ClientID);
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientID);

if(Team <= TEAM_FLOCK || Team >= TEAM_SUPER)
return;
Expand All @@ -943,7 +943,7 @@ void CGameContext::ConUnlockTeam(IConsole::IResult *pResult, void *pUserData)

void CGameContext::UnlockTeam(int ClientID, int Team)
{
((CGameControllerDDRace *)m_pController)->m_Teams.SetTeamLock(Team, false);
m_pController->Teams().SetTeamLock(Team, false);

char aBuf[512];
str_format(aBuf, sizeof(aBuf), "'%s' unlocked your team.", Server()->ClientName(ClientID));
Expand All @@ -969,7 +969,7 @@ void CGameContext::ConInviteTeam(IConsole::IResult *pResult, void *pUserData)
return;
}

int Team = pController->m_Teams.m_Core.Team(pResult->m_ClientID);
int Team = pController->Teams().m_Core.Team(pResult->m_ClientID);
if(Team > TEAM_FLOCK && Team < TEAM_SUPER)
{
int Target = -1;
Expand All @@ -988,7 +988,7 @@ void CGameContext::ConInviteTeam(IConsole::IResult *pResult, void *pUserData)
return;
}

if(pController->m_Teams.IsInvited(Team, Target))
if(pController->Teams().IsInvited(Team, Target))
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chatresp", "Player already invited");
return;
Expand All @@ -1000,7 +1000,7 @@ void CGameContext::ConInviteTeam(IConsole::IResult *pResult, void *pUserData)
return;
}

pController->m_Teams.SetClientInvited(Team, Target, true);
pController->Teams().SetClientInvited(Team, Target, true);
pSelf->m_apPlayers[pResult->m_ClientID]->m_LastInvited = pSelf->Server()->Tick();

char aBuf[512];
Expand Down Expand Up @@ -1060,27 +1060,27 @@ void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData)
int Team = pResult->GetInteger(0);

if(Team < 0 || Team >= MAX_CLIENTS)
Team = pController->m_Teams.GetFirstEmptyTeam();
Team = pController->Teams().GetFirstEmptyTeam();

if(pPlayer->m_Last_Team + (int64_t)pSelf->Server()->TickSpeed() * g_Config.m_SvTeamChangeDelay > pSelf->Server()->Tick())
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chatresp",
"You can\'t change teams that fast!");
}
else if(Team > 0 && Team < MAX_CLIENTS && pController->m_Teams.TeamLocked(Team) && !pController->m_Teams.IsInvited(Team, pResult->m_ClientID))
else if(Team > 0 && Team < MAX_CLIENTS && pController->Teams().TeamLocked(Team) && !pController->Teams().IsInvited(Team, pResult->m_ClientID))
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chatresp",
g_Config.m_SvInvite ?
"This team is locked using /lock. Only members of the team can unlock it using /lock." :
"This team is locked using /lock. Only members of the team can invite you or unlock it using /lock.");
}
else if(Team > 0 && Team < MAX_CLIENTS && pController->m_Teams.Count(Team) >= g_Config.m_SvMaxTeamSize)
else if(Team > 0 && Team < MAX_CLIENTS && pController->Teams().Count(Team) >= g_Config.m_SvMaxTeamSize)
{
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "This team already has the maximum allowed size of %d players", g_Config.m_SvMaxTeamSize);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chatresp", aBuf);
}
else if(const char *pError = pController->m_Teams.SetCharacterTeam(pPlayer->GetCID(), Team))
else if(const char *pError = pController->Teams().SetCharacterTeam(pPlayer->GetCID(), Team))
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chatresp", pError);
}
Expand All @@ -1093,7 +1093,7 @@ void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData)
pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
pPlayer->m_Last_Team = pSelf->Server()->Tick();

if(pController->m_Teams.IsPractice(Team))
if(pController->Teams().IsPractice(Team))
pSelf->SendChatTarget(pPlayer->GetCID(), "Practice mode enabled for your team, happy practicing!");
}
}
Expand All @@ -1114,7 +1114,7 @@ void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData)
aBuf,
sizeof(aBuf),
"You are in team %d",
((CGameControllerDDRace *)pSelf->m_pController)->m_Teams.m_Core.Team(pResult->m_ClientID));
pSelf->GetDDRaceTeam(pResult->m_ClientID));
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chatresp",
aBuf);
}
Expand Down Expand Up @@ -1489,8 +1489,8 @@ void CGameContext::ConRescue(IConsole::IResult *pResult, void *pUserData)
if(!pChr)
return;

CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
int Team = Teams.m_Core.Team(pResult->m_ClientID);
CGameTeams &Teams = pSelf->m_pController->Teams();
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientID);
if(!g_Config.m_SvRescue && !Teams.IsPractice(Team))
{
pSelf->SendChatTarget(pPlayer->GetCID(), "Rescue is not enabled on this server and you're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
Expand All @@ -1513,8 +1513,8 @@ void CGameContext::ConTele(IConsole::IResult *pResult, void *pUserData)
if(!pChr)
return;

CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
int Team = Teams.m_Core.Team(pResult->m_ClientID);
CGameTeams &Teams = pSelf->m_pController->Teams();
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientID);
if(!Teams.IsPractice(Team))
{
pSelf->SendChatTarget(pPlayer->GetCID(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
Expand Down Expand Up @@ -1565,8 +1565,8 @@ void CGameContext::ConLastTele(IConsole::IResult *pResult, void *pUserData)
if(!pChr)
return;

CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
int Team = Teams.m_Core.Team(pResult->m_ClientID);
CGameTeams &Teams = pSelf->m_pController->Teams();
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientID);
if(!Teams.IsPractice(Team))
{
pSelf->SendChatTarget(pPlayer->GetCID(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
Expand Down Expand Up @@ -1599,8 +1599,8 @@ void CGameContext::ConPracticeUnSolo(IConsole::IResult *pResult, void *pUserData
return;
}

CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
int Team = Teams.m_Core.Team(pResult->m_ClientID);
CGameTeams &Teams = pSelf->m_pController->Teams();
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientID);
if(!Teams.IsPractice(Team))
{
pSelf->SendChatTarget(pPlayer->GetCID(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
Expand All @@ -1622,8 +1622,8 @@ void CGameContext::ConPracticeUnDeep(IConsole::IResult *pResult, void *pUserData
if(!pChr)
return;

CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
int Team = Teams.m_Core.Team(pResult->m_ClientID);
CGameTeams &Teams = pSelf->m_pController->Teams();
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientID);
if(!Teams.IsPractice(Team))
{
pSelf->SendChatTarget(pPlayer->GetCID(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
Expand Down
6 changes: 3 additions & 3 deletions src/game/server/ddracecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,18 +791,18 @@ void CGameContext::ConSetDDRTeam(IConsole::IResult *pResult, void *pUserData)

CCharacter *pChr = pSelf->GetPlayerChar(Target);

if((pController->m_Teams.m_Core.Team(Target) && pController->m_Teams.GetDDRaceState(pSelf->m_apPlayers[Target]) == DDRACE_STARTED) || (pChr && pController->m_Teams.IsPractice(pChr->Team())))
if((pSelf->GetDDRaceTeam(Target) && pController->Teams().GetDDRaceState(pSelf->m_apPlayers[Target]) == DDRACE_STARTED) || (pChr && pController->Teams().IsPractice(pChr->Team())))
pSelf->m_apPlayers[Target]->KillCharacter(WEAPON_GAME);

pController->m_Teams.SetForceCharacterTeam(Target, Team);
pController->Teams().SetForceCharacterTeam(Target, Team);
}

void CGameContext::ConUninvite(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController;

pController->m_Teams.SetClientInvited(pResult->GetInteger(1), pResult->GetVictim(), false);
pController->Teams().SetClientInvited(pResult->GetInteger(1), pResult->GetVictim(), false);
}

void CGameContext::ConFreezeHammer(IConsole::IResult *pResult, void *pUserData)
Expand Down
16 changes: 7 additions & 9 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void CGameContext::SendChatTarget(int To, const char *pText, int Flags)
void CGameContext::SendChatTeam(int Team, const char *pText)
{
for(int i = 0; i < MAX_CLIENTS; i++)
if(m_apPlayers[i] != nullptr && ((CGameControllerDDRace *)m_pController)->m_Teams.m_Core.Team(i) == Team)
if(m_apPlayers[i] != nullptr && GetDDRaceTeam(i) == Team)
SendChatTarget(i, pText);
}

Expand Down Expand Up @@ -574,7 +574,7 @@ void CGameContext::SendChat(int ChatterClientID, int Team, const char *pText, in
}
else
{
CTeamsCore *pTeams = &((CGameControllerDDRace *)m_pController)->m_Teams.m_Core;
CTeamsCore *pTeams = &m_pController->Teams().m_Core;
CNetMsg_Sv_Chat Msg;
Msg.m_Team = 1;
Msg.m_ClientID = ChatterClientID;
Expand Down Expand Up @@ -907,17 +907,16 @@ void CGameContext::OnPreTickTeehistorian()
if(!m_TeeHistorianActive)
return;

auto *pController = ((CGameControllerDDRace *)m_pController);
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(m_apPlayers[i] != nullptr)
m_TeeHistorian.RecordPlayerTeam(i, pController->m_Teams.m_Core.Team(i));
m_TeeHistorian.RecordPlayerTeam(i, GetDDRaceTeam(i));
else
m_TeeHistorian.RecordPlayerTeam(i, 0);
}
for(int i = 0; i < MAX_CLIENTS; i++)
{
m_TeeHistorian.RecordTeamPractice(i, pController->m_Teams.IsPractice(i));
m_TeeHistorian.RecordTeamPractice(i, m_pController->Teams().IsPractice(i));
}
}

Expand Down Expand Up @@ -1726,7 +1725,7 @@ bool CGameContext::OnClientDDNetVersionKnown(int ClientID)
pPlayer->m_TimerType = g_Config.m_SvDefaultTimerType;

// First update the teams state.
((CGameControllerDDRace *)m_pController)->m_Teams.SendTeamsState(ClientID);
m_pController->Teams().SendTeamsState(ClientID);

// Then send records.
SendRecord(ClientID);
Expand Down Expand Up @@ -2033,7 +2032,7 @@ void CGameContext::OnSayNetMessage(const CNetMsg_Cl_Say *pMsg, int ClientID, con
if(Length == 0 || (pMsg->m_pMessage[0] != '/' && (g_Config.m_SvSpamprotection && pPlayer->m_LastChat && pPlayer->m_LastChat + Server()->TickSpeed() * ((31 + Length) / 32) > Server()->Tick())))
return;

int GameTeam = ((CGameControllerDDRace *)m_pController)->m_Teams.m_Core.Team(pPlayer->GetCID());
int GameTeam = GetDDRaceTeam(pPlayer->GetCID());
if(Team)
Team = ((pPlayer->GetTeam() == TEAM_SPECTATORS) ? CHAT_SPEC : GameTeam);
else
Expand Down Expand Up @@ -4218,8 +4217,7 @@ bool CGameContext::ProcessSpamProtection(int ClientID, bool RespectChatInitialDe

int CGameContext::GetDDRaceTeam(int ClientID)
{
CGameControllerDDRace *pController = (CGameControllerDDRace *)m_pController;
return pController->m_Teams.m_Core.Team(ClientID);
return m_pController->Teams().m_Core.Team(ClientID);
}

void CGameContext::ResetTuning()
Expand Down
6 changes: 5 additions & 1 deletion src/game/server/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "entities/pickup.h"
#include "entities/projectile.h"

IGameController::IGameController(class CGameContext *pGameServer)
IGameController::IGameController(class CGameContext *pGameServer) :
m_Teams(pGameServer)
{
m_pGameServer = pGameServer;
m_pConfig = m_pGameServer->Config();
Expand Down Expand Up @@ -480,6 +481,9 @@ int IGameController::OnCharacterDeath(class CCharacter *pVictim, class CPlayer *

void IGameController::OnCharacterSpawn(class CCharacter *pChr)
{
pChr->SetTeams(&Teams());
Teams().OnCharacterSpawn(pChr->GetPlayer()->GetCID());

// default health
pChr->IncreaseHealth(10);

Expand Down
4 changes: 4 additions & 0 deletions src/game/server/gamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <base/vmath.h>
#include <engine/map.h>
#include <engine/shared/protocol.h>
#include <game/server/teams.h>

#include <map>
#include <vector>
Expand All @@ -25,6 +26,8 @@ class IGameController
class CConfig *m_pConfig;
class IServer *m_pServer;

CGameTeams m_Teams;

protected:
CGameContext *GameServer() const { return m_pGameServer; }
CConfig *Config() { return m_pConfig; }
Expand Down Expand Up @@ -151,6 +154,7 @@ class IGameController
float m_CurrentRecord;
std::map<int, std::vector<vec2>> m_TeleOuts;
std::map<int, std::vector<vec2>> m_TeleCheckOuts;
CGameTeams &Teams() { return m_Teams; }
};

#endif
Loading

0 comments on commit 2dbfc72

Please sign in to comment.