remove casts to CServer

improving encapsulation by going through the interface instead of including engine/server/server.h
This commit is contained in:
eeeee 2017-06-05 20:51:12 -07:00
parent ec5ede7633
commit 9b6699d3b8
10 changed files with 44 additions and 34 deletions

View file

@ -145,6 +145,11 @@ public:
enum
{
AUTHED_NO=0,
AUTHED_HELPER,
AUTHED_MOD,
AUTHED_ADMIN,
RCON_CID_SERV=-1,
RCON_CID_VOTE=-2,
};
@ -167,6 +172,12 @@ public:
virtual int* GetIdMap(int ClientID) = 0;
virtual bool DnsblWhite(int ClientID) = 0;
virtual const char *GetAnnouncementLine(char const *FileName) = 0;
virtual bool ClientPrevIngame(int ClientID) = 0;
virtual const char *GetNetErrorString(int ClientID) = 0;
virtual void ResetNetErrorString(int ClientID) = 0;
virtual bool SetTimedOut(int ClientID, int OrigID) = 0;
virtual void SetTimeoutProtected(int ClientID) = 0;
};
class IGameServer : public IInterface

View file

@ -2791,7 +2791,7 @@ void CServer::GetClientAddr(int ClientID, NETADDR *pAddr)
}
}
char *CServer::GetAnnouncementLine(char const *pFileName)
const char *CServer::GetAnnouncementLine(char const *pFileName)
{
IOHANDLE File = m_pStorage->OpenFile(pFileName, IOFLAG_READ, IStorage::TYPE_ALL);
if(File)
@ -2831,3 +2831,16 @@ int* CServer::GetIdMap(int ClientID)
{
return (int*)(IdMap + VANILLA_MAX_CLIENTS * ClientID);
}
bool CServer::SetTimedOut(int ClientID, int OrigID) {
if (!m_NetServer.SetTimedOut(ClientID, OrigID))
{
return false;
}
CGameContext *GameServer = (CGameContext *) m_pGameServer;
DelClientCallback(OrigID, "Timeout Protection used", this);
m_aClients[ClientID].m_Authed = IServer::AUTHED_NO;
if (GameServer->m_apPlayers[ClientID]->GetCharacter())
GameServer->SendTuningParams(ClientID, GameServer->m_apPlayers[ClientID]->GetCharacter()->m_TuneZone);
return true;
}

View file

@ -98,11 +98,6 @@ public:
enum
{
AUTHED_NO=0,
AUTHED_HELPER,
AUTHED_MOD,
AUTHED_ADMIN,
MAX_RCONCMD_SEND=16,
};
@ -337,7 +332,7 @@ public:
void GetClientAddr(int ClientID, NETADDR *pAddr);
int m_aPrevStates[MAX_CLIENTS];
char *GetAnnouncementLine(char const *FileName);
const char *GetAnnouncementLine(char const *FileName);
unsigned m_AnnouncementLastLine;
void RestrictRconOutput(int ClientID) { m_RconRestrict = ClientID; }
@ -351,6 +346,11 @@ public:
}
void AuthRemoveKey(int KeySlot);
bool ClientPrevIngame(int ClientID) { return m_aPrevStates[ClientID] == CClient::STATE_INGAME; };
const char *GetNetErrorString(int ClientID) { return m_NetServer.ErrorString(ClientID); };
void ResetNetErrorString(int ClientID) { m_NetServer.ResetErrorString(ClientID); };
bool SetTimedOut(int ClientID, int OrigID);
void SetTimeoutProtected(int ClientID) { m_NetServer.SetTimeoutProtected(ClientID); };
};
#endif

View file

