some todo resolves

This commit is contained in:
kremsy
2014-03-01 11:11:50 +01:00
committed by Steffen Schröder
parent 5dcc8e865c
commit 7c4a038722
15 changed files with 66 additions and 90 deletions

View File

@ -10,6 +10,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
@ -53,7 +54,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
$this->maniaControl->callbackManager->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handlePlayerJoined');
}
@ -122,9 +123,9 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
}
/**
* Handle ManiaControl OnInit callback
* Handle ManiaControl AfterInit callback
*/
public function handleOnInit() {
public function handleAfterInit() {
$this->initCompleted = true;
$this->rebuildAndShowMenu();
}

View File

@ -2,7 +2,6 @@
namespace ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* Chat utility class
*
@ -68,15 +67,10 @@ class Chat {
return false;
}
$chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z';
try {
if ($login === null) {
$this->maniaControl->client->chatSendServerMessage($chatMessage);
} else {
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
}
} catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
return false;
if ($login === null) {
$this->maniaControl->client->chatSendServerMessage($chatMessage);
} else {
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
}
return true;
}

View File

@ -6,6 +6,7 @@ use FML\Controls\Frame;
use FML\Controls\Quad;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Players\Player;
@ -47,7 +48,7 @@ class IconManager implements CallbackListener {
$this->addDefaultIcons();
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
}
@ -88,7 +89,7 @@ class IconManager implements CallbackListener {
/**
* Handle OnInit Callback
*/
public function handleOnInit() {
public function handleAfterInit() {
$this->preloadIcons();
}

View File

@ -11,7 +11,6 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* Class offering commands to manage maps
@ -105,16 +104,10 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$map = $nextQueued[1];
$this->maniaControl->chat->sendInformation("Next map is $<" . $map->name . "$> from $<" . $map->authorNick . "$> requested by $<" . $requester->nickname . "$>.", $player->login);
} else {
try {
$mapIndex = $this->maniaControl->client->getNextMapIndex();
} catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
trigger_error("Error while Reading the next Map Index");
$this->maniaControl->chat->sendError("Error while Reading next Map Inde");
return;
}
$maps = $this->maniaControl->mapManager->getMaps();
$map = $maps[$mapIndex];
$mapIndex = $this->maniaControl->client->getNextMapIndex();
$maps = $this->maniaControl->mapManager->getMaps();
$map = $maps[$mapIndex];
$this->maniaControl->chat->sendInformation("Next map is $<" . $map->name . "$> from $<" . $map->authorNick . "$>.", $player->login);
}
}
@ -190,13 +183,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
return;
}
try {
$this->maniaControl->client->nextMap();
} catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
$this->maniaControl->chat->sendError("Error while Skipping the Map");
return;
}
$this->maniaControl->client->nextMap();
$message = '$<' . $player->nickname . '$> skipped the current Map!';
$this->maniaControl->chat->sendSuccess($message);
@ -217,12 +204,8 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$message = '$<' . $player->nickname . '$> restarted the current Map!';
$this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true);
try {
$this->maniaControl->client->restartMap();
} catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
//do nothing
}
$this->maniaControl->client->restartMap();
}
/**

View File

@ -545,23 +545,21 @@ class MapManager implements CallbackListener {
public function addMapFromMx($mapId, $login, $update = false) {
if (is_numeric($mapId)) {
// Check if map exists
$this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use ($login) {
$this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use (&$login, &$update) {
if (!$mapInfo || !isset($mapInfo->uploaded)) {
// Invalid id
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
return;
}
//Download the file
$function = function ($file, $error) use (&$login, &$mapInfo, &$mapDir, &$update) {
$this->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$login, &$mapInfo, &$mapDir, &$update) {
if (!$file) {
// Download error
$this->maniaControl->chat->sendError('Download failed!', $login);
return;
}
$this->processMapFile($file, $mapInfo, $mapDir, $login, $update);
};
$this->maniaControl->fileReader->loadFile($mapInfo->downloadurl, $function);
});
});
}
}

View File

@ -87,6 +87,7 @@ class PlayerActions {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 90: " . $e->getMessage());
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -96,6 +97,7 @@ class PlayerActions {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 100: " . $e->getMessage());
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -178,6 +180,7 @@ class PlayerActions {
try {
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(Exception $e) {
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 183: " . $e->getMessage());
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
//do nothing
}
@ -348,6 +351,7 @@ class PlayerActions {
}
} catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 354: " . $e->getMessage());
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}

View File

@ -107,6 +107,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
try {
$this->maniaControl->client->autoTeamBalance();
} catch(Exception $e) {
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerCommands Debug Line 110: " . $e->getMessage());
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;

View File

@ -650,6 +650,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
} catch(Exception $e) {
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerList Debug Line 653: " . $e->getMessage());
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
}
break;
@ -724,6 +725,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
} catch(Exception $e) {
//do nothing
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerList Debug Line 727: " . $e->getMessage());
}
});
break;
@ -747,6 +749,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
try {
$this->maniaControl->client->kick($target->login, $message);
} catch(Exception $e) {
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerList Debug Line 751: " . $e->getMessage());
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $target->login);
return;

View File

@ -20,7 +20,6 @@ class PlayerManager implements CallbackListener {
*/
const CB_PLAYERCONNECT = 'PlayerManagerCallback.PlayerConnect';
const CB_PLAYERDISCONNECT = 'PlayerManagerCallback.PlayerDisconnect';
const CB_ONINIT = 'PlayerManagerCallback.OnInit';
const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged';
const TABLE_PLAYERS = 'mc_players';
const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
@ -135,10 +134,6 @@ class PlayerManager implements CallbackListener {
$player->hasJoinedGame = true;
$this->addPlayer($player);
}
// Trigger own callback
// TODO: what for?
$this->maniaControl->callbackManager->triggerCallback(self::CB_ONINIT);
}
/**

View File

@ -30,14 +30,14 @@ class RankingManager implements CallbackListener {
*
* @param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) { //TODO statistic wins
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
//Register Callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
//TODO won message at end of the map (disable as setting)
//TODO won message at end of the map (disable as setting) (and public announce only all %50 (setting) players)
}
/**

View File

@ -60,7 +60,7 @@ class StatisticCollector implements CallbackListener {
*
* @param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) { //TODO statistic wins
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
//Register Callbacks