{"id":"ernisto/defnet","name":"defnet","scope":"ernisto","platform":"roblox","description":"A simple network definition library.","version":"0.1.0","latest":"0.1.0","versions":["0.1.0-alpha.2","0.1.0-alpha.4","0.1.0-alpha.5","0.1.0-alpha.6","0.1.0-alpha.7","0.1.0-alpha.8","0.1.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"9ab4c27369d020fe15dcef397764521d9caa6cdb2eeab818f929154697e73566","likes":0,"downloads":0,"install":"forest install ernisto/defnet","url":"https://forest.dev/p/roblox/ernisto/defnet","files":"https://api.forest.dev/ai/package/roblox/ernisto/defnet/files","readme":"# defnet [![Tests](https://github.com/ernisto/defnet/actions/workflows/check.yml/badge.svg)](https://github.com/ernisto/defnet/actions/workflows/check.yml)\n\nSmall Roblox networking library. Declare remotes once, share the module between server and client. Optional binary codec and server-authoritative replicated state.\n\n## Installation\n\n- Download (`defnet.rbxm`) from [latest release](https://github.com/ernisto/defnet/releases/latest)\n\n- Wally (`wally.toml`): add under `[dependencies]`\n```toml\ndefnet = \"ernisto/defnet@0.1.0-alpha.2\"\n```\n\n- Pesde in roblox (terminal):\n```sh\npesde add wally#ernisto/defnet\n```\n\n## Declare remotes\n\n```lua\n-- shared/net.luau\nlocal net = require(ReplicatedStorage.Packages.net)\n\nreturn net.remotes {\n    chat = {\n        send = net.event<<(string)>>(),\n        history = net.func<<(), ({ string })>>(),\n    },\n    world = net.state { players = {} :: { [string]: Vector3 } },\n}\n```\n\nCall `net.remotes(def, root?)` once at module load. Server instantiates the `RemoteEvent`/`RemoteFunction`/`Folder` tree; client `WaitForChild`s it. The def table is mutated in-place and frozen.\n\n## Event\n\n```lua\n-- server\nnet.chat.send.on_server(function(player, message)\n    print(player.Name, message)\nend)\nnet.chat.send.fire_all 'hello'\nnet.chat.send.fire_list({ p1, p2 }, 'hi')\nnet.chat.send.fire_except(p1, 'not you')\n\n-- client\nnet.chat.send.on_client(function(message) ... end)\nnet.chat.send.fire_server 'ping'\n```\n\nPass a codec to `net.event(codec)` to binary-encode payloads. Built-in `net.codec` covers nil, bool, number, string (ASCII), vector, table, buffer. Unknowns (instances, etc.) flow through a side-channel.\n\n## Func\n\n```lua\n-- server\nfunction net.chat.history.on_server_invoke(player)\n    return {...}\nend\n\n-- client\nlocal msgs = net.chat.history.invoke_server()\n```\n\n## State\n\nServer-authoritative replicated state. Diffed every `Heartbeat`, only the delta goes on the wire.\n\n```lua\nlocal world = { players = {} }\n\n-- server: write into targets[player]\nnet.world.server[player1] = world\ntable.insert(world.players, 'alice')\n\nnet.world.server[player2] = world\ntable.insert(world.players, 'bob')\n\n-- client: read current snapshot\nprint(net.world.client.players)\n```\n\nCall `net.step_sync()` to flush all syncers manually; otherwise it runs on `Heartbeat`.\n\n## License\n\nMIT\n","readmeTruncated":false}