- new master type "file", reads ip addresses from a file
git-svn-id: http://svn.code.sf.net/p/xqf/code/trunk@185 d2ac09be-c843-0410-8b1f-f8a84130e0ec
This commit is contained in:
parent
ec90f2560b
commit
fbe0e2d1b9
@ -1,3 +1,6 @@
|
||||
Sep 15, 2002: Ludwig Nussel <l-n@users.sourceforge.net>
|
||||
- new master type "file", reads ip addresses from a file
|
||||
|
||||
Sep 14, 2002: Ludwig Nussel <l-n@users.sourceforge.net>
|
||||
- support for Unreal Tournament 2003 Demo. No master yet. If you know one, tell
|
||||
me
|
||||
|
2
xqf/TODO
2
xqf/TODO
@ -2,7 +2,7 @@
|
||||
- Multiple Favorites
|
||||
- More general server filters so one can filter based on any server var.
|
||||
- Redial feature to connect to your favorite busy server.
|
||||
- Fix the server core dumps!
|
||||
- Fix the server core dumps! (are there any left?)
|
||||
- Detection if map is installed (req. home dir option)
|
||||
- improve performance with huge server lists (halflife), maybe by serverside
|
||||
filtering
|
||||
|
@ -212,7 +212,7 @@ char *master2url( struct master *m )
|
||||
{
|
||||
char *query_type;
|
||||
char *address;
|
||||
char *result;
|
||||
char *result = NULL;
|
||||
|
||||
if ( m->master_type >= MASTER_NATIVE
|
||||
&& m->master_type < MASTER_NUM_QUERY_TYPES )
|
||||
@ -222,21 +222,28 @@ char *master2url( struct master *m )
|
||||
else
|
||||
return NULL;
|
||||
|
||||
if( m->master_type == MASTER_HTTP )
|
||||
switch(m->master_type)
|
||||
{
|
||||
result = strdup(m->url);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m->host)
|
||||
{
|
||||
address = inet_ntoa(m->host->ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
address = m->hostname;
|
||||
}
|
||||
result = g_strdup_printf("%s%s:%d",query_type,address,m->port);
|
||||
case MASTER_NATIVE:
|
||||
case MASTER_GAMESPY:
|
||||
case MASTER_LAN:
|
||||
if(m->host)
|
||||
{
|
||||
address = inet_ntoa(m->host->ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
address = m->hostname;
|
||||
}
|
||||
result = g_strdup_printf("%s%s:%d",query_type,address,m->port);
|
||||
break;
|
||||
case MASTER_HTTP:
|
||||
case MASTER_FILE:
|
||||
result = strdup(m->url);
|
||||
break;
|
||||
case MASTER_NUM_QUERY_TYPES:
|
||||
case MASTER_INVALID_TYPE:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
182
xqf/src/source.c
182
xqf/src/source.c
@ -53,14 +53,16 @@ char* master_prefixes[MASTER_NUM_QUERY_TYPES] = {
|
||||
"master://",
|
||||
"gmaster://",
|
||||
"http://",
|
||||
"lan://"
|
||||
"lan://",
|
||||
"file://"
|
||||
};
|
||||
|
||||
char* master_designation[MASTER_NUM_QUERY_TYPES] = {
|
||||
N_("Standard"),
|
||||
N_("Gamespy"),
|
||||
N_("http"),
|
||||
N_("LAN")
|
||||
N_("LAN"),
|
||||
N_("File")
|
||||
};
|
||||
|
||||
static GSList *all_masters = NULL;
|
||||
@ -82,6 +84,7 @@ static void save_list (FILE *f, struct master *m) {
|
||||
fprintf (f, "[%s]\n", m->name);
|
||||
}
|
||||
else {
|
||||
/*
|
||||
if (m->url) {
|
||||
fprintf (f, "[%s %s]\n", games[m->type].id, m->url);
|
||||
}
|
||||
@ -95,6 +98,24 @@ static void save_list (FILE *f, struct master *m) {
|
||||
fprintf (f, "[%s %s%s:%d]\n", games[m->type].id, master_prefixes[MASTER_NATIVE],
|
||||
(m->hostname)? m->hostname : inet_ntoa (m->host->ip), m->port);
|
||||
}
|
||||
*/
|
||||
|
||||
switch(m->master_type)
|
||||
{
|
||||
case MASTER_NATIVE:
|
||||
case MASTER_GAMESPY:
|
||||
case MASTER_LAN:
|
||||
fprintf (f, "[%s %s%s:%d]\n", games[m->type].id, master_prefixes[m->master_type],
|
||||
(m->hostname)? m->hostname : inet_ntoa (m->host->ip), m->port);
|
||||
break;
|
||||
case MASTER_HTTP:
|
||||
case MASTER_FILE:
|
||||
fprintf (f, "[%s %s]\n", games[m->type].id, m->url);
|
||||
break;
|
||||
case MASTER_NUM_QUERY_TYPES:
|
||||
case MASTER_INVALID_TYPE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (srv = m->servers; srv; srv = srv->next) {
|
||||
@ -333,33 +354,34 @@ static struct master *find_master_url (char *url) {
|
||||
static struct master *read_list_parse_master (char *str, char *str2) {
|
||||
char *addr;
|
||||
unsigned short port;
|
||||
struct master *m;
|
||||
struct master *m = NULL;
|
||||
enum master_query_type query_type;
|
||||
|
||||
if (favorites && !g_strcasecmp (str, favorites->name))
|
||||
return favorites;
|
||||
|
||||
if (g_strncasecmp (str, master_prefixes[MASTER_NATIVE], strlen(master_prefixes[MASTER_NATIVE])) == 0) {
|
||||
if (parse_address (str + strlen(master_prefixes[MASTER_NATIVE]), &addr, &port)) {
|
||||
m = find_master_server (addr, port, str2);
|
||||
g_free (addr);
|
||||
return m;
|
||||
}
|
||||
query_type = get_master_query_type_from_address(str);
|
||||
|
||||
switch(query_type)
|
||||
{
|
||||
case MASTER_NATIVE:
|
||||
case MASTER_GAMESPY:
|
||||
case MASTER_LAN:
|
||||
if (parse_address (str + strlen(master_prefixes[query_type]), &addr, &port))
|
||||
{
|
||||
m = find_master_server (addr, port, str2);
|
||||
g_free (addr);
|
||||
}
|
||||
break;
|
||||
case MASTER_HTTP:
|
||||
case MASTER_FILE:
|
||||
m = find_master_url (str);
|
||||
break;
|
||||
case MASTER_NUM_QUERY_TYPES:
|
||||
case MASTER_INVALID_TYPE:
|
||||
}
|
||||
|
||||
if (g_strncasecmp (str, master_prefixes[MASTER_GAMESPY], strlen (master_prefixes[MASTER_GAMESPY])) == 0) {
|
||||
if (parse_address (str + strlen(master_prefixes[MASTER_GAMESPY]), &addr, &port)) {
|
||||
m = find_master_server (addr, port, str2);
|
||||
g_free (addr);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_strncasecmp (str, master_prefixes[MASTER_HTTP], strlen(master_prefixes[MASTER_HTTP])) == 0) {
|
||||
m = find_master_url (str);
|
||||
return m;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@ -613,46 +635,54 @@ struct master *add_master (char *path, char *name, enum server_type type,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( query_type == MASTER_NATIVE || query_type == MASTER_GAMESPY || query_type == MASTER_LAN)
|
||||
switch(query_type)
|
||||
{
|
||||
// check for valid hostname/ip
|
||||
if (parse_address (path + strlen(master_prefixes[query_type]), &addr, &port))
|
||||
{
|
||||
// if no port was specified, add default master port if available or fail
|
||||
if (!port)
|
||||
case MASTER_NATIVE:
|
||||
case MASTER_GAMESPY:
|
||||
case MASTER_LAN:
|
||||
// check for valid hostname/ip
|
||||
if (parse_address (path + strlen(master_prefixes[query_type]), &addr, &port))
|
||||
{
|
||||
// use default_port instead of default_master_port for lan broadcasts
|
||||
if( query_type == MASTER_LAN )
|
||||
// if no port was specified, add default master port if available or fail
|
||||
if (!port)
|
||||
{
|
||||
port = games[type].default_port;
|
||||
// unreal needs one port higher
|
||||
if(!strcmp(games[type].qstat_option,"-uns"))
|
||||
// use default_port instead of default_master_port for lan broadcasts
|
||||
if( query_type == MASTER_LAN )
|
||||
{
|
||||
port++;
|
||||
type=GPS_SERVER;
|
||||
port = games[type].default_port;
|
||||
// unreal needs one port higher
|
||||
if(!strcmp(games[type].qstat_option,"-uns"))
|
||||
{
|
||||
port++;
|
||||
type=GPS_SERVER;
|
||||
}
|
||||
}
|
||||
// do not use default for gamespy
|
||||
else if (query_type != MASTER_GAMESPY && games[type].default_master_port)
|
||||
{
|
||||
port = games[type].default_master_port;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (addr);
|
||||
// translator: %s == url, eg gmaster://bla.blub.org
|
||||
dialog_ok (NULL, _("You have to specify a port number for %s."),path);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
// do not use default for gamespy
|
||||
else if (query_type != MASTER_GAMESPY && games[type].default_master_port)
|
||||
{
|
||||
port = games[type].default_master_port;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (addr);
|
||||
// translator: %s == url, eg gmaster://bla.blub.org
|
||||
dialog_ok (NULL, _("You have to specify a port number for %s."),path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m = find_master_server (addr, port, games[type].id);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
m = find_master_server (addr, port, games[type].id);
|
||||
|
||||
}
|
||||
}
|
||||
else if( query_type == MASTER_HTTP )
|
||||
{
|
||||
case MASTER_HTTP:
|
||||
case MASTER_FILE:
|
||||
m = find_master_url (path);
|
||||
break;
|
||||
case MASTER_NUM_QUERY_TYPES:
|
||||
case MASTER_INVALID_TYPE:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (lookup_only)
|
||||
@ -681,28 +711,34 @@ struct master *add_master (char *path, char *name, enum server_type type,
|
||||
}
|
||||
|
||||
// master was not known already, create new
|
||||
if( query_type == MASTER_NATIVE || query_type == MASTER_GAMESPY || query_type == MASTER_LAN)
|
||||
switch(query_type)
|
||||
{
|
||||
m = create_master (name, type, FALSE);
|
||||
case MASTER_NATIVE:
|
||||
case MASTER_GAMESPY:
|
||||
case MASTER_LAN:
|
||||
m = create_master (name, type, FALSE);
|
||||
|
||||
h = host_add (addr);
|
||||
if (h) {
|
||||
m->host = h;
|
||||
host_ref (h);
|
||||
g_free (addr);
|
||||
addr = NULL;
|
||||
}
|
||||
else {
|
||||
m->hostname = addr;
|
||||
}
|
||||
m->port = port;
|
||||
h = host_add (addr);
|
||||
if (h) {
|
||||
m->host = h;
|
||||
host_ref (h);
|
||||
g_free (addr);
|
||||
addr = NULL;
|
||||
}
|
||||
else {
|
||||
m->hostname = addr;
|
||||
}
|
||||
m->port = port;
|
||||
break;
|
||||
case MASTER_HTTP:
|
||||
case MASTER_FILE:
|
||||
m = create_master (name, type, FALSE);
|
||||
m->url = g_strdup (path);
|
||||
break;
|
||||
case MASTER_NUM_QUERY_TYPES:
|
||||
case MASTER_INVALID_TYPE:
|
||||
return NULL;
|
||||
}
|
||||
else if( query_type == MASTER_HTTP )
|
||||
{
|
||||
m = create_master (name, type, FALSE);
|
||||
m->url = g_strdup (path);
|
||||
}
|
||||
else return NULL;
|
||||
|
||||
m->master_type = query_type;
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "stat.h"
|
||||
#include "utils.h"
|
||||
#include "server.h"
|
||||
#include "source.h"
|
||||
#include "filter.h"
|
||||
#include "dialogs.h"
|
||||
#include "host.h"
|
||||
@ -650,6 +651,49 @@ static void set_nonblock (int fd) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
return connection to local file
|
||||
*/
|
||||
static struct stat_conn *new_file_conn (struct stat_job *job, const char* file,
|
||||
GdkInputFunction input_callback, struct master *m)
|
||||
{
|
||||
struct stat_conn *conn;
|
||||
int fd = -1;
|
||||
|
||||
fd = open(file,O_RDONLY);
|
||||
if(fd == -1)
|
||||
{
|
||||
perror(__FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conn = g_malloc (sizeof (struct stat_conn));
|
||||
if(!conn)
|
||||
return NULL;
|
||||
|
||||
conn->buf = g_malloc (BUFFER_MINSIZE);
|
||||
conn->bufsize = BUFFER_MINSIZE;
|
||||
conn->tmpfile = NULL;
|
||||
conn->pid = 0;
|
||||
conn->fd = fd;
|
||||
conn->pos = 0;
|
||||
conn->lastnl = 0;
|
||||
|
||||
conn->strings = NULL;
|
||||
conn->servers = NULL;
|
||||
conn->uservers = NULL;
|
||||
|
||||
conn->master = m;
|
||||
|
||||
conn->job = job;
|
||||
job->cons = g_slist_prepend (job->cons, conn);
|
||||
|
||||
conn->tag = gdk_input_add (conn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
|
||||
(GdkInputFunction) input_callback, conn);
|
||||
conn->input_callback = (GdkInputFunction) input_callback;
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
/*
|
||||
start_qstat -- Fork and run qstat with the given command line
|
||||
@ -757,6 +801,9 @@ static struct stat_conn *stat_update_master_qstat (struct stat_job *job,
|
||||
char buf_rawarg[] = { QSTAT_DELIM, '\0' };
|
||||
struct stat_conn *conn;
|
||||
char *cmd = NULL;
|
||||
char *file = NULL;
|
||||
|
||||
short startprog = 1;
|
||||
|
||||
debug (3, "stat_update_master_qstat(%p,%p)", job, m);
|
||||
if (!m)
|
||||
@ -764,15 +811,22 @@ static struct stat_conn *stat_update_master_qstat (struct stat_job *job,
|
||||
|
||||
if (m->url) {
|
||||
|
||||
cmd = strdup_strip (HTTP_HELPER);
|
||||
if(!strncmp(m->url,master_prefixes[MASTER_FILE],strlen(master_prefixes[MASTER_FILE])))
|
||||
{
|
||||
startprog = 0;
|
||||
file=strdup_strip(m->url + strlen(master_prefixes[MASTER_FILE]));
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = strdup_strip (HTTP_HELPER);
|
||||
|
||||
argv[argi++] = strtok (cmd, delim);
|
||||
while ((argv[argi] = strtok (NULL, delim)) != NULL)
|
||||
argi++;
|
||||
|
||||
argv[argi++] = m->url;
|
||||
argv[argi] = NULL;
|
||||
argv[argi++] = strtok (cmd, delim);
|
||||
while ((argv[argi] = strtok (NULL, delim)) != NULL)
|
||||
argi++;
|
||||
|
||||
argv[argi++] = m->url;
|
||||
argv[argi] = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@ -821,17 +875,26 @@ static struct stat_conn *stat_update_master_qstat (struct stat_job *job,
|
||||
|
||||
} /* if (m->url) */
|
||||
|
||||
if (get_debug_level() > 3){
|
||||
char **argptr = argv;
|
||||
fprintf (stderr, "stat_update_master_qstat: EXEC> ");
|
||||
while (*argptr)
|
||||
fprintf (stderr, "%s ", *argptr++);
|
||||
fprintf (stderr, "\n");
|
||||
if(startprog)
|
||||
{
|
||||
if (get_debug_level() > 3){
|
||||
char **argptr = argv;
|
||||
fprintf (stderr, "stat_update_master_qstat: EXEC> ");
|
||||
while (*argptr)
|
||||
fprintf (stderr, "%s ", *argptr++);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
conn = start_qstat (job, argv,
|
||||
(GdkInputFunction) stat_master_input_callback, m);
|
||||
}
|
||||
else if(file)
|
||||
{
|
||||
conn = new_file_conn (job, file, (GdkInputFunction) stat_master_input_callback, m);
|
||||
g_free (file);
|
||||
}
|
||||
|
||||
|
||||
conn = start_qstat (job, argv,
|
||||
(GdkInputFunction) stat_master_input_callback, m);
|
||||
if (cmd)
|
||||
g_free (cmd);
|
||||
|
||||
|
@ -127,6 +127,7 @@ enum master_query_type {
|
||||
MASTER_GAMESPY,
|
||||
MASTER_HTTP,
|
||||
MASTER_LAN,
|
||||
MASTER_FILE,
|
||||
MASTER_NUM_QUERY_TYPES,
|
||||
MASTER_INVALID_TYPE
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user