C# Class SagaLib.Packet

Defines the base class of a network packet. Packets are send back and forth between the client and server. Different types of packets are used for different purposes. The general packet structure is: PACKET_SIZE (2 bytes), PACKET_ID (2 bytes), PACKET_DATA (x bytes). The id bytes are considered to be part of the data bytes. The size bytes are unencrypted, but the id bytes and all data following are encrypted.
Exibir arquivo Open project: Willyham/SagaRO2 Class Usage Examples

Public Properties

Property Type Description
data byte[]
doNotEncryptBuffer bool
isFullheader bool
isGateway bool
offset ushort
size ushort

Public Methods

Method Description
GetByte ( ) : byte

Get the byte at the current offset.

GetByte ( ushort index ) : byte

Get the byte at the given index.

GetBytes ( ushort count ) : byte[]

Get a certain amount of bytes from the current offset.

GetBytes ( ushort count, ushort index ) : byte[]

Get a set of bytes from a given location.

GetFloat ( ) : float

Get the float at the current offset.

GetFloat ( ushort index ) : float

Get the float at the given index.

GetInt ( ) : int

Get the int at the current offset.

GetInt ( ushort index ) : int

Get the int at the given index.

GetShort ( ) : short

Get the short at the current offset.

GetShort ( ushort index ) : short

Get the short at the given index.

GetString ( ) : string

Get the Unicode string at the current offset.

GetString ( ushort index ) : string

Get the Unicode string starting at index.

GetStringFixedSize ( ushort size ) : string

Get the Unicode string at the current offset.

GetStringFixedSize ( ushort index, ushort size ) : string

Get the Unicode string starting at index.

GetUInt ( ) : uint

Get the uint at the current offset.

GetUInt ( ushort index ) : uint

Get the uint at the given index.

GetUShort ( ) : ushort

Get the ushort at the current offset.

GetUShort ( ushort index ) : ushort

Get the ushort at the given index.

New ( ) : Packet

Create a new instance of this packet.

Packet ( ) : System

Create a new packet with no data bytes at all. The data array has to be initialized manually.

Packet ( byte data ) : System

Create a new packet with the given data bytes. The size and offset are set automatically.

Packet ( short length ) : System

Create a new packet with the given length. The data bytes are initialized to all zeroes.

Parse ( SagaLib.Client client ) : void

Parse this packet (only used for GetPackets)

PutByte ( byte b ) : void

Put the given byte at the current offset.

PutByte ( byte b, ushort index ) : void

Put the given byte at the given index.

PutBytes ( byte bdata ) : void

Put some given bytes at the current offset in the data array.

PutBytes ( byte bdata, ushort index ) : void

Put some given bytes at a given position in the data array.

PutFloat ( float s ) : void

Put the given float at the current offset in the data.

PutFloat ( float s, ushort index ) : void

Put the given float at the given index.

PutInt ( int s ) : void

Put the given int at the current offset in the data.

PutInt ( int s, ushort index ) : void

Put the given int at the given index.

PutShort ( short s ) : void

Put the given short at the current offset.

PutShort ( short s, ushort index ) : void

Put the given short at the given index.

PutStandardItem ( int id, uint u1, uint u2, string name, uint u3, byte clv, bool tradeable, ushort dura, byte stack, uint add1, uint add2, uint add3, byte itemindex, ushort index ) : void
PutString ( string s ) : void

Put a string a the current offset.

PutString ( string s, ushort index ) : void

Put a string at the given index of the data.

PutTradeItem ( int id, uint u1, uint u2, string name, uint u3, byte clv, bool tradeable, ushort dura, byte stack, uint add1, uint add2, uint add3, ushort index ) : void
PutUInt ( uint s ) : void

Put the given uint at the current offset.

PutUInt ( uint s, ushort index ) : void

Put the given uint at the given index.

PutUShort ( ushort s ) : void

Put the given ushort at the current offset.

PutUShort ( ushort s, ushort index ) : void

Put the given ushort at the given index.

SetLength ( ) : void

Write the data length to the first 2 bytes of the packet.

SizeIsOk ( ushort size ) : bool

Check to see if a given size is ok for a certain packet.

isStaticSize ( ) : bool

Method Details

GetByte() public method

Get the byte at the current offset.
public GetByte ( ) : byte
return byte

GetByte() public method

Get the byte at the given index.
public GetByte ( ushort index ) : byte
index ushort Index of the byte.
return byte

GetBytes() public method

Get a certain amount of bytes from the current offset.
public GetBytes ( ushort count ) : byte[]
count ushort Number of bytes to read.
return byte[]

GetBytes() public method

Get a set of bytes from a given location.
public GetBytes ( ushort count, ushort index ) : byte[]
count ushort Number of bytes to get.
index ushort Indec from where to get bytes.
return byte[]

GetFloat() public method

Get the float at the current offset.
public GetFloat ( ) : float
return float

GetFloat() public method

Get the float at the given index.
public GetFloat ( ushort index ) : float
index ushort Index of the float.
return float

GetInt() public method

Get the int at the current offset.
public GetInt ( ) : int
return int

GetInt() public method

Get the int at the given index.
public GetInt ( ushort index ) : int
index ushort Index of the int.
return int

GetShort() public method

Get the short at the current offset.
public GetShort ( ) : short
return short

GetShort() public method

Get the short at the given index.
public GetShort ( ushort index ) : short
index ushort Index of the short.
return short

GetString() public method

Get the Unicode string at the current offset.
public GetString ( ) : string
return string

GetString() public method

Get the Unicode string starting at index.
public GetString ( ushort index ) : string
index ushort Index of the string.
return string

GetStringFixedSize() public method

