Raised This Month: $204 Target: $400
 51% 

Solved Get players and steam id with php rcon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
4ever16
Veteran Member
Join Date: Apr 2015
Old 02-12-2020 , 09:44   Get players and steam id with php rcon
Reply With Quote #1

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

Last edited by 4ever16; Yesterday at 19:46.
4ever16 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-12-2020 , 23:09   Re: Get players and steam id with php rcon
Reply With Quote #2

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.
__________________
fysiks is offline
DruGzOG
Veteran Member
Join Date: Nov 2007
Location: Unknown
Old 02-12-2020 , 23:29   Re: Get players and steam id with php rcon
Reply With Quote #3

Kinda weird your player has that unique id
__________________

Home of the AMX SUPER
Discord
DruGzOG is offline
Send a message via AIM to DruGzOG
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-12-2020 , 23:45   Re: Get players and steam id with php rcon
Reply With Quote #4

Quote:
Originally Posted by DruGzOG View Post
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.
__________________

Last edited by fysiks; 02-12-2020 at 23:47.
fysiks is offline
DruGzOG
Veteran Member
Join Date: Nov 2007
Location: Unknown
Old 02-13-2020 , 01:20   Re: Get players and steam id with php rcon
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
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
__________________

Home of the AMX SUPER
Discord
DruGzOG is offline
Send a message via AIM to DruGzOG
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 02-13-2020 , 09:53   Re: Get players and steam id with php rcon
Reply With Quote #6

Quote:
Originally Posted by DruGzOG View Post
No assumptions, just unique that's all
it's called a unique id after all.
__________________


My Plugins:

Last edited by Napoleon_be; 02-13-2020 at 09:54.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
4ever16
Veteran Member
Join Date: Apr 2015
Old 02-13-2020 , 18:15   Re: Get players and steam id with php rcon
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
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.
4ever16 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-14-2020 , 00:45   Re: Get players and steam id with php rcon
Reply With Quote #8

"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.

I wrote a quick function for fun (it doesn't properly parse the non-player data but the player data is there):

PHP Code:
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 explode_by_whitespace(array_shift($PlayerListString));
    
    
// 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 = array();
    
$temp[0] = trim(substr($string12)); // Get the fixed-width player slot number
    
$temp array_merge($tempexplode_by_whitespace(substr($string4))); // The reset is whitespace delimited (not space delimited)
    
return $temp;
}

function 
explode_by_whitespace($string)
{
    
$pattern '/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/';
    
$matches = array();
    
$i 0;
    
$out = array();
    while( 
preg_match($pattern$string$matchesPREG_OFFSET_CAPTURE$i) )
    {
        
array_push($out$matches[0][0]);
        
$i $matches[0][1] + strlen($matches[0][0]);
    }
    return 
$out;

Simply pass your string to it and print it out to see how it's structured:

PHP Code:
print_r(parse_hlds_status($YourStatusString)); 
__________________

Last edited by fysiks; Yesterday at 19:01. Reason: Updated based on his server's output
fysiks is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 02-14-2020 , 08:29   Re: Get players and steam id with php rcon
Reply With Quote #9

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 
'';
?>
4ever16 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-14-2020 , 23:01   Re: Get players and steam id with php rcon
Reply With Quote #10

You are not passing your status string to the function. You need to replace "$YourStatusString" with your variable.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:37.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode