@axpecter/lync 1.5.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +499 -357
- package/package.json +2 -2
- package/src/Types.luau +69 -27
- package/src/api/Group.luau +101 -106
- package/src/api/Packet.luau +191 -157
- package/src/api/Query.luau +223 -282
- package/src/api/Scope.luau +46 -57
- package/src/api/Signal.luau +104 -137
- package/src/codec/Base.luau +69 -20
- package/src/codec/composite/Array.luau +189 -201
- package/src/codec/composite/Map.luau +97 -341
- package/src/codec/composite/Optional.luau +27 -23
- package/src/codec/composite/Shared.luau +96 -65
- package/src/codec/composite/Struct.luau +201 -339
- package/src/codec/composite/Tagged.luau +64 -178
- package/src/codec/composite/Tuple.luau +81 -95
- package/src/codec/datatype/Buffer.luau +49 -21
- package/src/codec/datatype/CFrame.luau +207 -30
- package/src/codec/datatype/Color.luau +21 -11
- package/src/codec/datatype/Instance.luau +29 -19
- package/src/codec/datatype/IntVector.luau +33 -21
- package/src/codec/datatype/NumberRange.luau +19 -10
- package/src/codec/datatype/Ray.luau +26 -22
- package/src/codec/datatype/Rect.luau +20 -16
- package/src/codec/datatype/Region.luau +51 -45
- package/src/codec/datatype/Sequence.luau +64 -56
- package/src/codec/datatype/String.luau +89 -56
- package/src/codec/datatype/UDim.luau +40 -22
- package/src/codec/datatype/Vector.luau +181 -17
- package/src/codec/meta/Auto.luau +295 -253
- package/src/codec/meta/Bitfield.luau +104 -148
- package/src/codec/meta/Custom.luau +8 -4
- package/src/codec/meta/Enum.luau +29 -57
- package/src/codec/meta/Float.luau +64 -0
- package/src/codec/meta/Nothing.luau +9 -5
- package/src/codec/meta/Unknown.luau +44 -35
- package/src/codec/primitive/Bool.luau +16 -26
- package/src/codec/primitive/Float16.luau +58 -64
- package/src/codec/primitive/Int.luau +68 -0
- package/src/codec/primitive/Number.luau +21 -43
- package/src/codec/primitive/Varint.luau +67 -46
- package/src/index.d.ts +249 -306
- package/src/init.luau +332 -173
- package/src/internal/Baseline.luau +29 -24
- package/src/internal/Channel.luau +346 -161
- package/src/internal/Middleware.luau +60 -85
- package/src/internal/Pool.luau +19 -30
- package/src/internal/Registry.luau +61 -101
- package/src/transport/Bridge.luau +64 -43
- package/src/transport/Client.luau +60 -117
- package/src/transport/Gate.luau +282 -133
- package/src/transport/Reader.luau +159 -100
- package/src/transport/Server.luau +147 -292
- package/src/api/Namespace.luau +0 -251
- package/src/codec/meta/Quantized.luau +0 -174
|
@@ -1,152 +1,95 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--!optimize 2
|
|
3
|
-
-- Client-side transport
|
|
3
|
+
-- Client-side transport: single channel pair, flush.
|
|
4
4
|
|
|
5
|
-
local
|
|
6
|
-
|
|
7
|
-
local Bridge = require(script.Parent.Bridge)
|
|
5
|
+
local Bridge = require(script.Parent.Parent.transport.Bridge)
|
|
8
6
|
local Channel = require(script.Parent.Parent.internal.Channel)
|
|
9
|
-
local
|
|
10
|
-
local Reader = require(script.Parent.Reader)
|
|
7
|
+
local Reader = require(script.Parent.Parent.transport.Reader)
|
|
11
8
|
local Types = require(script.Parent.Parent.Types)
|
|
12
9
|
|
|
13
|
-
type ChannelState = Types.ChannelState
|
|
14
|
-
type Codec<T> = Types.Codec<T>
|
|
15
|
-
|
|
16
10
|
-- State ---------------------------------------------------------------
|
|
17
11
|
|
|
18
|
-
local
|
|
19
|
-
|
|
20
|
-
local
|
|
21
|
-
local
|
|
22
|
-
local _prevRecv = nil :: buffer?
|
|
23
|
-
local _isStarted = false
|
|
12
|
+
local _reliable: Types.ChannelState = Channel.create()
|
|
13
|
+
local _unreliable: Types.ChannelState = Channel.create()
|
|
14
|
+
local _prevIncoming: buffer? = nil
|
|
15
|
+
local _prevIncomingLen = 0
|
|
24
16
|
|
|
25
|
-
--
|
|
26
|
-
|
|
27
|
-
local function receive(data: any, refs: any, applyXor: boolean): ()
|
|
28
|
-
local buf = Reader.decodeIncoming(data)
|
|
29
|
-
if not buf then
|
|
30
|
-
return
|
|
31
|
-
end
|
|
17
|
+
-- Public --------------------------------------------------------------
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
if applyXor then
|
|
35
|
-
raw = Channel.xorApply(buf, _prevRecv)
|
|
36
|
-
_prevRecv = raw
|
|
37
|
-
else
|
|
38
|
-
raw = buf
|
|
39
|
-
end
|
|
19
|
+
local Client = {}
|
|
40
20
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if not ok then
|
|
44
|
-
warn(`[Lync] Read failed: {err}`)
|
|
45
|
-
end
|
|
21
|
+
function Client.getChannel(isUnreliable: boolean): Types.ChannelState
|
|
22
|
+
return if isUnreliable then _unreliable else _reliable
|
|
46
23
|
end
|
|
47
24
|
|
|
48
|
-
|
|
49
|
-
if
|
|
50
|
-
|
|
25
|
+
function Client.flush(): ()
|
|
26
|
+
if Channel.hasTimestamps() then
|
|
27
|
+
Channel.updateTimestamp()
|
|
51
28
|
end
|
|
52
29
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
remote:FireServer(xored, refs)
|
|
59
|
-
else
|
|
60
|
-
remote:FireServer(raw, refs)
|
|
30
|
+
-- Reliable
|
|
31
|
+
if _reliable.cursor > 0 then
|
|
32
|
+
local snapshot, refs, byteLen, _ = Channel.sealAndDump(_reliable)
|
|
33
|
+
Bridge.fireServer(snapshot, refs)
|
|
34
|
+
Channel.reset(_reliable)
|
|
61
35
|
end
|
|
62
36
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
37
|
+
-- Unreliable
|
|
38
|
+
if _unreliable.cursor > 0 then
|
|
39
|
+
local snapshot, refs, byteLen, _ = Channel.sealAndDump(_unreliable)
|
|
40
|
+
Bridge.fireServerUnreliable(snapshot, refs)
|
|
41
|
+
Channel.reset(_unreliable)
|
|
42
|
+
end
|
|
69
43
|
end
|
|
70
44
|
|
|
71
|
-
-- Public --------------------------------------------------------------
|
|
72
|
-
|
|
73
|
-
local Client = {}
|
|
74
|
-
|
|
75
45
|
function Client.start(): ()
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
_isStarted = true
|
|
46
|
+
local container = game:GetService("ReplicatedStorage"):WaitForChild("LyncRemotes")
|
|
47
|
+
Bridge.setup(container)
|
|
80
48
|
|
|
81
|
-
Bridge.
|
|
49
|
+
local reliable = Bridge.reliable()
|
|
50
|
+
local unreliable = Bridge.unreliable()
|
|
82
51
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Bridge.unreliable.OnClientEvent:Connect(function(data: any, refs: any): ()
|
|
90
|
-
receive(data, refs, false)
|
|
91
|
-
end)
|
|
92
|
-
RunService.Heartbeat:Connect(flush)
|
|
93
|
-
end
|
|
52
|
+
-- Incoming reliable (XOR encoded)
|
|
53
|
+
reliable.OnClientEvent:Connect(function(data: any, refs: any?)
|
|
54
|
+
local incoming = Reader.decodeIncoming(data)
|
|
55
|
+
if not incoming then
|
|
56
|
+
return
|
|
57
|
+
end
|
|
94
58
|
|
|
95
|
-
|
|
96
|
-
id: number,
|
|
97
|
-
name: string,
|
|
98
|
-
codec: Codec<any>,
|
|
99
|
-
data: any,
|
|
100
|
-
isUnreliable: boolean
|
|
101
|
-
): ()
|
|
102
|
-
if not _isStarted then
|
|
103
|
-
error(NOT_STARTED)
|
|
104
|
-
end
|
|
59
|
+
local incomingLen = buffer.len(incoming)
|
|
105
60
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
61
|
+
-- XOR decode against previous frame
|
|
62
|
+
local decoded: buffer
|
|
63
|
+
if _prevIncoming then
|
|
64
|
+
decoded = Channel.xorApply(incoming, incomingLen, _prevIncoming, _prevIncomingLen)
|
|
65
|
+
else
|
|
66
|
+
decoded = incoming
|
|
111
67
|
end
|
|
112
|
-
else
|
|
113
|
-
final = data
|
|
114
|
-
end
|
|
115
68
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
69
|
+
-- Store decoded (not XOR'd) for next frame's XOR base
|
|
70
|
+
_prevIncoming = decoded
|
|
71
|
+
_prevIncomingLen = incomingLen
|
|
119
72
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
codec: Codec<any>,
|
|
126
|
-
data: any
|
|
127
|
-
): ()
|
|
128
|
-
if not _isStarted then
|
|
129
|
-
error(NOT_STARTED)
|
|
130
|
-
end
|
|
73
|
+
local ok, err = pcall(Reader.process, decoded, incomingLen, refs :: any, nil, false)
|
|
74
|
+
if not ok then
|
|
75
|
+
warn(`[Lync] Client: read error: {err}`)
|
|
76
|
+
end
|
|
77
|
+
end)
|
|
131
78
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if
|
|
79
|
+
-- Incoming unreliable (no XOR)
|
|
80
|
+
unreliable.OnClientEvent:Connect(function(data: any, refs: any?)
|
|
81
|
+
local incoming = Reader.decodeIncoming(data)
|
|
82
|
+
if not incoming then
|
|
136
83
|
return
|
|
137
84
|
end
|
|
138
|
-
else
|
|
139
|
-
final = data
|
|
140
|
-
end
|
|
141
85
|
|
|
142
|
-
|
|
143
|
-
end
|
|
86
|
+
local incomingLen = buffer.len(incoming)
|
|
144
87
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
88
|
+
local ok, err = pcall(Reader.process, incoming, incomingLen, refs :: any, nil, false)
|
|
89
|
+
if not ok then
|
|
90
|
+
warn(`[Lync] Client: read error (unreliable): {err}`)
|
|
91
|
+
end
|
|
92
|
+
end)
|
|
150
93
|
end
|
|
151
94
|
|
|
152
95
|
return table.freeze(Client)
|