Refactoring of g_Config.m_SvTeam, See #4601

This commit is contained in:
c0d3d3v 2022-02-19 15:20:32 +01:00
parent 40380d088f
commit eac2d731b6
No known key found for this signature in database
GPG key ID: 068AF680530DFF31
12 changed files with 46 additions and 38 deletions

View file

@ -143,9 +143,9 @@ void CGameContext::ConSettings(IConsole::IResult *pResult, void *pUserData)
if(str_comp(pArg, "teams") == 0)
{
str_format(aBuf, sizeof(aBuf), "%s %s",
g_Config.m_SvTeam == 1 ?
g_Config.m_SvTeam == SV_TEAM_ALLOWED ?
"Teams are available on this server" :
(g_Config.m_SvTeam == 0 || g_Config.m_SvTeam == 3) ?
(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) ?
"Teams are not available on this server" :
"You have to be in a team to play on this server", /*g_Config.m_SvTeamStrict ? "and if you die in a team all of you die" : */
"and all of your team will die if the team is locked");
@ -618,7 +618,7 @@ void CGameContext::ConPractice(IConsole::IResult *pResult, void *pUserData)
int Team = Teams.m_Core.Team(pResult->m_ClientID);
if(Team < TEAM_FLOCK || (Team == TEAM_FLOCK && g_Config.m_SvTeam != 3) || Team >= TEAM_SUPER)
if(Team < TEAM_FLOCK || (Team == TEAM_FLOCK && g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO) || Team >= TEAM_SUPER)
{
pSelf->Console()->Print(
IConsole::OUTPUT_LEVEL_STANDARD,
@ -695,7 +695,7 @@ void CGameContext::ConSwap(IConsole::IResult *pResult, void *pUserData)
int Team = Teams.m_Core.Team(pResult->m_ClientID);
if(Team < TEAM_FLOCK || (Team == TEAM_FLOCK && g_Config.m_SvTeam != 3) || Team >= TEAM_SUPER)
if(Team < TEAM_FLOCK || (Team == TEAM_FLOCK && g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO) || Team >= TEAM_SUPER)
{
pSelf->Console()->Print(
IConsole::OUTPUT_LEVEL_STANDARD,
@ -839,7 +839,7 @@ void CGameContext::ConLockTeam(IConsole::IResult *pResult, void *pUserData)
if(!CheckClientID(pResult->m_ClientID))
return;
if(g_Config.m_SvTeam == 0 || g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "lock",
"Teams are disabled");
@ -885,7 +885,7 @@ void CGameContext::ConUnlockTeam(IConsole::IResult *pResult, void *pUserData)
if(!CheckClientID(pResult->m_ClientID))
return;
if(g_Config.m_SvTeam == 0 || g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "unlock",
"Teams are disabled");
@ -918,7 +918,7 @@ void CGameContext::ConInviteTeam(IConsole::IResult *pResult, void *pUserData)
CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController;
const char *pName = pResult->GetString(0);
if(g_Config.m_SvTeam == 0 || g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "join",
"Teams are disabled");
@ -995,13 +995,13 @@ void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData)
"You are running a vote please try again after the vote is done!");
return;
}
else if(g_Config.m_SvTeam == 0 || g_Config.m_SvTeam == 3)
else if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "join",
"Teams are disabled");
return;
}
else if(g_Config.m_SvTeam == 2 && pResult->GetInteger(0) == 0 && pPlayer->GetCharacter() && pPlayer->GetCharacter()->m_LastStartWarning < pSelf->Server()->Tick() - 3 * pSelf->Server()->TickSpeed())
else if(g_Config.m_SvTeam == SV_TEAM_MANDATORY && pResult->GetInteger(0) == 0 && pPlayer->GetCharacter() && pPlayer->GetCharacter()->m_LastStartWarning < pSelf->Server()->Tick() - 3 * pSelf->Server()->TickSpeed())
{
pSelf->Console()->Print(
IConsole::OUTPUT_LEVEL_STANDARD,

View file

@ -707,7 +707,7 @@ void CGameContext::ConSetDDRTeam(IConsole::IResult *pResult, void *pUserData)
CGameContext *pSelf = (CGameContext *)pUserData;
CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController;
if(g_Config.m_SvTeam == 0 || g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "join",
"Teams are disabled");

View file

@ -1816,7 +1816,7 @@ void CCharacter::HandleTiles(int Index)
m_StartTime -= (min * 60 + sec) * Server()->TickSpeed();
if((g_Config.m_SvTeam == 3 || Team != TEAM_FLOCK) && Team != TEAM_SUPER)
if((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || Team != TEAM_FLOCK) && Team != TEAM_SUPER)
{
for(int i = 0; i < MAX_CLIENTS; i++)
{
@ -1842,7 +1842,7 @@ void CCharacter::HandleTiles(int Index)
if(m_StartTime > Server()->Tick())
m_StartTime = Server()->Tick();
if((g_Config.m_SvTeam == 3 || Team != TEAM_FLOCK) && Team != TEAM_SUPER)
if((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || Team != TEAM_FLOCK) && Team != TEAM_SUPER)
{
for(int i = 0; i < MAX_CLIENTS; i++)
{
@ -2082,7 +2082,7 @@ void CCharacter::DDRaceTick()
HandleTuneLayer(); // need this before coretick
// look for save position for rescue feature
if(g_Config.m_SvRescue || ((g_Config.m_SvTeam == 3 || Team() > TEAM_FLOCK) && Team() >= TEAM_FLOCK && Team() < TEAM_SUPER))
if(g_Config.m_SvRescue || ((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || Team() > TEAM_FLOCK) && Team() >= TEAM_FLOCK && Team() < TEAM_SUPER))
{
int Index = GameServer()->Collision()->GetPureMapIndex(m_Pos);
const int aTiles[] = {
@ -2319,7 +2319,7 @@ void CCharacter::DDRaceInit()
}
}
if(g_Config.m_SvTeam == 2 && Team == TEAM_FLOCK)
if(g_Config.m_SvTeam == SV_TEAM_MANDATORY && Team == TEAM_FLOCK)
{
GameServer()->SendStartWarning(GetPlayer()->GetCID(), "Please join a team before you start");
}

View file

@ -3192,7 +3192,7 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
g_Config.m_SvOldTeleportHook = 0;
g_Config.m_SvOldTeleportWeapons = 0;
g_Config.m_SvTeleportHoldHook = 0;
g_Config.m_SvTeam = 1;
g_Config.m_SvTeam = SV_TEAM_ALLOWED;
g_Config.m_SvShowOthersDefault = 0;
if(Collision()->m_NumSwitchers > 0)
@ -3208,7 +3208,7 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
if(g_Config.m_SvSoloServer)
{
g_Config.m_SvTeam = 3;
g_Config.m_SvTeam = SV_TEAM_FORCED_SOLO;
g_Config.m_SvShowOthersDefault = 1;
Tuning()->Set("player_collision", 0);

View file

@ -70,13 +70,13 @@ void CGameControllerDDRace::HandleCharacterTiles(CCharacter *pChr, int MapIndex)
pChr->Die(ClientID, WEAPON_WORLD);
return;
}
if(g_Config.m_SvTeam == 2 && (Team == TEAM_FLOCK || m_Teams.Count(Team) <= 1))
if(g_Config.m_SvTeam == SV_TEAM_MANDATORY && (Team == TEAM_FLOCK || m_Teams.Count(Team) <= 1))
{
GameServer()->SendStartWarning(ClientID, "You have to be in a team with other tees to start");
pChr->Die(ClientID, WEAPON_WORLD);
return;
}
if(g_Config.m_SvTeam != 3 && Team > TEAM_FLOCK && Team < TEAM_SUPER && m_Teams.Count(Team) < g_Config.m_SvMinTeamSize)
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team > TEAM_FLOCK && Team < TEAM_SUPER && m_Teams.Count(Team) < g_Config.m_SvMinTeamSize)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "Your team has fewer than %d players, so your team rank won't count", g_Config.m_SvMinTeamSize);
@ -149,7 +149,7 @@ void CGameControllerDDRace::OnPlayerDisconnect(CPlayer *pPlayer, const char *pRe
if(!GameServer()->PlayerModerating() && WasModerator)
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Server kick/spec votes are no longer actively moderated.");
if(g_Config.m_SvTeam != 3)
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO)
m_Teams.SetForceCharacterTeam(ClientID, TEAM_FLOCK);
}
@ -179,7 +179,7 @@ void CGameControllerDDRace::DoTeamChange(class CPlayer *pPlayer, int Team, bool
if(Team == TEAM_SPECTATORS)
{
if(g_Config.m_SvTeam != 3 && pCharacter)
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && pCharacter)
{
// Joining spectators should not kill a locked team, but should still
// check if the team finished by you leaving it.

View file

@ -702,7 +702,7 @@ void CPlayer::TryRespawn()
m_pCharacter->Spawn(this, SpawnPos);
GameServer()->CreatePlayerSpawn(SpawnPos, GameServer()->m_pController->GetMaskForPlayerWorldEvent(m_ClientID));
if(g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
m_pCharacter->SetSolo(true);
}

View file

@ -430,7 +430,7 @@ CSaveTeam::~CSaveTeam()
int CSaveTeam::Save(int Team)
{
if(g_Config.m_SvTeam == 3 || (Team > 0 && Team < MAX_CLIENTS))
if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || (Team > 0 && Team < MAX_CLIENTS))
{
CGameTeams *Teams = &(((CGameControllerDDRace *)m_pController)->m_Teams);

View file

@ -309,7 +309,7 @@ void CScore::LoadTeam(const char *Code, int ClientID)
int Team = pController->m_Teams.m_Core.Team(ClientID);
if(pController->m_Teams.GetSaving(Team))
return;
if(Team < TEAM_FLOCK || Team >= MAX_CLIENTS || (g_Config.m_SvTeam != 3 && Team == TEAM_FLOCK))
if(Team < TEAM_FLOCK || Team >= MAX_CLIENTS || (g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK))
{
GameServer()->SendChatTarget(ClientID, "You have to be in a team (from 1-63)");
return;

View file

@ -76,11 +76,11 @@ void CGameTeams::OnCharacterStart(int ClientID)
CCharacter *pStartingChar = Character(ClientID);
if(!pStartingChar)
return;
if(g_Config.m_SvTeam == 3 && pStartingChar->m_DDRaceState == DDRACE_STARTED)
if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO && pStartingChar->m_DDRaceState == DDRACE_STARTED)
return;
if((g_Config.m_SvTeam == 3 || m_Core.Team(ClientID) != TEAM_FLOCK) && pStartingChar->m_DDRaceState == DDRACE_FINISHED)
if((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || m_Core.Team(ClientID) != TEAM_FLOCK) && pStartingChar->m_DDRaceState == DDRACE_FINISHED)
return;
if(g_Config.m_SvTeam != 3 &&
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO &&
(m_Core.Team(ClientID) == TEAM_FLOCK || m_Core.Team(ClientID) == TEAM_SUPER))
{
m_TeeStarted[ClientID] = true;
@ -171,7 +171,7 @@ void CGameTeams::OnCharacterStart(int ClientID)
}
}
if(g_Config.m_SvTeam < 3 && g_Config.m_SvMaxTeamSize != 2 && g_Config.m_SvPauseable)
if(g_Config.m_SvTeam < SV_TEAM_FORCED_SOLO && g_Config.m_SvMaxTeamSize != 2 && g_Config.m_SvPauseable)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
@ -187,7 +187,7 @@ void CGameTeams::OnCharacterStart(int ClientID)
void CGameTeams::OnCharacterFinish(int ClientID)
{
if((m_Core.Team(ClientID) == TEAM_FLOCK && g_Config.m_SvTeam != 3) || m_Core.Team(ClientID) == TEAM_SUPER)
if((m_Core.Team(ClientID) == TEAM_FLOCK && g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO) || m_Core.Team(ClientID) == TEAM_SUPER)
{
CPlayer *pPlayer = GetPlayer(ClientID);
if(pPlayer && pPlayer->IsPlaying())
@ -391,7 +391,7 @@ void CGameTeams::SetForceCharacterTeam(int ClientID, int Team)
m_TeeFinished[ClientID] = false;
int OldTeam = m_Core.Team(ClientID);
if(Team != OldTeam && (OldTeam != TEAM_FLOCK || g_Config.m_SvTeam == 3) && OldTeam != TEAM_SUPER && m_TeamState[OldTeam] != TEAMSTATE_EMPTY)
if(Team != OldTeam && (OldTeam != TEAM_FLOCK || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) && OldTeam != TEAM_SUPER && m_TeamState[OldTeam] != TEAMSTATE_EMPTY)
{
bool NoElseInOldTeam = Count(OldTeam) <= 1;
if(NoElseInOldTeam)
@ -553,7 +553,7 @@ int64_t CGameTeams::TeamMask(int Team, int ExceptID, int Asker)
void CGameTeams::SendTeamsState(int ClientID)
{
if(g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
return;
if(!m_pGameContext->m_apPlayers[ClientID])
@ -647,7 +647,7 @@ void CGameTeams::OnTeamFinish(CPlayer **Players, unsigned int Size, float Time,
{
PlayerCIDs[i] = Players[i]->GetCID();
if(g_Config.m_SvRejoinTeam0 && g_Config.m_SvTeam != 3 && (m_Core.Team(Players[i]->GetCID()) >= TEAM_SUPER || !m_TeamLocked[m_Core.Team(Players[i]->GetCID())]))
if(g_Config.m_SvRejoinTeam0 && g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && (m_Core.Team(Players[i]->GetCID()) >= TEAM_SUPER || !m_TeamLocked[m_Core.Team(Players[i]->GetCID())]))
{
SetForceCharacterTeam(Players[i]->GetCID(), TEAM_FLOCK);
char aBuf[512];
@ -989,7 +989,7 @@ void CGameTeams::OnCharacterSpawn(int ClientID)
if(m_Core.Team(ClientID) >= TEAM_SUPER || !m_TeamLocked[Team])
{
if(g_Config.m_SvTeam != 3)
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO)
SetForceCharacterTeam(ClientID, TEAM_FLOCK);
else
SetForceCharacterTeam(ClientID, ClientID); // initialize team
@ -1006,7 +1006,7 @@ void CGameTeams::OnCharacterDeath(int ClientID, int Weapon)
return;
bool Locked = TeamLocked(Team) && Weapon != WEAPON_GAME;
if(g_Config.m_SvTeam == 3 && Team != TEAM_SUPER)
if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO && Team != TEAM_SUPER)
{
ChangeTeamState(Team, CGameTeams::TEAMSTATE_OPEN);
ResetRoundState(Team);
@ -1077,7 +1077,7 @@ void CGameTeams::KillSavedTeam(int ClientID, int Team)
void CGameTeams::ResetSavedTeam(int ClientID, int Team)
{
if(g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
{
ChangeTeamState(Team, CGameTeams::TEAMSTATE_OPEN);
ResetRoundState(Team);

View file

@ -177,7 +177,7 @@ public:
{
if(TeamID < TEAM_FLOCK || TeamID >= TEAM_SUPER)
return false;
if(g_Config.m_SvTeam != 3 && TeamID == TEAM_FLOCK)
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && TeamID == TEAM_FLOCK)
return false;
return m_pSaveTeamResult[TeamID] != nullptr;
@ -187,7 +187,7 @@ public:
{
if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
return;
if(g_Config.m_SvTeam != 3 && Team == TEAM_FLOCK)
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
return;
m_Practice[Team] = true;
@ -197,7 +197,7 @@ public:
{
if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
return false;
if(g_Config.m_SvTeam != 3 && Team == TEAM_FLOCK)
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
return false;
return m_Practice[Team];

View file

@ -46,7 +46,7 @@ void CTeamsCore::Reset()
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(g_Config.m_SvTeam == 3)
if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
m_Team[i] = i;
else
m_Team[i] = TEAM_FLOCK;

View file

@ -12,6 +12,14 @@ enum
VANILLA_TEAM_SUPER = VANILLA_MAX_CLIENTS
};
enum
{
SV_TEAM_FORBIDDEN,
SV_TEAM_ALLOWED,
SV_TEAM_MANDATORY,
SV_TEAM_FORCED_SOLO
};
class CTeamsCore
{
int m_Team[MAX_CLIENTS];