hlswmaster/plugins/gamespy1.c

118 lines
3.9 KiB
C
Raw Normal View History

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>
#include "plugin_helper.h"
2006-02-02 16:29:30 +01:00
static struct scan_ports port_arr[] = {
{ 7777, 7788, 5 }, /* ut(5), ut2k3(14), ut2k4(33) */
{ 22000, 22010, 16 }, /* bf1942(16) */
{ 23000, 23010, 35 }, /* bfv(35) */
{ 26001, 26011, 19 }, /* igi2(19) */
{ 27888, 27888, 17 }, /* avp2(17) (nur der standart-port..) */
2006-02-02 16:31:52 +01:00
{ 0, 0, 0 }
2006-02-02 16:29:30 +01:00
};
static char scanmsg[] = "\\status\\";
static char ut_reply[] = "\\gamename\\ut\\";
static char ut2k3_reply[] = "\\gamename\\ut2\\";
static char ut2k4_reply[] = "\\gamename\\ut2004\\";
static char bf1942_reply[] = "\\gamename\\bfield1942\\";
static char bfv_reply[] = "\\game_id\\bfvietnam\\";
static char avp2_reply[] = "\\gamename\\avp2\\";
static char igi2_reply[] = "\\gamename\\projectigi2r\\";
2006-02-02 16:31:52 +01:00
static char hostport_search[] = "\\hostport\\";
2006-02-02 16:29:30 +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;
}
static int parse(struct net_pkt *pkt) {
2006-02-02 16:31:52 +01:00
int gameid, port;
void *p;
2006-02-02 16:29:30 +01:00
if (!(gameid = pkt_check_portarr(pkt, port_arr)))
return 0;
2006-02-02 16:31:52 +01:00
switch (gameid) {
case 5:/* unreal tournament 2k3 */
if (pkt_memmem(pkt, 0, ut_reply, strlen(ut_reply)))
gameid = 5;
/* unreal tournament 2k3 */
else if (pkt_memmem(pkt, 0, ut2k3_reply, strlen(ut2k3_reply)))
gameid = 14;
/* unreal tournament 2k4 */
else if (pkt_memmem(pkt, 0, ut2k4_reply, strlen(ut2k4_reply)))
gameid = 33;
else
2006-02-02 16:31:52 +01:00
return 0;
break;
2006-02-02 16:31:52 +01:00
case 16:/* battlefield 1942 */
if (!pkt_memmem(pkt, 0, bf1942_reply, strlen(bf1942_reply)))
2006-02-02 16:31:52 +01:00
return 0;
break;
2006-02-02 16:31:52 +01:00
case 17:/* alien vs. predator 2 */
if (!pkt_memmem(pkt, 0, avp2_reply, strlen(avp2_reply)))
return 0;
break;
case 19:/* project igi2 covert strike */
if (!pkt_memmem(pkt, 0, igi2_reply, strlen(igi2_reply)))
return 0;
break;
case 35:/* battlefield vietnam */
if (!pkt_memmem(pkt, 0, bfv_reply, strlen(bfv_reply)))
return 0;
2006-02-02 16:31:52 +01:00
break;
default:
return 0;
}
/* hostport angabe suchen */
p = pkt_memmem(pkt, 0, hostport_search, strlen(hostport_search));
if (p) {
port = pkt_atoi(pkt, p + strlen(hostport_search));
}
/* wenn ein hostport angegeben wurde, und das nicht der src port ist
** beide ports in die serverliste uebernehmen
*/
if (p && port != ntohs(pkt->addr.sin_port)) {
server_add(gameid, pkt->addr.sin_addr.s_addr, port, ntohs(pkt->addr.sin_port));
} else {
2006-02-02 16:31:52 +01:00
server_add_pkt(gameid, pkt);
}
2006-02-02 16:29:30 +01:00
return 1;
}
struct hlswmaster_plugin plugin = {
2006-02-02 16:31:52 +01:00
.name = "gamespy1",
2006-02-02 16:29:30 +01:00
.scan = &scan,
.parse = &parse,
};