示例#1
0
        public void ProcessUNetMessage(byte[] rawPacket)
        {
            var unetBytes = UNetMessage.Deserialize(rawPacket);

            var reader = new NetworkReader(unetBytes);

            while (reader.Position < unetBytes.Length)
            {
                var msg = new NetworkMessage();
                msg.msgSeqNum = reader.ReadUInt32();
                var msgSize = reader.ReadUInt16();
                msg.msgType = reader.ReadInt16();
                var buffer = reader.ReadBytes(msgSize);
                msg.reader = new NetworkReader(buffer);

                var deserialized = Deserialize(msg, buffer);

                if (deserialized != null)
                {
                    if (_handlers.ContainsKey(deserialized.msgType))
                    {
                        if (deserialized.GetType() != typeof(AssetsLoadingProgress))
                        {
                            Log.Print(LogType.Game, $"{deserialized.GetType().Name} - {JsonConvert.SerializeObject(deserialized)}");
                        }
                        _handlers[deserialized.msgType].Invoke(deserialized);
                    }
                    else
                    {
                        Log.Print(LogType.Warning,
                                  $"Unhandled {msg.msgType}:{deserialized.GetType().Name} - {JsonConvert.SerializeObject(deserialized)}");
                    }
                }
            }
        }
示例#2
0
        public void ProcessUNetMessages(byte[] rawPacket)
        {
            var unetBytes = UNetMessage.Deserialize(rawPacket);

            var reader = new NetworkReader(unetBytes);

            while (reader.Position < unetBytes.Length)
            {
                var msg = new NetworkMessage();
                msg.msgSeqNum = reader.ReadUInt32();
                var msgSize = reader.ReadUInt16();
                msg.msgType = reader.ReadInt16();
                var buffer = reader.ReadBytes(msgSize);
                msg.reader = new NetworkReader(buffer);

                ProcessUnetMessage(msg);
            }
        }