@ -2,7 +2,6 @@
#include "gamecontext.h"
#include <engine/shared/config.h>
#include <engine/shared/protocol.h>
#include <engine/server/server.h>
#include <game/server/teams.h>
#include <game/server/gamemodes/DDRace.h>
#include <game/version.h>
@ -279,7 +278,7 @@ void CGameContext::ConToggleSpec(IConsole::IResult *pResult, void *pUserData)
}
CGameContext *pSelf = (CGameContext *) pUserData;
CServer* pServ = (CServer*)pSelf->Server();
IServer* pServ = pSelf->Server();
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
if(!pPlayer)
return;
@ -307,7 +306,7 @@ void CGameContext::ConTogglePause(IConsole::IResult *pResult, void *pUserData)
return;
CGameContext *pSelf = (CGameContext *) pUserData;
CServer* pServ = (CServer*)pSelf->Server();
IServer* pServ = pSelf->Server();
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
if(!pPlayer)
return;
@ -539,17 +538,12 @@ void CGameContext::ConTimeout(IConsole::IResult *pResult, void *pUserData)
if (i == pResult->m_ClientID) continue;
if (!pSelf->m_apPlayers[i]) continue;
if (str_comp(pSelf->m_apPlayers[i]->m_TimeoutCode, pResult->GetString(0))) continue;
if (((CServer *)pSelf->Server())->m_NetServer.SetTimedOut(i, pResult->m_ClientID))
{
((CServer *)pSelf->Server())->DelClientCallback(pResult->m_ClientID, "Timeout Protection used", ((CServer *)pSelf->Server()));
((CServer *)pSelf->Server())->m_aClients[i].m_Authed = CServer::AUTHED_NO;
if (pSelf->m_apPlayers[i]->GetCharacter())
((CGameContext *)(((CServer *)pSelf->Server())->GameServer()))->SendTuningParams(i, pSelf->m_apPlayers[i]->GetCharacter()->m_TuneZone);
if (pSelf->Server()->SetTimedOut(i, pResult->m_ClientID)) {
return;
}
}
((CServer *)pSelf->Server())->m_NetServer.SetTimeoutProtected(pResult->m_ClientID);
pSelf->Server()->SetTimeoutProtected(pResult->m_ClientID);
str_copy(pPlayer->m_TimeoutCode, pResult->GetString(0), sizeof(pPlayer->m_TimeoutCode));
}

View file

@ -1,7 +1,6 @@
/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
#include "gamecontext.h"
#include <engine/shared/config.h>
#include <engine/server/server.h>
#include <game/server/teams.h>
#include <game/server/gamemodes/DDRace.h>
#include <game/version.h>

View file

@ -11,7 +11,6 @@
#include <stdio.h>
#include <string.h>
#include <engine/server/server.h>
#include <game/server/gamemodes/DDRace.h>
#include <game/server/score.h>
#include "light.h"

View file

