Packet - Networking library
Features
Batching "Batches all your events into a single event"
Serialize "Serializes all data into one buffer"
Many types "16 bit floats + 24 bit floats + many more"
DDoS protection "Stops exploiters from crashing the server"
Remote Functions "Safely request a response from the client or server"
Unreliable "UnreliableRemoteEvent support"
Easy To Use "Simple and elegant"
Support My Work
If you liked my work and want to donate to me you can do so here
SourceCode
You can get the sourcecode to this module herePermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
Documentation
CONSTRUCTOR
Constructor(name: string, parameters: ...)
"Returns previously created packet else a new packet"
PROPERTIES
ResponseTimeout number 10
"Seconds until a response will timeout"
ResponseTimeoutValue any nil
"Value passed back if a response times out"
OnServerInvoke function nil
"Function called when packet is invoked from the client"
OnClientInvoke function nil
"Function called when packet is invoked from the server"
EVENTS
OnServerEvent(player: Player, parameters: ...) Signal
"Fires when the client fires a packet"
OnClientEvent(parameters: ...) Signal
"Fires when the server fires a packet"
METHODS
Response(parameters: ...) Packet
"Converts a RemoteEvent packet to a RemoteFunction packet"
Fire(parameters: ...) any
"Fires a packet to all clients or to the server, if Response() was called will also return a response"
FireClient(player: Player, parameters: ...) any
"Fires a packet to a client, if Response() was called will also return a response"
Serialize(parameters: ...) buffer {Instance}?
"Serializes parameters into a buffer and maybe a array of instances"
Deserialize(buffer {Instance}?) ...any
"Deserializes a buffer and maybe instances into parameters"
Examples
Simple Example
-- Server
local Packet = require(game.ReplicatedStorage.Packet)
local packet = Packet("PacketName", Packet.NumberS8, Packet.Vector3F32, Packet.Instance)
local player = game.Players.PlayerAdded:Wait()
packet:FireClient(player, -12, Vector3.zero, workspace.SpawnLocation)
-- Client
local Packet = require(game.ReplicatedStorage.Packet)
local packet = Packet("PacketName", Packet.NumberS8, Packet.Vector3F32, Packet.Instance)
packet.OnClientEvent:Connect(function(...)
print(...)
end)
Optional Example
local packet1 = Packet("OptionalString", Packet.Any :: string?)
local packet2 = Packet("OptionalNumber", Packet.Any :: number?)
Array Example
local packet = Packet("Array", {Packet.NumberU8})
packet:Fire({1, 6, 11, 3})
Dictionary Example
local packet = Packet("Dictionary", {Key = Packet.NumberF32, AnotherKey = Packet.String})
packet:Fire({Key = 22, AnotherKey = "Hello"})
Response Example
-- Server
local Packet = require(game.ReplicatedStorage.Packet)
local packet = Packet("PacketName", Packet.NumberF16, Packet.String):Response(Packet.Boolean8)
packet.OnServerInvoke = function(player, number, string)
print("OnServerInvoke", player, number, string) -- 2.2, "Text"
return true
end
-- Client
local Packet = require(game.ReplicatedStorage.Packet)
local packet = Packet("PacketName", Packet.NumberF16, Packet.String):Response(Packet.Boolean8)
local response = packet:Fire(2.2, "Text")
print("Server Response:", response) -- true
UnreliableRemoteEvent Wrapper
--!strict
local RunService = game:GetService("RunService")
local Packet = require(game.ReplicatedStorage.Packet)
local unreliablePackets = {
Packet1 = Packet("Packet1", Packet.NumberU8),
Packet2 = Packet("Packet2", Packet.String),
}
for index, packet in unreliablePackets do
local packet = packet :: Packet.Packet
if RunService:IsServer() then
local unreliableRemoteEvent = Instance.new("UnreliableRemoteEvent")
unreliableRemoteEvent.Name = packet.Name
unreliableRemoteEvent.Parent = game.ReplicatedStorage
unreliableRemoteEvent.OnServerEvent:Connect(function(player, ...)
packet.OnServerEvent:Fire(player, packet:Deserialize(...))
end)
packet.Fire = function(packet, ...)
unreliableRemoteEvent:FireAllClients(packet:Serialize(...))
end
packet.FireClient = function(packet, player, ...)
unreliableRemoteEvent:FireClient(player, packet:Serialize(...))
end
else
local unreliableRemoteEvent = game.ReplicatedStorage:WaitForChild(packet.Name)
unreliableRemoteEvent.OnClientEvent:Connect(function(...)
packet.OnClientEvent:Fire(packet:Deserialize(...))
end)
packet.Fire = function(packet, ...)
unreliableRemoteEvent:FireServer(packet:Serialize(...))
end
end
end
return unreliablePackets
Remove packet.Name and rely on order of creation
-- Varables
local packetCounter = 0
-- Constructor
local function Constructor<A..., B...>(_, ...: A...)
local packet = (setmetatable({}, Packet) :: any) :: Packet<A..., B...>
packet.Id = packetCounter
if RunService:IsServer() then
packet.OnServerEvent = Signal() :: Signal.Signal<(Player, A...)>
else
packet.OnClientEvent = Signal() :: Signal.Signal<A...>
end
packet.Reads, packet.Writes = ParametersToFunctions(table.pack(...))
packets[packetCounter] = packet
packetCounter += 1
return packet
end
Updates
1.1
- Fixed vulnerability that allows client to resume a thread if that thread is yielded after a fire()
1.2
- No longer possible for the client to make the server print error messages in live games
1.3
- Improved CPU performance
Anytype now supports tablesAnytype now supports EnumItems- Added
BooleanNumbertype - Added rate limit to how many events the client can send per server heartbeat [this only effects exploiters]
- Client is no longer framerate dependant and will fire a maximum of 60 events every second
- Bug fixes
1.4
- FPS spikes no longer cause the clients timer to fall behind
- Removed incorrect rounding for
UDim,UDim2,Vector2S16andVector3S16 Anytype numbers can now go higher then 4294967295Anytype tables only use 2 bytes instead of 3 and now have a unlimited size- Added
StringLongtype that supports a length longer then 255 - Added
BufferLongtype that supports a length longer then 255
1.5
- Fixed
EnumItemtype
1.6
- Fixed typo
1.7
- Fixed vulnerability
- Fire/FireClient will now skip thread ids if there in use
- Fire/FireClient will now error if you have more then 128 yielded threads
Other Projects
Infinite Terrain
Packet
Suphi’s DataStore Module
Global Framework
Infinite Scripter
Mesh Editor
Quick Math Calculator
Toggle Block Comment
Toggle Decomposition Geometry
Tag Explorer
Suphi’s Linked List Module
Suphi’s Hybrid Linked List Module
Suphi’s RemoteFunction Module
Robux Converter