shrink some structures, remove async from functions that didn't need it
This commit is contained in:
parent
8ebbbb272a
commit
10458baea0
@ -379,46 +379,46 @@ fn main() {
|
||||
let patch_config = load_config();
|
||||
let patch_motd = load_motd();
|
||||
let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str());
|
||||
let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd);
|
||||
let patch_loop = patch_mainloop(patch_state, patch_config.port);
|
||||
let patch_state = Box::new(PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd));
|
||||
let patch_loop = patch_mainloop(*patch_state, patch_config.port);
|
||||
|
||||
let thread_entity_gateway = entity_gateway.clone();
|
||||
info!("[auth] starting server");
|
||||
let login_state = LoginServerState::new(thread_entity_gateway, "127.0.0.1".parse().unwrap());
|
||||
let login_loop = login_mainloop(login_state, elseware::login::login::LOGIN_PORT);
|
||||
let login_state = Box::new(LoginServerState::new(thread_entity_gateway, "127.0.0.1".parse().unwrap()));
|
||||
let login_loop = login_mainloop(*login_state, elseware::login::login::LOGIN_PORT);
|
||||
|
||||
let thread_entity_gateway = entity_gateway.clone();
|
||||
info!("[character] starting server");
|
||||
let char_state = CharacterServerState::new(thread_entity_gateway, AuthToken("".into()));
|
||||
let character_loop = character_mainloop(char_state, elseware::login::character::CHARACTER_PORT, elseware::login::login::COMMUNICATION_PORT);
|
||||
let char_state = Box::new(CharacterServerState::new(thread_entity_gateway, AuthToken("".into())));
|
||||
let character_loop = character_mainloop(*char_state, elseware::login::character::CHARACTER_PORT, elseware::login::login::COMMUNICATION_PORT);
|
||||
|
||||
let thread_entity_gateway = entity_gateway.clone();
|
||||
info!("[ship] starting server");
|
||||
let ship_state = ShipServerStateBuilder::new()
|
||||
let ship_state = Box::new(ShipServerStateBuilder::new()
|
||||
.name("US/Sona-Nyl".into())
|
||||
.ip(Ipv4Addr::new(127,0,0,1))
|
||||
.port(elseware::ship::ship::SHIP_PORT)
|
||||
.gateway(thread_entity_gateway)
|
||||
.build();
|
||||
let ship_loop = ship_mainloop(ship_state, elseware::ship::ship::SHIP_PORT, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT);
|
||||
.build());
|
||||
let ship_loop = ship_mainloop(*ship_state, elseware::ship::ship::SHIP_PORT, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT);
|
||||
|
||||
let thread_entity_gateway = entity_gateway.clone();
|
||||
let ship_state = ShipServerStateBuilder::new()
|
||||
let ship_state = Box::new(ShipServerStateBuilder::new()
|
||||
.name("EU/Dylath-Leen".into())
|
||||
.ip(Ipv4Addr::new(127,0,0,1))
|
||||
.port(elseware::ship::ship::SHIP_PORT+2000)
|
||||
.gateway(thread_entity_gateway)
|
||||
.build();
|
||||
let ship_loop2 = ship_mainloop(ship_state, elseware::ship::ship::SHIP_PORT+2000, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT);
|
||||
.build());
|
||||
let ship_loop2 = ship_mainloop(*ship_state, elseware::ship::ship::SHIP_PORT+2000, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT);
|
||||
|
||||
let thread_entity_gateway = entity_gateway.clone();
|
||||
let ship_state = ShipServerStateBuilder::new()
|
||||
let ship_state = Box::new(ShipServerStateBuilder::new()
|
||||
.name("JP/Thalarion".into())
|
||||
.ip(Ipv4Addr::new(127,0,0,1))
|
||||
.port(elseware::ship::ship::SHIP_PORT+3000)
|
||||
.gateway(thread_entity_gateway)
|
||||
.build();
|
||||
let ship_loop3 = ship_mainloop(ship_state, elseware::ship::ship::SHIP_PORT+3000, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT);
|
||||
.build());
|
||||
let ship_loop3 = ship_mainloop(*ship_state, elseware::ship::ship::SHIP_PORT+3000, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT);
|
||||
|
||||
futures::future::join_all(vec![patch_loop, login_loop, character_loop, ship_loop, ship_loop2, ship_loop3]).await;
|
||||
});
|
||||
|
@ -139,7 +139,7 @@ enum ServerStateAction<S> {
|
||||
Disconnect,
|
||||
}
|
||||
|
||||
async fn client_recv_loop<S, R>(client_id: ClientId,
|
||||
fn client_recv_loop<S, R>(client_id: ClientId,
|
||||
socket: Arc<async_std::net::TcpStream>,
|
||||
cipher: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
|
||||
server_sender: async_std::sync::Sender<ClientAction<ServerStateAction<S>, R>>,
|
||||
@ -177,7 +177,7 @@ where
|
||||
});
|
||||
}
|
||||
|
||||
async fn client_send_loop<S>(client_id: ClientId,
|
||||
fn client_send_loop<S>(client_id: ClientId,
|
||||
socket: Arc<async_std::net::TcpStream>,
|
||||
cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
|
||||
cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
|
||||
@ -207,7 +207,7 @@ where
|
||||
});
|
||||
}
|
||||
|
||||
async fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
|
||||
fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
|
||||
server_state_receiver: async_std::sync::Receiver<ClientAction<ServerStateAction<S>, R>>) where
|
||||
STATE: ServerState<SendPacket=S, RecvPacket=R, PacketError=E> + Send + 'static,
|
||||
S: SendServerPacket + std::fmt::Debug + Send + 'static,
|
||||
@ -223,7 +223,6 @@ async fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
|
||||
|
||||
match action {
|
||||
ClientAction::NewClient(client_id, sender) => {
|
||||
clients.insert(client_id, sender.clone());
|
||||
let actions = state.on_connect(client_id).await;
|
||||
match actions {
|
||||
Ok(actions) => {
|
||||
@ -237,11 +236,12 @@ async fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
warn!("[client {:?} state on_connect error] {:?}", client_id, err);
|
||||
}
|
||||
}
|
||||
clients.insert(client_id, sender);
|
||||
},
|
||||
ClientAction::Packet(client_id, pkt) => {
|
||||
let pkts = state.handle(client_id, &pkt).await;
|
||||
@ -295,7 +295,7 @@ where
|
||||
let mut id = 0;
|
||||
|
||||
let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024);
|
||||
state_client_loop(state, server_state_receiver).await;
|
||||
state_client_loop(state, server_state_receiver);
|
||||
|
||||
loop {
|
||||
let (sock, addr) = listener.accept().await.unwrap();
|
||||
@ -309,8 +309,8 @@ where
|
||||
let cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {})));
|
||||
let cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {})));
|
||||
|
||||
client_recv_loop(client_id, socket.clone(), cipher_in.clone(), server_state_sender.clone(), client_sender).await;
|
||||
client_send_loop(client_id, socket.clone(), cipher_in.clone(), cipher_out.clone(), client_receiver).await;
|
||||
client_recv_loop(client_id, socket.clone(), cipher_in.clone(), server_state_sender.clone(), client_sender);
|
||||
client_send_loop(client_id, socket.clone(), cipher_in.clone(), cipher_out.clone(), client_receiver);
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ pub fn login_mainloop<EG: EntityGateway + 'static>(login_state: LoginServerState
|
||||
pub fn character_mainloop<EG: EntityGateway + 'static>(character_state: CharacterServerState<EG>, character_port: u16, comm_port: u16) -> Pin<Box<dyn Future<Output = ()>>> {
|
||||
let character_state = Arc::new(Mutex::new(character_state));
|
||||
let client_mainloop = client_accept_mainloop(character_state.clone(), character_port);
|
||||
let ship_communication_mainloop = login_listen_mainloop(character_state.clone(), comm_port);
|
||||
let ship_communication_mainloop = login_listen_mainloop(character_state, comm_port);
|
||||
Box::pin(join_all(vec![client_mainloop, ship_communication_mainloop]).map(|_| ()))
|
||||
}
|
||||
|
||||
@ -40,6 +40,6 @@ pub fn character_mainloop<EG: EntityGateway + 'static>(character_state: Characte
|
||||
pub fn ship_mainloop<EG: EntityGateway + 'static>(ship_state: ShipServerState<EG>, ship_port: u16, comm_ip: std::net::Ipv4Addr, comm_port: u16) -> Pin<Box<dyn Future<Output = ()>>> {
|
||||
let ship_state = Arc::new(Mutex::new(ship_state));
|
||||
let client_mainloop = client_accept_mainloop(ship_state.clone(), ship_port);
|
||||
let login_communication_mainloop = ship_connect_mainloop(ship_state.clone(), comm_ip, comm_port);
|
||||
let login_communication_mainloop = ship_connect_mainloop(ship_state, comm_ip, comm_port);
|
||||
Box::pin(join_all(vec![client_mainloop, login_communication_mainloop]).map(|_| ()))
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ pub enum SendCharacterPacket {
|
||||
ChecksumAck(ChecksumAck),
|
||||
CharacterPreview(CharacterPreview),
|
||||
GuildcardDataHeader(GuildcardDataHeader),
|
||||
GuildcardDataChunk(GuildcardDataChunk),
|
||||
GuildcardDataChunk(Box<GuildcardDataChunk>),
|
||||
ParamDataHeader(ParamDataHeader),
|
||||
ParamDataChunk(ParamDataChunk),
|
||||
Timestamp(Timestamp),
|
||||
@ -412,7 +412,7 @@ impl<EG: EntityGateway> CharacterServerState<EG> {
|
||||
let mut buf = [0u8; GUILD_CARD_CHUNK_SIZE as usize];
|
||||
buf[..len as usize].copy_from_slice(&client.guildcard_data_buffer.as_ref().unwrap()[start..end]);
|
||||
|
||||
vec![SendCharacterPacket::GuildcardDataChunk(GuildcardDataChunk::new(chunk, buf, len))]
|
||||
vec![SendCharacterPacket::GuildcardDataChunk(Box::new(GuildcardDataChunk::new(chunk, buf, len)))]
|
||||
} else {
|
||||
Vec::new()
|
||||
})
|
||||
|
@ -103,7 +103,7 @@ pub enum SendPatchPacket {
|
||||
ChangeDirectory(ChangeDirectory),
|
||||
EndFileSend(EndFileSend),
|
||||
FileInfo(FileInfo),
|
||||
FileSend(FileSend),
|
||||
FileSend(Box<FileSend>),
|
||||
FilesToPatchMetadata(FilesToPatchMetadata),
|
||||
FinalizePatching(FinalizePatching),
|
||||
Message(Message),
|
||||
@ -338,12 +338,12 @@ impl Iterator for SendFileIterator {
|
||||
else {
|
||||
let mut crc = crc32::Digest::new(crc32::IEEE);
|
||||
crc.write(&buf[0..len]);
|
||||
let pkt = SendPatchPacket::FileSend(FileSend {
|
||||
let pkt = SendPatchPacket::FileSend(Box::new(FileSend {
|
||||
chunk_num: self.chunk_num,
|
||||
checksum: crc.sum32(),
|
||||
chunk_size: len as u32,
|
||||
buffer: buf,
|
||||
});
|
||||
}));
|
||||
self.chunk_num += 1;
|
||||
Some(pkt)
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ pub fn block_selected(id: ClientId,
|
||||
.build();
|
||||
|
||||
Ok(vec![
|
||||
SendShipPacket::FullCharacter(FullCharacter {
|
||||
SendShipPacket::FullCharacter(Box::new(FullCharacter {
|
||||
character: fc,
|
||||
}),
|
||||
})),
|
||||
SendShipPacket::CharDataRequest(CharDataRequest {}),
|
||||
SendShipPacket::LobbyList(LobbyList::new()),
|
||||
])
|
||||
|
@ -145,7 +145,7 @@ pub enum SendShipPacket {
|
||||
ShipWelcome(ShipWelcome),
|
||||
LoginResponse(LoginResponse),
|
||||
ShipBlockList(ShipBlockList),
|
||||
FullCharacter(FullCharacter),
|
||||
FullCharacter(Box<FullCharacter>),
|
||||
CharDataRequest(CharDataRequest),
|
||||
JoinLobby(JoinLobby),
|
||||
AddToLobby(AddToLobby),
|
||||
@ -341,10 +341,10 @@ impl<EG: EntityGateway> ShipServerStateBuilder<EG> {
|
||||
ShipServerState {
|
||||
entity_gateway: self.entity_gateway.unwrap(),
|
||||
clients: HashMap::new(),
|
||||
client_location: ClientLocation::new(),
|
||||
client_location: Box::new(ClientLocation::new()),
|
||||
level_table: CharacterLevelTable::new(),
|
||||
name: self.name.unwrap_or("NAMENOTSET".into()),
|
||||
rooms: [None; MAX_ROOMS],
|
||||
rooms: Box::new([None; MAX_ROOMS]),
|
||||
item_manager: items::ItemManager::new(),
|
||||
quests: quests::load_quests("data/quests.toml".into()).unwrap(),
|
||||
ip: self.ip.unwrap_or(Ipv4Addr::new(127,0,0,1)),
|
||||
@ -358,10 +358,10 @@ impl<EG: EntityGateway> ShipServerStateBuilder<EG> {
|
||||
pub struct ShipServerState<EG: EntityGateway> {
|
||||
entity_gateway: EG,
|
||||
pub clients: Clients,
|
||||
client_location: ClientLocation,
|
||||
client_location: Box<ClientLocation>,
|
||||
level_table: CharacterLevelTable,
|
||||
name: String,
|
||||
pub rooms: Rooms,
|
||||
pub rooms: Box<Rooms>,
|
||||
item_manager: items::ItemManager,
|
||||
quests: quests::QuestList,
|
||||
ip: Ipv4Addr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user