hlswmaster/plugins/gamespy1.c

78 lines
2.6 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.h"
struct scan_ports port_arr[] = {
2006-02-02 16:31:52 +01:00
{ 22000, 22010, 16 }, /* Battlefield 1942 */
{ 0, 0, 0 }
2006-02-02 16:29:30 +01:00
};
static char scanmsg[] = "\\info\\";
2006-02-02 16:31:52 +01:00
static char bf1942_reply[] = "\\gameId\\BF1942\\";
static char hostport_search[] = "\\hostport\\";
2006-02-02 16:29:30 +01:00
int scan(void) {
pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg));
return 1;
}
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 16: /* battlefield 1942 */
if (!pkt_memmem(pkt, 0, bf1942_reply, strlen(bf1942_reply)))
return 0;
p = pkt_memmem(pkt, 0, hostport_search, strlen(hostport_search));
if (!p)
return 0;
port = pkt_atoi(pkt, p + strlen(hostport_search));
server_add(gameid, pkt->addr.sin_addr.s_addr, port, ntohs(pkt->addr.sin_port));
break;
default:
server_add_pkt(gameid, pkt);
break;
}
2006-02-02 16:29:30 +01:00
return 1;
}
static 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,
};
void __attribute__ ((constructor)) init(void) {
2006-02-02 16:29:30 +01:00
register_plugin(&plugin);
}
void __attribute__ ((destructor)) fini(void) {
2006-02-02 16:29:30 +01:00
unregister_plugin(&plugin);
}