|
|
@ -7,15 +7,13 @@ use crate::ship::items::state::ItemState; |
|
|
|
use crate::entity::item::{BankName, BankIdentifier};
|
|
|
|
use crate::ship::packet::builder::message::bank_item_list;
|
|
|
|
|
|
|
|
async fn default_bank<'a, EG, T>(id: ClientId,
|
|
|
|
tokens: T,
|
|
|
|
async fn default_bank<'a, EG>(id: ClientId,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
clients: &Clients,
|
|
|
|
item_state: &mut ItemState)
|
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, String>
|
|
|
|
where
|
|
|
|
EG: EntityGateway + Clone + 'static,
|
|
|
|
T: Iterator<Item = &'a str> + 'a,
|
|
|
|
{
|
|
|
|
let bank = clients
|
|
|
|
.with_mut(id, |client| {
|
|
|
@ -28,8 +26,8 @@ where |
|
|
|
})
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
.map_err(|err| format!("an error occured\n{:?}", err))?
|
|
|
|
.map_err(|err| format!("an error occured\n{:?}", err))?;
|
|
|
|
.map_err(|err| format!("an error occured\n{err:?}"))?
|
|
|
|
.map_err(|err| format!("an error occured\n{err:?}"))?;
|
|
|
|
|
|
|
|
let bank_items_pkt = bank_item_list(&bank);
|
|
|
|
Ok(vec![(id, SendShipPacket::BankItemList(bank_items_pkt))])
|
|
|
@ -45,8 +43,7 @@ where |
|
|
|
EG: EntityGateway + Clone + 'static,
|
|
|
|
T: Iterator<Item = &'a str> + 'a,
|
|
|
|
{
|
|
|
|
let bank_name = BankName(tokens.next().unwrap_or(&"").into());
|
|
|
|
|
|
|
|
let bank_name = BankName(tokens.next().unwrap_or("").into());
|
|
|
|
let bank = clients
|
|
|
|
.with_mut(id, |client| {
|
|
|
|
let mut item_state = item_state.clone();
|
|
|
@ -58,8 +55,8 @@ where |
|
|
|
})
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
.map_err(|err| format!("an error occured\n{:?}", err))?
|
|
|
|
.map_err(|err| format!("an error occured\n{:?}", err))?;
|
|
|
|
.map_err(|err| format!("an error occured\n{err:?}"))?
|
|
|
|
.map_err(|err| format!("an error occured\n{err:?}"))?;
|
|
|
|
|
|
|
|
let bank_items_pkt = bank_item_list(&bank);
|
|
|
|
Ok(vec![(id, SendShipPacket::BankItemList(bank_items_pkt))])
|
|
|
@ -76,11 +73,11 @@ where |
|
|
|
let mut tokens = message.message
|
|
|
|
.trim_start_matches("\tJ")
|
|
|
|
.trim_start_matches("\tE")
|
|
|
|
.trim_end_matches("\0")
|
|
|
|
.trim_end_matches('\0')
|
|
|
|
.split_whitespace();
|
|
|
|
let cmd = tokens.next()?;
|
|
|
|
match cmd {
|
|
|
|
"/bank" => Some(default_bank(id, tokens, &mut state.entity_gateway, &state.clients, &mut state.item_state).await),
|
|
|
|
"/bank" => Some(default_bank(id, &mut state.entity_gateway, &state.clients, &mut state.item_state).await),
|
|
|
|
"/sbank" => Some(switch_bank(id, tokens, &mut state.entity_gateway, &state.clients, &mut state.item_state).await),
|
|
|
|
|
|
|
|
_ => None,
|
|
|
|