C# Класс GarrysModLuaShared.net

The net library is one of a number of ways to send data between the client and server. The major advantages of the net library are the large size limit(64kb/message) and the ability to send data backwards - from the client to the server.
Показать файл Открыть проект

Открытые методы

Метод Описание
Broadcast ( LuaState luaState ) : void

Sends the currently built net message to all connected players.

BytesWritten ( LuaState luaState ) : double

Returns the size of the current message in bytes.

ReadBit ( LuaState luaState ) : double

Reads a bit from the received net message. Warning! You must read information in same order as you write it.

ReadBool ( LuaState luaState ) : bool

Reads a boolean from the received net message. Warning! You must read information in same order as you write it.

ReadData ( LuaState luaState, double length ) : string

Reads pure binary data from the message. Warning! You must read information in same order as you write it.

ReadDouble ( LuaState luaState ) : double

Reads a double-precision number from the received net message. Warning! You must read information in same order as you write it.

ReadFloat ( LuaState luaState ) : float

Reads a floating-point number from the received net message. Warning! You must read information in same order as you write it.

ReadHeader ( LuaState luaState ) : double

Returns the "header" of the message which contains a short which can be converted to the corresponding message name via util.NetworkIDToString.

ReadInt ( LuaState luaState, double bitCount = 32.0D ) : int

Reads an integer from the received net message. Warning! You must read information in same order as you write it.

ReadString ( LuaState luaState ) : string

Reads a null terminated string from the net stream. The size of the string is 8 bits plus 8 bits for every ASCII character in the string. Warning! You must read information in same order as you write it.

ReadUInt ( LuaState luaState, double bitCount = 32.0D ) : uint

Reads an unsigned integer with the specified number of bits from the received net message. Warning! You must read information in same order as you write it.

SendToServer ( LuaState luaState ) : void

Sends the current message to the server.

Start ( LuaState luaState, string messageName, bool unreliable = false ) : bool

Begins a new net message. Don't forget to pool the messageName with util.AddNetworkString!

WriteBit ( LuaState luaState, bool boolean ) : void

Appends a boolean (as 0 or 1) to the current net message.

WriteData ( LuaState luaState, string binaryData, double length ) : void

Writes a chunk of binary data to the message.

WriteDouble ( LuaState luaState, double @double ) : void

Appends a double-precision number to the current net message.

WriteFloat ( LuaState luaState, float @float ) : void

Appends a float (number with decimals) to the current net message.

WriteInt ( LuaState luaState, int integer, double bitCount = 32.0D ) : void

Appends an integer (number without decimals) to the current net message.

WriteString ( LuaState luaState, string @string ) : void

Appends a string to the current net message. The size of the string is 8 bits plus 8 bits for every ASCII character in the string. The maximum allowed length of a single written string is 1024 characters.

WriteUInt ( LuaState luaState, uint unsignedInteger, double numberOfBits = 32.0D ) : void

Appends an unsigned integer with the specified number of bits to the current net message.

Описание методов

Broadcast() публичный статический Метод

Sends the currently built net message to all connected players.
public static Broadcast ( LuaState luaState ) : void
luaState LuaState Pointer to lua_State struct.
Результат void

BytesWritten() публичный статический Метод

Returns the size of the current message in bytes.
public static BytesWritten ( LuaState luaState ) : double
luaState LuaState Pointer to lua_State struct.
Результат double

ReadBit() публичный статический Метод

Reads a bit from the received net message. Warning! You must read information in same order as you write it.
public static ReadBit ( LuaState luaState ) : double
luaState LuaState Pointer to lua_State struct.
Результат double

ReadBool() публичный статический Метод

Reads a boolean from the received net message. Warning! You must read information in same order as you write it.
public static ReadBool ( LuaState luaState ) : bool
luaState LuaState Pointer to lua_State struct.
Результат bool

ReadData() публичный статический Метод

Reads pure binary data from the message. Warning! You must read information in same order as you write it.
public static ReadData ( LuaState luaState, double length ) : string
luaState LuaState Pointer to lua_State struct.
length double /// The length of the data to be read, in bytes. /// /// When this is 0, does not return an empty string as you would expect, but random junk /// instead. ///
Результат string

ReadDouble() публичный статический Метод

Reads a double-precision number from the received net message. Warning! You must read information in same order as you write it.
public static ReadDouble ( LuaState luaState ) : double
luaState LuaState Pointer to lua_State struct.
Результат double

ReadFloat() публичный статический Метод

Reads a floating-point number from the received net message. Warning! You must read information in same order as you write it.
public static ReadFloat ( LuaState luaState ) : float
luaState LuaState Pointer to lua_State struct.
Результат float

ReadHeader() публичный статический Метод

