Skip to content

Commit 3b563fc

Browse files
committed
ye
1 parent 384b65c commit 3b563fc

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

src/api/Packet.luau

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,28 @@ type PacketFields = {
4141
_signal: Signal.Signal,
4242
}
4343

44-
-- Shared methods(both contexts)
45-
local SharedImpl = {}
44+
-- Server-only metatable. Single send() dispatches on target type.
45+
local ServerImpl = {}
46+
ServerImpl.__index = ServerImpl
47+
48+
export type Packet = typeof(setmetatable({} :: PacketFields, ServerImpl))
4649

47-
function SharedImpl.listen(self: Packet, callback: (...any) -> ()): Connection
50+
function ServerImpl.listen(self: Packet, callback: (...any) -> ()): Connection
4851
return self._signal:connect(callback)
4952
end
5053

51-
function SharedImpl.once(self: Packet, callback: (...any) -> ()): Connection
54+
function ServerImpl.once(self: Packet, callback: (...any) -> ()): Connection
5255
return self._signal:once(callback)
5356
end
5457

55-
function SharedImpl.wait(self: Packet): ...any
58+
function ServerImpl.wait(self: Packet): ...any
5659
return self._signal:wait()
5760
end
5861

59-
function SharedImpl.disconnectAll(self: Packet): ()
62+
function ServerImpl.disconnectAll(self: Packet): ()
6063
self._signal:disconnectAll()
6164
end
6265

63-
-- Server-only metatable. Single send() dispatches on target type.
64-
local ServerImpl = setmetatable({}, { __index = SharedImpl })
65-
ServerImpl.__index = ServerImpl
66-
67-
export type Packet = typeof(setmetatable({} :: PacketFields, ServerImpl))
68-
6966
local function checkDeltaMode(self: Packet, mode: number): ()
7067
if not self._isDelta then
7168
return
@@ -127,9 +124,25 @@ end
127124
table.freeze(ServerImpl)
128125

129126
-- Client-only metatable. Has send(), no target needed.
130-
local ClientImpl = setmetatable({}, { __index = SharedImpl })
127+
local ClientImpl = {}
131128
ClientImpl.__index = ClientImpl
132129

130+
function ClientImpl.listen(self: Packet, callback: (...any) -> ()): Connection
131+
return self._signal:connect(callback)
132+
end
133+
134+
function ClientImpl.once(self: Packet, callback: (...any) -> ()): Connection
135+
return self._signal:once(callback)
136+
end
137+
138+
function ClientImpl.wait(self: Packet): ...any
139+
return self._signal:wait()
140+
end
141+
142+
function ClientImpl.disconnectAll(self: Packet): ()
143+
self._signal:disconnectAll()
144+
end
145+
133146
function ClientImpl.send(self: Packet, data: any): ()
134147
clientWrite(self._id, self._name, self._codec, data, self._isUnreliable)
135148
end

0 commit comments

Comments
 (0)