diff options
| author | Darkelarious <github@333networks.com> | 2025-03-08 15:56:30 +0100 |
|---|---|---|
| committer | Darkelarious <github@333networks.com> | 2025-03-08 15:56:30 +0100 |
| commit | 6bd235f3e62251d8763a552ab0042d59584de842 (patch) | |
| tree | 2ff943b6ddb8aa8980a3ed1fb4a1f869fc787d1c /lib/MasterWebInterface/Handler/Json/JsonServerInfo.pm | |
| parent | 318a5a20a930192df788dbac54b1f9c60e1b98b8 (diff) | |
| download | WebInterface-Perl-6bd235f3e62251d8763a552ab0042d59584de842.tar.gz WebInterface-Perl-6bd235f3e62251d8763a552ab0042d59584de842.zip | |
Metadata and update to hotfix 4.
Display thumbnails / snippets in 3rd party apps (like discord) and add map thumbnails + icons for multiple games. Minor fixes/optimisations.
Diffstat (limited to 'lib/MasterWebInterface/Handler/Json/JsonServerInfo.pm')
| -rwxr-xr-x | lib/MasterWebInterface/Handler/Json/JsonServerInfo.pm | 26 |
1 files changed, 25 insertions, 1 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/</</g for values %{$pl_list->[$i]}; + s/>/>/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/</</g for values %{$info}; + s/>/>/g for values %{$info}; # response as json data $self->resJSON($info); |
