NEUES PROBLEM:
Mein Server mag keine socked Verbindungen anscheinend und ich weiss auch das man fsock nehmen kann und das geht auch bei mir bloss müsste man nun den socked code um programmieren!
Zeile 35-45!
Mein Server mag keine socked Verbindungen anscheinend und ich weiss auch das man fsock nehmen kann und das geht auch bei mir bloss müsste man nun den socked code um programmieren!
Zeile 35-45!
PHP-Code:
<?
if ($show == 1)
{
if (isset($_SESSION['id']))
{
if (isset($_POST['submit'])){
$ownerid = $_SESSION['id'];
$ip = $_SERVER['REMOTE_ADDR'];
$port = 7171;
$desc = trim(htmlentities($_POST['desc'], ENT_QUOTES));
$location = $_POST['location'];
$connection = $_POST['connection'];
$fel = 0;
if (empty($desc)){
$fel = 1;
error("Description was not filled in.", 1);
}
$conn = @fsockopen ("$ip", "$port",$null,$errstr,1);
if (!$conn)
{
$fel = 1;
error("Couldn't connect to the server.<br>To be able to add a server it must be online.", 1);
}
$ipcheck = mysql_num_rows(mysql_query("SELECT * FROM servers WHERE ip='".$ip."'"));
if ($ipcheck > 0){
$fel = 1;
error("That IP is already in our database.", 1);
}
if ($fel != 1)
{
//Hämta xml info från servern till variabeln $data
$info = chr(6).chr(0).chr(255).chr(255).'info';
$s = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
socket_connect($s, $ip, $port);
socket_send($s, $info, 8, 0);
$a = '';
$data = '';
while(socket_recv($s, $a, 1024, 0))
{
$data .= $a;
}
socket_close($s);
//Ladda infon från xml
$stack = array();
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");
$data = xml_parse($xml_parser, $data);
if(!$data) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
$info = array();
foreachzor($stack, $info);
if (! empty($info['SERVERNAME']))
{
$version = trim(htmlentities($info['VERSION'], ENT_QUOTES));
$uptime = trim(htmlentities($info['UPTIME'], ENT_QUOTES));
$servername = trim(htmlentities($info['SERVERNAME'], ENT_QUOTES));
$location_spec = trim(htmlentities($info['LOCATION'], ENT_QUOTES));
$url = trim(htmlentities($info['URL'], ENT_QUOTES));
$players_online = trim(htmlentities($info['ONLINE'], ENT_QUOTES));
$players_max = trim(htmlentities($info['MAX'], ENT_QUOTES));
$players_peak = trim(htmlentities($info['PEAK'], ENT_QUOTES));
$motd = trim(htmlentities($info['cdata'], ENT_QUOTES));
$insertserver = "INSERT INTO servers(ownerid, created, name, ip, port, description, location, location_spec, connection, players_max, players_peak, players_online, ";
$insertserver .= "version, online, lastcheck, homepage, motd, uptime, uptime_total, uptime_avarage) VALUES ";
$insertserver .= "('".$ownerid."', '".$cur."', '".$servername."', '".$ip."', '".$port."', '".$desc."', '".$location."', '".$location_spec."', '".$connection."', '".$players_max."', '".$players_peak."', ";
$insertserver .= "'".$players_online."', '".$version."', 1, '".$cur."', '".$url."', '".$motd."', '".$uptime."', '".$uptime."', '100.0')";
if (mysql_query($insertserver))
{
echo "Server was succefully added!";
}
else
{
echo "Server was not succefully added!<br>";
echo "Please notify webmaster about this: ".mysql_error();
}
}
else
{
error("Couldn't get server data.<br>Check that your version of OTserv actually sends data.", 1);
}
}
else
{
?>
<form method='post'>
<table>
<tr>
<td valign="top"><b>Description:</b></td><td><textarea name='desc' cols='25' rows='6'><?=$desc?></textarea></td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>
<select name="location">
<option selected>Europe</option>
<option>North America</option>
<option>South America</option>
<option>Africa</option>
<option>Asia</option>
<option>Oceania</option>
</select>
</td>
</tr>
<tr>
<td><b>Connection:</b></td>
<td>
<select name="connection">
<option selected value='< 0.5'>< 0.5 Mbit</option>
<option value='0.5'>0.5 Mbit</option>
<option value='1'>1 Mbit</option>
<option value='2'>2 Mbit</option>
<option value='2.5'>2.5 Mbit</option>
<option value='5'>5 Mbit</option>
<option value='8'>8 Mbit</option>
<option value='10'>10 Mbit</option>
<option value='> 10'>> 10 Mbit</option>
</select>
</td>
</tr>
<tr>
<td colspan='2'><br></td>
</tr>
</table>
<input type='submit' name='submit' value='Add server'>
</form>
<?
}
}
else
{
?>
<form method='post'>
<table>
<tr>
<td valign="top"><b>Description:</b></td><td><textarea name='desc' cols='25' rows='6'></textarea></td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>
<select name="location">
<option selected>Europe</option>
<option>North America</option>
<option>South America</option>
<option>Africa</option>
<option>Asia</option>
<option>Oceania</option>
</select>
</td>
</tr>
<tr>
<td><b>Connection:</b></td>
<td>
<select name="connection">
<option selected value='< 0.5'>< 0.5 Mbit</option>
<option value='0.5'>0.5 Mbit</option>
<option value='1.0'>1 Mbit</option>
<option value='2.0'>2 Mbit</option>
<option value='2.5'>2.5 Mbit</option>
<option value='5'>5 Mbit</option>
<option value='8'>8 Mbit</option>
<option value='10'>10 Mbit</option>
<option value='> 10'>> 10 Mbit</option>
</select>
</td>
</tr>
<tr>
<td colspan='2'><br></td>
</tr>
</table>
<input type='submit' name='submit' value='Add server'>
</form>
<?
}
}
}
?>
Kommentar