2010-05-29 07:25:38 +00:00
|
|
|
// copyright (c) 2007 magnus auvinen, see licence.txt for more info
|
2008-09-02 17:36:50 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/shared/network.h>
|
2008-09-02 17:36:50 +00:00
|
|
|
|
|
|
|
#include "versionsrv.h"
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
static CNetClient g_NetOp; // main
|
2008-09-02 17:36:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void SendVer(NETADDR *pAddr)
|
2008-09-02 17:36:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetChunk p;
|
|
|
|
unsigned char aData[sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)];
|
2008-09-02 17:36:50 +00:00
|
|
|
|
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));
|
2008-09-02 17:36:50 +00:00
|
|
|
|
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);
|
2008-09-02 17:36:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
g_NetOp.Send(&p);
|
2008-09-02 17:36:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int main(int argc, char **argv) // ignore_convention
|
2008-09-02 17:36:50 +00:00
|
|
|
{
|
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);
|
2008-09-02 17:36:50 +00:00
|
|
|
|
|
|
|
dbg_msg("versionsrv", "started");
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
g_NetOp.Update();
|
2008-09-02 17:36:50 +00:00
|
|
|
|
|
|
|
// process packets
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetChunk Packet;
|
|
|
|
while(g_NetOp.Recv(&Packet))
|
2008-09-02 17:36:50 +00:00
|
|
|
{
|
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)
|
2008-09-02 17:36:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
SendVer(&Packet.m_Address);
|
2008-09-02 17:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// be nice to the CPU
|
|
|
|
thread_sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|