Skip to content

melon.net

garryspins edited this page Feb 27, 2026 · 6 revisions

melon.net


shared link

Network handlers and abstractions
melon

Members

melon.net.Listeners

shared link

Table of all network listeners

Functions

melon.net.AwaitNotify

shared link
melon.net.AwaitNotify(id: string, on: function)

Argument and Return information

Arguments

# Name Type Description
1 id string The identifier of the notification
2 on function The callback, called with the status and data passed from the server

Awaits a notification from the server

local loading = true
melon.net.AwaitNotify("create_file", function(status)
    print("Status: ", status)
    loading = false
end )
net.Start("create_file")
net.WriteString("some.txt")
net.SendToServer()  

melon.net.ClearAwait

shared link
melon.net.ClearAwait(id: string)

Argument and Return information

Arguments

# Name Type Description
1 id string The identifier of the notification

Removes an await notification callback

melon.net.Notify

server link
melon.net.Notify(ply: Player, id: string, type: melon.net.NOTIFY_, data: any)

Argument and Return information

Arguments

# Name Type Description
1 ply Player The player to notify
2 id string The string ID of the notification for callbacks on the client
3 type melon.net.NOTIFY_ The notification type
4 data any Data to send to the client callback, uses net.WriteType so be careful
Notifies a player of the completion of a serverside task Paired with melon.net.AwaitNotify
net.Receive("create_file", function(_, ply)
    local name = net.ReadString()
    local f = file.Open(name, "w", "DATA")
    if not f then
        return melon.net.Notify(ply, "create_file", melon.net.NOTIFY_FAILURE)
    end
    f:Write("created!")
    f:Close()
    melon.net.Notify(ply, "create_file", melon.net.NOTIFY_SUCCESS)
end )  

melon.net.Recv

shared link

[!NOTE]
This is an alias of melon.net.Watch

melon.net.Schema

shared link
melon.net.Schema(identifier: string) -> melon.net.SchemaObj

Argument and Return information

Arguments

# Name Type Description
1 identifier string String identifier for the schema

Returns

# Name Type Description
1 obj melon.net.SchemaObj The schema object

Creates a new schema object

---- Creates and registers the schema
local schema = melon.net.Schema("unique_name")
    --- Contains a string
    :Value ("SomeString",  melon.net.TYPE_STRING)
    ---- And another schema
    :Schema("SomeSchema", "some_other_schema")
--- Called when the schema message gets recieved
function schema:Recv(sender)
    print(self.SomeString) -- "hi!"
    print(self.SomeSchema.TestString) -- "hello!"
    print(self.SomeSchema.TestInteger) -- nil
end
--- Registers another schema
melon.net.Schema("some_other_schema")
    --- Contains another string
    :Value("TestString",  melon.net.TYPE_STRING)
    --- Contains an optional integer
    :Value("TestInteger", melon.net.TYPE_INTEGER, true)
--- Due to this being used as a sub-schema, it does not need a recv assigned to it
schema:Send({
    SomeString = "hi!",
    SomeSchema = {
        TestString = "hello!",
        --- Omitting TestInteger
    }
}, player) --- Sending to `player`, if youre sending to the server from the client this can be omitted  

melon.net.SchemaFromTable

shared link
melon.net.SchemaFromTable(name: string, tbl: table, done: table) -> melon.net.SchemaObj

Argument and Return information

Arguments

# Name Type Description
1 name string Name of the schema to be registered as
2 tbl table Table to make a schema out of
3 done table Table of already created schemas to avoid infinite recursion

Returns

# Name Type Description
1 obj melon.net.SchemaObj The schema object
Makes a schema from the given table with the types of values given Generates nested schemas for you, but not arrays Due to this features immediate use case, every value is optional by default

melon.net.Unwatch

shared link
melon.net.Unwatch(msg: string, name: string)

Argument and Return information

Arguments

# Name Type Description
1 msg string Message name added with [util.AddNetworkString]
2 name string Identifier of the watcher to be removed

Unwatches a network message added with melon.net.Watch

melon.net.Unwatch("ping_net_name", "Other Identifier")  

melon.net.Watch

shared link
melon.net.Watch(msg: string, name: string, callback: fn)

Argument and Return information

Arguments

# Name Type Description
1 msg string Message name added with [util.AddNetworkString] to watch
2 name string Identifier for the watcher
3 callback fn Function callback for whenever the listener recieves an input
Watches a network message, replacement for invalidlink(net.Receive) that takes multiple callbacks Only use if you desperately need
util.AddNetworkString("ping_net_name")
melon.net.Watch("ping_net_name", "Identifier", function(len, ply)
    net.Start("ping_net_name")
    net.WriteString("Pong :)")
    net.Send(ply)
end )
melon.net.Watch("ping_net_name", "Other Identifier", function(len, ply)
    print("Ponged from Identifier :)")
end )  

Classes

melon.net.SchemaObj

shared link

Net Schema Object

Accessors

All of these values have Set*/Get* methods for them. They can also be indexed by their name, object.*

Name Type Comment
Identifier string String identifier for this message

shared link internal

melon.net.SchemaObj:Init

