Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijan committed Jan 13, 2025
1 parent 397262c commit 0c86c7d
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 137 deletions.
9 changes: 3 additions & 6 deletions entities/src/dao/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,10 @@ impl item::Model {
/// 1. mineral id
/// 2. option 1
/// 3. option 2
#[allow(clippy::cast_possible_truncation)]
pub fn get_augmentation(&self) -> Option<(i32, i32, i32)> {
let Some(option_1) = self.variations.get("option_1").and_then(Value::as_i64) else {
return None;
};
let Some(option_2) = self.variations.get("option_2").and_then(Value::as_i64) else {
return None;
};
let option_1 = self.variations.get("option_1").and_then(Value::as_i64)?;
let option_2 = self.variations.get("option_2").and_then(Value::as_i64)?;
let mineral_id = self
.variations
.get("mineralId")
Expand Down
208 changes: 104 additions & 104 deletions game/src/data/classes/mapping.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions l2-core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub const PROTOCOL_REVISION: i32 = 0x0106;
#[must_use]
pub fn get_server_name_by_id(server_id: u8) -> Option<String> {
if (0..127).contains(&server_id) {
return Some(SERVER_NAMES[server_id as usize - 1].to_owned());
Expand Down
23 changes: 12 additions & 11 deletions l2-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
use std::time::Duration;
use argon2::{Argon2, PasswordHasher};
use crate::dto::Database as DBConfig;
use argon2::password_hash::SaltString;
use argon2::{Argon2, PasswordHasher};
use rand_core::OsRng;
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
use std::time::Duration;
use tokio::task::spawn_blocking;
use tracing::instrument;
use crate::dto::Database as DBConfig;

pub mod config;
pub mod constants;
pub mod crypt;
pub mod dto;
pub mod errors;
pub mod message_broker;
pub mod network;
pub mod shared_packets;
pub mod session;
pub mod shared_packets;
pub mod str;
pub mod tests;
pub mod traits;
pub mod config;
pub mod crypt;
pub mod message_broker;

#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn hash_password(password: &str) -> anyhow::Result<String> {
let pwd = password.to_owned();
spawn_blocking(move || {
Expand All @@ -29,11 +30,11 @@ pub async fn hash_password(password: &str) -> anyhow::Result<String> {
// might take a second of CPU time
argon2
.hash_password(pwd.as_bytes(), &salt)
.unwrap()
.expect("Unable to hash password")
.to_string()
})
.await
.map_err(Into::into)
.await
.map_err(Into::into)
}

#[instrument]
Expand All @@ -49,4 +50,4 @@ pub async fn new_db_pool(db_config: &DBConfig) -> DatabaseConnection {
Database::connect(opt)
.await
.expect("Failed to connect to the database")
}
}
2 changes: 1 addition & 1 deletion l2-core/src/message_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where

broker.inbox.retain(|_, req| {
now.duration_since(req.sent_at)
.map_or(false, |elapsed| elapsed <= broker.timeout)
.is_ok_and(|elapsed| elapsed <= broker.timeout)
});
// send packet later, now we only remember it
let Some(req_body) = request.body.take() else {
Expand Down
1 change: 1 addition & 0 deletions l2-core/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anyhow::Context;
use std::net::ToSocketAddrs;
use tokio::net::{TcpListener, TcpSocket};

#[allow(clippy::missing_errors_doc)]
pub fn bind_addr(config: &InboundConnection) -> anyhow::Result<TcpListener> {
let addr = format!("{}:{}", &config.ip, &config.port)
.to_socket_addrs()
Expand Down
4 changes: 3 additions & 1 deletion l2-core/src/shared_packets/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait SendablePacket: Debug + Send + Sync {
}

pub trait ReadablePacket: Debug + Send + Sync {
const PACKET_ID:u8;
const PACKET_ID:u8;
fn read(data: &[u8]) -> Option<Self>
where
Self: Sized + ReadablePacket;
Expand Down Expand Up @@ -65,6 +65,7 @@ pub struct ServerData {
}

impl ServerData {
#[must_use]
pub fn get_ip_octets(&self) -> [u8; 4] {
self.ip.octets()
}
Expand Down Expand Up @@ -121,6 +122,7 @@ pub enum GSLoginFailReasons {
}

impl GSLoginFailReasons {
#[allow(clippy::missing_errors_doc)]
pub fn from_u8(reason: u8) -> anyhow::Result<Self> {
match reason {
0x00 => Ok(Self::None),
Expand Down
4 changes: 3 additions & 1 deletion l2-core/src/shared_packets/gs_2_ls/blowfish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct BlowFish {
pub encrypted_key: Vec<u8>,
}
impl BlowFish {
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn new(encrypted_key: Vec<u8>) -> Self {
let mut inst = Self {
buffer: SendablePacketBuffer::new(),
Expand All @@ -17,7 +19,7 @@ impl BlowFish {
.expect("Failed to write bytes while building blowfish packet.");
inst
}

#[allow(clippy::cast_possible_truncation)]
fn write_all(&mut self) -> Result<(), anyhow::Error> {
self.buffer.write(0x00)?;
Expand Down
2 changes: 2 additions & 0 deletions l2-core/src/shared_packets/gs_2_ls/gs_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ impl GSStatusUpdate {
const MAX_PLAYERS: i32 = 0x04;
const TEST_SERVER: i32 = 0x05;
const SERVER_AGE: i32 = 0x06;

#[allow(clippy::missing_errors_doc)]
pub fn new(cfg: &GSServer) -> anyhow::Result<Self> {
let mut inst = Self {
buffer: SendablePacketBuffer::new(),
Expand Down
3 changes: 2 additions & 1 deletion l2-core/src/shared_packets/gs_2_ls/reply_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub struct ReplyChars {
}

impl ReplyChars {
#[allow(clippy::cast_possible_truncation)]
#[must_use]
#[allow(clippy::cast_possible_truncation, clippy::missing_panics_doc)]
pub fn new(account_name: String, chars: &[character::Model]) -> ReplyChars {
let mut chars_to_del_list = vec![];
for ch in chars {
Expand Down
1 change: 1 addition & 0 deletions l2-core/src/shared_packets/ls_2_gs/init_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct InitLS {
}

impl InitLS {
#[must_use]
pub fn new(public_key: Vec<u8>) -> Self {
let mut init_ls = InitLS {
buffer: SendablePacketBuffer::new(),
Expand Down
1 change: 1 addition & 0 deletions l2-core/src/shared_packets/ls_2_gs/kick_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct KickPlayer {
}

impl KickPlayer {
#[must_use]
pub fn new(account_name: &str) -> Self {
let mut pack = Self {
buffer: SendablePacketBuffer::new(),
Expand Down
1 change: 1 addition & 0 deletions l2-core/src/shared_packets/ls_2_gs/request_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct RequestChars {
}

impl RequestChars {
#[must_use]
pub fn new(account_name: &str) -> RequestChars {
let mut gg = RequestChars {
buffer: SendablePacketBuffer::new(),
Expand Down
11 changes: 7 additions & 4 deletions l2-core/src/shared_packets/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub struct ReadablePacketBuffer {

#[allow(unused)]
impl ReadablePacketBuffer {

#[must_use]
pub fn new(bytes: Vec<u8>) -> Self {
ReadablePacketBuffer { bytes, position: 0 }
Expand Down Expand Up @@ -41,12 +40,14 @@ impl ReadablePacketBuffer {
hosts
}

#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_sign_loss, clippy::missing_panics_doc)]
pub fn read_sized_string(&mut self) -> String {
let length = self.read_i16() as usize;
let bytes = self.read_bytes(length * 2);
// safe to use unwrap, because decoder is "Replace", error here unreachable
UTF_16LE.decode(&bytes, DecoderTrap::Replace).unwrap()
UTF_16LE
.decode(&bytes, DecoderTrap::Replace)
.expect("Can not decode string from bytes")
}
pub fn read_bytes(&mut self, length: usize) -> Vec<u8> {
let result = &self.bytes[self.position..self.position + length];
Expand Down Expand Up @@ -82,7 +83,7 @@ impl ReadablePacketBuffer {
self.position += 4;
int
}

pub fn read_u32(&mut self) -> u32 {
let int = u32::from_le_bytes([
self.bytes[self.position],
Expand Down Expand Up @@ -117,10 +118,12 @@ impl ReadablePacketBuffer {
f64::from_bits(self.read_i64() as u64)
}

#[must_use]
pub fn get_remaining_length(&self) -> usize {
self.bytes.len() - self.position
}

#[must_use]
pub fn get_length(&self) -> usize {
self.bytes.len()
}
Expand Down
4 changes: 2 additions & 2 deletions login/src/client_thread/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct Client {

/// # This function called each time when there is a new connection.
/// ## Arguments
/// - stream - `TcpStream` to send/receive shared_packets
/// - stream - `TcpStream` to send/receive `shared_packets`
/// - lc - `LoginClient` object is needed to store some client related data
///
/// # The whole login process looks like the following:
Expand Down Expand Up @@ -166,7 +166,7 @@ impl PacketHandler for Client {
Ok(())
}


}

#[async_trait]
Expand Down
2 changes: 1 addition & 1 deletion login/src/gs_thread/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct GameServer {
///
/// `tcp_reader` and `tcp_writer` are wrapped into Arc<Mutex> because we need to share the handler
/// across two tokio threads:
/// 1. Main thread to accept and answer shared_packets
/// 1. Main thread to accept and answer `shared_packets`
/// 2. Listen for messages from Client login thread if we need info about logging in Player
tcp_reader: Arc<Mutex<OwnedReadHalf>>,
tcp_writer: Arc<Mutex<OwnedWriteHalf>>,
Expand Down
11 changes: 6 additions & 5 deletions migration/src/m20250103_134559_create_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm::JsonValue;
use crate::m20241213_210106_create_char::Character;
use sea_orm::JsonValue;
use sea_orm_migration::prelude::*;
use sea_orm_migration::schema::{big_unsigned, decimal_len, integer, json_binary, pk_auto, string};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -15,7 +16,7 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(pk_auto(Item::Id))
.col(integer(Item::Owner))
.col(integer(Item::ItemId))
.col(integer(Item::TypeId))
.col(big_unsigned(Item::Count).default(0))
.col(integer(Item::EnchantLevel).default(0))
.col(string(Item::Loc))
Expand Down Expand Up @@ -69,7 +70,7 @@ pub enum Item {
Table,
Id,
Owner,
ItemId,
TypeId, //item_id
Count,
EnchantLevel,
Loc,
Expand All @@ -80,5 +81,5 @@ pub enum Item {
ManaLeft,
Time,
Variables,
Variations
Variations,
}

0 comments on commit 0c86c7d

Please sign in to comment.