private function getlock($match, $model, $serv) { $Query = new SourceQuery(); if (!is_null($serv)) { $server = $serv; } else { $server = $model->getServersByID($match->sid); } /* if (is_null($server)) { return ''; }*/ $addr = explode(':', $server->addr); try { $Query->Connect($addr[0], $addr[1], 1, SourceQuery::SOURCE); $info = $Query->GetInfo(); $players = $info['Players']; $serverLock = $model->getServerLock($match->id, $server->id, INTERVAL_LOCK); if ($players == 0 && is_null($serverLock)) { return 'Go to our server : ' . $server->addr . ' <a href="steam://connect/' . $server->addr . '" id="join" title="Join">Join</a>'; } } catch (Exception $e) { return ' Error: ' . $e->getMessage(); //echo $e->getMessage(); } finally { $Query->Disconnect(); } return ' Error: Server not found'; }
private function LinkOnlinePlayers() { // $Timer = MicroTime(true); // $online = new SSQL().Players(new IPEndPoint(IPAddress.Parse(ipString), port))).ToList(); $Query = new SourceQuery(); try { $Query->Connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound // $Info = $Query->GetInfo(); $queryPlayers = $Query->GetPlayers(); // $Rules = $Query->GetRules(); // $Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' ); foreach ($queryPlayers as $key => $var) { $var = (object) $var; if (empty($var->Name)) { continue; } foreach ($this->Players as $key => $value) { if ($value->SteamName == $var->Name) { $this->Players[$value->Id]->Online = true; } } } } catch (Exception $e) { $Exception = $e; die($Exception->getMessage()); } finally { $Query->Disconnect(); } }
<?php require __DIR__ . '/../SourceQuery/bootstrap.php'; use xPaw\SourceQuery\SourceQuery; // For the sake of this example Header('Content-Type: text/plain'); Header('X-Content-Type-Options: nosniff'); // Edit this -> define('SQ_SERVER_ADDR', '69.30.238.74'); define('SQ_SERVER_PORT', 27017); define('SQ_TIMEOUT', 1); define('SQ_ENGINE', SourceQuery::SOURCE); // Edit this <- $Query = new SourceQuery(); try { $Query->Connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); //$info = $Query->GetInfo( ); //print_r( $Query->GetPlayers( ) ); //print_r( $Query->GetRules( ) ); } catch (Exception $e) { echo $e->getMessage(); } finally { $Query->Disconnect(); }
public function startServer($model, $match) { $servers = $model->getServersList(); //Header('Content-Type: text/plain'); //Header('X-Content-Type-Options: nosniff'); //define('SQ_TIMEOUT', 1); //define('SQ_ENGINE', SourceQuery::SOURCE); $Query = new SourceQuery(); foreach ($servers as $server) { $addr = explode(':', $server->addr); //define('SQ_SERVER_ADDR', $addr[0]); //define('SQ_SERVER_PORT', $addr[1]); try { $Query->Connect($addr[0], $addr[1], 1, SourceQuery::SOURCE); $info = $Query->GetInfo(); $players = $info['Players']; //print_r($Query->GetInfo()); //print_r($Query->GetPlayers()); //print_r($Query->GetRules()); $serverLock = $model->getServerLock($server->id, INTERVAL_LOCK); if ($players == 0 && is_null($serverLock)) { //$response['target_h']['#map_note'] = 'Go to our '. var_export($server->addr, true). ' '. var_export($match->id, true); $response['target_h']['#map_note'] = 'Go to our server : ' . $server->addr . ' <a href="steam://connect/' . $server->addr . '" id="join" title="Join">Join</a>'; $model->setMatchServer($match->id, $server->id); //update matches with server id break; } } catch (Exception $e) { $response['target_h']['#map_note'] = 'error: ' . $e->getMessage(); //echo $e->getMessage(); } finally { $Query->Disconnect(); } } }