Browse Source

Merge pull request 'bank_withdraw_fix2' (#44) from bank_withdraw_fix2 into master

Reviewed-on: #44
pull/64/head
jake 3 years ago
parent
commit
9131dc0e51
  1. 4
      src/ship/packet/handler/direct_message.rs
  2. 32
      tests/test_bank.rs

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

@ -249,7 +249,7 @@ where
{ {
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; 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 area_client = client_location.get_local_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 other_clients_in_area = client_location.get_all_clients_by_client(id).map_err(|err| -> ClientLocationError { err.into() })?;
let bank_action_pkts = match bank_interaction.action { let bank_action_pkts = match bank_interaction.action {
BANK_ACTION_DEPOSIT => { BANK_ACTION_DEPOSIT => {
if bank_interaction.item_id == 0xFFFFFFFF { if bank_interaction.item_id == 0xFFFFFFFF {
@ -281,7 +281,7 @@ where
vec![SendShipPacket::Message(Message::new(GameMessage::CreateItem(item_created)))] vec![SendShipPacket::Message(Message::new(GameMessage::CreateItem(item_created)))]
} }
}, },
_ => {
_ => { // TODO: error?
Vec::new() Vec::new()
} }
}; };

32
tests/test_bank.rs

@ -293,8 +293,8 @@ async fn test_deposit_individual_item() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10001 if player_no_longer_has_item.item_id == 0x10001
&& player_no_longer_has_item.amount == 0 && player_no_longer_has_item.amount == 0
)); ));
@ -356,8 +356,8 @@ async fn test_deposit_stacked_item() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10000 if player_no_longer_has_item.item_id == 0x10000
&& player_no_longer_has_item.amount == 3 && player_no_longer_has_item.amount == 3
)); ));
@ -420,8 +420,8 @@ async fn test_deposit_partial_stacked_item() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10000 if player_no_longer_has_item.item_id == 0x10000
&& player_no_longer_has_item.amount == 2 && player_no_longer_has_item.amount == 2
)); ));
@ -508,8 +508,8 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
if player_no_longer_has_item.item_id == 0x10000 if player_no_longer_has_item.item_id == 0x10000
&& player_no_longer_has_item.amount == 2 && player_no_longer_has_item.amount == 2
)); ));
@ -1024,8 +1024,8 @@ async fn test_withdraw_individual_item() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
if create_item.item_id == 0x20000 if create_item.item_id == 0x20000
)); ));
@ -1088,8 +1088,8 @@ async fn test_withdraw_stacked_item() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
if create_item.item_id == 0x10002 if create_item.item_id == 0x10002
)); ));
@ -1151,8 +1151,8 @@ async fn test_withdraw_partial_stacked_item() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
if create_item.item_id == 0x10002 if create_item.item_id == 0x10002
)); ));
@ -1236,8 +1236,8 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() {
unknown: 0, unknown: 0,
})))).await.unwrap().collect::<Vec<_>>(); })))).await.unwrap().collect::<Vec<_>>();
assert!(packets.len() == 1);
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
assert!(packets.len() == 2);
assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
if create_item.item_id == 0x10000 if create_item.item_id == 0x10000
)); ));

Loading…
Cancel
Save