SRCDS Steam group


help with player query
#1
hey guys, i need help - i don't know what's wrong with this code, but its not working. Please Help me Sad

Code:
<?php

$ip = "212.59.22.131";
$port = "21100";

$socket = fsockopen("udp://".$ip, $port, $errno, $errstr, 3);

// Send a -1 value for the challenge ID (server will reply with challenge ID)
$challenegeRequest = "\xFF\xFF\xFF\xFF\x55\xFF\xFF\xFF\xFF";
fwrite($socket, $challenegeRequest);

// Read the first 4 bytes (FF FF FF FF)
fread($socket, 4);

// Get the type (hoping for 'A')
$type = fread($socket, 1);

// error check
if ($type == "A")
{
    // Get the 4 byte challenge ID
    $challengeID = fread($socket, 4);
}

$playerRequest = "\xFF\xFF\xFF\xFF\x55" . $challengeID;
fwrite($socket, $playerRequest);
// Read the first 4 bytes (FF FF FF FF)
fread($socket, 4);
$type2 = fread($socket, 1);

if ($type2 == "D")
{
        // Get the 4 byte challenge ID
    $players = ord(fread($socket, 4));
}

// loop through each player
for ($i = 0; $i < $players; $i++)
{
// get player index from first byte
$playerData[$i]['id'] = ord(fread($socket, 4));

// keep reading data to get players name
$playerName = "";
while(true)
{
// read the next byte
$tempString = fread($socket, 1);
// if it containts data
// append to playersName
if (ord($tempString) != 0)
{
$playerName .= $tempString;
}
else
{
// if it does = 0 break the loop
break;
}
}
$playerData[$i]['name'] = $tempString;

// unpack the next 4 bytes to get the players kills
$kills = unpack("L", fread($socket, 4));
$playerData[$i]['kills'] = $kills;

// same deal for time connected
$time = unpack("f", fread($socket, 4));
$playerData[$i]['time'] = round($time);
}

print_r($playerData);

?>

it should output List of players on that server but i get this :

Code:
Array ( [0] => Array ( [id] => 108 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [1] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [2] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [3] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [4] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [5] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [6] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [7] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [8] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [9] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 6 ) [time] => ) [10] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [11] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [12] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [13] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [14] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [15] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [16] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) [17] => Array ( [id] => 0 [name] => [kills] => Array ( [1] => 0 ) [time] => ) )
Reply
#2
anyone?
Reply
#3
Moved to the correct area.
~ Mooga ...w00t? - SRCDS.com on Twitter
[Image: 76561197965445574.png]
Please do not PM me for server related help
fqdn Wrote:if you've seen the any of the matrix movies, a game server is not all that different. it runs a version of the game that handles the entire world for each client connected. that's the 2 sentence explanation.
Reply
#4
$challenegeRequest = "\xFF\xFF\xFF\xFF\x55\xFF\xFF\xFF\xFF";
fwrite($socket, $challenegeRequest);

Big Grin
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)