Raised This Month: $ Target: $400
 0% 

[PHP] Check if SteamID is connected to Server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 10-20-2013 , 07:53   [PHP] Check if SteamID is connected to Server
Reply With Quote #1

Hey everyone,

I'd like to ask how I can check if a player (here the SteamID) is connected to a server using PHP.
I need that for my next mod.

Greetz, Kia.
__________________
Kia is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-20-2013 , 08:03   Re: [PHP] Check if SteamID is connected to Server
Reply With Quote #2

You will have to connect to the server using RCON and send the command status and then parse the results
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-20-2013 , 10:28   Re: [PHP] Check if SteamID is connected to Server
Reply With Quote #3

There might be a way to do it without the background plugin on the server. I don't know how to.
PHP Code:
<?php

define
("SERV_PORT""");
define("SERV_IP",  "");
define("SERV_RCON""");

require 
"SourceQuery/SourceQuery.class.php";

$query = new SourceQuery();

try {
    
$query->Connect(SERV_IPSERV_PORT3SourceQuery::GOLDSOURCE);
    
$query->SetRconPassword(SERV_RCON);
    
$return $query->Rcon("_SteamID_Check  \"" "STEAM_1:23456789" "\"");
}
catch( 
SQueryException $e ) {
    echo 
$e -> getMessage( );
}

$query -> Disconnect();

echo 
$return;

?>
Code:
#include <amxmodx> public plugin_init() {     register_plugin("Test Plugin 4", "", "");         register_srvcmd("_SteamID_Check", "cmd_SteamID_Check"); } public cmd_SteamID_Check() {         new SteamID[32], pSteamID[32], pName[32];     read_argv(1, SteamID, charsmax(SteamID));         new players[32], playersnum;     get_players(players, playersnum, "c");         for ( new i = 0 ; i < playersnum ; i++ ) {                 get_user_authid(players[i], pSteamID, charsmax(pSteamID));                 if ( equali(SteamID, pSteamID) ) {             get_user_name(players[i], pName, charsmax(pName));             server_print("%s was found, named %s", pSteamID, pName);             return;         }     }         server_print("Sorry, no match.<br>Here is a list of the players online:<br>");         for ( new i = 0 ; i < playersnum ; i++ ) {         get_user_authid(players[i], pSteamID, charsmax(pSteamID));         get_user_name(players[i], pName, charsmax(pName));         server_print("%s %s<br>", pSteamID, pName);     } }

With SteamID 1:23456789
Code:
Sorry, no match.
Here is a list of the players online:
STEAM_0:1:*snip*182 PFM* NAKNO-EMO ,,talani
With the SteamID that was online:
Code:
STEAM_0:1:*snip*182 was found, named PFM* NAKNO-EMO ,,talani
__________________

Last edited by Black Rose; 10-20-2013 at 10:38.
Black Rose is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 10-20-2013 , 11:15   Re: [PHP] Check if SteamID is connected to Server
Reply With Quote #4

Thanks.
__________________
Kia is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-20-2013 , 17:05   Re: [PHP] Check if SteamID is connected to Server
Reply With Quote #5

Using only PHP, requires PHP Source Query Class

PHP Code:
<?php

require_once("SourceQuery/SourceQuery.class.php");

// Edit this ->
$values['address']  = "127.0.0.1";
$values['port']     = 27015;
$values['timeout']  = 1;
$values['engine']   = SourceQuery::GOLDSOURCE;
$values['rcon']     = "test";
// Edit this <-

$query = new SourceQuery();

try
{
    
$query->Connect($values['address'], $values['port'], $values['timeout'], $values['engine']);
    
    
$query->SetRconPassword($values['rcon']);
    
    
$return $query->Rcon("status");
    
$status explode("\n"$return);
    
    
$players = array();
    for (
$k 7$k count($status)-1$k++)
    {
        
$player explode(" "$status[$k]);
        
$players[] = $player;
    }
    
    
/* $players format
     * 1 = Index
     * 2 = Name
     * 3 = UserID
     * 4 = SteamID
     * 7 = Frags
     * 8 = Connection Time
     * 11 = Ping
     * 15 = Loss
     * 16 = IP
     */
}
catch( 
Exception $e )
{
    echo 
$e->getMessage( );
}

$query->Disconnect( );
After the for loop, the $players array will contain the details about the connected users. Refer to the comment block about what index in the array contains what value. Example, to get the first player's SteamID, $players[0][4]
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 10-20-2013 at 17:07.
YamiKaitou is offline
Reply



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 01:09.


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