1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Merge pull request 'Create society service with basic functionality and auth #118' (#120) from feat-society into main

Reviewed-on: https://git.ngram.ca/OpenJam/rc-servers/pulls/120
This commit is contained in:
NGnius
2026-05-02 15:10:43 +00:00
51 changed files with 1424 additions and 77 deletions

View File

@@ -19,7 +19,7 @@ impl crate::DisconnectHandler for ClientDisconnecter {
async fn handle(&self, _peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData) {
if let Some(user_info) = user.user().await {
crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::EndConnection {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
is_unregister: false,
}).await);
} else {

View File

@@ -21,7 +21,7 @@ impl crate::handlers::DatalessEventCodeHandler for RequestLoadingSync {
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(),
user_id: user_info.account_id(),
}).await);
} else {
log::error!("Failed to handle sync loading request for unknown user");

View File

@@ -21,7 +21,7 @@ impl crate::handlers::DatalessEventCodeHandler for RequestAllLoadingProgress {
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(),
user_id: user_info.account_id(),
}).await);
} else {
log::error!("Failed to broadcast loading progress for unknown user");

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for AssistBonus {
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::AssistBonus {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
shootee: data.requester_player_id as u8,
shooters: data.player_ids.into_iter().map(|x| x.player).collect(),
}).await);

View File

@@ -21,7 +21,7 @@ impl crate::handlers::DatalessEventCodeHandler for ClientUnregisterer {
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::EndConnection {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
is_unregister: true,
}).await);
} else {

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for DamageBonus {
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::DestroyCubesBonus {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
info: data,
}).await);
}

View File

@@ -21,7 +21,7 @@ impl crate::handlers::DatalessEventCodeHandler for RectifierStart {
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::FlippingStarted {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
}).await);
} else {
log::error!("Failed to handle sync loading request for unknown user");

View File

@@ -23,7 +23,7 @@ impl crate::handlers::RlnlEventCodeHandler for HealAssistBonus {
if let Some(user_info) = user.user().await {
//log::info!("Heal assist for player {}", data.healing_player_id);
super::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::HealAssistBonus {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
healer: data.healing_player_id,
healee: data.healed_player_id,
}).await);

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for HealBonus {
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::HealCubesBonus {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
info: data,
}).await);
}

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for KillEnemyBonus {
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::KillBonus {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
shootee: data.killee_player_id,
shooter: data.killer_player_id,
}).await);

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for KillEnemy {
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::DestroyVehicle {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
remote_player: data.killee_player_id,
killer_player: data.killer_player_id,
}).await);

View File

@@ -21,7 +21,7 @@ impl crate::handlers::DatalessEventCodeHandler for LoadComplete {
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::LoadComplete {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
}).await);
} else {
log::error!("Failed to handle sync loading request for unknown user");

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for GameLoadingProgress {
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_id: user_info.account_id(),
user_name: data.user_name.0,
progress: data.progress,
}).await);

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for PingMap {
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::MapPing {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
ping: data,
}).await);
}

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for PlayerInput {
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.user_id(),
user_id: user_info.account_id(),
data,
}).await);
} else {

View File

@@ -21,7 +21,7 @@ impl crate::handlers::DatalessEventCodeHandler for PlayerQuit {
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::RequestLeave {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
}).await);
} else {
log::error!("Failed to handle sync loading request for unknown user");

View File

@@ -21,7 +21,7 @@ impl crate::handlers::DatalessEventCodeHandler for SelfDestructElim {
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::SelfDestruct {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
is_classic: true,
}).await);
} else {

View File

@@ -22,7 +22,7 @@ impl crate::handlers::RlnlEventCodeHandler for SpotEnemy {
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::SpotVehicle {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
remote_player: data.player_id,
}).await);
}

View File

