{"id":"syn-developmentlabs/buffernet","name":"buffernet","scope":"syn-developmentlabs","platform":"roblox","description":"Networking with buffers on roblox","version":"0.1.6","latest":"0.1.6","versions":["0.1.2","0.1.3","0.1.4","0.1.5","0.1.6"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"a8fce4496f9829c8e9f49a6f593a88b980be266386b91c29eee79ce96d8cbb00","likes":0,"downloads":0,"install":"forest install syn-developmentlabs/buffernet","url":"https://forest.dev/p/roblox/syn-developmentlabs/buffernet","files":"https://api.forest.dev/ai/package/roblox/syn-developmentlabs/buffernet/files","readme":"# BufferNet2\n\n## Setup\n\n**Server**\n```lua\nlocal BufferNet = require(path.to.BufferNet2)\nlocal net = BufferNet.new(game.ReplicatedStorage)\n\n-- create your remotes here...\n\nnet.FinishInitilaztion()\n```\n\n**Client**\n```lua\nlocal BufferNet = require(path.to.BufferNet2)\nlocal net = BufferNet.new() -- yields until the server finishes initialization\n```\n\n---\n\n## Creating Remotes (Server)\n\n### CreateRemote - Event\n```lua\nnet:CreateRemote(\"Event\", \"PlayerDamaged\", function(player: Player, data: buffer)\n    print(player.Name, \"sent damage data\")\nend)\n```\n\n### CreateRemote - Function\n```lua\nnet:CreateRemote(\"Function\", \"GetInventory\", function(player: Player, data: buffer)\n    return { \"Sword\", \"Shield\", \"Potion\" }\nend)\n```\n\n### CreateRemote - With Encryption\n```lua\nnet:CreateRemote(\"Event\", \"SecureChat\", function(player: Player, data: buffer)\n    print(\"Encrypted message received from\", player.Name)\nend, { IsEncrypted = true })\n```\n\n---\n\n## Firing & Invoking from the Client\n\n### FireServer\nFires a RemoteEvent from the client to the server.\n```lua\n-- send a damage value to the server\nnet:FireServer(\"PlayerDamaged\", { damage = 25, weapon = \"Sword\" })\n```\n\n### InvokeServer\nCalls a RemoteFunction from the client and waits for the server's return value.\n```lua\nlocal inventory = net:InvokeServer(\"GetInventory\")\nprint(\"My inventory:\", inventory)\n```\n\n---\n\n## Firing Clients from the Server\n\n### FireClient\nFires a RemoteEvent to one specific player.\n```lua\nlocal Players = game:GetService(\"Players\")\n\nPlayers.PlayerAdded:Connect(function(player)\n    net:FireClient(\"PlayerDamaged\", player, { damage = 0, weapon = \"None\" })\nend)\n```\n\n### FireAllClients\nFires a RemoteEvent to every connected player.\n```lua\nnet:FireAllClients(\"PlayerDamaged\", { damage = 10, weapon = \"Explosion\" })\n```\n\n### FireAllClientsExcept\nFires a RemoteEvent to all players except the one(s) specified. Accepts a\nsingle `Player` or a `{Player}` array.\n```lua\n-- exclude a single player\nnet:FireAllClientsExcept(\"PlayerDamaged\", excludedPlayer, { damage = 10, weapon = \"Explosion\" })\n\n-- exclude multiple players\nnet:FireAllClientsExcept(\"PlayerDamaged\", { playerA, playerB }, { damage = 10, weapon = \"Explosion\" })\n```\n\n### FireClients\nFires a RemoteEvent to an explicit list of players.\n```lua\nlocal targets = { playerA, playerB, playerC }\nnet:FireClients(\"PlayerDamaged\", targets, { damage = 50, weapon = \"Sniper\" })\n```\n\n---\n\n## Invoking Clients from the Server\n\n> ! `InvokeClient` and `InvokeAllClients` can **infinitely yield** if a client\n> disconnects mid-invocation. Always wrap call sites in a timeout or `pcall`\n> in production.\n\n### InvokeClient\nCalls a RemoteFunction on a specific player and waits for their return value.\n```lua\nlocal Players = game:GetService(\"Players\")\n\nPlayers.PlayerAdded:Connect(function(player)\n    local clientData = net:InvokeClient(\"GetInventory\", player)\n    print(player.Name .. \"'s inventory:\", clientData)\nend)\n```\n\n### InvokeAllClients\nInvokes all connected players concurrently and returns a `{[Player]: any}`\ntable of their responses. Failed or disconnected players will return `nil`.\n```lua\nlocal allStuff = net:InvokeAllClients(\"getStuff\")\n\nfor player, stuff in allStuff do\n    if stuff then\n        print(player.Name, \"->\", stuff)\n    else\n        print(player.Name, \"didnt respond\")\n    end\nend\n```\n\n---\n\n## Listening on the Client\n\n### OnClientEvent\nConnects a callback that fires whenever the server sends to this client.\nReturns an `RBXScriptConnection` so you can disconnect to avoid mem leaks\n```lua\nlocal connection = net:OnClientEvent(\"getCountry\", function(data)\n    print(\"hello\", data.name, \"from\", data.country)\nend)\n\n-- disconnect when no longer neede\nconnection:Disconnect()\n```\n\n### OnClientInvoke\nSets the callback the server receives a return value from when it calls\n`InvokeClient`. If you for some reason decide to assign it twice, it'll\nreplace it.\n```lua\nnet:OnClientInvoke(\"X\", function()\n    return { \"X\", \"Y\", \"Z\" }\nend)\n\n-- unregister later if needed\nnet:OnClientInvoke(\"GetInventory\", function() end)\n```\n\n---\n\n## Encryption\n\nAny remote can be created with `IsEncrypted = true`. The key is generated on\nthe server and synced to clients automatically via attirbutes.\n\n```lua\n-- server\nnet:CreateRemote(\"Event\", \"payload_thing\", function(player, data)\n    print(\"Secure data from\", player.Name)\nend, { IsEncrypted = true })\n\n-- client - FireServer, InvokeServer, OnClientEvent, OnClientInvoke all\n-- handle encryption/decryption\nnet:FireServer(\"payload_thing\", { secret = \"hello\" })\n```","readmeTruncated":false}