@ -21,7 +21,6 @@
#include <stdio.h>
#include <string.h>
#include <engine/server/server.h>
#include "gamemodes/DDRace.h"
#include "score.h"
#include "score/file_score.h"
@ -767,7 +766,7 @@ void CGameContext::OnTick()
if(Server()->Tick() % (g_Config.m_SvAnnouncementInterval * Server()->TickSpeed() * 60) == 0)
{
char *Line = ((CServer *) Server())->GetAnnouncementLine(g_Config.m_SvAnnouncementFileName);
const char *Line = Server()->GetAnnouncementLine(g_Config.m_SvAnnouncementFileName);
if(Line)
SendChat(-1, CGameContext::CHAT_ALL, Line);
}
@ -917,7 +916,7 @@ void CGameContext::OnClientEnter(int ClientID)
Score()->LoadScore(ClientID);
Score()->CheckBirthday(ClientID);
if(((CServer *) Server())->m_aPrevStates[ClientID] < CServer::CClient::STATE_INGAME)
if(!Server()->ClientPrevIngame(ClientID))
{
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "'%s' entered and joined the %s", Server()->ClientName(ClientID), m_pController->GetTeamName(m_apPlayers[ClientID]->GetTeam()));
@ -946,7 +945,7 @@ void CGameContext::OnClientEnter(int ClientID)
if(m_VoteCloseTime)
SendVoteSet(ClientID);
m_apPlayers[ClientID]->m_Authed = ((CServer*)Server())->m_aClients[ClientID].m_Authed;
m_apPlayers[ClientID]->m_Authed = Server()->IsAuthed(ClientID);
}
void CGameContext::OnClientConnected(int ClientID)
@ -1131,7 +1130,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
Console()->SetFlagMask(CFGFLAG_CHAT);
if (pPlayer->m_Authed)
Console()->SetAccessLevel(pPlayer->m_Authed == CServer::AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : pPlayer->m_Authed == CServer::AUTHED_MOD ? IConsole::ACCESS_LEVEL_MOD : IConsole::ACCESS_LEVEL_HELPER);
Console()->SetAccessLevel(pPlayer->m_Authed == IServer::AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : pPlayer->m_Authed == IServer::AUTHED_MOD ? IConsole::ACCESS_LEVEL_MOD : IConsole::ACCESS_LEVEL_HELPER);
else
Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_USER);
Console()->SetPrintOutputLevel(m_ChatPrintCBIndex, 0);
@ -1312,7 +1311,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
if(!pOption)
{
if (pPlayer->m_Authed != CServer::AUTHED_ADMIN) // allow admins to call any vote they want
if (pPlayer->m_Authed != IServer::AUTHED_ADMIN) // allow admins to call any vote they want
{
str_format(aChatmsg, sizeof(aChatmsg), "'%s' isn't an option on this server", pMsg->m_Value);
SendChatTarget(ClientID, aChatmsg);
@ -2952,12 +2951,11 @@ float CGameContext::PlayerJetpack()
void CGameContext::OnSetAuthed(int ClientID, int Level)
{
CServer *pServ = (CServer*)Server();
if(m_apPlayers[ClientID])
{
m_apPlayers[ClientID]->m_Authed = Level;
char aBuf[512], aIP[NETADDR_MAXSTRSIZE];
pServ->GetClientAddr(ClientID, aIP, sizeof(aIP));
Server()->GetClientAddr(ClientID, aIP, sizeof(aIP));
str_format(aBuf, sizeof(aBuf), "ban %s %d Banned by vote", aIP, g_Config.m_SvVoteKickBantime);
if(!str_comp_nocase(m_aVoteCommand, aBuf) && Level > 0)
{

View file

@ -5,7 +5,6 @@
#include "player.h"
#include <engine/server.h>
#include <engine/server/server.h>
#include "gamecontext.h"
#include <game/gamecore.h>
#include <game/version.h>
@ -181,12 +180,12 @@ void CPlayer::Tick()
}
}
if(((CServer *)Server())->m_NetServer.ErrorString(m_ClientID)[0])
if(Server()->GetNetErrorString(m_ClientID)[0])
{
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);
((CServer *)(Server()))->m_NetServer.ResetErrorString(m_ClientID);
Server()->ResetNetErrorString(m_ClientID);
}
if(!GameServer()->m_World.m_Paused)
@ -618,8 +617,7 @@ bool CPlayer::AfkTimer(int NewTargetX, int NewTargetY)
}
else if(m_LastPlaytime < time_get()-time_freq()*g_Config.m_SvMaxAfkTime)
{
CServer* serv = (CServer*)m_pGameServer->Server();
serv->Kick(m_ClientID,"Away from keyboard");
m_pGameServer->Server()->Kick(m_ClientID, "Away from keyboard");
return true;
}
}

View file

@ -3,7 +3,6 @@
#include "save.h"
#include "teams.h"
#include <engine/server/server.h>
#include "./gamemodes/DDRace.h"
#include <engine/shared/config.h>

View file

@ -1,7 +1,6 @@
/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
#include "teams.h"
#include <engine/shared/config.h>
#include <engine/server/server.h>
CGameTeams::CGameTeams(CGameContext *pGameContext) :
m_pGameContext(pGameContext)