Merge branch 'coffee-compiler/localize_server_command_results' into 'master'

Localize more server command results

See merge request veloren/veloren!4559
This commit is contained in:
Illia Denysenko 2024-08-21 07:36:03 +00:00
commit 488062643b
2 changed files with 144 additions and 56 deletions

View File

@ -122,6 +122,9 @@ command-username-uuid-unavailable = Unable to determine UUID for username { $use
command-uuid-username-unavailable = Unable to determine username for UUID { $uuid } command-uuid-username-unavailable = Unable to determine username for UUID { $uuid }
command-no-sudo = It's rude to impersonate people command-no-sudo = It's rude to impersonate people
command-entity-dead = Entity '{ $entity }' is dead! command-entity-dead = Entity '{ $entity }' is dead!
command-error-write-settings = Failed to write settings file to disk, but succeeded in memory.
Error (storage): { $error }
Success (memory): { $message }
command-error-while-evaluating-request = Encountered an error while validating the request: { $error } command-error-while-evaluating-request = Encountered an error while validating the request: { $error }
command-give-inventory-full = Player inventory full. Gave { $given -> command-give-inventory-full = Player inventory full. Gave { $given ->
[1] only one [1] only one
@ -139,6 +142,8 @@ command-time-parse-too-large = { $n } is invalid, cannot be larger than 16 digit
command-time-parse-negative = { $n } is invalid, cannot be negative. command-time-parse-negative = { $n } is invalid, cannot be negative.
command-time-backwards = { $t } is before the current time, time cannot go backwards. command-time-backwards = { $t } is before the current time, time cannot go backwards.
command-time-invalid = { $t } is not a valid time. command-time-invalid = { $t } is not a valid time.
command-time-current = It is { $t }
command-time-unknown = Time unknown
command-rtsim-purge-perms = You must be a real admin (not just a temporary admin) to purge rtsim data. command-rtsim-purge-perms = You must be a real admin (not just a temporary admin) to purge rtsim data.
command-chunk-not-loaded = Chunk { $x }, { $y } not loaded command-chunk-not-loaded = Chunk { $x }, { $y } not loaded
command-chunk-out-of-bounds = Chunk { $x }, { $y } not within map bounds command-chunk-out-of-bounds = Chunk { $x }, { $y } not within map bounds
@ -159,6 +164,9 @@ command-no-buid-perms = You do not have permission to build.
command-set-build-mode-off = Toggled build mode off. command-set-build-mode-off = Toggled build mode off.
command-set-build-mode-on-persistent = Toggled build mode on. Experimental terrain persistence is enabled. The server will attempt to persist changes, but this is not guaranteed. command-set-build-mode-on-persistent = Toggled build mode on. Experimental terrain persistence is enabled. The server will attempt to persist changes, but this is not guaranteed.
command-set-build-mode-on-unpersistent = Toggled build mode on. Changes will not be persisted when a chunk unloads. command-set-build-mode-on-unpersistent = Toggled build mode on. Changes will not be persisted when a chunk unloads.
command-set_motd-message-added = Server message of the day set to { $message }
command-set_motd-message-removed = Removed server message of the day
command-set_motd-message-not-set = This locale had no motd set
command-invalid-alignment = Invalid alignment: { $alignment } command-invalid-alignment = Invalid alignment: { $alignment }
command-kit-not-enough-slots = Inventory doesn't have enough slots command-kit-not-enough-slots = Inventory doesn't have enough slots
command-lantern-unequiped = Please equip a lantern first command-lantern-unequiped = Please equip a lantern first
@ -198,6 +206,7 @@ command-repaired-items = Repaired all equipped items
command-message-group-missing = You are using group chat but do not belong to a group. Use /world or command-message-group-missing = You are using group chat but do not belong to a group. Use /world or
/region to change chat. /region to change chat.
command-tell-request = { $sender } wants to talk to you. command-tell-request = { $sender } wants to talk to you.
command-tell-to-yourself = You can't /tell yourself.
command-transform-invalid-presence = Cannot transform in the current presence command-transform-invalid-presence = Cannot transform in the current presence
command-aura-invalid-buff-parameters = Invalid buff parameters for aura command-aura-invalid-buff-parameters = Invalid buff parameters for aura
command-aura-spawn = Spawned new aura attached to entity command-aura-spawn = Spawned new aura attached to entity
@ -205,6 +214,36 @@ command-aura-spawn-new-entity = Spawned new aura
command-reloaded-chunks = Reloaded { $reloaded } chunks command-reloaded-chunks = Reloaded { $reloaded } chunks
command-server-no-experimental-terrain-persistence = Server was compiled without terrain persistence enabled command-server-no-experimental-terrain-persistence = Server was compiled without terrain persistence enabled
command-experimental-terrain-persistence-disabled = Experimental terrain persistence is disabled command-experimental-terrain-persistence-disabled = Experimental terrain persistence is disabled
command-adminify-assign-higher-than-own = Cannot assign someone a temporary role higher than your own permanent one.
command-adminify-reassign-to-above = Cannot reassign a role for anyone with your role or higher.
command-adminify-cannot-find-player = Cannot find player entity!
command-adminify-already-has-role = Player already has that role!
command-adminify-already-has-no-role = Player already has no role!
command-adminify-role-downgraded = Role for player { $player } downgraded to { $role }
command-adminify-role-upgraded = Role for player { $player } upgraded to { $role }
command-adminify-removed-role = Role removed from player { $player }: { $role }
command-ban-added = Added { $player } to the banlist with reason: { $reason }
command-ban-already-added = { $player } is already on the banlist
command-faction-join = Please join a faction with /join_faction
command-group-join = Please create a group first
command-group_invite-invited-to-group = Invited { $player } to the group.
command-group_invite-invited-to-your-group = { $player } has been invited to your group.
command-into_npc-warning = I hope you aren't abusing this!
command-kick-higher-role = Cannot kick players with roles higher than your own.
command-respawn-no-waypoint = No waypoint set
command-site-not-found = Site not found
command-sudo-higher-role = Cannot sudo players with roles higher than your own.
command-sudo-no-permission-for-non-players = You don't have permission to sudo non-players.
command-time_scale-current = The current time scale is { $scale }.
command-time_scale-changed = Set time scale to { $scale }.
command-unban-successful = { $player } was successfully unbanned.
command-unban-already-unbanned = { $player } was already unbanned.
command-version-current = Server is running { $hash }[{ $date }]
command-whitelist-added = Added to whitelist: { $username }
command-whitelist-already-added = Already in whitelist: { $username }!
command-whitelist-removed = Removed from whitelist: { $username }
command-whitelist-unlisted = Not part of whitelist: { $username }
command-whitelist-permission-denied = Permission denied to remove user: { $username }
# Unreachable/untestable but added for consistency # Unreachable/untestable but added for consistency

View File

@ -341,7 +341,7 @@ fn verify_above_role(
server: &mut Server, server: &mut Server,
(client, client_uuid): (EcsEntity, Uuid), (client, client_uuid): (EcsEntity, Uuid),
(player, player_uuid): (EcsEntity, Uuid), (player, player_uuid): (EcsEntity, Uuid),
reason: &str, reason: Content,
) -> CmdResult<()> { ) -> CmdResult<()> {
let client_temp = server.entity_admin_role(client); let client_temp = server.entity_admin_role(client);
let client_perm = server let client_perm = server
@ -360,7 +360,7 @@ fn verify_above_role(
if client_perm > player_perm || client_perm == player_perm && client_temp > player_temp { if client_perm > player_perm || client_perm == player_perm && client_temp > player_temp {
Ok(()) Ok(())
} else { } else {
Err(reason.into()) Err(reason)
} }
} }
@ -429,8 +429,8 @@ fn uuid_to_username(
fn edit_setting_feedback<S: EditableSetting>( fn edit_setting_feedback<S: EditableSetting>(
server: &mut Server, server: &mut Server,
client: EcsEntity, client: EcsEntity,
result: Option<(String, Result<(), SettingError<S>>)>, result: Option<(Content, Result<(), SettingError<S>>)>,
failure: impl FnOnce() -> String, failure: impl FnOnce() -> Content,
) -> CmdResult<()> { ) -> CmdResult<()> {
let (info, result) = result.ok_or_else(failure)?; let (info, result) = result.ok_or_else(failure)?;
match result { match result {
@ -445,19 +445,17 @@ fn edit_setting_feedback<S: EditableSetting>(
warn!( warn!(
?err, ?err,
"Failed to write settings file to disk, but succeeded in memory (success message: \ "Failed to write settings file to disk, but succeeded in memory (success message: \
{})", {:?})",
info, info,
); );
server.notify_client( server.notify_client(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandError, ChatType::CommandError,
format!( Content::localized_with_args("command-error-write-settings", [
"Failed to write settings file to disk, but succeeded in memory.\n ("error", Content::Plain(format!("{:?}", err))),
Error (storage): {:?}\n ("message", info),
Success (memory): {}", ]),
err, info
),
), ),
); );
Ok(()) Ok(())
@ -655,7 +653,7 @@ fn handle_into_npc(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandInfo, ChatType::CommandInfo,
Content::Plain("I hope you aren't abusing this!".to_owned()), Content::localized("command-into_npc-warning"),
), ),
); );
} }
@ -866,7 +864,10 @@ fn handle_set_motd(
.editable_settings_mut() .editable_settings_mut()
.server_description .server_description
.edit(data_dir.as_ref(), |d| { .edit(data_dir.as_ref(), |d| {
let info = format!("Server message of the day set to {:?}", msg); let info = Content::localized_with_args(
"command-set_motd-message-added",
[("message", format!("{:?}", msg))],
);
if let Some(description) = d.descriptions.get_mut(&locale) { if let Some(description) = d.descriptions.get_mut(&locale) {
description.motd = msg; description.motd = msg;
@ -892,9 +893,9 @@ fn handle_set_motd(
.edit(data_dir.as_ref(), |d| { .edit(data_dir.as_ref(), |d| {
if let Some(description) = d.descriptions.get_mut(&locale) { if let Some(description) = d.descriptions.get_mut(&locale) {
description.motd.clear(); description.motd.clear();
Some("Removed server message of the day".to_string()) Some(Content::localized("command-set_motd-message-removed"))
} else { } else {
Some("This locale had no motd set".to_string()) Some(Content::localized("command-set_motd-message-not-set"))
} }
}); });
drop(data_dir); drop(data_dir);
@ -974,7 +975,7 @@ fn handle_site(
site.site_tmp site.site_tmp
.map_or(false, |id| server.index.sites[id].name() == dest_name) .map_or(false, |id| server.index.sites[id].name() == dest_name)
}) })
.ok_or_else(|| "Site not found".to_string())?; .ok_or_else(|| Content::localized("command-site-not-found"))?;
let site_pos = server.world.find_accessible_pos( let site_pos = server.world.find_accessible_pos(
server.index.as_index_ref(), server.index.as_index_ref(),
@ -1003,7 +1004,7 @@ fn handle_respawn(
.state .state
.read_storage::<comp::Waypoint>() .read_storage::<comp::Waypoint>()
.get(target) .get(target)
.ok_or("No waypoint set")? .ok_or(Content::localized("command-respawn-no-waypoint"))?
.get_pos(); .get_pos();
server.state.position_mut(target, true, |current_pos| { server.state.position_mut(target, true, |current_pos| {
@ -1179,8 +1180,11 @@ fn handle_time(
0, 0,
); );
let msg = match current_time { let msg = match current_time {
Some(time) => format!("It is {}", time.format("%H:%M")), Some(time) => Content::localized_with_args("command-time-current", [(
None => String::from("Unknown Time"), "t",
time.format("%H:%M").to_string(),
)]),
None => Content::localized("command-time-unknown"),
}; };
server.notify_client( server.notify_client(
client, client,
@ -1244,14 +1248,23 @@ fn handle_time_scale(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandInfo, ChatType::CommandInfo,
format!("The current time scale is {time_scale}."), Content::localized_with_args("command-time_scale-current", [(
"scale",
time_scale.to_string(),
)]),
), ),
); );
} else if let Some(scale) = parse_cmd_args!(args, f64) { } else if let Some(scale) = parse_cmd_args!(args, f64) {
time_scale.0 = scale.clamp(0.0001, 1000.0); time_scale.0 = scale.clamp(0.0001, 1000.0);
server.notify_client( server.notify_client(
client, client,
ServerGeneral::server_msg(ChatType::CommandInfo, format!("Set time scale to {scale}.")), ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::localized_with_args("command-time_scale-changed", [(
"scale",
scale.to_string(),
)]),
),
); );
// Update all clients with the new TimeOfDay (without this they would have to // Update all clients with the new TimeOfDay (without this they would have to
// wait for the next 100th tick to receive the update). // wait for the next 100th tick to receive the update).
@ -3073,7 +3086,7 @@ fn handle_adminify(
server, server,
(client, client_uuid), (client, client_uuid),
(player, player_uuid), (player, player_uuid),
"Cannot reassign a role for anyone with your role or higher.", Content::localized("command-adminify-reassign-to-above"),
)?; )?;
// Ensure that it's not possible to assign someone a higher role than your own // Ensure that it's not possible to assign someone a higher role than your own
@ -3091,18 +3104,18 @@ fn handle_adminify(
// ban. So if we change how bans work, we should change how things work // ban. So if we change how bans work, we should change how things work
// here, too, for consistency. // here, too, for consistency.
if desired_role > Some(client_real_role) { if desired_role > Some(client_real_role) {
return Err( return Err(Content::localized(
"Cannot assign someone a temporary role higher than your own permanent one".into(), "command-adminify-assign-higher-than-own",
); ));
} }
let mut admin_storage = server.state.ecs().write_storage::<comp::Admin>(); let mut admin_storage = server.state.ecs().write_storage::<comp::Admin>();
let entry = admin_storage let entry = admin_storage
.entry(player) .entry(player)
.map_err(|_| "Cannot find player entity!".to_string())?; .map_err(|_| Content::localized("command-adminify-cannot-find-player"))?;
match (entry, desired_role) { match (entry, desired_role) {
(StorageEntry::Vacant(_), None) => { (StorageEntry::Vacant(_), None) => {
return Err("Player already has no role!".into()); return Err(Content::localized("command-adminify-already-has-no-role"));
}, },
(StorageEntry::Occupied(o), None) => { (StorageEntry::Occupied(o), None) => {
let old_role = o.remove().0; let old_role = o.remove().0;
@ -3110,26 +3123,32 @@ fn handle_adminify(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandInfo, ChatType::CommandInfo,
format!("Role removed from player {}: {:?}", alias, old_role), Content::localized_with_args("command-adminify-removed-role", [
("player", alias),
("role", format!("{:?}", old_role)),
]),
), ),
); );
}, },
(entry, Some(desired_role)) => { (entry, Some(desired_role)) => {
let verb = match entry let key = match entry
.replace(comp::Admin(desired_role)) .replace(comp::Admin(desired_role))
.map(|old_admin| old_admin.0.cmp(&desired_role)) .map(|old_admin| old_admin.0.cmp(&desired_role))
{ {
Some(Ordering::Equal) => { Some(Ordering::Equal) => {
return Err("Player already has that role!".into()); return Err(Content::localized("command-adminify-already-has-role"));
}, },
Some(Ordering::Greater) => "downgraded", Some(Ordering::Greater) => "command-adminify-role-downgraded",
Some(Ordering::Less) | None => "upgraded", Some(Ordering::Less) | None => "command-adminify-role-upgraded",
}; };
server.notify_client( server.notify_client(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandInfo, ChatType::CommandInfo,
format!("Role for player {} {} to {:?}", alias, verb, desired_role), Content::localized_with_args(key, [
("player", alias),
("role", format!("{:?}", desired_role)),
]),
), ),
); );
}, },
@ -3161,7 +3180,7 @@ fn handle_tell(
let player = find_alias(ecs, &alias)?.0; let player = find_alias(ecs, &alias)?.0;
if player == target { if player == target {
return Err("You can't /tell yourself.".into()); return Err(Content::localized("command-tell-to-yourself"));
} }
let target_uid = uid(server, target, "target")?; let target_uid = uid(server, target, "target")?;
let player_uid = uid(server, player, "player")?; let player_uid = uid(server, player, "player")?;
@ -3211,7 +3230,7 @@ fn handle_faction(
server.notify_client(target, ServerGeneral::ChatMode(mode)); server.notify_client(target, ServerGeneral::ChatMode(mode));
Ok(()) Ok(())
} else { } else {
Err("Please join a faction with /join_faction".into()) Err(Content::localized("command-faction-join"))
} }
} }
@ -3240,7 +3259,7 @@ fn handle_group(
server.notify_client(target, ServerGeneral::ChatMode(mode)); server.notify_client(target, ServerGeneral::ChatMode(mode));
Ok(()) Ok(())
} else { } else {
Err("Please create a group first".into()) Err(Content::localized("command-group-join"))
} }
} }
@ -3264,7 +3283,10 @@ fn handle_group_invite(
target, target,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandInfo, ChatType::CommandInfo,
format!("{} has been invited to your group.", target_alias), Content::localized_with_args("command-group_invite-invited-to-your-group", [(
"player",
target_alias.to_owned(),
)]),
), ),
); );
} }
@ -3273,7 +3295,10 @@ fn handle_group_invite(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandInfo, ChatType::CommandInfo,
format!("Invited {} to the group.", target_alias), Content::localized_with_args("command-group_invite-invited-to-group", [(
"player",
target_alias.to_owned(),
)]),
), ),
); );
Ok(()) Ok(())
@ -3864,10 +3889,12 @@ fn handle_sudo(
server, server,
(client, client_uuid), (client, client_uuid),
(entity, player_uuid), (entity, player_uuid),
"Cannot sudo players with roles higher than your own.", Content::localized("command-sudo-higher-role"),
)?; )?;
} else if server.entity_admin_role(client) < Some(AdminRole::Admin) { } else if server.entity_admin_role(client) < Some(AdminRole::Admin) {
return Err("You don't have permission to sudo non-players.".into()); return Err(Content::localized(
"command-sudo-no-permission-for-non-players",
));
} }
} }
@ -3894,11 +3921,10 @@ fn handle_version(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(
ChatType::CommandInfo, ChatType::CommandInfo,
format!( Content::localized_with_args("command-version-current", [
"Server is running {}[{}]", ("hash", (*common::util::GIT_HASH).to_owned()),
*common::util::GIT_HASH, ("date", (*common::util::GIT_DATE).to_owned()),
*common::util::GIT_DATE, ]),
),
), ),
); );
Ok(()) Ok(())
@ -3939,18 +3965,23 @@ fn handle_whitelist(
if w.insert(uuid, record).is_some() { if w.insert(uuid, record).is_some() {
None None
} else { } else {
Some(format!("added to whitelist: {}", username)) Some(Content::localized_with_args("command-whitelist-added", [(
"username",
username.to_owned(),
)]))
} }
}); });
edit_setting_feedback(server, client, edit, || { edit_setting_feedback(server, client, edit, || {
format!("already in whitelist: {}!", username) Content::localized_with_args("command-whitelist-already-added", [(
"username", username,
)])
}) })
} else if whitelist_action.eq_ignore_ascii_case("remove") { } else if whitelist_action.eq_ignore_ascii_case("remove") {
let client_uuid = uuid(server, client, "client")?; let client_uuid = uuid(server, client, "client")?;
let client_role = real_role(server, client_uuid, "client")?; let client_role = real_role(server, client_uuid, "client")?;
let uuid = find_username(server, &username)?; let uuid = find_username(server, &username)?;
let mut err_info = "not part of whitelist: "; let mut err_key = "command-whitelist-unlisted";
let edit = let edit =
server server
.editable_settings_mut() .editable_settings_mut()
@ -3961,13 +3992,20 @@ fn handle_whitelist(
if record.whitelisted_by_role() <= client_role.into() { if record.whitelisted_by_role() <= client_role.into() {
true true
} else { } else {
err_info = "permission denied to remove user: "; err_key = "command-whitelist-permission-denied";
false false
} }
}) })
.map(|_| format!("removed from whitelist: {}", username)) .map(|_| {
Content::localized_with_args("command-whitelist-removed", [(
"username",
username.to_owned(),
)])
})
}); });
edit_setting_feedback(server, client, edit, || format!("{}{}", err_info, username)) edit_setting_feedback(server, client, edit, || {
Content::localized_with_args(err_key, [("username", username)])
})
} else { } else {
Err(action.help_content()) Err(action.help_content())
} }
@ -3986,7 +4024,7 @@ fn kick_player(
server, server,
(client, client_uuid), (client, client_uuid),
(target_player, target_player_uuid), (target_player, target_player_uuid),
"Cannot kick players with roles higher than your own.", Content::localized("command-kick-higher-role"),
)?; )?;
server.notify_client( server.notify_client(
target_player, target_player,
@ -4084,13 +4122,16 @@ fn handle_ban(
) )
.map(|result| { .map(|result| {
( (
format!("Added {} to the banlist with reason: {}", username, reason), Content::localized_with_args("command-ban-added", [
("player", username.to_owned()),
("reason", reason.to_owned()),
]),
result, result,
) )
}); });
edit_setting_feedback(server, client, edit, || { edit_setting_feedback(server, client, edit, || {
format!("{} is already on the banlist", username) Content::localized_with_args("command-ban-already-added", [("player", username)])
})?; })?;
// If the player is online kick them (this may fail if the player is a hardcoded // If the player is online kick them (this may fail if the player is a hardcoded
// admin; we don't care about that case because hardcoded admins can log on even // admin; we don't care about that case because hardcoded admins can log on even
@ -4397,10 +4438,18 @@ fn handle_unban(
unban, unban,
false, false,
) )
.map(|result| (format!("{} was successfully unbanned", username), result)); .map(|result| {
(
Content::localized_with_args("command-unban-successful", [(
"player",
username.to_owned(),
)]),
result,
)
});
edit_setting_feedback(server, client, edit, || { edit_setting_feedback(server, client, edit, || {
format!("{} was already unbanned", username) Content::localized_with_args("command-unban-already-unbanned", [("player", username)])
}) })
} else { } else {
Err(action.help_content()) Err(action.help_content())