• Welcome to Vice City Multiplayer.
 

Getting server info from Website...

Started by thijn, March 07, 2009, 01:19:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

thijn

Hey all,
Maby someone can help me. I'm trying to get the server info from my website,
I thought it could with the masterlist file (http://vicecitymultiplayer.com/masterlist.php) but I don't know how :'(
It keeps saying "Error: invalid version", Maby someone knows what to do??

Thanks,
Thijn


thijn

k thx ;)
I will see if I can modify it so it will work for vcmp.
Thanks again ;)


Mex

#2
yo,

To retrieve all the servers on the server list, it uses the TCP protocol.
http://38.103.164.119/servers.php

(to query an individual server uses UDP)

the following should connect to the site and echo all the servers (including the headers received from the server)
(alot easier to read in the source as the servers are seperated by \n's)


<?php
$host "38.103.164.119";
$port 80;

$sock fsockopen($host$port$errorid$error30);
if (!$sock) die("Could not open socket to mast server list, errorid='$errorid' error='$error'");

$packet "GET /servers.php HTTP/1.1\r\n";
$packet .= "Content-Type: text/html\r\n";
$packet .= "Host: 38.103.164.119\r\n";
$packet .= "Accept: text/html, */*\r\n";
$packet .= "User-Agent: Mozilla/3.0 (compatible; VC:MP v0.3z BETA)\r\n";
$packet .= "\r\n";

fwrite($sock$packet);

while (!feof($sock)) {
echo fgets($sock128);
}

fclose($sock);
?>


thijn

thanks for that, But how can I get info (like players etc.) from the server?


thijn

Thanks goes to AdTec_224 And Kenny01!!!
Here it is dudes!!
Just paste this in a new php file, And upload it ;D ;D


<html>
  <head>
    <title>VCMP Server Info</title>
    <style type="text/css">
      body { font-family: verdana; font-size: 11px; }
      td { font-family: verdana; font-size: 11px; }
    </style>
  </head>
  <body bgcolor="#1B304B" text="#EEEEEE">
    <br><center><b><font color="#ffffff">VCMP Server Info Script</font></b></center><br><br>
    <table width="350" bgcolor="#000000" cellpadding="4" cellspacing="1" align="center">
<?php
$ip 
'<YOUR IP>';
$port '<PORT>';

$fp fsockopen('udp://' $ip$port$errno$errstr);
if (!$fp)
{
echo "<tr><td bgcolor=\"#2B5486\">Socket Error: $errno - $errstr</td></tr>\n";
}
else
{
$packet 'VCMP';
$packet .= chr(strtok($ip'.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr($port 0xFF);
$packet .= chr($port >> 0xFF);

fwrite($fp$packet.'i');
fread($fp11);
$is_passworded ord(fread($fp1));
$plr_count     ord(fread($fp2));
$max_plrs      ord(fread($fp2));
$strlen        ord(fread($fp4));
$hostname      fread($fp$strlen);
$strlen        ord(fread($fp4));
$gamemode      fread($fp$strlen);
$strlen        ord(fread($fp4));
$mapname       fread($fp$strlen);

echo '      <tr><td bgcolor="#2B5486" colspan="2" align="center"><b>' $hostname '</b></td></tr>'."\n";
echo '      <tr><td bgcolor="#2B5486" width="100">Players: </td><td bgcolor="#2B5486" width="250">' $plr_count ' / ' $max_plrs '</td></tr>'."\n";
echo '      <tr><td bgcolor="#2B5486">GameMode: </td><td bgcolor="#2B5486">' $gamemode '</td></tr>'."\n";
echo '      <tr><td bgcolor="#2B5486">MapName: </td><td bgcolor="#2B5486">' $mapname '</td></tr>'."\n";
if ($is_passworded)
{
echo '      <tr><td bgcolor="#2B5486">Passworded: </td><td bgcolor="#2B5486">Yes</td></tr>'."\n";
} else {
echo '      <tr><td bgcolor="#2B5486">Passworded: </td><td bgcolor="#2B5486">No</td></tr>'."\n";
}

fwrite($fp$packet.'c');
fread($fp11);
$plr_count ord(fread($fp2));
if ($plr_count 0)
{
echo '    </table><br>'."\n";
echo '    <table width="350" bgcolor="#000000" cellpadding="4" cellspacing="1" align="center">'."\n";
echo '      <tr><td bgcolor="#2B5486" colspan="2" align="center"><b>Players:</b></td></tr>'."\n";
echo '      <tr><td bgcolor="#2B5486" align="center" width="250"><b>Player</b></td><td bgcolor="#2B5486" align="center" width="100"><b>Score</b></td></tr>'."\n";
for ($i=0$i<$plr_count$i++)
{
$strlen ord(fread($fp1));
$plrname fread($fp$strlen);
$score samp_getLong(fread($fp4));

echo '      <tr><td bgcolor="#2B5486">' $plrname '</td><td bgcolor="#2B5486">' 
$score  '</td></tr>'."\n";
}
}
fclose($fp);
}
?>

    </table><br>
    <center><small>? 2006 SA:MP Team. All rights reserved.</small></center>
  </body>
</html>

<?php

function samp_getLong($dat) {
$num=0;
if ((ord(substr($dat,3,1)) & 128) > 0) {
for ($i=0$i<strlen($dat); $i++) {
$num-=((255-ord(substr($dat,$i,1))) << 8*$i);
}
$num--;
} else {
for ($i=0$i<strlen($dat); $i++) {
$num+=(ord(substr($dat,$i,1)) << 8*$i);
}
}
return $num;
}


Thanks again for this awesome script ;D ;D