Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Networking/Channel.luau
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ function Channel._applyUpdate(b: buffer)
state[field.name] = field.type.read(clientBuf, field.offset)
end
for _, callback in def.subscribers do
callback(entityId, state)
xpcall(callback, function(err)
warn(`[Satset] Channel '{def.name}' subscriber error: {err}`)
end, entityId, state)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion src/Networking/Packet.luau
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ function Packet._dispatchSingle(packetId: number, payload: buffer, sender: Playe
end

for _, listener in def.listeners do
listener(data, sender)
xpcall(listener, function(err)
warn(`[Satset] Packet '{def.name}' listener error: {err}`)
end, data, sender)
end
end

Expand Down
17 changes: 17 additions & 0 deletions src/Types/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ Types.u4 = {
Types.string8 = {
read = function(b: buffer, cursor: number)
local len = readu8(b, cursor)
if cursor + 1 + len > buffer.len(b) then
return ""
end
return readstring(b, cursor + 1, len)
end,
write = function(b: buffer, cursor: number, value: string)
Expand All @@ -177,6 +180,9 @@ Types.string8 = {
Types.string16 = {
read = function(b: buffer, cursor: number)
local len = readu16(b, cursor)
if cursor + 2 + len > buffer.len(b) then
return ""
end
return readstring(b, cursor + 2, len)
end,
write = function(b: buffer, cursor: number, value: string)
Expand Down Expand Up @@ -458,9 +464,13 @@ end
function Types.array(elementType: Type<any>): Type<{ any }>
return {
read = function(b: buffer, cursor: number)
local bufLen = buffer.len(b)
local len = readu16(b, cursor)
local arr, pos = table.create(len), cursor + 2
for i = 1, len do
if pos + elementType.size > bufLen then
break
end
local val = elementType.read(b, pos)
arr[i] = val
pos += elementType.getSize(val)
Expand Down Expand Up @@ -492,11 +502,18 @@ end
function Types.map(keyType: Type<any>, valueType: Type<any>): Type<{ [any]: any }>
return {
read = function(b: buffer, cursor: number)
local bufLen = buffer.len(b)
local count = readu16(b, cursor)
local result, pos = {}, cursor + 2
for _ = 1, count do
if pos + keyType.size > bufLen then
break
end
local key = keyType.read(b, pos)
pos += keyType.getSize(key)
if pos + valueType.size > bufLen then
break
end
local val = valueType.read(b, pos)
pos += valueType.getSize(val)
result[key] = val
Expand Down
7 changes: 7 additions & 0 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local CHANNEL_UNRELIABLE_NAME = "__SatsetChannelUnreliable"

-- [ State ]

local _initialized = false
local _guard: any = nil
local channelReliable: RemoteEvent
local channelUnreliable: UnreliableRemoteEvent
Expand All @@ -48,6 +49,12 @@ export type SatsetConfig = {
the client before using any packets or channels.
]]
function Satset.start(config: SatsetConfig?)
if _initialized then
warn("[Satset] Already initialized. Ignoring duplicate start() call.")
return
end
_initialized = true

local context = if IS_SERVER then "Server" else "Client"
print(`[Satset v{VERSION}] Initializing on {context}`)

Expand Down
Loading