Use Chat::formatMessage in Configurator/*, ManiaExchange/* and Maps/*

This commit is contained in:
Alexander Nell 2020-05-27 00:01:36 +02:00
parent 1d0215df52
commit 06f24a1bfb
9 changed files with 292 additions and 127 deletions

View File

@ -28,16 +28,17 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA
/*
* Constants
*/
const SETTING_FORMAT_ERROR = 'Error Format';
const SETTING_FORMAT_INFORMATION = 'Information Format';
const SETTING_FORMAT_SUCCESS = 'Success Format';
const SETTING_FORMAT_USAGEINFO = 'UsageInfo Format';
const SETTING_FORMAT_MESSAGE_INPUT_COLOR = 'Format Message Input Color';
const SETTING_FORMAT_MESSAGE_MAP_AUTHOR = 'Format Message Add Map Author';
const SETTING_FORMAT_MESSAGE_PLAYER_LOGIN = 'Format Message Add Player Login';
const SETTING_PUBLIC_PREFIX = 'Public Messages Prefix';
const SETTING_PRIVATE_PREFIX = 'Private Messages Prefix';
const CHAT_BUFFER_SIZE = 200;
const SETTING_FORMAT_ERROR = 'Error Format';
const SETTING_FORMAT_INFORMATION = 'Information Format';
const SETTING_FORMAT_SUCCESS = 'Success Format';
const SETTING_FORMAT_USAGEINFO = 'UsageInfo Format';
const SETTING_FORMAT_MESSAGE_INPUT_COLOR = 'Format Message Input Color';
const SETTING_FORMAT_MESSAGE_MAP_AUTHOR_LOGIN = 'Format Message Add Map Author Login';
const SETTING_FORMAT_MESSAGE_MAP_AUTHOR_NICKNAME = 'Format Message Add Map Author Nickname';
const SETTING_FORMAT_MESSAGE_PLAYER_LOGIN = 'Format Message Add Player Login';
const SETTING_PUBLIC_PREFIX = 'Public Messages Prefix';
const SETTING_PRIVATE_PREFIX = 'Private Messages Prefix';
const CHAT_BUFFER_SIZE = 200;
/*
* Private properties
@ -60,7 +61,8 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_SUCCESS, '$0f0');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_USAGEINFO, '$f80');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_MESSAGE_INPUT_COLOR, '$fff');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_MESSAGE_MAP_AUTHOR, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_MESSAGE_MAP_AUTHOR_LOGIN, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_MESSAGE_MAP_AUTHOR_NICKNAME, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_MESSAGE_PLAYER_LOGIN, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PUBLIC_PREFIX, '» ');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PRIVATE_PREFIX, '»» ');
@ -171,7 +173,8 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA
* @return string
*/
public function formatMessage($message, ...$inputs) {
$addMapAuthor = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_MESSAGE_MAP_AUTHOR);
$addMapAuthorLogin = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_MESSAGE_MAP_AUTHOR_LOGIN);
$addMapAuthorNickname = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_MESSAGE_MAP_AUTHOR_NICKNAME);
$addPlayerLogin = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_MESSAGE_PLAYER_LOGIN);
$formatInputColor = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_MESSAGE_INPUT_COLOR);
@ -183,12 +186,18 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA
$strInput = $input ? 'true' : 'false';
} elseif ($input instanceof Map) {
$strInput = $input->getEscapedName();
if ($addMapAuthor) {
$strInput .= " (by {$input->authorLogin})";
if ($addMapAuthorNickname && $input->authorNick) {
$strInput .= " (by {$input->authorNick}";
if ($addMapAuthorLogin && $input->authorLogin) {
$strInput .= " ({$input->authorLogin})";
}
$strInput .= ")";
} elseif ($addMapAuthorLogin && $input->authorLogin) {
$strInput .= " (by {$input->authorLogin})";
}
} elseif ($input instanceof Player) {
$strInput = $input->getEscapedNickname();
if ($addPlayerLogin) {
if ($addPlayerLogin && $input->login) {
$strInput .= " ({$input->login})";
}
} else {

View File

@ -281,6 +281,7 @@ class HelpManager implements CommandListener, CallbackListener, ManialinkPageAns
* @param string $method
*/
public function registerCommand($name, $adminCommand = false, $description = '', $method) {
// TODO replace with new class Command
if ($adminCommand) {
array_push($this->adminCommands, array("Name" => $name, "Description" => $description, "Method" => $method));
} else {

View File

@ -563,10 +563,16 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
$settingsCount = count($newSettings);
$settingIndex = 0;
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($player);
$chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set GameMode-Setting' . ($settingsCount > 1 ? 's' : '') . ' ';
$chatMessage = $this->maniaControl->getChat()->formatMessage(
"\$ff0{$title} %s set GameMode-Setting" . ($settingsCount > 1 ? "s" : "") . " ",
$player
);
foreach ($newSettings as $settingName => $settingValue) {
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $settingName) . '$z$ff0 ';
$chatMessage .= 'to $fff' . $this->parseSettingValue($settingValue) . '$>';
$chatMessage .= $this->maniaControl->getChat()->formatMessage(
'%s to %s',
preg_replace('/^S_/', '', $settingName),
$this->parseSettingValue($settingValue)
);
if ($settingIndex <= $settingsCount - 2) {
$chatMessage .= ', ';

View File

@ -160,7 +160,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$mxSearch->fetchMapsAsync(function (array $maps) use (&$player) {
if (!$maps) {
$this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player->login);
$this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player);
return;
}
$this->showManiaExchangeList($maps, $player);

View File

@ -371,7 +371,11 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$this->maniaControl->getMapManager()->updateMapTimestamp($map->uid);
// Message
$message = $player->getEscapedNickname() . ' added ' . $map->getEscapedName() . '!';
$message = $this->maniaControl->getChat()->formatMessage(
'%s added %s!',
$player,
$map
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
@ -391,10 +395,18 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$filePath = $folderPath . $fileName;
if (@unlink($filePath)) {
$this->maniaControl->getChat()->sendSuccess("Erased {$fileName}!");
$message = $this->maniaControl->getChat()->formatMessage(
'Erased %s!',
$fileName
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
$this->showManiaLink($player);
} else {
$this->maniaControl->getChat()->sendError("Couldn't erase {$fileName}!");
$message = $this->maniaControl->getChat()->formatMessage(
'Could not erase %s!',
$fileName
);
$this->maniaControl->getChat()->sendError($message, $player);
}
}
}

View File

@ -15,6 +15,7 @@ use ManiaControl\Manialinks\ElementBuilder;
use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use ManiaControl\Utils\DataUtil;
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException;
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
@ -62,7 +63,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->getCommandManager()->registerCommandListener(array('readmaplist', 'rml'), $this, 'command_ReadMapList', true, 'Loads a maplist into the server.');
// Player commands
$this->maniaControl->getCommandManager()->registerCommandListener('nextmap', $this, 'command_showNextMap', false, 'Shows which map is next.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('nextmap', 'next'), $this, 'command_showNextMap', false, 'Shows which map is next.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('maps', 'list'), $this, 'command_List', false, 'Shows the current maplist (or variations).');
$this->maniaControl->getCommandManager()->registerCommandListener(array('xmaps', 'xlist'), $this, 'command_xList', false, 'Shows maps from ManiaExchange.');
@ -117,12 +118,20 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$requester = $nextQueued[0];
/** @var Map $map */
$map = $nextQueued[1];
$this->maniaControl->getChat()->sendInformation("Next Map is $<{$map->name}$> from $<{$map->authorNick}$> requested by $<{$requester->nickname}$>.", $player);
$message = $this->maniaControl->getChat()->formatMessage(
'Next Map is %s, requested by %s.',
$map,
$requester
);
$this->maniaControl->getChat()->sendInformation($message, $player);
} else {
$mapIndex = $this->maniaControl->getClient()->getNextMapIndex();
$maps = $this->maniaControl->getMapManager()->getMaps();
$map = $maps[$mapIndex];
$this->maniaControl->getChat()->sendInformation("Next Map is $<{$map->name}$> from $<{$map->authorNick}$>.", $player);
$map = $this->maniaControl->getMapManager()->getMapByIndex($mapIndex);
$message = $this->maniaControl->getChat()->formatMessage(
'Next Map is %s.',
$map
);
$this->maniaControl->getChat()->sendInformation($message, $player);
}
}
@ -137,14 +146,14 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
// Get map
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
$this->maniaControl->getChat()->sendError("Couldn't remove map.", $player);
$this->maniaControl->getChat()->sendError('Could not fetch current map to remove!', $player);
return;
}
// Remove map
// no chat message necessary, the MapManager will do that
$this->maniaControl->getMapManager()->removeMap($player, $map->uid);
}
@ -159,14 +168,14 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
// Get map
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
$this->maniaControl->getChat()->sendError("Couldn't erase map.", $player);
$this->maniaControl->getChat()->sendError('Could not fetch current map to erase!', $player);
return;
}
// Erase map
// no chat message necessary, the MapManager will do that
$this->maniaControl->getMapManager()->removeMap($player, $map->uid, true);
}
@ -182,7 +191,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
return;
}
// Shuffles the maps
// no chat message necessary, the MapManager will do that
$this->maniaControl->getMapManager()->shuffleMapList($player);
}
@ -197,13 +206,17 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$params = explode(' ', $chatCallback[1][2], 2);
if (count($params) < 2) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //addmap 1234', $player);
$message = $this->maniaControl->getChat()->formatMessage(
'Usage example: %s',
'//addmap 1234'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return;
}
// add Map from Mania Exchange
$this->maniaControl->getMapManager()->addMapFromMx($params[1], $player->login);
}
@ -221,7 +234,10 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->getMapManager()->getMapActions()->skipMap();
$message = $player->getEscapedNickname() . ' skipped the current Map!';
$message = $this->maniaControl->getChat()->formatMessage(
'%s skipped the current Map!',
$player
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
}
@ -237,17 +253,21 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$message = $player->getEscapedNickname() . ' restarted the current Map!';
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
try {
$this->maniaControl->getClient()->restartMap();
} catch (ChangeInProgressException $e) {
$this->maniaControl->getChat()->sendException($e, $player);
return;
}
}
////$this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap());
$message = $this->maniaControl->getChat()->formatMessage(
'%s restarted the current Map!',
$player
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
}
/**
* Handle replaymap command
@ -260,11 +280,15 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$message = $player->getEscapedNickname() . ' replays the current Map!';
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
$this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($player, $this->maniaControl->getMapManager()->getCurrentMap());
$message = $this->maniaControl->getChat()->formatMessage(
'%s queued the current Map to replay!',
$player
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
}
/**
@ -280,26 +304,35 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
$chatCommand = explode(' ', $chat[1][2]);
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR;
if (isset($chatCommand[1])) {
if (strstr($chatCommand[1], '.txt')) {
$maplist = $chatCommand[1];
if (!DataUtil::endsWith($chatCommand[1], '.txt')) {
$maplist .= $chatCommand[1] . '.txt';
} else {
$maplist = $chatCommand[1] . '.txt';
$maplist .= $chatCommand[1];
}
} else {
$maplist = 'maplist.txt';
$maplist .= 'maplist.txt';
}
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
try {
$this->maniaControl->getClient()->saveMatchSettings($maplist);
$message = 'Maplist $<$fff' . $maplist . '$> written.';
$this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::logInfo($message, true);
} catch (FaultException $e) {
$this->maniaControl->getChat()->sendError('Cannot write maplist $<$fff' . $maplist . '$>!', $player);
$this->maniaControl->getChat()->sendException($e, $player);
$message = $this->maniaControl->getChat()->formatMessage(
'Cannot write maplist %s!',
$maplist
);
$this->maniaControl->getChat()->sendError($message, $player);
return;
}
$message = $this->maniaControl->getChat()->formatMessage(
'Maplist %s written.',
$maplist
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::logInfo($message, true);
}
/**
@ -315,27 +348,36 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
$chatCommand = explode(' ', $chat[1][2]);
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR;
if (isset($chatCommand[1])) {
if (strstr($chatCommand[1], '.txt')) {
$maplist = $chatCommand[1];
if (!DataUtil::endsWith($chatCommand[1], '.txt')) {
$maplist .= $chatCommand[1] . '.txt';
} else {
$maplist = $chatCommand[1] . '.txt';
$maplist .= $chatCommand[1];
}
} else {
$maplist = 'maplist.txt';
$maplist .= 'maplist.txt';
}
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
try {
$this->maniaControl->getClient()->loadMatchSettings($maplist);
$message = 'Maplist $<$fff' . $maplist . '$> loaded.';
$this->maniaControl->getMapManager()->restructureMapList();
$this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::logInfo($message, true);
} catch (FaultException $e) {
$this->maniaControl->getChat()->sendError('Cannot load maplist $<$fff' . $maplist . '$>!', $player);
$this->maniaControl->getChat()->sendException($e, $player);
$message = $this->maniaControl->getChat()->formatMessage(
'Cannot load maplist %s!',
$maplist
);
$this->maniaControl->getChat()->sendError($message, $player);
return;
}
$message = $this->maniaControl->getChat()->formatMessage(
'Maplist %s loaded.',
$maplist
);
$this->maniaControl->getMapManager()->restructureMapList();
$this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::logInfo($message, true);
}
/**

View File

@ -588,18 +588,22 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->getMapManager()->getMapQueue()->dontQueueNextMapChange();
try {
$this->maniaControl->getClient()->jumpToMapIdent($mapUid);
} catch (NextMapException $exception) {
$this->maniaControl->getChat()->sendError('Error on Jumping to Map Ident: ' . $exception->getMessage(), $player);
} catch (NextMapException $e) {
$this->maniaControl->getChat()->sendException($e, $player);
break;
} catch (NotInListException $exception) {
} catch (NotInListException $e) {
// TODO: "Map not found." -> how is that possible?
$this->maniaControl->getChat()->sendError('Error on Jumping to Map Ident: ' . $exception->getMessage(), $player);
$this->maniaControl->getChat()->sendException($e, $player);
break;
}
$map = $this->maniaControl->getMapManager()->getMapByUid($mapUid);
$message = $player->getEscapedNickname() . ' skipped to Map $z' . $map->getEscapedName() . '!';
$message = $this->maniaControl->getChat()->formatMessage(
'%s skipped to Map %s!',
$player,
$map
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
@ -610,14 +614,19 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$map = $this->maniaControl->getMapManager()->getMapByUid($mapUid);
$message = $player->getEscapedNickname() . '$s started a vote to switch to ' . $map->getEscapedName() . '!';
$message = $this->maniaControl->getChat()->formatMessage(
'%s started a vote to switch to Map %s!',
$player,
$map
);
$votesPlugin->defineVote('switchmap', 'Goto ' . $map->name, true, $message)->setStopCallback(Callbacks::ENDMAP);
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) {
$votesPlugin->undefineVote('switchmap');
// will be only called, if successful
//Don't queue on Map-Change
$votesPlugin->undefineVote('switchmap');
// Don't queue on Map-Change
$this->maniaControl->getMapManager()->getMapQueue()->dontQueueNextMapChange();
try {
@ -631,7 +640,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
return;
}
$this->maniaControl->getChat()->sendInformation('$sVote Successful -> Map switched!');
$this->maniaControl->getChat()->sendSuccess('Vote Successful -> Map switched!');
});
break;
case self::ACTION_QUEUED_MAP:

View File

@ -192,7 +192,11 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
if (!isset($uid) || !isset($this->maps[$uid])) {
if ($admin) {
$this->maniaControl->getChat()->sendError("Error updating Map: Unknown UID '{$uid}'!", $admin);
$message = $this->maniaControl->getChat()->formatMessage(
'Error updating Map, unknown UID %s!',
$uid
);
$this->maniaControl->getChat()->sendError($message, $admin);
}
return;
}
@ -278,16 +282,22 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
// Check if ManiaControl can even write to the maps dir
$mapDir = $this->maniaControl->getClient()->getMapsDirectory();
if ($this->maniaControl->getServer()->checkAccess($mapDir)) {
$mapFile = $mapDir . $map->fileName;
// Delete map file
if (!@unlink($mapDir . $map->fileName)) {
if (!@unlink($mapFile)) {
if ($admin) {
$this->maniaControl->getChat()->sendError("Couldn't erase the map file.", $admin);
$message = $this->maniaControl->getChat()->formatMessage(
'Could not erase the map file %s.',
$mapFile
);
$this->maniaControl->getChat()->sendError($message, $admin);
}
$eraseFile = false;
}
} else {
if ($admin) {
$this->maniaControl->getChat()->sendError("Couldn't erase the map file (no access).", $admin);
$this->maniaControl->getChat()->sendError('Could not erase the map file (no access to Maps-Directory).', $admin);
}
$eraseFile = false;
}
@ -297,9 +307,16 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
if ($message) {
$action = ($eraseFile ? 'erased' : 'removed');
if ($admin) {
$message = $admin->getEscapedNickname() . ' ' . $action . ' ' . $map->getEscapedName() . '!';
$message = $this->maniaControl->getChat()->formatMessage(
"%s {$action} %s!",
$admin,
$map
);
} else {
$message = $map->getEscapedName() . ' got ' . $action . '!';
$message = $this->maniaControl->getChat()->formatMessage(
"%s got {$action}!",
$map
);
}
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
@ -363,7 +380,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
if (!$file || $error) {
if ($login) {
// Download error
$this->maniaControl->getChat()->sendError("Download failed: '{$error}'!", $login);
$this->maniaControl->getChat()->sendError("Download failed: {$error}!", $login);
}
return;
}
@ -406,7 +423,11 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
if ($this->maniaControl->getServer()->checkAccess($mapDir)) {
// Create download directory if necessary
if (!is_dir($downloadDirectory) && !mkdir($downloadDirectory) || !is_writable($downloadDirectory)) {
$this->maniaControl->getChat()->sendError("ManiaControl doesn't have to rights to save maps in '{$downloadDirectory}'.", $login);
$message = $this->maniaControl->getChat()->formatMessage(
'ManiaControl does not have to rights to save maps in %s!',
$downloadDirectory
);
$this->maniaControl->getChat()->sendError($message, $login);
return;
}
@ -421,12 +442,12 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
$this->maniaControl->getClient()->writeFile($relativeMapFileName, $file);
} catch (InvalidArgumentException $e) {
if ($e->getMessage() === 'data are too big') {
$this->maniaControl->getChat()->sendError("Map is too big for a remote save.", $login);
$this->maniaControl->getChat()->sendError('Map is too big for a remote save!', $login);
return;
}
throw $e;
} catch (FileException $e) {
$this->maniaControl->getChat()->sendError("Could not write file", $login);
$this->maniaControl->getChat()->sendError('Could not write file!', $login);
return;
}
}
@ -434,26 +455,26 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
// Check for valid map
try {
$this->maniaControl->getClient()->checkMapForCurrentServerParams($relativeMapFileName);
} catch (InvalidMapException $exception) {
$this->maniaControl->getChat()->sendException($exception, $login);
} catch (InvalidMapException $e) {
$this->maniaControl->getChat()->sendException($e, $login);
return;
} catch (FileException $exception) {
$this->maniaControl->getChat()->sendException($exception, $login);
} catch (FileException $e) {
$this->maniaControl->getChat()->sendException($e, $login);
return;
}catch (FaultException $exception){
$this->maniaControl->getChat()->sendException($exception, $login);
}catch (FaultException $e){
$this->maniaControl->getChat()->sendException($e, $login);
return;
}
// Add map to map list
try {
$this->maniaControl->getClient()->insertMap($relativeMapFileName);
} catch (AlreadyInListException $exception) {
$this->maniaControl->getChat()->sendException($exception, $login);
} catch (AlreadyInListException $e) {
$this->maniaControl->getChat()->sendException($e, $login);
return;
} catch (InvalidMapException $exception) {
$this->maniaControl->getChat()->sendException($exception, $login);
if ($exception->getMessage() != 'Map lightmap is not up to date. (will still load for now)') {
} catch (InvalidMapException $e) {
$this->maniaControl->getChat()->sendException($e, $login);
if ($e->getMessage() != 'Map lightmap is not up to date. (will still load for now)') {
return;
}
}
@ -482,14 +503,21 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
if ($login) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if (!$update) {
// Message
$message = $player->getEscapedNickname() . ' added $<' . $mapInfo->name . '$>!';
$message = $this->maniaControl->getChat()->formatMessage(
'%s added %s from MX!',
$player,
$map
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
// Queue requested Map
$this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($login, $mapInfo->uid);
} else {
$message = $player->getEscapedNickname() . ' updated $<' . $mapInfo->name . '$>!';
$message = $this->maniaControl->getChat()->formatMessage(
'%s updated %s from MX!',
$player,
$map
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
}
@ -649,15 +677,18 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
$this->maniaControl->getClient()->chooseNextMapList($mapArray);
} catch (Exception $e) {
//TODO temp added 19.04.2014
$this->maniaControl->getErrorHandler()->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
$this->maniaControl->getErrorHandler()->triggerDebugNotice('Exception line 331 MapManager' . $e->getMessage());
trigger_error('Could not shuffle mapList. ' . $e->getMessage());
return false;
}
$this->fetchCurrentMap();
if ($admin) {
$message = $admin->getEscapedNickname() . ' shuffled the Maplist!';
$message = $this->maniaControl->getChat()->formatMessage(
'%s shuffled the Maplist!',
$admin
);
$this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true);
}
@ -725,7 +756,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
try {
$this->maniaControl->getClient()->chooseNextMapList($mapArray);
} catch (Exception $e) {
trigger_error("Error restructuring the Maplist. " . $e->getMessage());
trigger_error('Error restructuring the Maplist. ' . $e->getMessage());
return false;
}
return true;

View File

@ -34,6 +34,7 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
const SETTING_MAPLIMIT_PLAYER = 'Maximum maps per player in the Map-Queue (-1 = unlimited)';
const SETTING_MAPLIMIT_ADMIN = 'Maximum maps per admin (Admin+) in the Map-Queue (-1 = unlimited)';
const SETTING_MESSAGE_FORMAT = 'Message Format';
const SETTING_BUFFERSIZE = 'Size of the Map-Queue buffer (recently played maps)';
const SETTING_PERMISSION_CLEAR_MAPQUEUE = 'Clear MapQueue';
const SETTING_PERMISSION_QUEUE_BUFFER = 'Queue maps in buffer';
@ -69,6 +70,7 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIMIT_PLAYER, 1);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIMIT_ADMIN, -1);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MESSAGE_FORMAT, '$fa0');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_BUFFERSIZE, 10);
// Permissions
@ -117,17 +119,22 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
return;
}
$messagePrefix = $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MESSAGE_FORMAT);
if ($admin && empty($this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('$fa0There are no maps in the jukebox!', $admin->login);
$this->maniaControl->getChat()->sendError($messagePrefix . 'There are no maps in the jukebox!', $admin);
return;
}
//Destroy map - queue list
// Destroy map - queue list
$this->queuedMaps = array();
if ($admin) {
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
$message = '$fa0' . $title . ' $<$fff' . $admin->nickname . '$> cleared the Map-Queue!';
$title = $admin->getAuthLevelName();
$message = $this->maniaControl->getChat()->formatMessage(
$messagePrefix . '%s %s cleared the Map-Queue!',
$title,
$admin
);
$this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($message, true);
}
@ -172,15 +179,20 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
* @param Player $player
*/
public function showMapQueue(Player $player) {
$messagePrefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MESSAGE_FORMAT);
if (empty($this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('$fa0There are no maps in the jukebox!', $player->login);
$this->maniaControl->getChat()->sendInformation($messagePrefix . 'There are no maps in the jukebox!', $player);
return;
}
$message = '$fa0Upcoming maps in the Map-Queue:';
$message = $messagePrefix . 'Upcoming maps in the Map-Queue:';
$index = 1;
foreach ($this->queuedMaps as $queuedMap) {
$message .= ' $<$fff' . $index . '$>. [$<$fff' . Formatter::stripCodes($queuedMap[1]->name) . '$>]';
$message .= $this->maniaControl->getChat()->formatMessage(
' %s. [%s]',
$index,
Formatter::stripCodes($queuedMap[1]->name)
);
$index++;
}
@ -193,8 +205,9 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
* @param Player $player
*/
public function showMapQueueManialink(Player $player) {
$messagePrefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MESSAGE_FORMAT);
if (empty($this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('There are no Maps in the Jukebox!', $player);
$this->maniaControl->getChat()->sendInformation($messagePrefix . 'There are no Maps in the Jukebox!', $player);
return;
}
@ -246,7 +259,12 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
$this->queuedMaps[$uid] = array(null, $map);
$this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $map->name . '$> has been added to the Map-Queue by the Server.');
$messagePrefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MESSAGE_FORMAT);
$message = $this->maniaControl->getChat()->formatMessage(
$messagePrefix . '%s has been added to the Map-Queue by the Server.',
$map
);
$this->maniaControl->getChat()->sendInformation($message);
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
@ -285,13 +303,21 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
if ($isModerator) {
$maxAdmin = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAPLIMIT_ADMIN);
if ($maxAdmin >= 0 && $mapsForPlayer >= $maxAdmin) {
$this->maniaControl->getChat()->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
$message = $this->maniaControl->getChat()->formatMessage(
'You already have %s map(s) in the Map-Queue!',
$maxAdmin
);
$this->maniaControl->getChat()->sendError($message, $player);
return;
}
} else {
$maxPlayer = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAPLIMIT_PLAYER);
if ($maxPlayer >= 0 && $mapsForPlayer >= $maxPlayer) {
$this->maniaControl->getChat()->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
$message = $this->maniaControl->getChat()->formatMessage(
'You already have %s map(s) in the Map-Queue!',
$maxPlayer
);
$this->maniaControl->getChat()->sendError($message, $player);
return;
}
}
@ -303,14 +329,15 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
$uid = $map->uid;
}
if (array_key_exists($uid, $this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('That map is already in the Map-Queue!', $login);
$this->maniaControl->getChat()->sendError('This map is already in the Map-Queue!', $player);
return;
}
//TODO recently maps not able to add to queue-amps setting, and management
// Check if map is in the buffer
$messagePrefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MESSAGE_FORMAT);
if (in_array($uid, $this->buffer)) {
$this->maniaControl->getChat()->sendError('That map has recently been played!', $login);
$this->maniaControl->getChat()->sendInformation($messagePrefix . 'This map has recently been played!', $player);
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
return;
}
@ -322,7 +349,12 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
$this->queuedMaps[$uid] = array($player, $map);
$this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $map->name . '$> has been added to the Map-Queue by $<$fff' . $player->nickname . '$>.');
$message = $this->maniaControl->getChat()->formatMessage(
$messagePrefix . '%s has been added to the Map-Queue by %s.',
$map,
$player
);
$this->maniaControl->getChat()->sendInformation($message);
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
@ -343,7 +375,13 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
unset($this->queuedMaps[$uid]);
if ($player) {
$this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $map->name . '$> is removed from the Map-Queue by $<$fff' . $player->nickname . '$>.');
$messagePrefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MESSAGE_FORMAT);
$message = $this->maniaControl->getChat()->formatMessage(
$messagePrefix . '%s has been removed from the Map-Queue by %s.',
$map,
$player
);
$this->maniaControl->getChat()->sendInformation($message);
}
// Trigger callback
@ -356,17 +394,22 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
* @internal
*/
public function endMap() {
//Don't queue next map (for example on skip to map)
// Don't queue next map (for example on skip to map)
if ($this->nextNoQueue) {
$this->nextNoQueue = false;
return;
}
$messagePrefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MESSAGE_FORMAT);
$this->nextMap = null;
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SKIP_MAP_ON_LEAVE)) {
// Skip Map if requester has left
foreach ($this->queuedMaps as $queuedMap) {
/** @var Player $player */
$player = $queuedMap[0];
/** @var Map $map */
$map = $queuedMap[1];
// Check if map is added via replay vote/command
if (isset($queuedMap[2]) && $queuedMap[2] === true) {
@ -391,22 +434,34 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
// Player not found, so remove the map from the mapqueue
array_shift($this->queuedMaps);
$this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
$message = $this->maniaControl->getChat()->formatMessage(
$messagePrefix . '%s will be skipped, because %s left the game!',
$map,
$player
);
$this->maniaControl->getChat()->sendInformation($message);
}
}
$this->nextMap = array_shift($this->queuedMaps);
//Check if Map Queue is empty
// Check if Map Queue is empty
if (!$this->nextMap || !isset($this->nextMap[1])) {
return;
}
/** @var Player $player */
$player = $this->nextMap[0];
/** @var Map $map */
$map = $this->nextMap[1];
//Message only if it's juked by a player (not by the server)
if ($this->nextMap[0]) {
/** @var Map $map */
$this->maniaControl->getChat()->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
// Message only if it's juked by a player (not by the server)
if ($player) {
$message = $this->maniaControl->getChat()->formatMessage(
$messagePrefix . 'Next map will be %s as requested by %s.',
$map,
$player
);
$this->maniaControl->getChat()->sendInformation($message);
}
try {