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

Readability fixes for cargo clippy

This commit is contained in:
NG (Graham)
2025-09-03 22:33:26 -04:00
parent 9dcb12131b
commit 0e35aced01
77 changed files with 725 additions and 735 deletions

View File

@@ -38,53 +38,53 @@ impl crate::handlers::RlnlEventCodeHandler for AuthUserGame {
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)
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).await);
peer.disconnect();
} else {
peer.certify();
}
} 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)
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).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)
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).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)
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).await);
peer.disconnect();
},
}

View File

@@ -137,8 +137,8 @@ impl literustlib::packet::PacketData for EventData {
use std::io::Write;
let mut buf = Vec::new();
buf.write_all(&(self.message_ty as i16).to_le_bytes()).unwrap();
buf.write_all(&(self.variant as i16).to_le_bytes()).unwrap();
buf.write_all(&(self.data_size as u16).to_le_bytes()).unwrap();
buf.write_all(&self.variant.to_le_bytes()).unwrap();
buf.write_all(&self.data_size.to_le_bytes()).unwrap();
buf.write_all(&self.data).unwrap();
buf.into()
}

View File

@@ -16,7 +16,7 @@ impl <const EVENT: i16, const PROPERTY: u8, InOut: byteserde::des_slice::ByteDes
msg_router: init_ctx.matches_chann.clone(),
event: crate::handler::i16_to_event_or_panic(EVENT),
property: literustlib::packet::Property::try_from(PROPERTY).expect("Invalid literustlib packet property"),
_in: std::marker::PhantomData::default(),
_in: std::marker::PhantomData,
}
}
}

View File

@@ -15,7 +15,7 @@ impl <const EXCLUDE_SENDER: bool, const CODE_IN: i16, const CODE_OUT: i16, const
msg_router: init_ctx.matches_chann.clone(),
code_out: crate::handler::i16_to_event_or_panic(CODE_OUT),
property: literustlib::packet::Property::try_from(PROPERTY).expect("Invalid literustlib packet property"),
_in: std::marker::PhantomData::default(),
_in: std::marker::PhantomData,
}
}
}

View File