Returns the "header" of the message which contains a short which can be converted to the corresponding message name via util.NetworkIDToString.
public static ReadHeader ( LuaState luaState ) : double
luaState LuaState Pointer to lua_State struct.
Результат double

ReadInt() публичный статический Метод

Reads an integer from the received net message. Warning! You must read information in same order as you write it.
public static ReadInt ( LuaState luaState, double bitCount = 32.0D ) : int
luaState LuaState Pointer to lua_State struct.
bitCount double The amount of bits to be read.
Результат int

ReadString() публичный статический Метод

Reads a null terminated string from the net stream. The size of the string is 8 bits plus 8 bits for every ASCII character in the string. Warning! You must read information in same order as you write it.
public static ReadString ( LuaState luaState ) : string
luaState LuaState Pointer to lua_State struct.
Результат string

ReadUInt() публичный статический Метод

Reads an unsigned integer with the specified number of bits from the received net message. Warning! You must read information in same order as you write it.
public static ReadUInt ( LuaState luaState, double bitCount = 32.0D ) : uint
luaState LuaState Pointer to lua_State struct.
bitCount double The size of the integer to be read, in bits.
Результат uint

SendToServer() публичный статический Метод

Sends the current message to the server.
public static SendToServer ( LuaState luaState ) : void
luaState LuaState Pointer to lua_State struct.
Результат void

Start() публичный статический Метод

Begins a new net message. Don't forget to pool the messageName with util.AddNetworkString!
public static Start ( LuaState luaState, string messageName, bool unreliable = false ) : bool
luaState LuaState Pointer to lua_State struct.
messageName string The name of the message to send.
unreliable bool If set to true, the message is not guaranteed to reach its destination.
Результат bool

WriteBit() публичный статический Метод

Appends a boolean (as 0 or 1) to the current net message.
public static WriteBit ( LuaState luaState, bool boolean ) : void
luaState LuaState Pointer to lua_State struct.
boolean bool Bit status (false = 0, true = 1) to be sent.
Результат void

WriteData() публичный статический Метод

Writes a chunk of binary data to the message.
public static WriteData ( LuaState luaState, string binaryData, double length ) : void
luaState LuaState Pointer to lua_State struct.
binaryData string The binary data to be sent.
length double The length of the binary data to be sent, in bytes.
Результат void

WriteDouble() публичный статический Метод

Appends a double-precision number to the current net message.
public static WriteDouble ( LuaState luaState, double @double ) : void
luaState LuaState Pointer to lua_State struct.
@double double
Результат void

WriteFloat() публичный статический Метод

Appends a float (number with decimals) to the current net message.
public static WriteFloat ( LuaState luaState, float @float ) : void
luaState LuaState Pointer to lua_State struct.
@float float
Результат void

WriteInt() публичный статический Метод

Appends an integer (number without decimals) to the current net message.
public static WriteInt ( LuaState luaState, int integer, double bitCount = 32.0D ) : void
luaState LuaState Pointer to lua_State struct.
integer int The integer to be sent.
bitCount double /// The amount of bits the number consists of. (signed) /// /// This must be 32 or less. If you are unsure what to set, just set it to 32. /// /// To determine just how many bits exactly you're going to need for your integer, you first need to understand what /// those bits actually are. A bit can have two possible states: 0 and 1. For every bit you add, you get an /// exponentially increasing amount of possible combinations. 2 bits allow for 2^2 = 4 possible combinations (namely /// 00, 01, 10 and 11), 3 bits allow for 2^3 = 8 possible combinations, 4 bits allow for 2^4 = 16 possible combinations /// and so on. Since we start counting from 0, a 4-bit integer would thus be able to represent any integer number /// between 0 and 15. /// /// Do note that Garry's Mod is using the first bit for purposes other than storing your integer's value. Just figure /// out how many bits you'd normally need, then increase that number by one (so if you want to send an integer that may /// assume any number between 0 and 15, you don't use a 4 as your bitCount but rather a 5). /// /// Consult this table for a /// quick reference on how many bits you need for a given value. ///
Результат void

WriteString() публичный статический Метод

Appends a string to the current net message. The size of the string is 8 bits plus 8 bits for every ASCII character in the string. The maximum allowed length of a single written string is 1024 characters.
public static WriteString ( LuaState luaState, string @string ) : void
luaState LuaState Pointer to lua_State struct.
@string string
Результат void

WriteUInt() публичный статический Метод

Appends an unsigned integer with the specified number of bits to the current net message.
public static WriteUInt ( LuaState luaState, uint unsignedInteger, double numberOfBits = 32.0D ) : void
luaState LuaState Pointer to lua_State struct.
unsignedInteger uint The unsigned integer to be sent.
numberOfBits double /// The size of the integer to be sent, in bits. Acceptable values range from 1 to 32. 1 = bit, /// 4 = nibble, 8 = byte, 16 = short, 32 = long. ///
Результат void