Backport IGameController::OnPlayerDisconnect() from the upstream

Upstream commit 5e4caa9b9c
This commit is contained in:
Alexander Akulich 2021-01-12 23:03:20 +03:00
parent 7512ad285b
commit 19234987c9
5 changed files with 33 additions and 27 deletions

View file

@ -1394,7 +1394,7 @@ void CGameContext::OnClientConnected(int ClientID)
void CGameContext::OnClientDrop(int ClientID, const char *pReason)
{
AbortVoteKickOnDisconnect(ClientID);
m_apPlayers[ClientID]->OnDisconnect(pReason);
m_pController->OnPlayerDisconnect(m_apPlayers[ClientID], pReason);
delete m_apPlayers[ClientID];
m_apPlayers[ClientID] = 0;

View file

@ -385,6 +385,33 @@ bool IGameController::OnEntity(int Index, vec2 Pos, int Layer, int Flags, int Nu
return false;
}
void IGameController::OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason)
{
bool WasModerator = pPlayer->m_Moderating;
pPlayer->OnDisconnect();
int ClientID = pPlayer->GetCID();
if(Server()->ClientIngame(ClientID))
{
char aBuf[512];
if(pReason && *pReason)
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);
str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", ClientID, Server()->ClientName(ClientID));
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf);
if(!GameServer()->PlayerModerating() && WasModerator)
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Server kick/spec votes are no longer actively moderated.");
}
CGameControllerDDRace *Controller = (CGameControllerDDRace *)GameServer()->m_pController;
if(g_Config.m_SvTeam != 3)
Controller->m_Teams.SetForceCharacterTeam(ClientID, TEAM_FLOCK);
}
void IGameController::EndRound()
{
if(m_Warmup) // game can't end when we are running warmup

View file

@ -113,6 +113,8 @@ public:
*/
virtual bool OnEntity(int Index, vec2 Pos, int Layer, int Flags, int Number = 0);
void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason);
void OnReset();
// game

View file

@ -468,34 +468,11 @@ void CPlayer::FakeSnap()
pSpectatorInfo->m_Y = m_ViewPos.y;
}
void CPlayer::OnDisconnect(const char *pReason)
void CPlayer::OnDisconnect()
{
KillCharacter();
if(Server()->ClientIngame(m_ClientID))
{
char aBuf[512];
if(pReason && *pReason)
str_format(aBuf, sizeof(aBuf), "'%s' has left the game (%s)", Server()->ClientName(m_ClientID), pReason);
else
str_format(aBuf, sizeof(aBuf), "'%s' has left the game", Server()->ClientName(m_ClientID));
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, -1, CGameContext::CHAT_SIX);
str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID));
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf);
bool WasModerator = m_Moderating;
// Set this to false, otherwise PlayerModerating() will return true.
m_Moderating = false;
if(!GameServer()->PlayerModerating() && WasModerator)
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Server kick/spec votes are no longer actively moderated.");
}
CGameControllerDDRace *Controller = (CGameControllerDDRace *)GameServer()->m_pController;
if(g_Config.m_SvTeam != 3)
Controller->m_Teams.SetForceCharacterTeam(m_ClientID, TEAM_FLOCK);
m_Moderating = false;
}
void CPlayer::OnPredictedInput(CNetObj_PlayerInput *NewInput)

View file

@ -47,7 +47,7 @@ public:
void OnDirectInput(CNetObj_PlayerInput *NewInput);
void OnPredictedInput(CNetObj_PlayerInput *NewInput);
void OnPredictedEarlyInput(CNetObj_PlayerInput *NewInput);
void OnDisconnect(const char *pReason);
void OnDisconnect();
void KillCharacter(int Weapon = WEAPON_GAME);
CCharacter *GetCharacter();