Use Chat::formatMessage in Server/*

This commit is contained in:
Alexander Nell 2020-06-02 17:30:30 +02:00
parent 5717589588
commit 9abadac932
5 changed files with 159 additions and 77 deletions

View File

@ -164,12 +164,16 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
return; return;
} }
if ($this->maniaControl->getClient()->cancelVote()) { if (!$this->maniaControl->getClient()->cancelVote()) {
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' cancelled the Vote!'); $this->maniaControl->getChat()->sendError("There is no vote running currently!", $player);
} else { return;
$this->maniaControl->getChat()->sendInformation("There's no vote running currently!", $player);
} }
$message = $this->maniaControl->getChat()->formatMessage(
'%s cancelled the Vote!',
$player
);
$this->maniaControl->getChat()->sendInformation($message);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_VOTE_CANCELLED, $player); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_VOTE_CANCELLED, $player);
} }
@ -186,10 +190,21 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
return; return;
} }
//TODO command paprameter for seconds $extension = 10;
$this->maniaControl->getModeScriptEventManager()->extendManiaPlanetWarmup(10);
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!');
$params = explode(' ', $chat[1][2]);
if (count($params) >= 2) {
$extension = $params[1];
}
$this->maniaControl->getModeScriptEventManager()->extendManiaPlanetWarmup($extension);
$message = $this->maniaControl->getChat()->formatMessage(
'%s extended the WarmUp by %s seconds!',
$player,
$extension
);
$this->maniaControl->getChat()->sendInformation($message);
} }
/** /**
@ -205,7 +220,11 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
} }
$this->maniaControl->getModeScriptEventManager()->stopManiaPlanetWarmup(); $this->maniaControl->getModeScriptEventManager()->stopManiaPlanetWarmup();
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' stopped the WarmUp!'); $message = $this->maniaControl->getChat()->formatMessage(
'%s stopped the WarmUp!',
$player
);
$this->maniaControl->getChat()->sendInformation($message);
} }
/** /**
@ -220,17 +239,22 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
return; return;
} }
$message = $this->maniaControl->getChat()->formatMessage(
'%s paused the Game!',
$player
);
//Normal Gamemodes //Normal Gamemodes
try { try {
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceWarmUp' => true)); $this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceWarmUp' => true));
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' paused the Game!'); $this->maniaControl->getChat()->sendInformation($message);
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
try { try {
//Chase and Combo? //Chase and Combo?
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_SetPause' => true)); $this->maniaControl->getClient()->sendModeScriptCommands(array('Command_SetPause' => true));
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' paused the Game!'); $this->maniaControl->getChat()->sendInformation($message);
//Especially for chase, force end of the round to reach a draw //Especially for chase, force end of the round to reach a draw
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceEndRound' => true)); $this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceEndRound' => true));
@ -239,7 +263,6 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
//TODO verify if not everything is replaced through the new pause //TODO verify if not everything is replaced through the new pause
$this->maniaControl->getModeScriptEventManager()->startPause(); $this->maniaControl->getModeScriptEventManager()->startPause();
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
} }
/** /**
@ -283,9 +306,17 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$systemInfo = $this->maniaControl->getClient()->getSystemInfo(); $systemInfo = $this->maniaControl->getClient()->getSystemInfo();
$message = 'SystemInfo: ip=' . $systemInfo->publishedIp . ', port=' . $systemInfo->port . ', p2pPort=' . $systemInfo->p2PPort . ', title=' . $systemInfo->titleId . ', login=' . $systemInfo->serverLogin . '.'; $message = $this->maniaControl->getChat()->formatMessage(
$this->maniaControl->getChat()->sendInformation($message, $player->login); 'SystemInfo: ip=%s, port=%s, p2pPort=%s, title=%s, login=%s',
$systemInfo->publishedIp,
$systemInfo->port,
$systemInfo->p2PPort,
$systemInfo->titleId,
$systemInfo->serverLogin
);
$this->maniaControl->getChat()->sendInformation($message, $player);
} }
/** /**
@ -301,7 +332,11 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
} }
// Check for delayed shutdown // Check for delayed shutdown
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (count($params) >= 2) { if (count($params) < 2) {
$this->shutdownServer($player->login);
return;
}
$param = $params[1]; $param = $params[1];
if (strtolower($param) === 'empty') { if (strtolower($param) === 'empty') {
$this->serverShutdownEmpty = !$this->serverShutdownEmpty; $this->serverShutdownEmpty = !$this->serverShutdownEmpty;
@ -309,9 +344,11 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getChat()->sendInformation("The server will shutdown as soon as it's empty!", $player); $this->maniaControl->getChat()->sendInformation("The server will shutdown as soon as it's empty!", $player);
return; return;
} }
$this->maniaControl->getChat()->sendInformation("Empty-shutdown cancelled!", $player); $this->maniaControl->getChat()->sendInformation("Empty-shutdown cancelled!", $player);
return; return;
} }
$delay = (int) $param; $delay = (int) $param;
if ($delay <= 0) { if ($delay <= 0) {
// Cancel shutdown // Cancel shutdown
@ -319,12 +356,14 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getChat()->sendInformation("Delayed shutdown cancelled!", $player); $this->maniaControl->getChat()->sendInformation("Delayed shutdown cancelled!", $player);
return; return;
} }
// Trigger delayed shutdown // Trigger delayed shutdown
$this->serverShutdownTime = time() + $delay * 60.; $this->serverShutdownTime = time() + $delay * 60.;
$this->maniaControl->getChat()->sendInformation("The server will shut down in {$delay} minutes!", $player); $message = $this->maniaControl->getChat()->formatMessage(
return; 'The server will shut down in %s minutes!',
} $delay
$this->shutdownServer($player->login); );
$this->maniaControl->getChat()->sendInformation($message, $player);
} }
/** /**
@ -338,14 +377,24 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 2); $params = explode(' ', $chat[1][2], 2);
if (count($params) < 2) { if (count($params) < 2) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setservername ManiaPlanet Server', $player); $message = $this->maniaControl->getChat()->formatMessage(
'Usage example: %s',
'//setservername ManiaPlanet Server Name'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$serverName = $params[1]; $serverName = $params[1];
$this->maniaControl->getClient()->setServerName($serverName); $this->maniaControl->getClient()->setServerName($serverName);
$this->maniaControl->getChat()->sendSuccess("Server name changed to: '{$serverName}'!", $player); $message = $this->maniaControl->getChat()->formatMessage(
'Server name changed to %s!',
$serverName
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
} }
/** /**
@ -359,15 +408,20 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
$password = ''; $password = '';
$successMessage = 'Password removed!'; $message = 'Password removed!';
if (isset($messageParts[1])) { if (isset($messageParts[1])) {
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!"; $message = $this->maniaControl->getChat()->formatMessage(
'Password changed to %s!',
$password
);
} }
$this->maniaControl->getClient()->setServerPassword($password); $this->maniaControl->getClient()->setServerPassword($password);
$this->maniaControl->getChat()->sendSuccess($successMessage, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
/** /**
@ -381,15 +435,20 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
$password = ''; $password = '';
$successMessage = 'Spectator password removed!'; $message = 'Spectator password removed!';
if (isset($messageParts[1])) { if (isset($messageParts[1])) {
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!"; $message = $this->maniaControl->getChat()->formatMessage(
'Spectator password changed to %s!',
$password
);
} }
$this->maniaControl->getClient()->setServerPasswordForSpectator($password); $this->maniaControl->getClient()->setServerPasswordForSpectator($password);
$this->maniaControl->getChat()->sendSuccess($successMessage, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
/** /**
@ -403,23 +462,28 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) { if (!isset($messageParts[1]) || !is_numeric($messageParts[1])) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxplayers 16', $player); $message = $this->maniaControl->getChat()->formatMessage(
'Usage example: %s',
'//setmaxplayers 16'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$amount = $messageParts[1];
if (!is_numeric($amount)) { $amount = intval($messageParts[1]);
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxplayers 16', $player);
return;
}
$amount = (int) $amount;
if ($amount < 0) { if ($amount < 0) {
$amount = 0; $amount = 0;
} }
$this->maniaControl->getClient()->setMaxPlayers($amount); $this->maniaControl->getClient()->setMaxPlayers($amount);
$this->maniaControl->getChat()->sendSuccess("Changed max players to: {$amount}", $player); $message = $this->maniaControl->getChat()->formatMessage(
'Changed max players to %s!',
$amount
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
} }
/** /**
@ -433,22 +497,27 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) { if (!isset($messageParts[1]) || !is_numeric($messageParts[1])) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxspectators 16', $player); $message = $this->maniaControl->getChat()->formatMessage(
'Usage example: %s',
'//setmaxspectators 16'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$amount = $messageParts[1];
if (!is_numeric($amount)) { $amount = intval($messageParts[1]);
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxspectators 16', $player);
return;
}
$amount = (int) $amount;
if ($amount < 0) { if ($amount < 0) {
$amount = 0; $amount = 0;
} }
$this->maniaControl->getClient()->setMaxSpectators($amount); $this->maniaControl->getClient()->setMaxSpectators($amount);
$this->maniaControl->getChat()->sendSuccess("Changed max spectators to: {$amount}", $player); $message = $this->maniaControl->getChat()->formatMessage(
'Changed max spectators to %s!',
$amount
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
} }
} }

View File

@ -100,11 +100,20 @@ class Server implements CallbackListener, CommandListener, UsageInformationAble
$hours = intval($hourstotal - 24 * $days); $hours = intval($hourstotal - 24 * $days);
$minutes = intval($minutestotal - 24 * 60 * $days - $hours * 60); $minutes = intval($minutestotal - 24 * 60 * $days - $hours * 60);
$days > 1 ? $dayString = 'days' : $dayString = 'day'; $dayString = ($days == 1 ? 'day' : 'days' );
$hours > 1 ? $hourString = 'hours' : $hourString = 'hour'; $hourString = ($hours == 1 ? 'hour' : 'hours' );
$minutes > 1 ? $minuteString = 'minutes' : $minuteString = 'minute'; $minuteString = ($minutes == 1 ? 'minute' : 'minutes');
$this->maniaControl->getChat()->sendChat('Server is running since $<$fff' . $days . '$> ' . $dayString . ', $<$fff' . $hours . '$> ' . $hourString . ' and $<$fff' . $minutes . '$> ' . $minuteString, $player); $message = $this->maniaControl->getChat()->formatMessage(
'Server is running since %s %s, %s %s and %s %s',
$days,
$dayString,
$hours,
$hourString,
$minutes,
$minuteString
);
$this->maniaControl->getChat()->sendChat($message, $player);
} }
/** /**

View File

@ -210,8 +210,8 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$loaded = false; $loaded = false;
try { try {
$loaded = $this->maniaControl->getClient()->setServerOptions($newServerOptions); $loaded = $this->maniaControl->getClient()->setServerOptions($newServerOptions);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $e) {
$this->maniaControl->getChat()->sendExceptionToAdmins($exception); $this->maniaControl->getChat()->sendExceptionToAdmins($e);
} }
if ($loaded) { if ($loaded) {
@ -371,8 +371,8 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
private function applyNewServerOptions(ServerOptions $newServerOptions, $player = null) { private function applyNewServerOptions(ServerOptions $newServerOptions, $player = null) {
try { try {
$this->maniaControl->getClient()->setServerOptions($newServerOptions); $this->maniaControl->getClient()->setServerOptions($newServerOptions);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $e) {
$this->maniaControl->getChat()->sendException($exception, $player); $this->maniaControl->getChat()->sendException($e, $player);
return false; return false;
} }

View File

@ -440,7 +440,7 @@ class ServerUIPropertiesMenu implements ConfiguratorMenu, CallbackListener, Time
// Notifications // Notifications
$uiPropertiesCount = count($newUIProperties); $uiPropertiesCount = count($newUIProperties);
$uiPropertyIndex = 0; $uiPropertyIndex = 0;
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($player); $title = $player->getAuthLevelName();
$chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set ServerUIPropert' . ($uiPropertiesCount > 1 ? 'ies' : 'y') . ' '; $chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set ServerUIPropert' . ($uiPropertiesCount > 1 ? 'ies' : 'y') . ' ';
foreach ($newUIProperties as $uiPropertyName => $uiPropertyValue) { foreach ($newUIProperties as $uiPropertyName => $uiPropertyValue) {
$chatMessage .= '$<$fff' . $uiPropertyName . '$>$ff0 '; $chatMessage .= '$<$fff' . $uiPropertyName . '$>$ff0 ';

View File

@ -172,6 +172,10 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
* @param string $commandName * @param string $commandName
*/ */
private function sendInvalidValueError(Player $player, $commandName) { private function sendInvalidValueError(Player $player, $commandName) {
$this->maniaControl->getChat()->sendError("Invalid Value given for '{$commandName}'!", $player); $message = $this->maniaControl->getChat()->formatMessage(
'Invalid Value given for %s!',
$commandName
);
$this->maniaControl->getChat()->sendError($message, $player);
} }
} }