mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-30 11:47:45 +00:00
Fix the "unknown command" message for real, now
Now it takes into account if the command exists on the Rust side, and the message should now *only* display if no one truly handles this command.
This commit is contained in:
parent
fbe6862c7b
commit
77b6fbad7f
2 changed files with 52 additions and 37 deletions
|
@ -504,6 +504,7 @@ async fn client_loop(
|
|||
let parts: Vec<&str> = chat_message.message.split(' ').collect();
|
||||
let command_name = &parts[0][1..];
|
||||
|
||||
{
|
||||
let lua = lua.lock().unwrap();
|
||||
let state = lua.app_data_ref::<ExtraLuaState>().unwrap();
|
||||
|
||||
|
@ -568,11 +569,25 @@ async fn client_loop(
|
|||
|
||||
if let Err(err) = run_script() {
|
||||
tracing::warn!("Lua error in {file_name}: {:?}", err);
|
||||
handled = false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to Rust implemented commands
|
||||
if !handled {
|
||||
handled = ChatHandler::handle_chat_message(
|
||||
&mut connection,
|
||||
chat_message,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
// If it's truly not existent:
|
||||
if !handled {
|
||||
tracing::info!("Unknown command {command_name}");
|
||||
|
||||
let lua = lua.lock().unwrap();
|
||||
|
||||
let mut call_func = || {
|
||||
lua.scope(|scope| {
|
||||
let connection_data = scope
|
||||
|
@ -586,19 +601,9 @@ async fn client_loop(
|
|||
|
||||
if let Err(err) = call_func() {
|
||||
tracing::warn!("Lua error in Global.lua: {:?}", err);
|
||||
handled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to Rust implemented commands
|
||||
if !handled {
|
||||
ChatHandler::handle_chat_message(
|
||||
&mut connection,
|
||||
chat_message,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
ClientZoneIpcData::GMCommand { command, arg0, arg1, .. } => {
|
||||
tracing::info!("Got a game master command!");
|
||||
|
|
|
@ -9,14 +9,18 @@ use super::ZoneConnection;
|
|||
pub struct ChatHandler {}
|
||||
|
||||
impl ChatHandler {
|
||||
pub async fn handle_chat_message(connection: &mut ZoneConnection, chat_message: &ChatMessage) {
|
||||
/// Returns true if the command is handled, otherwise false.
|
||||
pub async fn handle_chat_message(
|
||||
connection: &mut ZoneConnection,
|
||||
chat_message: &ChatMessage,
|
||||
) -> bool {
|
||||
if connection.player_data.gm_rank == GameMasterRank::NormalUser {
|
||||
tracing::info!("Rejecting debug command because the user is not GM!");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
let parts: Vec<&str> = chat_message.message.split(' ').collect();
|
||||
match parts[0] {
|
||||
return match parts[0] {
|
||||
"!spawnnpc" => {
|
||||
connection
|
||||
.handle
|
||||
|
@ -25,6 +29,7 @@ impl ChatHandler {
|
|||
connection.player_data.actor_id,
|
||||
))
|
||||
.await;
|
||||
true
|
||||
}
|
||||
"!spawnmonster" => {
|
||||
connection
|
||||
|
@ -34,6 +39,7 @@ impl ChatHandler {
|
|||
connection.player_data.actor_id,
|
||||
))
|
||||
.await;
|
||||
true
|
||||
}
|
||||
"!spawnclone" => {
|
||||
connection
|
||||
|
@ -43,6 +49,7 @@ impl ChatHandler {
|
|||
connection.player_data.actor_id,
|
||||
))
|
||||
.await;
|
||||
true
|
||||
}
|
||||
"!equip" => {
|
||||
let (_, name) = chat_message.message.split_once(' ').unwrap();
|
||||
|
@ -69,10 +76,12 @@ impl ChatHandler {
|
|||
}
|
||||
|
||||
connection.send_inventory(true).await;
|
||||
true
|
||||
}
|
||||
"!reload" => {
|
||||
connection.reload_scripts();
|
||||
connection.send_message("Scripts reloaded!").await;
|
||||
true
|
||||
}
|
||||
"!finishevent" => {
|
||||
if let Some(event) = &connection.event {
|
||||
|
@ -81,8 +90,9 @@ impl ChatHandler {
|
|||
.send_message("Current event forcefully finished.")
|
||||
.await;
|
||||
}
|
||||
true
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue