2006-02-02 16:29:30 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 03/2005 by Olaf Rempel *
|
|
|
|
* razzor@kopf-tisch.de *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#include <string.h>
|
2006-11-24 21:53:25 +01:00
|
|
|
#include "netpkt.h"
|
|
|
|
#include "plugin.h"
|
2006-02-02 16:43:41 +01:00
|
|
|
#include "plugin_helper.h"
|
2006-02-02 16:29:30 +01:00
|
|
|
|
2006-02-02 16:41:56 +01:00
|
|
|
static struct scan_ports port_arr[] = {
|
2006-02-02 16:43:41 +01:00
|
|
|
{ 27960, 27969, 6 }, /* q3(6), ef(7), et25), rtcw(8) */
|
2006-02-02 16:47:20 +01:00
|
|
|
{ 28070, 28070, 12 }, /* jk2(12) */
|
2006-02-02 16:52:26 +01:00
|
|
|
{ 28960, 28963, 31 }, /* cod(31), cod:uo(42), cod2(48) */
|
2006-02-02 16:47:20 +01:00
|
|
|
{ 29070, 29070, 27 }, /* jk3(27) */
|
2006-02-02 16:29:30 +01:00
|
|
|
{ 0,0,0 }
|
|
|
|
};
|
|
|
|
|
2006-02-02 16:31:52 +01:00
|
|
|
static char scanmsg[] = "\xff\xff\xff\xffgetStatus";
|
|
|
|
static char replymsg[] = "\xff\xff\xff\xffstatusResponse";
|
2006-02-02 16:47:20 +01:00
|
|
|
static char search_version[] = "\\version\\";
|
|
|
|
static char search_gamename[] = "\\gamename\\";
|
|
|
|
static char reply_q3[] = "Q3 ";
|
|
|
|
static char reply_ef[] = "ST:V HM ";
|
|
|
|
static char reply_rtcw[] = "Wolf ";
|
|
|
|
static char reply_et[] = "ET";
|
|
|
|
static char reply_jk2[] = "JK2MP";
|
|
|
|
static char reply_jk3[] = "JAmp";
|
|
|
|
static char reply_cod[] = "Call of Duty\\";
|
|
|
|
static char reply_coduo[] = "CoD:United Offensive\\";
|
2006-02-02 16:52:26 +01:00
|
|
|
static char reply_cod2[] = "Call of Duty 2\\";
|
2006-02-02 16:29:30 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
static int scan(void)
|
|
|
|
{
|
2006-02-02 16:29:30 +01:00
|
|
|
pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
static int parse(struct net_pkt *pkt)
|
|
|
|
{
|
|
|
|
int gameid = 0, pos1, pos2;
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
if (!pkt_check_portarr(pkt, port_arr))
|
|
|
|
return PARSE_REJECT;
|
|
|
|
|
2006-02-02 16:29:30 +01:00
|
|
|
if (pkt_memcmp(pkt, 0, replymsg, strlen(replymsg)))
|
2006-02-02 16:47:20 +01:00
|
|
|
return PARSE_REJECT;
|
2006-02-02 16:29:30 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
pos1 = pkt_memmem(pkt, 0, search_version, strlen(search_version));
|
|
|
|
pos2 = pkt_memmem(pkt, 0, search_gamename, strlen(search_gamename));
|
2006-02-02 16:31:52 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
if (pos1 != -1) {
|
|
|
|
pos1 += strlen(search_version);
|
|
|
|
if (!pkt_memcmp(pkt, pos1, reply_q3, strlen(reply_q3)))
|
|
|
|
gameid = 6;
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
else if (!pkt_memcmp(pkt, pos1, reply_ef, strlen(reply_ef)))
|
2006-02-02 16:31:52 +01:00
|
|
|
gameid = 7;
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
else if (!pkt_memcmp(pkt, pos1, reply_rtcw, strlen(reply_rtcw)))
|
2006-02-02 16:43:41 +01:00
|
|
|
gameid = 8;
|
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
else if (!pkt_memcmp(pkt, pos1, reply_et, strlen(reply_et)))
|
2006-02-02 16:34:11 +01:00
|
|
|
gameid = 25;
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
else if (!pkt_memcmp(pkt, pos1, reply_jk2, strlen(reply_jk2)))
|
|
|
|
gameid = 12;
|
|
|
|
|
|
|
|
else if (!pkt_memcmp(pkt, pos1, reply_jk3, strlen(reply_jk3)))
|
|
|
|
gameid = 27;
|
|
|
|
}
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
if (gameid == 0 && pos2 != -1) {
|
|
|
|
pos2 += strlen(search_gamename);
|
|
|
|
if (!pkt_memcmp(pkt, pos2, reply_cod, strlen(reply_cod)))
|
2006-02-02 16:34:11 +01:00
|
|
|
gameid = 31;
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
else if (!pkt_memcmp(pkt, pos2, reply_coduo, strlen(reply_coduo)))
|
2006-02-02 16:34:11 +01:00
|
|
|
gameid = 42;
|
2006-02-02 16:52:26 +01:00
|
|
|
|
|
|
|
else if (!pkt_memcmp(pkt, pos2, reply_cod2, strlen(reply_cod2)))
|
|
|
|
gameid = 48;
|
2006-02-02 16:31:52 +01:00
|
|
|
}
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:47:20 +01:00
|
|
|
if (gameid == 0)
|
|
|
|
return PARSE_REJECT;
|
2006-11-24 21:53:25 +01:00
|
|
|
|
2006-02-02 16:29:30 +01:00
|
|
|
server_add_pkt(gameid, pkt);
|
2006-02-02 16:47:20 +01:00
|
|
|
return PARSE_ACCEPT;
|
2006-02-02 16:29:30 +01:00
|
|
|
}
|
|
|
|
|
2006-02-02 16:41:56 +01:00
|
|
|
struct hlswmaster_plugin plugin = {
|
2006-02-02 16:31:52 +01:00
|
|
|
.name = "q3engine",
|
2006-02-02 16:29:30 +01:00
|
|
|
.scan = &scan,
|
|
|
|
.parse = &parse,
|
|
|
|
};
|