diff options
| author | Darkelarious <darkelarious@333networks.com> | 2021-05-23 11:58:03 +0200 |
|---|---|---|
| committer | Darkelarious <darkelarious@333networks.com> | 2021-05-23 11:58:03 +0200 |
| commit | 7510e6780dd4c1f18e66c19dcd7bd401614c8a60 (patch) | |
| tree | b67212f867a5ecaec8506d2ac97ef601a17fc4d9 | |
| parent | 8ce0403acff44e3de082595ba68d70ceea2e2517 (diff) | |
| download | MasterServer-Perl-master.tar.gz MasterServer-Perl-master.zip | |
| -rwxr-xr-x | README.md (renamed from README) | 28 | ||||
| -rwxr-xr-x | lib/MasterServer/Database/SQLite/dbUTServerInfo.pm | 122 |
2 files changed, 138 insertions, 12 deletions
@@ -1,6 +1,11 @@ +# MasterServer-Perl + +Repository for the 333networks MasterServer written in Perl. + + ========= -DESCRIPTION +# DESCRIPTION This repository contains software to host a MasterServer for a variety of legacy games. The software was written Darkelarious to soften the effects of @@ -14,15 +19,14 @@ DESCRIPTION More information about the masterserver and variations on the protocol by 333networks can be found online at http://333networks.com/masterserver - http://wiki.333networks.com/index.php/MasterServer -AUTHOR +# AUTHOR Darkelarious http://333networks.com darkelarious@333networks.com -REQUIREMENTS +# REQUIREMENTS - Postgresql, SQLite3 - Perl 5.22 or above @@ -33,13 +37,13 @@ REQUIREMENTS DBD::Pg / DBD::SQLite Encode Exporter - IP::Country::Fast + IP::Country::Fast; Socket Switch JSON - screen (or another terminal multiplexer, optional) -INSTALL +# INSTALL THE MASTER SERVER IS WRITTEN ON LINUX. IF YOU WANT TO RUN THE SOFTWARE IN MICROSOFT WINDOWS OR APPLE OSX, IT WILL NOT WORK WITHOUT MODIFICATIONS. @@ -60,7 +64,7 @@ INSTALL servers. Carefully read through the code and documentation before you start randomly querying other game servers and/or masterservers. -CONFIGURATION +# CONFIGURATION The 333networks masterserver comes with options. These options are found in configuration file "data/masterserver-config.pl". Comments in that file give @@ -186,7 +190,7 @@ CONFIGURATION above. If "beacon_checker_enabled" is disabled, this function will NOT work properly. Enable/Disable with "master_applet_enabled". - Synchronization settings + Synchronization settings Synchronization between masterservers allows you to receive the list from other masterservers. In return and to make this communication two-way, the @@ -216,7 +220,7 @@ CONFIGURATION If you want to sync with us, please email us on info@333networks.com -RUNNING +# RUNNING After all CPAN modules have been installed and all options have been reviewed in the configuration file, the masterserver can be started with the following @@ -242,7 +246,7 @@ RUNNING 333networks is not responsible for your masterserver querying (or spamming) game servers and/or masterservers. Your configuration is YOUR responsibility! -TOOLS +# TOOLS In the "util/tools" folder, a few handy tools are included. In general, it is not necessary to use these tools. While debugging and writing new features for @@ -252,7 +256,7 @@ TOOLS per tool. Expert knowledge required! These tools will move to a new repository on our git soon. -KNOWN ISSUES +# KNOWN ISSUES There are a few known issues that will be resolved in future versions. The following issues are listed and do not need to be reported. @@ -297,5 +301,5 @@ KNOWN ISSUES (or other's) masterservers with unnecessarily fast sync request. If you want to sync with us, please email us on info@333networks.com -COPYING +# COPYING See file COPYING diff --git a/lib/MasterServer/Database/SQLite/dbUTServerInfo.pm b/lib/MasterServer/Database/SQLite/dbUTServerInfo.pm new file mode 100755 index 0000000..5a579ac --- /dev/null +++ b/lib/MasterServer/Database/SQLite/dbUTServerInfo.pm @@ -0,0 +1,122 @@ +package MasterServer::Database::SQLite::dbUTServerInfo; + +use strict; +use warnings; +use MasterServer::Core::Util 'sqlprint'; +use Exporter 'import'; + +our @EXPORT = qw| add_utserver + update_utserver + delete_utplayers + insert_utplayer |; + +################################################################################ +## Update serverinfo for an existing address to the utserver list. +## opts: all server info data fields. +################################################################################ +sub update_utserver { + my $self = shift; + my $id = shift; + my %s = ( + # defaults + updated => time, + @_); + + # try updating it in serverlist + my %H = ( + $s{minnetver} ? ( 'minnetver = ?' => $s{minnetver} ) : (), + $s{gamever} ? ( 'gamever = ?' => int( $s{gamever}) ) : (), + $s{location} ? ( 'location = ?' => $s{location} ) : (), + $s{listenserver} ? ( 'listenserver = ?' => ( $s{listenserver} ? 1 : 0) ) : (), + $s{hostport} ? ( 'hostport = ?' => $s{hostport}) : (), + $s{hostname} ? ( 'hostname = ?' => $s{hostname}) : (), + $s{AdminName} ? ( 'adminname = ?' => $s{AdminName}) : (), + $s{AdminEMail} ? ( 'adminemail = ?' => $s{AdminEMail}) : (), + $s{password} ? ( 'password = ?' => ( $s{password} ? 1 : 0) ) : (), + $s{gametype} ? ( 'gametype = ?' => $s{gametype}) : (), + $s{gamestyle} ? ( 'gamestyle = ?' => $s{gamestyle}) : (), + $s{changelevels} ? ( 'changelevels = ?' => ( $s{changelevels} ? 1 : 0) ) : (), + $s{maptitle} ? ( 'maptitle = ?' => $s{maptitle}) : (), + $s{mapname} ? ( 'mapname = ?' => $s{mapname}) : (), + $s{numplayers} ? ( 'numplayers = ?' => $s{numplayers}) : ('numplayers = ?' => 0), + $s{maxplayers} ? ( 'maxplayers = ?' => $s{maxplayers}) : ('maxplayers = ?' => 0), + $s{minplayers} ? ( 'minplayers = ?' => $s{minplayers}) : ('minplayers = ?' => 0), + $s{botskill} ? ( 'botskill = ?' => $s{botskill}) : (), + $s{balanceteams} ? ( 'balanceteams = ?' => ( $s{balanceteams} ? 1 : 0) ) : (), + $s{playersbalanceteams} ? ( 'playersbalanceteams = ?' => ( $s{playersbalanceteams} ? 1 : 0) ) : (), + $s{friendlyfire} ? ( 'friendlyfire = ?' => $s{friendlyfire}) : (), + $s{maxteams} ? ( 'maxteams = ?' => $s{maxteams}) : (), + $s{timelimit} ? ( 'timelimit = ?' => $s{timelimit}) : (), + $s{goalteamscore} ? ( 'goalteamscore = ?' => int( $s{goalteamscore}) ) : (), + $s{fraglimit} ? ( 'fraglimit = ?' => int( $s{fraglimit}) ) : (), + $s{mutators} ? ( 'mutators = ?' => $s{mutators}) : ('mutators = ?' => "None"), + $s{updated} ? ('updated = datetime(?, \'unixepoch\')' => $s{updated}) : (), + ); + + my($q, @p) = sqlprint("UPDATE utserver_info !H WHERE server_id = ?", \%H, $id); + return $self->{dbh}->do($q, undef, @p); +} + + +################################################################################ +## Add a new utserver and trigger the update routine above. +## opts: id, server info data +################################################################################ +sub add_utserver { + my ($self, $ip, $port) = @_; + + # create new entry + return $self->{dbh}->do( + "INSERT INTO utserver_info (server_id) + SELECT (SELECT id FROM serverlist WHERE ip = ? AND port = ?)", + undef, $ip, $port); +} + + +################################################################################ +## Delete all players from a certain server ID +## opts: server id +################################################################################ +sub delete_utplayers { + my ($self, $sid) = @_; + + # delete players for server_id + return $self->{dbh}->do( + "DELETE FROM utplayer_info WHERE server_id = ?", + undef, $sid); +} + +################################################################################ +## Insert player info for a single player in server sid +## opts: server id, player info +################################################################################ +sub insert_utplayer { + my $self = shift; + my $sid = shift; + my %s = ( + updated => time, + @_); + + # apparently useless chunk of code + # FIXME move to site part + my %H = ( + $s{server_id} ? ( 'server_id = ?' => $s{server_id}) : (), + $s{player} ? ( 'player = ?' => $s{player}) : (), + $s{team} ? ( 'team = ?' => int( $s{team})) : (), + $s{frags} ? ( 'frags = ?' => int( $s{frags})) : (), + $s{mesh} ? ( 'mesh = ?' => $s{mesh}) : (), + $s{skin} ? ( 'skin = ?' => $s{skin}) : (), + $s{face} ? ( 'face = ?' => $s{face}) : (), + $s{ping} ? ( 'ping = ?' => int( $s{ping})) : (), + $s{ngsecret} ? ( 'ngsecret = ?' => $s{ngsecret}) : (), + $s{updated} ? ('updated = datetime(?, \'unixepoch\')' => $s{updated}) : (), + ); + + # insert + return $self->{dbh}->do( + "INSERT INTO utplayer_info (server_id, player, team, frags, mesh, skin, face, ping, ngsecret) + VALUES (?,?,?,?,?,?,?,?,?)", + undef, $sid, $s{player}, $s{team}, $s{frags}, $s{mesh}, $s{skin}, $s{face}, $s{ping}, $s{ngsecret}); +} + +1; |
