2025-03-16 14:07:56 -04:00
|
|
|
use crate::{
|
2025-05-12 22:32:03 -04:00
|
|
|
inventory::Storage,
|
2025-06-21 13:30:52 -04:00
|
|
|
ipc::zone::{ChatMessage, GameMasterRank},
|
2025-06-18 20:53:07 -04:00
|
|
|
world::ToServer,
|
2025-03-16 14:07:56 -04:00
|
|
|
};
|
|
|
|
|
2025-06-18 20:53:07 -04:00
|
|
|
use super::ZoneConnection;
|
2025-03-15 20:36:39 -04:00
|
|
|
|
|
|
|
pub struct ChatHandler {}
|
|
|
|
|
|
|
|
impl ChatHandler {
|
2025-06-22 09:28:50 -04:00
|
|
|
/// Returns true if the command is handled, otherwise false.
|
|
|
|
pub async fn handle_chat_message(
|
|
|
|
connection: &mut ZoneConnection,
|
|
|
|
chat_message: &ChatMessage,
|
|
|
|
) -> bool {
|
2025-06-18 20:58:32 -04:00
|
|
|
if connection.player_data.gm_rank == GameMasterRank::NormalUser {
|
|
|
|
tracing::info!("Rejecting debug command because the user is not GM!");
|
2025-06-22 09:28:50 -04:00
|
|
|
return true;
|
2025-06-18 20:58:32 -04:00
|
|
|
}
|
|
|
|
|
2025-03-15 20:36:39 -04:00
|
|
|
let parts: Vec<&str> = chat_message.message.split(' ').collect();
|
2025-06-22 09:28:50 -04:00
|
|
|
return match parts[0] {
|
2025-03-18 22:13:28 -04:00
|
|
|
"!spawnnpc" => {
|
2025-04-01 19:15:08 -04:00
|
|
|
connection
|
2025-06-18 20:38:55 -04:00
|
|
|
.handle
|
|
|
|
.send(ToServer::DebugNewNpc(
|
|
|
|
connection.id,
|
|
|
|
connection.player_data.actor_id,
|
|
|
|
))
|
2025-04-01 19:15:08 -04:00
|
|
|
.await;
|
2025-06-22 09:28:50 -04:00
|
|
|
true
|
2025-03-23 10:33:49 -04:00
|
|
|
}
|
|
|
|
"!spawnmonster" => {
|
2025-05-09 20:09:22 -04:00
|
|
|
connection
|
|
|
|
.handle
|
2025-06-18 20:38:55 -04:00
|
|
|
.send(ToServer::DebugNewEnemy(
|
2025-06-18 20:28:03 -04:00
|
|
|
connection.id,
|
|
|
|
connection.player_data.actor_id,
|
|
|
|
))
|
2025-05-09 20:09:22 -04:00
|
|
|
.await;
|
2025-06-22 09:28:50 -04:00
|
|
|
true
|
2025-03-16 14:07:56 -04:00
|
|
|
}
|
2025-04-01 19:15:08 -04:00
|
|
|
"!spawnclone" => {
|
|
|
|
connection
|
2025-06-18 20:57:20 -04:00
|
|
|
.handle
|
|
|
|
.send(ToServer::DebugSpawnClone(
|
|
|
|
connection.id,
|
|
|
|
connection.player_data.actor_id,
|
|
|
|
))
|
2025-04-01 19:15:08 -04:00
|
|
|
.await;
|
2025-06-22 09:28:50 -04:00
|
|
|
true
|
2025-04-01 19:15:08 -04:00
|
|
|
}
|
2025-05-12 22:32:03 -04:00
|
|
|
"!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
|
2025-06-23 14:10:04 -04:00
|
|
|
.get_slot_mut(slot)
|
2025-05-12 22:32:03 -04:00
|
|
|
.id = id;
|
|
|
|
connection
|
|
|
|
.player_data
|
|
|
|
.inventory
|
|
|
|
.equipped
|
2025-06-23 14:10:04 -04:00
|
|
|
.get_slot_mut(slot)
|
2025-05-12 22:32:03 -04:00
|
|
|
.quantity = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connection.send_inventory(true).await;
|
2025-06-22 09:28:50 -04:00
|
|
|
true
|
2025-05-12 22:32:03 -04:00
|
|
|
}
|
2025-06-22 08:49:06 -04:00
|
|
|
"!reload" => {
|
|
|
|
connection.reload_scripts();
|
|
|
|
connection.send_message("Scripts reloaded!").await;
|
2025-06-22 09:28:50 -04:00
|
|
|
true
|
2025-06-22 08:49:06 -04:00
|
|
|
}
|
|
|
|
"!finishevent" => {
|
|
|
|
if let Some(event) = &connection.event {
|
|
|
|
connection.event_finish(event.id).await;
|
|
|
|
connection
|
|
|
|
.send_message("Current event forcefully finished.")
|
|
|
|
.await;
|
|
|
|
}
|
2025-06-22 09:28:50 -04:00
|
|
|
true
|
2025-06-22 08:49:06 -04:00
|
|
|
}
|
2025-06-22 09:28:50 -04:00
|
|
|
_ => false,
|
|
|
|
};
|
2025-03-15 20:36:39 -04:00
|
|
|
}
|
|
|
|
}
|