network — Networking API
Phase: Server (server-side) · Client scripts use client.network
Atomicoffe multiplexes all custom packets over two low-level channels (atomicoffe:lua_s2c and atomicoffe:lua_c2s). You address messages using arbitrary channel strings — no registration required.
Payload data is serialised as JSON and decoded into a Lua table on the receiving end.
Server → Client
network.sendToPlayer(player, channel, data)
Sends a packet to a single player.
| Parameter | Type | Description |
|---|---|---|
player | player table | The target player (from server.getPlayer() etc.) |
channel | string | Logical channel name, e.g. "myplugin:update" |
data | table | Lua table to send (serialised to JSON) |
onEvent("player.join", function(e)
network.sendToPlayer(e.player, "myplugin:welcome", {
message = "Hello!",
playerCount = server.getPlayerCount()
})
end)
network.sendToAll(channel, data)
Sends a packet to every currently online player.
network.sendToAll("myplugin:broadcast", { text = "Server event starting!" })
Client → Server
network.onReceive(channel, fn)
Registers a handler for packets sent from clients on the given channel. fn receives a player table and the decoded data table.
network.onReceive("myplugin:action", function(player, data)
logger.info(player.name .. " sent action: " .. tostring(data.type))
if data.type == "buyItem" then
player.give("minecraft:diamond", 1)
end
end)
Client-side counterpart
In client_scripts/, use client.network to send to the server and receive from it:
-- client_scripts/example.lua
client.network.sendToServer("myplugin:action", { type = "buyItem" })
client.network.onReceiveFromServer("myplugin:welcome", function(data)
client.sendMessage("Server says: " .. data.message)
end)