|
@ -262,10 +262,10 @@ pub struct ClientState { |
|
|
impl ClientState {
|
|
|
impl ClientState {
|
|
|
pub fn new(user: UserAccountEntity, settings: UserSettingsEntity, character: CharacterEntity, session: Session) -> ClientState {
|
|
|
pub fn new(user: UserAccountEntity, settings: UserSettingsEntity, character: CharacterEntity, session: Session) -> ClientState {
|
|
|
ClientState {
|
|
|
ClientState {
|
|
|
user: user,
|
|
|
|
|
|
settings: settings,
|
|
|
|
|
|
character: character,
|
|
|
|
|
|
session: session,
|
|
|
|
|
|
|
|
|
user,
|
|
|
|
|
|
settings,
|
|
|
|
|
|
character,
|
|
|
|
|
|
session,
|
|
|
block: 0,
|
|
|
block: 0,
|
|
|
item_drop_location: None,
|
|
|
item_drop_location: None,
|
|
|
done_loading_quest: false,
|
|
|
done_loading_quest: false,
|
|
@ -287,8 +287,8 @@ pub struct ItemShops { |
|
|
pub armor_shop: ArmorShop<rand_chacha::ChaCha20Rng>,
|
|
|
pub armor_shop: ArmorShop<rand_chacha::ChaCha20Rng>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl ItemShops {
|
|
|
|
|
|
pub fn new() -> ItemShops {
|
|
|
|
|
|
|
|
|
impl Default for ItemShops {
|
|
|
|
|
|
fn default() -> ItemShops {
|
|
|
let difficulty = [room::Difficulty::Normal, room::Difficulty::Hard, room::Difficulty::VeryHard, room::Difficulty::Ultimate];
|
|
|
let difficulty = [room::Difficulty::Normal, room::Difficulty::Hard, room::Difficulty::VeryHard, room::Difficulty::Ultimate];
|
|
|
let section_id = [SectionID::Viridia, SectionID::Greenill, SectionID::Skyly, SectionID::Bluefull, SectionID::Purplenum,
|
|
|
let section_id = [SectionID::Viridia, SectionID::Greenill, SectionID::Skyly, SectionID::Bluefull, SectionID::Purplenum,
|
|
|
SectionID::Pinkal, SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill];
|
|
|
SectionID::Pinkal, SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill];
|
|
@ -301,7 +301,7 @@ impl ItemShops { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
ItemShops {
|
|
|
ItemShops {
|
|
|
weapon_shop: weapon_shop,
|
|
|
|
|
|
|
|
|
weapon_shop,
|
|
|
tool_shop: ToolShop::default(),
|
|
|
tool_shop: ToolShop::default(),
|
|
|
armor_shop: ArmorShop::default(),
|
|
|
armor_shop: ArmorShop::default(),
|
|
|
}
|
|
|
}
|
|
@ -318,8 +318,8 @@ pub struct ShipServerStateBuilder<EG: EntityGateway> { |
|
|
num_blocks: usize,
|
|
|
num_blocks: usize,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> ShipServerStateBuilder<EG> {
|
|
|
|
|
|
pub fn new() -> ShipServerStateBuilder<EG> {
|
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> Default for ShipServerStateBuilder<EG> {
|
|
|
|
|
|
fn default() -> ShipServerStateBuilder<EG> {
|
|
|
ShipServerStateBuilder {
|
|
|
ShipServerStateBuilder {
|
|
|
entity_gateway: None,
|
|
|
entity_gateway: None,
|
|
|
name: None,
|
|
|
name: None,
|
|
@ -329,7 +329,9 @@ impl<EG: EntityGateway> ShipServerStateBuilder<EG> { |
|
|
num_blocks: 2,
|
|
|
num_blocks: 2,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> ShipServerStateBuilder<EG> {
|
|
|
pub fn gateway(mut self, entity_gateway: EG) -> ShipServerStateBuilder<EG> {
|
|
|
pub fn gateway(mut self, entity_gateway: EG) -> ShipServerStateBuilder<EG> {
|
|
|
self.entity_gateway = Some(entity_gateway);
|
|
|
self.entity_gateway = Some(entity_gateway);
|
|
|
self
|
|
|
self
|
|
@ -366,16 +368,16 @@ impl<EG: EntityGateway> ShipServerStateBuilder<EG> { |
|
|
entity_gateway: self.entity_gateway.unwrap(),
|
|
|
entity_gateway: self.entity_gateway.unwrap(),
|
|
|
clients: HashMap::new(),
|
|
|
clients: HashMap::new(),
|
|
|
level_table: CharacterLevelTable::new(),
|
|
|
level_table: CharacterLevelTable::new(),
|
|
|
name: self.name.unwrap_or("NAMENOTSET".into()),
|
|
|
|
|
|
|
|
|
name: self.name.unwrap_or_else(|| "NAMENOTSET".into()),
|
|
|
item_manager: items::ItemManager::default(),
|
|
|
item_manager: items::ItemManager::default(),
|
|
|
quests: quests::load_quests("data/quests.toml".into()).unwrap(),
|
|
|
quests: quests::load_quests("data/quests.toml".into()).unwrap(),
|
|
|
ip: self.ip.unwrap_or(Ipv4Addr::new(127,0,0,1)),
|
|
|
|
|
|
|
|
|
ip: self.ip.unwrap_or_else(|| Ipv4Addr::new(127,0,0,1)),
|
|
|
port: self.port.unwrap_or(SHIP_PORT),
|
|
|
port: self.port.unwrap_or(SHIP_PORT),
|
|
|
shops: Box::new(ItemShops::new()),
|
|
|
|
|
|
|
|
|
shops: Box::new(ItemShops::default()),
|
|
|
|
|
|
|
|
|
blocks: Blocks(blocks),
|
|
|
blocks: Blocks(blocks),
|
|
|
|
|
|
|
|
|
auth_token: self.auth_token.unwrap_or(AuthToken("".into())),
|
|
|
|
|
|
|
|
|
auth_token: self.auth_token.unwrap_or_else(|| AuthToken("".into())),
|
|
|
ship_list: Vec::new(),
|
|
|
ship_list: Vec::new(),
|
|
|
shipgate_sender: None,
|
|
|
shipgate_sender: None,
|
|
|
}
|
|
|
}
|
|
@ -428,7 +430,7 @@ pub struct ShipServerState<EG: EntityGateway> { |
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> ShipServerState<EG> {
|
|
|
impl<EG: EntityGateway> ShipServerState<EG> {
|
|
|
pub fn builder() -> ShipServerStateBuilder<EG> {
|
|
|
pub fn builder() -> ShipServerStateBuilder<EG> {
|
|
|
ShipServerStateBuilder::new()
|
|
|
|
|
|
|
|
|
ShipServerStateBuilder::default()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn set_sender(&mut self, sender: Box<dyn Fn(ShipMessage) + Send + Sync>) {
|
|
|
pub fn set_sender(&mut self, sender: Box<dyn Fn(ShipMessage) + Send + Sync>) {
|
|
@ -443,7 +445,7 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerDropItem(player_drop_item) => {
|
|
|
GameMessage::PlayerDropItem(player_drop_item) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &mut block.client_location, &mut self.clients, &mut block.rooms, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut block.rooms, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::DropCoordinates(drop_coordinates) => {
|
|
|
GameMessage::DropCoordinates(drop_coordinates) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
@ -451,37 +453,37 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerNoLongerHasItem(no_longer_has_item) => {
|
|
|
GameMessage::PlayerNoLongerHasItem(no_longer_has_item) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
handler::message::no_longer_has_item(id, no_longer_has_item, &mut self.entity_gateway, &mut block.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::message::no_longer_has_item(id, no_longer_has_item, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) |
|
|
|
GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) |
|
|
|
GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) |
|
|
|
GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) |
|
|
|
GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) |
|
|
|
GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) |
|
|
|
GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
|
|
|
GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
handler::message::update_player_position(id, &msg, &mut self.clients, &mut block.client_location, &block.rooms)?
|
|
|
|
|
|
|
|
|
handler::message::update_player_position(id, msg, &mut self.clients, &block.client_location, &block.rooms)?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::ChargeAttack(charge_attack) => {
|
|
|
GameMessage::ChargeAttack(charge_attack) => {
|
|
|
handler::message::charge_attack(id, charge_attack, &mut self.clients, &mut self.entity_gateway).await?
|
|
|
handler::message::charge_attack(id, charge_attack, &mut self.clients, &mut self.entity_gateway).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerUseItem(player_use_item) => {
|
|
|
GameMessage::PlayerUseItem(player_use_item) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
handler::message::use_item(id, player_use_item, &mut self.entity_gateway, &mut block.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::message::use_item(id, player_use_item, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerUsedMedicalCenter(player_used_medical_center) => {
|
|
|
GameMessage::PlayerUsedMedicalCenter(player_used_medical_center) => {
|
|
|
handler::message::player_used_medical_center(id, &player_used_medical_center, &mut self.entity_gateway, &mut self.clients).await?
|
|
|
|
|
|
|
|
|
handler::message::player_used_medical_center(id, player_used_medical_center, &mut self.entity_gateway, &mut self.clients).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerFeedMag(player_feed_mag) => {
|
|
|
GameMessage::PlayerFeedMag(player_feed_mag) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
handler::message::player_feed_mag(id, &player_feed_mag, &mut self.entity_gateway, &mut block.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::message::player_feed_mag(id, player_feed_mag, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerEquipItem(player_equip_item) => {
|
|
|
GameMessage::PlayerEquipItem(player_equip_item) => {
|
|
|
handler::message::player_equips_item(id, &player_equip_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::message::player_equips_item(id, player_equip_item, &mut self.entity_gateway, &self.clients, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerUnequipItem(player_unequip_item) => {
|
|
|
GameMessage::PlayerUnequipItem(player_unequip_item) => {
|
|
|
handler::message::player_unequips_item(id, &player_unequip_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::message::player_unequips_item(id, player_unequip_item, &mut self.entity_gateway, &self.clients, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::SortItems(sort_items) => {
|
|
|
GameMessage::SortItems(sort_items) => {
|
|
|
handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &self.clients, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
_ => {
|
|
|
_ => {
|
|
|
let cmsg = msg.clone();
|
|
|
let cmsg = msg.clone();
|
|
@ -502,13 +504,13 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
handler::direct_message::guildcard_send(id, guildcard_send, target, &block.client_location, &self.clients)
|
|
|
handler::direct_message::guildcard_send(id, guildcard_send, target, &block.client_location, &self.clients)
|
|
|
},
|
|
|
},
|
|
|
GameMessage::RequestItem(request_item) => {
|
|
|
GameMessage::RequestItem(request_item) => {
|
|
|
handler::direct_message::request_item(id, request_item, &mut self.entity_gateway, &mut block.client_location, &mut self.clients, &mut block.rooms, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::direct_message::request_item(id, request_item, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut block.rooms, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PickupItem(pickup_item) => {
|
|
|
GameMessage::PickupItem(pickup_item) => {
|
|
|
handler::direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &mut block.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::BoxDropRequest(box_drop_request) => {
|
|
|
GameMessage::BoxDropRequest(box_drop_request) => {
|
|
|
handler::direct_message::request_box_item(id, box_drop_request, &mut self.entity_gateway, &mut block.client_location, &mut self.clients, &mut block.rooms, &mut self.item_manager).await?
|
|
|
|
|
|
|
|
|
handler::direct_message::request_box_item(id, box_drop_request, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut block.rooms, &mut self.item_manager).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::BankRequest(_bank_request) => {
|
|
|
GameMessage::BankRequest(_bank_request) => {
|
|
|
handler::direct_message::send_bank_list(id, &self.clients, &mut self.item_manager).await?
|
|
|
handler::direct_message::send_bank_list(id, &self.clients, &mut self.item_manager).await?
|
|
@ -626,7 +628,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::PlayerChat(msg) => {
|
|
|
RecvShipPacket::PlayerChat(msg) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
Box::new(handler::communication::player_chat(id, msg, &block.client_location, &self.clients)?.into_iter())
|
|
|
|
|
|
|
|
|
Box::new(handler::communication::player_chat(id, msg, &block.client_location, &self.clients)?)
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::CreateRoom(create_room) => {
|
|
|
RecvShipPacket::CreateRoom(create_room) => {
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
|
let block = self.blocks.with_client(id, &self.clients)?;
|
|
@ -706,7 +708,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
|
|
|
|
|
|
let pkt = match block.client_location.get_area(id)? {
|
|
|
let pkt = match block.client_location.get_area(id)? {
|
|
|
RoomLobby::Room(room) => {
|
|
|
RoomLobby::Room(room) => {
|
|
|
if neighbors.len() == 0 {
|
|
|
|
|
|
|
|
|
if neighbors.is_empty() {
|
|
|
block.rooms[room.0] = None;
|
|
|
block.rooms[room.0] = None;
|
|
|
}
|
|
|
}
|
|
|
let leader = block.client_location.get_room_leader(room)?;
|
|
|
let leader = block.client_location.get_room_leader(room)?;
|
|
@ -719,7 +721,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
if let Some(shipgate_sender) = self.shipgate_sender.as_ref() {
|
|
|
if let Some(shipgate_sender) = self.shipgate_sender.as_ref() {
|
|
|
shipgate_sender(ShipMessage::RemoveUser(client.user.id.clone()));
|
|
|
|
|
|
|
|
|
shipgate_sender(ShipMessage::RemoveUser(client.user.id));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
block.client_location.remove_client_from_area(id);
|
|
|
block.client_location.remove_client_from_area(id);
|
|
@ -748,7 +750,7 @@ impl<EG: EntityGateway> InterserverActor for ShipServerState<EG> { |
|
|
(id, ShipMessage::Authenticate(self.auth_token.clone())),
|
|
|
(id, ShipMessage::Authenticate(self.auth_token.clone())),
|
|
|
(id, ShipMessage::NewShip(Ship {
|
|
|
(id, ShipMessage::NewShip(Ship {
|
|
|
name: self.name.clone(),
|
|
|
name: self.name.clone(),
|
|
|
ip: self.ip.clone(),
|
|
|
|
|
|
|
|
|
ip: self.ip,
|
|
|
port: self.port,
|
|
|
port: self.port,
|
|
|
block_count: 2,
|
|
|
block_count: 2,
|
|
|
})),
|
|
|
})),
|
|
@ -768,7 +770,7 @@ impl<EG: EntityGateway> InterserverActor for ShipServerState<EG> { |
|
|
LoginMessage::RequestUsers => {
|
|
|
LoginMessage::RequestUsers => {
|
|
|
Ok(self.clients.iter()
|
|
|
Ok(self.clients.iter()
|
|
|
.map(|(_, client)| {
|
|
|
.map(|(_, client)| {
|
|
|
(id, ShipMessage::AddUser(client.user.id.clone()))
|
|
|
|
|
|
|
|
|
(id, ShipMessage::AddUser(client.user.id))
|
|
|
})
|
|
|
})
|
|
|
.collect())
|
|
|
.collect())
|
|
|
}
|
|
|
}
|
|
|