2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_SERVER_SERVER_H
|
|
|
|
#define ENGINE_SERVER_SERVER_H
|
|
|
|
|
|
|
|
#include <engine/server.h>
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <engine/map.h>
|
2010-09-13 04:49:01 +00:00
|
|
|
#include <engine/shared/demo.h>
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <engine/shared/protocol.h>
|
|
|
|
#include <engine/shared/snapshot.h>
|
|
|
|
#include <engine/shared/network.h>
|
|
|
|
#include <engine/shared/engine.h>
|
|
|
|
#include <engine/server/register.h>
|
|
|
|
#include <engine/shared/console.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
class CSnapIDPool
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_IDS = 16*1024,
|
|
|
|
};
|
|
|
|
|
|
|
|
class CID
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
short m_Next;
|
|
|
|
short m_State; // 0 = free, 1 = alloced, 2 = timed
|
|
|
|
int m_Timeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
CID m_aIDs[MAX_IDS];
|
|
|
|
|
|
|
|
int m_FirstFree;
|
|
|
|
int m_FirstTimed;
|
|
|
|
int m_LastTimed;
|
|
|
|
int m_Usage;
|
|
|
|
int m_InUsage;
|
2010-05-30 12:01:11 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
CSnapIDPool();
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
void RemoveFirstTimeout();
|
|
|
|
int NewID();
|
|
|
|
void TimeoutIDs();
|
|
|
|
void FreeID(int Id);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CServer : public IServer
|
|
|
|
{
|
|
|
|
class IGameServer *m_pGameServer;
|
|
|
|
class IConsole *m_pConsole;
|
|
|
|
class IStorage *m_pStorage;
|
|
|
|
public:
|
|
|
|
class IGameServer *GameServer() { return m_pGameServer; }
|
|
|
|
class IConsole *Console() { return m_pConsole; }
|
|
|
|
class IStorage *Storage() { return m_pStorage; }
|
|
|
|
class CEngine *Engine() { return &m_Engine; }
|
|
|
|
|
|
|
|
class CClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STATE_EMPTY = 0,
|
|
|
|
STATE_AUTH,
|
|
|
|
STATE_CONNECTING,
|
|
|
|
STATE_READY,
|
|
|
|
STATE_INGAME,
|
|
|
|
|
|
|
|
SNAPRATE_INIT=0,
|
|
|
|
SNAPRATE_FULL,
|
|
|
|
SNAPRATE_RECOVER
|
|
|
|
};
|
|
|
|
|
|
|
|
class CInput
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int m_aData[MAX_INPUT_SIZE];
|
|
|
|
int m_GameTick; // the tick that was chosen for the input
|
|
|
|
};
|
|
|
|
|
|
|
|
// connection state info
|
|
|
|
int m_State;
|
|
|
|
int m_Latency;
|
|
|
|
int m_SnapRate;
|
|
|
|
|
|
|
|
int m_LastAckedSnapshot;
|
|
|
|
int m_LastInputTick;
|
|
|
|
CSnapshotStorage m_Snapshots;
|
|
|
|
|
|
|
|
CInput m_LatestInput;
|
|
|
|
CInput m_aInputs[200]; // TODO: handle input better
|
|
|
|
int m_CurrentInput;
|
|
|
|
|
|
|
|
char m_aName[MAX_NAME_LENGTH];
|
|
|
|
char m_aClan[MAX_CLANNAME_LENGTH];
|
|
|
|
int m_Score;
|
|
|
|
int m_Authed;
|
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
int m_Resistent;
|
|
|
|
|
|
|
|
NETADDR m_Addr; // for storing address
|
|
|
|
int m_PwTries; // a players rcon pw tries
|
|
|
|
int m_CmdTries; //Floff players rcon command tries, to prevent command flood server crash
|
2010-07-30 12:50:09 +00:00
|
|
|
int64 m_CmdTriesTimer; // time
|
2010-07-29 05:21:18 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
CClient m_aClients[MAX_CLIENTS];
|
|
|
|
|
|
|
|
CSnapshotDelta m_SnapshotDelta;
|
|
|
|
CSnapshotBuilder m_SnapshotBuilder;
|
|
|
|
CSnapIDPool m_IDPool;
|
|
|
|
CNetServer m_NetServer;
|
|
|
|
|
|
|
|
IEngineMap *m_pMap;
|
|
|
|
|
|
|
|
int64 m_GameStartTime;
|
|
|
|
//int m_CurrentGameTick;
|
|
|
|
int m_RunServer;
|
2010-05-30 12:01:11 +00:00
|
|
|
int m_MapReload;
|
2010-09-12 11:52:25 +00:00
|
|
|
int m_RconClientId;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
char m_aBrowseinfoGametype[16];
|
|
|
|
int m_BrowseinfoProgression;
|
|
|
|
|
|
|
|
int64 m_Lastheartbeat;
|
|
|
|
//static NETADDR4 master_server;
|
|
|
|
|
|
|
|
char m_aCurrentMap[64];
|
|
|
|
int m_CurrentMapCrc;
|
|
|
|
unsigned char *m_pCurrentMapData;
|
|
|
|
int m_CurrentMapSize;
|
|
|
|
|
|
|
|
CDemoRecorder m_DemoRecorder;
|
|
|
|
CEngine m_Engine;
|
|
|
|
CRegister m_Register;
|
|
|
|
|
|
|
|
CServer();
|
|
|
|
|
|
|
|
int TrySetClientName(int ClientID, const char *pName);
|
|
|
|
|
|
|
|
virtual void SetClientName(int ClientID, const char *pName);
|
|
|
|
virtual void SetClientScore(int ClientID, int Score);
|
|
|
|
virtual void SetBrowseInfo(const char *pGameType, int Progression);
|
2010-07-29 05:21:18 +00:00
|
|
|
virtual void SetClientAuthed(int ClientID, int Authed);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void Kick(int ClientID, const char *pReason);
|
|
|
|
|
|
|
|
//int Tick()
|
|
|
|
int64 TickStartTime(int Tick);
|
|
|
|
//int TickSpeed()
|
|
|
|
|
|
|
|
int Init();
|
|
|
|
|
2010-06-02 02:42:17 +00:00
|
|
|
bool IsAuthed(int ClientID);
|
2010-05-29 07:25:38 +00:00
|
|
|
int GetClientInfo(int ClientID, CClientInfo *pInfo);
|
|
|
|
void GetClientIP(int ClientID, char *pIPString, int Size);
|
|
|
|
const char *ClientName(int ClientId);
|
|
|
|
bool ClientIngame(int ClientID);
|
|
|
|
|
|
|
|
int *LatestInput(int ClientId, int *size);
|
|
|
|
|
|
|
|
virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientId);
|
|
|
|
int SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System);
|
|
|
|
|
|
|
|
void DoSnapshot();
|
|
|
|
|
|
|
|
static int NewClientCallback(int ClientId, void *pUser);
|
2010-08-17 22:06:00 +00:00
|
|
|
static int DelClientCallback(int ClientId, const char *pReason, void *pUser);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void SendMap(int ClientId);
|
|
|
|
void SendRconLine(int ClientId, const char *pLine);
|
|
|
|
static void SendRconLineAuthed(const char *pLine, void *pUser);
|
|
|
|
|
|
|
|
void ProcessClientPacket(CNetChunk *pPacket);
|
|
|
|
|
|
|
|
void SendServerInfo(NETADDR *pAddr, int Token);
|
|
|
|
void UpdateServerInfo();
|
|
|
|
|
2010-07-29 19:55:33 +00:00
|
|
|
int BanAdd(NETADDR Addr, int Seconds, const char *Reason);
|
2010-05-29 07:25:38 +00:00
|
|
|
int BanRemove(NETADDR Addr);
|
|
|
|
|
|
|
|
|
|
|
|
void PumpNetwork();
|
|
|
|
|
2010-09-03 19:28:31 +00:00
|
|
|
char *GetMapName();
|
2010-05-29 07:25:38 +00:00
|
|
|
int LoadMap(const char *pMapName);
|
|
|
|
|
|
|
|
void InitEngine(const char *pAppname);
|
2010-08-17 22:06:00 +00:00
|
|
|
void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole);
|
2010-05-29 07:25:38 +00:00
|
|
|
int Run();
|
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
static void ConKick(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConBan(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConUnban(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConBans(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConStatus(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConShutdown(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConRecord(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConStopRecord(IConsole::IResult *pResult, void *pUser, int ClientId);
|
|
|
|
static void ConMapReload(IConsole::IResult *pResult, void *pUser, int ClientId);
|
2010-05-29 07:25:38 +00:00
|
|
|
static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
2010-06-03 12:48:32 +00:00
|
|
|
static void ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void RegisterCommands();
|
|
|
|
|
|
|
|
|
|
|
|
virtual int SnapNewID();
|
|
|
|
virtual void SnapFreeID(int ID);
|
|
|
|
virtual void *SnapNewItem(int Type, int Id, int Size);
|
|
|
|
void SnapSetStaticsize(int ItemType, int Size);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|