From cb90132d40421e523422bd1cf43466044d9c937a Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Thu, 2 Feb 2006 16:34:11 +0100 Subject: [PATCH] Version 0.41 --- plugins/q3engine.c | 33 ++++++++++++++++++++++++++++----- plugins/ut.c | 16 +++++++++------- src/main.c | 2 +- src/plugin_helper.c | 17 +++++++++++++---- src/scanner.c | 8 +++++--- src/serverlist.c | 4 ++-- 6 files changed, 58 insertions(+), 22 deletions(-) diff --git a/plugins/q3engine.c b/plugins/q3engine.c index 735fe4f..26033b0 100644 --- a/plugins/q3engine.c +++ b/plugins/q3engine.c @@ -21,14 +21,20 @@ #include "plugin.h" struct scan_ports port_arr[] = { - { 27960, 27969, 6 }, /* Quake3(6), Elite Force(7) */ - { 28960, 28963, 31 }, /* Call of Duty(31) */ + { 27960, 27969, 6 }, /* Quake3(6), Elite Force(7), Enemy Territory(25) */ + { 28960, 28963, 31 }, /* Call of Duty(31), Call of Duty: United Offensive (42) */ { 0,0,0 } }; static char scanmsg[] = "\xff\xff\xff\xffgetStatus"; static char replymsg[] = "\xff\xff\xff\xffstatusResponse"; +static char q3_reply[] = "\\version\\Q3 "; +static char ef_reply[] = "\\version\\ST:V "; +static char et_reply[] = "\\version\\ET "; +static char cod_reply[] = "\\gamename\\Call of Duty\\"; +static char coduo_reply[] = "\\gamename\\CoD:United Offensive\\"; + int scan(void) { pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg)); return 1; @@ -43,16 +49,33 @@ int parse(struct net_pkt *pkt) { if (pkt_memcmp(pkt, 0, replymsg, strlen(replymsg))) return 0; - if (gameid == 6) { - if (pkt_memmem(pkt, 0, "\\version\\Q3 ", 12)) { + switch (gameid) { + case 6: /* q3, ef, et */ + if (pkt_memmem(pkt, 0, q3_reply, strlen(q3_reply))) { gameid = 6; - } else if (pkt_memmem(pkt, 0, "\\version\\ST:V ", 14)) { + } else if (pkt_memmem(pkt, 0, ef_reply, strlen(ef_reply))) { gameid = 7; + } else if (pkt_memmem(pkt, 0, et_reply, strlen(et_reply))) { + gameid = 25; + } else { return 0; } + break; + + case 31: /* cod, cod:uo */ + if (pkt_memmem(pkt, 0, cod_reply, strlen(cod_reply))) { + gameid = 31; + + } else if (pkt_memmem(pkt, 0, coduo_reply, strlen(coduo_reply))) { + gameid = 42; + + } else { + return 0; + } + break; } server_add_pkt(gameid, pkt); diff --git a/plugins/ut.c b/plugins/ut.c index 5a853fe..9cec9d4 100644 --- a/plugins/ut.c +++ b/plugins/ut.c @@ -21,12 +21,13 @@ #include "plugin.h" struct scan_ports port_arr[] = { - { 8777, 8786, 5 }, /* Unreal Tournament */ + { 8777, 8786, 5 }, /* Unreal Tournament (5), Ravenshield (-) */ { 0,0,0 } }; static char scanmsg[] = "REPORTQUERY"; static char ut_reply[] = "ut "; +static char rvs_reply[] = "rvnshld 0"; int scan(void) { pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg)); @@ -41,14 +42,15 @@ int parse(struct net_pkt *pkt) { return 0; switch (gameid) { - case 5: /* Unreal Tournament */ - p = pkt_memmem(pkt, 0, ut_reply, strlen(ut_reply)); - if (!p) - return 0; + case 5: /* ut, rvs */ + if ((p = pkt_memmem(pkt, 0, ut_reply, strlen(ut_reply)))) { + port = pkt_atoi(pkt, p + strlen(ut_reply)); + server_add(gameid, pkt->addr.sin_addr.s_addr, port -1, port); - port = pkt_atoi(pkt, p + strlen(ut_reply)); + } else if ((p = pkt_memmem(pkt, 0, rvs_reply, strlen(rvs_reply)))) { + server_add_pkt(0, pkt); - server_add(gameid, pkt->addr.sin_addr.s_addr, port -1, port); + } break; default: diff --git a/src/main.c b/src/main.c index 4b0c903..da8f084 100644 --- a/src/main.c +++ b/src/main.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) { } -// plugin_load("plugins/hlswproxy.so"); + plugin_load("plugins/hlswproxy.so"); plugin_load("plugins/q3engine.so"); plugin_load("plugins/quake2.so"); plugin_load("plugins/gamespy1.so"); diff --git a/src/plugin_helper.c b/src/plugin_helper.c index 1f836fd..49de018 100644 --- a/src/plugin_helper.c +++ b/src/plugin_helper.c @@ -24,6 +24,8 @@ #define __USE_GNU #include +#include + #include #include #include @@ -183,10 +185,17 @@ unsigned short pkt_getport(struct net_pkt *pkt) { * @return int */ int pkt_atoi(struct net_pkt *pkt, void *p) { - /* check buffer bounds */ - if ((void *)pkt->buf > p || ((void *)pkt->buf + pkt->size) < p) + int val = 0; + void *max = ((void *)pkt->buf + pkt->size); + char *c = p; + + /* check lower bounds */ + if ((void *)pkt->buf > p || p > max) return 0; - // TODO: kann ueber paketlaenge lesen - return atoi(p); + while (isdigit(*c) && (void *)c < max) + val = (val * 10) + (*c++ - 0x30); + + return val; } + diff --git a/src/scanner.c b/src/scanner.c index a8c7bd3..e449f3c 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -104,9 +104,11 @@ void scan_receive(void) { i = sizeof(struct sockaddr_in); pkt->size = recvfrom(scan_sock, pkt->buf, recvsize, 0, (struct sockaddr *)&pkt->addr, &i); - if (!plugins_parse(pkt)) - log_print("scan_receive(): received unknown packet"); - + if (!plugins_parse(pkt)) { + log_print("scan_receive(): unknown packet: %s:%d size:%d", + inet_ntoa(pkt->addr.sin_addr), ntohs(pkt->addr.sin_port), pkt->size); + } + free(pkt); } } diff --git a/src/serverlist.c b/src/serverlist.c index 1aebbb7..18bc385 100644 --- a/src/serverlist.c +++ b/src/serverlist.c @@ -86,7 +86,7 @@ int server_add(u_int16_t gameid, u_int32_t ip, u_int16_t port1, u_int16_t port2) { struct in_addr tmp; tmp.s_addr = server.ip; - printf("server_add_new: gameid=%d ip=%s port1=%d port2=%d\n", + printf("server_add_new: gameid=%2d ip=%15s port1=%5d port2=%5d\n", server.gameid, inet_ntoa(tmp), server.port1, server.port2); } #endif @@ -123,7 +123,7 @@ void server_collector(void) { { struct in_addr tmp2; tmp2.s_addr = server->ip; - printf("server timeout: gameid=%d ip=%s port1=%d port2=%d\n", + printf("server timeout: gameid=%2d ip=%15s port1=%5d port2=%5d\n", server->gameid, inet_ntoa(tmp2), server->port1, server->port2); } #endif