Skip to content

class Packet (server-side)

Available since version: 0.0.3

This class represents data packet that gets send over the network.

Properties

int bitsUsed

Available since version: 0.3.0

Represents the total number of bits used by the script packet data.


int bytesUsed

Available since version: 0.3.0

Represents the total number of bytes used by the script packet data.


Methods

reset

This method will clear the packet data, making it empty.

void reset()

send

This method will send the packet data to the specified player.

void send(int playerid, int Reliability)

Parameters:

  • int playerid: the id of the player to whom you want to send the packet.
  • int Reliability: the reliability type, for more information see Reliability constants.

sendToAll

This method will send the packet data to all of the connected players.

void sendToAll(int Reliability)

Parameters:


writeBool

This method will append boolean value to the packet. (1 bit)

void writeBool(bool value)

Parameters:

  • bool value: the boolean value.

writeInt8

Available since version: 0.1.0

This method will append signed int8 value to the packet. (1 byte)

void writeInt8(int value)

Parameters:

  • int value: the number value in range -128 to 127.

writeUInt8

Available since version: 0.1.0

This method will append unsigned int8 value to the packet. (1 byte)

void writeUInt8(int value)

Parameters:

  • int value: the number value in range 0 to 255.

writeInt16

This method will append signed int16 value to the packet. (2 bytes)

void writeInt16(int value)

Parameters:

  • int value: the number value in range -32768 to 32767.

writeUInt16

Available since version: 0.1.0

This method will append unsigned int16 value to the packet. (2 bytes)

void writeUInt16(int value)

Parameters:

  • int value: the number value in range 0 to 65535.

writeInt32

This method will append signed int32 value to the packet. (4 bytes)

void writeInt32(int value)

Parameters:

  • int value: the number value in range -2147483648 to 2147483647.

writeUInt32

Available since version: 0.1.0

Note

By default squirrel uses int32 values, which means that this method behaves exactly the same as writeInt32 in scripts.

This method will append unsigned int32 value to the packet. (4 bytes)

void writeUInt32(int value)

Parameters:

  • int value: the number value in range 0 to 4294967295.

writeFloat

This method will append float value to the packet. (4 bytes)

void writeFloat(float value)

Parameters:

  • float value: the number value.

writeString

Note

The amount of bytes appended to the packet depends on the length of string, 1 byte = 1 char.

This method will append string value to the packet.

void writeString(string value)

Parameters:

  • string value: the text value.

readBool

This method will get boolean value from the packet.

bool readBool()

Returns bool:

the boolean value.


readInt8

Available since version: 0.1.0

This method will get signed int8 value from the packet. (1 byte)

int readInt8()

Returns int:

the number value in range -128 to 127.


readUInt8

Available since version: 0.1.0

This method will get unsigned int8 value from the packet. (1 byte)

int readUInt8()

Returns int:

the number value in range 0 to 255.


readInt16

This method will get signed int16 value from the packet. (2 bytes)

int readInt16()

Returns int:

the number value in range -32768 to 32767.


readUInt16

Available since version: 0.1.0

This method will get unsigned int16 value from the packet. (2 bytes)

int readUInt16()

Returns int:

the number value in range 0 to 65535.


readInt32

This method will get signed int32 value from the packet. (4 bytes)

int readInt32()

Returns int:

the number value in range -2147483648 to 2147483647.


readUInt32

Available since version: 0.1.0

This method will get unsigned int32 value from the packet. (4 bytes)

int readUInt32()

Returns int:

the number value in range 0 to 4294967295.


readFloat

This method will get float value from the packet. (4 bytes)

float readFloat()

Returns float:

the number value.


readString

Note

The amount of bytes appended to the packet depends on the length of string, 1 byte = 1 char.

This method will get string value from the packet.

string readString()

Returns string:

the text value.