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
|
package MasterWebInterface::Handler::Servers;
use strict;
use utf8;
use TUWF ':html';
use Exporter 'import';
use Geography::Countries;
TUWF::register(
qr{s/(.[\w]*)} => \&serverlist,
qr{s/(.[\w]*)/(all|[0a-z])} => \&serverlist,
);
################################################################################
# List servers
# Generate a list of selected games in the database per game (arg: gamename)
################################################################################
sub serverlist {
my($self, $gamename, $char) = @_;
# default list if nothing defined
$char = "all" unless $char;
# process additional query information, such as order, sorting, page, etc
my $f = $self->formValidate(
{ get => 's', required => 0, default => 'diff', enum => [ qw| country hostname description gamename gametype ip hostport numplayers mapname diff added | ] },
{ get => 'o', required => 0, default => 'a', enum => [ 'a','d' ] },
{ get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'q', required => 0, default => '', maxlength => 90 },
);
return $self->resNotFound if $f->{_err};
# load server list from database
my($list, $np, $p) = $self->dbServerListGet(
sort => $f->{s},
reverse => $f->{o} eq 'd',
$char ne 'all' ? (
firstchar => uc $char ) : (),
results => 50,
search => $f->{q},
gamename => $gamename,
page => $f->{p},
);
# game name description in title
my $gn_desc = $self->dbGetGameDesc($gamename) || $gamename;
# Write page
$self->htmlHeader(title => "Browse $gn_desc game servers");
div class => 'mainbox';
div class => "header";
h1 'Browse Servers';
p class => "alttitle";
txt "Servers listed for ";
span class => "acc", $gn_desc;
txt " games. Can be sorted by location, server name, gametype, players and current map.";
end;
end;
form action => "/s/$gamename/all", 'accept-charset' => 'UTF-8', method => 'get';
$self->htmlSearchBox('s', $f->{q});
end;
p class => 'browseopts';
for ('all', 'a'..'z', 0) {
a href => "/s/$gamename/$_", $_ eq $char ? (class => 'optselected') : (), $_ eq 'all' ? ('all') : $_ ? uc $_ : '#';
}
end;
end;
# print list
$self->htmlBrowse(
items => $list,
options => $f,
total => $p,
nextpage => [$p,50],#$np,
pageurl => "/s/$gamename/$char?o=$f->{o};s=$f->{s};q=$f->{q}",
sorturl => "/s/$gamename/$char?q=$f->{q}",
class => "serverlist",
($p <= 0) ? (footer => sub {Tr;td colspan => 6, class => 'tc2', 'No online servers found';end 'tr';}) : (),
header => [
[ '', 'country' ],
[ 'Server Name', 'hostname' ],
[ 'Game', 'gamename' ],
[ 'Gametype', 'gametype' ],
[ 'Players', 'numplayers' ],
[ 'Map', 'mapname' ],
],
row => sub {
my($s, $n, $l) = @_;
Tr $n % 2 ? (class => 's odd') : (class => 's');
my ($flag, $country) = $self->countryflag($l->{country});
td class => "tc1 flag", style => "background-image: url(/flag/$flag.svg);", title => $country, '';
td class => "tc2"; a href => "/$l->{gamename}/$l->{ip}:$l->{hostport}", $l->{hostname}; end;
td class => "tc3", title => $l->{description}; a href => "/s/$l->{gamename}", $l->{gamename};end;
td class => "tc4", title => $l->{gametype}, $l->{gametype};
td class => "tc5"; txt $l->{numplayers}; txt "/"; txt $l->{maxplayers}; end;
td class => "tc6", title => ( $l->{maptitle} || $l->{mapname}), ($l->{maptitle} || $l->{mapname});
end;
},
);
$self->htmlFooter;
}
1;
|