ddnet/src/versionsrv/versionsrv.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

2010-05-29 07:25:38 +00:00
// copyright (c) 2007 magnus auvinen, see licence.txt for more info
#include <base/system.h>
2010-05-29 07:25:38 +00:00
#include <engine/shared/network.h>
#include "versionsrv.h"
2010-05-29 07:25:38 +00:00
static CNetClient g_NetOp; // main
2010-05-29 07:25:38 +00:00
void SendVer(NETADDR *pAddr)
{
2010-05-29 07:25:38 +00:00
CNetChunk p;
unsigned char aData[sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)];
2010-05-29 07:25:38 +00:00
mem_copy(aData, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION));
mem_copy(aData + sizeof(VERSIONSRV_VERSION), VERSION_DATA, sizeof(VERSION_DATA));
2010-05-29 07:25:38 +00:00
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_pData = aData;
p.m_DataSize = sizeof(aData);
2010-05-29 07:25:38 +00:00
g_NetOp.Send(&p);
}
2010-05-29 07:25:38 +00:00
int main(int argc, char **argv) // ignore_convention
{
2010-05-29 07:25:38 +00:00
NETADDR BindAddr;
2008-10-01 18:34:43 +00:00
dbg_logger_stdout();
net_init();
2010-05-29 07:25:38 +00:00
mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.port = VERSIONSRV_PORT;
g_NetOp.Open(BindAddr, 0);
dbg_msg("versionsrv", "started");
while(1)
{
2010-05-29 07:25:38 +00:00
g_NetOp.Update();
// process packets
2010-05-29 07:25:38 +00:00
CNetChunk Packet;
while(g_NetOp.Recv(&Packet))
{
2010-05-29 07:25:38 +00:00
if(Packet.m_DataSize == sizeof(VERSIONSRV_GETVERSION) &&
mem_comp(Packet.m_pData, VERSIONSRV_GETVERSION, sizeof(VERSIONSRV_GETVERSION)) == 0)
{
2010-05-29 07:25:38 +00:00
SendVer(&Packet.m_Address);
}
}
// be nice to the CPU
thread_sleep(1);
}
return 0;
}