2006-02-02 16:27:19 +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 <stdio.h>
|
2006-02-02 16:43:41 +01:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <arpa/inet.h>
|
2006-02-02 16:27:19 +01:00
|
|
|
|
2006-02-02 16:43:41 +01:00
|
|
|
#include "plugin_helper.h"
|
2006-02-02 16:27:19 +01:00
|
|
|
|
2006-02-02 16:43:41 +01:00
|
|
|
struct _entry {
|
2006-02-02 16:27:19 +01:00
|
|
|
u_int16_t gameid;
|
|
|
|
u_int32_t ip;
|
|
|
|
u_int16_t port1;
|
|
|
|
u_int16_t port2;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2006-02-02 16:43:41 +01:00
|
|
|
static struct in_addr *ip_arr = NULL;
|
|
|
|
static int ip_arr_size = 0;
|
|
|
|
|
|
|
|
static char scanmsg[] = "\xff\xff\xff\xffHLSWLANSEARCH";
|
|
|
|
|
2006-02-02 16:41:56 +01:00
|
|
|
static int scan(void) {
|
2006-02-02 16:43:41 +01:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < ip_arr_size; i++)
|
|
|
|
pkt_send(&ip_arr[i], 7140, scanmsg, sizeof(scanmsg));
|
2006-02-02 16:27:19 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-02-02 16:41:56 +01:00
|
|
|
static int parse(struct net_pkt *pkt) {
|
2006-02-02 16:27:19 +01:00
|
|
|
struct _entry *server;
|
|
|
|
if (pkt_getport(pkt) != 7140)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
server = (void *)pkt->buf + sizeof(scanmsg);
|
|
|
|
|
|
|
|
while ((void *)server < ((void *)pkt->buf + pkt->size)) {
|
|
|
|
server_add(server->gameid, server->ip, server->port1, server->port2);
|
|
|
|
server++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-02-02 16:41:56 +01:00
|
|
|
static int init(struct conf_section *section) {
|
|
|
|
struct conf_tupel *tupel;
|
2006-02-02 16:43:41 +01:00
|
|
|
int i = 0;
|
2006-02-02 16:41:56 +01:00
|
|
|
list_for_each_entry(tupel, §ion->tupel, list)
|
|
|
|
if (!strcmp(tupel->option, "scan_ip"))
|
2006-02-02 16:43:41 +01:00
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i == 0 || !(ip_arr = malloc(sizeof(struct in_addr) * i)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
list_for_each_entry(tupel, §ion->tupel, list) {
|
|
|
|
if (!strcmp(tupel->option, "scan_ip")) {
|
|
|
|
if (inet_pton(AF_INET, tupel->parameter, &ip_arr[i]) <= 0) {
|
|
|
|
log_print(" invalid ip: %s", tupel->parameter);
|
|
|
|
} else {
|
|
|
|
log_print(" adding %s", tupel->parameter);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ip_arr_size = i;
|
|
|
|
log_print(" added %d master server(s)", i);
|
|
|
|
return 1;
|
2006-02-02 16:41:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fini() {
|
2006-02-02 16:43:41 +01:00
|
|
|
if (ip_arr_size > 0 && ip_arr)
|
|
|
|
free(ip_arr);
|
2006-02-02 16:41:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hlswmaster_plugin plugin = {
|
2006-02-02 16:27:19 +01:00
|
|
|
.name = "hlswproxy",
|
|
|
|
.scan = &scan,
|
|
|
|
.parse = &parse,
|
2006-02-02 16:41:56 +01:00
|
|
|
.init = &init,
|
|
|
|
.fini = &fini,
|
2006-02-02 16:27:19 +01:00
|
|
|
};
|