@@ -64,7 +64,7 @@ impl crate::handlers::RlnlEventCodeHandler for AuthUserGame {
}
},
Ok(None) => {
log::warn!("Cannot validate game guid for user {} with no ongoing game [disconnecting...]", user_info.user_id());
log::warn!("Cannot validate game guid for user {} with no ongoing game [disconnecting...]", user_info.account_id());
super::log_lnl_send_failure(crate::handlers::RlnlSender::new(sender)
.send_data(&rlnl::types::StringCode {
ty: rlnl::types::GameServerErrorCodes::StrErrIncorrectGameGuid,
@@ -76,7 +76,7 @@ impl crate::handlers::RlnlEventCodeHandler for AuthUserGame {
peer.disconnect();
},
Err(e) => {
log::error!("Failed to get current game for user {}: {} [disconnecting...]", user_info.user_id(), e.message);
log::error!("Failed to get current game for user {}: {} [disconnecting...]", user_info.account_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),

View File

@@ -24,7 +24,7 @@ impl crate::handlers::RlnlEventCodeHandler for WeaponSelect {
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_size as _) {
super::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::WeaponSelect {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
machine_id: data.machine_id,
category,
size: tier,

View File

@@ -79,7 +79,7 @@ impl literustlib_server::EventHandler for LnlEventHandler {
async fn on_disconnect(&self, peer: &std::sync::Arc<literustlib_server::Connection<Self::PacketData>>, user: &Self::UserData) {
self.disconnect_handler.handle(peer, user).await;
if let Some(user_info) = user.user().await {
log::info!("Disconnect from user {} ({})", user_info.user_id(), peer.id());
log::info!("Disconnect from user {} ({})", user_info.account_id(), peer.id());
} else {
log::debug!("Disconnect from connection {}", peer.id());
}

View File

@@ -29,7 +29,7 @@ impl <const EVENT: i16, const PROPERTY: u8, InOut: byteserde::des_slice::ByteDes
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 {
crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::CustomLogicRlnl {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
event: self.event,
property: self.property,
data: Box::new(data),

View File

@@ -30,7 +30,7 @@ impl <const EXCLUDE_SENDER: bool, const CODE_IN: i16, const CODE_OUT: i16, const
if EXCLUDE_SENDER {
crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::RebroadcastRlnl {
skip_user_id: user_info.user_id(),
skip_user_id: user_info.account_id(),
event: self.code_out,
event_in: Self::CODE,
property: self.property,
@@ -38,7 +38,7 @@ impl <const EXCLUDE_SENDER: bool, const CODE_IN: i16, const CODE_OUT: i16, const
}).await);
} else {
crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::BroadcastRlnl {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
event: self.code_out,
event_in: Self::CODE,
property: self.property,

View File

@@ -27,7 +27,7 @@ impl <const EXCLUDE_SENDER: bool, const CODE_IN: i16, const CODE_OUT: i16, const
if let Some(user_info) = user.user().await {
if EXCLUDE_SENDER {
crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::RebroadcastRlnl {
skip_user_id: user_info.user_id(),
skip_user_id: user_info.account_id(),
event: self.code_out,
event_in: Self::CODE,
property: self.property,
@@ -35,7 +35,7 @@ impl <const EXCLUDE_SENDER: bool, const CODE_IN: i16, const CODE_OUT: i16, const
}).await);
} else {
crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::BroadcastRlnl {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
event: self.code_out,
event_in: Self::CODE,
property: self.property,

View File

@@ -260,7 +260,7 @@ impl GameMatches {
}
};
self.matches.insert(game_guid.clone(), tx.clone());
self.routing.insert(user.user_id(), game_guid.clone());
self.routing.insert(user.account_id(), game_guid.clone());
if !self.is_crystal_regen_running.swap(true, std::sync::atomic::Ordering::SeqCst) {
tokio::task::spawn(Self::regenerate_crystal_order_task(
self.ba_sorted_crystals.clone(),
@@ -304,7 +304,7 @@ impl GameMatches {
self.do_game_cleanup(&game_guid);
self.create_new_game(user.clone(), game_guid, connection, response, sender).await;
} else {
self.routing.insert(user.user_id(), game_guid.clone());
self.routing.insert(user.account_id(), game_guid.clone());
if tx.send(super::GameMessage::NewConnection { user: user.clone(), game_guid, connection, response, sender }).await.is_err() {
log::error!("Failed to send NewConnection game message to existing match");
}

View File

@@ -370,7 +370,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
pub(super) async fn rebroadcast<T: byteserde::ser_heap::ByteSerializeHeap + ?Sized>(&self, user_id: i32, code: rlnl::event_code::NetworkEvent, property: literustlib::packet::Property, data: &T, in_game: bool) {
for (player_id, conn) in self.users.read().await.iter() {
if user_id == conn.user.user_id() { continue; }
if user_id == conn.user.account_id() { continue; }
if conn.aliases.contains(player_id) { continue; }
if in_game {
let mode = ConnectionMode::from_u8(self.user_descriptor(*player_id).unwrap().state.mode.load(std::sync::atomic::Ordering::Relaxed));
@@ -388,7 +388,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
pub(super) async fn rebroadcast_dataless(&self, user_id: i32, code: rlnl::event_code::NetworkEvent, property: literustlib::packet::Property, in_game: bool) {
for (player_id, conn) in self.users.read().await.iter() {
if user_id == conn.user.user_id() { continue; }
if user_id == conn.user.account_id() { continue; }
if conn.aliases.contains(player_id) { continue; }
if in_game {
let mode = ConnectionMode::from_u8(self.user_descriptor(*player_id).unwrap().state.mode.load(std::sync::atomic::Ordering::Relaxed));
@@ -586,7 +586,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
} else {
//tokio::time::sleep(std::time::Duration::from_secs(1)).await;
//let id = users.len() as u8;
let user_id = user.user_id();
let user_id = user.account_id();
let player_info_opt = self.descriptors.values().find(|p| p.descriptor.user_id == Some(user_id));
if player_info_opt.is_none() {
log::warn!("User {} tried to connect to match {} which they are not in", user_id, self.game_guid());
@@ -617,7 +617,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
literustlib::packet::Property::ReliableOrdered,
&new_user.connection.connection
).await);
log::debug!("User {} is validated to play game {}", new_user.user.user_id(), game_guid);
log::debug!("User {} is validated to play game {}", new_user.user.account_id(), game_guid);
let new_user = std::sync::Arc::new(new_user);
if let Err(e) = new_user.user.save_player_connected_status(self.game_guid(), true).await {
log::error!("Failed to mark player {} (user {}) as connected to game {}: {}", id, user_id, self.game_guid(), e);
@@ -757,7 +757,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
};
for (player_id, conn) in self.users.read().await.iter() {
let user_desc = self.user_descriptor(*player_id).unwrap();
if user_id == conn.user.user_id() {
if user_id == conn.user.account_id() {
let progress_percent = ((progress * 100.0).ceil() as u8).clamp(0, 100);
log::debug!("User {} is loaded {}% into game {}", user_id, progress_percent, self.game_guid());
user_desc.state.progress.store(progress_percent, std::sync::atomic::Ordering::Relaxed);
@@ -894,7 +894,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
for (player_id, user) in self.users.read().await.iter() {
let user_desc = self.user_descriptor(*player_id).unwrap();
if user.aliases.contains(player_id) { continue; }
if user.user.user_id() == user_id {
if user.user.account_id() == user_id {
if !matches!(ConnectionMode::from_u8(user_desc.state.mode.load(std::sync::atomic::Ordering::Relaxed)), ConnectionMode::Loading | ConnectionMode::Disconnected) {
log::warn!("Got RequestLoadingSync after user {} was already in/past WaitingForSync stage", user_id);
continue;
@@ -1362,7 +1362,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
fn spawn_send_loading_events(&self, user: &UserConnection, player_id: u8, players: Vec<std::sync::Arc<oj_rc_core::persist::user::PlayerDescriptor>>, client_ais: Vec<u8>) {
let connection = user.connection.clone();
let user_id = user.user.user_id();
let user_id = user.user.account_id();
tokio::spawn(Self::send_loading_events_wrapper(connection, player_id, user_id, players, client_ais));
}

View File

@@ -120,7 +120,7 @@ impl GameMessage {
pub fn user_id(&self) -> i32 {
match self {
Self::NewConnection { user, .. } => {
user.user_id()
user.account_id()
}
Self::EndConnection { user_id, .. } => *user_id,
Self::RequestLeave { user_id, .. } => *user_id,

View File

@@ -411,7 +411,7 @@ impl CustomGameLogic for PitLogic {
}
}
if single_client.is_some() {
let user_id = read_lock.values().next().unwrap().user.user_id();
let user_id = read_lock.values().next().unwrap().user.account_id();
let player_id = generic.user_key_by_user_id(user_id).unwrap();
let user_info = generic.user_descriptor(player_id).unwrap();
WinTracker::do_win(generic, self, user_info.descriptor.team as u8).await;

View File

@@ -24,7 +24,7 @@ impl crate::RobotMotionHandler for VehicleMotionHandler {
match rlnl::machine_motion::MachineMotion::byte_deserialize(&mut des) {
Ok(motion_data) => {
crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::Motion {
user_id: user_info.user_id(),
user_id: user_info.account_id(),
motion: motion_data,
}).await);
},