Version 0.35
This commit is contained in:
parent
6f6760f9d8
commit
7b37fcec90
16
Makefile
16
Makefile
|
@ -1,15 +1,18 @@
|
|||
# Toplevel Makefile
|
||||
|
||||
MASTER_SRC := src/client.c src/daemon.c src/logging.c src/main.c src/plugin.c src/plugin_helper.c src/scanner.c src/serverlist.c
|
||||
PLUGIN_SRC := plugins/hlswproxy.c plugins/quake3.c
|
||||
MASTER_SRC := client.c daemon.c logging.c main.c plugin.c plugin_helper.c scanner.c serverlist.c
|
||||
PLUGIN_SRC := hlswproxy.c quake3.c quake2.c halo.c doom3.c ut.c battlefield1942.c
|
||||
|
||||
CFLAGS := -Wall -I. -I./include -g
|
||||
# ############################
|
||||
|
||||
all: $(PLUGIN_SRC:%.c=%.so) src/hlswmaster
|
||||
all: $(PLUGIN_SRC:%.c=plugins/%.so) src/hlswmaster tools/masterquery
|
||||
|
||||
src/hlswmaster: $(MASTER_SRC:%.c=%.o)
|
||||
gcc -ldl -lpthread -rdynamic $^ -o $@
|
||||
src/hlswmaster: $(MASTER_SRC:%.c=src/%.o)
|
||||
$(CC) -ldl -lpthread -rdynamic $^ -o $@
|
||||
|
||||
tools/masterquery: tools/masterquery.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
@ -21,4 +24,5 @@ src/hlswmaster: $(MASTER_SRC:%.c=%.o)
|
|||
$(LD) -shared -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -rf src/hlswmaster src/*.o plugins/*.so plugins/*.o
|
||||
rm -rf src/*.o plugins/*.so plugins/*.o src/hlswmaster tools/masterquery
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/***************************************************************************
|
||||
* 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[] = {
|
||||
{ 22000, 22010, 16 }, /* Battlefield 1942 */
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static char scanmsg[] = "\\info\\";
|
||||
static char replymsg[] = "ut ";
|
||||
|
||||
int scan(void) {
|
||||
pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TODO: port2 parsen */
|
||||
int parse(struct net_pkt *pkt) {
|
||||
int gameid;
|
||||
|
||||
if (pkt_memcmp(pkt, 0, replymsg, strlen(replymsg)))
|
||||
return 0;
|
||||
|
||||
if (!(gameid = pkt_check_portarr(pkt, port_arr)))
|
||||
return 0;
|
||||
|
||||
server_add_pkt(gameid, pkt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct hlswmaster_plugin plugin = {
|
||||
.name = "battlefield1942",
|
||||
.scan = &scan,
|
||||
.parse = &parse,
|
||||
};
|
||||
|
||||
void _init(void) {
|
||||
register_plugin(&plugin);
|
||||
}
|
||||
|
||||
void _fini(void) {
|
||||
unregister_plugin(&plugin);
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/***************************************************************************
|
||||
* 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[] = {
|
||||
{ 27666, 27673, 38 }, /* Doom 3 */
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static char scanmsg[] = "\xff\xffgetInfo";
|
||||
static char replymsg[] = "\xff\xffinfoResponse";
|
||||
|
||||
int scan(void) {
|
||||
pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parse(struct net_pkt *pkt) {
|
||||
int gameid;
|
||||
|
||||
if (pkt_memcmp(pkt, 0, replymsg, strlen(replymsg)))
|
||||
return 0;
|
||||
|
||||
if (!(gameid = pkt_check_portarr(pkt, port_arr)))
|
||||
return 0;
|
||||
|
||||
server_add_pkt(gameid, pkt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct hlswmaster_plugin plugin = {
|
||||
.name = "doom3",
|
||||
.scan = &scan,
|
||||
.parse = &parse,
|
||||
};
|
||||
|
||||
void _init(void) {
|
||||
register_plugin(&plugin);
|
||||
}
|
||||
|
||||
void _fini(void) {
|
||||
unregister_plugin(&plugin);
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/***************************************************************************
|
||||
* 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"
|
||||
|
||||
static char scanmsg[] = { 0xFE, 0xFD, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
static char replymsg[] = { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
int scan(void) {
|
||||
pkt_send(NULL, 2302, scanmsg, sizeof(scanmsg));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parse(struct net_pkt *pkt) {
|
||||
if (pkt_memcmp(pkt, 0, replymsg, sizeof(replymsg)))
|
||||
return 0;
|
||||
|
||||
server_add_pkt(30, pkt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct hlswmaster_plugin plugin = {
|
||||
.name = "halo",
|
||||
.scan = &scan,
|
||||
.parse = &parse,
|
||||
};
|
||||
|
||||
void _init(void) {
|
||||
register_plugin(&plugin);
|
||||
}
|
||||
|
||||
void _fini(void) {
|
||||
unregister_plugin(&plugin);
|
||||
}
|
|
@ -49,16 +49,16 @@ int parse(struct net_pkt *pkt) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static struct hlswmaster_plugin hlswproxy_plugin = {
|
||||
static struct hlswmaster_plugin plugin = {
|
||||
.name = "hlswproxy",
|
||||
.scan = &scan,
|
||||
.parse = &parse,
|
||||
};
|
||||
|
||||
void _init(void) {
|
||||
register_plugin(&hlswproxy_plugin);
|
||||
register_plugin(&plugin);
|
||||
}
|
||||
|
||||
void _fini(void) {
|
||||
unregister_plugin(&hlswproxy_plugin);
|
||||
unregister_plugin(&plugin);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/***************************************************************************
|
||||
* 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"
|
||||
|
||||
static char scanmsg[] = "\xff\xff\xff\xffinfo";
|
||||
|
||||
int scan(void) {
|
||||
pkt_send(NULL, 27910, scanmsg, strlen(scanmsg));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parse(struct net_pkt *pkt) {
|
||||
if (pkt_memcmp(pkt, 0, scanmsg, strlen(scanmsg)))
|
||||
return 0;
|
||||
|
||||
server_add_pkt(3, pkt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct hlswmaster_plugin plugin = {
|
||||
.name = "quake2",
|
||||
.scan = &scan,
|
||||
.parse = &parse,
|
||||
};
|
||||
|
||||
void _init(void) {
|
||||
register_plugin(&plugin);
|
||||
}
|
||||
|
||||
void _fini(void) {
|
||||
unregister_plugin(&plugin);
|
||||
}
|
|
@ -21,13 +21,13 @@
|
|||
#include "plugin.h"
|
||||
|
||||
struct scan_ports port_arr[] = {
|
||||
{ 27960, 27963, 6 }, /* Quake3 (razzor) */
|
||||
{ 28960, 28964, 31 }, /* Call of Duty (ove) */
|
||||
{ 27960, 27963, 6 }, /* Quake3 */
|
||||
{ 28960, 28963, 31 }, /* Call of Duty */
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static char scanmsg[] = "\xff\xff\xff\xffgetstatus";
|
||||
static char replymsg[] = "\xff\xff\xff\xffstatusResponse";
|
||||
static char scanmsg[] = "\xff\xff\xff\xffgetInfo";
|
||||
static char replymsg[] = "\xff\xff\xff\xffinfoResponse";
|
||||
|
||||
int scan(void) {
|
||||
pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg));
|
||||
|
@ -47,16 +47,16 @@ int parse(struct net_pkt *pkt) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static struct hlswmaster_plugin quake3_plugin = {
|
||||
static struct hlswmaster_plugin plugin = {
|
||||
.name = "quake3",
|
||||
.scan = &scan,
|
||||
.parse = &parse,
|
||||
};
|
||||
|
||||
void _init(void) {
|
||||
register_plugin(&quake3_plugin);
|
||||
register_plugin(&plugin);
|
||||
}
|
||||
|
||||
void _fini(void) {
|
||||
unregister_plugin(&quake3_plugin);
|
||||
unregister_plugin(&plugin);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/***************************************************************************
|
||||
* 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[] = {
|
||||
{ 8777, 8786, 5 }, /* Unreal Tournament */
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static char scanmsg[] = "REPORTQUERY";
|
||||
static char replymsg[] = "ut ";
|
||||
|
||||
int scan(void) {
|
||||
pkt_send_portarr(NULL, port_arr, scanmsg, strlen(scanmsg));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TODO: port2 parsen */
|
||||
int parse(struct net_pkt *pkt) {
|
||||
int gameid;
|
||||
|
||||
if (pkt_memcmp(pkt, 0, replymsg, strlen(replymsg)))
|
||||
return 0;
|
||||
|
||||
if (!(gameid = pkt_check_portarr(pkt, port_arr)))
|
||||
return 0;
|
||||
|
||||
server_add_pkt(gameid, pkt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct hlswmaster_plugin plugin = {
|
||||
.name = "ut",
|
||||
.scan = &scan,
|
||||
.parse = &parse,
|
||||
};
|
||||
|
||||
void _init(void) {
|
||||
register_plugin(&plugin);
|
||||
}
|
||||
|
||||
void _fini(void) {
|
||||
unregister_plugin(&plugin);
|
||||
}
|
|
@ -78,8 +78,13 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
|
||||
plugin_load("plugins/quake3.so");
|
||||
plugin_load("plugins/hlswproxy.so");
|
||||
plugin_load("plugins/quake3.so");
|
||||
plugin_load("plugins/quake2.so");
|
||||
plugin_load("plugins/halo.so");
|
||||
plugin_load("plugins/doom3.so");
|
||||
plugin_load("plugins/ut.so");
|
||||
plugin_load("plugins/battlefield1942.so");
|
||||
|
||||
scan_init();
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ void scan_receive(void) {
|
|||
*/
|
||||
int scan_init() {
|
||||
struct sockaddr_in dst;
|
||||
int i;
|
||||
int i = 1;
|
||||
|
||||
if ((scan_sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
log_print("scan_init(): socket()");
|
||||
|
|
|
@ -81,6 +81,11 @@ int server_add(u_int16_t gameid, u_int32_t ip, u_int16_t port1, u_int16_t port2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct in_addr tmp;
|
||||
tmp.s_addr = server.ip;
|
||||
printf("new server: gameid=%d ip=%s port1=%d port2=%d\n",
|
||||
server.gameid, inet_ntoa(tmp), server.port1, server.port2);
|
||||
|
||||
memcpy(nserver, &server, sizeof(struct game_server));
|
||||
list_add_tail(&nserver->list, &server_list);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
struct _entry {
|
||||
u_int16_t gameid;
|
||||
u_int32_t ip;
|
||||
u_int16_t port1;
|
||||
u_int16_t port2;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
static char scanmsg[] = "\xFF\xFF\xFF\xFFHLSWLANSEARCH";
|
||||
|
||||
char *gameid2name[] = { "Unknown", // 0
|
||||
"HL",
|
||||
"Q1",
|
||||
"Q2",
|
||||
"Q3Comp",
|
||||
"UT",
|
||||
"Q3",
|
||||
"EF",
|
||||
"RtCW",
|
||||
"GSProt",
|
||||
"CCR", // 10
|
||||
"MoHAA",
|
||||
"JK2",
|
||||
"SoF2",
|
||||
"UT2K3",
|
||||
"AAO",
|
||||
"BF1942",
|
||||
"AvP2",
|
||||
"Rune",
|
||||
"IGI2",
|
||||
"NWN", // 20
|
||||
"MoHAAS",
|
||||
"OPF",
|
||||
"OPFR",
|
||||
"DVS",
|
||||
"ET",
|
||||
"EF2",
|
||||
"JK3",
|
||||
"MoHAAB",
|
||||
"Tribes2",
|
||||
"HALO", // 30
|
||||
"CoD",
|
||||
"Savage",
|
||||
"UT2K4",
|
||||
"HLSteam",
|
||||
"BFV",
|
||||
"GS2Prot",
|
||||
"PK",
|
||||
"D3",
|
||||
"OGPProt",
|
||||
"HL2", // 40
|
||||
"TribesV",
|
||||
"CoDUO" };
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct sockaddr_in dst;
|
||||
struct timeval tv;
|
||||
struct _entry *srv;
|
||||
fd_set fdsel, fdcpy;
|
||||
int sock, i = 1, recvsize;
|
||||
void *pkt;
|
||||
|
||||
if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("socket()");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i))) {
|
||||
perror("setsockopt()");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
dst.sin_family = AF_INET;
|
||||
dst.sin_port = htons(7130);
|
||||
inet_aton("0.0.0.0", &dst.sin_addr);
|
||||
|
||||
if (bind(sock, (struct sockaddr *)&dst, sizeof(dst)) < 0) {
|
||||
perror("bind()");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
dst.sin_port = htons(7140);
|
||||
inet_aton("255.255.255.255", &dst.sin_addr);
|
||||
|
||||
if (sendto(sock, scanmsg, sizeof(scanmsg), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0) {
|
||||
perror("sendto()");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
FD_ZERO(&fdsel);
|
||||
FD_SET(sock, &fdsel);
|
||||
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
while (1) {
|
||||
memcpy(&fdcpy, &fdsel, sizeof(fdsel));
|
||||
if (select(FD_SETSIZE, &fdcpy, NULL, NULL, &tv) < 0) {
|
||||
perror("select");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (tv.tv_sec == 0 && tv.tv_usec == 0)
|
||||
exit(0);
|
||||
|
||||
ioctl(sock, FIONREAD, &recvsize);
|
||||
|
||||
if (recvsize <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(pkt = malloc(recvsize))) {
|
||||
perror("malloc()");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
i = sizeof(struct sockaddr_in);
|
||||
recvsize = recvfrom(sock, pkt, recvsize, 0, (struct sockaddr *)&dst, &i);
|
||||
|
||||
printf("received packet from: %s:%d size=%d\n",
|
||||
inet_ntoa(dst.sin_addr), ntohs(dst.sin_port), recvsize);
|
||||
|
||||
srv = pkt + sizeof(scanmsg);
|
||||
while ((void *)srv < pkt + recvsize) {
|
||||
dst.sin_addr.s_addr = srv->ip;
|
||||
printf(" ip=%s port1=%d port2=%d gameid=%d (%s)\n",
|
||||
inet_ntoa(dst.sin_addr),
|
||||
srv->port1,
|
||||
srv->port2,
|
||||
srv->gameid,
|
||||
gameid2name[srv->gameid]);
|
||||
srv++;
|
||||
}
|
||||
free(pkt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue