1
0
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:
NGnius (Graham)
2025-03-18 22:30:20 -04:00
parent 67c14fe80a
commit 78941fb8ff
17 changed files with 132 additions and 153 deletions

View File

@@ -1,5 +1,4 @@
mod cli;
mod state;
use polariton_auth::Handshake;
use tokio::net;
@@ -44,11 +43,11 @@ async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAdd
return;
}
};
let sock_state = state::State::new(enc);
while let Ok(packet) = polariton_server::utils::receive_packet_async(&mut socket, &sock_state.serdes_ctx()).await {
let ctx = polariton::packet::SerdesContext::from_boxed(Default::default(), enc);
while let Ok(packet) = polariton_server::utils::receive_packet_async(&mut socket, &ctx).await {
match packet {
Packet::Ping(ping) => {
polariton_server::utils::handle_ping_async(ping, &mut socket, &sock_state.serdes_ctx()).await.unwrap_or_default();
polariton_server::utils::handle_ping_async(ping, &mut socket, &ctx).await.unwrap_or_default();
},
Packet::Packet(packet) => log::warn!("Not handling packet {:?}", packet),
}
@@ -107,7 +106,7 @@ async fn do_connect_handshake(
socket: &mut net::TcpStream,
game_server_name: &str,
game_server_url: &str,
) -> Option<polariton_auth::CryptoImpl> {
) -> Option<Box<dyn polariton::packet::Cryptographer>> {
let handshake = Handshake::new(APP_ID);
// connect
log::debug!("(connect) Handling first packet");
@@ -168,7 +167,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 {
@@ -188,7 +187,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) => {
@@ -257,5 +256,5 @@ async fn do_connect_handshake(
}
}
Some(crypto)
Some(ctx.into_crypto())
}

View File

@@ -1,17 +0,0 @@
const SERDES_SERDES_CTX_REF: &'static polariton::serdes::SerdesContext<(), polariton::serdes::NoCustomSerdes> = &polariton::serdes::SerdesContext::default_const();
pub struct State {
pub crypto: polariton_auth::CryptoImpl,
}
impl State {
pub fn new(c: polariton_auth::CryptoImpl) -> Self {
Self {
crypto: c,
}
}
pub fn serdes_ctx(&self) -> polariton::packet::SerdesContext<'_, (), polariton::serdes::NoCustomSerdes> {
polariton::packet::SerdesContext::new(SERDES_SERDES_CTX_REF, &self.crypto)
}
}