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_H
|
|
|
|
#define ENGINE_SERVER_H
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "message.h"
|
2013-12-31 05:13:57 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <engine/shared/protocol.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
class IServer : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("server", 0)
|
|
|
|
protected:
|
|
|
|
int m_CurrentGameTick;
|
|
|
|
int m_TickSpeed;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
Structure: CClientInfo
|
|
|
|
*/
|
|
|
|
struct CClientInfo
|
|
|
|
{
|
|
|
|
const char *m_pName;
|
|
|
|
int m_Latency;
|
2014-01-30 15:49:15 +00:00
|
|
|
int m_ClientVersion;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int Tick() const { return m_CurrentGameTick; }
|
|
|
|
int TickSpeed() const { return m_TickSpeed; }
|
|
|
|
|
2011-12-04 15:51:33 +00:00
|
|
|
virtual int MaxClients() const = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual const char *ClientName(int ClientID) = 0;
|
2011-03-15 10:23:49 +00:00
|
|
|
virtual const char *ClientClan(int ClientID) = 0;
|
|
|
|
virtual int ClientCountry(int ClientID) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual bool ClientIngame(int ClientID) = 0;
|
|
|
|
virtual int GetClientInfo(int ClientID, CClientInfo *pInfo) = 0;
|
2011-03-28 18:11:28 +00:00
|
|
|
virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) = 0;
|
2013-07-30 23:31:53 +00:00
|
|
|
virtual void RestrictRconOutput(int ClientID) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) = 0;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
int SendPackMsg(T *pMsg, int Flags, int ClientID)
|
2013-12-31 05:13:57 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
T tmp;
|
|
|
|
if (ClientID == -1)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
|
|
|
if(ClientIngame(i))
|
|
|
|
{
|
|
|
|
mem_copy(&tmp, pMsg, sizeof(T));
|
|
|
|
result = SendPackMsgTranslate(&tmp, Flags, i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mem_copy(&tmp, pMsg, sizeof(T));
|
|
|
|
result = SendPackMsgTranslate(&tmp, Flags, ClientID);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
int SendPackMsgTranslate(T *pMsg, int Flags, int ClientID)
|
|
|
|
{
|
|
|
|
return SendPackMsgOne(pMsg, Flags, ClientID);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SendPackMsgTranslate(CNetMsg_Sv_Emoticon *pMsg, int Flags, int ClientID)
|
|
|
|
{
|
|
|
|
return Translate(pMsg->m_ClientID, ClientID) && SendPackMsgOne(pMsg, Flags, ClientID);
|
|
|
|
}
|
|
|
|
|
|
|
|
char msgbuf[1000];
|
|
|
|
|
|
|
|
int SendPackMsgTranslate(CNetMsg_Sv_Chat *pMsg, int Flags, int ClientID)
|
|
|
|
{
|
|
|
|
if (pMsg->m_ClientID >= 0 && !Translate(pMsg->m_ClientID, ClientID))
|
|
|
|
{
|
|
|
|
str_format(msgbuf, sizeof(msgbuf), "%s: %s", ClientName(pMsg->m_ClientID), pMsg->m_pMessage);
|
|
|
|
pMsg->m_pMessage = msgbuf;
|
|
|
|
pMsg->m_ClientID = VANILLA_MAX_CLIENTS - 1;
|
|
|
|
}
|
|
|
|
return SendPackMsgOne(pMsg, Flags, ClientID);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SendPackMsgTranslate(CNetMsg_Sv_KillMsg *pMsg, int Flags, int ClientID)
|
|
|
|
{
|
|
|
|
if (!Translate(pMsg->m_Victim, ClientID)) return 0;
|
|
|
|
if (!Translate(pMsg->m_Killer, ClientID)) pMsg->m_Killer = pMsg->m_Victim;
|
|
|
|
return SendPackMsgOne(pMsg, Flags, ClientID);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
int SendPackMsgOne(T *pMsg, int Flags, int ClientID)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
CMsgPacker Packer(pMsg->MsgID());
|
|
|
|
if(pMsg->Pack(&Packer))
|
|
|
|
return -1;
|
|
|
|
return SendMsg(&Packer, Flags, ClientID);
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2013-12-31 05:13:57 +00:00
|
|
|
bool Translate(int& target, int client)
|
|
|
|
{
|
|
|
|
CClientInfo info;
|
|
|
|
GetClientInfo(client, &info);
|
2014-01-30 15:49:15 +00:00
|
|
|
if (info.m_ClientVersion >= VERSION_DDNET_OLD)
|
2013-12-31 05:13:57 +00:00
|
|
|
return true;
|
|
|
|
int* map = GetIdMap(client);
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < VANILLA_MAX_CLIENTS; i++)
|
|
|
|
{
|
|
|
|
if (target == map[i])
|
|
|
|
{
|
|
|
|
target = i;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReverseTranslate(int& target, int client)
|
|
|
|
{
|
|
|
|
CClientInfo info;
|
|
|
|
GetClientInfo(client, &info);
|
2014-01-30 15:49:15 +00:00
|
|
|
if (info.m_ClientVersion >= VERSION_DDNET_OLD)
|
2013-12-31 05:13:57 +00:00
|
|
|
return true;
|
|
|
|
int* map = GetIdMap(client);
|
|
|
|
if (map[target] == -1)
|
|
|
|
return false;
|
|
|
|
target = map[target];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void SetClientName(int ClientID, char const *pName) = 0;
|
2011-03-15 10:23:49 +00:00
|
|
|
virtual void SetClientClan(int ClientID, char const *pClan) = 0;
|
|
|
|
virtual void SetClientCountry(int ClientID, int Country) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void SetClientScore(int ClientID, int Score) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int SnapNewID() = 0;
|
|
|
|
virtual void SnapFreeID(int ID) = 0;
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void *SnapNewItem(int Type, int ID, int Size) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
virtual void SnapSetStaticsize(int ItemType, int Size) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-12-31 11:11:48 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RCON_CID_SERV=-1,
|
|
|
|
RCON_CID_VOTE=-2,
|
|
|
|
};
|
|
|
|
virtual void SetRconCID(int ClientID) = 0;
|
2011-08-13 00:11:06 +00:00
|
|
|
virtual bool IsAuthed(int ClientID) = 0;
|
2010-10-09 17:14:42 +00:00
|
|
|
virtual void Kick(int ClientID, const char *pReason) = 0;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
virtual void DemoRecorder_HandleAutoStart() = 0;
|
2012-01-08 23:49:20 +00:00
|
|
|
virtual bool DemoRecorder_IsRecording() = 0;
|
2011-08-13 00:11:06 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
// DDRace
|
|
|
|
|
2014-09-26 00:05:22 +00:00
|
|
|
virtual void SaveDemo(int ClientID, float Time) = 0;
|
|
|
|
virtual void StartRecord(int ClientID) = 0;
|
|
|
|
virtual void StopRecord(int ClientID) = 0;
|
|
|
|
virtual bool IsRecording(int ClientID) = 0;
|
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
virtual void GetClientAddr(int ClientID, NETADDR *pAddr) = 0;
|
2013-12-31 05:13:57 +00:00
|
|
|
|
|
|
|
virtual int* GetIdMap(int ClientID) = 0;
|
2015-11-23 21:49:18 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IGameServer : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("gameserver", 0)
|
|
|
|
protected:
|
|
|
|
public:
|
|
|
|
virtual void OnInit() = 0;
|
|
|
|
virtual void OnConsoleInit() = 0;
|
2015-07-14 20:08:29 +00:00
|
|
|
virtual void OnMapChange(char *pNewMapName, int MapNameSize) = 0;
|
2016-05-04 13:32:24 +00:00
|
|
|
|
|
|
|
// FullShutdown is true if the program is about to exit (not if the map is changed)
|
|
|
|
virtual void OnShutdown(bool FullShutdown = false) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnTick() = 0;
|
|
|
|
virtual void OnPreSnap() = 0;
|
|
|
|
virtual void OnSnap(int ClientID) = 0;
|
|
|
|
virtual void OnPostSnap() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
virtual void OnClientConnected(int ClientID) = 0;
|
|
|
|
virtual void OnClientEnter(int ClientID) = 0;
|
2011-02-14 18:41:32 +00:00
|
|
|
virtual void OnClientDrop(int ClientID, const char *pReason) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnClientDirectInput(int ClientID, void *pInput) = 0;
|
|
|
|
virtual void OnClientPredictedInput(int ClientID, void *pInput) = 0;
|
2011-03-15 08:58:57 +00:00
|
|
|
|
|
|
|
virtual bool IsClientReady(int ClientID) = 0;
|
2011-03-20 14:33:49 +00:00
|
|
|
virtual bool IsClientPlayer(int ClientID) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-02-16 11:31:47 +00:00
|
|
|
virtual const char *GameType() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual const char *Version() = 0;
|
|
|
|
virtual const char *NetVersion() = 0;
|
2011-08-26 18:03:30 +00:00
|
|
|
|
|
|
|
// DDRace
|
|
|
|
|
|
|
|
virtual void OnSetAuthed(int ClientID, int Level) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern IGameServer *CreateGameServer();
|
|
|
|
#endif
|