1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-07-17 10:47:44 +00:00
kawari/src/world/chat_handler.rs
Joshua Goins c0daf7b06b Skip sending empty UpdateItems on first login
There's no reason to do this, the client has no pre-existing
inventory state so we're just wasting bytes.
2025-07-13 08:29:45 -04:00

116 lines
3.8 KiB
Rust

use crate::{
ITEM_CONDITION_MAX,
common::ItemInfoQuery,
inventory::{Item, Storage},
ipc::zone::{ChatMessage, GameMasterRank},
world::ToServer,
};
use super::ZoneConnection;
pub struct ChatHandler {}
impl ChatHandler {
/// 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 true;
}
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;
true
}
"!spawnmonster" => {
connection
.handle
.send(ToServer::DebugNewEnemy(
connection.id,
connection.player_data.actor_id,
))
.await;
true
}
"!spawnclone" => {
connection
.handle
.send(ToServer::DebugSpawnClone(
connection.id,
connection.player_data.actor_id,
))
.await;
true
}
"!equip" => {
let (_, name) = chat_message.message.split_once(' ').unwrap();
{
let mut gamedata = connection.gamedata.lock().unwrap();
if let Some(item_info) =
gamedata.get_item_info(ItemInfoQuery::ByName(name.to_string()))
{
let slot = gamedata
.get_equipslot_category(item_info.equip_category)
.unwrap();
let slot = connection.player_data.inventory.equipped.get_slot_mut(slot);
slot.id = item_info.id;
slot.quantity = 1;
slot.condition = ITEM_CONDITION_MAX;
}
}
connection.send_inventory(true, false).await;
true
}
"!item" => {
let (_, name) = chat_message.message.split_once(' ').unwrap();
{
let mut gamedata = connection.gamedata.lock().unwrap();
if let Some(item_info) =
gamedata.get_item_info(ItemInfoQuery::ByName(name.to_string()))
{
connection
.player_data
.inventory
.add_in_next_free_slot(Item::new(1, item_info.id));
}
}
connection.send_inventory(false, false).await;
true
}
"!reload" => {
connection.reload_scripts();
connection.send_message("Scripts reloaded!").await;
true
}
"!finishevent" => {
if let Some(event) = &connection.event {
connection.event_finish(event.id).await;
connection
.send_message("Current event forcefully finished.")
.await;
}
true
}
_ => false,
}
}
}