From fa5231f2c2745ba8d02e674781628dbc3d6a8c16 Mon Sep 17 00:00:00 2001 From: Alfred Eriksson Date: Tue, 2 Sep 2008 17:36:50 +0000 Subject: merge from 0.4.3: versionserver and red team score-use in dm --- src/versionsrv/versionsrv.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/versionsrv/versionsrv.cpp (limited to 'src/versionsrv/versionsrv.cpp') diff --git a/src/versionsrv/versionsrv.cpp b/src/versionsrv/versionsrv.cpp new file mode 100644 index 00000000..eff155f5 --- /dev/null +++ b/src/versionsrv/versionsrv.cpp @@ -0,0 +1,60 @@ +/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ +#include +#include + +extern "C" { + #include +} + +#include "versionsrv.h" + +static net_client net_op; // main + +void send_ver(NETADDR *addr) +{ + NETCHUNK p; + unsigned char data[sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)]; + + memcpy(data, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)); + memcpy(data + sizeof(VERSIONSRV_VERSION), VERSION_DATA, sizeof(VERSION_DATA)); + + p.client_id = -1; + p.address = *addr; + p.flags = NETSENDFLAG_CONNLESS; + p.data = data; + p.data_size = sizeof(data); + + net_op.send(&p); +} + +int main(int argc, char **argv) +{ + NETADDR bindaddr; + mem_zero(&bindaddr, sizeof(bindaddr)); + bindaddr.port = VERSIONSRV_PORT; + + net_op.open(bindaddr, 0); + + dbg_msg("versionsrv", "started"); + + while(1) + { + net_op.update(); + + // process packets + NETCHUNK packet; + while(net_op.recv(&packet)) + { + if(packet.data_size == sizeof(VERSIONSRV_GETVERSION) && + memcmp(packet.data, VERSIONSRV_GETVERSION, sizeof(VERSIONSRV_GETVERSION)) == 0) + { + send_ver(&packet.address); + } + } + + // be nice to the CPU + thread_sleep(1); + } + + return 0; +} -- cgit 1.4.1