- patch from Jochen Baier

* icon for LAN servers
  * new GeoIP server filter GUI


git-svn-id: http://svn.code.sf.net/p/xqf/code/trunk@504 d2ac09be-c843-0410-8b1f-f8a84130e0ec
This commit is contained in:
Ludwig Nussel 2003-08-17 23:00:55 +00:00 committed by l-n
parent 44e6dd7cf8
commit 7e414f976b
8 changed files with 804 additions and 222 deletions

View File

@ -1,3 +1,8 @@
Aug 17, 2003: Ludwig Nussel <l-n@users.sourceforge.net>
- patch from Jochen Baier
* icon for LAN servers
* new GeoIP server filter GUI
Aug 14, 2003: Ludwig Nussel <l-n@users.sourceforge.net>
- detect cheating-death on halflife-servers
- set variable XQF_SERVER_ANTICHEAT before launching a game when the server

View File

@ -23,6 +23,7 @@
#include "i18n.h"
#include "debug.h"
#include "pixmaps.h"
#include "loadpixmap.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <ctype.h>
@ -30,6 +31,7 @@
#include <GeoIP.h>
const int MaxCountries = sizeof(GeoIP_country_code)/3;
static const int LAN_GeoIPid = sizeof(GeoIP_country_code)/3; // MaxCountries doesn't work in C
static GeoIP* gi;
@ -39,7 +41,7 @@ void geoip_init(void)
{
gi = GeoIP_new(GEOIP_STANDARD);
if(gi)
flags = g_malloc0(MaxCountries*sizeof(struct pixmap));
flags = g_malloc0((MaxCountries+1) *sizeof(struct pixmap)); /*+1-> flag for LAN server*/
else
xqf_error("GeoIP initialization failed");
}
@ -51,26 +53,98 @@ void geoip_done(void)
g_free(flags);
}
gboolean geoip_is_working (void)
{
if (gi)
return TRUE;
else
return FALSE;
}
const char* geoip_code_by_id(int id)
{
if(id < 0 || id >= MaxCountries ) return NULL;
return GeoIP_country_code[id];
if(id < 0 || id > MaxCountries ) return NULL;
/* LAN server have code ="00" */
if (id == LAN_GeoIPid)
return "00";
else
return GeoIP_country_code[id];
}
const char* geoip_name_by_id(int id)
{
if(id < 0 || id >= MaxCountries ) return NULL;
return GeoIP_country_name[id];
if(id < 0 || id > MaxCountries) return NULL;
if (id == LAN_GeoIPid)
return "LAN";
else
return GeoIP_country_name[id];
}
/*Checks for RFC1918 private addresses; returns TRUE if is a private address. */
/*from the napshare source*/
static gboolean is_private_ip(guint32 ip)
{
/* 10.0.0.0 -- (10/8 prefix) */
if ((ip & 0xff000000) == 0xa000000)
{
return TRUE;
}
/* 172.16.0.0 -- (172.16/12 prefix) */
if ((ip & 0xfff00000) == 0xac100000)
{
return TRUE;
}
/* 192.168.0.0 -- (192.168/16 prefix) */
if ((ip & 0xffff0000) == 0xc0a80000)
{
return TRUE;
}
return FALSE;
}
int geoip_id_by_ip(struct in_addr in)
{
if(!gi) return -1;
return GeoIP_country_id_by_addr(gi, inet_ntoa (in));
if(!gi) return -1;
/*check if the server is inside a LAN*/
if (is_private_ip(htonl(in.s_addr)))
return LAN_GeoIPid;
else
return GeoIP_country_id_by_addr(gi, inet_ntoa (in));
}
int geoip_id_by_code(const char *country)
{
int i;
if(!gi) return -1;
if (strcmp(country,"00")==0)
return LAN_GeoIPid;
for (i=1;i<MaxCountries;++i)
{
if (strcmp(country,GeoIP_country_code[i])==0)
return i;
}
return 0;
}
#warning enter KDE path
static char kdeflagpath[]="/opt/kde3/share/locale/l10n/%2s/flag.png";;
static char kdeflagpath[]="/opt/kde3/share/locale/l10n/%2s/flag.png";
struct pixmap* get_pixmap_for_country(int id)
{
@ -95,14 +169,18 @@ struct pixmap* get_pixmap_for_country(int id)
code = g_strdup(code);
g_strdown(code);
filename = g_strdup_printf(kdeflagpath,code);
if(id==LAN_GeoIPid)
filename = find_pixmap_directory("lan.png");
else
filename = g_strdup_printf(kdeflagpath,code);
if(!filename)
{
g_free(code);
return NULL;
}
debug(0,"loading %s",filename);
debug(4,"loading %s",filename);
pixbuf = gdk_pixbuf_new_from_file(filename);
if (pixbuf == NULL)

View File

@ -37,9 +37,16 @@ const char* geoip_name_by_id(int id);
/** return id for an ip address */
int geoip_id_by_ip(struct in_addr in);
/** return id by country code **/
int geoip_id_by_code(const char *country);
/** return TRUE if geoip init was successful */
gboolean geoip_is_working (void);
struct pixmap* get_pixmap_for_country(int id);
#endif
#endif /*__COUNTRY_FILTER_H__*/

File diff suppressed because it is too large Load Diff

View File

@ -79,6 +79,22 @@ add_pixmap_directory (const gchar *directory)
g_strdup (directory));
}
gchar* find_pixmap_directory(const gchar* filename)
{
const gchar* found_filename = NULL;
GList *elem;
elem = pixmaps_directories;
while (elem)
{
found_filename = check_file_exists ((gchar*)elem->data, filename);
if (found_filename)
break;
elem = elem->next;
}
return found_filename;
}
/* This is an internally used function to create pixmaps. */
GtkWidget*
load_pixmap (GtkWidget *widget,
@ -89,26 +105,19 @@ load_pixmap (GtkWidget *widget,
GdkPixmap *gdkpixmap;
GdkBitmap *mask;
GtkWidget *pixmap;
GList *elem;
if (!filename || !filename[0])
return create_dummy_pixmap (widget);
/* We first try any pixmaps directories set by the application. */
elem = pixmaps_directories;
while (elem)
{
found_filename = check_file_exists ((gchar*)elem->data, filename);
if (found_filename)
break;
elem = elem->next;
}
found_filename = find_pixmap_directory(filename);
#if 0 //crap...
/* If we haven't found the pixmap, try the source directory. */
if (!found_filename)
{
found_filename = check_file_exists ("src/xpm", filename);
}
#endif
if (!found_filename)
{

View File

@ -23,6 +23,11 @@
/* Use this function to set the directory containing installed pixmaps. */
void add_pixmap_directory (const gchar* directory);
/* search a pixmap in the paths added by add_pixmap_directory()
* must free returned path manually
* returns NULL if file was not found
*/
gchar* find_pixmap_directory(const gchar* filename);
/*
* Private Functions.

View File

@ -1,4 +1,4 @@
EXTRA_DIST=$(wildcard *.xpm) $(pixmaps_DATA)
pixmapsdir = $(pkgdatadir)/pixmaps
pixmaps_DATA = xqflogo.png
pixmaps_DATA = $(wildcard *.png)

BIN
xqf/src/xpm/lan.png Normal file

Binary file not shown.