Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 692 lines (569 sloc) 18.594 kb
9c679c2 @johnnycz add gnu/gpl preamble to files where it was missing
johnnycz authored
1 /*
2 Copyright (C) 2011 azazello and ezQuake team
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
19 #include "quakedef.h"
20 #ifdef _WIN32
21 #include "winquake.h"
22 #else
23 #include <sys/time.h>
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <netdb.h>
28 #include <sys/param.h>
29 #include <sys/ioctl.h>
30 #include <sys/uio.h>
31 #include <arpa/inet.h>
32 #include <errno.h>
b0375a7 Fix a ton of gcc warnings...
oldmanuk authored
33 #include <unistd.h>
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
34 #endif
95c525c take away headers from quakedef.h
disconn3ct authored
35 #include "menu.h"
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
36 #include "EX_browser.h"
95c525c take away headers from quakedef.h
disconn3ct authored
37 #include "sbar.h"
38 #include "keys.h"
39
1cd2c78 qboolean --> qbool
disconn3ct authored
40 extern qbool useNewPing;
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
41 int oldPingHost(char *host_to_ping, int count);
42 int oldPingHosts(server_data *servs[], int servsn, int count);
67dd21b @johnnycz sb_hidehighping & sb_pinglimit - when used, filters out server with p…
johnnycz authored
43 int PingHost(char *host_to_ping, unsigned short port, int count, int time_out);
ab859c2 @biomass Changed variable types to match actual type used after seeing strange…
biomass authored
44 int PingHosts(server_data *servs[], int servsn, int count);
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
45 void TP_ExecTrigger (const char *s);
46
6e44347 @biomass Another server browser patch. Added more multiple access/update prote…
biomass authored
47 extern sem_t serverinfo_semaphore;
74857ac @biomass bugfix: Server Browser should now work without crashing, several fixe…
biomass authored
48 // To prevent several Serverinfo threads to be started at the same time
b818d88 @johnnycz sb_refresh fixes
johnnycz authored
49 static int serverinfo_lock;
6376457 @biomass moved around some code to make it less confusing (from r4195)
biomass authored
50
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
51 typedef struct infohost_s
52 {
53 double lastsenttime;
54 int phase;
55 } infohost;
56
57 int autoupdate_serverinfo = 0;
58
59 server_data *autoupdate_server;
11073a0 intelligent pinging - if possible (and if no -nosockraw is present), …
hdworak authored
60
c0b40ca Show team per player in SB, sure if sever support, u can check this o…
qqshka authored
61 static const char senddata[] = {255, 255, 255, 255, 's','t','a','t','u','s',' ','2','3','\n'};
62
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
63 int server_during_update = 0;
64
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
65 int ReadInt (char *playerinfo, int *i)
66 {
67 int s = 0, d = 0;
68 char buf[100];
69 while (playerinfo[s] == ' ')
70 s++;
71 while (playerinfo[s] != ' ' && playerinfo[s] != '\n' && s < 99)
72 buf[d++] = playerinfo[s++];
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
73
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
74 buf[d] = 0;
75 *i = atoi(buf);
76 return s;
77 }
78
c0b40ca Show team per player in SB, sure if sever support, u can check this o…
qqshka authored
79
80 int ReadString (char *playerinfo, char *str)
81 {
82 int s = 0, d = 0;
83 while (playerinfo[s] == ' ')
84 s++;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
85 if (playerinfo[s] == '\"') {
86 s++;
87 while (playerinfo[s] != '\"' && playerinfo[s] != '\n' && s < 99)
88 str[d++] = playerinfo[s++];
89 if (playerinfo[s] == '\"')
90 s++;
91 }
c0b40ca Show team per player in SB, sure if sever support, u can check this o…
qqshka authored
92
93 str[d] = 0;
94 return s;
95 }
96
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
97 char *ValueForKey(server_data *s, char *k)
98 {
99 int i;
100 for (i=0; i < s->keysn; i++)
454a749 @johnnycz patch by zxc, fixes some crashes in SB
johnnycz authored
101 if (s->keys[i] && !strcmp(k, s->keys[i]))
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
102 return s->values[i];
103
104 return NULL;
105 }
106
107 void SetPing(server_data *s, int ping)
108 {
109 if (ping < 0)
1169299 strcat --> strlcat // seems like no strcats anymore
disconn3ct authored
110 strlcpy (s->display.ping, "n/a", sizeof (s->display.ping));
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
111 else
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
112 snprintf (s->display.ping, sizeof (s->display.ping), "%3d", ping > 999 ? 999 : ping);
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
113
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
114 s->ping = ping;
b64ef78 @johnnycz sb_findroutes: make server browser look up best routes automatically;…
johnnycz authored
115
116 SB_Server_SetBestPing(s, -1);
117 }
118
119 void SB_Server_SetBestPing(server_data *s, int bestping)
120 {
121 if (bestping < 0)
122 strlcpy (s->display.bestping, "n/a", sizeof (s->display.bestping));
123 else
124 snprintf (s->display.bestping, sizeof (s->display.bestping), "%3d", bestping > 999 ? 999 : bestping);
125
126 s->bestping = bestping;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
127 }
128
579ff64 @johnnycz do full refresh also if sb_hidedead is 0 and all the servers are dead
johnnycz authored
129 qbool SB_AllServersDead()
130 {
131 int i;
132
133 for (i = 0; i < serversn; i++) {
134 if (servers[i]->ping != -1) {
135 return false;
136 }
137 }
138
139 return true;
140 }
141
35aa0ad @johnnycz mark QWfwd servers in the server browser with light-green background
johnnycz authored
142 qbool SB_IsServerQWfwd(server_data *s)
143 {
144 char *ident_match = "qwfwd";
145 size_t match_len = strlen(ident_match);
146 char *ident_value = ValueForKey(s, "*version");
147
148 if (ident_value) {
149 return strncmp(ident_value, ident_match, match_len) == 0;
150 }
151 else
152 {
153 return false;
154 }
155 }
156
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
157 void Parse_Serverinfo(server_data *s, char *info)
158 {
159 int i, j;
160 char *pinfo;
161 char *tmp;
162
163 s->passed_filters = 1;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
164 s->support_teams = false; // by default server does't support team info per player
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
165
166 if (strncmp(info, "\xFF\xFF\xFF\xFFn", 5))
167 {
168 SetPing(s, -1);
169 return;
170 }
171
172 pinfo = strchr(info, '\n');
173 if (pinfo != NULL)
174 *(pinfo++) = 0;
175
176 info += 5;
177
178 while (*info == '\\' && s->keysn < MAX_KEYS)
179 {
180 char *i2, *i3;
181 i2 = strchr(info+1, '\\');
182 if (i2 == NULL)
183 break;
184 i3 = strchr(i2+1, '\\');
185 if (i3 == NULL)
186 i3 = info + strlen(info);
187
4b374a1 malloc() --> Q_malloc()
tonik authored
188 s->keys[s->keysn] = (char *) Q_malloc(i2-info);
0b5907d getting rid of unsafe functions: strncat, strncpy, strcat, strcpy, sp…
disconn3ct authored
189 strlcpy(s->keys[s->keysn], info+1, i2-info);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
190
4b374a1 malloc() --> Q_malloc()
tonik authored
191 s->values[s->keysn] = (char *) Q_malloc(i3-i2);
0b5907d getting rid of unsafe functions: strncat, strncpy, strcat, strcpy, sp…
disconn3ct authored
192 strlcpy(s->values[s->keysn], i2+1, i3-i2);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
193
194 s->keysn++;
195
196 info = i3;
197 }
198
199 // read players
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
200
c0b40ca Show team per player in SB, sure if sever support, u can check this o…
qqshka authored
201 for (i = s->spectatorsn = s->playersn = 0; pinfo && strchr(pinfo, '\n'); i++)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
202 {
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
203 qbool spec;
d8a9ddd SB now showed "spec" in frags column for specs
qqshka authored
204 int id, frags, time, ping, slen;
c0b40ca Show team per player in SB, sure if sever support, u can check this o…
qqshka authored
205 char name[100], skin[100], team[100];
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
206 int top, bottom;
207 int pos;
208
209 if (s->playersn + s->spectatorsn >= MAX_PLAYERS)
210 break; // man
211
212 pos = 0;
213 pos += ReadInt(pinfo+pos, &id);
214 pos += ReadInt(pinfo+pos, &frags);
215 pos += ReadInt(pinfo+pos, &time);
216 pos += ReadInt(pinfo+pos, &ping);
217 pos += ReadString(pinfo+pos, name);
218 pos += ReadString(pinfo+pos, skin);
219 pos += ReadInt(pinfo+pos, &top);
220 pos += ReadInt(pinfo+pos, &bottom);
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
221 pos += ReadString(pinfo+pos, team);
d8a9ddd SB now showed "spec" in frags column for specs
qqshka authored
222
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
223 if (team[0])
224 s->support_teams = true; // seems server support team info per player
7f3b3d8 bug fix: spectators may affect SB so line " score xxx yyy" disapearin…
qqshka authored
225
d8a9ddd SB now showed "spec" in frags column for specs
qqshka authored
226 if (ping > 0) { // seems player if relay on ping
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
227 spec = false;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
228 s->playersn++;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
229 }
d8a9ddd SB now showed "spec" in frags column for specs
qqshka authored
230 else // spec
c0b40ca Show team per player in SB, sure if sever support, u can check this o…
qqshka authored
231 {
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
232 spec = true;
233 slen = strlen(name);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
234 s->spectatorsn++;
235 ping = -ping;
d8a9ddd SB now showed "spec" in frags column for specs
qqshka authored
236
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
237 if (name[0] == '\\' && name[1] == 's' && name[2] == '\\')
238 strlcpy(name, name+3, sizeof(name)); // strip \s\<name>
239 if (slen > 3 && name[slen-3] == '(' && name[slen-2] == 's' && name[slen-1] == ')')
240 name[slen-3] = 0; // strip <name>(s) for old servers
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
241 }
242
4b374a1 malloc() --> Q_malloc()
tonik authored
243 s->players[i] = (playerinfo *)Q_malloc(sizeof(playerinfo));
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
244 s->players[i]->id = id;
245 s->players[i]->frags = frags;
246 s->players[i]->time = time;
247 s->players[i]->ping = ping;
d8a9ddd SB now showed "spec" in frags column for specs
qqshka authored
248 s->players[i]->spec = spec;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
249
250 s->players[i]->top = Sbar_ColorForMap(top);
251 s->players[i]->bottom = Sbar_ColorForMap(bottom);
252
d8a9ddd SB now showed "spec" in frags column for specs
qqshka authored
253 strlcpy(s->players[i]->name, name, sizeof(s->players[0]->name));
254 strlcpy(s->players[i]->skin, skin, sizeof(s->players[0]->skin));
255 strlcpy(s->players[i]->team, team, sizeof(s->players[0]->team));
c0b40ca Show team per player in SB, sure if sever support, u can check this o…
qqshka authored
256
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
257 pinfo = strchr(pinfo, '\n') + 1;
258 }
259
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
260 {
261 void *swap;
262 int n;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
263 // sort players by frags
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
264 n = s->playersn + s->spectatorsn - 2;
265 for (i = 0; i <= n; i++)
266 for (j = n; j >= i; j--)
2499d7d @johnnycz bugfix: yet another crash in serverbrowser removed
johnnycz authored
267 if (s->players[j] && s->players[j+1] && s->players[j]->frags < s->players[j+1]->frags)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
268 {
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
269 swap = (void*)s->players[j];
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
270 s->players[j] = s->players[j+1];
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
271 s->players[j+1] = (playerinfo*)swap;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
272 }
273 // sort keys
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
274 n = s->keysn - 2;
275 for (i = 0; i <= n; i++)
276 for (j = n; j >= i; j--)
bc431aa Z dead baby, Z dead =:-)
disconn3ct authored
277 if (strcasecmp(s->keys[j], s->keys[j+1]) > 0)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
278 {
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
279 swap = (void*)s->keys[j];
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
280 s->keys[j] = s->keys[j+1];
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
281 s->keys[j+1] = (char*)swap;
282 swap = (void*)s->values[j];
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
283 s->values[j] = s->values[j+1];
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
284 s->values[j+1] = (char*)swap;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
285 }
4111ef5 Bugfix: #1030146 shows players wrong in sb :E (incorrect sorting)
vvd0 authored
286 }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
287
288 // fill-in display
35aa0ad @johnnycz mark QWfwd servers in the server browser with light-green background
johnnycz authored
289 s->qwfwd = SB_IsServerQWfwd(s);
290
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
291 tmp = ValueForKey(s, "hostname");
292 if (tmp != NULL)
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
293 snprintf (s->display.name, sizeof (s->display.name),"%-.*s", COL_NAME, tmp);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
294 else
295 return;
296
297 tmp = ValueForKey(s, "fraglimit");
298 if (tmp != NULL)
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
299 snprintf(s->display.fraglimit, sizeof (s->display.fraglimit), "%*.*s", COL_FRAGLIMIT, COL_FRAGLIMIT, strlen(tmp) > COL_FRAGLIMIT ? "999" : tmp);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
300
301 tmp = ValueForKey(s, "timelimit");
302 if (tmp != NULL)
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
303 snprintf(s->display.timelimit, sizeof (s->display.timelimit), "%*.*s", COL_TIMELIMIT, COL_TIMELIMIT, strlen(tmp) > COL_TIMELIMIT ? "99" : tmp);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
304
305 tmp = ValueForKey(s, "*gamedir");
ddc4e6c @johnnycz server browser: colored background for even/odd/qizmo servers, inspir…
johnnycz authored
306 s->qizmo = false;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
307 if (tmp != NULL)
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
308 snprintf(s->display.gamedir, sizeof (s->display.gamedir) ,"%.*s", COL_GAMEDIR, tmp==NULL ? "" : tmp);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
309 else
310 {
311 tmp = ValueForKey(s, "*progs");
312 if (tmp != NULL && !strcmp(tmp, "666"))
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
313 {
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
314 snprintf(s->display.gamedir, sizeof (s->display.gamedir), "qizmo");
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
315 s->qizmo = true;
316 }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
317 }
318
319 tmp = ValueForKey(s, "map");
320 if (tmp != NULL)
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
321 snprintf(s->display.map, sizeof (s->display.map), "%-.*s", COL_MAP, tmp==NULL ? "" : tmp);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
322
323 tmp = ValueForKey(s, "maxclients");
ad18d81 @johnnycz bugfix: don't crash if ValueForKey(s, "maxclients") returns null, ins…
johnnycz authored
324 if (!tmp || strlen(tmp) > 2)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
325 tmp = "99";
326 i = s->playersn > 99 ? 99 : s->playersn;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
327 if (i < 1) { s->occupancy = SERVER_EMPTY; }
328 else if (i > 0 && i < atoi(tmp)) { s->occupancy = SERVER_NONEMPTY; }
329 else { s->occupancy = SERVER_FULL; }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
330 if (tmp != NULL)
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
331 snprintf(s->display.players, sizeof (s->display.players), "%2d/%-2s", i, tmp==NULL ? "" : tmp);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
332 }
333
334 void GetServerInfo(server_data *serv)
335 {
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
336 socket_t newsocket;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
337 struct sockaddr_storage server;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
338 int ret;
339 char answer[5000];
340 fd_set fd;
341 struct timeval tv;
342
343 // so we have a socket
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
344 newsocket = UDP_OpenSocket(PORT_ANY);
345 NetadrToSockadr (&(serv->address), &server);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
346
347 // send status request
348 ret = sendto (newsocket, senddata, sizeof(senddata), 0,
349 (struct sockaddr *)&server, sizeof(server) );
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
350
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
351 if (ret == -1)
352 return;
353
354 //fd.fd_count = 1;
355 //fd.fd_array[0] = newsocket;
356 FD_ZERO(&fd);
357 FD_SET(newsocket, &fd);
358 tv.tv_sec = 0;
359 tv.tv_usec = 1000 * 1.5 * sb_infotimeout.value; // multiply timeout by 1.5
360 ret = select(newsocket+1, &fd, NULL, NULL, &tv);
361
362 // get answer
363 if (ret > 0)
364 ret = recvfrom (newsocket, answer, 5000, 0, NULL, NULL);
365
366 if (ret > 0 && ret < 5000)
367 {
368 answer[ret] = 0;
369 server_during_update = 1;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
370 Reset_Server(serv);
371 Parse_Serverinfo(serv, answer);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
372 server_during_update = 0;
373 }
374 closesocket(newsocket);
375 }
376
377 //
378 // Gets multiple server info simultaneously
379 //
380
381 DWORD WINAPI GetServerInfosProc(void * lpParameter)
382 {
383 infohost *hosts; // 0 if not sent yet, -1 if data read
384 double interval, lastsenttime;
385
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
386 socket_t newsocket;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
387 struct sockaddr_storage dest;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
388 int ret, i;
389 fd_set fd;
390 struct timeval timeout;
391
392 if (abort_ping)
393 return 0;
394
395 // so we have a socket
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
396 newsocket = UDP_OpenSocket(PORT_ANY);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
397
4b374a1 malloc() --> Q_malloc()
tonik authored
398 hosts = (infohost *) Q_malloc (serversn * sizeof(infohost));
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
399 for (i=0; i < serversn; i++)
400 {
401 hosts[i].phase = 0;
402 hosts[i].lastsenttime = -1000;
403 Reset_Server(servers[i]);
404
405 // do not update dead servers
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
406 if (servers[i]->ping < 0) {
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
407 hosts[i].phase = -1;//(int)sb_inforetries.value;
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
408 }
409 // do not update too distant servers
410 else if (sb_hidehighping.integer && servers[i]->ping > sb_pinglimit.integer) {
411 hosts[i].phase = -1;
412 }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
413 }
414
415 interval = (1000.0 / sb_infospersec.value) / 1000;
416 lastsenttime = Sys_DoubleTime() - interval;
417 timeout.tv_sec = 0;
418 timeout.tv_usec = (long)(interval * 1000.0 * 1000.0 / 2);
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
419
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
420 ping_pos = 0;
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
421
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
422 while (1 && !abort_ping)
423 {
424 int index = -1;
425 double time = Sys_DoubleTime();
426
427 // if it is time to send next request
428 if (time > lastsenttime + interval)
429 {
430 int finished = 0;
431 int to_ask = 0;
432 int phase = (int)(sb_inforetries.value);
433
434 // find next server to ask
435 for (i=0; i < serversn; i++)
436 {
437 if (hosts[i].phase < phase && hosts[i].phase >= 0 &&
438 time > hosts[i].lastsenttime + (sb_infotimeout.value / 1000))
439 {
440 index = i;
441 phase = hosts[i].phase;
442 }
443
444 if (hosts[i].phase >= (int)sb_inforetries.value)
445 finished++;
446 else
447 if (hosts[i].phase >= 0)
448 to_ask++;
449 }
450 //ping_pos = finished / (double)serversn;
451 ping_pos = (finished+to_ask <= 0) ? 0 :
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
452 finished / (double)(finished+to_ask);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
453 }
454
455 // check if we should finish
456 if (index < 0)
457 if (time > lastsenttime + 1.2 * (sb_infotimeout.value / 1000))
458 break;
459
460 // send status request
461 if (index >= 0)
462 {
463 hosts[index].phase ++;
464 hosts[index].lastsenttime = time;
465 lastsenttime = time;
466
467 NetadrToSockadr (&(servers[index]->address), &dest);
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
468
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
469 ret = sendto (newsocket, senddata, sizeof(senddata), 0,
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
470 (struct sockaddr *)&dest, sizeof(*(struct sockaddr *)&dest));
471 if(ret < 0)
472 {
473 Com_DPrintf("sendto() gave errno = %d : %s\n", errno, strerror(errno));
474 }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
475 if (ret == -1)
476 ;//return;
477
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
478 // requests_sent++;
479 // ping_pos = requests_total <= 0 ? 0 : requests_sent / (double)requests_total;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
480 }
481
482 // check if answer arrived and decode it
483 //fd.fd_count = 1;
484 //fd.fd_array[0] = newsocket;
485 FD_ZERO(&fd);
486 FD_SET(newsocket, &fd);
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
487
488 ret = select(newsocket+1, &fd, NULL, NULL, &timeout);
489 if (ret < 1)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
490 {
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
491 Com_DPrintf("select() gave errno = %d : %s\n", errno, strerror(errno));
492 }
493
494 if (FD_ISSET(newsocket, &fd))
495 {
496 struct sockaddr_storage hostaddr;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
497 netadr_t from;
498 int i;
499 char answer[5000];
500 answer[0] = 0;
501
502 i = sizeof(hostaddr);
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
503 ret = recvfrom (newsocket, answer, 5000, 0, (struct sockaddr *)&hostaddr, (socklen_t *)&i);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
504 answer[max(0, min(ret, 4999))] = 0;
505
506 if (ret > 0)
507 {
508 SockadrToNetadr (&hostaddr, &from);
509
510 for (i=0; i < serversn; i++)
511 if (from.ip[0] == servers[i]->address.ip[0] &&
512 from.ip[1] == servers[i]->address.ip[1] &&
513 from.ip[2] == servers[i]->address.ip[2] &&
514 from.ip[3] == servers[i]->address.ip[3] &&
515 from.port == servers[i]->address.port)
516 {
517 hosts[i].phase = (int)sb_inforetries.value;
518 Parse_Serverinfo(servers[i], answer);
519 break;
520 }
521 }
522 }
523 }
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
524
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
525 // reset pings to 999 if server didn't answer
526 for (i=0; i < serversn; i++)
527 if (servers[i]->keysn <= 0)
528 SetPing(servers[i], -1);
529
530 closesocket(newsocket);
3337b7b experimental changes to server browser, fixes mac, works on linux but…
oldmanuk authored
531 Q_free(hosts);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
532
533 return 0;
534 }
535
536 void GetServerPing(server_data *serv)
537 {
538 int p;
2bbb546 getting rid of sprintf && rounding buffers to power of two
disconn3ct authored
539 char buf[32];
540 snprintf (buf, sizeof (buf), "%d.%d.%d.%d",
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
541 serv->address.ip[0],
542 serv->address.ip[1],
543 serv->address.ip[2],
544 serv->address.ip[3]);
545
25c1fa0 @johnnycz comment & cleanup & oldPingHost() declaration was wrong
johnnycz authored
546 p = useNewPing
547 // new ping = UPD QW Packet
548 ? PingHost(buf, serv->address.port, (int)max(1, min(sb_pings.value, 10)), sb_pingtimeout.value)
549 // old ping = ICMP PING Packet
550 : oldPingHost(buf, (int)max(1, min(sb_pings.value, 10)));
551
552 if (p)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
553 SetPing(serv, p-1);
554 else
555 SetPing(serv, p-1);
556 }
557
558 DWORD WINAPI GetServerPingsAndInfosProc(void * lpParameter)
559 {
4a07d09 @johnnycz when refreshing and no sources are marked (happens for users with old…
johnnycz authored
560 unsigned int SB_Sources_Marked_Count(void);
0de0a83 @johnnycz added sb_listcache, when turned on, after each refresh the server lis…
johnnycz authored
561 extern cvar_t sb_listcache;
562 extern void SB_Serverlist_Serialize_f();
563
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
564 int full = (int) lpParameter;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
565 abort_ping = 0;
566
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
567 if (full || serversn_passed == 0) {
4a07d09 @johnnycz when refreshing and no sources are marked (happens for users with old…
johnnycz authored
568 if (SB_Sources_Marked_Count() == 0) {
569 // ensure some sources are marked, otherwise the refresh makes no sense
570 MarkDefaultSources();
571 }
572
6ccb485 @johnnycz when there are no servers filtered, re-query sources when updating; t…
johnnycz authored
573 SB_Sources_Update(true);
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
574 if (useNewPing) {
575 // New Ping = UPD QW Packet ping using 2 threads (sender and receiver)
9a11f85 @biomass small change forgotten in r4297 causing compiler warning
biomass authored
576 PingHosts(servers, serversn, sb_pings.integer);
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
577 }
578 else {
579 // Old Ping = ICMP PING Packet using single thread
ab859c2 @biomass Changed variable types to match actual type used after seeing strange…
biomass authored
580 oldPingHosts(servers, serversn, sb_pings.integer );
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
581 }
25c1fa0 @johnnycz comment & cleanup & oldPingHost() declaration was wrong
johnnycz authored
582 }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
583
584 if (!abort_ping)
585 {
586 ping_phase = 2;
587 GetServerInfosProc(NULL);
588 }
589
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
590 /*
591 if (abort_ping)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
592 Sys_MSleep(500); // let the packets end the road
81a9025 @johnnycz enabled warning level 4 in msvs2005 gldebug and fixed/silenced all wa…
johnnycz authored
593 */
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
594
595 resort_servers = 1;
596 rebuild_all_players = 1;
597 ping_phase = 0;
598
34f37d2 @johnnycz added command sb_refresh; added trigger f_sbrefreshdone;
johnnycz authored
599 TP_ExecTrigger("f_sbrefreshdone");
0de0a83 @johnnycz added sb_listcache, when turned on, after each refresh the server lis…
johnnycz authored
600
601 if (sb_listcache.integer) {
602 SB_Serverlist_Serialize_f();
603 }
34f37d2 @johnnycz added command sb_refresh; added trigger f_sbrefreshdone;
johnnycz authored
604
e964bd3 @johnnycz rebuild the ping tree only when necessary
johnnycz authored
605 if (sb_findroutes.integer && (full || !SB_PingTree_Built())) {
b64ef78 @johnnycz sb_findroutes: make server browser look up best routes automatically;…
johnnycz authored
606 SB_PingTree_Build();
607 }
608
74857ac @biomass bugfix: Server Browser should now work without crashing, several fixe…
biomass authored
609 serverinfo_lock = 0;
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
610 return 0;
611 }
612
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
613 void GetServerPingsAndInfos(int full)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
614 {
11e109a @johnnycz fix: make sb_refresh also wait for ping tree
johnnycz authored
615 if (serverinfo_lock || SB_PingTree_IsBuilding()) {
b818d88 @johnnycz sb_refresh fixes
johnnycz authored
616 Com_Printf("Server list refresh is still pending\n");
617 return;
618 }
74857ac @biomass bugfix: Server Browser should now work without crashing, several fixe…
biomass authored
619
620 serverinfo_lock = 1;
621
622 if (rebuild_servers_list)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
623 Rebuild_Servers_List();
624
74857ac @biomass bugfix: Server Browser should now work without crashing, several fixe…
biomass authored
625 if (rebuild_all_players && show_serverinfo == NULL)
626 Rebuild_All_Players();
627
579ff64 @johnnycz do full refresh also if sb_hidedead is 0 and all the servers are dead
johnnycz authored
628 if (serversn <= 0 || (sb_hidedead.integer == 0 && SB_AllServersDead())) {
6ccb485 @johnnycz when there are no servers filtered, re-query sources when updating; t…
johnnycz authored
629 // there's a possibility that sources hasn't been queried yet
630 // so let's do a full update, that ensures sources are updated
631 full = true;
632 }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
633
634 ping_phase = 1;
635 ping_pos = 0;
636
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
637 Sys_CreateThread (GetServerPingsAndInfosProc, (void *) full);
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
638 }
639
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
640 void GetServerPingsAndInfos_f()
641 {
b818d88 @johnnycz sb_refresh fixes
johnnycz authored
642 qbool full = true;
643 if (Cmd_Argc() > 0 && strcmp(Cmd_Argv(1), "info") == 0) {
644 full = false;
645 }
646 GetServerPingsAndInfos(full);
3172a5a @johnnycz when pings are already known, just pressing space won't start ping ph…
johnnycz authored
647 }
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
648
649 //
650 // autoupdate serverinfo
651 //
652
653 DWORD WINAPI AutoupdateProc(void * lpParameter)
654 {
655 double lastupdatetime = -1;
656
657 while (autoupdate_serverinfo)
658 {
659 double time = Sys_DoubleTime();
660
e973452 @biomass bugfix: fix for crash in server browser when the server detail window…
biomass authored
661 if ((sb_liveupdate.integer > 0) &&
662 time >= lastupdatetime + sb_liveupdate.integer &&
8eed1cf @johnnycz main menu changes: use mcharset, Multiplayer now leads directly to se…
johnnycz authored
663 key_dest == key_menu /* todo: add "on server list tab" condition here */)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
664 {
e973452 @biomass bugfix: fix for crash in server browser when the server detail window…
biomass authored
665 server_data *serv;
666
6e44347 @biomass Another server browser patch. Added more multiple access/update prote…
biomass authored
667 Sys_SemWait(&serverinfo_semaphore);
e973452 @biomass bugfix: fix for crash in server browser when the server detail window…
biomass authored
668 serv = autoupdate_server;
669 if (serv != NULL)
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
670 {
671 GetServerInfo(serv);
672 lastupdatetime = time;
673 }
6e44347 @biomass Another server browser patch. Added more multiple access/update prote…
biomass authored
674 Sys_SemPost(&serverinfo_semaphore);
e973452 @biomass bugfix: fix for crash in server browser when the server detail window…
biomass authored
675 }
c778df1 @johnnycz make autoupdate loop more sleepy (also magically fixes sluggish serve…
johnnycz authored
676
677 Sys_MSleep(1000); // we don't need nor allow updates faster than 1 second anyway
33f9914 This commit was generated by cvs2svn to compensate for changes in r7,
hexum authored
678 }
679 return 0;
680 }
681
682 void Start_Autoupdate(server_data *s)
683 {
684 autoupdate_server = s;
685 Sys_CreateThread(AutoupdateProc, (void *) s);
686 }
687
688 void Alter_Autoupdate(server_data *s)
689 {
690 autoupdate_server = s;
691 }
Something went wrong with that request. Please try again.