Get the Unicode string at the current offset.
public GetStringFixedSize ( ushort size ) : string
size ushort
return string

GetStringFixedSize() public method

Get the Unicode string starting at index.
public GetStringFixedSize ( ushort index, ushort size ) : string
index ushort Index of the string.
size ushort
return string

GetUInt() public method

Get the uint at the current offset.
public GetUInt ( ) : uint
return uint

GetUInt() public method

Get the uint at the given index.
public GetUInt ( ushort index ) : uint
index ushort Index of the uint.
return uint

GetUShort() public method

Get the ushort at the current offset.
public GetUShort ( ) : ushort
return ushort

GetUShort() public method

Get the ushort at the given index.
public GetUShort ( ushort index ) : ushort
index ushort Index of the ushort.
return ushort

New() public method

Create a new instance of this packet.
public New ( ) : Packet
return Packet

Packet() public method

Create a new packet with no data bytes at all. The data array has to be initialized manually.
public Packet ( ) : System
return System

Packet() public method

Create a new packet with the given data bytes. The size and offset are set automatically.
public Packet ( byte data ) : System
data byte The (unencrypted) data bytes
return System

Packet() public method

Create a new packet with the given length. The data bytes are initialized to all zeroes.
public Packet ( short length ) : System
length short Length of the data bytes.
return System

Parse() public method

Parse this packet (only used for GetPackets)
public Parse ( SagaLib.Client client ) : void
client SagaLib.Client
return void

PutByte() public method

Put the given byte at the current offset.
public PutByte ( byte b ) : void
b byte Byte to insert.
return void

PutByte() public method

Put the given byte at the given index.
public PutByte ( byte b, ushort index ) : void
b byte Byte to insert.
index ushort Index to insert at.
return void

PutBytes() public method

Put some given bytes at the current offset in the data array.
public PutBytes ( byte bdata ) : void
bdata byte bytes to add to the data array
return void

PutBytes() public method

Put some given bytes at a given position in the data array.
public PutBytes ( byte bdata, ushort index ) : void
bdata byte bytes to add to the data array
index ushort position to add the bytes to
return void

PutFloat() public method

Put the given float at the current offset in the data.
public PutFloat ( float s ) : void
s float Float to insert.
return void

PutFloat() public method

Put the given float at the given index.
public PutFloat ( float s, ushort index ) : void
s float Float to insert.
index ushort Index to insert at.
return void

PutInt() public method

Put the given int at the current offset in the data.
public PutInt ( int s ) : void
s int Int to insert.
return void

PutInt() public method

Put the given int at the given index.
public PutInt ( int s, ushort index ) : void
s int Int to insert.
index ushort Index to insert at.
return void

PutShort() public method

Put the given short at the current offset.
public PutShort ( short s ) : void
s short Short to insert.
return void

PutShort() public method

Put the given short at the given index.
public PutShort ( short s, ushort index ) : void
s short Short to insert.
index ushort Index to insert at.
return void

PutStandardItem() public method

public PutStandardItem ( int id, uint u1, uint u2, string name, uint u3, byte clv, bool tradeable, ushort dura, byte stack, uint add1, uint add2, uint add3, byte itemindex, ushort index ) : void
id int
u1 uint
u2 uint
name string
u3 uint
clv byte
tradeable bool
dura ushort
stack byte
add1 uint
add2 uint
add3 uint
itemindex byte
index ushort
return void

PutString() public method

Put a string a the current offset.
public PutString ( string s ) : void
s string String to insert.
return void

PutString() public method

Put a string at the given index of the data.
public PutString ( string s, ushort index ) : void
s string String to insert.
index ushort Index at which to insert.
return void

PutTradeItem() public method

public PutTradeItem ( int id, uint u1, uint u2, string name, uint u3, byte clv, bool tradeable, ushort dura, byte stack, uint add1, uint add2, uint add3, ushort index ) : void
id int
u1 uint
u2 uint
name string
u3 uint
clv byte
tradeable bool
dura ushort
stack byte
add1 uint
add2 uint
add3 uint
index ushort
return void

PutUInt() public method

Put the given uint at the current offset.
public PutUInt ( uint s ) : void
s uint uint to insert
return void

PutUInt() public method

Put the given uint at the given index.
public PutUInt ( uint s, ushort index ) : void
s uint uint to insert.
index ushort Index to insert at.
return void

PutUShort() public method

Put the given ushort at the current offset.
public PutUShort ( ushort s ) : void
s ushort
return void

PutUShort() public method

Put the given ushort at the given index.
public PutUShort ( ushort s, ushort index ) : void
s ushort Ushort to insert.
index ushort Index to insert at.
return void

SetLength() public method

Write the data length to the first 2 bytes of the packet.
public SetLength ( ) : void
return void

SizeIsOk() public method

Check to see if a given size is ok for a certain packet.
public SizeIsOk ( ushort size ) : bool
size ushort Size to compare with.
return bool

isStaticSize() public method

public isStaticSize ( ) : bool
return bool

Property Details

data public_oe property

The data bytes (note: these include the id bytes and the size bytes)
public byte[] data
return byte[]

doNotEncryptBuffer public_oe property

If true, the data byte array will be cloned before it gets encrypted. Set it to "true" if you want to send the packet multiple times.
public bool doNotEncryptBuffer
return bool

isFullheader public_oe property

public bool isFullheader
return bool

isGateway public_oe property

public bool isGateway
return bool

offset public_oe property

Our current offset in the data array. After creation this will be set to 4 (the first non ID data byte)
public ushort offset
return ushort

size public_oe property

The size of the packet is equal to the number of data bytes plus 2 bytes for the message id plus 2 bytes for the size.
public ushort size
return ushort