Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ jobs:
uses: actions/checkout@v4

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@nightly
with:
profile: minimal
toolchain: nightly
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2
Expand All @@ -59,13 +57,11 @@ jobs:
run: bash ./scripts/fetch-test-fixtures.bash

- name: Run cargo build
uses: actions-rs/cargo@v1
env:
DATABASE_URL: file::memory:?cache=shared
with:
command: build
run: cargo build

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
env:
DATABASE_URL: file::memory:?cache=shared
run: cargo test
14 changes: 3 additions & 11 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ jobs:
uses: actions/checkout@v4

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@nightly
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Rust Cache
Expand All @@ -41,15 +39,9 @@ jobs:
uses: rui314/setup-mold@v1

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
run: cargo fmt --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
env:
SQLX_OFFLINE: true
with:
command: clippy
args: -- -D warnings
run: cargo clippy -- -D warnings
4 changes: 2 additions & 2 deletions crates/crypto/src/cq_cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl super::Cipher for CQCipher {
(0..data.len()).for_each(|i| {
data[i] ^= key1[((x >> 8) + 0x100) as usize];
data[i] ^= key1[(x & 0xff) as usize];
data[i] = data[i] >> 4 | data[i] << 4;
data[i] = data[i].rotate_left(4);
data[i] ^= 0xAB;
x = x.wrapping_add(1);
});
Expand All @@ -143,7 +143,7 @@ impl super::Cipher for CQCipher {
data[i] ^= key2[(x & 0xff) as usize];
},
}
data[i] = data[i] >> 4 | data[i] << 4;
data[i] = data[i].rotate_left(4);
data[i] ^= 0xAB;
x = x.wrapping_add(1);
});
Expand Down
6 changes: 3 additions & 3 deletions crates/crypto/src/rc5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl crate::Cipher for TQRC5 {
fn decrypt(&self, data: &mut [u8]) {
// Pad the buffer
let mut src_len = data.len() / 8;
if data.len() % 8 > 0 {
if !data.len().is_multiple_of(8) {
src_len += 1;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ impl crate::Cipher for TQRC5 {

fn encrypt(&self, data: &mut [u8]) {
let mut src_len = data.len() / 8;
if data.len() % 8 > 0 {
if !data.len().is_multiple_of(8) {
src_len += 1;
}

Expand Down Expand Up @@ -220,6 +220,6 @@ mod tests {
let original = buf;
rc5.encrypt(&mut buf);
rc5.decrypt(&mut buf);
assert_eq!(buf, origional);
assert_eq!(buf, original);
}
}
2 changes: 1 addition & 1 deletion crates/crypto/src/tq_cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl TQCipher {
let mut x = counter.fetch_add(src.len() as u16, Ordering::SeqCst);
(0..src.len()).for_each(|i| {
src[i] ^= 0xAB;
src[i] = src[i] >> 4 | src[i] << 4;
src[i] = src[i].rotate_left(4);
src[i] ^= key[(x & 0xff) as usize];
src[i] ^= key[((x >> 8) + 0x100) as usize];
x = x.wrapping_add(1);
Expand Down
2 changes: 1 addition & 1 deletion crates/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl PacketEncode for (u16, Bytes) {
}
}

impl<'a> PacketEncode for (u16, &'a [u8]) {
impl PacketEncode for (u16, &[u8]) {
type Error = Error;
type Packet = ();

Expand Down
4 changes: 2 additions & 2 deletions crates/serde/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
T: Deserialize<'a>,
{
let mut deserializer = Deserializer::from_bytes(s);
T::deserialize(&mut deserializer).map_err(Into::into)
T::deserialize(&mut deserializer)
}

macro_rules! impl_nums {
Expand All @@ -86,7 +86,7 @@ macro_rules! impl_nums {
};
}

impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
impl<'de> de::Deserializer<'de> for &mut Deserializer<'de> {
type Error = TQSerdeError;

impl_nums!(u8, deserialize_u8, visit_u8, read_u8);
Expand Down
17 changes: 7 additions & 10 deletions crates/serde/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Serializer {
output: BytesMut,
}

impl<'a> ser::Serializer for &'a mut Serializer {
impl ser::Serializer for &mut Serializer {
type Error = TQSerdeError;
type Ok = ();
type SerializeMap = ser::Impossible<(), Self::Error>;
Expand Down Expand Up @@ -127,16 +127,13 @@ impl<'a> ser::Serializer for &'a mut Serializer {
value.serialize(self)
}

fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T: Serialize + ?Sized>(
self,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
_value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
{
) -> Result<Self::Ok, Self::Error> {
Ok(())
}

Expand Down Expand Up @@ -185,7 +182,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
}
}

impl<'a> ser::SerializeSeq for &'a mut Serializer {
impl ser::SerializeSeq for &mut Serializer {
type Error = TQSerdeError;
type Ok = ();

Expand All @@ -198,7 +195,7 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
}
}

impl<'a> ser::SerializeTuple for &'a mut Serializer {
impl ser::SerializeTuple for &mut Serializer {
type Error = TQSerdeError;
type Ok = ();

Expand All @@ -211,7 +208,7 @@ impl<'a> ser::SerializeTuple for &'a mut Serializer {
}
}

impl<'a> ser::SerializeStruct for &'a mut Serializer {
impl ser::SerializeStruct for &mut Serializer {
type Error = TQSerdeError;
type Ok = ();

Expand All @@ -224,7 +221,7 @@ impl<'a> ser::SerializeStruct for &'a mut Serializer {
}
}

impl<'a> ser::SerializeStructVariant for &'a mut Serializer {
impl ser::SerializeStructVariant for &mut Serializer {
type Error = TQSerdeError;
type Ok = ();

Expand Down
1 change: 1 addition & 0 deletions server/auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ mod tests {
let msg_account = Module::from_file(&engine, msg_account::WASM_BINARY.unwrap()).unwrap();

std::env::set_var("DATABASE_URL", "sqlite::memory:");
std::env::set_var("DATA_LOCATION", ".");
let state = State::init().await.unwrap();

// Run database migrations
Expand Down
2 changes: 1 addition & 1 deletion server/game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bytes.workspace = true
tq-network = { workspace = true, features = ["std"] }
tq-serde = { workspace = true, features = ["std"] }
tq-math.workspace = true
tq-db.workspace = true
tq-db = { workspace = true, features = ["sqlx"] }
tq-server.workspace = true
primitives.workspace = true
async-trait.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions server/game/src/packets/msg_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::{SystemTime, UNIX_EPOCH};

use crate::state::State;
use crate::{ActorState, Error};
use chrono::{Datelike, NaiveDateTime, Timelike};
use chrono::{Datelike, Timelike};
use num_enum::{FromPrimitive, IntoPrimitive};
use serde::{Deserialize, Serialize};
use tq_network::{Actor, PacketID, PacketProcess};
Expand Down Expand Up @@ -37,8 +37,7 @@ impl MsgData {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time before Unix epoch");
let naive = NaiveDateTime::from_timestamp_opt(now.as_secs() as i64, now.subsec_nanos()).unwrap();
let now = chrono::TimeZone::from_utc_datetime(&chrono::Utc, &naive);
let now = chrono::DateTime::<chrono::Utc>::from_timestamp(now.as_secs() as i64, now.subsec_nanos()).unwrap();
Self {
action: DataAction::SetServerTime.into(),
year: now.year() - 1900,
Expand Down
22 changes: 20 additions & 2 deletions server/game/src/systems/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,26 @@ impl Floor {
trace!("we didn't found the map at {}", map_path.display());
let mut p = self.path.clone();
p.set_extension("DMap");
let orignal_path = data_path.join("GameMaps").join("map").join(p);
self.convert_and_load(orignal_path).await?;
let maps_dir = data_path.join("GameMaps").join("map");
let original_path = maps_dir.join(&p);
let original_path = if let Ok(true) = original_path.try_exists() {
original_path
} else {
let mut fallback = None;
let mut entries = tokio::fs::read_dir(&maps_dir).await?;
while let Some(entry) = entries.next_entry().await? {
if entry
.file_name()
.to_string_lossy()
.eq_ignore_ascii_case(&p.to_string_lossy())
{
fallback = Some(entry.path());
break;
}
}
fallback.unwrap_or(original_path)
};
self.convert_and_load(original_path).await?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion server/game/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
.pretty()
.with_target(true)
.with_test_writer();
tracing_subscriber::registry().with(env_filter).with(logger).init();
let _ = tracing_subscriber::registry().with(env_filter).with(logger).try_init();

let pool = SqlitePoolOptions::new()
.max_connections(42)
Expand Down
7 changes: 6 additions & 1 deletion server/game/src/world/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,12 @@ mod tests {
async move {
let test_map_id = Maps::Arena;
let map = state.try_map(test_map_id.into())?;
map.load().await?;
if let Err(err) = map.load().await {
if matches!(&err, Error::IO(e) if e.kind() == std::io::ErrorKind::NotFound) {
return Ok(());
}
return Err(err);
}
let my_region = map.region(50, 50);
assert!(my_region.is_some(), "Can't find a region on (50, 50)");
let my_region = map.region(67, 50);
Expand Down
Loading