mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Update for event system in (failed) attempt to get Singleplayer to spawn robots
This commit is contained in:
@@ -32,7 +32,7 @@ async fn main() -> std::io::Result<()> {
|
||||
users,
|
||||
});
|
||||
|
||||
let server = std::sync::Arc::new(polariton_server::Server::new(operations::handler(&init_ctx)));
|
||||
let server = std::sync::Arc::new(polariton_server::Server::new(operations::handler(&init_ctx), polariton_server::events::EventsHandler::new()));
|
||||
|
||||
let ip_addr: std::net::IpAddr = args.ip.parse().expect("Invalid IP address");
|
||||
|
||||
@@ -41,14 +41,16 @@ async fn main() -> std::io::Result<()> {
|
||||
if args.once {
|
||||
log::warn!("Handling first connection and then exiting");
|
||||
let (socket, address) = listener.accept().await?;
|
||||
process_socket(socket, address, server, init_ctx).await;
|
||||
Ok(())
|
||||
process_socket(socket, address, server.clone(), init_ctx).await;
|
||||
} else {
|
||||
loop {
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, server.clone(), init_ctx.clone()));
|
||||
}
|
||||
}
|
||||
server.join();
|
||||
server.join_async().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: std::sync::Arc<polariton_server::Server<crate::UserTy>>, init_ctx: std::sync::Arc<InitConfig>) {
|
||||
@@ -60,8 +62,10 @@ async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAdd
|
||||
return;
|
||||
}
|
||||
};
|
||||
let (socket_r, socket_w) = socket.into_split();
|
||||
let user_state = std::sync::RwLock::new(state::UserState::<()>::new(init_ctx.users.clone()));
|
||||
server.handle_async(socket, user_state, enc, Default::default()).await;
|
||||
let ctx = polariton::packet::SerdesContext::from_boxed(Default::default(), enc);
|
||||
server.handle_async(socket_r, socket_w, user_state, ctx).await;
|
||||
log::debug!("Goodbye connection from address {}", address);
|
||||
}
|
||||
|
||||
@@ -114,7 +118,7 @@ impl polariton_auth::AuthProvider<AuthError> for AuthImpl {
|
||||
|
||||
async fn do_connect_handshake(
|
||||
socket: &mut net::TcpStream,
|
||||
) -> Option<polariton_auth::CryptoImpl> {
|
||||
) -> Option<Box<dyn polariton::packet::Cryptographer>> {
|
||||
let handshake = Handshake::new(APP_ID);
|
||||
// connect
|
||||
log::debug!("(connect) Handling first packet");
|
||||
@@ -175,7 +179,7 @@ async fn do_connect_handshake(
|
||||
// pre-auth
|
||||
let handshake = handshake.with_auth(AuthImpl);
|
||||
let op_ctx = polariton::serdes::SerdesContext::default();
|
||||
let ctx = polariton::packet::SerdesContext::new(&op_ctx, &crypto);
|
||||
let ctx = polariton::packet::SerdesContext::new(op_ctx, crypto);
|
||||
// authenticate
|
||||
log::debug!("(connect) Handling third packet");
|
||||
let mut packet3 = match polariton_server::utils::receive_packet_async(socket, &ctx).await {
|
||||
@@ -195,7 +199,7 @@ async fn do_connect_handshake(
|
||||
}
|
||||
};
|
||||
}
|
||||
let to_send = match handshake.authenticate(&packet3, &crypto) {
|
||||
let to_send = match handshake.authenticate(&packet3, &ctx) {
|
||||
Ok(x) => x,
|
||||
Err(h) => match h.extra {
|
||||
polariton_auth::AuthError::Validation(e) => {
|
||||
@@ -266,5 +270,5 @@ async fn do_connect_handshake(
|
||||
}
|
||||
}
|
||||
|
||||
Some(crypto)
|
||||
Some(ctx.into_crypto())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user