All pastes #74377 Raw Edit

Unnamed

public text v1 · immutable
#74377 ·published 2006-06-28 23:06 UTC
rendered paste body
<?php

class GameserversDefinition extends FAModelDefinition {
	function getPrimaryKey() {
		return 'id_gameserver';
	}
	
	function getTable() {
		return 'gameserver';
	}
	
	function getSelectOrder() {
		return 'address ASC';
	}
}

class GameserversRecord extends FARecord {
	function GameserversRecord(&$dba, &$def, &$finder, &$model, $current = array()) {
		$constructor = get_parent_class($this);
		parent::$constructor($dba, $def, $finder, $model, $current);
		
		$this->loadServer();
	}
	
	function getName() {
		return $this->_data->get('sv_hostname');
	}
	
	function getFullAddress() {
		return $this->_server->getAddress();
	}
	
	function getData() {
		return $this->_data->getRawData();
	}
	
	function getOnlinePlayers() {
		return count($this->_data->getPlayers());
	}
	
	function getMaxPlayers() {
		return $this->_data->get('sv_maxclients');
	}
	
	function getMod() {
		return $this->_data->get('gamename');
	}
	
	function getMap() {
		return $this->_data->get('mapname');
	}
	
	function getStatus() {
		return (int)$this->_server->_status;
	}
	
	function getPlayers() {
		return $this->_data->getPlayers();
	}
	
	function &getSettings() {
		$settings = $this->_data->getSettings();
		
		$buffer = array();
		foreach($settings as $name => $value) {
			$buffer[] = array('name' => $name, 'value' => $value);
		}
		
		return new FAArrayIterator($buffer);
	}
	
	function getNumSettings() {
		return count($this->_data->getSettings());
	}
	
	function loadServer() {
		$api = &new GameServerExtension;
		$this->_server = &$api->load('q3');
		$this->_server->setAddress($this->get('address'));
		$this->_server->connect();
		if($this->_server->getStatus())
			$this->_data = $this->_server->getData();
	}
}

?>