|
|
@ -16,7 +16,7 @@ use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState |
|
|
|
use crate::common::leveltable::CharacterLevelTable;
|
|
|
|
|
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
|
|
|
|
use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM, GuildCard};
|
|
|
|
use crate::entity::character::Character;
|
|
|
|
use crate::entity::item::{ItemLocation, Item};
|
|
|
|
use crate::login::login::get_login_status;
|
|
|
@ -123,18 +123,20 @@ struct ClientState { |
|
|
|
character: Character,
|
|
|
|
session: Session,
|
|
|
|
inventory: items::Inventory,
|
|
|
|
guildcard: GuildCard,
|
|
|
|
//bank: Bank,
|
|
|
|
block: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ClientState {
|
|
|
|
fn new(user: UserAccount, settings: UserSettings, character: Character, inventory: items::Inventory, /*bank: Bank,*/ session: Session) -> ClientState {
|
|
|
|
fn new(user: UserAccount, settings: UserSettings, character: Character, inventory: items::Inventory, /*bank: Bank,*/ session: Session, guildcard: GuildCard) -> ClientState {
|
|
|
|
ClientState {
|
|
|
|
user: user,
|
|
|
|
settings: settings,
|
|
|
|
character: character,
|
|
|
|
session: session,
|
|
|
|
inventory: inventory,
|
|
|
|
guildcard: guildcard,
|
|
|
|
//bank: bank,
|
|
|
|
block: 1,
|
|
|
|
}
|
|
|
@ -184,8 +186,10 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
let stacked_items = items::stack_items(inventory);
|
|
|
|
let activated_items = stacked_items.into_iter().map(|item| self.item_activator.activate_item(item)).collect();
|
|
|
|
let inventory = items::Inventory::new(activated_items);
|
|
|
|
let guildcard = self.entity_gateway.get_guild_card_by_character(&character)
|
|
|
|
.ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
|
|
|
|
self.clients.insert(id, ClientState::new(user, settings, character, inventory, pkt.session));
|
|
|
|
self.clients.insert(id, ClientState::new(user, settings, character, inventory, pkt.session, guildcard));
|
|
|
|
vec![SendShipPacket::LoginResponse(response), SendShipPacket::ShipBlockList(ShipBlockList::new(&self.name, 3))]
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
@ -330,11 +334,40 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
|
|
|
|
fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
|
|
|
let cmsg = msg.clone();
|
|
|
|
Box::new(self.client_location.get_area_by_user(id).clients().iter()
|
|
|
|
.filter(|client| client.index == cmsg.flag as usize)
|
|
|
|
.map(|client| {
|
|
|
|
(client.client_id, SendShipPacket::DirectMessage(cmsg.clone()))
|
|
|
|
}).collect::<Vec<_>>().into_iter())
|
|
|
|
let client = self.clients.get_mut(&id).unwrap();
|
|
|
|
let gc = self.entity_gateway.get_guild_card_by_character(&client.character).unwrap();
|
|
|
|
match &cmsg.msg {
|
|
|
|
GameMessage::GuildcardSend(GuildcardSend) => {
|
|
|
|
let out_msg = DirectMessage{
|
|
|
|
flag: cmsg.flag,
|
|
|
|
msg: GameMessage::GuildcardRecv(GuildcardRecv {
|
|
|
|
client: 141,
|
|
|
|
target: 8,
|
|
|
|
guildcard: gc.guildcard.guildcard,
|
|
|
|
name: gc.guildcard.name,
|
|
|
|
team: gc.guildcard.team,
|
|
|
|
desc: gc.guildcard.desc,
|
|
|
|
one: 1,
|
|
|
|
language: gc.guildcard.language,
|
|
|
|
section_id: gc.guildcard.section_id,
|
|
|
|
class: gc.guildcard.class,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
Box::new(self.client_location.get_area_by_user(id).clients().iter()
|
|
|
|
.filter(|client| client.index == cmsg.flag as usize)
|
|
|
|
.map(|client| {
|
|
|
|
(client.client_id, SendShipPacket::DirectMessage(out_msg.clone()))
|
|
|
|
}).collect::<Vec<_>>().into_iter())
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
Box::new(self.client_location.get_area_by_user(id).clients().iter()
|
|
|
|
.filter(|client| client.index == cmsg.flag as usize)
|
|
|
|
.map(|client| {
|
|
|
|
(client.client_id, SendShipPacket::DirectMessage(cmsg.clone()))
|
|
|
|
}).collect::<Vec<_>>().into_iter())
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|