@@ -24,7 +24,7 @@ pub trait RlnlEventCodeHandler: Sync + Send {
#[async_trait::async_trait]
impl <In: byteserde::des_slice::ByteDeserializeSlice<In> + Send, H: RlnlEventCodeHandler<In=In>> crate::EventCodeHandler for SimpleRlnl<In, H> {
async fn handle(&self, data: &bytes::Bytes, peer: &std::sync::Arc<literustlib_server::Connection<crate::PacketData>>, user: &crate::UserData, sender: &std::sync::Arc<literustlib_server::DataSender<crate::PacketData>>) {
let mut des = byteserde::des_slice::ByteDeserializerSlice::new(&data);
let mut des = byteserde::des_slice::ByteDeserializerSlice::new(data);
match In::byte_deserialize(&mut des) {
Ok(rlnl_data) => {
//log::info!("Received {:?} message", H::CODE);

View File

@@ -10,7 +10,7 @@ impl <const CODE_IN: i16, In: byteserde::des_slice::ByteDeserializeSlice<In> + S
fn new(_init_ctx: &crate::InitConfig) -> Self {
Self {
_in: std::marker::PhantomData::default(),
_in: std::marker::PhantomData,
}
}
}

View File

@@ -52,7 +52,7 @@ impl GameMatches {
fakes
}
async fn start_new_match_engine(&self, user: &Box<dyn oj_rc_core::persist::user::MultiplayerUser + Send + Sync + 'static>, guid: &str) -> Result<tokio::sync::mpsc::Sender<super::GameMessage>, oj_rc_core::persist::user::MultiplayerError> {
async fn start_new_match_engine(&self, user: &(dyn oj_rc_core::persist::user::MultiplayerUser + Send + Sync + 'static), guid: &str) -> Result<tokio::sync::mpsc::Sender<super::GameMessage>, oj_rc_core::persist::user::MultiplayerError> {
let game_info = user.game_info(guid).await?
.ok_or_else(|| oj_rc_core::persist::user::MultiplayerError {
code: oj_rc_core::persist::user::MultiplayerErrorCode::CustomString,
@@ -89,7 +89,7 @@ impl GameMatches {
oj_rc_core::data::game_mode::GameMode::BattleArena => {
log::warn!("Game {}: Battle Arena is experimental", guid);
let resolved_ba_conf = self.ba_settings.resolve(
user.as_ref(),
user,
self.factory.as_ref(),
&self.cube_parsers.weapon_order(),
&self.cube_parsers.cpu_counter(),
@@ -127,7 +127,7 @@ impl GameMatches {
sender: std::sync::Arc<literustlib_server::DataSender<crate::PacketData>>,
) {
log::info!("Creating new game {}", game_guid);
let tx = match self.start_new_match_engine(&user, &game_guid).await {
let tx = match self.start_new_match_engine(user.as_ref().as_ref(), &game_guid).await {
Ok(tx) => tx,
Err(e) => {
if response.send(Some(crate::matches::messages::ErrorMessage {
@@ -190,10 +190,8 @@ impl GameMatches {
if let Some(tx) = self.matches.get(guid) {
if tx.is_closed() {
to_clean = Some(guid.to_owned());
} else {
if tx.send(msg).await.is_err() {
log::error!("Failed to route game message from user {} to match {}", user_id, guid);
}
} else if tx.send(msg).await.is_err() {
log::error!("Failed to route game message from user {} to match {}", user_id, guid);
}
} else {
self.routing.remove(&user_id);

View File

@@ -25,6 +25,7 @@ pub trait CustomGameLogic: Sized + Send + Sync + 'static {
/// Called when the game is marked as complete
async fn on_game_completed(&self, generic: &super::GenericGamemodeEngine<Self>) -> bool;
/// Called when various network events are broadcast from one client but before they are sent to the rest of the clients
#[allow(clippy::too_many_arguments)]
async fn on_broadcast(&self, generic: &super::GenericGamemodeEngine<Self>, user_id: i32, event_out: rlnl::event_code::NetworkEvent, event_in: rlnl::event_code::NetworkEvent, property: literustlib::packet::Property, data: &Option<Box<dyn crate::Broadcastable>>, skip_user: bool) -> bool;
/// Called when a vehicle motion event is received from a client
async fn on_motion(&self, generic: &super::GenericGamemodeEngine<Self>, motion: &rlnl::machine_motion::MachineMotion, location: (f32, f32, f32)) -> bool;

View File

@@ -17,8 +17,8 @@ impl ExperimentalPlayer {
#[async_trait::async_trait]
impl super::FakeUser for ExperimentalPlayer {
async fn on_init(&self, descriptors: &Vec<oj_rc_core::persist::user::PlayerDescriptor>, player_id: u8) {
if let Some(my_desc) = descriptors.iter().filter(|x| x.player_id == player_id).next() {
async fn on_init(&self, descriptors: &[oj_rc_core::persist::user::PlayerDescriptor], player_id: u8) {
if let Some(my_desc) = descriptors.iter().find(|x| x.player_id == player_id) {
*self.me.write().await = Some(my_desc.to_owned());
}
}

View File

@@ -1,6 +1,6 @@
#[async_trait::async_trait]
pub trait FakeUser: Send + Sync {
async fn on_init(&self, descriptors: &Vec<oj_rc_core::persist::user::PlayerDescriptor>, player_id: u8);
async fn on_init(&self, descriptors: &[oj_rc_core::persist::user::PlayerDescriptor], player_id: u8);
async fn on_ready(&self, real_players: &std::collections::HashMap<u8, crate::matches::generic::UserSender>);
//fn on_damage(&self, data: &rlnl::events::ingame::DestroyCubesFull);
async fn on_end(&self);

View File

@@ -233,7 +233,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
}
pub(super) async fn user_key_by_user_id(&self, user_id: i32) -> Option<u8> {
self.user_id_map.read().await.get(&user_id).map(|x| *x)
self.user_id_map.read().await.get(&user_id).copied()
}
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) {
@@ -335,7 +335,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
//tokio::time::sleep(std::time::Duration::from_secs(1)).await;
//let id = users.len() as u8;
let user_id = user.user_id();
let player_info = self.players_info.iter().filter(|p| p.user_id == Some(user_id)).next().unwrap();
let player_info = self.players_info.iter().find(|p| p.user_id == Some(user_id)).unwrap();
let id = player_info.player_id;
let new_user = UserConnection {
user,
@@ -535,10 +535,8 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
log::info!("User {} is awaiting sync", user_id);
user.state.mode.store(ConnectionMode::WaitingForSync.to_u8(), std::sync::atomic::Ordering::Relaxed);
ready_count += 1;
} else {
if matches!(ConnectionMode::from_u8(user.state.mode.load(std::sync::atomic::Ordering::Relaxed)), ConnectionMode::WaitingForSync) {
ready_count += 1;
}
} else if matches!(ConnectionMode::from_u8(user.state.mode.load(std::sync::atomic::Ordering::Relaxed)), ConnectionMode::WaitingForSync) {
ready_count += 1;
}
}
let player_count = self.players_info.iter().filter(|x| x.user_id.is_some()).count();
@@ -675,7 +673,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
},
super::GameMessage::MapPing { user_id: _, ping } => {
for (id, conn) in self.users.read().await.iter() {
if (*id as i32) != ping.sender && (conn.descriptor.team as i32) == ping.team_id {
if (*id as i32) != ping.sender && conn.descriptor.team == ping.team_id {
crate::events::log_lnl_send_failure(conn.connection.rlnl().send_data(
&ping,
rlnl::event_code::NetworkEvent::MapPingEvent,
@@ -931,7 +929,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
sender.send_data(
&rlnl::events::sync::InitialiseGameStats {
num_players,
stats: (0..num_players).into_iter()
stats: (0..num_players)
.map(|i| rlnl::types::IngamePlayerStats {
player_name: i,
num_stats: 0,

View File

@@ -1,11 +1,11 @@
mod engine;
pub(self) use engine::{CustomGameLogic, RlnlPacket};
use engine::{CustomGameLogic, RlnlPacket};
mod messages;
pub use messages::GameMessage;
mod generic;
pub(self) use generic::GenericGamemodeEngine;
use generic::GenericGamemodeEngine;
mod aggregate;
pub use aggregate::GameMatches;
@@ -16,6 +16,6 @@ pub mod modes;
mod timer;
pub(self) mod fake;
mod fake;
pub const CHANNEL_BOUND: usize = 16;

View File

@@ -112,12 +112,10 @@ impl PointInfo {
let team = self.team.load(std::sync::atomic::Ordering::SeqCst);
if team < 0 {
0
} else if let Some(counter) = self.on_point.read().await.get(&(team as u8)) {
counter.load(std::sync::atomic::Ordering::SeqCst)
} else {
if let Some(counter) = self.on_point.read().await.get(&(team as u8)) {
counter.load(std::sync::atomic::Ordering::SeqCst)
} else {
0
}
0
}
}
@@ -212,7 +210,7 @@ impl PointTracker {
notification: rlnl::types::CapturePointNotificationType::CaptureLocked,
id: point_i,
defending_team: point_team,
attacking_team: player_team as i8,
attacking_team: player_team,
},
true,
).await;
@@ -228,7 +226,7 @@ impl PointTracker {
notification: rlnl::types::CapturePointNotificationType::CaptureStarted,
id: point_i,
defending_team: point_team,
attacking_team: player_team as i8,
attacking_team: player_team,
},
true,
).await;
@@ -240,7 +238,7 @@ impl PointTracker {
notification: rlnl::types::CapturePointNotificationType::CaptureLocked,
id: point_i,
defending_team: point_team,
attacking_team: player_team as i8,
attacking_team: player_team,
},
true,
).await;
@@ -267,20 +265,18 @@ impl PointTracker {
// something is out of sync, let's just ignore it and try to undo any underflow
log::warn!("Team {} players on point {} counting error", player_team, point_i);
point.on_point.read().await[&player_team_u8].store(0, std::sync::atomic::Ordering::SeqCst);
} else {
if old_friendlies == 1 && current_enemies != 0 {
generic.broadcast(
rlnl::event_code::NetworkEvent::CapturePointNotification,
literustlib::packet::Property::ReliableOrdered,
&rlnl::events::ingame::CapturePointNotification {
notification: rlnl::types::CapturePointNotificationType::CaptureUnlocked,
id: point_i,
defending_team: point_team,
attacking_team: player_team as i8,
},
true,
).await;
}
} else if old_friendlies == 1 && current_enemies != 0 {
generic.broadcast(
rlnl::event_code::NetworkEvent::CapturePointNotification,
literustlib::packet::Property::ReliableOrdered,
&rlnl::events::ingame::CapturePointNotification {
notification: rlnl::types::CapturePointNotificationType::CaptureUnlocked,
id: point_i,
defending_team: point_team,
attacking_team: player_team,
},
true,
).await;
}
} else {
let old_enemies = point.on_point.read().await[&player_team_u8].fetch_sub(1, std::sync::atomic::Ordering::SeqCst);
@@ -289,34 +285,32 @@ impl PointTracker {
// something is out of sync, let's just ignore it and try to undo any underflow
log::warn!("Team {} players on point {} counting error", player_team, point_i);
point.on_point.read().await[&player_team_u8].store(0, std::sync::atomic::Ordering::SeqCst);
} else {
if old_enemies == 1 {
//log::info!("Enemy has left the capture point");
generic.broadcast(
rlnl::event_code::NetworkEvent::CapturePointNotification,
literustlib::packet::Property::ReliableOrdered,
&rlnl::events::ingame::CapturePointNotification {
notification: rlnl::types::CapturePointNotificationType::CaptureStoppedNoAttackers,
id: point_i,
defending_team: point_team,
attacking_team: player_team as i8,
},
true,
).await;
let progress_now = point.capture.load(std::sync::atomic::Ordering::SeqCst).floor();
point.capture.store(progress_now, std::sync::atomic::Ordering::SeqCst);
let data = rlnl::events::ingame::TeamBaseState {
base_team_or_mining_point_index: point_i,
current_progress: rlnl::types::ByteFloat::from(progress_now),
max_progress: rlnl::types::ByteFloat::from(max_progress),
};
generic.broadcast(
rlnl::event_code::NetworkEvent::CapturePointProgress,
literustlib::packet::Property::ReliableOrdered,
&data,
true
).await;
}
} else if old_enemies == 1 {
//log::info!("Enemy has left the capture point");
generic.broadcast(
rlnl::event_code::NetworkEvent::CapturePointNotification,
literustlib::packet::Property::ReliableOrdered,
&rlnl::events::ingame::CapturePointNotification {
notification: rlnl::types::CapturePointNotificationType::CaptureStoppedNoAttackers,
id: point_i,
defending_team: point_team,
attacking_team: player_team,
},
true,
).await;
let progress_now = point.capture.load(std::sync::atomic::Ordering::SeqCst).floor();
point.capture.store(progress_now, std::sync::atomic::Ordering::SeqCst);
let data = rlnl::events::ingame::TeamBaseState {
base_team_or_mining_point_index: point_i,
current_progress: rlnl::types::ByteFloat::from(progress_now),
max_progress: rlnl::types::ByteFloat::from(max_progress),
};
generic.broadcast(
rlnl::event_code::NetworkEvent::CapturePointProgress,
literustlib::packet::Property::ReliableOrdered,
&data,
true
).await;
}
}
}
@@ -364,7 +358,7 @@ impl PointTracker {
log::info!("Point {} was captured by team {} in game {}", i, new_team, generic.game_guid());
cap_point.capture.store(0.0, std::sync::atomic::Ordering::SeqCst);
cap_point.team.store(new_team, std::sync::atomic::Ordering::SeqCst);
if owned_points.get(&(new_team as u8)).map(|x| *x).unwrap_or(0) == 0 {
if owned_points.get(&(new_team as u8)).copied().unwrap_or(0) == 0 {
captured_firsts.insert(new_team as u8);
}
if point_owner >= 0 && *owned_points.get(&(point_owner as u8)).unwrap() == 1 {
@@ -738,7 +732,7 @@ impl CustomGameLogic for BattleArenaLogic {
property: literustlib::packet::Property::ReliableOrdered,
data: Box::new(rlnl::events::sync::GetCapturePoints {
points: [
generic.map_config.capture_points.get(0).map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)),
generic.map_config.capture_points.first().map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)),
generic.map_config.capture_points.get(1).map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)),
generic.map_config.capture_points.get(2).map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)),
]
@@ -758,7 +752,7 @@ impl CustomGameLogic for BattleArenaLogic {
}),
}),
// SetShieldState
if generic.map_config.bases.get(&0).is_some() {
if generic.map_config.bases.contains_key(&0) {
Some(crate::matches::RlnlPacket {
event: rlnl::event_code::NetworkEvent::SetShieldState,
property: literustlib::packet::Property::ReliableOrdered,
@@ -770,7 +764,7 @@ impl CustomGameLogic for BattleArenaLogic {
} else {
None
},
if generic.map_config.bases.get(&1).is_some() {
if generic.map_config.bases.contains_key(&1) {
Some(crate::matches::RlnlPacket {
event: rlnl::event_code::NetworkEvent::SetShieldState,
property: literustlib::packet::Property::ReliableOrdered,
@@ -852,7 +846,7 @@ impl CustomGameLogic for BattleArenaLogic {
health: 7,
}),
},*/
].into_iter().filter_map(|x| x).collect()
].into_iter().flatten().collect()
}
async fn on_countdown_start(&self, generic: &crate::matches::GenericGamemodeEngine<Self>, game_start: chrono::DateTime<chrono::Utc>) -> bool {

View File

@@ -332,7 +332,7 @@ impl BaseTracker {
}
fn teams(&self) -> std::collections::HashSet<u8> {
self.bases.keys().map(|x| *x).collect()
self.bases.keys().copied().collect()
}
}

View File

@@ -20,7 +20,7 @@ impl VehicleMotionHandler {
impl crate::RobotMotionHandler for VehicleMotionHandler {
async fn handle(&self, data: &bytes::Bytes, user: &crate::UserData) {
if let Some(user_info) = user.user().await {
let mut des = byteserde::des_slice::ByteDeserializerSlice::new(&data);
let mut des = byteserde::des_slice::ByteDeserializerSlice::new(data);
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 {