|
|
@ -1,6 +1,6 @@ |
|
|
|
#![allow(dead_code, unused_assignments)]
|
|
|
|
use std::io::Read;
|
|
|
|
use std::collections::{BTreeMap, HashMap};
|
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
|
|
|
|
|
|
|
use rand::Rng;
|
|
|
|
use crc::{crc32, Hasher32};
|
|
|
@ -28,6 +28,7 @@ use crate::entity::item::mag::Mag; |
|
|
|
use crate::entity::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel};
|
|
|
|
|
|
|
|
use crate::login::login::{get_login_status, check_if_already_online};
|
|
|
|
use crate::common::interserver::AuthToken;
|
|
|
|
|
|
|
|
pub const CHARACTER_PORT: u16 = 12001;
|
|
|
|
const SHIP_MENU_ID: u32 = 1;
|
|
|
@ -174,6 +175,8 @@ pub struct CharacterServerState<EG: EntityGateway> { |
|
|
|
clients: HashMap<ClientId, ClientState>,
|
|
|
|
ships: BTreeMap<ServerId, Ship>,
|
|
|
|
level_table: CharacterLevelTable,
|
|
|
|
auth_token: AuthToken,
|
|
|
|
authenticated_ships: BTreeSet<ServerId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -266,7 +269,7 @@ async fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAc |
|
|
|
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> CharacterServerState<EG> {
|
|
|
|
pub fn new(entity_gateway: EG) -> CharacterServerState<EG> {
|
|
|
|
pub fn new(entity_gateway: EG, auth_token: AuthToken) -> CharacterServerState<EG> {
|
|
|
|
let (param_header, param_data) = generate_param_data("data/param/");
|
|
|
|
|
|
|
|
CharacterServerState {
|
|
|
@ -276,6 +279,8 @@ impl<EG: EntityGateway> CharacterServerState<EG> { |
|
|
|
clients: HashMap::new(),
|
|
|
|
ships: BTreeMap::new(),
|
|
|
|
level_table: CharacterLevelTable::new(),
|
|
|
|
auth_token: auth_token,
|
|
|
|
authenticated_ships: BTreeSet::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -558,9 +563,15 @@ impl<EG: EntityGateway> InterserverActor for CharacterServerState<EG> { |
|
|
|
|
|
|
|
async fn action(&mut self, id: ServerId, msg: Self::RecvMessage) -> Result<Vec<(ServerId, Self::SendMessage)>, Self::Error> {
|
|
|
|
match msg {
|
|
|
|
ShipMessage::Authenticate(_auth_token) => {},
|
|
|
|
ShipMessage::Authenticate(auth_token) => {
|
|
|
|
if self.auth_token == auth_token {
|
|
|
|
self.authenticated_ships.insert(id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ShipMessage::NewShip(new_ship) => {
|
|
|
|
self.ships.insert(id, new_ship);
|
|
|
|
if self.authenticated_ships.contains(&id) {
|
|
|
|
self.ships.insert(id, new_ship);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
@ -681,7 +692,7 @@ mod test { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut server = CharacterServerState::new(TestData {});
|
|
|
|
let mut server = CharacterServerState::new(TestData {}, AuthToken("".into()));
|
|
|
|
let mut clientstate = ClientState::new();
|
|
|
|
clientstate.user = Some(UserAccountEntity {
|
|
|
|
id: UserAccountId(1),
|
|
|
@ -716,7 +727,7 @@ mod test { |
|
|
|
#[derive(Clone)]
|
|
|
|
struct TestData;
|
|
|
|
impl EntityGateway for TestData {}
|
|
|
|
let mut server = CharacterServerState::new(TestData {});
|
|
|
|
let mut server = CharacterServerState::new(TestData {}, AuthToken("".into()));
|
|
|
|
let send = server.handle(ClientId(1), &RecvCharacterPacket::Checksum(Checksum {checksum: 1234,
|
|
|
|
padding: 0,
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
@ -746,7 +757,7 @@ mod test { |
|
|
|
at_ship: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
let mut server = CharacterServerState::new(test_data.clone());
|
|
|
|
let mut server = CharacterServerState::new(test_data.clone(), AuthToken("".into()));
|
|
|
|
server.clients.insert(ClientId(1), fake_user.clone());
|
|
|
|
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);
|
|
|
|