1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00
Files
ojrc/rc_multiplayer/src/events/player_input.rs

33 lines
1.3 KiB
Rust

pub struct PlayerInput {
msg_router: tokio::sync::mpsc::Sender<crate::matches::GameMessage>,
}
pub(super) fn handler(init_ctx: &crate::InitConfig) -> crate::handlers::SimpleRlnl<rlnl::events::ingame::PlayerIdAndInputData, PlayerInput> {
crate::handlers::SimpleRlnl::new(PlayerInput::new(init_ctx))
}
impl PlayerInput {
fn new(init_ctx: &crate::InitConfig) -> Self {
Self {
msg_router: init_ctx.matches_chann.clone(),
}
}
}
#[async_trait::async_trait]
impl crate::handlers::RlnlEventCodeHandler for PlayerInput {
type In = rlnl::events::ingame::PlayerIdAndInputData;
const CODE: rlnl::event_code::NetworkEvent = rlnl::event_code::NetworkEvent::OnPlayerInputChanged;
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::PlayerInputChanged {
user_id: user_info.account_id(),
data,
}).await);
} else {
log::error!("Failed to rebroadcast OnPlayerInputChanged for user (no auth!)");
}
}
}