Skip to content

outgoing packet

mtanksl edited this page Apr 17, 2023 · 1 revision

Introduction

Packets are the primary unity. Incoming packets wrap the intent of the client and Outgoing packets wrap all the information of a server change that the client needs to receive in order to keep in sync.

Example

Tibia's protocol uses byte 0x83 to show a magic effect. You must specify the position and the magic effect type.

public class ShowMagicEffectOutgoingPacket : IOutgoingPacket
{
    public ShowMagicEffectOutgoingPacket(Position position, MagicEffectType magicEffectType)
    {
        this.Position = position;

        this.MagicEffectType = magicEffectType;
    }

    public Position Position { get; set; }

    public MagicEffectType MagicEffectType { get; set; }
        
    public void Write(ByteArrayStreamWriter writer)
    {
        writer.Write( (byte)0x83 );

        writer.Write(Position.X);

        writer.Write(Position.Y);

        writer.Write(Position.Z);

        writer.Write( (byte)MagicEffectType );
    }
}