• PHP Query Source Server - Exploding?
    6 replies, posted
Hey there, So, I was thinking of a way to workaround the non existant [steamid] $_GET variable for the loading screen, and thought of this solution: 1) Query game server each time loading page is rendered 2) Gather IPs and SteamIDs of all players connecting 3) Compare to IP loading the loading page 4) Get SteamID relating to that IP from server output 5) Do stuff. I have only got this far: [url]http://sammyservers.com/server/yup.php[/url] And for them, I'm using this class: [url]http://pastebin.com/6cYpQriG[/url] with the following: [php] <?php include_once("rcon.class.php"); $oTest = new clsRcon('66.90.103.33', 27083, 'xxxx'); $oTest->connect(); $aResponse = $oTest->rcon('status'); echo '<pre>'; ob_start(); var_dump($aResponse[0]['String1']); $a=ob_get_contents(); ob_end_clean(); echo htmlspecialchars($a,ENT_QUOTES); echo '</pre>'; ?> [/php] What would be the best way to go about splitting that output up into 3 variables for each person, name, steamid, and ip?
explode()?
[QUOTE=supersnail11;27486415]explode()?[/QUOTE] Easier said than done. Where would I explode? Every " ", or at every "#", then to string, and then explode that again? I was asking here, if there was a better way to do that, perhaps matching some regex pattern or the likes?
Maybe you could add a serverside command that lists the players in an easily explodeable format using Lua and then run that?
Paste a sample line, and I'll come up with a regex to match out all the data you need.
[QUOTE=^seth;27487744]Maybe you could add a serverside command that lists the players in an easily explodeable format using Lua and then run that?[/QUOTE] /garrysmod/lua/autorun/server/playerlisting.lua: [lua]if SERVER then function playerList(ply, cmd, args) if ply:EntIndex() ~= 0 then return ply:Msg("Not Authorized!") end local list = {} for k, v in pairs(player.getAll()) do list.insert(v:SteamID()) end return table.concat(list, ",") end concommand.Add("listplayers", playerList) end[/lua] I'm not the greatest at Lua, but I guess that may work. Fizzidar knows this better than I do v:v:v
Thanks for the help everyone. A friend of mine solved it for me with: [php] function getInfoPlayer($data){ $lines = explode('#',$data); $find_ip = '/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/'; $find_steam = '/STEAM_[0-9]:[0-5]:[0-9]{1,55}/'; $players = array(); foreach($lines as $key => $line){ if($key > 1){ preg_match($find_ip,$line,$ip,PREG_OFFSET_CAPTURE); preg_match($find_steam,$line,$steamid,PREG_OFFSET_CAPTURE); $players[] = array( 'ip' => $ip[0][0], 'steamid' => $steamid[0][0], ); } } return $players; } [/php]
Sorry, you need to Log In to post a reply to this thread.