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

View File

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

View File

@ -5,6 +5,7 @@ namespace ManiaControl\Players;
use ManiaControl\Admin\AdminLists; use ManiaControl\Admin\AdminLists;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Statistics\StatisticManager; use ManiaControl\Statistics\StatisticManager;
@ -14,7 +15,7 @@ use ManiaControl\Statistics\StatisticManager;
* *
* @author kremsy & steeffeen * @author kremsy & steeffeen
*/ */
class PlayerManager implements CallbackListener { class PlayerManager implements CallbackListener, TimerListener {
/** /**
* Constants * Constants
*/ */
@ -203,6 +204,8 @@ class PlayerManager implements CallbackListener {
//Check if Player finished joining the game //Check if Player finished joining the game
if($player->hasJoinedGame && !$prevJoinState){ if($player->hasJoinedGame && !$prevJoinState){
//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()) { 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'); $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!'; $chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
@ -218,6 +221,7 @@ class PlayerManager implements CallbackListener {
// Trigger own PlayerJoined callback // Trigger own PlayerJoined callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player); $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player);
}, 2000);
} }
// Trigger own callback // 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, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'importMxKarmaVotes'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'importMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'sendMxKarmaVotes'); $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'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
// Define player stats // Define player stats
@ -239,11 +239,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
/** /**
* Handle PlayerConnect callback * Handle PlayerConnect callback
* *
* @param array $callback * @param \ManiaControl\Players\Player $player
*/ */
public function handlePlayerConnect(array $callback) { public function handlePlayerConnect(Player $player) {
$login = $callback[1][0];
$player = $this->maniaControl->playerManager->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }