Created
February 27, 2013 15:12
-
-
Save wpottier/5048624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Geekswire\Egames\SteamBundle\Manager; | |
class L4D2ServerManager | |
{ | |
/** | |
* @var \SourceServer | |
*/ | |
private $serverConnexion; | |
private $players = array(); | |
public function __construct($serverIp, $rconPassword, $serverPort = 27015) | |
{ | |
$this->serverConnexion = new \SourceServer($serverIp, $serverPort); | |
$this->serverConnexion->initialize(); | |
$this->serverConnexion->rconAuth($rconPassword); | |
} | |
public function updateStatus() | |
{ | |
$status = $this->serverConnexion->rconExec('status'); | |
var_dump($status); | |
$isInUserContext = false; | |
foreach (preg_split('/\\n/', $status) as $line) { | |
if (!$isInUserContext && strpos($line, '#') === 0) { | |
$isInUserContext = true; | |
} elseif ($isInUserContext && strpos($line, '#end') === 0) { | |
$isInUserContext = false; | |
} elseif ($isInUserContext) { | |
if (preg_match('/.*"(.*)" STEAM_([0-9]):([0-9]):([0-9]+)/', $line, $matches)) { | |
var_dump($matches); | |
echo $matches[1] . ' connected !'; | |
// "STEAM_X:Y:Z", where X, Y and Z are integers | |
$steamIdX = $matches[2]; | |
$steamIdY = $matches[3]; | |
$steamIdZ = $matches[4]; | |
$steamId64 = 0x0110000100000000; | |
$steamIdW = $steamIdZ * 2 + $steamId64 + $steamIdY; | |
var_dump($steamIdW); | |
$steamId = \SteamId::create($steamIdW); | |
var_dump($steamId->getGameStats('l4d2')->getHoursPlayed()); | |
echo '<br /><img src="' . $steamId->getFullAvatarUrl() . '" /><br />'; | |
$this->players[] = $line; | |
} | |
} | |
} | |
} | |
public function getPlayers() | |
{ | |
return $this->players; | |
} | |
public function forcePanicEvent() | |
{ | |
$this->serverConnexion->rconExec('director_force_panic_event'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment