|
@ -60,9 +60,15 @@ pub fn get_login_status(entity_gateway: &dyn EntityGateway, pkt: &Login) -> Resu |
|
|
let username = array_to_utf8(pkt.username).map_err(|_err| AccountStatus::Error)?;
|
|
|
let username = array_to_utf8(pkt.username).map_err(|_err| AccountStatus::Error)?;
|
|
|
let password = array_to_utf8(pkt.password).map_err(|_err| AccountStatus::Error)?;
|
|
|
let password = array_to_utf8(pkt.password).map_err(|_err| AccountStatus::Error)?;
|
|
|
let user = entity_gateway.get_user_by_name(username).ok_or(AccountStatus::InvalidUser)?;
|
|
|
let user = entity_gateway.get_user_by_name(username).ok_or(AccountStatus::InvalidUser)?;
|
|
|
|
|
|
let banned = user.banned;
|
|
|
let verified = bcrypt::verify(password, user.password.as_str()).map_err(|_err| AccountStatus::Error)?;
|
|
|
let verified = bcrypt::verify(password, user.password.as_str()).map_err(|_err| AccountStatus::Error)?;
|
|
|
match verified {
|
|
|
match verified {
|
|
|
true => Ok(user),
|
|
|
|
|
|
|
|
|
true => if banned {
|
|
|
|
|
|
Err(AccountStatus::Banned)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
Ok(user)
|
|
|
|
|
|
},
|
|
|
false => Err(AccountStatus::InvalidPassword)
|
|
|
false => Err(AccountStatus::InvalidPassword)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -279,4 +285,47 @@ mod test { |
|
|
caps: 258
|
|
|
caps: 258
|
|
|
}))])
|
|
|
}))])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_banned_user() {
|
|
|
|
|
|
struct TestData {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl EntityGateway for TestData {
|
|
|
|
|
|
fn get_user_by_name(&self, name: String) -> Option<UserAccount> {
|
|
|
|
|
|
assert!(name == "testuser");
|
|
|
|
|
|
Some(UserAccount {
|
|
|
|
|
|
id: 1,
|
|
|
|
|
|
username: "testuser".to_owned(),
|
|
|
|
|
|
password: bcrypt::hash("mypassword", 5).unwrap(),
|
|
|
|
|
|
guildcard: None,
|
|
|
|
|
|
team_id: None,
|
|
|
|
|
|
banned: true,
|
|
|
|
|
|
muted_until: SystemTime::now(),
|
|
|
|
|
|
created_at: SystemTime::now(),
|
|
|
|
|
|
flags: 0,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} // end impl EntityGateway for TestData
|
|
|
|
|
|
|
|
|
|
|
|
let mut server = LoginServerState::new(TestData {});
|
|
|
|
|
|
let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(send == vec![
|
|
|
|
|
|
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
|
|
|
|
|
|
status: AccountStatus::Banned,
|
|
|
|
|
|
tag: 65536,
|
|
|
|
|
|
guildcard: 0,
|
|
|
|
|
|
team_id: 0,
|
|
|
|
|
|
session: Session {
|
|
|
|
|
|
version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30),
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
session_id: 0,
|
|
|
|
|
|
interserver_checksum: 0,
|
|
|
|
|
|
action: SessionAction::None,
|
|
|
|
|
|
character_slot: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
caps: 258
|
|
|
|
|
|
}))])
|
|
|
|
|
|
} // end test_banned_user()
|
|
|
}
|
|
|
}
|