Example #1
0
        public void Write(PacketLogEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            if (!Servers.ContainsKey(entry.ServerId))
            {
                throw new ArgumentException("Invalid server ID.", nameof(entry));
            }

            if (!Messages.Game.OpCodeToName.ContainsKey(entry.OpCode))
            {
                throw new ArgumentException("Invalid opcode.", nameof(entry));
            }

            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            _writer.WriteInt64(new DateTimeOffset(entry.Timestamp).ToUnixTimeMilliseconds());
            _writer.WriteInt32(entry.ServerId);
            _writer.WriteByte((byte)entry.Direction);
            _writer.WriteUInt16(entry.OpCode);
            _writer.WriteUInt16((ushort)entry.Payload.Count);
            _writer.WriteBytes(entry.Payload.ToArray());
        }
Example #2
0
        static void SerializePrimitive(TeraBinaryWriter writer, object value)
        {
            var type = value.GetType();

            if (type.IsEnum)
            {
                type = type.GetEnumUnderlyingType();
            }

            if (type == typeof(bool))
            {
                writer.WriteBoolean((bool)value);
            }
            else if (type == typeof(byte))
            {
                writer.WriteByte((byte)value);
            }
            else if (type == typeof(sbyte))
            {
                writer.WriteSByte((sbyte)value);
            }
            else if (type == typeof(ushort))
            {
                writer.WriteUInt16((ushort)value);
            }
            else if (type == typeof(short))
            {
                writer.WriteInt16((short)value);
            }
            else if (type == typeof(uint))
            {
                writer.WriteUInt32((uint)value);
            }
            else if (type == typeof(int))
            {
                writer.WriteInt32((int)value);
            }
            else if (type == typeof(ulong))
            {
                writer.WriteUInt64((ulong)value);
            }
            else if (type == typeof(long))
            {
                writer.WriteInt64((long)value);
            }
            else if (type == typeof(float))
            {
                writer.WriteSingle((float)value);
            }
            else if (type == typeof(Vector3))
            {
                writer.WriteVector3((Vector3)value);
            }
            else if (type == typeof(EntityId))
            {
                writer.WriteEntityId((EntityId)value);
            }
            else if (type == typeof(SkillId))
            {
                writer.WriteSkillId((SkillId)value);
            }
            else if (type == typeof(Angle))
            {
                writer.WriteAngle((Angle)value);
            }
            else
            {
                throw Assert.Unreachable();
            }
        }