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;
}
if ($this->maniaControl->getClient()->cancelVote()) {
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' cancelled the Vote!');
} else {
$this->maniaControl->getChat()->sendInformation("There's no vote running currently!", $player);
if (!$this->maniaControl->getClient()->cancelVote()) {
$this->maniaControl->getChat()->sendError("There is no vote running currently!", $player);
return;
}
$message = $this->maniaControl->getChat()->formatMessage(
'%s cancelled the Vote!',
$player
);
$this->maniaControl->getChat()->sendInformation($message);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_VOTE_CANCELLED, $player);
}
@ -186,10 +190,21 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
return;
}
//TODO command paprameter for seconds
$this->maniaControl->getModeScriptEventManager()->extendManiaPlanetWarmup(10);
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!');
$extension = 10;
$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->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;
}
$message = $this->maniaControl->getChat()->formatMessage(
'%s paused the Game!',
$player
);
//Normal Gamemodes
try {
$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) {
}
try {
//Chase and Combo?
$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
$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
$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);
return;
}
$systemInfo = $this->maniaControl->getClient()->getSystemInfo();
$message = 'SystemInfo: ip=' . $systemInfo->publishedIp . ', port=' . $systemInfo->port . ', p2pPort=' . $systemInfo->p2PPort . ', title=' . $systemInfo->titleId . ', login=' . $systemInfo->serverLogin . '.';
$this->maniaControl->getChat()->sendInformation($message, $player->login);
$message = $this->maniaControl->getChat()->formatMessage(
'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,30 +332,38 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
}
// Check for delayed shutdown
$params = explode(' ', $chat[1][2]);
if (count($params) >= 2) {
$param = $params[1];
if (strtolower($param) === 'empty') {
$this->serverShutdownEmpty = !$this->serverShutdownEmpty;
if ($this->serverShutdownEmpty) {
$this->maniaControl->getChat()->sendInformation("The server will shutdown as soon as it's empty!", $player);
return;
}
$this->maniaControl->getChat()->sendInformation("Empty-shutdown cancelled!", $player);
return;
}
$delay = (int) $param;
if ($delay <= 0) {
// Cancel shutdown
$this->serverShutdownTime = -1;
$this->maniaControl->getChat()->sendInformation("Delayed shutdown cancelled!", $player);
return;
}
// Trigger delayed shutdown
$this->serverShutdownTime = time() + $delay * 60.;
$this->maniaControl->getChat()->sendInformation("The server will shut down in {$delay} minutes!", $player);
if (count($params) < 2) {
$this->shutdownServer($player->login);
return;
}
$this->shutdownServer($player->login);
$param = $params[1];
if (strtolower($param) === 'empty') {
$this->serverShutdownEmpty = !$this->serverShutdownEmpty;
if ($this->serverShutdownEmpty) {
$this->maniaControl->getChat()->sendInformation("The server will shutdown as soon as it's empty!", $player);
return;
}
$this->maniaControl->getChat()->sendInformation("Empty-shutdown cancelled!", $player);
return;
}
$delay = (int) $param;
if ($delay <= 0) {
// Cancel shutdown
$this->serverShutdownTime = -1;
$this->maniaControl->getChat()->sendInformation("Delayed shutdown cancelled!", $player);
return;
}
// Trigger delayed shutdown
$this->serverShutdownTime = time() + $delay * 60.;
$message = $this->maniaControl->getChat()->formatMessage(
'The server will shut down in %s minutes!',
$delay
);
$this->maniaControl->getChat()->sendInformation($message, $player);
}
/**
@ -338,14 +377,24 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$params = explode(' ', $chat[1][2], 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;
}
$serverName = $params[1];
$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);
return;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
$password = '';
$successMessage = 'Password removed!';
$messageParts = explode(' ', $chatCallback[1][2], 2);
$password = '';
$message = 'Password removed!';
if (isset($messageParts[1])) {
$password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!";
$password = $messageParts[1];
$message = $this->maniaControl->getChat()->formatMessage(
'Password changed to %s!',
$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);
return;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
$password = '';
$successMessage = 'Spectator password removed!';
$messageParts = explode(' ', $chatCallback[1][2], 2);
$password = '';
$message = 'Spectator password removed!';
if (isset($messageParts[1])) {
$password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!";
$password = $messageParts[1];
$message = $this->maniaControl->getChat()->formatMessage(
'Spectator password changed to %s!',
$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);
return;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxplayers 16', $player);
if (!isset($messageParts[1]) || !is_numeric($messageParts[1])) {
$message = $this->maniaControl->getChat()->formatMessage(
'Usage example: %s',
'//setmaxplayers 16'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return;
}
$amount = $messageParts[1];
if (!is_numeric($amount)) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxplayers 16', $player);
return;
}
$amount = (int) $amount;
$amount = intval($messageParts[1]);
if ($amount < 0) {
$amount = 0;
}
$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);
return;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxspectators 16', $player);
if (!isset($messageParts[1]) || !is_numeric($messageParts[1])) {
$message = $this->maniaControl->getChat()->formatMessage(
'Usage example: %s',
'//setmaxspectators 16'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return;
}
$amount = $messageParts[1];
if (!is_numeric($amount)) {
$this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxspectators 16', $player);
return;
}
$amount = (int) $amount;
$amount = intval($messageParts[1]);
if ($amount < 0) {
$amount = 0;
}
$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);
$minutes = intval($minutestotal - 24 * 60 * $days - $hours * 60);
$days > 1 ? $dayString = 'days' : $dayString = 'day';
$hours > 1 ? $hourString = 'hours' : $hourString = 'hour';
$minutes > 1 ? $minuteString = 'minutes' : $minuteString = 'minute';
$dayString = ($days == 1 ? 'day' : 'days' );
$hourString = ($hours == 1 ? 'hour' : 'hours' );
$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;
try {
$loaded = $this->maniaControl->getClient()->setServerOptions($newServerOptions);
} catch (ServerOptionsException $exception) {
$this->maniaControl->getChat()->sendExceptionToAdmins($exception);
} catch (ServerOptionsException $e) {
$this->maniaControl->getChat()->sendExceptionToAdmins($e);
}
if ($loaded) {
@ -371,8 +371,8 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
private function applyNewServerOptions(ServerOptions $newServerOptions, $player = null) {
try {
$this->maniaControl->getClient()->setServerOptions($newServerOptions);
} catch (ServerOptionsException $exception) {
$this->maniaControl->getChat()->sendException($exception, $player);
} catch (ServerOptionsException $e) {
$this->maniaControl->getChat()->sendException($e, $player);
return false;
}

View File

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

View File

@ -172,6 +172,10 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
* @param string $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);
}
}