From 7d240e319b6dd29e50d5ea16155d247caf29ca0e Mon Sep 17 00:00:00 2001 From: ThePerkinrex Date: Wed, 3 Nov 2021 11:49:02 +0100 Subject: [PATCH] Fixed EpochTime lexicographical ordering --- server/src/server/game.rs | 23 +++++++++++++++++++++-- server/src/server/time.rs | 11 +++++++++-- unity/Assets/Scripts/Client.cs | 4 ++++ unity/Assets/Scripts/GameLoader.cs | 1 + 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/server/src/server/game.rs b/server/src/server/game.rs index 20f3c4b..bcea1ae 100644 --- a/server/src/server/game.rs +++ b/server/src/server/game.rs @@ -223,11 +223,20 @@ pub(super) async fn get_cards_images( .and_then(|x| { p.as_ref() .metadata() - .and_then(|x| x.modified()) + .map_err(|e| { + log::error!("MetadataError: {}", e); + e + }) + .and_then(|x| { + x.modified().map_err(|e| { + log::error!("ModifiedError: {}", e); + e + }) + }) .ok() .map(|y| (y.into(), x.into())) }) - .map_or(false, |(x, y): (EpochTime, EpochTime)| x > y) + .map_or(true, |(x, y): (EpochTime, EpochTime)| x > y) } if is_newer(&card_kind, &face) { @@ -261,8 +270,18 @@ pub(super) async fn get_cards_images( .unwrap(); } } + // log::info!( + // "Loading {} (face: {}, back: {})", + // card_kind.kind, + // is_newer(&card_kind, &face), + // is_newer(&card_kind, &back) + // ) } let mut b = Bytes::from(ar.into_inner().unwrap().finish().into_result().unwrap()); + log::info!( + "Compressed tar size: {}", + crate::allocator::as_string(b.len()) + ); let n = (b.len() / MESSAGE_SIZE) + if b.len() % MESSAGE_SIZE == 0 { 0 } else { 1 }; socket_mgr .write( diff --git a/server/src/server/time.rs b/server/src/server/time.rs index a924826..c945c88 100644 --- a/server/src/server/time.rs +++ b/server/src/server/time.rs @@ -18,10 +18,17 @@ impl From for EpochTime { impl PartialOrd for EpochTime { fn partial_cmp(&self, other: &Self) -> Option { + // log::debug!("{:?} > {:?} = {:?}, {:?}", self, other, self.0.seconds.partial_cmp(&other.0.seconds), self.0.nanos.partial_cmp(&other.0.nanos)); if other.0.seconds == self.0.seconds { - self.0.seconds.partial_cmp(&other.0.seconds) - } else { self.0.nanos.partial_cmp(&other.0.nanos) + } else { + self.0.seconds.partial_cmp(&other.0.seconds) } } } + +impl std::fmt::Debug for EpochTime { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}+{}", self.0.seconds, self.0.nanos) + } +} diff --git a/unity/Assets/Scripts/Client.cs b/unity/Assets/Scripts/Client.cs index 372cb6b..0aba59c 100644 --- a/unity/Assets/Scripts/Client.cs +++ b/unity/Assets/Scripts/Client.cs @@ -150,6 +150,7 @@ public class Client : MonoBehaviour { this.currentImagesPacketLength = (int)p.ReturnCardsImages.Setup.Number; this.currentImagesPacketIndex = 0; this.currentImages = new MemoryStream(); + // Debug.Log("Setup received"); } else { if (p.ReturnCardsImages.DataPacket.Id != this.currentImagesPacketIndex) throw new Exception("images packet id doesn't match expected"); @@ -157,9 +158,12 @@ public class Client : MonoBehaviour { Debug.Log(this.currentImages.ToArray()[0] + ":" + p.ReturnCardsImages.DataPacket.Data.Span.ToArray()[0]); this.currentImagesPacketIndex++; if (this.currentImagesPacketIndex == this.currentImagesPacketLength) { + // Debug.Log("Last packet received"); // Debug.Log("Images tar length: " + this.currentImages.Length); this.currentImages.Seek(0, SeekOrigin.Begin); + // Debug.Log("Starting decoding"); Images i = new Images(this.currentImages); + // Debug.Log("Finished decoding"); this.currentImagesPacketIndex = 0; var v = new Action[this.returnCardImagesHandlers.Count]; this.returnCardImagesHandlers.Values.CopyTo(v, 0); diff --git a/unity/Assets/Scripts/GameLoader.cs b/unity/Assets/Scripts/GameLoader.cs index 20425c6..649ded0 100644 --- a/unity/Assets/Scripts/GameLoader.cs +++ b/unity/Assets/Scripts/GameLoader.cs @@ -169,6 +169,7 @@ public class GameLoader : MonoBehaviour { // }); // conn.GetCardImage(card.Kind.Kind); cards.Add(new Client.Card(card.Kind.Kind)); + // Debug.Log(card.Kind.Kind); } } }