improved error handling
This commit is contained in:
		| @@ -6,7 +6,6 @@ use ManiaControl\Commands\CommandListener; | |||||||
| use ManiaControl\ManiaControl; | use ManiaControl\ManiaControl; | ||||||
| use ManiaControl\Players\Player; | use ManiaControl\Players\Player; | ||||||
| use ManiaControl\Plugins\Plugin; | use ManiaControl\Plugins\Plugin; | ||||||
| use Maniaplanet\DedicatedServer\Xmlrpc\Exception; |  | ||||||
| use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException; | use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -362,11 +361,8 @@ class ChatMessagePlugin implements CommandListener, Plugin { | |||||||
| 		$message = '$39F Thanks for Playing, see you around!$z'; | 		$message = '$39F Thanks for Playing, see you around!$z'; | ||||||
| 		try { | 		try { | ||||||
| 			$this->maniaControl->client->kick($player->login, $message); | 			$this->maniaControl->client->kick($player->login, $message); | ||||||
| 		} catch (Exception $e) { | 		} catch (UnknownPlayerException $exception) { | ||||||
| 			$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line 316: " . $e->getMessage()); | 			$this->maniaControl->chat->sendException($exception, $player); | ||||||
| 			// TODO: only possible valid exception should be "wrong login" - throw others (like connection error) |  | ||||||
| 			$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); |  | ||||||
| 			return; |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -377,12 +373,11 @@ class ChatMessagePlugin implements CommandListener, Plugin { | |||||||
| 	 * @param Player $player | 	 * @param Player $player | ||||||
| 	 */ | 	 */ | ||||||
| 	public function chat_ragequit(array $chat, Player $player) { | 	public function chat_ragequit(array $chat, Player $player) { | ||||||
|  | 		try { | ||||||
|  | 			$message = '$39F Thanks for Playing, please come back soon!$z '; | ||||||
|  | 			$this->maniaControl->client->kick($player->login, $message); | ||||||
| 			$msg = '$i$ff0 $<' . $player->nickname . '$>$s$f00 said: "@"#!" and ragequitted!'; | 			$msg = '$i$ff0 $<' . $player->nickname . '$>$s$f00 said: "@"#!" and ragequitted!'; | ||||||
| 			$this->maniaControl->chat->sendChat($msg, null, true); | 			$this->maniaControl->chat->sendChat($msg, null, true); | ||||||
|  |  | ||||||
| 		$message = '$39F Thanks for Playing, please come back soon!$z '; |  | ||||||
| 		try { |  | ||||||
| 			$this->maniaControl->client->kick($player->login, $message); |  | ||||||
| 		} catch (UnknownPlayerException $e) { | 		} catch (UnknownPlayerException $e) { | ||||||
| 			$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player); | 			$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player); | ||||||
| 		} | 		} | ||||||
| @@ -398,31 +393,21 @@ class ChatMessagePlugin implements CommandListener, Plugin { | |||||||
| 		$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iAway From Keyboard!'; | 		$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iAway From Keyboard!'; | ||||||
| 		$this->maniaControl->chat->sendChat($msg, null, false); | 		$this->maniaControl->chat->sendChat($msg, null, false); | ||||||
|  |  | ||||||
| 		if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_AFK_FORCE_SPEC)) { | 		if (!$this->maniaControl->settingManager->getSettingValue($this, self::SETTING_AFK_FORCE_SPEC)) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
| 		if ($player->isSpectator) { | 		if ($player->isSpectator) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 			// force into spec |  | ||||||
| 		try { | 		try { | ||||||
|  | 			// Force into spec | ||||||
| 			$this->maniaControl->client->forceSpectator($player->login, 3); | 			$this->maniaControl->client->forceSpectator($player->login, 3); | ||||||
| 			} catch (Exception $e) { | 			// Free player slot | ||||||
| 				$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) |  | ||||||
| 				$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			// free player slot |  | ||||||
| 			try { |  | ||||||
| 			$this->maniaControl->client->spectatorReleasePlayerSlot($player->login); | 			$this->maniaControl->client->spectatorReleasePlayerSlot($player->login); | ||||||
| 			} catch (Exception $e) { | 		} catch (UnknownPlayerException $exception) { | ||||||
| 				if ($e->getMessage() !== 'The player is not a spectator') { | 			$this->maniaControl->chat->sendException($exception, $player); | ||||||
| 					$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage()); | 			return; | ||||||
| 					// TODO: only possible valid exception should be "wrong login" - throw others (like connection error) |  | ||||||
| 					//to nothing |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user