Auf einen zweiten Versuch
Diesmal sind die Änderungen ein wenig umfangreicher.
Zuerst musste ich das Server-Skript leicht überarbeiten (Hinweis: man muss die Tabelle servers löschen und neu anlegen, da eine neue Spalte angelegt wird; außerdem wird noch die neue Tabelle uul neu angelegt).
server.php
Code: Alles auswählen
<?php
/* Generic PHP-based lobby server (for Dudos)
* Copyright (C) 2005 Wolfgang Keller
* Contact: mail.wolfgang.keller@web.de
*
* Based on the
* Generic PHP-based lobby server
* (by The.Modificator)
*
* This program is free software; you can
* redistribute it and/or modify it under
* the terms of the GNU General Public License
* as published by the Free Software Foundation;
* either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License
* for more details.
* You should have received a copy of the
* GNU General Public License along with
* this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
unset($setup); unset($createdb); unset($dbserver); unset($dbuser); unset($dbpassword); unset($dbname);
unset($create_uul_support);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Change values below
////////////////////////////////////////////////////////////////////////////////////////////////////
$dbserver = "localhost"; // database hostname
$dbuser = "meinname"; // database username
$dbpassword = "meinpasswort"; // database password
$dbname = "dudos"; // database name
//Just change this value once to 1 to setup the database
$setup = 0;
$createdb = 0; // if your provider supports the "CREATE DATABASE" command, you can also change
// this value to 1
$create_uul_support = 1;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Change values above
////////////////////////////////////////////////////////////////////////////////////////////////////
if($setup == 1)
{
if(!($dbcid = mysql_connect($dbserver, $dbuser, $dbpassword)))
{
exit("ERR\nCould not connect.");
}
if($createdb == 1)
{
$sql="CREATE DATABASE `$dbname`;";
mysql_query($sql,$dbcid);
}
if(!mysql_select_db($dbname))
{
exit("ERR\nCould not select the db.");
}
$sql="CREATE TABLE `$dbname`.`servers` (
`server_ip` VARCHAR(255) NOT NULL,
`last_signal_time` INTEGER UNSIGNED NOT NULL,
`game_name` VARCHAR(255) NOT NULL,
`ki_nr` BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(`server_ip`)
);";
mysql_query($sql,$dbcid);
if ($create_uul_support==1)
{
$sql="CREATE TABLE `$dbname`.`uul` (
`next_ki_nr` BIGINT UNSIGNED NOT NULL
);";
mysql_query($sql,$dbcid);
$sql = "INSERT INTO `uul` (`next_ki_nr`) VALUES ('1');";
mysql_query($sql,$dbcid);
}
mysql_close($dbcid);
echo("OK\nDatabase should be up now. Change the \$setup and the \$createdb values back to 0 now.");
exit();
}
if(isset($HTTP_GET_VARS['command'])||isset($HTTP_POST_VARS['command']))
{
$command = isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:$HTTP_POST_VARS['command'];
}
else
{
exit("ERR\nNo command specified");
}
if(!($dbcid = mysql_connect($dbserver, $dbuser, $dbpassword)))
{
exit("ERR\nCould not connect.");
}
if(!mysql_select_db($dbname))
{
exit("ERR\nCould not select the db.");
}
$ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$time = time();
$toolate = $time - 2*60;
if($command=="refresh")
{
$gamename_unesc = isset($HTTP_GET_VARS['gamename']) ? $HTTP_GET_VARS['gamename'] : $HTTP_POST_VARS['gamename'];
$gamename = mysql_escape_string($gamename_unesc);
}
//delete servers that timed out
$sql = "DELETE FROM `servers` WHERE `last_signal_time` < $toolate;";
mysql_query($sql,$dbcid);
switch($command)
{
case "newserver":
$ki_ret=mysql_query("SELECT * FROM uul ;",$dbcid);
$ki_nr = mysql_fetch_array($ki_ret);
$sql = "INSERT INTO `servers` (`server_ip`,`last_signal_time`,`game_name`,`ki_nr`) VALUES ('$ip', '$time','','".$ki_nr['next_ki_nr']."');";
mysql_query($sql,$dbcid);
mysql_query("UPDATE `uul` SET `next_ki_nr`='".($ki_nr['next_ki_nr']+1)."' ;",$dbcid);
echo "OK\n";
break;
case "refresh":
$sql = "UPDATE `servers` SET `last_signal_time` = $time, `game_name` = '$gamename' WHERE `server_ip` = '$ip';";
mysql_query($sql,$dbcid);
echo "OK\n";
break;
case "removeserver":
$sql = "DELETE FROM `servers` WHERE `server_ip` = '$ip';";
mysql_query($sql,$dbcid);
echo "OK\n";
break;
case "getservers":
$sql = "SELECT `server_ip`,`last_signal_time`,`game_name` FROM servers;";
$ret = mysql_query($sql,$dbcid);
//$count = mysql_num_rows($ret);
echo "OK\n";
while($data = mysql_fetch_array($ret))
{
echo $data['server_ip'];
echo ",";
echo str_replace("\n","&br;",str_replace("&","&",$data['game_name']));
echo "\n";
};
echo "END";
break;
default:
exit("ERR\nNo command specified");
}
mysql_close($dbcid);
?>
Nun das eigentliche UUL-Skript:
uul_interface.php
<?php
/* UU Locator Client for the Dudos Server
* Copyright (C) 2005 Wolfgang Keller
* Contact:
mail.wolfgang.keller@web.de
*
* Based on the
* PHP-based Untìl Uru player lister for automatic interpreters based on structure "tiana 0x4"
* and the
* Generic PHP-based lobby server
* (both by The.Modificator)
*
* This program is free software; you can
* redistribute it and/or modify it under
* the terms of the GNU General Public License
* as published by the Free Software Foundation;
* either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License
* for more details.
* You should have received a copy of the
* GNU General Public License along with
* this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
error_reporting(0); //disable all errors/warnings/whatever
unset($dbserver); unset($dbuser); unset($dbpassword); unset($dbname);
$dbserver = "localhost"; // database hostname
$dbuser = "wkeller"; // database username
$dbpassword = "wk658358"; // database password
$dbname = "wkeller_db"; // database name
if(!($dbcid = mysql_connect($dbserver, $dbuser, $dbpassword)))
{
exit("ERR\nCould not connect to database.");
}
if(!mysql_select_db($dbname))
{
mysql_close($dbcid);
exit("ERR\nCould not select the database.");
}
// The cleanup work (else a server could stay too long in the list, because nobody calls
// server.php
$time = time();
$toolate = $time - 2*60;
//delete servers that timed out
$sql = "DELETE FROM `servers` WHERE `last_signal_time` < $toolate;";
mysql_query($sql,$dbcid);
// end cleanup
$sql = "SELECT `game_name`, `ki_nr` FROM servers;";
$ret = mysql_query($sql,$dbcid);
$count = mysql_num_rows($ret);
if ($count==0)
{
print "NUL\nNo players are connected.";
}
else
{
print("LST\n");
echo "$count\n";
while($data = mysql_fetch_array($ret))
{
$name=str_replace("\n","&br;",str_replace("&","&", $data['game_name'] ));
echo ($name=="") ? "\n\nunknown\n" : "\n\n$name\n";
echo $data['ki_nr'];
echo "\nDudos";
};
}
mysql_close($dbcid);
?>
[/php]
Der Zyklustyp einer Permutation ist konjugationsinvariant.