mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Get part way through loading (to sync) #30
This commit is contained in:
30
rc_multiplayer/src/events/activate_sync.rs
Normal file
30
rc_multiplayer/src/events/activate_sync.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
pub struct RequestLoadingSync {
|
||||
msg_router: tokio::sync::mpsc::Sender<crate::matches::GameMessage>,
|
||||
}
|
||||
|
||||
pub(super) fn handler(init_ctx: &crate::InitConfig) -> crate::handlers::dataless::Dataless<RequestLoadingSync> {
|
||||
crate::handlers::dataless::Dataless::new(RequestLoadingSync::new(init_ctx))
|
||||
}
|
||||
|
||||
impl RequestLoadingSync {
|
||||
fn new(init_ctx: &crate::InitConfig) -> Self {
|
||||
Self {
|
||||
msg_router: init_ctx.matches_chann.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl crate::handlers::dataless::DatalessEventCodeHandler for RequestLoadingSync {
|
||||
const CODE: rlnl::event_code::NetworkEvent = rlnl::event_code::NetworkEvent::RequestSync;
|
||||
|
||||
async fn handle(&self, _peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData, _sender: &std::sync::Arc<literustlib_server::DataSender<crate::PacketData>>) {
|
||||
if let Some(user_info) = user.user().await {
|
||||
super::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::RequestLoadingSync {
|
||||
user_id: user_info.user_id(),
|
||||
}).await);
|
||||
} else {
|
||||
log::error!("Failed to handle sync loading request for unknown user");
|
||||
}
|
||||
}
|
||||
}
|
||||
30
rc_multiplayer/src/events/all_loading_progress.rs
Normal file
30
rc_multiplayer/src/events/all_loading_progress.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
pub struct RequestAllLoadingProgress {
|
||||
msg_router: tokio::sync::mpsc::Sender<crate::matches::GameMessage>,
|
||||
}
|
||||
|
||||
pub(super) fn handler(init_ctx: &crate::InitConfig) -> crate::handlers::dataless::Dataless<RequestAllLoadingProgress> {
|
||||
crate::handlers::dataless::Dataless::new(RequestAllLoadingProgress::new(init_ctx))
|
||||
}
|
||||
|
||||
impl RequestAllLoadingProgress {
|
||||
fn new(init_ctx: &crate::InitConfig) -> Self {
|
||||
Self {
|
||||
msg_router: init_ctx.matches_chann.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl crate::handlers::dataless::DatalessEventCodeHandler for RequestAllLoadingProgress {
|
||||
const CODE: rlnl::event_code::NetworkEvent = rlnl::event_code::NetworkEvent::RequestLoadingProgressAllUsers;
|
||||
|
||||
async fn handle(&self, _peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData, _sender: &std::sync::Arc<literustlib_server::DataSender<crate::PacketData>>) {
|
||||
if let Some(user_info) = user.user().await {
|
||||
super::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::RequestLoadingProgress {
|
||||
user_id: user_info.user_id(),
|
||||
}).await);
|
||||
} else {
|
||||
log::error!("Failed to broadcast loading progress for unknown user");
|
||||
}
|
||||
}
|
||||
}
|
||||
33
rc_multiplayer/src/events/loading_progress.rs
Normal file
33
rc_multiplayer/src/events/loading_progress.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
pub struct GameLoadingProgress {
|
||||
msg_router: tokio::sync::mpsc::Sender<crate::matches::GameMessage>,
|
||||
}
|
||||
|
||||
pub(super) fn handler(init_ctx: &crate::InitConfig) -> crate::handlers::simple_typed::SimpleRlnl<rlnl::events::loading::LoadingProgress, GameLoadingProgress> {
|
||||
crate::handlers::simple_typed::SimpleRlnl::new(GameLoadingProgress::new(init_ctx))
|
||||
}
|
||||
|
||||
impl GameLoadingProgress {
|
||||
fn new(init_ctx: &crate::InitConfig) -> Self {
|
||||
Self {
|
||||
msg_router: init_ctx.matches_chann.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl crate::handlers::simple_typed::RlnlEventCodeHandler for GameLoadingProgress {
|
||||
type In = rlnl::events::loading::LoadingProgress;
|
||||
const CODE: rlnl::event_code::NetworkEvent = rlnl::event_code::NetworkEvent::BroadcastLoadingProgress;
|
||||
|
||||
async fn handle(&self, data: Self::In, _peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData, _sender: &std::sync::Arc<literustlib_server::DataSender<crate::PacketData>>) {
|
||||
if let Some(user_info) = user.user().await {
|
||||
super::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::LoadingProgress {
|
||||
user_id: user_info.user_id(),
|
||||
user_name: data.user_name.0,
|
||||
progress: data.progress,
|
||||
}).await);
|
||||
} else {
|
||||
log::error!("Failed to broadcast loading progress for user {} (no auth!)", data.user_name.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,28 @@
|
||||
mod validate_game_guid;
|
||||
mod loading_progress;
|
||||
mod all_loading_progress;
|
||||
mod weapon_select;
|
||||
mod activate_sync;
|
||||
|
||||
pub async fn handler(init_ctx: &crate::InitConfig) -> crate::handler::LnlEventHandler {
|
||||
crate::handler::LnlEventHandler::new()
|
||||
crate::handler::LnlEventHandler::new(init_ctx.users.clone(), crate::vehicle_motion::handler(init_ctx))
|
||||
.add(validate_game_guid::handler(init_ctx))
|
||||
.add(loading_progress::handler(init_ctx))
|
||||
.add(all_loading_progress::handler(init_ctx))
|
||||
.add(weapon_select::handler(init_ctx))
|
||||
.add(activate_sync::handler(init_ctx))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn log_channel_send_failure<T>(result: Result<(), tokio::sync::mpsc::error::SendError<T>>) {
|
||||
if result.is_err() {
|
||||
log::error!("Failed to send game message");
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn log_lnl_send_failure(result: std::io::Result<usize>) {
|
||||
if let Err(e) = result {
|
||||
log::error!("Failed to send packet: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub struct AuthUserGame {
|
||||
|
||||
matches: tokio::sync::mpsc::Sender<crate::matches::GameMessage>,
|
||||
}
|
||||
|
||||
pub(super) fn handler(init_ctx: &crate::InitConfig) -> crate::handlers::simple_typed::SimpleRlnl<rlnl::events::loading::GameGuidInfo, AuthUserGame> {
|
||||
@@ -7,9 +7,9 @@ pub(super) fn handler(init_ctx: &crate::InitConfig) -> crate::handlers::simple_t
|
||||
}
|
||||
|
||||
impl AuthUserGame {
|
||||
fn new(_init_ctx: &crate::InitConfig) -> Self {
|
||||
fn new(init_ctx: &crate::InitConfig) -> Self {
|
||||
Self {
|
||||
|
||||
matches: init_ctx.matches_chann.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,26 @@ impl crate::handlers::simple_typed::RlnlEventCodeHandler for AuthUserGame {
|
||||
type In = rlnl::events::loading::GameGuidInfo;
|
||||
const CODE: rlnl::event_code::NetworkEvent = rlnl::event_code::NetworkEvent::ValidateGameGuid;
|
||||
|
||||
async fn handle(&self, data: Self::In, peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData, sender: &literustlib_server::DataSender<crate::PacketData>) {
|
||||
log::debug!("Got {:?} event with data {:?}", Self::CODE, data);
|
||||
async fn handle(&self, data: Self::In, peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData, sender: &std::sync::Arc<literustlib_server::DataSender<crate::PacketData>>) {
|
||||
let username = data.player_name.0.clone();
|
||||
let game_guid = data.game_guid.0.clone();
|
||||
if user.authenticate(data).await {
|
||||
let user_info = user.user().await.unwrap();
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
super::log_channel_send_failure(self.matches.send(crate::matches::GameMessage::NewConnection {
|
||||
user: user_info.clone(),
|
||||
game_guid,
|
||||
connection: peer.to_owned(),
|
||||
response: tx,
|
||||
sender: sender.to_owned(),
|
||||
}).await);
|
||||
log::debug!("Sent NewConnection message to matches handler");
|
||||
if let Ok(Some(e)) = rx.await {
|
||||
log::error!("Failed {:?} event: {}", Self::CODE, e);
|
||||
}
|
||||
} else {
|
||||
log::error!("Failed to validate game guid for user {} (other packets will probably be ignored)", username);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
36
rc_multiplayer/src/events/weapon_select.rs
Normal file
36
rc_multiplayer/src/events/weapon_select.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
pub struct WeaponSelect {
|
||||
msg_router: tokio::sync::mpsc::Sender<crate::matches::GameMessage>,
|
||||
}
|
||||
|
||||
pub(super) fn handler(init_ctx: &crate::InitConfig) -> crate::handlers::simple_typed::SimpleRlnl<rlnl::events::ingame::SelectWeapon, WeaponSelect> {
|
||||
crate::handlers::simple_typed::SimpleRlnl::new(WeaponSelect::new(init_ctx))
|
||||
}
|
||||
|
||||
impl WeaponSelect {
|
||||
fn new(init_ctx: &crate::InitConfig) -> Self {
|
||||
Self {
|
||||
msg_router: init_ctx.matches_chann.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl crate::handlers::simple_typed::RlnlEventCodeHandler for WeaponSelect {
|
||||
type In = rlnl::events::ingame::SelectWeapon;
|
||||
const CODE: rlnl::event_code::NetworkEvent = rlnl::event_code::NetworkEvent::WeaponSelect;
|
||||
|
||||
async fn handle(&self, data: Self::In, _peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData, _sender: &std::sync::Arc<literustlib_server::DataSender<crate::PacketData>>) {
|
||||
if let Some(user_info) = user.user().await {
|
||||
if let Some(category) = oj_rc_core::data::weapon_list::ItemCategory::from_smaller(data.item_category as _) {
|
||||
if let Some(tier) = oj_rc_core::data::cube_list::ItemTier::from_u32(data.item_category as _) {
|
||||
super::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::WeaponSelect {
|
||||
user_id: user_info.user_id(),
|
||||
machine_id: data.machine_id,
|
||||
category,
|
||||
size: tier,
|
||||
}).await);
|
||||
} else { log::warn!("Bad WeaponSelect tier") }
|
||||
} else { log::warn!("Bad WeaponSelect category") }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user