function onTick() { $this->tick++; switch ($this->state) { case self::OVER: case self::SLEEPING: break; case self::WAITING: case self::DECIDING: case self::PLAYING: break; case self::PLAYER_LEFT: case self::WAITING_BACKUPS: break; } if (new \DateTime() < $this->nextTick) { return; } switch ($this->state) { case self::SLEEPING: //Waiting for a match in database $match = $this->matchMakingService->getServerCurrentMatch($this->storage->serverLogin, $this->scriptName, $this->titleIdString); if ($match) { $this->prepare($match); } else { $this->sleep(); } break; case self::WAITING: //Waiting for players, if Match change or cancel, change state and wait $this->waitingTime += 5; \ManiaLive\Utilities\Logger::debug(sprintf('waiting time %d', $this->waitingTime)); $match = $this->matchMakingService->getServerCurrentMatch($this->storage->serverLogin, $this->scriptName, $this->titleIdString); if ($this->waitingTime > static::TIME_WAITING_CONNECTION) { \ManiaLive\Utilities\Logger::debug('Waiting time over'); foreach ($this->players as $login => $state) { if ($state == Services\PlayerInfo::PLAYER_STATE_NOT_CONNECTED) { $this->updateMatchPlayerState($login, Services\PlayerInfo::PLAYER_STATE_QUITTER); } } $this->waitBackups(); break; } if ($match === false) { \ManiaLive\Utilities\Logger::debug('Match was prepared but not in database anymore (canceled on lobby ?'); $this->cancel(false); break; } if ($this->match->isDifferent($match)) { $this->prepare($match); break; } $this->changeState(self::WAITING); break; case self::DECIDING: \ManiaLive\Utilities\Logger::debug('tick: DECIDING'); $this->play(); break; case static::PLAYING: $this->changeState(static::PLAYING); break; case self::PLAYER_LEFT: \ManiaLive\Utilities\Logger::debug('tick: PLAYER_LEFT'); $this->waitBackups(); break; case self::WAITING_BACKUPS: switch ($this->config->waitingForBackups) { case 0: $isWaitingTimeOver = true; break; case 2: $isWaitingTimeOver = false; break; case 1: //nobreak //nobreak default: $isWaitingTimeOver = ++$this->waitingBackupTime > static::TIME_WAITING_BACKUP; break; } if ($isWaitingTimeOver) { \ManiaLive\Utilities\Logger::debug('tick: WAITING_BACKUPS over'); $this->cancel(); } else { $match = $this->matchMakingService->getServerCurrentMatch($this->storage->serverLogin, $this->scriptName, $this->titleIdString); if ($match && $this->match->isDifferent($match)) { $this->updatePlayerList($match); } $this->changeState(self::WAITING_BACKUPS); } break; case self::OVER: \ManiaLive\Utilities\Logger::debug('tick: OVER'); $this->end(); } }