asyncify tests
This commit is contained in:
parent
8d49c50cc5
commit
7ae60fafc5
@ -6,7 +6,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
libpso = { git = "http://git.sharnoth.com/jake/libpso" }
|
||||
async-std = { version = "1.5.0", features = ["unstable"] }
|
||||
async-std = { version = "1.5.0", features = ["unstable", "attributes"] }
|
||||
futures = "0.3.5"
|
||||
rand = "0.7.3"
|
||||
rand_chacha = "0.2.2"
|
||||
|
@ -658,13 +658,15 @@ mod test {
|
||||
use std::time::SystemTime;
|
||||
use crate::entity::gateway::{InMemoryGateway};
|
||||
|
||||
#[test]
|
||||
fn test_option_send() {
|
||||
#[async_std::test]
|
||||
async fn test_option_send() {
|
||||
#[derive(Clone)]
|
||||
struct TestData {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl EntityGateway for TestData {
|
||||
fn get_user_settings_by_user(&self, user: &UserAccountEntity) -> Option<UserSettingsEntity> {
|
||||
async fn get_user_settings_by_user(&self, user: &UserAccountEntity) -> Option<UserSettingsEntity> {
|
||||
Some(UserSettingsEntity {
|
||||
id: UserSettingsId(0),
|
||||
user_id: user.id,
|
||||
@ -688,7 +690,7 @@ mod test {
|
||||
});
|
||||
server.clients.insert(ClientId(5), clientstate);
|
||||
|
||||
let send = server.handle(ClientId(5), &RecvCharacterPacket::RequestSettings(RequestSettings{}))
|
||||
let send = server.handle(ClientId(5), &RecvCharacterPacket::RequestSettings(RequestSettings{})).await
|
||||
.unwrap()
|
||||
.collect::<Vec<_>>();
|
||||
assert!(send.len() == 1);
|
||||
@ -699,22 +701,23 @@ mod test {
|
||||
assert!(bytes.len() == 0xAFC);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_user_checksum() {
|
||||
#[async_std::test]
|
||||
async fn test_user_checksum() {
|
||||
#[derive(Clone)]
|
||||
struct TestData;
|
||||
impl EntityGateway for TestData {}
|
||||
let mut server = CharacterServerState::new(TestData {});
|
||||
let send = server.handle(ClientId(1), &RecvCharacterPacket::Checksum(Checksum {checksum: 1234,
|
||||
padding: 0,
|
||||
})).unwrap().collect::<Vec<_>>();
|
||||
})).await.unwrap().collect::<Vec<_>>();
|
||||
assert!(send.len() == 1);
|
||||
|
||||
let bytes = send[0].1.as_bytes();
|
||||
assert!(bytes == [0xC, 0, 0xE8, 0x02, 0,0,0,0, 1,0,0,0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_character_create() {
|
||||
#[async_std::test]
|
||||
async fn test_character_create() {
|
||||
let test_data = InMemoryGateway::new();
|
||||
let mut fake_user = ClientState::new();
|
||||
fake_user.user = Some(UserAccountEntity {
|
||||
@ -731,8 +734,8 @@ mod test {
|
||||
|
||||
let mut server = CharacterServerState::new(test_data.clone());
|
||||
server.clients.insert(ClientId(1), fake_user.clone());
|
||||
let mut send = server.handle(ClientId(1), &RecvCharacterPacket::SetFlag(SetFlag {flags: 1})).unwrap().collect::<Vec<_>>();
|
||||
assert!(test_data.get_user_by_id(UserAccountId(3)).unwrap().flags == 1);
|
||||
let mut send = server.handle(ClientId(1), &RecvCharacterPacket::SetFlag(SetFlag {flags: 1})).await.unwrap().collect::<Vec<_>>();
|
||||
assert!(test_data.get_user_by_id(UserAccountId(3)).await.unwrap().flags == 1);
|
||||
send = server.handle(ClientId(1), &RecvCharacterPacket::CharacterPreview(CharacterPreview {slot: 1, character: character::SelectScreenCharacter {
|
||||
exp: 0,
|
||||
level: 0,
|
||||
@ -759,10 +762,10 @@ mod test {
|
||||
prop_y: 0.0,
|
||||
name: [9, 69, 116, 101, 115, 116, 32, 110, 97, 109, 101, 0, 0, 0, 0, 0], // "\tEtest name"
|
||||
play_time: 0,
|
||||
} })).unwrap().collect::<Vec<_>>();
|
||||
} })).await.unwrap().collect::<Vec<_>>();
|
||||
assert!(send.len() == 2);
|
||||
|
||||
let chars = test_data.get_characters_by_user(&fake_user.user.unwrap());
|
||||
let chars = test_data.get_characters_by_user(&fake_user.user.unwrap()).await;
|
||||
assert!(chars[1].as_ref().unwrap().name == "\tEtest name");
|
||||
assert!(chars[0].is_none());
|
||||
}
|
||||
|
@ -168,13 +168,15 @@ mod test {
|
||||
}
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_correct_login() {
|
||||
#[async_std::test]
|
||||
async fn test_correct_login() {
|
||||
#[derive(Clone)]
|
||||
struct TestData {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl EntityGateway for TestData {
|
||||
fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
|
||||
async fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
|
||||
assert!(name == "testuser");
|
||||
Some(UserAccountEntity {
|
||||
id: UserAccountId(1),
|
||||
@ -188,11 +190,11 @@ mod test {
|
||||
flags: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut server = LoginServerState::new(TestData {});
|
||||
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::<Vec<_>>();
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).await.unwrap().collect::<Vec<_>>();
|
||||
assert!(send == vec![
|
||||
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
|
||||
status: AccountStatus::Ok,
|
||||
@ -216,19 +218,21 @@ mod test {
|
||||
}))])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_bad_username() {
|
||||
#[async_std::test]
|
||||
async fn test_login_bad_username() {
|
||||
#[derive(Clone)]
|
||||
struct TestData {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl EntityGateway for TestData {
|
||||
fn get_user_by_name(&self, _name: String) -> Option<UserAccountEntity> {
|
||||
async fn get_user_by_name(&self, _name: String) -> Option<UserAccountEntity> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
let mut server = LoginServerState::new(TestData {});
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::<Vec<_>>();
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).await.unwrap().collect::<Vec<_>>();
|
||||
|
||||
assert!(send == vec![
|
||||
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
|
||||
@ -248,13 +252,15 @@ mod test {
|
||||
}))])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_bad_password() {
|
||||
#[async_std::test]
|
||||
async fn test_login_bad_password() {
|
||||
#[derive(Clone)]
|
||||
struct TestData {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl EntityGateway for TestData {
|
||||
fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
|
||||
async fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
|
||||
assert!(name == "testuser");
|
||||
Some(UserAccountEntity {
|
||||
id: UserAccountId(1),
|
||||
@ -271,7 +277,7 @@ mod test {
|
||||
}
|
||||
|
||||
let mut server = LoginServerState::new(TestData {});
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::<Vec<_>>();
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).await.unwrap().collect::<Vec<_>>();
|
||||
|
||||
assert!(send == vec![
|
||||
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
|
||||
@ -291,13 +297,15 @@ mod test {
|
||||
}))])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_banned_user() {
|
||||
#[async_std::test]
|
||||
async fn test_banned_user() {
|
||||
#[derive(Clone)]
|
||||
struct TestData {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl EntityGateway for TestData {
|
||||
fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
|
||||
async fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
|
||||
assert!(name == "testuser");
|
||||
Some(UserAccountEntity {
|
||||
id: UserAccountId(1),
|
||||
@ -314,7 +322,7 @@ mod test {
|
||||
}
|
||||
|
||||
let mut server = LoginServerState::new(TestData {});
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::<Vec<_>>();
|
||||
let send = server.handle(ClientId(1), &LOGIN_PACKET).await.unwrap().collect::<Vec<_>>();
|
||||
|
||||
assert!(send == vec![
|
||||
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
|
||||
|
@ -15,7 +15,7 @@ use libpso::packet::login::{Login, Session};
|
||||
use libpso::{utf8_to_array, utf8_to_utf16_array};
|
||||
|
||||
|
||||
pub fn new_user_character<EG: EntityGateway>(entity_gateway: &mut EG, username: &str, password: &str) -> (UserAccountEntity, CharacterEntity) {
|
||||
pub async fn new_user_character<EG: EntityGateway>(entity_gateway: &mut EG, username: &str, password: &str) -> (UserAccountEntity, CharacterEntity) {
|
||||
let new_user = NewUserAccountEntity {
|
||||
username: username.into(),
|
||||
password: bcrypt::hash(password, 5).unwrap(),
|
||||
@ -27,16 +27,16 @@ pub fn new_user_character<EG: EntityGateway>(entity_gateway: &mut EG, username:
|
||||
flags: 0,
|
||||
};
|
||||
|
||||
let user = entity_gateway.create_user(new_user).unwrap();
|
||||
let user = entity_gateway.create_user(new_user).await.unwrap();
|
||||
let new_settings = NewUserSettingsEntity::new(user.id);
|
||||
let _settings = entity_gateway.create_user_settings(new_settings).unwrap();
|
||||
let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap();
|
||||
let new_character = NewCharacterEntity::new(user.id);
|
||||
let character = entity_gateway.create_character(new_character).unwrap();
|
||||
let character = entity_gateway.create_character(new_character).await.unwrap();
|
||||
|
||||
(user, character)
|
||||
}
|
||||
|
||||
pub fn log_in_char<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, username: &str, password: &str) {
|
||||
pub async fn log_in_char<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, username: &str, password: &str) {
|
||||
let username = username.to_string();
|
||||
let password = password.to_string();
|
||||
ship.handle(id, &RecvShipPacket::Login(Login {
|
||||
@ -51,16 +51,16 @@ pub fn log_in_char<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: Client
|
||||
unknown3: [0; 40],
|
||||
hwinfo: [0; 8],
|
||||
session: Session::new(),
|
||||
})).unwrap().for_each(drop);
|
||||
})).await.unwrap().for_each(drop);
|
||||
}
|
||||
|
||||
pub fn join_lobby<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
|
||||
pub async fn join_lobby<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
|
||||
ship.handle(id, &RecvShipPacket::CharData(CharData {
|
||||
_unknown: [0; 0x828]
|
||||
})).unwrap().for_each(drop);
|
||||
})).await.unwrap().for_each(drop);
|
||||
}
|
||||
|
||||
pub fn create_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str) {
|
||||
pub async fn create_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str) {
|
||||
ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
|
||||
unknown: [0; 2],
|
||||
name: utf8_to_utf16_array!(name, 16),
|
||||
@ -71,24 +71,24 @@ pub fn create_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: Client
|
||||
episode: 1,
|
||||
single_player: 0,
|
||||
padding: [0; 3],
|
||||
})).unwrap().for_each(drop);
|
||||
ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).unwrap().for_each(drop);
|
||||
})).await.unwrap().for_each(drop);
|
||||
ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
|
||||
}
|
||||
|
||||
pub fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
|
||||
pub async fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
|
||||
ship.handle(id, &RecvShipPacket::MenuSelect(MenuSelect {
|
||||
menu: ROOM_MENU_ID,
|
||||
item: room_id,
|
||||
})).unwrap().for_each(drop);
|
||||
})).await.unwrap().for_each(drop);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
||||
#[async_std::test]
|
||||
async fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
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 {
|
||||
@ -102,7 +102,7 @@ fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
||||
slot: 0,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
|
||||
for (slot, tool) in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter().enumerate() {
|
||||
for _ in 0..5 {
|
||||
@ -118,19 +118,19 @@ fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
||||
slot: slot,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
}
|
||||
}
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
||||
client: 0,
|
||||
@ -141,7 +141,7 @@ fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -149,7 +149,7 @@ fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
||||
item_id: 0x210000,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
||||
assert!(p1_inventory.count() == 1);
|
||||
@ -158,12 +158,12 @@ fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
||||
assert!(inventory_item.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 6));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pick_up_item_stack_of_items_not_already_held() {
|
||||
#[async_std::test]
|
||||
async fn test_pick_up_item_stack_of_items_not_already_held() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
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 {
|
||||
@ -177,17 +177,17 @@ fn test_pick_up_item_stack_of_items_not_already_held() {
|
||||
slot: 0,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
||||
client: 0,
|
||||
@ -198,7 +198,7 @@ fn test_pick_up_item_stack_of_items_not_already_held() {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -206,7 +206,7 @@ fn test_pick_up_item_stack_of_items_not_already_held() {
|
||||
item_id: 0x210000,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
||||
assert!(p1_inventory.count() == 1);
|
||||
@ -215,12 +215,12 @@ fn test_pick_up_item_stack_of_items_not_already_held() {
|
||||
assert!(inventory_item.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pick_up_meseta_when_inventory_full() {
|
||||
#[async_std::test]
|
||||
async fn test_pick_up_meseta_when_inventory_full() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
||||
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
||||
|
||||
for slot in 0..30 {
|
||||
entity_gateway.create_item(
|
||||
@ -239,21 +239,21 @@ fn test_pick_up_meseta_when_inventory_full() {
|
||||
slot: slot,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
}
|
||||
|
||||
char2.meseta = 300;
|
||||
entity_gateway.save_character(&char2);
|
||||
entity_gateway.save_character(&char2).await;
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
|
||||
client: 0,
|
||||
@ -262,14 +262,14 @@ fn test_pick_up_meseta_when_inventory_full() {
|
||||
map_area: 0,
|
||||
x: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSplitItemStack(PlayerSplitItemStack {
|
||||
client: 0,
|
||||
target: 0,
|
||||
item_id: 0xFFFFFFFF,
|
||||
amount: 23,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -277,7 +277,7 @@ fn test_pick_up_meseta_when_inventory_full() {
|
||||
item_id: 0xF0000001,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
||||
assert!(p1_inventory.count() == 30);
|
||||
@ -288,12 +288,12 @@ fn test_pick_up_meseta_when_inventory_full() {
|
||||
assert!(c2.character.meseta == 277);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
|
||||
#[async_std::test]
|
||||
async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
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 slot in 0..29 {
|
||||
entity_gateway.create_item(
|
||||
@ -312,7 +312,7 @@ fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
|
||||
slot: slot,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
}
|
||||
|
||||
entity_gateway.create_item(
|
||||
@ -327,7 +327,7 @@ fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
|
||||
slot: 29,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
entity_gateway.create_item(
|
||||
item::NewItemEntity {
|
||||
item: item::ItemDetail::Tool(
|
||||
@ -340,17 +340,17 @@ fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
|
||||
slot: 0,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
||||
client: 0,
|
||||
@ -361,7 +361,7 @@ fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -369,22 +369,21 @@ fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
|
||||
item_id: 0x210000,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
||||
assert!(p1_inventory.count() == 30);
|
||||
|
||||
|
||||
let monomates = p1_inventory.slot(29).unwrap();
|
||||
assert!(monomates.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_not_pick_up_item_when_inventory_full() {
|
||||
#[async_std::test]
|
||||
async fn test_can_not_pick_up_item_when_inventory_full() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
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 slot in 0..30 {
|
||||
entity_gateway.create_item(
|
||||
@ -403,7 +402,7 @@ fn test_can_not_pick_up_item_when_inventory_full() {
|
||||
slot: slot,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
}
|
||||
|
||||
entity_gateway.create_item(
|
||||
@ -422,18 +421,17 @@ fn test_can_not_pick_up_item_when_inventory_full() {
|
||||
slot: 0,
|
||||
equipped: false,
|
||||
}
|
||||
}
|
||||
);
|
||||
}).await;
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
||||
client: 0,
|
||||
@ -444,7 +442,7 @@ fn test_can_not_pick_up_item_when_inventory_full() {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -452,7 +450,7 @@ fn test_can_not_pick_up_item_when_inventory_full() {
|
||||
item_id: 0x210000,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
||||
assert!(p1_inventory.count() == 30);
|
||||
@ -460,21 +458,21 @@ fn test_can_not_pick_up_item_when_inventory_full() {
|
||||
assert!(floor_item.item_id == ClientItemId(0x210000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_not_drop_more_meseta_than_is_held() {
|
||||
#[async_std::test]
|
||||
async fn test_can_not_drop_more_meseta_than_is_held() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
||||
|
||||
char1.meseta = 300;
|
||||
entity_gateway.save_character(&char1);
|
||||
entity_gateway.save_character(&char1).await;
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
|
||||
join_lobby(&mut ship, ClientId(1));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
|
||||
client: 0,
|
||||
@ -483,14 +481,14 @@ fn test_can_not_drop_more_meseta_than_is_held() {
|
||||
map_area: 0,
|
||||
x: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let split_attempt = ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSplitItemStack(PlayerSplitItemStack {
|
||||
client: 0,
|
||||
target: 0,
|
||||
item_id: 0xFFFFFFFF,
|
||||
amount: 301,
|
||||
}))));
|
||||
})))).await;
|
||||
assert!(split_attempt.is_err());
|
||||
|
||||
let c1 = ship.clients.get(&ClientId(1)).unwrap();
|
||||
@ -498,12 +496,12 @@ fn test_can_not_drop_more_meseta_than_is_held() {
|
||||
assert!(ship.item_manager.get_floor_item_by_id(&char1, ClientItemId(0xF0000001)).is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pick_up_stack_that_would_exceed_stack_limit() {
|
||||
#[async_std::test]
|
||||
async fn test_pick_up_stack_that_would_exceed_stack_limit() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
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..6 {
|
||||
entity_gateway.create_item(
|
||||
@ -518,7 +516,7 @@ fn test_pick_up_stack_that_would_exceed_stack_limit() {
|
||||
slot: 0,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
}
|
||||
for _ in 0..6 {
|
||||
entity_gateway.create_item(
|
||||
@ -533,18 +531,18 @@ fn test_pick_up_stack_that_would_exceed_stack_limit() {
|
||||
slot: 0,
|
||||
equipped: false,
|
||||
}
|
||||
});
|
||||
}).await;
|
||||
}
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
||||
client: 0,
|
||||
@ -555,7 +553,7 @@ fn test_pick_up_stack_that_would_exceed_stack_limit() {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -563,7 +561,7 @@ fn test_pick_up_stack_that_would_exceed_stack_limit() {
|
||||
item_id: 0x210000,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
||||
let monomates = p1_inventory.slot(0).unwrap();
|
||||
@ -572,27 +570,27 @@ fn test_pick_up_stack_that_would_exceed_stack_limit() {
|
||||
assert!(floor_monomates.item == FloorItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 6));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_not_pick_up_meseta_when_full() {
|
||||
#[async_std::test]
|
||||
async fn test_can_not_pick_up_meseta_when_full() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
||||
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
||||
|
||||
char1.meseta = 999999;
|
||||
entity_gateway.save_character(&char1);
|
||||
entity_gateway.save_character(&char1).await;
|
||||
char2.meseta = 300;
|
||||
entity_gateway.save_character(&char2);
|
||||
entity_gateway.save_character(&char2).await;
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
|
||||
client: 0,
|
||||
@ -601,14 +599,14 @@ fn test_can_not_pick_up_meseta_when_full() {
|
||||
map_area: 0,
|
||||
x: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSplitItemStack(PlayerSplitItemStack {
|
||||
client: 0,
|
||||
target: 0,
|
||||
item_id: 0xFFFFFFFF,
|
||||
amount: 23,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -616,7 +614,7 @@ fn test_can_not_pick_up_meseta_when_full() {
|
||||
item_id: 0xF0000001,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let c1 = ship.clients.get(&ClientId(1)).unwrap();
|
||||
let c2 = ship.clients.get(&ClientId(2)).unwrap();
|
||||
@ -627,27 +625,27 @@ fn test_can_not_pick_up_meseta_when_full() {
|
||||
assert!(floor_meseta.item == FloorItemType::Meseta(item::Meseta(23)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
|
||||
#[async_std::test]
|
||||
async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
|
||||
let mut entity_gateway = InMemoryGateway::new();
|
||||
|
||||
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a");
|
||||
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a");
|
||||
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
||||
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
||||
|
||||
char1.meseta = 999998;
|
||||
entity_gateway.save_character(&char1);
|
||||
entity_gateway.save_character(&char1).await;
|
||||
char2.meseta = 300;
|
||||
entity_gateway.save_character(&char2);
|
||||
entity_gateway.save_character(&char2).await;
|
||||
|
||||
let mut ship = ShipServerState::new(entity_gateway.clone());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a");
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a");
|
||||
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));
|
||||
join_lobby(&mut ship, ClientId(2));
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
|
||||
create_room(&mut ship, ClientId(1), "room", "");
|
||||
join_room(&mut ship, ClientId(2), 0);
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
|
||||
client: 0,
|
||||
@ -656,14 +654,14 @@ fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
|
||||
map_area: 0,
|
||||
x: 0.0,
|
||||
z: 0.0,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSplitItemStack(PlayerSplitItemStack {
|
||||
client: 0,
|
||||
target: 0,
|
||||
item_id: 0xFFFFFFFF,
|
||||
amount: 23,
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
||||
client: 0,
|
||||
@ -671,7 +669,7 @@ fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
|
||||
item_id: 0xF0000001,
|
||||
area: 0,
|
||||
unknown: [0; 3]
|
||||
})))).unwrap().for_each(drop);
|
||||
})))).await.unwrap().for_each(drop);
|
||||
|
||||
let c1 = ship.clients.get(&ClientId(1)).unwrap();
|
||||
let c2 = ship.clients.get(&ClientId(2)).unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user