|
|
@ -11,6 +11,7 @@ using Empty = Google.Protobuf.WellKnownTypes.Empty; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
|
|
|
|
|
|
public class Client : MonoBehaviour { |
|
|
public class Client : MonoBehaviour { |
|
|
|
|
|
public static DateTime UnixEpoch() => new DateTime(1970, 1, 1, 0, 0, 0, 0); |
|
|
private static ConnectionImpl reference; |
|
|
private static ConnectionImpl reference; |
|
|
|
|
|
|
|
|
public static void Connect(string name, string address = "127.0.0.1:50052") { |
|
|
public static void Connect(string name, string address = "127.0.0.1:50052") { |
|
|
@ -41,6 +42,21 @@ public class Client : MonoBehaviour { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class Card { |
|
|
|
|
|
public DateTime timestamp; |
|
|
|
|
|
public string card; |
|
|
|
|
|
|
|
|
|
|
|
public Card(string card, DateTime lastUpdated) { |
|
|
|
|
|
this.card = card; |
|
|
|
|
|
this.timestamp = lastUpdated > UnixEpoch() ? lastUpdated : UnixEpoch(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Card(string card) { |
|
|
|
|
|
this.card = card; |
|
|
|
|
|
this.timestamp = UnixEpoch(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public class NetEventManager { |
|
|
public class NetEventManager { |
|
|
private Dictionary<string, Action<Common.Name>> returnNameHandlers = new Dictionary<string, Action<Common.Name>>(); |
|
|
private Dictionary<string, Action<Common.Name>> returnNameHandlers = new Dictionary<string, Action<Common.Name>>(); |
|
|
private Dictionary<string, Action<Connection.UserID>> returnConnectHandlers = new Dictionary<string, Action<Connection.UserID>>(); |
|
|
private Dictionary<string, Action<Connection.UserID>> returnConnectHandlers = new Dictionary<string, Action<Connection.UserID>>(); |
|
|
@ -134,13 +150,15 @@ public class Client : MonoBehaviour { |
|
|
this.currentImagesPacketLength = (int)p.ReturnCardsImages.Setup.Number; |
|
|
this.currentImagesPacketLength = (int)p.ReturnCardsImages.Setup.Number; |
|
|
this.currentImagesPacketIndex = 0; |
|
|
this.currentImagesPacketIndex = 0; |
|
|
this.currentImages = new MemoryStream(); |
|
|
this.currentImages = new MemoryStream(); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
if (p.ReturnCardsImages.DataPacket.Id != this.currentImagesPacketIndex) |
|
|
if (p.ReturnCardsImages.DataPacket.Id != this.currentImagesPacketIndex) |
|
|
throw new Exception("images packet id doesn't match expected"); |
|
|
throw new Exception("images packet id doesn't match expected"); |
|
|
this.currentImages.Write(p.ReturnCardsImages.DataPacket.Data.ToArray(), 0, p.ReturnCardsImages.DataPacket.Data.Length); |
|
|
this.currentImages.Write(p.ReturnCardsImages.DataPacket.Data.Span.ToArray(), 0, p.ReturnCardsImages.DataPacket.Data.Span.Length); |
|
|
|
|
|
Debug.Log(this.currentImages.ToArray()[0] + ":" + p.ReturnCardsImages.DataPacket.Data.Span.ToArray()[0]); |
|
|
this.currentImagesPacketIndex++; |
|
|
this.currentImagesPacketIndex++; |
|
|
if (this.currentImagesPacketIndex == this.currentImagesPacketLength) { |
|
|
if (this.currentImagesPacketIndex == this.currentImagesPacketLength) { |
|
|
|
|
|
// Debug.Log("Images tar length: " + this.currentImages.Length);
|
|
|
|
|
|
this.currentImages.Seek(0, SeekOrigin.Begin); |
|
|
Images i = new Images(this.currentImages); |
|
|
Images i = new Images(this.currentImages); |
|
|
this.currentImagesPacketIndex = 0; |
|
|
this.currentImagesPacketIndex = 0; |
|
|
var v = new Action<Images>[this.returnCardImagesHandlers.Count]; |
|
|
var v = new Action<Images>[this.returnCardImagesHandlers.Count]; |
|
|
@ -374,9 +392,9 @@ public class Client : MonoBehaviour { |
|
|
conn.SendMessage(new Protocol.ClientServerPacket() { QueryCardImage = new Game.CardKind { Kind = cardKind } }); |
|
|
conn.SendMessage(new Protocol.ClientServerPacket() { QueryCardImage = new Game.CardKind { Kind = cardKind } }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void GetCardImages(string cardKind) { |
|
|
public void GetCardImages(Card[] cards) { |
|
|
Game.Cards c = new Game.Cards(); |
|
|
Game.Cards c = new Game.Cards(); |
|
|
c.Cards_.Append(new Game.Cards.Types.Card { Kind = cardKind, Time = new Google.Protobuf.WellKnownTypes.Timestamp { Seconds = 0, Nanos = 0 } }); |
|
|
c.Cards_.Add(cards.Select(c => new Game.Cards.Types.Card() { Kind = c.card, Time = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(c.timestamp.ToUniversalTime()) })); |
|
|
conn.SendMessage(new Protocol.ClientServerPacket() { QueryCardImages = c }); |
|
|
conn.SendMessage(new Protocol.ClientServerPacket() { QueryCardImages = c }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|