mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Allow two or more people to load into the same multiplayer match #30
This commit is contained in:
1 parent
cd45c22d0b
commit
37cbc8d85f
24 files changed
+902
-149
No files matched your search
@@ -42,6 +42,13 @@ pub async fn handler(init_ctx: &crate::InitConfig) -> crate::handler::LnlEventHa
|
||||
{literustlib::packet::Property::Unreliable as u8},
|
||||
rlnl::events::ingame::FireMiss,
|
||||
>::handler(init_ctx))
|
||||
.add(crate::handlers::Broadcaster::<
|
||||
true,
|
||||
{rlnl::event_code::NetworkEvent::EnemySpotted as i16},
|
||||
{rlnl::event_code::NetworkEvent::EnemySpotted as i16},
|
||||
{literustlib::packet::Property::ReliableOrdered as u8},
|
||||
rlnl::events::ingame::SpottingIds,
|
||||
>::handler(init_ctx))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -24,21 +24,91 @@ impl crate::handlers::RlnlEventCodeHandler for AuthUserGame {
|
||||
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);
|
||||
match user_info.current_game().await {
|
||||
Ok(Some(current_game)) => {
|
||||
if current_game.guid == game_guid {
|
||||
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: {} [disconnecting...]", Self::CODE, e);
|
||||
super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender)
|
||||
.send_data(&rlnl::types::StringCode {
|
||||
ty: rlnl::types::GameServerErrorCodes::StrErrCustomString,
|
||||
custom: Some(rlnl::types::BinaryWriterString(e.message)),
|
||||
},
|
||||
rlnl::event_code::NetworkEvent::OnFailedToConnectToServer,
|
||||
literustlib::packet::Property::ReliableOrdered,
|
||||
&peer).await);
|
||||
peer.disconnect();
|
||||
}
|
||||
} else {
|
||||
log::error!("Registered game GUID does not match sent GUID (got: {}, expected: {}) [disconnecting...]", game_guid, current_game.guid);
|
||||
super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender)
|
||||
.send_data(&rlnl::types::StringCode {
|
||||
ty: rlnl::types::GameServerErrorCodes::StrErrIncorrectGameGuid,
|
||||
custom: Some(rlnl::types::BinaryWriterString(format!("Send game guid does not equal expected guid; {} != {}", game_guid, current_game.guid))),
|
||||
},
|
||||
rlnl::event_code::NetworkEvent::OnFailedToConnectToServer,
|
||||
literustlib::packet::Property::ReliableOrdered,
|
||||
&peer).await);
|
||||
peer.disconnect();
|
||||
}
|
||||
},
|
||||
Ok(None) => {
|
||||
log::warn!("Cannot validate game guid for user {} with no ongoing game [disconnecting...]", user_info.user_id());
|
||||
super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender)
|
||||
.send_data(&rlnl::types::StringCode {
|
||||
ty: rlnl::types::GameServerErrorCodes::StrErrIncorrectGameGuid,
|
||||
custom: None,
|
||||
},
|
||||
rlnl::event_code::NetworkEvent::OnFailedToConnectToServer,
|
||||
literustlib::packet::Property::ReliableOrdered,
|
||||
&peer).await);
|
||||
peer.disconnect();
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!("Failed to get current game for user {}: {} [disconnecting...]", user_info.user_id(), e.message);
|
||||
super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender)
|
||||
.send_data(&rlnl::types::StringCode {
|
||||
ty: core_to_rlnl_mp_error_code(e.code),
|
||||
custom: Some(rlnl::types::BinaryWriterString(e.message)),
|
||||
},
|
||||
rlnl::event_code::NetworkEvent::OnFailedToConnectToServer,
|
||||
literustlib::packet::Property::ReliableOrdered,
|
||||
&peer).await);
|
||||
peer.disconnect();
|
||||
},
|
||||
}
|
||||
|
||||
} else {
|
||||
log::error!("Failed to validate game guid for user {} (other packets will probably be ignored)", username);
|
||||
log::error!("Failed to validate game guid for user {} [disconnecting...]", username);
|
||||
peer.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fn core_to_rlnl_mp_error_code(core_: oj_rc_core::persist::user::MultiplayerErrorCode) -> rlnl::types::GameServerErrorCodes {
|
||||
match core_ {
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxSpeed => rlnl::types::GameServerErrorCodes::StrErrHaxSpeed,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxException => rlnl::types::GameServerErrorCodes::StrErrHaxException,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxTeleport => rlnl::types::GameServerErrorCodes::StrErrHaxTeleport,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxEacViolation => rlnl::types::GameServerErrorCodes::StrErrHaxEacViolation,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxAfk => rlnl::types::GameServerErrorCodes::StrErrHaxAfk,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxFirerange => rlnl::types::GameServerErrorCodes::StrErrHaxFirerange,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxFiredamage => rlnl::types::GameServerErrorCodes::StrErrHaxFiredamage,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxFirerate => rlnl::types::GameServerErrorCodes::StrErrHaxFirerate,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::HaxFireposition => rlnl::types::GameServerErrorCodes::StrErrHaxFireposition,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::IncorrectGameGuid => rlnl::types::GameServerErrorCodes::StrErrIncorrectGameGuid,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::CustomString => rlnl::types::GameServerErrorCodes::StrErrCustomString,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::TimedOut => rlnl::types::GameServerErrorCodes::StrErrTimedOut,
|
||||
oj_rc_core::persist::user::MultiplayerErrorCode::GameEnded => rlnl::types::GameServerErrorCodes::StrErrGameEnded,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user