improve logging

This commit is contained in:
Beu
2025-06-22 11:45:37 +02:00
parent aefff423f7
commit 271395edfa

View File

@ -15,6 +15,7 @@ use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\Controls\Quads\Quad_UIConstructionBullet_Buttons; use FML\Controls\Quads\Quad_UIConstructionBullet_Buttons;
use FML\ManiaLink; use FML\ManiaLink;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Files\FileUtil; use ManiaControl\Files\FileUtil;
use ManiaControl\Logger; use ManiaControl\Logger;
@ -562,6 +563,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$fileName $fileName
); );
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') erased the map file "'. $filePath .'"');
$this->showManiaLink($player); $this->showManiaLink($player);
} else { } else {
$message = $this->maniaControl->getChat()->formatMessage( $message = $this->maniaControl->getChat()->formatMessage(
@ -593,13 +595,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (mkdir($folderPath . $name, 755, true)) { if (mkdir($folderPath . $name, 755, true)) {
$message = "Successfully created directory ". $name; $message = "Successfully created directory ". $name;
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log($message . " by " . $player->nickname); Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') created the folder "'. $folderPath .'"');
$this->showManiaLink($player, $name); $this->showManiaLink($player, $name);
} else { } else {
$message = "Failed to create directory ". $name; $message = "Failed to create directory ". $name;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message . " by " . $player->nickname); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when creating the folder "'. $folderPath .'".');
$this->showManiaLink($player); $this->showManiaLink($player);
} }
@ -622,7 +624,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (!$file || $error) { if (!$file || $error) {
$message = "Impossible to download the file: " . $error; $message = "Impossible to download the file: " . $error;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error during the download of the zip file "'. $url .'": '. $error);
return; return;
} }
$filePath = ""; $filePath = "";
@ -640,13 +642,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if ($open === true) { if ($open === true) {
$zip->extractTo($folderPath); $zip->extractTo($folderPath);
$zip->close(); $zip->close();
$message = "Succesfully extracted zip archive from ". $url; $message = "Successfully extracted zip archive from ". $url;
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log($message . " by " . $player->nickname); Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') downloaded the zip file "'. $url .'"');
} else { } else {
$message = "Cannot extract archive from ". $url; $message = "Cannot extract archive from ". $url;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message . " by " . $player->nickname); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloading the zip file "'. $url .'": Cannot extract the archive');
} }
// Clean up the temporary file // Clean up the temporary file
unlink($tempFile); unlink($tempFile);
@ -706,7 +708,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (!$this->isMapFileName($filePath)) { if (!$this->isMapFileName($filePath)) {
$message = "File is not a map: " . $fileName; $message = "File is not a map: " . $fileName;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloadeding the map file "'. $fileName .'": File is not a map');
return; return;
} }
} else { } else {
@ -733,13 +735,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
$message = "Failed to write file " . $filePath; $message = "Failed to write file " . $filePath;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message . " by " . $player->nickname); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloadeding the map file "'. $fileName .'": Failed to write the file');
return; return;
} }
$message = "Succesfully downloaded the map ". $fileName; $message = "Successfully downloaded the map ". $fileName;
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log($message . " by " . $player->nickname); Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') downloaded the map file "'. $filePath .'"');
} }
} }