Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use App\ServerMap as ServerMap;
- use Illuminate\Database\Eloquent\Model;
- class Server extends Model
- {
- public function __construct()
- {
- // steam condenser issue; must disable this error type for server queries to work
- error_reporting(~E_USER_NOTICE);
- }
- public function queryServer($connection)
- {
- $server = $connection->gameFlag ? new \SourceServer($connection->ip, $connection->port) : new \GoldSrcServer($connection->ip, $connection->port);
- $server->initialize();
- $serverAddress = $connection->ip . ':' . $connection->port;
- $serverInfo = $server->getServerInfo();
- return [
- 'serverAddress' => $serverAddress,
- 'serverName' => $serverInfo['serverName'],
- 'mapName' => $serverInfo['mapName'],
- 'population' => $serverInfo['numberOfPlayers'] . '/' . $serverInfo['maxPlayers'],
- 'gameId' => $serverInfo['gameId'],
- 'players' => $this->getServerPlayers($server),
- 'maps' => $this->getServerMaps($connection->id)
- ];
- }
- public function getServerMaps($id, $amount = 4)
- {
- return ServerMap::where('server_id', $id)
- ->orderBy('created_at', 'desc')
- ->orderBy('id', 'desc')
- ->take($amount)
- ->get();
- }
- public function getServerPlayers($server)
- {
- return array_map(function ($player) {
- return $player->getName();
- }, $server->getPlayers());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement