From 0b6bb8287aebfc2d90fa8356769c84956c08ade5 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 5 May 2024 11:35:17 +0800 Subject: [PATCH] Use enum for teams (Closed #8306) --- datasrc/compile.py | 7 +++-- datasrc/datatypes.py | 3 +- datasrc/network.py | 6 ++-- src/game/client/components/chat.cpp | 6 ++-- src/game/server/ddracechat.cpp | 6 ++-- src/game/server/ddracecommands.cpp | 14 +++++----- src/game/server/gamecontext.cpp | 42 ++++++++++++++-------------- src/game/server/gamecontext.h | 7 ----- src/game/server/gamecontroller.cpp | 4 +-- src/game/server/gamemodes/DDRace.cpp | 4 +-- src/game/server/gameworld.cpp | 2 +- src/game/server/player.cpp | 12 ++++---- src/game/server/teams.cpp | 10 +++---- src/game/server/teams.h | 16 +++++------ src/game/teamscore.h | 2 +- src/tools/demo_extract_chat.cpp | 4 +-- 16 files changed, 70 insertions(+), 75 deletions(-) diff --git a/datasrc/compile.py b/datasrc/compile.py index 34dd1ea0b..fa8522aa3 100644 --- a/datasrc/compile.py +++ b/datasrc/compile.py @@ -4,9 +4,12 @@ import network from datatypes import EmitDefinition, EmitTypeDeclaration -def create_enum_table(names, num): +def create_enum_table(names, num, start = 0): lines = [] lines += ["enum", "{"] + if len(names) > 0 and start != 0: + lines += [f"\t{names[0]} = {start},"] + names = names[1:] for name in names: lines += [f"\t{name},"] lines += [f"\t{num}", "};"] @@ -48,7 +51,7 @@ def gen_network_header(): print(network.RawHeader) for e in network.Enums: - for line in create_enum_table([f"{e.name}_{v}" for v in e.values], f'NUM_{e.name}S'): # pylint: disable=no-member + for line in create_enum_table([f"{e.name}_{v}" for v in e.values], f'NUM_{e.name}S', e.start): # pylint: disable=no-member print(line) print("") diff --git a/datasrc/datatypes.py b/datasrc/datatypes.py index 182a9aed3..8d3ce023b 100644 --- a/datasrc/datatypes.py +++ b/datasrc/datatypes.py @@ -196,9 +196,10 @@ class Object: pass class Enum: - def __init__(self, name, values): + def __init__(self, name, values, start = 0): self.name = name self.values = values + self.start = start class Flags: def __init__(self, name, values): diff --git a/datasrc/network.py b/datasrc/network.py index 112dc4c52..d6c33ffae 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -49,6 +49,7 @@ Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", Powerups = ["HEALTH", "ARMOR", "WEAPON", "NINJA", "ARMOR_SHOTGUN", "ARMOR_GRENADE", "ARMOR_NINJA", "ARMOR_LASER"] Authed = ["NO", "HELPER", "MOD", "ADMIN"] EntityClasses = ["PROJECTILE", "DOOR", "DRAGGER_WEAK", "DRAGGER_NORMAL", "DRAGGER_STRONG", "GUN_NORMAL", "GUN_EXPLOSIVE", "GUN_FREEZE", "GUN_UNFREEZE", "LIGHT", "PICKUP"] +Teams = ["ALL", "SPECTATORS", "RED", "BLUE", "WHISPER_SEND", "WHISPER_RECV"] RawHeader = ''' #include @@ -60,10 +61,6 @@ enum enum { - TEAM_SPECTATORS=-1, - TEAM_RED, - TEAM_BLUE, - FLAG_MISSING=-3, FLAG_ATSTAND, FLAG_TAKEN, @@ -87,6 +84,7 @@ Enums = [ Enum("LASERTYPE", LaserTypes), Enum("LASERDRAGGERTYPE", DraggerTypes), Enum("LASERGUNTYPE", GunTypes), + Enum("TEAM", Teams, -2), ] Flags = [ diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index d68296efb..5f7b4fff3 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -815,14 +815,14 @@ void CChat::AddLine(int ClientId, int Team, const char *pLine) pCurrentLine->m_NameColor = TEAM_BLUE; } - if(Team == 2) // whisper send + if(Team == TEAM_WHISPER_SEND) { str_format(pCurrentLine->m_aName, sizeof(pCurrentLine->m_aName), "→ %s", LineAuthor.m_aName); pCurrentLine->m_NameColor = TEAM_BLUE; pCurrentLine->m_Highlighted = false; Highlighted = false; } - else if(Team == 3) // whisper recv + else if(Team == TEAM_WHISPER_RECV) { str_format(pCurrentLine->m_aName, sizeof(pCurrentLine->m_aName), "← %s", LineAuthor.m_aName); pCurrentLine->m_NameColor = TEAM_RED; @@ -894,7 +894,7 @@ void CChat::AddLine(int ClientId, int Team, const char *pLine) } } } - else if(Team != 2) + else if(Team != TEAM_WHISPER_SEND) { if(Now - m_aLastSoundPlayed[CHAT_CLIENT] >= time_freq() * 3 / 10) { diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 0d75dfb8d..33ea3b329 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -1052,7 +1052,7 @@ void CGameContext::AttemptJoinTeam(int ClientId, int Team) str_format(aBuf, sizeof(aBuf), "'%s' joined team %d", Server()->ClientName(pPlayer->GetCid()), Team); - SendChat(-1, CGameContext::CHAT_ALL, aBuf); + SendChat(-1, TEAM_ALL, aBuf); pPlayer->m_Last_Team = Server()->Tick(); if(m_pController->Teams().IsPractice(Team)) @@ -1286,7 +1286,7 @@ void CGameContext::ConMe(IConsole::IResult *pResult, void *pUserData) pSelf->Server()->ClientName(pResult->m_ClientId), pResult->GetString(0)); if(g_Config.m_SvSlashMe) - pSelf->SendChat(-2, CGameContext::CHAT_ALL, aBuf, pResult->m_ClientId); + pSelf->SendChat(-2, TEAM_ALL, aBuf, pResult->m_ClientId); else pSelf->Console()->Print( IConsole::OUTPUT_LEVEL_STANDARD, @@ -1552,7 +1552,7 @@ void CGameContext::ConSayTimeAll(IConsole::IResult *pResult, void *pUserData) const char *pName = pSelf->Server()->ClientName(pResult->m_ClientId); str_time(Time, TIME_HOURS, aBufTime, sizeof(aBufTime)); str_format(aBuf, sizeof(aBuf), "%s\'s current race time is %s", pName, aBufTime); - pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf, pResult->m_ClientId); + pSelf->SendChat(-1, TEAM_ALL, aBuf, pResult->m_ClientId); } void CGameContext::ConTime(IConsole::IResult *pResult, void *pUserData) diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index a9ea9693d..2f15c066e 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -95,7 +95,7 @@ void CGameContext::ConKillPlayer(IConsole::IResult *pResult, void *pUserData) str_format(aBuf, sizeof(aBuf), "%s was killed by %s", pSelf->Server()->ClientName(Victim), pSelf->Server()->ClientName(pResult->m_ClientId)); - pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + pSelf->SendChat(-1, TEAM_ALL, aBuf); } } @@ -489,7 +489,7 @@ void CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pReason, else str_format(aBuf, sizeof(aBuf), "'%s' banned '%s' for %d seconds from voting", Server()->ClientName(AuthedId), pDisplayName, Secs); - SendChat(-1, CHAT_ALL, aBuf); + SendChat(-1, TEAM_ALL, aBuf); } bool CGameContext::VoteUnmute(const NETADDR *pAddr, const char *pDisplayName, int AuthedId) @@ -562,7 +562,7 @@ void CGameContext::Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName str_format(aBuf, sizeof(aBuf), "'%s' has been muted for %d seconds (%s)", pDisplayName, Secs, pReason); else str_format(aBuf, sizeof(aBuf), "'%s' has been muted for %d seconds", pDisplayName, Secs); - SendChat(-1, CHAT_ALL, aBuf); + SendChat(-1, TEAM_ALL, aBuf); } void CGameContext::ConVoteMute(IConsole::IResult *pResult, void *pUserData) @@ -764,10 +764,10 @@ void CGameContext::ConModerate(IConsole::IResult *pResult, void *pUserData) pPlayer->m_Moderating = !pPlayer->m_Moderating; if(!HadModerator && pPlayer->m_Moderating) - pSelf->SendChat(-1, CHAT_ALL, "Server kick/spec votes will now be actively moderated.", 0); + pSelf->SendChat(-1, TEAM_ALL, "Server kick/spec votes will now be actively moderated.", 0); if(!pSelf->PlayerModerating()) - pSelf->SendChat(-1, CHAT_ALL, "Server kick/spec votes are no longer actively moderated.", 0); + pSelf->SendChat(-1, TEAM_ALL, "Server kick/spec votes are no longer actively moderated.", 0); if(pPlayer->m_Moderating) pSelf->SendChatTarget(pResult->m_ClientId, "Active moderator mode enabled for you."); @@ -822,7 +822,7 @@ void CGameContext::ConFreezeHammer(IConsole::IResult *pResult, void *pUserData) char aBuf[128]; str_format(aBuf, sizeof(aBuf), "'%s' got freeze hammer!", pSelf->Server()->ClientName(Victim)); - pSelf->SendChat(-1, CHAT_ALL, aBuf); + pSelf->SendChat(-1, TEAM_ALL, aBuf); pChr->m_FreezeHammer = true; } @@ -840,7 +840,7 @@ void CGameContext::ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData char aBuf[128]; str_format(aBuf, sizeof(aBuf), "'%s' lost freeze hammer!", pSelf->Server()->ClientName(Victim)); - pSelf->SendChat(-1, CHAT_ALL, aBuf); + pSelf->SendChat(-1, TEAM_ALL, aBuf); pChr->m_FreezeHammer = false; } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 3e0089456..6ca53c492 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -534,7 +534,7 @@ void CGameContext::CallVote(int ClientId, const char *pDesc, const char *pCmd, c if(!pPlayer) return; - SendChat(-1, CGameContext::CHAT_ALL, pChatmsg, -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, pChatmsg, -1, CHAT_SIX); if(!pSixupDesc) pSixupDesc = pDesc; @@ -601,9 +601,9 @@ void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText, in } else str_format(aBuf, sizeof(aBuf), "*** %s", aText); - Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, Team != CHAT_ALL ? "teamchat" : "chat", aBuf); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, Team != TEAM_ALL ? "teamchat" : "chat", aBuf); - if(Team == CHAT_ALL) + if(Team == TEAM_ALL) { CNetMsg_Sv_Chat Msg; Msg.m_Team = 0; @@ -646,16 +646,16 @@ void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText, in { if(m_apPlayers[i] != 0) { - if(Team == CHAT_SPEC) + if(Team == TEAM_SPECTATORS) { - if(m_apPlayers[i]->GetTeam() == CHAT_SPEC) + if(m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS) { Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, i); } } else { - if(pTeams->Team(i) == Team && m_apPlayers[i]->GetTeam() != CHAT_SPEC) + if(pTeams->Team(i) == Team && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) { Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, i); } @@ -1033,14 +1033,14 @@ void CGameContext::OnTick() // abort the kick-vote on player-leave if(m_VoteEnforce == VOTE_ENFORCE_ABORT) { - SendChat(-1, CGameContext::CHAT_ALL, "Vote aborted"); + SendChat(-1, TEAM_ALL, "Vote aborted"); EndVote(); } else if(m_VoteEnforce == VOTE_ENFORCE_CANCEL) { char aBuf[64]; str_format(aBuf, sizeof(aBuf), "'%s' canceled their vote", Server()->ClientName(m_VoteCreator)); - SendChat(-1, CGameContext::CHAT_ALL, aBuf); + SendChat(-1, TEAM_ALL, aBuf); EndVote(); } else @@ -1169,7 +1169,7 @@ void CGameContext::OnTick() Console()->ExecuteLine(m_aVoteCommand); Server()->SetRconCid(IServer::RCON_CID_SERV); EndVote(); - SendChat(-1, CGameContext::CHAT_ALL, "Vote passed", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote passed", -1, CHAT_SIX); if(m_apPlayers[m_VoteCreator] && !IsKickVote() && !IsSpecVote()) m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; @@ -1177,22 +1177,22 @@ void CGameContext::OnTick() else if(m_VoteEnforce == VOTE_ENFORCE_YES_ADMIN) { Console()->ExecuteLine(m_aVoteCommand, m_VoteEnforcer); - SendChat(-1, CGameContext::CHAT_ALL, "Vote passed enforced by authorized player", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote passed enforced by authorized player", -1, CHAT_SIX); EndVote(); } else if(m_VoteEnforce == VOTE_ENFORCE_NO_ADMIN) { EndVote(); - SendChat(-1, CGameContext::CHAT_ALL, "Vote failed enforced by authorized player", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote failed enforced by authorized player", -1, CHAT_SIX); } //else if(m_VoteEnforce == VOTE_ENFORCE_NO || time_get() > m_VoteCloseTime) else if(m_VoteEnforce == VOTE_ENFORCE_NO || (time_get() > m_VoteCloseTime && g_Config.m_SvVoteMajority)) { EndVote(); if(VetoStop || (m_VoteWillPass && Veto)) - SendChat(-1, CGameContext::CHAT_ALL, "Vote failed because of veto. Find an empty server instead", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote failed because of veto. Find an empty server instead", -1, CHAT_SIX); else - SendChat(-1, CGameContext::CHAT_ALL, "Vote failed", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote failed", -1, CHAT_SIX); } else if(m_VoteUpdate) { @@ -1222,7 +1222,7 @@ void CGameContext::OnTick() { const char *pLine = Server()->GetAnnouncementLine(g_Config.m_SvAnnouncementFileName); if(pLine) - SendChat(-1, CGameContext::CHAT_ALL, pLine); + SendChat(-1, TEAM_ALL, pLine); } for(auto &Switcher : Switchers()) @@ -2103,9 +2103,9 @@ void CGameContext::OnSayNetMessage(const CNetMsg_Cl_Say *pMsg, int ClientId, con int GameTeam = GetDDRaceTeam(pPlayer->GetCid()); if(Team) - Team = ((pPlayer->GetTeam() == TEAM_SPECTATORS) ? CHAT_SPEC : GameTeam); + Team = ((pPlayer->GetTeam() == TEAM_SPECTATORS) ? TEAM_SPECTATORS : GameTeam); else - Team = CHAT_ALL; + Team = TEAM_ALL; if(pMsg->m_pMessage[0] == '/') { @@ -2585,7 +2585,7 @@ void CGameContext::OnChangeInfoNetMessage(const CNetMsg_Cl_ChangeInfo *pMsg, int char aChatText[256]; str_format(aChatText, sizeof(aChatText), "'%s' changed name to '%s'", aOldName, Server()->ClientName(ClientId)); - SendChat(-1, CGameContext::CHAT_ALL, aChatText); + SendChat(-1, TEAM_ALL, aChatText); // reload scores Score()->PlayerData(ClientId)->Reset(); @@ -3126,7 +3126,7 @@ void CGameContext::ConBroadcast(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConSay(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - pSelf->SendChat(-1, CGameContext::CHAT_ALL, pResult->GetString(0)); + pSelf->SendChat(-1, TEAM_ALL, pResult->GetString(0)); } void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData) @@ -3156,7 +3156,7 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData) char aBuf[256]; str_format(aBuf, sizeof(aBuf), "All players were moved to the %s", pSelf->m_pController->GetTeamName(Team)); - pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + pSelf->SendChat(-1, TEAM_ALL, aBuf); for(auto &pPlayer : pSelf->m_apPlayers) if(pPlayer) @@ -4564,7 +4564,7 @@ void CGameContext::WhisperId(int ClientId, int VictimId, const char *pMessage) else if(GetClientVersion(ClientId) >= VERSION_DDNET_WHISPER) { CNetMsg_Sv_Chat Msg; - Msg.m_Team = CHAT_WHISPER_SEND; + Msg.m_Team = TEAM_WHISPER_SEND; Msg.m_ClientId = VictimId; Msg.m_pMessage = aCensoredMessage; if(g_Config.m_SvDemoChat) @@ -4591,7 +4591,7 @@ void CGameContext::WhisperId(int ClientId, int VictimId, const char *pMessage) else if(GetClientVersion(VictimId) >= VERSION_DDNET_WHISPER) { CNetMsg_Sv_Chat Msg2; - Msg2.m_Team = CHAT_WHISPER_RECV; + Msg2.m_Team = TEAM_WHISPER_RECV; Msg2.m_ClientId = ClientId; Msg2.m_pMessage = aCensoredMessage; if(g_Config.m_SvDemoChat) diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index a47effe24..ec1f1624e 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -248,13 +248,6 @@ public: enum { - CHAT_ALL = -2, - CHAT_SPEC = -1, - CHAT_RED = 0, - CHAT_BLUE = 1, - CHAT_WHISPER_SEND = 2, - CHAT_WHISPER_RECV = 3, - CHAT_SIX = 1 << 0, CHAT_SIXUP = 1 << 1, }; diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 557503787..41c11a7c7 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -410,7 +410,7 @@ void IGameController::OnPlayerDisconnect(class CPlayer *pPlayer, const char *pRe str_format(aBuf, sizeof(aBuf), "'%s' has left the game (%s)", Server()->ClientName(ClientId), pReason); else str_format(aBuf, sizeof(aBuf), "'%s' has left the game", Server()->ClientName(ClientId)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, -1, CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::CHAT_SIX); str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", ClientId, Server()->ClientName(ClientId)); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf); @@ -722,7 +722,7 @@ void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg) if(DoChatMsg) { str_format(aBuf, sizeof(aBuf), "'%s' joined the %s", Server()->ClientName(ClientId), GameServer()->m_pController->GetTeamName(Team)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + GameServer()->SendChat(-1, TEAM_ALL, aBuf); } str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", ClientId, Server()->ClientName(ClientId), Team); diff --git a/src/game/server/gamemodes/DDRace.cpp b/src/game/server/gamemodes/DDRace.cpp index 3ab91ec0d..ff7fbdbd3 100644 --- a/src/game/server/gamemodes/DDRace.cpp +++ b/src/game/server/gamemodes/DDRace.cpp @@ -127,7 +127,7 @@ void CGameControllerDDRace::OnPlayerConnect(CPlayer *pPlayer) { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "'%s' entered and joined the %s", Server()->ClientName(ClientId), GetTeamName(pPlayer->GetTeam())); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, -1, CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::CHAT_SIX); GameServer()->SendChatTarget(ClientId, "DDraceNetwork Mod. Version: " GAME_VERSION); GameServer()->SendChatTarget(ClientId, "please visit DDNet.org or say /info and make sure to read our /rules"); @@ -142,7 +142,7 @@ void CGameControllerDDRace::OnPlayerDisconnect(CPlayer *pPlayer, const char *pRe IGameController::OnPlayerDisconnect(pPlayer, pReason); if(!GameServer()->PlayerModerating() && WasModerator) - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Server kick/spec votes are no longer actively moderated."); + GameServer()->SendChat(-1, TEAM_ALL, "Server kick/spec votes are no longer actively moderated."); if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO) Teams().SetForceCharacterTeam(ClientId, TEAM_FLOCK); diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 6166d2ff1..4e9d90aa4 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -212,7 +212,7 @@ void CGameWorld::Tick() if(!m_Paused) { if(GameServer()->m_pController->IsForceBalanced()) - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Teams have been balanced"); + GameServer()->SendChat(-1, TEAM_ALL, "Teams have been balanced"); // update all objects for(int i = 0; i < NUM_ENTTYPES; i++) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index c7a137665..cf9d4b2d3 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -183,7 +183,7 @@ void CPlayer::Tick() GameServer()->SendChatTarget(m_ClientId, "Active moderator mode disabled because you are afk."); if(!GameServer()->PlayerModerating()) - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Server kick/spec votes are no longer actively moderated."); + GameServer()->SendChat(-1, TEAM_ALL, "Server kick/spec votes are no longer actively moderated."); } // do latency stuff @@ -213,7 +213,7 @@ void CPlayer::Tick() char aBuf[512]; str_format(aBuf, sizeof(aBuf), "'%s' would have timed out, but can use timeout protection now", Server()->ClientName(m_ClientId)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + GameServer()->SendChat(-1, TEAM_ALL, aBuf); Server()->ResetNetErrorString(m_ClientId); } @@ -799,7 +799,7 @@ int CPlayer::Pause(int State, bool Force) if(g_Config.m_SvPauseMessages) { str_format(aBuf, sizeof(aBuf), (State > PAUSE_NONE) ? "'%s' speced" : "'%s' resumed", Server()->ClientName(m_ClientId)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + GameServer()->SendChat(-1, TEAM_ALL, aBuf); } break; } @@ -829,7 +829,7 @@ int CPlayer::ForcePause(int Time) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "'%s' was force-paused for %ds", Server()->ClientName(m_ClientId), Time); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + GameServer()->SendChat(-1, TEAM_ALL, aBuf); } return Pause(PAUSE_SPEC, true); @@ -885,7 +885,7 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result) if(GameServer()->ProcessSpamProtection(m_ClientId) && PrimaryMessage) break; - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aMessage, -1); + GameServer()->SendChat(-1, TEAM_ALL, aMessage, -1); PrimaryMessage = false; } break; @@ -924,7 +924,7 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result) str_format(aBuf, sizeof(aBuf), "Happy DDNet birthday to %s for finishing their first map %d year%s ago!", Server()->ClientName(m_ClientId), Birthday, Birthday > 1 ? "s" : ""); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, m_ClientId); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, m_ClientId); str_format(aBuf, sizeof(aBuf), "Happy DDNet birthday, %s!\nYou have finished your first map exactly %d year%s ago!", Server()->ClientName(m_ClientId), Birthday, Birthday > 1 ? "s" : ""); diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index 6f15fa78b..870d9ff13 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -28,7 +28,7 @@ void CGameTeams::Reset() SendTeamsState(i); } - for(int i = 0; i < NUM_TEAMS; ++i) + for(int i = 0; i < NUM_DDRACE_TEAMS; ++i) { m_aTeamState[i] = TEAMSTATE_EMPTY; m_aTeamLocked[i] = false; @@ -680,7 +680,7 @@ void CGameTeams::OnTeamFinish(CPlayer **Players, unsigned int Size, float Time, char aBuf[512]; str_format(aBuf, sizeof(aBuf), "'%s' joined team 0", GameServer()->Server()->ClientName(Players[i]->GetCid())); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + GameServer()->SendChat(-1, TEAM_ALL, aBuf); } } @@ -706,7 +706,7 @@ void CGameTeams::OnFinish(CPlayer *Player, float Time, const char *pTimestamp) if(g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores) GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::CHAT_SIX); else - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, -1., CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1., CGameContext::CHAT_SIX); float Diff = absolute(Time - pData->m_BestTime); @@ -725,7 +725,7 @@ void CGameTeams::OnFinish(CPlayer *Player, float Time, const char *pTimestamp) if(g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores) GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::CHAT_SIX); else - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, -1, CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::CHAT_SIX); } else if(pData->m_BestTime != 0) // tee has already finished? { @@ -965,7 +965,7 @@ void CGameTeams::SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPla void CGameTeams::ProcessSaveTeam() { - for(int Team = 0; Team < NUM_TEAMS; Team++) + for(int Team = 0; Team < NUM_DDRACE_TEAMS; Team++) { if(m_apSaveTeamResult[Team] == nullptr || !m_apSaveTeamResult[Team]->m_Completed) continue; diff --git a/src/game/server/teams.h b/src/game/server/teams.h index b703ed078..e4bdc3199 100644 --- a/src/game/server/teams.h +++ b/src/game/server/teams.h @@ -23,19 +23,19 @@ class CGameTeams bool m_aTeeFinished[MAX_CLIENTS]; int m_aLastChat[MAX_CLIENTS]; - int m_aTeamState[NUM_TEAMS]; - bool m_aTeamLocked[NUM_TEAMS]; - bool m_aTeamFlock[NUM_TEAMS]; - CClientMask m_aInvited[NUM_TEAMS]; - bool m_aPractice[NUM_TEAMS]; - std::shared_ptr m_apSaveTeamResult[NUM_TEAMS]; + int m_aTeamState[NUM_DDRACE_TEAMS]; + bool m_aTeamLocked[NUM_DDRACE_TEAMS]; + bool m_aTeamFlock[NUM_DDRACE_TEAMS]; + CClientMask m_aInvited[NUM_DDRACE_TEAMS]; + bool m_aPractice[NUM_DDRACE_TEAMS]; + std::shared_ptr m_apSaveTeamResult[NUM_DDRACE_TEAMS]; uint64_t m_aLastSwap[MAX_CLIENTS]; // index is id of player who initiated swap - bool m_aTeamSentStartWarning[NUM_TEAMS]; + bool m_aTeamSentStartWarning[NUM_DDRACE_TEAMS]; // `m_aTeamUnfinishableKillTick` is -1 by default and gets set when a // team becomes unfinishable. If the team hasn't entered practice mode // by that time, it'll get killed to prevent people not understanding // the message from playing for a long time in an unfinishable team. - int m_aTeamUnfinishableKillTick[NUM_TEAMS]; + int m_aTeamUnfinishableKillTick[NUM_DDRACE_TEAMS]; class CGameContext *m_pGameContext; diff --git a/src/game/teamscore.h b/src/game/teamscore.h index c651ac319..4c8229482 100644 --- a/src/game/teamscore.h +++ b/src/game/teamscore.h @@ -8,7 +8,7 @@ enum { TEAM_FLOCK = 0, TEAM_SUPER = MAX_CLIENTS, - NUM_TEAMS = TEAM_SUPER + 1, + NUM_DDRACE_TEAMS = TEAM_SUPER + 1, VANILLA_TEAM_SUPER = VANILLA_MAX_CLIENTS }; diff --git a/src/tools/demo_extract_chat.cpp b/src/tools/demo_extract_chat.cpp index 5c19153f3..e8157e954 100644 --- a/src/tools/demo_extract_chat.cpp +++ b/src/tools/demo_extract_chat.cpp @@ -173,9 +173,9 @@ public: return; } - if(pMsg->m_Team == 2) // WHISPER SEND + if(pMsg->m_Team == TEAM_WHISPER_SEND) printf("%s: -> %s: %s\n", Prefix, m_pClientSnapshotHandler->m_aClients[pMsg->m_ClientId].m_aName, pMsg->m_pMessage); - else if(pMsg->m_Team == 3) // WHISPER RECEIVE + else if(pMsg->m_Team == TEAM_WHISPER_RECV) printf("%s: <- %s: %s\n", Prefix, m_pClientSnapshotHandler->m_aClients[pMsg->m_ClientId].m_aName, pMsg->m_pMessage); else printf("%s: %s: %s\n", Prefix, m_pClientSnapshotHandler->m_aClients[pMsg->m_ClientId].m_aName, pMsg->m_pMessage);