mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
restored master server
This commit is contained in:
parent
29a4448dbc
commit
3f49c69522
|
@ -7,7 +7,8 @@
|
|||
#include "network.h"
|
||||
#include "huffman.h"
|
||||
|
||||
void CNetRecvUnpacker::Clear() {
|
||||
void CNetRecvUnpacker::Clear()
|
||||
{
|
||||
m_Valid = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* (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. */
|
||||
/* (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. */
|
||||
#ifndef ENGINE_SHARED_NETWORK_H
|
||||
#define ENGINE_SHARED_NETWORK_H
|
||||
|
||||
|
@ -393,7 +394,7 @@ public:
|
|||
bool Open(NETADDR BindAddr, class CNetBan *pNetBan, int MaxClients, int MaxClientsPerIP, int Flags);
|
||||
int Close();
|
||||
|
||||
// the token and version parameter are only used for connless packets
|
||||
// the token parameter is only used for connless packets
|
||||
int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0);
|
||||
int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE);
|
||||
int Update();
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,149 +1,52 @@
|
|||
/* (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. */
|
||||
#ifndef MASTERSRV_MASTERSRV_H
|
||||
#define MASTERSRV_MASTERSRV_H
|
||||
|
||||
#include <engine/kernel.h>
|
||||
#include <engine/shared/network.h>
|
||||
|
||||
struct CMastersrvAddr
|
||||
{
|
||||
unsigned char m_aIp[16];
|
||||
unsigned char m_aPort[2];
|
||||
};
|
||||
|
||||
|
||||
static const unsigned char SERVERBROWSE_HEARTBEAT[] = {255, 255, 255, 255, 'b', 'e', 'a', '2'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETLIST[] = {255, 255, 255, 255, 'r', 'e', 'q', '2'};
|
||||
static const unsigned char SERVERBROWSE_LIST[] = {255, 255, 255, 255, 'l', 'i', 's', '2'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETCOUNT[] = {255, 255, 255, 255, 'c', 'o', 'u', '2'};
|
||||
static const unsigned char SERVERBROWSE_COUNT[] = {255, 255, 255, 255, 's', 'i', 'z', '2'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETINFO[] = {255, 255, 255, 255, 'g', 'i', 'e', '3'};
|
||||
static const unsigned char SERVERBROWSE_INFO[] = {255, 255, 255, 255, 'i', 'n', 'f', '3'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_FWCHECK[] = {255, 255, 255, 255, 'f', 'w', '?', '?'};
|
||||
static const unsigned char SERVERBROWSE_FWRESPONSE[] = {255, 255, 255, 255, 'f', 'w', '!', '!'};
|
||||
static const unsigned char SERVERBROWSE_FWOK[] = {255, 255, 255, 255, 'f', 'w', 'o', 'k'};
|
||||
static const unsigned char SERVERBROWSE_FWERROR[] = {255, 255, 255, 255, 'f', 'w', 'e', 'r'};
|
||||
|
||||
class CNetChunk;
|
||||
class IMastersrv;
|
||||
|
||||
enum
|
||||
{
|
||||
MASTERSERVER_PORT=8300,
|
||||
MASTERSERVER_CHECKER_PORT=MASTERSERVER_PORT+1,
|
||||
VERSIONSERVER_PORT=8302,
|
||||
};
|
||||
|
||||
class IMastersrv : public IInterface
|
||||
{
|
||||
MACRO_INTERFACE("mastersrv", 0)
|
||||
public:
|
||||
enum
|
||||
{
|
||||
MASTERSRV_0_7=0,
|
||||
MASTERSRV_0_6,
|
||||
MASTERSRV_0_5,
|
||||
MASTERSRV_VER,
|
||||
NUM_MASTERSRV,
|
||||
|
||||
SOCKET_OP=0,
|
||||
SOCKET_CHECKER,
|
||||
SOCKET_VERSION,
|
||||
NUM_SOCKETS,
|
||||
};
|
||||
|
||||
IMastersrv() {}
|
||||
virtual ~IMastersrv() {}
|
||||
|
||||
virtual int Init() = 0;
|
||||
virtual int Run() = 0;
|
||||
|
||||
virtual void AddServer(const NETADDR *pAddr, void *pUserData, int Version) = 0;
|
||||
virtual void AddCheckserver(const NETADDR *pAddr, const NETADDR *pAltAddr, void *pUserData, int Version) = 0;
|
||||
virtual void SendList(const NETADDR *pAddr, void *pUserData, int Version) = 0;
|
||||
virtual int GetCount() const = 0;
|
||||
|
||||
virtual int Send(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion) = 0;
|
||||
};
|
||||
|
||||
class IMastersrvSlave
|
||||
{
|
||||
public:
|
||||
IMastersrvSlave(IMastersrv *pOwner, int Version) : m_pOwner(pOwner), m_Version(Version) {}
|
||||
virtual ~IMastersrvSlave() {}
|
||||
|
||||
// hooks
|
||||
void AddServer(const NETADDR *pAddr, void *pUserData) { m_pOwner->AddServer(pAddr, pUserData, m_Version); }
|
||||
void AddCheckserver(const NETADDR *pAddr, const NETADDR *pAltAddr, void *pUserData) { m_pOwner->AddCheckserver(pAddr, pAltAddr, pUserData, m_Version); }
|
||||
void SendList(const NETADDR *pAddr, void *pUserData) { m_pOwner->SendList(pAddr, pUserData, m_Version); }
|
||||
|
||||
// interface for packet building
|
||||
// these functions return number of bytes written
|
||||
// if that number smaller than 0, an error is assumed
|
||||
virtual int BuildPacketStart(void *pData, int MaxLength) { return 0; };
|
||||
virtual int BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData) = 0;
|
||||
virtual int BuildPacketFinalize(void *pData, int MaxLength) { return 0; };
|
||||
|
||||
// interface for packet receiving
|
||||
// this function shall return 0 if the packet should be furtherly processed
|
||||
virtual int ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion) = 0;
|
||||
|
||||
// interface for network
|
||||
virtual void SendCheck(const NETADDR *pAddr, void *pUserData) = 0;
|
||||
virtual void SendOk(const NETADDR *pAddr, void *pUserData) = 0;
|
||||
virtual void SendError(const NETADDR *pAddr, void *pUserData) = 0;
|
||||
virtual void SendList(const NETADDR *pAddr, const void *pData, int DataSize, void *pUserData) = 0;
|
||||
|
||||
static void NetaddrToMastersrv(CMastersrvAddr *pOut, const NETADDR *pIn);
|
||||
|
||||
protected:
|
||||
IMastersrv *m_pOwner;
|
||||
const int m_Version;
|
||||
};
|
||||
|
||||
class IMastersrvSlaveAdv : public IMastersrvSlave
|
||||
{
|
||||
public:
|
||||
IMastersrvSlaveAdv(IMastersrv *pOwner, int Version) : IMastersrvSlave(pOwner, Version) {}
|
||||
virtual ~IMastersrvSlaveAdv() {}
|
||||
|
||||
virtual void SendCount(const NETADDR *pAddr, void *pUserData) { SendPacket(PACKET_COUNT, pAddr, pUserData); }
|
||||
virtual void SendCheck(const NETADDR *pAddr, void *pUserData) { SendPacket(PACKET_CHECK, pAddr, pUserData); }
|
||||
virtual void SendOk(const NETADDR *pAddr, void *pUserData) { SendPacket(PACKET_OK, pAddr, pUserData); }
|
||||
virtual void SendError(const NETADDR *pAddr, void *pUserData) { SendPacket(PACKET_ERROR, pAddr, pUserData); }
|
||||
virtual void SendList(const NETADDR *pAddr, const void *pData, int DataSize, void *pUserData)
|
||||
{
|
||||
m_aPackets[PACKET_LIST].m_DataSize = DataSize;
|
||||
m_aPackets[PACKET_LIST].m_pData = pData;
|
||||
SendPacket(PACKET_LIST, pAddr, pUserData);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void SendPacket(int PacketType, const NETADDR *pAddr, void *pUserData) = 0;
|
||||
|
||||
enum
|
||||
{
|
||||
PACKET_COUNT=0,
|
||||
PACKET_CHECK,
|
||||
PACKET_OK,
|
||||
PACKET_ERROR,
|
||||
PACKET_LIST,
|
||||
NUM_PACKETS,
|
||||
};
|
||||
CNetChunk m_aPackets[NUM_PACKETS];
|
||||
};
|
||||
|
||||
IMastersrv *CreateMastersrv();
|
||||
|
||||
IMastersrvSlave *CreateSlave_0_5(IMastersrv *pOwner);
|
||||
IMastersrvSlave *CreateSlave_0_6(IMastersrv *pOwner);
|
||||
IMastersrvSlave *CreateSlave_0_7(IMastersrv *pOwner);
|
||||
IMastersrvSlave *CreateSlave_Ver(IMastersrv *pOwner);
|
||||
|
||||
|
||||
#endif
|
||||
/* (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. */
|
||||
#ifndef MASTERSRV_MASTERSRV_H
|
||||
#define MASTERSRV_MASTERSRV_H
|
||||
static const int MASTERSERVER_PORT = 8300;
|
||||
|
||||
enum ServerType
|
||||
{
|
||||
SERVERTYPE_INVALID = -1,
|
||||
SERVERTYPE_NORMAL,
|
||||
SERVERTYPE_LEGACY
|
||||
};
|
||||
|
||||
struct CMastersrvAddr
|
||||
{
|
||||
unsigned char m_aIp[16];
|
||||
unsigned char m_aPort[2];
|
||||
};
|
||||
|
||||
static const unsigned char SERVERBROWSE_HEARTBEAT[] = {255, 255, 255, 255, 'b', 'e', 'a', '2'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETLIST[] = {255, 255, 255, 255, 'r', 'e', 'q', '2'};
|
||||
static const unsigned char SERVERBROWSE_LIST[] = {255, 255, 255, 255, 'l', 'i', 's', '2'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETCOUNT[] = {255, 255, 255, 255, 'c', 'o', 'u', '2'};
|
||||
static const unsigned char SERVERBROWSE_COUNT[] = {255, 255, 255, 255, 's', 'i', 'z', '2'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETINFO[] = {255, 255, 255, 255, 'g', 'i', 'e', '3'};
|
||||
static const unsigned char SERVERBROWSE_INFO[] = {255, 255, 255, 255, 'i', 'n', 'f', '3'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_FWCHECK[] = {255, 255, 255, 255, 'f', 'w', '?', '?'};
|
||||
static const unsigned char SERVERBROWSE_FWRESPONSE[] = {255, 255, 255, 255, 'f', 'w', '!', '!'};
|
||||
static const unsigned char SERVERBROWSE_FWOK[] = {255, 255, 255, 255, 'f', 'w', 'o', 'k'};
|
||||
static const unsigned char SERVERBROWSE_FWERROR[] = {255, 255, 255, 255, 'f', 'w', 'e', 'r'};
|
||||
|
||||
|
||||
// packet headers for the 0.5 branch
|
||||
|
||||
struct CMastersrvAddrLegacy
|
||||
{
|
||||
unsigned char m_aIp[4];
|
||||
unsigned char m_aPort[2];
|
||||
};
|
||||
|
||||
static const unsigned char SERVERBROWSE_HEARTBEAT_LEGACY[] = {255, 255, 255, 255, 'b', 'e', 'a', 't'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETLIST_LEGACY[] = {255, 255, 255, 255, 'r', 'e', 'q', 't'};
|
||||
static const unsigned char SERVERBROWSE_LIST_LEGACY[] = {255, 255, 255, 255, 'l', 'i', 's', 't'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETCOUNT_LEGACY[] = {255, 255, 255, 255, 'c', 'o', 'u', 'n'};
|
||||
static const unsigned char SERVERBROWSE_COUNT_LEGACY[] = {255, 255, 255, 255, 's', 'i', 'z', 'e'};
|
||||
#endif
|
||||
|
|
|
@ -1,155 +0,0 @@
|
|||
/* (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. */
|
||||
|
||||
#include "mastersrv.h"
|
||||
|
||||
static const unsigned char SERVERBROWSE_HEARTBEAT_LEGACY[] = {255, 255, 255, 255, 'b', 'e', 'a', 't'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETLIST_LEGACY[] = {255, 255, 255, 255, 'r', 'e', 'q', 't'};
|
||||
static const unsigned char SERVERBROWSE_LIST_LEGACY[] = {255, 255, 255, 255, 'l', 'i', 's', 't'};
|
||||
|
||||
static const unsigned char SERVERBROWSE_GETCOUNT_LEGACY[] = {255, 255, 255, 255, 'c', 'o', 'u', 'n'};
|
||||
static const unsigned char SERVERBROWSE_COUNT_LEGACY[] = {255, 255, 255, 255, 's', 'i', 'z', 'e'};
|
||||
|
||||
class CMastersrvSlave_0_5 : public IMastersrvSlaveAdv
|
||||
{
|
||||
public:
|
||||
CMastersrvSlave_0_5(IMastersrv *pOwner);
|
||||
virtual ~CMastersrvSlave_0_5() {}
|
||||
|
||||
virtual int BuildPacketStart(void *pData, int MaxLength);
|
||||
virtual int BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData);
|
||||
virtual int ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion);
|
||||
|
||||
virtual void SendPacket(int PacketType, const NETADDR *pAddr, void *pUserData);
|
||||
|
||||
struct CCountPacketData
|
||||
{
|
||||
unsigned char m_Header[sizeof(SERVERBROWSE_COUNT_LEGACY)];
|
||||
unsigned char m_High;
|
||||
unsigned char m_Low;
|
||||
} m_CountData;
|
||||
|
||||
struct CMastersrvAddrLegacy
|
||||
{
|
||||
unsigned char m_aIp[4];
|
||||
unsigned char m_aPort[2];
|
||||
};
|
||||
|
||||
static void NetaddrToMastersrv(CMastersrvAddrLegacy *pOut, const NETADDR *pIn);
|
||||
};
|
||||
|
||||
CMastersrvSlave_0_5::CMastersrvSlave_0_5(IMastersrv *pOwner)
|
||||
: IMastersrvSlaveAdv(pOwner, IMastersrv::MASTERSRV_0_5)
|
||||
{
|
||||
mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT_LEGACY, sizeof(m_CountData.m_Header));
|
||||
|
||||
for(int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
m_aPackets[i].m_ClientID = -1;
|
||||
m_aPackets[i].m_Flags = NETSENDFLAG_CONNLESS|NETSENDFLAG_STATELESS;
|
||||
}
|
||||
|
||||
m_aPackets[PACKET_COUNT].m_DataSize = sizeof(m_CountData);
|
||||
m_aPackets[PACKET_COUNT].m_pData = &m_CountData;
|
||||
|
||||
m_aPackets[PACKET_CHECK].m_DataSize = sizeof(SERVERBROWSE_FWCHECK);
|
||||
m_aPackets[PACKET_CHECK].m_pData = SERVERBROWSE_FWCHECK;
|
||||
|
||||
m_aPackets[PACKET_OK].m_DataSize = sizeof(SERVERBROWSE_FWOK);
|
||||
m_aPackets[PACKET_OK].m_pData = SERVERBROWSE_FWOK;
|
||||
|
||||
m_aPackets[PACKET_ERROR].m_DataSize = sizeof(SERVERBROWSE_FWERROR);
|
||||
m_aPackets[PACKET_ERROR].m_pData = SERVERBROWSE_FWERROR;
|
||||
|
||||
dbg_msg("mastersrv", "started mastersrv 0.5");
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_5::BuildPacketStart(void *pData, int MaxLength)
|
||||
{
|
||||
if(MaxLength < sizeof(SERVERBROWSE_LIST_LEGACY))
|
||||
return -1;
|
||||
mem_copy(pData, SERVERBROWSE_LIST_LEGACY, sizeof(SERVERBROWSE_LIST_LEGACY));
|
||||
return sizeof(SERVERBROWSE_LIST_LEGACY);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_5::BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData)
|
||||
{
|
||||
if(MaxLength < sizeof(CMastersrvAddrLegacy))
|
||||
return -1;
|
||||
NetaddrToMastersrv((CMastersrvAddrLegacy *)pData, pAddr);
|
||||
return sizeof(CMastersrvAddrLegacy);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_5::ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion)
|
||||
{
|
||||
if(PacketVersion != NET_PACKETVERSION_LEGACY || !(pPacket->m_Flags&NETSENDFLAG_CONNLESS))
|
||||
return 0;
|
||||
|
||||
if(Socket == IMastersrv::SOCKET_OP)
|
||||
{
|
||||
if(pPacket->m_DataSize == sizeof(SERVERBROWSE_HEARTBEAT_LEGACY)+2 &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_HEARTBEAT_LEGACY, sizeof(SERVERBROWSE_HEARTBEAT_LEGACY)) == 0)
|
||||
{
|
||||
NETADDR Alt;
|
||||
unsigned char *d = (unsigned char *)pPacket->m_pData;
|
||||
Alt = pPacket->m_Address;
|
||||
Alt.port = (d[sizeof(SERVERBROWSE_HEARTBEAT_LEGACY)]<<8)
|
||||
| d[sizeof(SERVERBROWSE_HEARTBEAT_LEGACY)+1];
|
||||
AddCheckserver(&pPacket->m_Address, &Alt, 0);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_GETCOUNT_LEGACY) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_GETCOUNT_LEGACY, sizeof(SERVERBROWSE_GETCOUNT_LEGACY)) == 0)
|
||||
{
|
||||
int Count = m_pOwner->GetCount();
|
||||
m_CountData.m_High = (Count>>8)&0xff;
|
||||
m_CountData.m_Low = Count&0xff;
|
||||
SendPacket(PACKET_COUNT, &pPacket->m_Address, 0);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_GETLIST_LEGACY) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_GETLIST_LEGACY, sizeof(SERVERBROWSE_GETLIST_LEGACY)) == 0)
|
||||
{
|
||||
IMastersrvSlave::SendList(&pPacket->m_Address, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(Socket == IMastersrv::SOCKET_CHECKER)
|
||||
{
|
||||
if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWRESPONSE) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_FWRESPONSE, sizeof(SERVERBROWSE_FWRESPONSE)) == 0)
|
||||
{
|
||||
AddServer(&pPacket->m_Address, 0);
|
||||
return 0; // for 0.6 compatiblity
|
||||
}
|
||||
}
|
||||
else
|
||||
dbg_assert(0, "invalid socket type");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMastersrvSlave_0_5::SendPacket(int PacketType, const NETADDR *pAddr, void *pUserData)
|
||||
{
|
||||
dbg_assert(PacketType >= 0 && PacketType < NUM_PACKETS, "invalid packet type");
|
||||
|
||||
m_aPackets[PacketType].m_Address = *pAddr;
|
||||
m_pOwner->Send((PacketType != PACKET_CHECK) ? IMastersrv::SOCKET_OP : IMastersrv::SOCKET_CHECKER,
|
||||
&m_aPackets[PacketType], NET_TOKEN_NONE, NET_PACKETVERSION_LEGACY);
|
||||
}
|
||||
|
||||
void CMastersrvSlave_0_5::NetaddrToMastersrv(CMastersrvAddrLegacy *pOut, const NETADDR *pIn)
|
||||
{
|
||||
dbg_assert(pIn->type == NETTYPE_IPV4, "legacy mastersrv addresses only support ipv4");
|
||||
|
||||
mem_copy(pOut->m_aIp, pIn->ip, 4);
|
||||
pOut->m_aPort[0] = (pIn->port>>0)&0xff; // little endian
|
||||
pOut->m_aPort[1] = (pIn->port>>8)&0xff;
|
||||
}
|
||||
|
||||
IMastersrvSlave *CreateSlave_0_5(IMastersrv *pOwner)
|
||||
{
|
||||
return new CMastersrvSlave_0_5(pOwner);
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
/* (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. */
|
||||
|
||||
#include "mastersrv.h"
|
||||
|
||||
class CMastersrvSlave_0_6 : public IMastersrvSlaveAdv
|
||||
{
|
||||
public:
|
||||
CMastersrvSlave_0_6(IMastersrv *pOwner);
|
||||
virtual ~CMastersrvSlave_0_6() {}
|
||||
|
||||
virtual int BuildPacketStart(void *pData, int MaxLength);
|
||||
virtual int BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData);
|
||||
virtual int ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion);
|
||||
|
||||
virtual void SendPacket(int PacketType, const NETADDR *pAddr, void *pUserData);
|
||||
|
||||
struct CCountPacketData
|
||||
{
|
||||
unsigned char m_Header[sizeof(SERVERBROWSE_COUNT)];
|
||||
unsigned char m_High;
|
||||
unsigned char m_Low;
|
||||
} m_CountData;
|
||||
};
|
||||
|
||||
CMastersrvSlave_0_6::CMastersrvSlave_0_6(IMastersrv *pOwner)
|
||||
: IMastersrvSlaveAdv(pOwner, IMastersrv::MASTERSRV_0_6)
|
||||
{
|
||||
mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(m_CountData.m_Header));
|
||||
|
||||
for(int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
m_aPackets[i].m_ClientID = -1;
|
||||
m_aPackets[i].m_Flags = NETSENDFLAG_CONNLESS|NETSENDFLAG_STATELESS;
|
||||
}
|
||||
|
||||
m_aPackets[PACKET_COUNT].m_DataSize = sizeof(m_CountData);
|
||||
m_aPackets[PACKET_COUNT].m_pData = &m_CountData;
|
||||
|
||||
m_aPackets[PACKET_CHECK].m_DataSize = sizeof(SERVERBROWSE_FWCHECK);
|
||||
m_aPackets[PACKET_CHECK].m_pData = SERVERBROWSE_FWCHECK;
|
||||
|
||||
m_aPackets[PACKET_OK].m_DataSize = sizeof(SERVERBROWSE_FWOK);
|
||||
m_aPackets[PACKET_OK].m_pData = SERVERBROWSE_FWOK;
|
||||
|
||||
m_aPackets[PACKET_ERROR].m_DataSize = sizeof(SERVERBROWSE_FWERROR);
|
||||
m_aPackets[PACKET_ERROR].m_pData = SERVERBROWSE_FWERROR;
|
||||
|
||||
dbg_msg("mastersrv", "started mastersrv 0.6");
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_6::BuildPacketStart(void *pData, int MaxLength)
|
||||
{
|
||||
if(MaxLength < sizeof(SERVERBROWSE_LIST))
|
||||
return -1;
|
||||
mem_copy(pData, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST));
|
||||
return sizeof(SERVERBROWSE_LIST);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_6::BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData)
|
||||
{
|
||||
if(MaxLength < sizeof(CMastersrvAddr))
|
||||
return -1;
|
||||
NetaddrToMastersrv((CMastersrvAddr *)pData, pAddr);
|
||||
return sizeof(CMastersrvAddr);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_6::ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion)
|
||||
{
|
||||
if(PacketVersion != NET_PACKETVERSION_LEGACY || !(pPacket->m_Flags&NETSENDFLAG_CONNLESS))
|
||||
return 0;
|
||||
|
||||
if(Socket == IMastersrv::SOCKET_OP)
|
||||
{
|
||||
if(pPacket->m_DataSize == sizeof(SERVERBROWSE_HEARTBEAT)+2 &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT)) == 0)
|
||||
{
|
||||
NETADDR Alt;
|
||||
unsigned char *d = (unsigned char *)pPacket->m_pData;
|
||||
Alt = pPacket->m_Address;
|
||||
Alt.port = (d[sizeof(SERVERBROWSE_HEARTBEAT)]<<8)
|
||||
| d[sizeof(SERVERBROWSE_HEARTBEAT)+1];
|
||||
AddCheckserver(&pPacket->m_Address, &Alt, 0);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_GETCOUNT) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_GETCOUNT, sizeof(SERVERBROWSE_GETCOUNT)) == 0)
|
||||
{
|
||||
int Count = m_pOwner->GetCount();
|
||||
m_CountData.m_High = (Count>>8)&0xff;
|
||||
m_CountData.m_Low = Count&0xff;
|
||||
SendPacket(PACKET_COUNT, &pPacket->m_Address, 0);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_GETLIST) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_GETLIST, sizeof(SERVERBROWSE_GETLIST)) == 0)
|
||||
{
|
||||
IMastersrvSlave::SendList(&pPacket->m_Address, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(Socket == IMastersrv::SOCKET_CHECKER)
|
||||
{
|
||||
if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWRESPONSE) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_FWRESPONSE, sizeof(SERVERBROWSE_FWRESPONSE)) == 0)
|
||||
{
|
||||
AddServer(&pPacket->m_Address, 0);
|
||||
return 0; // for 0.5 compatiblity
|
||||
}
|
||||
}
|
||||
else
|
||||
dbg_assert(0, "invalid socket type");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMastersrvSlave_0_6::SendPacket(int PacketType, const NETADDR *pAddr, void *pUserData)
|
||||
{
|
||||
dbg_assert(PacketType >= 0 && PacketType < NUM_PACKETS, "invalid packet type");
|
||||
|
||||
m_aPackets[PacketType].m_Address = *pAddr;
|
||||
m_pOwner->Send((PacketType != PACKET_CHECK) ? IMastersrv::SOCKET_OP : IMastersrv::SOCKET_CHECKER,
|
||||
&m_aPackets[PacketType], NET_TOKEN_NONE, NET_PACKETVERSION_LEGACY);
|
||||
}
|
||||
|
||||
IMastersrvSlave *CreateSlave_0_6(IMastersrv *pOwner)
|
||||
{
|
||||
return new CMastersrvSlave_0_6(pOwner);
|
||||
}
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
/* (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. */
|
||||
|
||||
#include "mastersrv.h"
|
||||
|
||||
class CMastersrvSlave_0_7 : public IMastersrvSlaveAdv
|
||||
{
|
||||
public:
|
||||
CMastersrvSlave_0_7(IMastersrv *pOwner);
|
||||
virtual ~CMastersrvSlave_0_7() {}
|
||||
|
||||
virtual int BuildPacketStart(void *pData, int MaxLength);
|
||||
virtual int BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData);
|
||||
virtual int ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion);
|
||||
|
||||
virtual void SendPacket(int PacketType, const NETADDR *pAddr, void *pUserData);
|
||||
|
||||
struct CCountPacketData
|
||||
{
|
||||
unsigned char m_Header[sizeof(SERVERBROWSE_COUNT)];
|
||||
unsigned char m_High;
|
||||
unsigned char m_Low;
|
||||
} m_CountData;
|
||||
};
|
||||
|
||||
CMastersrvSlave_0_7::CMastersrvSlave_0_7(IMastersrv *pOwner)
|
||||
: IMastersrvSlaveAdv(pOwner, IMastersrv::MASTERSRV_0_7)
|
||||
{
|
||||
mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(m_CountData.m_Header));
|
||||
|
||||
for(int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
m_aPackets[i].m_ClientID = -1;
|
||||
m_aPackets[i].m_Flags = NETSENDFLAG_CONNLESS;
|
||||
}
|
||||
|
||||
m_aPackets[PACKET_COUNT].m_DataSize = sizeof(m_CountData);
|
||||
m_aPackets[PACKET_COUNT].m_pData = &m_CountData;
|
||||
|
||||
m_aPackets[PACKET_CHECK].m_DataSize = sizeof(SERVERBROWSE_FWCHECK);
|
||||
m_aPackets[PACKET_CHECK].m_pData = SERVERBROWSE_FWCHECK;
|
||||
|
||||
m_aPackets[PACKET_OK].m_DataSize = sizeof(SERVERBROWSE_FWOK);
|
||||
m_aPackets[PACKET_OK].m_pData = SERVERBROWSE_FWOK;
|
||||
|
||||
m_aPackets[PACKET_ERROR].m_DataSize = sizeof(SERVERBROWSE_FWERROR);
|
||||
m_aPackets[PACKET_ERROR].m_pData = SERVERBROWSE_FWERROR;
|
||||
|
||||
dbg_msg("mastersrv", "started mastersrv 0.7");
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_7::BuildPacketStart(void *pData, int MaxLength)
|
||||
{
|
||||
if(MaxLength < sizeof(SERVERBROWSE_LIST))
|
||||
return -1;
|
||||
mem_copy(pData, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST));
|
||||
return sizeof(SERVERBROWSE_LIST);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_7::BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData)
|
||||
{
|
||||
if(MaxLength < sizeof(CMastersrvAddr))
|
||||
return -1;
|
||||
NetaddrToMastersrv((CMastersrvAddr *)pData, pAddr);
|
||||
return sizeof(CMastersrvAddr);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_0_7::ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion)
|
||||
{
|
||||
if(PacketVersion != NET_PACKETVERSION || !(pPacket->m_Flags&NETSENDFLAG_CONNLESS))
|
||||
return 0;
|
||||
|
||||
if(Socket == IMastersrv::SOCKET_OP)
|
||||
{
|
||||
if(pPacket->m_DataSize == sizeof(SERVERBROWSE_HEARTBEAT)+2 &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT)) == 0)
|
||||
{
|
||||
if(pPacket->m_Flags&NETSENDFLAG_STATELESS)
|
||||
return -1;
|
||||
NETADDR Alt;
|
||||
unsigned char *d = (unsigned char *)pPacket->m_pData;
|
||||
Alt = pPacket->m_Address;
|
||||
Alt.port = (d[sizeof(SERVERBROWSE_HEARTBEAT)]<<8)
|
||||
| d[sizeof(SERVERBROWSE_HEARTBEAT)+1];
|
||||
AddCheckserver(&pPacket->m_Address, &Alt, (void *)PacketToken);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_GETCOUNT) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_GETCOUNT, sizeof(SERVERBROWSE_GETCOUNT)) == 0)
|
||||
{
|
||||
int Count = m_pOwner->GetCount();
|
||||
m_CountData.m_High = (Count>>8)&0xff;
|
||||
m_CountData.m_Low = Count&0xff;
|
||||
SendPacket(PACKET_COUNT, &pPacket->m_Address, (void *)PacketToken);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_GETLIST) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_GETLIST, sizeof(SERVERBROWSE_GETLIST)) == 0)
|
||||
{
|
||||
if(pPacket->m_Flags&NETSENDFLAG_STATELESS)
|
||||
return -1;
|
||||
IMastersrvSlave::SendList(&pPacket->m_Address, (void *)PacketToken);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(Socket == IMastersrv::SOCKET_CHECKER)
|
||||
{
|
||||
if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWRESPONSE) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_FWRESPONSE, sizeof(SERVERBROWSE_FWRESPONSE)) == 0)
|
||||
{
|
||||
AddServer(&pPacket->m_Address, (void *)PacketToken);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
dbg_assert(0, "invalid socket type");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMastersrvSlave_0_7::SendPacket(int PacketType, const NETADDR *pAddr, void *pUserData)
|
||||
{
|
||||
dbg_assert(PacketType >= 0 && PacketType < NUM_PACKETS, "invalid packet type");
|
||||
|
||||
m_aPackets[PacketType].m_Address = *pAddr;
|
||||
m_pOwner->Send((PacketType != PACKET_CHECK) ? IMastersrv::SOCKET_OP : IMastersrv::SOCKET_CHECKER,
|
||||
&m_aPackets[PacketType], (TOKEN) (long int) pUserData, NET_PACKETVERSION);
|
||||
}
|
||||
|
||||
IMastersrvSlave *CreateSlave_0_7(IMastersrv *pOwner)
|
||||
{
|
||||
return new CMastersrvSlave_0_7(pOwner);
|
||||
}
|
||||
|
|
@ -1,155 +0,0 @@
|
|||
/* (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. */
|
||||
|
||||
#include "mastersrv.h"
|
||||
|
||||
#include <game/version.h>
|
||||
|
||||
struct CMapVersion
|
||||
{
|
||||
char m_aName[8];
|
||||
unsigned char m_aCrc[4];
|
||||
unsigned char m_aSize[4];
|
||||
};
|
||||
|
||||
static CMapVersion s_aMapVersionList[] = {
|
||||
{"ctf1", {0x06, 0xb5, 0xf1, 0x17}, {0x00, 0x00, 0x12, 0x38}},
|
||||
{"ctf2", {0x27, 0xbc, 0x5e, 0xac}, {0x00, 0x00, 0x64, 0x1a}},
|
||||
{"ctf3", {0xa3, 0x73, 0x9d, 0x41}, {0x00, 0x00, 0x17, 0x0f}},
|
||||
{"ctf4", {0xbe, 0x7c, 0x4d, 0xb9}, {0x00, 0x00, 0x2e, 0xfe}},
|
||||
{"ctf5", {0xd9, 0x21, 0x29, 0xa0}, {0x00, 0x00, 0x2f, 0x4c}},
|
||||
{"ctf6", {0x28, 0xc8, 0x43, 0x51}, {0x00, 0x00, 0x69, 0x2f}},
|
||||
{"ctf7", {0x1d, 0x35, 0x98, 0x72}, {0x00, 0x00, 0x15, 0x87}},
|
||||
{"dm1", {0xf2, 0x15, 0x9e, 0x6e}, {0x00, 0x00, 0x16, 0xad}},
|
||||
{"dm2", {0x71, 0x83, 0x98, 0x78}, {0x00, 0x00, 0x21, 0xdf}},
|
||||
{"dm6", {0x47, 0x4d, 0xa2, 0x35}, {0x00, 0x00, 0x1e, 0x95}},
|
||||
{"dm7", {0x42, 0x6d, 0xa1, 0x67}, {0x00, 0x00, 0x27, 0x2a}},
|
||||
{"dm8", {0x85, 0xf1, 0x1e, 0xd6}, {0x00, 0x00, 0x9e, 0xbd}},
|
||||
{"dm9", {0x42, 0xd4, 0x77, 0x7e}, {0x00, 0x00, 0x20, 0x11}},
|
||||
};
|
||||
|
||||
static const int s_NumMapVersionItems = sizeof(s_aMapVersionList)/sizeof(CMapVersion);
|
||||
|
||||
static const unsigned char VERSIONSRV_GETVERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 'g'};
|
||||
static const unsigned char VERSIONSRV_VERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 's'};
|
||||
|
||||
static const unsigned char VERSIONSRV_GETMAPLIST[] = {255, 255, 255, 255, 'v', 'm', 'l', 'g'};
|
||||
static const unsigned char VERSIONSRV_MAPLIST[] = {255, 255, 255, 255, 'v', 'm', 'l', 's'};
|
||||
|
||||
class CMastersrvSlave_Ver : public IMastersrvSlave
|
||||
{
|
||||
public:
|
||||
struct CNetConnData
|
||||
{
|
||||
TOKEN m_Token;
|
||||
int m_Version;
|
||||
};
|
||||
|
||||
CMastersrvSlave_Ver(IMastersrv *pOwner);
|
||||
virtual ~CMastersrvSlave_Ver() {}
|
||||
|
||||
virtual int BuildPacketStart(void *pData, int MaxLength);
|
||||
virtual int BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData);
|
||||
virtual int ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion);
|
||||
|
||||
virtual void SendList(const NETADDR *pAddr, const void *pData, int DataSize, void *pUserData);
|
||||
virtual void SendVersion(const NETADDR *pAddr, TOKEN PacketToken, int PacketVersion);
|
||||
|
||||
// stubs, not needed
|
||||
virtual void SendCheck(const NETADDR *pAddr, void *pUserData) { dbg_assert(0, "stub"); }
|
||||
virtual void SendOk(const NETADDR *pAddr, void *pUserData) { dbg_assert(0, "stub"); }
|
||||
virtual void SendError(const NETADDR *pAddr, void *pUserData) { dbg_assert(0, "stub"); }
|
||||
|
||||
static NETADDR s_NullAddr;
|
||||
|
||||
char m_aVersionPacket[sizeof(VERSIONSRV_VERSION) + sizeof(GAME_RELEASE_VERSION)];
|
||||
};
|
||||
|
||||
NETADDR CMastersrvSlave_Ver::s_NullAddr = { 0 };
|
||||
|
||||
CMastersrvSlave_Ver::CMastersrvSlave_Ver(IMastersrv *pOwner)
|
||||
: IMastersrvSlave(pOwner, IMastersrv::MASTERSRV_VER)
|
||||
{
|
||||
for(int i = 0; i < s_NumMapVersionItems; i++)
|
||||
AddServer(&s_NullAddr, &s_aMapVersionList[i]);
|
||||
mem_copy(m_aVersionPacket, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION));
|
||||
mem_copy(m_aVersionPacket + sizeof(VERSIONSRV_VERSION),
|
||||
GAME_RELEASE_VERSION, sizeof(GAME_RELEASE_VERSION));
|
||||
|
||||
dbg_msg("mastersrv", "started versionsrv");
|
||||
}
|
||||
|
||||
void CMastersrvSlave_Ver::SendVersion(const NETADDR *pAddr, TOKEN PacketToken, int PacketVersion)
|
||||
{
|
||||
CNetChunk Packet;
|
||||
Packet.m_ClientID = -1;
|
||||
Packet.m_Address = *pAddr;
|
||||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
if(PacketVersion == NET_PACKETVERSION_LEGACY)
|
||||
Packet.m_Flags |= NETSENDFLAG_STATELESS;
|
||||
Packet.m_pData = m_aVersionPacket;
|
||||
Packet.m_DataSize = sizeof(m_aVersionPacket);
|
||||
m_pOwner->Send(IMastersrv::SOCKET_VERSION, &Packet, PacketToken, PacketVersion);
|
||||
}
|
||||
|
||||
void CMastersrvSlave_Ver::SendList(const NETADDR *pAddr, const void *pData, int DataSize, void *pUserData)
|
||||
{
|
||||
CNetConnData *pConn = (CNetConnData *)pUserData;
|
||||
CNetChunk Packet;
|
||||
Packet.m_ClientID = -1;
|
||||
Packet.m_Address = *pAddr;
|
||||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
if(pConn->m_Version == NET_PACKETVERSION_LEGACY)
|
||||
Packet.m_Flags |= NETSENDFLAG_STATELESS;
|
||||
Packet.m_pData = pData;
|
||||
Packet.m_DataSize = DataSize;
|
||||
m_pOwner->Send(IMastersrv::SOCKET_VERSION, &Packet, pConn->m_Token, pConn->m_Version);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_Ver::BuildPacketStart(void *pData, int MaxLength)
|
||||
{
|
||||
if(MaxLength < sizeof(VERSIONSRV_MAPLIST))
|
||||
return -1;
|
||||
mem_copy(pData, VERSIONSRV_MAPLIST, sizeof(VERSIONSRV_MAPLIST));
|
||||
return sizeof(VERSIONSRV_MAPLIST);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_Ver::BuildPacketAdd(void *pData, int MaxLength, const NETADDR *pAddr, void *pUserData)
|
||||
{
|
||||
if(MaxLength < sizeof(CMapVersion))
|
||||
return -1;
|
||||
mem_copy(pData, pUserData, sizeof(CMapVersion));
|
||||
return sizeof(CMapVersion);
|
||||
}
|
||||
|
||||
int CMastersrvSlave_Ver::ProcessMessage(int Socket, const CNetChunk *pPacket, TOKEN PacketToken, int PacketVersion)
|
||||
{
|
||||
if(Socket != IMastersrv::SOCKET_VERSION)
|
||||
return 0;
|
||||
|
||||
if(pPacket->m_DataSize == sizeof(VERSIONSRV_GETVERSION) &&
|
||||
mem_comp(pPacket->m_pData, VERSIONSRV_GETVERSION, sizeof(VERSIONSRV_GETVERSION)) == 0)
|
||||
{
|
||||
SendVersion(&pPacket->m_Address, PacketToken, PacketVersion);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(VERSIONSRV_GETMAPLIST) &&
|
||||
mem_comp(pPacket->m_pData, VERSIONSRV_GETMAPLIST, sizeof(VERSIONSRV_GETMAPLIST)) == 0)
|
||||
{
|
||||
if(PacketVersion == NET_PACKETVERSION &&
|
||||
(pPacket->m_Flags&NETSENDFLAG_STATELESS))
|
||||
return 1; // new-style packet without token -> drop
|
||||
CNetConnData Data;
|
||||
Data.m_Token = PacketToken;
|
||||
Data.m_Version = PacketVersion;
|
||||
IMastersrvSlave::SendList(&pPacket->m_Address, &Data);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
IMastersrvSlave *CreateSlave_Ver(IMastersrv *pOwner)
|
||||
{
|
||||
return new CMastersrvSlave_Ver(pOwner);
|
||||
}
|
||||
|
Loading…
Reference in a new issue