error fixes

This commit is contained in:
kremsy 2014-03-13 18:47:40 +01:00 committed by Steffen Schröder
parent d3cc9db29c
commit 79a771583e
7 changed files with 66 additions and 33 deletions

View File

@ -48,9 +48,13 @@ if (LOG_WRITE_CURRENT_FILE) {
function logMessage($message) { function logMessage($message) {
$message .= PHP_EOL; $message .= PHP_EOL;
if (defined('LOG_CURRENT_FILE')) { if (defined('LOG_CURRENT_FILE')) {
file_put_contents(LOG_CURRENT_FILE, $message, FILE_APPEND); if(!file_put_contents(LOG_CURRENT_FILE, $message, FILE_APPEND)){
echo "Logfile not Write-able, please check your file Permissions";
}
}
if(!file_put_contents(LOG_FILE, $message, FILE_APPEND)){
echo "Logfile not Write-able, please check your file Permissions";
} }
file_put_contents(LOG_FILE, $message, FILE_APPEND);
echo $message; echo $message;
} }

View File

@ -46,29 +46,29 @@ class CommandManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false) { public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false) {
if(is_array($commandName)) { if (is_array($commandName)) {
$success = true; $success = true;
foreach($commandName as $command) { foreach($commandName as $command) {
if(!$this->registerCommandListener($command, $listener, $method, $adminCommand)) { if (!$this->registerCommandListener($command, $listener, $method, $adminCommand)) {
$success = false; $success = false;
} }
} }
return $success; return $success;
} }
$command = strtolower($commandName); $command = strtolower($commandName);
if(!method_exists($listener, $method)) { if (!method_exists($listener, $method)) {
trigger_error("Given listener can't handle command '{$command}' (no method '{$method}')!"); trigger_error("Given listener can't handle command '{$command}' (no method '{$method}')!");
return false; return false;
} }
if($adminCommand) { if ($adminCommand) {
if(!array_key_exists($command, $this->adminCommandListeners) || !is_array($this->adminCommandListeners[$command])) { if (!array_key_exists($command, $this->adminCommandListeners) || !is_array($this->adminCommandListeners[$command])) {
// Init admin listeners array // Init admin listeners array
$this->adminCommandListeners[$command] = array(); $this->adminCommandListeners[$command] = array();
} }
// Register admin command listener // Register admin command listener
array_push($this->adminCommandListeners[$command], array($listener, $method)); array_push($this->adminCommandListeners[$command], array($listener, $method));
} else { } else {
if(!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) { if (!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
// Init listeners array // Init listeners array
$this->commandListeners[$command] = array(); $this->commandListeners[$command] = array();
} }
@ -92,7 +92,7 @@ class CommandManager implements CallbackListener {
$removed = false; $removed = false;
foreach($this->commandListeners as &$listeners) { foreach($this->commandListeners as &$listeners) {
foreach($listeners as $key => &$listenerCallback) { foreach($listeners as $key => &$listenerCallback) {
if($listenerCallback[0] == $listener) { if ($listenerCallback[0] == $listener) {
unset($listeners[$key]); unset($listeners[$key]);
$removed = true; $removed = true;
} }
@ -100,7 +100,7 @@ class CommandManager implements CallbackListener {
} }
foreach($this->adminCommandListeners as &$listeners) { foreach($this->adminCommandListeners as &$listeners) {
foreach($listeners as $key => &$listenerCallback) { foreach($listeners as $key => &$listenerCallback) {
if($listenerCallback[0] == $listener) { if ($listenerCallback[0] == $listener) {
unset($listeners[$key]); unset($listeners[$key]);
$removed = true; $removed = true;
} }
@ -116,14 +116,14 @@ class CommandManager implements CallbackListener {
*/ */
public function handleChatCallback(array $callback) { public function handleChatCallback(array $callback) {
// Check for command // Check for command
if(!$callback[1][3]) { if (!$callback[1][3]) {
return; return;
} }
// Check for valid player // Check for valid player
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if(!$player) { if (!$player) {
return; return;
} }
@ -131,18 +131,20 @@ class CommandManager implements CallbackListener {
$message = $callback[1][2]; $message = $callback[1][2];
$commandArray = explode(' ', $message); $commandArray = explode(' ', $message);
$command = ltrim(strtolower($commandArray[0]), '/'); $command = ltrim(strtolower($commandArray[0]), '/');
if(!$command) { if (!$command) {
return; return;
} }
if(substr($message, 0, 2) == '//' || $command == 'admin') { if (substr($message, 0, 2) == '//' || $command == 'admin') {
// Admin command // Admin command
$commandListeners = $this->adminCommandListeners; $commandListeners = $this->adminCommandListeners;
if($command == 'admin') { if ($command == 'admin') {
// Strip 'admin' keyword // Strip 'admin' keyword
$command = $commandArray[1]; if (isset($commandArray[1])) {
unset($commandArray[1]); $command = $commandArray[1];
unset($commandArray[1]);
}
} }
unset($commandArray[0]); unset($commandArray[0]);
@ -157,7 +159,7 @@ class CommandManager implements CallbackListener {
$commandListeners = $this->commandListeners; $commandListeners = $this->commandListeners;
} }
if(!array_key_exists($command, $commandListeners) || !is_array($commandListeners[$command])) { if (!array_key_exists($command, $commandListeners) || !is_array($commandListeners[$command])) {
// No command listener registered // No command listener registered
return; return;
} }

View File

@ -215,7 +215,7 @@ class Client
while(strlen($contents) < 8){ while(strlen($contents) < 8){
$newContent = fread($this->socket, 8 - strlen($contents)); $newContent = fread($this->socket, 8 - strlen($contents));
//var_dump($contents, $newContent, strlen($contents)); //var_dump($contents, $newContent, strlen($contents));
if(strlen($newContent) == 0){ if(strlen($newContent) === false){
var_dump("deb1 transport error" . $contents); var_dump("deb1 transport error" . $contents);
throw new FatalException('deb1 transport error - connection interrupted!' . $contents, FatalException::INTERRUPTED); throw new FatalException('deb1 transport error - connection interrupted!' . $contents, FatalException::INTERRUPTED);
} }

View File

@ -86,9 +86,14 @@ class PlayerActions {
try { try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER); $this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch(Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error) if ($e->getMessage() == 'There are too many players') {
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 90: " . $e->getMessage()); $this->maniaControl->chat->sendError("Too many Spectators");
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login); return;
} else {
// 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; return;
} }
@ -192,10 +197,11 @@ class PlayerActions {
if ($e->getMessage() == 'The player is not a spectator') { if ($e->getMessage() == 'The player is not a spectator') {
$this->kickPlayer($adminLogin, $targetLogin, 'Disconnect'); $this->kickPlayer($adminLogin, $targetLogin, 'Disconnect');
$this->maniaControl->errorHandler->triggerDebugNotice("inaktiv spec player kicked " . $e->getMessage()); $this->maniaControl->errorHandler->triggerDebugNotice("inaktiv spec player kicked " . $e->getMessage());
} else {
$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
} }
$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
} }
} }
} }

View File

@ -723,9 +723,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); $this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login); $this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(Exception $e) { } catch(Exception $e) {
//do nothing if ($e->getMessage() != 'Login unknown.') {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error) //do nothing
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerList Debug Line 727: " . $e->getMessage()); // 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; break;

View File

@ -196,7 +196,9 @@ class StatisticManager {
case self::SPECIAL_STAT_KD_RATIO: case self::SPECIAL_STAT_KD_RATIO:
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex); $kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex);
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex); $deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex);
if(!$kills || !$deaths){
return array();
}
foreach($deaths as $key => $death) { foreach($deaths as $key => $death) {
if ($death == 0 || !isset($kills[$key])) { if ($death == 0 || !isset($kills[$key])) {
continue; continue;
@ -208,6 +210,9 @@ class StatisticManager {
case self::SPECIAL_STAT_HITS_PH: case self::SPECIAL_STAT_HITS_PH:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex);
$times = $this->getStatsRanking(StatisticCollector::STAT_PLAYTIME, $serverIndex); $times = $this->getStatsRanking(StatisticCollector::STAT_PLAYTIME, $serverIndex);
if(!$hits || !$times){
return array();
}
foreach($times as $key => $time) { foreach($times as $key => $time) {
if ($time == 0 || !isset($hits[$key])) { if ($time == 0 || !isset($hits[$key])) {
continue; continue;
@ -219,6 +224,9 @@ class StatisticManager {
case self::SPECIAL_STAT_ARROW_ACC: case self::SPECIAL_STAT_ARROW_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_ARROW_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_ARROW_SHOT, $serverIndex);
if(!$hits || !$shots){
return array();
}
foreach($shots as $key => $shot) { foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) { if ($shot == 0 || !isset($hits[$key])) {
continue; continue;
@ -230,6 +238,9 @@ class StatisticManager {
case self::SPECIAL_STAT_LASER_ACC: case self::SPECIAL_STAT_LASER_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_LASER_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_LASER_SHOT, $serverIndex);
if(!$hits || !$shots){
return array();
}
foreach($shots as $key => $shot) { foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) { if ($shot == 0 || !isset($hits[$key])) {
continue; continue;
@ -241,6 +252,9 @@ class StatisticManager {
case self::SPECIAL_STAT_ROCKET_ACC: case self::SPECIAL_STAT_ROCKET_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_SHOT, $serverIndex);
if(!$hits || !$shots){
return array();
}
foreach($shots as $key => $shot) { foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) { if ($shot == 0 || !isset($hits[$key])) {
continue; continue;
@ -252,6 +266,9 @@ class StatisticManager {
case self::SPECIAL_STAT_NUCLEUS_ACC: case self::SPECIAL_STAT_NUCLEUS_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_SHOT, $serverIndex);
if(!$hits || !$shots){
return array();
}
foreach($shots as $key => $shot) { foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) { if ($shot == 0 || !isset($hits[$key])) {
continue; continue;

View File

@ -352,7 +352,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$this->maniaControl->chat->sendChat($msg, null, false); $this->maniaControl->chat->sendChat($msg, null, false);
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)) {
if($player->isSpectator){ if ($player->isSpectator) {
return; return;
} }
@ -370,9 +370,11 @@ class ChatMessagePlugin implements CommandListener, Plugin {
try { try {
$this->maniaControl->client->spectatorReleasePlayerSlot($player->login); $this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
} catch(Exception $e) { } catch(Exception $e) {
$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage()); if ($e->getMessage() != 'The player is not a spectator') {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error) $this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
//to nothing // TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
//to nothing
}
} }
} }
} }