From fa5231f2c2745ba8d02e674781628dbc3d6a8c16 Mon Sep 17 00:00:00 2001 From: Alfred Eriksson Date: Tue, 2 Sep 2008 17:36:50 +0000 Subject: [PATCH] merge from 0.4.3: versionserver and red team score-use in dm --- src/game/server/gamecontroller.cpp | 2 +- src/versionsrv/versionsrv.cpp | 60 ++++++++++++++++++++++++++++++ src/versionsrv/versionsrv.h | 7 ++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/versionsrv/versionsrv.cpp create mode 100644 src/versionsrv/versionsrv.h diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index ab24b7d48..7ff698801 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -390,7 +390,7 @@ void GAMECONTROLLER::snap(int snapping_client) gameobj->warmup = warmup; - gameobj->teamscore_red = teamscore[0]; + gameobj->teamscore_red = is_teamplay() ? teamscore[0] : game.players[snapping_client].score; gameobj->teamscore_blue = teamscore[1]; } diff --git a/src/versionsrv/versionsrv.cpp b/src/versionsrv/versionsrv.cpp new file mode 100644 index 000000000..eff155f5b --- /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; +} diff --git a/src/versionsrv/versionsrv.h b/src/versionsrv/versionsrv.h new file mode 100644 index 000000000..023e0713e --- /dev/null +++ b/src/versionsrv/versionsrv.h @@ -0,0 +1,7 @@ +/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ +static const int VERSIONSRV_PORT = 8302; + +static const unsigned char VERSION_DATA[] = {0x00, 0, 4, 3}; + +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'};