shared link internal
melon.net.SchemaObj:Init()

Internal initialization for a Schema Object


shared link

melon.net.SchemaObj:RecvOn

shared link
melon.net.SchemaObj:RecvOn(on: melon.net.RECV_ON_) -> self

Argument and Return information

Arguments

# Name Type Description
1 on melon.net.RECV_ON_ Where to allow recieving from

Returns

# Name Type Description
1 self self The SchemaObj
This is set to recv on CLIENT by default, you need to switch this in order to be able to recieve on server. This is here to prevent abuse where the client can send large schemas over the network and the server has to sit there and take it, just to reject it later

shared link

melon.net.SchemaObj:Array

shared link
melon.net.SchemaObj:Array(name: string, type: melon.net.TYPE_, optional?: bool) -> self

Argument and Return information

Arguments

# Name Type Description
1 name string Keyname of the array
2 type melon.net.TYPE_ Type enum of the data being sent
3 optional? bool Is this array optional

Returns

# Name Type Description
1 self self The SchemaObj
Adds an array to the schema, which sends a sequental table of allowed types Tables are always scrubbed for server safety

shared link

melon.net.SchemaObj:Recv

shared link
melon.net.SchemaObj:Recv(data: table, sender: Player, obj: melon.net.SchemaObj)

Argument and Return information

Arguments

# Name Type Description
1 data table The data recieved
2 sender Player If on the server then this is the player that sent the message
3 obj melon.net.SchemaObj The SchemaObj
Function to call when recieving data You should treat this like a method even though it isnt really one, as seen in the example

shared link

melon.net.SchemaObj:Send

shared link
melon.net.SchemaObj:Send(tbl: table, to: table<Player>) -> bool?

Argument and Return information

Arguments

# Name Type Description
1 tbl table Table to write
2 to table<Player> A table of players or a player, accepts what net.Send does, doesn't matter on the client since it uses net.SendToServer.

Returns

# Name Type Description
1 success bool Was the write successful
Starts the `melon` net message and sends the schema Writes the actual net.Write* calls to the netbuffer

shared link

melon.net.SchemaObj:Read

shared link
melon.net.SchemaObj:Read() -> table

Argument and Return information

Returns

# Name Type Description
1 tbl table The read schema table

Reads the schema table from the net message


shared link internal

melon.net.SchemaObj:WriteValue

shared link internal
melon.net.SchemaObj:WriteValue()


shared link

melon.net.SchemaObj:Validate

shared link
melon.net.SchemaObj:Validate(args: table) -> bool?, number, any

Argument and Return information

Arguments

# Name Type Description
1 args table Table to validate if it meets the schema or not

Returns

# Name Type Description
1 does bool Does this table match the schema
2 key number If not valid, key of the bad value
3 value any If not valid, the invalid schema name

Is the argument table provided valid to this schema


shared link

melon.net.SchemaObj:Value

shared link
melon.net.SchemaObj:Value(name: string, type: melon.net.TYPE_, optional?: bool) -> self

Argument and Return information

Arguments

# Name Type Description
1 name string Keyname of the value
2 type melon.net.TYPE_ Type of the value
3 optional? bool Is this value optional

Returns

# Name Type Description
1 self self The SchemaObj

Adds a value row to the schema


shared link internal

melon.net.SchemaObj:ReadValue

shared link internal
melon.net.SchemaObj:ReadValue()


shared link internal

melon.net.SchemaObj:Add

shared link internal
melon.net.SchemaObj:Add()


shared link internal

melon.net.SchemaObj:ValidateValue

shared link internal
melon.net.SchemaObj:ValidateValue()


shared link

melon.net.SchemaObj:Schema

shared link
melon.net.SchemaObj:Schema(name: string, identifier: string, optional?: bool) -> self

Argument and Return information

Arguments

# Name Type Description
1 name string Keyname of the schema
2 identifier string Identifier for the schema thats registered in melon.net.schemas
3 optional? bool Is this schema optional

Returns

# Name Type Description
1 self self The SchemaObj

Adds a schema row to the schema, used to send nested schemas

Enumerations

melon.net.NOTIFY_

shared link

Describes the type of notification for melon.net.Notify

Name Description
NOTIFY_OTHER Custom notification
NOTIFY_SUCCESS Successful response
NOTIFY_WARNING Warning response
NOTIFY_FAILURE Failure response
NOTIFY_INSUFFICIENT_PERMISSIONS Insufficient permissions, duh

melon.net.RECV_ON_

shared link

Name Description
RECV_ON_CLIENT Recieve on the client
RECV_ON_SERVER Recieve on the server
RECV_ON_SHARED Recieve from both

melon.net.TYPE_

shared link

Name Description
TYPE_STRING String
TYPE_INTEGER I32
TYPE_FLOAT Double
TYPE_ENUM U8
TYPE_BOOL Boolean
TYPE_ANGLE Angle
TYPE_VECTOR Vector
TYPE_ENTITY Entity
TYPE_PLAYER Player (sent via UserID)
TYPE_SCHEMA Another NetSchema
TYPE_ARRAY An array of primitives

Clone this wiki locally