-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoip.patch
209 lines (185 loc) · 5.09 KB
/
geoip.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
diff -r 1c674b2e1981 Makefile
--- a/Makefile Sun Nov 22 15:22:55 2009 +0000
+++ b/Makefile Sat Dec 18 19:57:19 2010 -0300
@@ -143,6 +143,10 @@
USE_INTERNAL_ZLIB=1
endif
+ifndef USE_GEOIP
+ USE_GEOIP=1
+endif
+
ifndef USE_LOCAL_HEADERS
USE_LOCAL_HEADERS=1
endif
@@ -199,6 +203,7 @@
PDCDIR=$(MOUNT_DIR)/pdcurses
LIBSDIR=$(MOUNT_DIR)/libs
MASTERDIR=$(MOUNT_DIR)/master
+GEOIPDIR=$(MOUNT_DIR)/GeoIP
TEMPDIR=/tmp
bin_path=$(shell which $(1) 2> /dev/null)
@@ -1116,6 +1121,10 @@
LDFLAGS += -lz
endif
+ifeq ($(USE_GEOIP),1)
+ BASE_CFLAGS += -DUSEGEOIP
+endif
+
ifdef DEFAULT_BASEDIR
BASE_CFLAGS += -DDEFAULT_BASEDIR=\\\"$(DEFAULT_BASEDIR)\\\"
endif
@@ -1644,6 +1653,10 @@
$(B)/client/zutil.o
endif
+ifeq ($(USE_GEOIP),1)
+ Q3OBJ += $(B)/client/GeoIP.o
+endif
+
ifeq ($(USE_CURSES),1)
Q3OBJ_ += $(B)/client/con_curses.o
endif
@@ -1834,6 +1847,10 @@
endif
endif
+ifeq ($(USE_GEOIP),1)
+ Q3DOBJ += $(B)/ded/GeoIP.o
+endif
+
ifeq ($(PLATFORM),mingw32)
Q3DOBJ += \
$(B)/ded/win_resource.o \
@@ -1928,6 +1945,9 @@
$(B)/client/%.o: $(NDIR)/%.c
$(DO_CC)
+$(B)/client/%.o: $(GEOIPDIR)/%.c
+ $(DO_CC)
+
$(B)/clienttty/%.o: $(ASMDIR)/%.s
$(DO_AS)
@@ -1978,6 +1998,9 @@
$(B)/ded/%.o: $(NDIR)/%.c
$(DO_DED_CC)
+$(B)/ded/%.o: $(GEOIPDIR)/%.c
+ $(DO_DED_CC)
+
# Extra dependencies to ensure the SVN version is incorporated
ifeq ($(USE_SVN),1)
$(B)/client/cl_console.o : .svn/entries
diff -r 1c674b2e1981 src/game/g_public.h
--- a/src/game/g_public.h Sun Nov 22 15:22:55 2009 +0000
+++ b/src/game/g_public.h Sat Dec 18 19:57:19 2010 -0300
@@ -221,6 +221,7 @@
G_PARSE_SOURCE_FILE_AND_LINE,
G_SEND_GAMESTAT,
+ G_GEOIP_GETCOUNTRYNAME,
G_DEMO_COMMAND
} gameImport_t;
diff -r 1c674b2e1981 src/server/server.h
--- a/src/server/server.h Sun Nov 22 15:22:55 2009 +0000
+++ b/src/server/server.h Sat Dec 18 19:57:19 2010 -0300
@@ -26,6 +26,7 @@
#include "../qcommon/qcommon.h"
#include "../game/g_public.h"
#include "../game/bg_public.h"
+#include "../GeoIP/GeoIP.h"
//=============================================================================
@@ -92,6 +93,8 @@
demoState_t demoState;
char demoName[MAX_QPATH];
+ GeoIP* geoipDatabase;
+
// previous frame for delta compression
sharedEntity_t demoEntities[MAX_GENTITIES];
playerState_t demoPlayerStates[MAX_CLIENTS];
@@ -279,6 +282,7 @@
extern cvar_t *sv_autoDemo;
extern cvar_t *sv_pure;
extern cvar_t *sv_downloadRate;
+extern cvar_t *sv_GeoIPDatabase;
#ifdef USE_VOIP
extern cvar_t *sv_voip;
diff -r 1c674b2e1981 src/server/sv_game.c
--- a/src/server/sv_game.c Sun Nov 22 15:22:55 2009 +0000
+++ b/src/server/sv_game.c Sat Dec 18 19:57:19 2010 -0300
@@ -287,6 +287,32 @@
*cmd = svs.clients[clientNum].lastUsercmd;
}
+/*
+===============
+SV_GeoIP_GetCountryName
+
+===============
+*/
+int SV_GeoIP_GetCountryName( const char* ip, char* dest )
+{
+ const char* buf;
+
+ if( !sv_GeoIPDatabase->string[ 0 ] )
+ return 0;
+
+ if( sv.geoipDatabase == NULL )
+ return 0;
+
+ buf = GeoIP_country_name_by_addr( sv.geoipDatabase, ip );
+
+ if( buf == NULL )
+ return 0;
+
+ strcpy( dest, buf );
+
+ return 1;
+}
+
//==============================================
static int FloatAsInt( float f ) {
@@ -453,13 +479,16 @@
SV_MasterGameStat( VMA(1) );
return 0;
+ case G_GEOIP_GETCOUNTRYNAME:
+ return SV_GeoIP_GetCountryName( VMA(1), VMA(2) );
+
case G_DEMO_COMMAND:
if ( sv.demoState == DS_RECORDING )
{
@@ -594,6 +623,13 @@
Com_Error( ERR_FATAL, "VM_Create on game failed" );
}
+ //Open the GeoIP database
+ sv.geoipDatabase = GeoIP_open( sv_GeoIPDatabase->string, GEOIP_STANDARD );
+ if( sv.geoipDatabase == NULL )
+ Com_Printf( "WARNING: GeoIP database %s does not exists!\n", sv_GeoIPDatabase->string );
+ else
+ Com_Printf( "Using GeoIP database %s\n", sv_GeoIPDatabase->string );
+
SV_InitGameVM( qfalse );
}
diff -r 1c674b2e1981 src/server/sv_init.c
--- a/src/server/sv_init.c Sun Nov 22 15:22:55 2009 +0000
+++ b/src/server/sv_init.c Sat Dec 18 19:57:19 2010 -0300
@@ -645,6 +645,7 @@
sv_dequeuePeriod = Cvar_Get ("sv_dequeuePeriod", "500", CVAR_ARCHIVE );
sv_demoState = Cvar_Get ("sv_demoState", "0", CVAR_ROM );
sv_autoDemo = Cvar_Get ("sv_autoDemo", "0", CVAR_ARCHIVE );
+ sv_GeoIPDatabase = Cvar_Get( "sv_GeoIPDatabase", "GeoIP.dat", CVAR_ARCHIVE );
}
@@ -722,6 +723,12 @@
Cvar_Set( "sv_running", "0" );
Cvar_Set("ui_singlePlayerActive", "0");
+ //Close the database
+ if( sv.geoipDatabase != NULL ) {
+ Com_Printf( "Closing GeoIP database\n" );
+ GeoIP_delete( sv.geoipDatabase );
+ }
+
Com_Printf( "---------------------------\n" );
// disconnect any local clients
diff -r 1c674b2e1981 src/server/sv_main.c
--- a/src/server/sv_main.c Sun Nov 22 15:22:55 2009 +0000
+++ b/src/server/sv_main.c Sat Dec 18 19:57:19 2010 -0300
@@ -60,6 +60,7 @@
cvar_t *sv_autoDemo;
cvar_t *sv_pure;
cvar_t *sv_downloadRate;
+cvar_t *sv_GeoIPDatabase;
/*
=============================================================================