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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
package MasterWebInterface::Handler::ServInfo;
use strict;
use warnings;
use utf8;
use TUWF ':html';
use URI::Escape;
use POSIX 'strftime';
use Exporter 'import';
our @EXPORT = qw| serverError |;
TUWF::register(
qr{(.[\w]*)/([\.\w]+):(\d+)} => \&show_server,
);
################################################################################
# Display server information
# Verify if game and server (ip:hostport) exist. Display as many available
# values as possible.
# Display error pages if not found or incorrect.
################################################################################
sub show_server {
# self, gamename, "ip:port"
my ($self, $gamename, $s_addr, $s_port) = @_;
# break address apart in valid ip, port
my ($ip,$port) = $self->valid_address($s_addr, $s_port);
# display an error in case of an invalid IP or port
unless ($ip && $port) {
$self->serverError(
ip => ($ip ? 0 : 1),
port => ($port ? 0 : 1),
);
return;
}
# select server from database
my $info = $self->dbGetServerListInfo(
ip => $ip,
hostport => $port,
limit => 1,
)->[0];
# either redirect or show error when no info was found
if (!defined $info) {
# try if query port was provided instead
my $attempt = $self->dbGetServerListInfo(
ip => $ip,
port => $port,
limit => 1
)->[0];
# if it exists now, automatically redirect to this page (don't show info here)
if (defined $attempt && defined $attempt->{hostport}) {
$self->resRedirect("/$gamename/$ip:$attempt->{hostport}");
return;
}
# otherwise, it was not found in the database at all. Notify.
$self->serverError(db => 1);
return;
}
# load additional information if available
my $details = $self->dbGetServerDetails(id => $info->{id})->[0];
$info = { %$info, %$details } if $details;
#
# generate info page
#
$self->htmlHeader(title => $info->{hostname} || "Yet Another Server");
div class => "mainbox detail";
div class => "header";
h1 $info->{hostname} || "Yet Another Server";
end;
# if no detailed info was found, the server was not updated or
# the game is not supported.
if (!defined $details) {
div class => 'warning';
h2 'Detailed information missing!';
p "Additional information could not be loaded. Either the server was not updated in our database, or detailed information for this game is not yet supported. The information on this page may not be accurate!";
end;
}
#
# Map thumbnail and bot info
#
div class => "container";
div class => "thumbnail";
# find the correct thumbnail, otherwise standard 333 esrb pic
my $mapfig = "$self->{map_url}/default/333esrb.jpg";
# get prefix and mapname
my $mapname = lc $info->{mapname};
my ($pre,$post) = $mapname =~ /^(DM|CTF\-BT|BT|CTF|DOM|AS|JB|TO|SCR|MH)-(.*)/i;
my $prefix = ($pre ? uc $pre : "other");
# if map figure exists, use it
if (-e "$self->{map_dir}/$info->{gamename}/$prefix/$mapname.jpg") {
$mapfig = "$self->{map_url}/$info->{gamename}/$prefix/$mapname.jpg";
}
# if not, game default image
elsif (-e "$self->{map_dir}/default/$info->{gamename}.jpg") {
$mapfig = "$self->{map_url}/default/$info->{gamename}.jpg";
}
img src => $mapfig,
alt => $mapfig,
title => ($info->{mapname} || "Unknown");
span ($info->{maptitle} || ($info->{mapname} || "Unknown"));
end;
table class => "mapinfo";
if ($info->{maxplayers}) {
Tr;
td class => "wc1", "Players:";
td;
txt $info->{numplayers} || 0;
txt "/";
txt $info->{maxplayers} || 0;
end;
end;
}
if ($info->{botskill} && $info->{minplayers}) {
Tr;
td "Bots:";
td;
txt $info->{minplayers} || 0;
txt " ";
txt ($info->{botskill} || "Standard");
txt " bot"; txt ($info->{minplayers} == 1 ? "" : "s");
end;
end;
}
end;
end; # container
#
# Specific server entry information
#
table class => "serverinfo";
Tr;
th class => "wc1", title => "Server ID: ".$info->{id}, "Server Info";
th "";
end;
Tr;
td "Address:";
td title => $info->{port}, (($info->{ip} || $ip). ":". ($info->{hostport} || $port));
end;
if ($info->{adminname}) {
Tr;
td "Admin:";
td $info->{adminname};
end;
}
Tr;
td class => "wc1", "Contact:";
td;
if ($info->{adminemail}) {txt $info->{adminemail}} else {
i;
txt "This server has no contact information listed ";
a href => "https://ut99.org/viewtopic.php?f=33&t=6660", "[?]";
end;
}
end;
end;
Tr;
td class => "wc1", "Location:";
my ($flag, $country) = $self->countryflag($info->{country} || "");
td;
img class => "flag", src => "/flag/$flag.svg";
txt " ". $country;
end;
end;
Tr; {
td "Added:";
my @t = gmtime($info->{addiff});
my $sig = 0;
my $diff = "";
if ($t[5]-70){$diff.=$t[5]-70 ." year".(($t[5]-70==1)?"":"s"); $sig++}
if ($t[7]){$diff.=($sig?", ":""). $t[7]." day".(($t[7]==1)?"":"s")}
if ($diff eq "") {$diff = "Less than one day";}
td $diff." ago (".(strftime "%e %b %Y", gmtime $info->{e_added}).")";}
end;
Tr;
td "Last seen:";
td;{
my @t = gmtime($info->{updiff});
if ($t[5]-70 || $t[7]) {
# more than 1 day? show date
span class => "r", (strftime "%e %b %Y", gmtime $info->{e_updated});
} else {
# less than 1 day? show "time ago"
my $diff = "";
$diff .= ($t[2] ? $t[2]." hour".($t[2]>1?"s, ":", ") : "");
$diff .= ($t[1] ? $t[1]." minute".($t[1]>1?"s, ":", ") : "");
$diff .= ($t[0] ? $t[0]." second".($t[0]>1?"s":" ") : "0 seconds");
$diff .= " ago";
span $diff;
}
end;}
end;
Tr;
td "Flags: ";
td;
i ($info->{b333ms} ? "direct uplink, " : "applet or manual, ");
i ($info->{blacklisted} ? "blacklisted, " : "not blacklisted, ");
i ($info->{password} ? "passworded" : "not passworded");
end;
end;
end;
#
# Specific game and version information
#
table class => "gameinfo";
Tr;
th class => "wc1", "Game Info";
th "";
end;
Tr;
td "Game:";
td $info->{description} || $gamename;
end;
if ($info->{gametype}) {
Tr;
td "Type:";
td $info->{gametype};
end;
}
if ($info->{gamestyle}) {
Tr;
td "Style:";
td $info->{gamestyle};
end;
}
if ($info->{gamever}) {
Tr;
td "Version:";
td $info->{gamever};
end;
}
end;
#
# Mutator list
#
table class => "mutators";
Tr;
th "Mutators";
end;
Tr;
td;
if (defined $info->{mutators} && $info->{mutators} ne "None") {
txt $info->{mutators};}
else {i "This server does not have any mutators listed.";}
end;
end;
end;
table class => "players";
my $player = $self->dbGetPlayerInfo(server_id => $info->{id});
my %team = ( 0 => "#e66",
1 => "#66e",
2 => "#6e6",
3 => "#ee6",
4 => "#fe6" );
# loop through players and print them in a nicely formatted table with funky colors
Tr;
th class => "wc1", "Player Info";
th class => "frags", 'Frags';
th class => "mesh", 'Mesh';
th class => "skin", 'Skin';
th class => "ping", 'Ping';
end;
for (my $i=0; defined $player->[$i]->{player}; $i++) {
Tr $i % 2 ? (class => 'odd') : (), style => 'color:'.$team{$player->[$i]->{team}} || "#aaa";
td class => "wc1", $player->[$i]->{player} . (($player->[$i]->{ngsecret} =~ m/^bot$/i) ? " (bot)" : "");
td class => "frags", $player->[$i]->{frags};
td class => "mesh", $player->[$i]->{mesh};
td class => "skin", $player->[$i]->{skin};
td class => "ping", $player->[$i]->{ping};
end;
}
if (!defined $player->[0]->{player}) { Tr; td colspan => 5; lit '<i>There is no player information available.</i>'; end; end;}
end;
#
# Share options (copy fields)
#
my $url = $self->{url}. "/". $gamename. "/". $info->{ip}. ":". $info->{hostport};
table class => "shareopts";
Tr;
th class => "wc1", "Share";
th "";
end;
Tr;
td class => "tc1", "Link";
td class => "tc2";
input type => 'text', class => 'text', name => 'url', value => $url;
end;
end;
Tr;
td class => "tc1";
txt "Json API ";
a href => "/json", title => "The url to access this server over the 333networks Json API", "*";
end;
td class => "tc2";
input type => 'text', class => 'text', name => 'url', value => $self->{url}. "/json/". $gamename. "/". $info->{ip}. ":". $info->{hostport};
end;
end;
Tr;
td "Forum Link";
td;
textarea type => 'textarea', class => 'text', rows => 3, name => 'paste';
txt "\[url=$url\]";lit "\n";
lit "\t";txt $info->{hostname};lit "\n";
txt "\[/url\]";
end;
end;
end;
Tr;
td "HTML Code";
td;
textarea type => 'textarea', class => 'text', rows => 3, name => 'paste';
txt "<a href=\"$url\">";lit "\n";
lit "\t"; txt $info->{hostname};lit "\n";
txt "</a>";
end;
end;
end;
end;
=pod
Optional information blocks:
#
# Teams
#
table class => "teaminfo";
Tr;
th class => "wc1", "Team Info";
th "";
end;
Tr;
td "Balance Teams:";
td ($info->{balanceteams} ? "Yes" : "No");
end;
Tr;
td "Players Balance Teams:";
td ($info->{playersbalanceteams} ? "Yes" : "No");
end;
Tr;
td "Friendly Fire:";
td ($info->{friendlyfire} || "0%");
end;
Tr;
td "Max Teams:";
td ($info->{maxteams} || 1);
end;
end;
#
# Game Limits
#
table class => "limits";
Tr;
th class => "wc1", "Limits";
th "";
end;
Tr;
td "Time Limit:";
td (($info->{timelimit} || 0). ":00 min");
end;
Tr;
td "Score Limit:";
td ($info->{goalteamscore} || 0);
end;
Tr;
td "Frag Limit:";
td ($info->{fraglimit} || 0);
end;
end;
div class => "code";
use Data::Dumper 'Dumper';
pre;
txt Dumper [$info, $player];
end;
end;
if ($self->debug) {
use Data::Dumper 'Dumper';
lit "<!--\n";
lit Dumper $info;
lit Dumper $player;
lit "\n-->";
}
=cut
end; # mainbox details
$self->htmlFooter;
}
################################################################################
# Display server errors
# Generates error pages in case of faulty gamename, server or other vagueness
################################################################################
sub serverError{
my ($self, %error) = @_;
$self->htmlHeader(title => "Server Info");
div class => 'warning';
h2 'An error occurred while trying to display the server.';
ul;
if (!%error) {
li "Not even the error message works. Please contact the administrator.";}
if ($error{ip}) {
li "The provided address is incorrect or does not resolve.";}
if ($error{port}) {
li "The provided port is not valid.";}
if ($error{gamename}) {
li "The game was not found in our database.";}
if ($error{db}) {
li "The server was not found in our database.";}
end;
end;
$self->htmlFooter;
}
1;
|