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) {
$message .= PHP_EOL;
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;
}

View File

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

View File

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

View File

@ -86,9 +86,14 @@ class PlayerActions {
try {
$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);
if ($e->getMessage() == 'There are too many players') {
$this->maniaControl->chat->sendError("Too many Spectators");
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;
}
@ -192,10 +197,11 @@ class PlayerActions {
if ($e->getMessage() == 'The player is not a spectator') {
$this->kickPlayer($adminLogin, $targetLogin, 'Disconnect');
$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->spectatorReleasePlayerSlot($target->login);
} 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());
if ($e->getMessage() != 'Login unknown.') {
//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;

View File

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

View File

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