Browse Source

send deposit packets to correct clients

pbs
jake 4 years ago
parent
commit
0dca90ff5a
  1. 4
      src/ship/packet/handler/direct_message.rs
  2. 26
      tests/test_bank.rs

4
src/ship/packet/handler/direct_message.rs

@ -222,7 +222,7 @@ where
{
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
let area_client = client_location.get_local_client(id).map_err(|err| -> ClientLocationError { err.into() })?;
let clients_in_area = client_location.get_all_clients_by_client(id).map_err(|err| -> ClientLocationError { err.into() })?;
let other_clients_in_area = client_location.get_client_neighbors(id).map_err(|err| -> ClientLocationError { err.into() })?;
let bank_action_pkts = match bank_interaction.action {
BANK_ACTION_DEPOSIT => {
if bank_interaction.item_id == 0xFFFFFFFF {
@ -258,7 +258,7 @@ where
}
};
Ok(Box::new(clients_in_area.into_iter()
Ok(Box::new(other_clients_in_area.into_iter()
.map(move |c| {
bank_action_pkts.clone().into_iter()
.map(move |pkt| {

26
tests/test_bank.rs

@ -212,6 +212,7 @@ async fn test_deposit_individual_item() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
entity_gateway.create_item(
item::NewItemEntity {
@ -250,8 +251,11 @@ async fn test_deposit_individual_item() {
let mut ship = ShipServerState::new(entity_gateway.clone());
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
join_room(&mut ship, ClientId(2), 0).await;
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
client: 0,
@ -270,7 +274,7 @@ async fn test_deposit_individual_item() {
})))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10001
&& player_no_longer_has_item.amount == 0
));
@ -294,6 +298,7 @@ async fn test_deposit_stacked_item() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
for _ in 0..3 {
entity_gateway.create_item(
@ -313,8 +318,11 @@ async fn test_deposit_stacked_item() {
let mut ship = ShipServerState::new(entity_gateway.clone());
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
join_room(&mut ship, ClientId(2), 0).await;
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
client: 0,
@ -333,7 +341,7 @@ async fn test_deposit_stacked_item() {
})))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10000
&& player_no_longer_has_item.amount == 3
));
@ -357,6 +365,7 @@ async fn test_deposit_partial_stacked_item() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
for _ in 0..3 {
entity_gateway.create_item(
@ -376,8 +385,11 @@ async fn test_deposit_partial_stacked_item() {
let mut ship = ShipServerState::new(entity_gateway.clone());
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
join_room(&mut ship, ClientId(2), 0).await;
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
client: 0,
@ -396,7 +408,7 @@ async fn test_deposit_partial_stacked_item() {
})))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10000
&& player_no_longer_has_item.amount == 2
));
@ -433,6 +445,7 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
for _ in 0..2 {
entity_gateway.create_item(
@ -465,8 +478,11 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() {
let mut ship = ShipServerState::new(entity_gateway.clone());
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
join_room(&mut ship, ClientId(2), 0).await;
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
client: 0,
@ -485,7 +501,7 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() {
})))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10000
&& player_no_longer_has_item.amount == 2
));
@ -906,7 +922,6 @@ async fn test_deposit_meseta() {
let characters = entity_gateway.get_characters_by_user(&user1).await;
let char = characters[0].as_ref().unwrap();
println!("meseta {}", char.meseta);
assert!(char.meseta == 277);
assert!(char.bank_meseta == 23);
}
@ -943,7 +958,6 @@ async fn test_deposit_too_much_meseta() {
let characters = entity_gateway.get_characters_by_user(&user1).await;
let char = characters[0].as_ref().unwrap();
println!("meseta {}", char.meseta);
assert!(char.meseta == 300);
assert!(char.bank_meseta == 999980);
}

Loading…
Cancel
Save