Skip to content

Commit

Permalink
just for pr, will revert soon
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-Chara committed Mar 26, 2022
1 parent fcd26d0 commit 170a3e8
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 6 deletions.
5 changes: 3 additions & 2 deletions bam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ function build(settings)

-- build the small libraries
json = Compile(settings, "src/engine/external/json-parser/json.c")

md5 = Compile(settings, Collect("src/engine/external/md5/*.c"))

-- build game components
engine_settings = settings:Copy()
server_settings = engine_settings:Copy()
Expand Down Expand Up @@ -270,7 +271,7 @@ function build(settings)

-- build server
server_exe = Link(server_settings, "teeworlds_srv", engine, server,
game_shared, game_server, zlib, server_link_other, teeuniverses, json)
game_shared, game_server, zlib, server_link_other, teeuniverses, json, md5)

serverlaunch = {}
if platform == "macosx" then
Expand Down
95 changes: 93 additions & 2 deletions src/engine/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "kernel.h"
#include "message.h"

#include <game/generated/protocol.h>
#include <engine/shared/protocol.h>

class IServer : public IInterface
{
MACRO_INTERFACE("server", 0)
Expand All @@ -28,6 +31,7 @@ class IServer : public IInterface
{
const char *m_pName;
int m_Latency;
bool m_CustClt;
};

inline class CLocalization* Localization() { return m_pLocalization; }
Expand All @@ -48,12 +52,96 @@ class IServer : public IInterface
template<class T>
int SendPackMsg(T *pMsg, int Flags, int ClientID)
{
CMsgPacker Packer(pMsg->MsgID());
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)
{
CMsgPacker Packer(pMsg->MsgID());
if(pMsg->Pack(&Packer))
return -1;
return SendMsg(&Packer, Flags, ClientID);
}

bool Translate(int& target, int client)
{
CClientInfo info;
GetClientInfo(client, &info);
if (info.m_CustClt)
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);
if (info.m_CustClt)
return true;
int* map = GetIdMap(client);
if (map[target] == -1)
return false;
target = map[target];
return true;
}

virtual void SetClientName(int ClientID, char const *pName) = 0;
virtual void SetClientClan(int ClientID, char const *pClan) = 0;
virtual void SetClientCountry(int ClientID, int Country) = 0;
Expand All @@ -79,6 +167,8 @@ class IServer : public IInterface

virtual const char* GetClientLanguage(int ClientID) = 0;
virtual void SetClientLanguage(int ClientID, const char* pLanguage) = 0;
virtual int* GetIdMap(int ClientID) = 0;
virtual void SetCustClt(int ClientID) = 0;
};

class IGameServer : public IInterface
Expand Down Expand Up @@ -111,7 +201,8 @@ class IGameServer : public IInterface
virtual const char *NetVersion() = 0;

virtual void OnSetAuthed(int ClientID, int Level) = 0;
virtual class CLayers *Layers() = 0;
};

extern IGameServer *CreateGameServer();
#endif
#endif
11 changes: 9 additions & 2 deletions src/engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CServer : public IServer
int m_LastInputTick;
CSnapshotStorage m_Snapshots;


CInput m_LatestInput;
CInput m_aInputs[200]; // TODO: handle input better
int m_CurrentInput;
Expand All @@ -127,9 +128,12 @@ class CServer : public IServer
void Reset();

char m_aLanguage[16];
NETADDR m_Addr;
bool m_CustClt;
};

CClient m_aClients[MAX_CLIENTS];
int IdMap[MAX_CLIENTS * VANILLA_MAX_CLIENTS];

CSnapshotDelta m_SnapshotDelta;
CSnapshotBuilder m_SnapshotBuilder;
Expand Down Expand Up @@ -196,6 +200,7 @@ class CServer : public IServer
void DoSnapshot();

static int NewClientCallback(int ClientID, void *pUser);
static int NewClientNoAuthCallback(int ClientID, void *pUser);
static int DelClientCallback(int ClientID, const char *pReason, void *pUser);

void SendMap(int ClientID);
Expand All @@ -209,7 +214,7 @@ class CServer : public IServer

void ProcessClientPacket(CNetChunk *pPacket);

void SendServerInfo(const NETADDR *pAddr, int Token);
void SendServerInfo(const NETADDR *pAddr, int Token, bool Extended=false, int Offset=0);
void UpdateServerInfo();

void PumpNetwork();
Expand Down Expand Up @@ -243,6 +248,8 @@ class CServer : public IServer
public:
virtual const char* GetClientLanguage(int ClientID);
virtual void SetClientLanguage(int ClientID, const char* pLanguage);
virtual int* GetIdMap(int ClientID);
virtual void SetCustClt(int ClientID);
};

#endif
#endif
10 changes: 10 additions & 0 deletions src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team)
SetLanguage(Server()->GetClientLanguage(ClientID));

m_Authed = IServer::AUTHED_NO;

m_PrevTuningParams = *pGameServer->Tuning();
m_NextTuningParams = m_PrevTuningParams;

int* idMap = Server()->GetIdMap(ClientID);
for (int i = 1;i < VANILLA_MAX_CLIENTS;i++)
{
idMap[i] = -1;
}
idMap[0] = ClientID;
}

CPlayer::~CPlayer()
Expand Down
9 changes: 9 additions & 0 deletions src/game/server/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ class CPlayer
int m_Team;

char m_aLanguage[16];

private:
CTuningParams m_PrevTuningParams;
CTuningParams m_NextTuningParams;

void HandleTuningParams(); //This function will send the new parameters if needed

public:
CTuningParams* GetNextTuningParams() { return &m_NextTuningParams; };
};

#endif

0 comments on commit 170a3e8

Please sign in to comment.