aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterWebInterface/Handler/Json
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MasterWebInterface/Handler/Json')
-rwxr-xr-xlib/MasterWebInterface/Handler/Json/JsonServerInfo.pm26
-rwxr-xr-xlib/MasterWebInterface/Handler/Json/JsonServerList.pm17
2 files changed, 40 insertions, 3 deletions
diff --git a/lib/MasterWebInterface/Handler/Json/JsonServerInfo.pm b/lib/MasterWebInterface/Handler/Json/JsonServerInfo.pm
index a3b2d08..519017e 100755
--- a/lib/MasterWebInterface/Handler/Json/JsonServerInfo.pm
+++ b/lib/MasterWebInterface/Handler/Json/JsonServerInfo.pm
@@ -2,11 +2,14 @@ package MasterWebInterface::Handler::Json::JsonServerInfo;
use strict;
use TUWF ':html';
use Exporter 'import';
+use Socket;
use JSON;
TUWF::register(
qr{json/([\w]{1,20})/(\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}):(\d{1,5})} => \&json_serverinfo, # ipv6
qr{json/([\w]{1,20})/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})} => \&json_serverinfo, # ipv4
+ qr{json/([\w]{1,20})/([\w\.]{3,63}):(\d{1,5})} => \&json_serverinfo, #domain name
+
);
#
@@ -14,7 +17,16 @@ TUWF::register(
#
sub json_serverinfo
{
- my ($self, $gamename, $ip, $port) = @_;
+ my ($self, $gamename, $addr, $port) = @_;
+
+ # domain name check
+ my $ip = $addr;
+ if ($addr =~ m/[a-z]/ig )
+ {
+ # $addr holds a value that is a domain. try to resolve.
+ my $packed_ip = gethostbyname($ip);
+ $ip = inet_ntoa($packed_ip) if (defined $packed_ip);
+ }
# select server from database
my $info = $self->dbGetServerInfo(
@@ -45,6 +57,11 @@ sub json_serverinfo
for (my $i=0; defined $pl_list->[$i]->{name}; $i++)
{
+
+ # fix html "injection" (quick fix, ask Yorhel for better suited solution)
+ s/</&lt;/g for values %{$pl_list->[$i]};
+ s/>/&gt;/g for values %{$pl_list->[$i]};
+
$players{"player_$i"} = $pl_list->[$i];
}
@@ -53,6 +70,9 @@ sub json_serverinfo
# find the correct thumbnail, otherwise game default, otherwise 333 default
my $mapname = lc $info->{mapname};
+
+ # FIXME
+ $info->{debug_map_path} = "$self->{root}/s/map/$info->{gamename}/$mapname.jpg";
# if map figure exists, use it
if (-e "$self->{root}/s/map/$info->{gamename}/$mapname.jpg")
@@ -72,6 +92,10 @@ sub json_serverinfo
# 333networks default
$info->{mapurl} = "/map/default/333networks.jpg";
}
+
+ # fix html "injection" (quick fix, ask Yorhel for better suited solution)
+ s/</&lt;/g for values %{$info};
+ s/>/&gt;/g for values %{$info};
# response as json data
$self->resJSON($info);
diff --git a/lib/MasterWebInterface/Handler/Json/JsonServerList.pm b/lib/MasterWebInterface/Handler/Json/JsonServerList.pm
index e108066..d02455f 100755
--- a/lib/MasterWebInterface/Handler/Json/JsonServerList.pm
+++ b/lib/MasterWebInterface/Handler/Json/JsonServerList.pm
@@ -21,10 +21,16 @@ sub serverlist_json
{ get => 's', required => 0, default => 'gamename', enum => [qw|hostname gamename country added gametype numplayers mapname|] },
{ get => 'o', required => 0, default => 'a', enum => ['a','d'] },
{ get => 'p', required => 0, default => 1, template => 'page' },
- { get => 'r', required => 0, default => 100, template => 'page' },
+ { get => 'r', required => 0, default => 50, template => 'page' },
{ get => 'q', required => 0, default => '', maxlength => 90 },
{ get => 'g', required => 0, default => '', maxlength => 90 },
{ get => 'a', required => 0, default => '', maxlength => 200 },
+
+ #{ get => 'gamename', required => 0, default => '', maxlength => 90 }, # gamename in advanced search
+ { get => 'gametype', required => 0, default => '', maxlength => 90 }, # gametype
+ { get => 'hostname', required => 0, default => '', maxlength => 90 }, # hostname (replaces q in advanced search)
+ { get => 'mapname', required => 0, default => '', maxlength => 90 }, # mapname
+ { get => 'country', required => 0, default => '', maxlength => 90 }, # country (code)
);
# allow all outside sources to access the json api
@@ -56,13 +62,20 @@ sub serverlist_json
# parse extra request parameters for ubrowser.333networks.com
($f->{a} =~ m/popserv/ig) ? (popserv => 1) : (),
($f->{a} =~ m/utdemo/ig) ? (utdemo => 1) : (),
+
+ gametype => $f->{gametype},
+ hostname => $f->{hostname},
+ mapname => $f->{mapname},
+ country => $f->{country},
);
# get total number of players in selected page(s)
my $pl = 0;
for (@{$list})
{
- $pl += $_->{numplayers}
+ $pl += $_->{numplayers};
+ s/</&lt;/g for values %{$_};
+ s/>/&gt;/g for values %{$_};
}
# response as json data