AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   HL1 Servers (HLDS) (https://forums.alliedmods.net/forumdisplay.php?f=131)
-   -   Solved Get players and steam id with php rcon (https://forums.alliedmods.net/showthread.php?t=321468)

4ever16 02-12-2020 08:44

Get players and steam id with php rcon
 
I have rcon password.
I use SourceQuery but i dont understand how to get only player name and steam id without other shit inofmration.

How to do that?

I use this code in php.
Quote:

echo $Query->Rcon( 'status' );
It prints this shit. I just need name and steam id.
Quote:

hostname: SERVERNAME
version : 48/1.1.2.7/Stdio 2117 secure (10)
tcp/ip : SERVER IP
map : de_dust2 at: 0 x, 0 y, 0 z
players : 1 active (12 max)

# name userid uniqueid frag time ping loss adr
# 1 "test" 42 STEAM_0:1:232323232323232 0 52:16 35 0 44.44444.444.44:27005
1 users

fysiks 02-12-2020 22:09

Re: Get players and steam id with php rcon
 
That is what the status command does for you. If you need just the player names and SteamIDs, you need to parse the status output.

DruGzOG 02-12-2020 22:29

Re: Get players and steam id with php rcon
 
Kinda weird your player has that unique id

fysiks 02-12-2020 22:45

Re: Get players and steam id with php rcon
 
Quote:

Originally Posted by DruGzOG (Post 2683585)
Kinda weird your player has that unique id

No need to assume the worst right away, many people anonymize their status outputs when posting to forums.

DruGzOG 02-13-2020 00:20

Re: Get players and steam id with php rcon
 
Quote:

Originally Posted by fysiks (Post 2683588)
No need to assume the worst right away, many people anonymize their status outputs when posting to forums.

No assumptions, just unique that's all

Napoleon_be 02-13-2020 08:53

Re: Get players and steam id with php rcon
 
Quote:

Originally Posted by DruGzOG (Post 2683596)
No assumptions, just unique that's all

it's called a unique id after all.

4ever16 02-13-2020 17:15

Re: Get players and steam id with php rcon
 
Quote:

Originally Posted by fysiks (Post 2683582)
That is what the status command does for you. If you need just the player names and SteamIDs, you need to parse the status output.

What do you mean by parse status output? My english isnt the best.

fysiks 02-13-2020 23:45

Re: Get players and steam id with php rcon
 
1 Attachment(s)
"parse" means to break the information down into the parts that you want. All the information that you want is in the status output, you just need to get that data out of the whole "mess".

It looks like it shouldn't be too hard. First get each of the lines that contains a player and use str_getcsv() with the delimiter set to " " (a space) on that line. This should give you an array with the name at index 2 and the SteamID at index 4 of the returned array. Do that on each line while saving the name and SteamID into your new array that contains only the data you need.

I'm sure you're capable of getting it to work just fine. Just take your time and test your code. For example, manually test each step of the code with hard coded test data to make sure that you know it works. Basically, you can work backwards from the smaller steps. I'd probably test simply using str_getcsv() on a single player line of the status output.

Attached is a PHP function for parsing the status (change the extension to ".php" and then you can use require() to include it in your script). Simply pass your string to it and print it out to see how it's structured:

PHP Code:

print_r(parse_hlds_status($YourStatusString)); 


4ever16 02-14-2020 07:29

Re: Get players and steam id with php rcon
 
Im getting this output with this this code combined with yours.
PHP Code:

Array ( [hostname] => [version] => [tcp/ip] => [map] => [maxplayers] => [Players] => Array ( ) ) 

Php code.
PHP Code:

<?php
require 'SourceQuery.class.php';    
$Query = new SourceQuery( );
    
try
{
$Query->Connect'SERVER IP'27015 );        
$Query->SetRconPassword'rcon password' );            
$StatusString $Query->Rcon'status' );    

function 
parse_hlds_status($StatusString)
{
    
// parse everything up to the player list
    
$StatusArray preg_split("/(\r\n|\n|\r)/"$StatusString);
    
    
$out['hostname'] = array_shift($StatusArray);
    
$out['version'] = array_shift($StatusArray);
    
$out['tcp/ip'] = array_shift($StatusArray);
    
$out['map'] = array_shift($StatusArray);
    
$out['maxplayers'] = array_shift($StatusArray);
    
    
array_shift($StatusArray); // Get rid of blank line
    
    // Parse player list
    
$PlayerListString $StatusArray// Including header row
    
array_pop($PlayerListString);
    
    
// Parse headers
    
$header str_getcsv(array_shift($PlayerListString), $delimiter " ");
    
    
// Parse players
    
$PlayerList array_map('parse_player_line'$PlayerListString);
    
array_walk($PlayerList'_combine_array'$header);
    
    
$out['Players'] = $PlayerList;
    
    return 
$out;
}

// Define private functions
function _combine_array(&$row$key$header)
{
    
$row array_combine($header$row);
}

function 
parse_player_line($string)
{
    
$temp str_getcsv($string$delimiter " ");
    
array_shift($temp);
    return 
$temp;




print_r(parse_hlds_status($YourStatusString)); 
    


$Query->Disconnect( );
    }
catch( 
SQueryException $e )
    {
$Query->Disconnect( );
    }
echo 
'';
?>


fysiks 02-14-2020 22:01

Re: Get players and steam id with php rcon
 
You are not passing your status string to the function. You need to replace "$YourStatusString" with your variable.


All times are GMT -4. The time now is 04:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.