-
Notifications
You must be signed in to change notification settings - Fork 0
GNet
GNet is a better abstraction over default gmod net library. It's pure lua and does not use any remote server - everything is done with default net. It offers support for automatic data compression and chunking - theoretically allowing for transfer of infinite amount of data.
- ID:
net - Accessed with:
thorium.gnet

GM:Thorium_NetworkMessageReceived(message: string, size: number)
Called when whole network message (not chunked) was received by GNet.

GM:Thorium_NetworkMessageBegin(message: string, totalsize: number, transid: number)
Called when starting receiving chunked network message.

GM:Thorium_NetworkMessageChunk(message: string, recvsize: number, transid: number)
Called when network message chunk was received.

GM:Thorium_NetworkMessageEnd(message: string, totalsize: number, transid: number)
Called when chunked network message was fully received.

GNet.Start(message: string) -> NetHandle
Creates new NetHandle

GNet.Receive(message: string, callback: fun(handle: NetHandle, size: integer, from: Player|nil))
Adds a net message handler. Only one receiver can be used to receive the message
If message was received from another 

GNet.Send(handle: NetHandle, target: Entity|Player|"SERVER"|"BROADCAST|nil, docompress: boolean?, dochunk: boolean?, callbacks: table?) -> number|nil
Sends a NetHandle over network
If on 
Entity(0) or "SERVER" will send to server.
If on 
If callbacks table is supplied, function with key "progress" gets called every time that new chunk is transmitted. (arguments are message, handle, and pointer)
If callbacks table is supplied, function with key "done" gets called once every fragment of message was transmitted. (arguments are message and handle)
Returns transfer id or nil, if transfer was completed immediately

GNet.GetByTransferID(transid: number) -> NetHandle|nil
Gets NetHandle by transfer ID. If you are going to use this function, please note that
- it's your responsibility to keep pointer in the right place after your code returns.
- GNet network messages are not validated on other end, changing data in handle will result in corruption

GNet.GetReceiver(message: string) -> fun(handle: NetHandle, size: integer, from: Player|nil)
Gets GNet message handler. Only one receiver can be used to receive the message
- Inherits:
ByteBuffer

NetHandle.ReadEntity(self: NetHandle, ent: any) -> ent: Entity
Reads entity from buffer. Reads 2 bytes.

NetHandle.WriteEntity(self: NetHandle, ent: Entity) -> self: NetHandle
Writes entity to buffer. Writes 2 bytes.