server empty callback

This commit is contained in:
Steffen Schröder 2014-05-04 16:45:59 +02:00
parent 3b4f21d482
commit 5219e0206c

View File

@ -25,6 +25,7 @@ class PlayerManager implements CallbackListener, TimerListener {
const CB_PLAYERCONNECT = 'PlayerManagerCallback.PlayerConnect'; const CB_PLAYERCONNECT = 'PlayerManagerCallback.PlayerConnect';
const CB_PLAYERDISCONNECT = 'PlayerManagerCallback.PlayerDisconnect'; const CB_PLAYERDISCONNECT = 'PlayerManagerCallback.PlayerDisconnect';
const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged'; const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged';
const CB_SERVER_EMPTY = 'PlayerManagerCallback.ServerEmpty';
const TABLE_PLAYERS = 'mc_players'; const TABLE_PLAYERS = 'mc_players';
const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages'; const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
const STAT_JOIN_COUNT = 'Joins'; const STAT_JOIN_COUNT = 'Joins';
@ -48,7 +49,7 @@ class PlayerManager implements CallbackListener, TimerListener {
/** /**
* Construct a new Player Manager * Construct a new Player Manager
* *
* @param \ManiaControl\ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
@ -76,7 +77,7 @@ class PlayerManager implements CallbackListener, TimerListener {
} }
/** /**
* Initialize necessary database tables * Initialize necessary Database Tables
* *
* @return bool * @return bool
*/ */
@ -100,6 +101,7 @@ class PlayerManager implements CallbackListener, TimerListener {
$playerTableStatement->execute(); $playerTableStatement->execute();
if ($playerTableStatement->error) { if ($playerTableStatement->error) {
trigger_error($playerTableStatement->error, E_USER_ERROR); trigger_error($playerTableStatement->error, E_USER_ERROR);
$playerTableStatement->close();
return false; return false;
} }
$playerTableStatement->close(); $playerTableStatement->close();
@ -212,7 +214,7 @@ class PlayerManager implements CallbackListener, TimerListener {
} }
/** /**
* Handle playerConnect callback * Handle PlayerConnect Callback
* *
* @param array $callback * @param array $callback
*/ */
@ -228,7 +230,7 @@ class PlayerManager implements CallbackListener, TimerListener {
} }
/** /**
* Handle playerDisconnect callback * Handle PlayerDisconnect callback
* *
* @param array $callback * @param array $callback
*/ */
@ -239,8 +241,11 @@ class PlayerManager implements CallbackListener, TimerListener {
return; return;
} }
// Trigger own callback // Trigger own callbacks
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECT, $player); $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECT, $player);
if ($this->getPlayerCount(false) <= 0) {
$this->maniaControl->callbackManager->triggerCallback(self::CB_SERVER_EMPTY);
}
if ($player->isFakePlayer()) { if ($player->isFakePlayer()) {
return; return;
@ -292,6 +297,23 @@ class PlayerManager implements CallbackListener, TimerListener {
return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->server->index, $playedTime); return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->server->index, $playedTime);
} }
/**
* Get the Count of all Player
*
* @param bool $withoutSpectators
* @return int
*/
public function getPlayerCount($withoutSpectators = true) {
$count = 0;
foreach ($this->players as $player) {
/** @var Player $player */
if (!$player->isSpectator || !$withoutSpectators) {
$count++;
}
}
return $count;
}
/** /**
* Update PlayerInfo * Update PlayerInfo
* *
@ -401,22 +423,6 @@ class PlayerManager implements CallbackListener, TimerListener {
return $this->players; return $this->players;
} }
/**
* Gets the Count of all Player
*
* @return int
*/
public function getPlayerCount() {
$count = 0;
foreach ($this->players as $player) {
/** @var Player $player */
if (!$player->isSpectator) {
$count++;
}
}
return $count;
}
/** /**
* Gets the Count of all Spectators * Gets the Count of all Spectators
* *
@ -436,7 +442,7 @@ class PlayerManager implements CallbackListener, TimerListener {
/** /**
* Gets a Player by his index * Gets a Player by his index
* *
* @param $index * @param int $index
* @param bool $connectedPlayersOnly * @param bool $connectedPlayersOnly
* @return Player|null * @return Player|null
*/ */
@ -456,9 +462,9 @@ class PlayerManager implements CallbackListener, TimerListener {
} }
/** /**
* Get's a Player out of the database * Get a Player out of the database
* *
* @param $playerIndex * @param int $playerIndex
* @return Player $player * @return Player $player
*/ */
private function getPlayerFromDatabaseByIndex($playerIndex) { private function getPlayerFromDatabaseByIndex($playerIndex) {