small bug fixes, time delay playerjoin

This commit is contained in:
kremsy 2014-03-02 11:25:47 +01:00 committed by Steffen Schröder
parent 90568f1d43
commit 2f9cab62fa
4 changed files with 33 additions and 21 deletions

View File

@ -43,7 +43,7 @@ class TimerManager {
* @return bool
*/
public function registerTimerListening(TimerListener $listener, $method, $time, $oneTime = false) {
if (!method_exists($listener, $method) && !is_callable($method)) {
if ((!is_string($method) || !method_exists($listener, $method)) && !is_callable($method)) {
trigger_error("Given listener (" . get_class($listener) . ") can't handle timer (no method '{$method}')!");
return false;
}
@ -54,9 +54,12 @@ class TimerManager {
$listening->listener = $listener;
$listening->method = $method;
$listening->deltaTime = $time / 1000;
$listening->lastTrigger = -1;
$listening->oneTime = $oneTime;
if($oneTime){
$listening->lastTrigger = microtime(true);
}else{
$listening->lastTrigger = -1;
}
array_push($this->timerListenings, $listening);
return true;

View File

@ -1,6 +1,7 @@
<?php
namespace ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* Chat utility class
@ -70,7 +71,13 @@ class Chat {
if ($login === null) {
$this->maniaControl->client->chatSendServerMessage($chatMessage);
} else {
try{
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
} catch(Exception $e){
if($e->getMessage() != "Login unknown."){
throw $e;
}
}
}
return true;
}

View File

@ -5,6 +5,7 @@ namespace ManiaControl\Players;
use ManiaControl\Admin\AdminLists;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Statistics\StatisticManager;
@ -14,7 +15,7 @@ use ManiaControl\Statistics\StatisticManager;
*
* @author kremsy & steeffeen
*/
class PlayerManager implements CallbackListener {
class PlayerManager implements CallbackListener, TimerListener {
/**
* Constants
*/
@ -203,21 +204,24 @@ class PlayerManager implements CallbackListener {
//Check if Player finished joining the game
if($player->hasJoinedGame && !$prevJoinState){
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
$this->maniaControl->chat->sendChat($chatMessage);
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
}
//Delay join on 5secs to avoid the non appearing widgets in tm
$this->maniaControl->timerManager->registerOneTimeListening($this, function($time) use (&$player){
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
$this->maniaControl->chat->sendChat($chatMessage);
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
}
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
$this->maniaControl->log($logMessage);
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
$this->maniaControl->log($logMessage);
// Increment the Player Join Count
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->index);
// Increment the Player Join Count
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->index);
// Trigger own PlayerJoined callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player);
// Trigger own PlayerJoined callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player);
}, 2000);
}
// Trigger own callback

View File

@ -97,7 +97,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'importMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'sendMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
// Define player stats
@ -239,11 +239,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
/**
* Handle PlayerConnect callback
*
* @param array $callback
* @param \ManiaControl\Players\Player $player
*/
public function handlePlayerConnect(array $callback) {
$login = $callback[1][0];
$player = $this->maniaControl->playerManager->getPlayer($login);
public function handlePlayerConnect(Player $player) {
if (!$player) {
return;
}