ddnet/src/engine/server/server.h

289 lines
7.5 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef ENGINE_SERVER_SERVER_H
#define ENGINE_SERVER_SERVER_H
#include <engine/server.h>
#include <engine/map.h>
#include <engine/shared/demo.h>
#include <engine/shared/protocol.h>
#include <engine/shared/snapshot.h>
#include <engine/shared/network.h>
#include <engine/server/register.h>
#include <engine/shared/console.h>
#include <base/math.h>
#include <engine/shared/mapchecker.h>
#include <engine/shared/econ.h>
#include <engine/shared/netban.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];
2010-05-29 07:25:38 +00:00
int m_FirstFree;
int m_FirstTimed;
int m_LastTimed;
int m_Usage;
int m_InUsage;
public:
2010-05-29 07:25:38 +00:00
CSnapIDPool();
2010-05-29 07:25:38 +00:00
void Reset();
void RemoveFirstTimeout();
int NewID();
void TimeoutIDs();
void FreeID(int ID);
2010-05-29 07:25:38 +00:00
};
2011-12-29 22:36:53 +00:00
class CServerBan : public CNetBan
{
class CServer *m_pServer;
template<class T> int BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason);
public:
class CServer *Server() const { return m_pServer; }
void InitServerBan(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer);
2011-12-29 22:36:53 +00:00
virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason);
virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason);
2011-12-29 22:36:53 +00:00
static void ConBanExt(class IConsole::IResult *pResult, void *pUser);
};
2010-05-29 07:25:38 +00:00
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; }
enum
{
AUTHED_NO=0,
AUTHED_MOD,
AUTHED_ADMIN,
MAX_RCONCMD_SEND=16,
};
2010-05-29 07:25:38 +00:00
class CClient
{
public:
2010-05-29 07:25:38 +00:00
enum
{
STATE_EMPTY = 0,
STATE_AUTH,
STATE_CONNECTING,
2014-08-13 00:00:45 +00:00
STATE_SPOOFCHECK,
STATE_POSTSPOOFCHECK,
2010-05-29 07:25:38 +00:00
STATE_READY,
STATE_INGAME,
2010-05-29 07:25:38 +00:00
SNAPRATE_INIT=0,
SNAPRATE_FULL,
SNAPRATE_RECOVER
};
2010-05-29 07:25:38 +00:00
class CInput
{
public:
int m_aData[MAX_INPUT_SIZE];
int m_GameTick; // the tick that was chosen for the input
};
2010-05-29 07:25:38 +00:00
// connection state info
int m_State;
int m_Latency;
int m_SnapRate;
2013-08-04 15:50:12 +00:00
float m_Traffic;
2013-08-04 02:24:03 +00:00
int64 m_TrafficSince;
2010-05-29 07:25:38 +00:00
int m_LastAckedSnapshot;
int m_LastInputTick;
CSnapshotStorage m_Snapshots;
2010-05-29 07:25:38 +00:00
CInput m_LatestInput;
CInput m_aInputs[200]; // TODO: handle input better
int m_CurrentInput;
2010-05-29 07:25:38 +00:00
char m_aName[MAX_NAME_LENGTH];
char m_aClan[MAX_CLAN_LENGTH];
int m_Country;
2010-05-29 07:25:38 +00:00
int m_Score;
int m_Authed;
int m_LastAuthed;
int m_AuthTries;
2014-08-13 00:00:45 +00:00
int m_Nonce; // number to reach
int m_NonceCount; // current num
int64 m_LastNonceCount;
const IConsole::CCommandInfo *m_pRconCmdToSend;
2010-05-29 07:25:38 +00:00
void Reset();
2013-12-31 05:13:57 +00:00
// DDRace
NETADDR m_Addr;
2010-05-29 07:25:38 +00:00
};
2010-05-29 07:25:38 +00:00
CClient m_aClients[MAX_CLIENTS];
2013-12-31 05:13:57 +00:00
int IdMap[MAX_CLIENTS * VANILLA_MAX_CLIENTS];
2010-05-29 07:25:38 +00:00
CSnapshotDelta m_SnapshotDelta;
CSnapshotBuilder m_SnapshotBuilder;
CSnapIDPool m_IDPool;
CNetServer m_NetServer;
2011-07-30 11:40:01 +00:00
CEcon m_Econ;
2011-12-29 22:36:53 +00:00
CServerBan m_ServerBan;
2010-05-29 07:25:38 +00:00
IEngineMap *m_pMap;
int64 m_GameStartTime;
//int m_CurrentGameTick;
int m_RunServer;
int m_MapReload;
int m_RconClientID;
int m_RconAuthLevel;
2011-07-30 11:40:01 +00:00
int m_PrintCBIndex;
2010-05-29 07:25:38 +00:00
int64 m_Lastheartbeat;
//static NETADDR4 master_server;
char m_aCurrentMap[64];
unsigned m_CurrentMapCrc;
2010-05-29 07:25:38 +00:00
unsigned char *m_pCurrentMapData;
int m_CurrentMapSize;
CDemoRecorder m_aDemoRecorder[MAX_CLIENTS+1];
2010-05-29 07:25:38 +00:00
CRegister m_Register;
CMapChecker m_MapChecker;
int m_RconRestrict;
2010-05-29 07:25:38 +00:00
CServer();
2010-05-29 07:25:38 +00:00
int TrySetClientName(int ClientID, const char *pName);
virtual void SetClientName(int ClientID, const char *pName);
virtual void SetClientClan(int ClientID, char const *pClan);
virtual void SetClientCountry(int ClientID, int Country);
2010-05-29 07:25:38 +00:00
virtual void SetClientScore(int ClientID, int Score);
void Kick(int ClientID, const char *pReason);
void DemoRecorder_HandleAutoStart();
2012-01-08 23:49:20 +00:00
bool DemoRecorder_IsRecording();
2010-05-29 07:25:38 +00:00
//int Tick()
int64 TickStartTime(int Tick);
//int TickSpeed()
int Init();
void SetRconCID(int ClientID);
bool IsAuthed(int ClientID);
2010-05-29 07:25:38 +00:00
int GetClientInfo(int ClientID, CClientInfo *pInfo);
void GetClientAddr(int ClientID, char *pAddrStr, int Size);
const char *ClientName(int ClientID);
const char *ClientClan(int ClientID);
int ClientCountry(int ClientID);
2010-05-29 07:25:38 +00:00
bool ClientIngame(int ClientID);
2011-12-04 15:51:33 +00:00
int MaxClients() const;
2010-05-29 07:25:38 +00:00
virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID);
2010-05-29 07:25:38 +00:00
int SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System);
void DoSnapshot();
static int NewClientCallback(int ClientID, void *pUser);
static int DelClientCallback(int ClientID, const char *pReason, void *pUser);
2010-05-29 07:25:38 +00:00
void SendMap(int ClientID);
void SendConnectionReady(int ClientID);
void SendRconLine(int ClientID, const char *pLine);
2010-05-29 07:25:38 +00:00
static void SendRconLineAuthed(const char *pLine, void *pUser);
void SendRconCmdAdd(const IConsole::CCommandInfo *pCommandInfo, int ClientID);
void SendRconCmdRem(const IConsole::CCommandInfo *pCommandInfo, int ClientID);
void UpdateClientRconCommands();
2010-05-29 07:25:38 +00:00
void ProcessClientPacket(CNetChunk *pPacket);
2013-12-31 05:13:57 +00:00
void SendServerInfo(const NETADDR *pAddr, int Token, bool Extended=false, int Offset=0);
2010-05-29 07:25:38 +00:00
void UpdateServerInfo();
void PumpNetwork();
char *GetMapName();
2010-05-29 07:25:38 +00:00
int LoadMap(const char *pMapName);
void SaveDemo(int ClientID, float Time);
void StartRecord(int ClientID);
void StopRecord(int ClientID);
bool IsRecording(int ClientID);
void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole);
2010-05-29 07:25:38 +00:00
int Run();
static void ConTestingCommands(IConsole::IResult *pResult, void *pUser);
static void ConKick(IConsole::IResult *pResult, void *pUser);
2011-12-29 22:36:53 +00:00
static void ConStatus(IConsole::IResult *pResult, void *pUser);
static void ConShutdown(IConsole::IResult *pResult, void *pUser);
static void ConRecord(IConsole::IResult *pResult, void *pUser);
static void ConStopRecord(IConsole::IResult *pResult, void *pUser);
static void ConMapReload(IConsole::IResult *pResult, void *pUser);
2011-12-26 21:07:57 +00:00
static void ConLogout(IConsole::IResult *pResult, void *pUser);
2010-05-29 07:25:38 +00:00
static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainModCommandUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
2011-07-30 11:40:01 +00:00
static void ConchainConsoleOutputLevelUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainRconPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainRconModPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
2011-01-06 03:46:10 +00:00
2010-05-29 07:25:38 +00:00
void RegisterCommands();
2010-05-29 07:25:38 +00:00
virtual int SnapNewID();
virtual void SnapFreeID(int ID);
virtual void *SnapNewItem(int Type, int ID, int Size);
2010-05-29 07:25:38 +00:00
void SnapSetStaticsize(int ItemType, int Size);
// DDRace
void GetClientAddr(int ClientID, NETADDR *pAddr);
int m_aPrevStates[MAX_CLIENTS];
2010-12-06 02:27:35 +00:00
char *GetAnnouncementLine(char const *FileName);
unsigned m_AnnouncementLastLine;
void RestrictRconOutput(int ClientID) { m_RconRestrict = ClientID; }
2013-12-31 05:13:57 +00:00
virtual int* GetIdMap(int ClientID);
2010-05-29 07:25:38 +00:00
};
#endif