From dfb11de2416afab53205c3d9122ba5dcd1ecb9c8 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 31 Oct 2013 01:35:47 +0000 Subject: [PATCH] - Web and JSon scripts now show finsihed games that are no older than 8 hours --- source/masterserver/addServerInfo.php | 41 ++++++++++++++++----- source/masterserver/functions.php | 2 +- source/masterserver/showServers.php | 2 +- source/masterserver/showServersForGlest.php | 2 +- source/masterserver/showServersJson.php | 2 +- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/source/masterserver/addServerInfo.php b/source/masterserver/addServerInfo.php index 5fbfc519..b1449931 100644 --- a/source/masterserver/addServerInfo.php +++ b/source/masterserver/addServerInfo.php @@ -71,25 +71,46 @@ // consider replacing this by a cron job cleanupServerList(); - $server_in_db = @mysql_query( 'SELECT ip, externalServerPort FROM glestserver WHERE ip=\'' . mysql_real_escape_string( $remote_ip ) . '\' AND externalServerPort=\'' . mysql_real_escape_string( $service_port ) . '\';' ); - $server = @mysql_fetch_row( $server_in_db ); - - - // Representation starts here (but it should really be starting much later, there is way too much logic behind this point) - header( 'Content-Type: text/plain; charset=utf-8' ); - $gameUUID = ""; $whereClause = 'ip=\'' . mysql_real_escape_string( $remote_ip ) . '\' && externalServerPort=\'' . mysql_real_escape_string( $service_port ) . '\';'; if ( isset( $_GET['gameUUID'] ) ) { $gameUUID = (string) clean_str( $_GET['gameUUID'] ); $whereClause = 'gameUUID=\'' . mysql_real_escape_string( $gameUUID ) . '\';'; } - // echo '#1 ' . $whereClause; + $server_in_db = @mysql_query( 'SELECT ip, externalServerPort FROM glestserver WHERE ' . $whereClause ); + $server = @mysql_fetch_row( $server_in_db ); + + // Representation starts here (but it should really be starting much later, there is way too much logic behind this point) + header( 'Content-Type: text/plain; charset=utf-8' ); + if ( (version_compare($glestVersion,"v3.4.0-dev","<") && $connectedClients == $networkSlots) || $gameCmd == "gameOver") // game servers' slots are all full - { // delete server; no checks are performed - mysql_query( 'DELETE FROM glestserver WHERE ' . $whereClause ); + { + if($gameCmd == "gameOver" && $gameUUID != "") + { + // update database info on this game server; no checks are performed + mysql_query( 'UPDATE glestserver SET ' . + 'glestVersion=\'' . mysql_real_escape_string( $glestVersion ) . '\', ' . + 'platform=\'' . mysql_real_escape_string( $platform ) . '\', ' . + 'binaryCompileDate=\'' . mysql_real_escape_string( $binaryCompileDate ) . '\', ' . + 'serverTitle=\'' . mysql_real_escape_string( $serverTitle ) . '\', ' . + 'tech=\'' . mysql_real_escape_string( $tech ) . '\', ' . + 'map=\'' . mysql_real_escape_string( $map ) . '\', ' . + 'tileset=\'' . mysql_real_escape_string( $tileset ) . '\', ' . + 'activeSlots=\'' . mysql_real_escape_string( $activeSlots ) . '\', ' . + 'networkSlots=\'' . mysql_real_escape_string( $networkSlots ) . '\', ' . + 'connectedClients=\'' . mysql_real_escape_string( $connectedClients ) . '\', ' . + 'externalServerPort=\''. mysql_real_escape_string( $service_port ) . '\', ' . + 'status=\'' . mysql_real_escape_string( $status ) . '\', ' . + 'lasttime=' . 'now()' . ' ' . + 'WHERE ' . $whereClause); + } + else + { + // delete server; no checks are performed + mysql_query( 'DELETE FROM glestserver WHERE ' . $whereClause ); + } echo 'OK' ; } // game in progress else if ( ($remote_ip == $server[0] && $service_port == $server[1]) || $status == 2 ) // this server is contained in the database diff --git a/source/masterserver/functions.php b/source/masterserver/functions.php index 75783ad7..22e7051d 100644 --- a/source/masterserver/functions.php +++ b/source/masterserver/functions.php @@ -55,7 +55,7 @@ function cleanupServerList() { // on a busy server, this function should be invoked by cron in regular intervals instead (one SQL query less for the script) - return mysql_query( 'DELETE FROM glestserver WHERE lasttime 3 AND lasttime < DATE_add(NOW(), INTERVAL -1 minute);' ); //return mysql_query( 'UPDATE glestserver SET status=\'???\' WHERE lasttime0 DESC, (networkSlots - connectedClients) , ip DESC;' ); + $servers_in_db = mysql_query( 'SELECT * FROM glestserver WHERE status <> 3 OR (status = 3 AND lasttime > DATE_add(NOW(), INTERVAL -8 hour)) ORDER BY status, connectedClients > 0 DESC, (networkSlots - connectedClients) , ip DESC;' ); $all_servers = array(); while ( $server = mysql_fetch_array( $servers_in_db ) ) { diff --git a/source/masterserver/showServersForGlest.php b/source/masterserver/showServersForGlest.php index accb7b33..3c3bab9b 100644 --- a/source/masterserver/showServersForGlest.php +++ b/source/masterserver/showServersForGlest.php @@ -12,7 +12,7 @@ // consider replacing this by a cron job cleanupServerList(); - $servers_in_db = mysql_query( 'SELECT * FROM glestserver ORDER BY status, connectedClients>0 DESC, (networkSlots - connectedClients) , ip DESC;' ); + $servers_in_db = mysql_query( 'SELECT * FROM glestserver WHERE status <> 3 ORDER BY status, connectedClients > 0 DESC, (networkSlots - connectedClients) , ip DESC;' ); $all_servers = array(); while ( $server = mysql_fetch_array( $servers_in_db ) ) { diff --git a/source/masterserver/showServersJson.php b/source/masterserver/showServersJson.php index 81fed491..4858d3d0 100644 --- a/source/masterserver/showServersJson.php +++ b/source/masterserver/showServersJson.php @@ -12,7 +12,7 @@ // consider replacing this by a cron job cleanupServerList(); - $servers_in_db = mysql_query( 'SELECT * FROM glestserver ORDER BY status, connectedClients>0 DESC, (networkSlots - connectedClients), ip DESC;' ); + $servers_in_db = mysql_query( 'SELECT * FROM glestserver status <> 3 OR (status = 3 AND lasttime > DATE_add(NOW(), INTERVAL -8 hour)) ORDER BY status, connectedClients > 0 DESC, (networkSlots - connectedClients), ip DESC;' ); $all_servers = array(); while ( $server = mysql_fetch_array( $servers_in_db ) ) {