Prevent client from ignoring Kicked event

This commit is contained in:
tylerlowrey 2020-08-11 13:02:21 -04:00 committed by Joshua Yanovski
parent d379f3ecd8
commit 10ad6dac0d
3 changed files with 33 additions and 11 deletions

View File

@ -24,9 +24,9 @@ use std::convert::TryFrom;
use vek::*; use vek::*;
use world::util::Sampler; use world::util::Sampler;
use crate::login_provider::LoginProvider;
use scan_fmt::{scan_fmt, scan_fmt_some}; use scan_fmt::{scan_fmt, scan_fmt_some};
use tracing::error; use tracing::error;
use crate::login_provider::LoginProvider;
pub trait ChatCommandExt { pub trait ChatCommandExt {
fn execute(&self, server: &mut Server, entity: EcsEntity, args: String); fn execute(&self, server: &mut Server, entity: EcsEntity, args: String);
@ -1816,6 +1816,11 @@ fn handle_whitelist(
} }
fn kick_player(server: &mut Server, target_player: EcsEntity, reason: &str) { fn kick_player(server: &mut Server, target_player: EcsEntity, reason: &str) {
server
.state
.ecs()
.read_resource::<EventBus<ServerEvent>>()
.emit_now(ServerEvent::ClientDisconnect(target_player));
server.notify_client(target_player, ServerMsg::Kicked(reason.to_string())); server.notify_client(target_player, ServerMsg::Kicked(reason.to_string()));
} }
@ -1871,7 +1876,11 @@ fn handle_ban(
scan_fmt_some!(&args, &action.arg_fmt(), String, String) scan_fmt_some!(&args, &action.arg_fmt(), String, String)
{ {
let reason = reason_opt.unwrap_or_default(); let reason = reason_opt.unwrap_or_default();
let uuid_result = server.state.ecs().read_resource::<LoginProvider>().username_to_uuid(&target_alias); let uuid_result = server
.state
.ecs()
.read_resource::<LoginProvider>()
.username_to_uuid(&target_alias);
if let Ok(uuid) = uuid_result { if let Ok(uuid) = uuid_result {
if server.settings().banlist.contains_key(&uuid) { if server.settings().banlist.contains_key(&uuid) {
@ -1882,7 +1891,8 @@ fn handle_ban(
) )
} else { } else {
server.settings_mut().edit(|s| { server.settings_mut().edit(|s| {
s.banlist.insert(uuid, (target_alias.clone(), reason.clone())); s.banlist
.insert(uuid, (target_alias.clone(), reason.clone()));
}); });
server.notify_client( server.notify_client(
client, client,
@ -1905,7 +1915,10 @@ fn handle_ban(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.server_msg(format!("Unable to determine UUID for username \"{}\"", target_alias)) ChatType::CommandError.server_msg(format!(
"Unable to determine UUID for username \"{}\"",
target_alias
)),
) )
} }
} else { } else {
@ -1924,7 +1937,11 @@ fn handle_unban(
action: &ChatCommand, action: &ChatCommand,
) { ) {
if let Ok(username) = scan_fmt!(&args, &action.arg_fmt(), String) { if let Ok(username) = scan_fmt!(&args, &action.arg_fmt(), String) {
let uuid_result = server.state.ecs().read_resource::<LoginProvider>().username_to_uuid(&username); let uuid_result = server
.state
.ecs()
.read_resource::<LoginProvider>()
.username_to_uuid(&username);
if let Ok(uuid) = uuid_result { if let Ok(uuid) = uuid_result {
server.settings_mut().edit(|s| { server.settings_mut().edit(|s| {
@ -1937,10 +1954,12 @@ fn handle_unban(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.server_msg(format!("Unable to determine UUID for username \"{}\"", username)) ChatType::CommandError.server_msg(format!(
"Unable to determine UUID for username \"{}\"",
username
)),
) )
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,

View File

@ -1,4 +1,4 @@
use authc::{AuthClient, AuthToken, Uuid, AuthClientError}; use authc::{AuthClient, AuthClientError, AuthToken, Uuid};
use common::msg::RegisterError; use common::msg::RegisterError;
use hashbrown::HashMap; use hashbrown::HashMap;
use std::str::FromStr; use std::str::FromStr;
@ -105,6 +105,9 @@ impl LoginProvider {
} }
pub fn username_to_uuid(&self, username: &str) -> Result<Uuid, AuthClientError> { pub fn username_to_uuid(&self, username: &str) -> Result<Uuid, AuthClientError> {
self.auth_server.as_ref().map_or_else(|| Ok(derive_uuid(username)), |auth| auth.username_to_uuid(&username)) self.auth_server.as_ref().map_or_else(
|| Ok(derive_uuid(username)),
|auth| auth.username_to_uuid(&username),
)
} }
} }

View File

@ -1,10 +1,10 @@
use authc::Uuid;
use hashbrown::HashMap; use hashbrown::HashMap;
use portpicker::pick_unused_port; use portpicker::pick_unused_port;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{fs, io::prelude::*, net::SocketAddr, path::PathBuf, time::Duration}; use std::{fs, io::prelude::*, net::SocketAddr, path::PathBuf, time::Duration};
use tracing::{error, warn}; use tracing::{error, warn};
use world::sim::FileOpts; use world::sim::FileOpts;
use authc::Uuid;
const DEFAULT_WORLD_SEED: u32 = 59686; const DEFAULT_WORLD_SEED: u32 = 59686;