1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-30 11:47:45 +00:00
kawari/src/world/chat_handler.rs
Joshua Goins 198a8a3e2c Make !reload command always available, add !finishevent
The reload command was previously implemented in Lua, but this
is a little dangerous as it could itself have an error and is
unable to work in the first place. I moved this to Rust to
ensure it's always available. I left the reload_scripts() API
in Lua as someone could still find that useful!

Additionally, I added a !finishevent debug command to forcefully
end the current event you're in. This can be useful if your script
is incomplete or has an error, as your client gets stuck very
easily.
2025-06-22 08:49:06 -04:00

88 lines
2.9 KiB
Rust

use crate::{
inventory::Storage,
ipc::zone::{ChatMessage, GameMasterRank},
world::ToServer,
};
use super::ZoneConnection;
pub struct ChatHandler {}
impl ChatHandler {
pub async fn handle_chat_message(connection: &mut ZoneConnection, chat_message: &ChatMessage) {
if connection.player_data.gm_rank == GameMasterRank::NormalUser {
tracing::info!("Rejecting debug command because the user is not GM!");
return;
}
let parts: Vec<&str> = chat_message.message.split(' ').collect();
match parts[0] {
"!spawnnpc" => {
connection
.handle
.send(ToServer::DebugNewNpc(
connection.id,
connection.player_data.actor_id,
))
.await;
}
"!spawnmonster" => {
connection
.handle
.send(ToServer::DebugNewEnemy(
connection.id,
connection.player_data.actor_id,
))
.await;
}
"!spawnclone" => {
connection
.handle
.send(ToServer::DebugSpawnClone(
connection.id,
connection.player_data.actor_id,
))
.await;
}
"!equip" => {
let (_, name) = chat_message.message.split_once(' ').unwrap();
{
let mut gamedata = connection.gamedata.lock().unwrap();
if let Some((equip_category, id)) = gamedata.get_item_by_name(name) {
let slot = gamedata.get_equipslot_category(equip_category).unwrap();
connection
.player_data
.inventory
.equipped
.get_slot_mut(slot as u16)
.id = id;
connection
.player_data
.inventory
.equipped
.get_slot_mut(slot as u16)
.quantity = 1;
}
}
connection.send_inventory(true).await;
}
"!reload" => {
connection.reload_scripts();
connection.send_message("Scripts reloaded!").await;
}
"!finishevent" => {
if let Some(event) = &connection.event {
connection.event_finish(event.id).await;
connection
.send_message("Current event forcefully finished.")
.await;
}
}
_ => {}
}
}
}