/// <summary> /// deserialize from the message /// </summary> /// <param name="message"></param> public void OnDeserialize(Lidgren.Network.NetIncomingMessage message) { var size = message.ReadInt32(); dictionary = new Dictionary <T, U>(size); for (int i = 0; i < size; ++i) { var key = message.Read <T>(); var value = message.Read <U>(); dictionary[key] = value; } }
// TODO: consider outputting a NetIncomingMessage instead of byte[] private (bool Success, byte[]? Hail, int HailLength) ValidateHandshakeData(int offset, int payloadLength) { // create temporary incoming message NetIncomingMessage msg = Peer.SetupReadHelperMessage(offset, payloadLength); try { string remoteAppIdentifier = msg.ReadString(); long remoteUniqueIdentifier = msg.ReadInt64(); InitializeRemoteTimeOffset(msg.ReadTimeSpan()); byte[]? hail = null; int hailLength = payloadLength - (msg.BytePosition - offset); if (hailLength > 0) { hail = msg.StoragePool.Rent(hailLength); msg.Read(hail.AsSpan(0, hailLength)); } if (remoteAppIdentifier != Peer.Configuration.AppIdentifier) { ExecuteDisconnect(NetMessageType.WrongAppIdentifier); return(false, hail, hailLength); } RemoteUniqueIdentifier = remoteUniqueIdentifier; return(true, hail, hailLength); } catch (Exception ex) { // whatever; we failed ExecuteDisconnect(NetMessageType.InvalidHandshake); Peer.LogWarning(new NetLogMessage(NetLogCode.InvalidHandshake, ex)); return(false, null, 0); } }