@axpecter/lync 1.4.0 → 1.4.1

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.
Files changed (40) hide show
  1. package/README.md +24 -24
  2. package/package.json +1 -1
  3. package/src/Types.luau +13 -2
  4. package/src/api/Group.luau +3 -5
  5. package/src/api/Namespace.luau +6 -6
  6. package/src/api/Packet.luau +9 -8
  7. package/src/api/Query.luau +11 -9
  8. package/src/api/Scope.luau +2 -2
  9. package/src/api/Signal.luau +10 -4
  10. package/src/codec/Base.luau +7 -3
  11. package/src/codec/composite/Array.luau +18 -15
  12. package/src/codec/composite/Map.luau +45 -31
  13. package/src/codec/composite/Optional.luau +3 -2
  14. package/src/codec/composite/Shared.luau +7 -5
  15. package/src/codec/composite/Struct.luau +6 -4
  16. package/src/codec/composite/Tagged.luau +6 -6
  17. package/src/codec/composite/Tuple.luau +9 -7
  18. package/src/codec/datatype/Buffer.luau +3 -2
  19. package/src/codec/datatype/CFrame.luau +2 -1
  20. package/src/codec/datatype/Instance.luau +3 -2
  21. package/src/codec/datatype/Sequence.luau +3 -4
  22. package/src/codec/datatype/String.luau +3 -6
  23. package/src/codec/meta/Auto.luau +77 -72
  24. package/src/codec/meta/Bitfield.luau +5 -4
  25. package/src/codec/meta/Enum.luau +6 -5
  26. package/src/codec/meta/Quantized.luau +5 -4
  27. package/src/codec/meta/Unknown.luau +5 -1
  28. package/src/codec/primitive/Float16.luau +5 -4
  29. package/src/codec/primitive/Varint.luau +2 -2
  30. package/src/init.luau +39 -37
  31. package/src/internal/Baseline.luau +6 -2
  32. package/src/internal/Channel.luau +11 -6
  33. package/src/internal/Middleware.luau +13 -12
  34. package/src/internal/Pool.luau +5 -5
  35. package/src/internal/Registry.luau +4 -4
  36. package/src/transport/Bridge.luau +4 -3
  37. package/src/transport/Client.luau +4 -3
  38. package/src/transport/Gate.luau +5 -5
  39. package/src/transport/Reader.luau +3 -3
  40. package/src/transport/Server.luau +7 -8
@@ -6,7 +6,7 @@ local Types = require (script.Parent.Parent.Types)
6
6
 
7
7
  type ChannelState = Types.ChannelState
8
8
 
9
- -- Constants --------------------------------------------------------------
9
+ -- Constants ----------------------------------------------------------
10
10
 
11
11
  local INITIAL_SIZE = 1024
12
12
  local MAX_SIZE = 262144
@@ -18,12 +18,15 @@ local band32 = bit32.band
18
18
  local countlz = bit32.countlz
19
19
  local lshift = bit32.lshift
20
20
 
21
- -- State ------------------------------------------------------------------
21
+ -- State --------------------------------------------------------------
22
22
 
23
23
  local _maxSize = MAX_SIZE
24
+
25
+ -- Packet name for overflow diagnostics. Not coroutine-safe: concurrent
26
+ -- serializers may overwrite before the error fires.
24
27
  local _currentPacket = ""
25
28
 
26
- -- Public -----------------------------------------------------------------
29
+ -- Public -------------------------------------------------------------
27
30
 
28
31
  local Channel = {}
29
32
 
@@ -163,9 +166,11 @@ local function sealOpen (ch: ChannelState): ()
163
166
  end
164
167
  end
165
168
 
166
- -- Writes a query frame. Seals any open batch, then writes:
167
- -- id (u8) + correlationId (u16) + status (u8)
168
- -- Status 0 = payload follows. Status 1 = nil response.
169
+ --[[
170
+ Writes a query frame. Seals any open batch, then writes:
171
+ id (u8) + correlationId (u16) + status (u8)
172
+ Status 0 = payload follows. Status 1 = nil response.
173
+ ]]
169
174
  function Channel.writeQuery (
170
175
  ch: ChannelState,
171
176
  id: number,
@@ -2,8 +2,6 @@
2
2
  --!optimize 2
3
3
  -- Ordered intercept chains for send and receive.
4
4
 
5
- -- State ------------------------------------------------------------------
6
-
7
5
  type Handler = (data: any, name: string, player: Player?) -> any?
8
6
 
9
7
  type Chain = {
@@ -11,14 +9,16 @@ type Chain = {
11
9
  snapshot: { Handler }?,
12
10
  }
13
11
 
14
- local _send: Chain = { handlers = {}, snapshot = nil }
15
- local _receive: Chain = { handlers = {}, snapshot = nil }
16
-
17
- -- Constants --------------------------------------------------------------
12
+ -- Constants ----------------------------------------------------------
18
13
 
19
14
  local DROP = table.freeze ({ _tag = "drop" })
20
15
 
21
- -- Private ----------------------------------------------------------------
16
+ -- State --------------------------------------------------------------
17
+
18
+ local _send: Chain = { handlers = {}, snapshot = nil }
19
+ local _receive: Chain = { handlers = {}, snapshot = nil }
20
+
21
+ -- Private ------------------------------------------------------------
22
22
 
23
23
  local function runChain (chain: { Handler }, data: any, name: string, player: Player?): any?
24
24
  local current = data
@@ -79,10 +79,14 @@ local function addTo (chain: Chain, fn: Handler): () -> ()
79
79
  end
80
80
  end
81
81
 
82
- -- Public -----------------------------------------------------------------
82
+ -- Public -------------------------------------------------------------
83
83
 
84
84
  local Middleware = {}
85
85
 
86
+ Middleware.hasSend = false
87
+ Middleware.hasReceive = false
88
+ Middleware.DROP = DROP
89
+
86
90
  function Middleware.addSend (fn: Handler): () -> ()
87
91
  local remover = addTo (_send, fn)
88
92
  Middleware.hasSend = true
@@ -111,8 +115,5 @@ function Middleware.runReceive (data: any, name: string, player: Player?): any?
111
115
  return run (_receive, data, name, player)
112
116
  end
113
117
 
114
- Middleware.hasSend = false
115
- Middleware.hasReceive = false
116
- Middleware.DROP = DROP
117
-
118
+ -- Not frozen: hasSend and hasReceive are mutated at runtime.
118
119
  return Middleware
@@ -7,24 +7,24 @@ local Types = require (script.Parent.Parent.Types)
7
7
 
8
8
  type ChannelState = Types.ChannelState
9
9
 
10
- -- Constants --------------------------------------------------------------
10
+ -- Constants ----------------------------------------------------------
11
11
 
12
12
  local DEFAULT_MAX = 16
13
13
 
14
- -- State ------------------------------------------------------------------
14
+ -- State --------------------------------------------------------------
15
15
 
16
16
  local _stack = {} :: { ChannelState }
17
17
  local _depth = 0
18
18
  local _maxSize = DEFAULT_MAX
19
19
 
20
- -- Public -----------------------------------------------------------------
20
+ -- Public -------------------------------------------------------------
21
21
 
22
22
  local Pool = {}
23
23
 
24
- -- Override the max idle ChannelStates in the pool. Default 16. Range: 2128.
24
+ -- Override the max idle ChannelStates in the pool. Default 16. Range: 2-128.
25
25
  function Pool.setMaxSize (count: number): ()
26
26
  if count < 2 or count > 128 then
27
- error (`[Lync] Pool max size must be 2128, got {count}`)
27
+ error (`[Lync] Pool max size must be 2-128, got {count}`)
28
28
  end
29
29
  _maxSize = count
30
30
  end
@@ -8,20 +8,20 @@ type Codec<T> = Types.Codec<T>
8
8
  type Registration = Types.Registration
9
9
  type RateLimitConfig = Types.RateLimitConfig
10
10
 
11
- -- Constants --------------------------------------------------------------
11
+ -- Constants ----------------------------------------------------------
12
12
 
13
13
  local KIND_PACKET = 0
14
14
  local KIND_REQUEST = 1
15
15
  local KIND_RESPONSE = 2
16
16
  local MAX_PACKETS = 255
17
17
 
18
- -- State ------------------------------------------------------------------
18
+ -- State --------------------------------------------------------------
19
19
 
20
20
  local _entries = {} :: { Registration }
21
21
  local _names = {} :: { [string]: number }
22
22
  local _nextId = 1
23
23
 
24
- -- Private ----------------------------------------------------------------
24
+ -- Private ------------------------------------------------------------
25
25
 
26
26
  local function assign (
27
27
  name: string,
@@ -77,7 +77,7 @@ local function assign (
77
77
  return reg
78
78
  end
79
79
 
80
- -- Public -----------------------------------------------------------------
80
+ -- Public -------------------------------------------------------------
81
81
 
82
82
  local Registry = {
83
83
  KIND_PACKET = KIND_PACKET,
@@ -5,19 +5,19 @@
5
5
  local ReplicatedStorage = game:GetService ("ReplicatedStorage")
6
6
  local RunService = game:GetService ("RunService")
7
7
 
8
- -- Constants --------------------------------------------------------------
8
+ -- Constants ----------------------------------------------------------
9
9
 
10
10
  local FOLDER = "_lync"
11
11
  local RELIABLE = "R"
12
12
  local UNRELIABLE = "U"
13
13
  local TIMEOUT = 10
14
14
 
15
- -- State ------------------------------------------------------------------
15
+ -- State --------------------------------------------------------------
16
16
 
17
17
  local _reliable: RemoteEvent
18
18
  local _unreliable: UnreliableRemoteEvent
19
19
 
20
- -- Public -----------------------------------------------------------------
20
+ -- Public -------------------------------------------------------------
21
21
 
22
22
  local Bridge = {}
23
23
 
@@ -63,4 +63,5 @@ function Bridge.setup (): ()
63
63
  table.freeze (Bridge)
64
64
  end
65
65
 
66
+ -- Not frozen at module level: setup() populates reliable/unreliable then freezes.
66
67
  return Bridge
@@ -13,15 +13,16 @@ local Types = require (script.Parent.Parent.Types)
13
13
  type ChannelState = Types.ChannelState
14
14
  type Codec<T> = Types.Codec<T>
15
15
 
16
- -- State ------------------------------------------------------------------
16
+ -- State --------------------------------------------------------------
17
17
 
18
18
  local NOT_STARTED = "[Lync] Client not started. Call Lync.start() before sending"
19
+
19
20
  local _reliable = nil :: ChannelState?
20
21
  local _unreliable = nil :: ChannelState?
21
22
  local _prevRecv = nil :: buffer?
22
23
  local _isStarted = false
23
24
 
24
- -- Private ----------------------------------------------------------------
25
+ -- Private ------------------------------------------------------------
25
26
 
26
27
  local function receive (data: any, refs: any, applyXor: boolean): ()
27
28
  local buf = Reader.decodeIncoming (data)
@@ -67,7 +68,7 @@ local function flush (): ()
67
68
  flushChannel (Bridge.unreliable, _unreliable :: ChannelState, false)
68
69
  end
69
70
 
70
- -- Public -----------------------------------------------------------------
71
+ -- Public -------------------------------------------------------------
71
72
 
72
73
  local Client = {}
73
74
 
@@ -7,7 +7,7 @@ local Types = require (script.Parent.Parent.Types)
7
7
  type Registration = Types.Registration
8
8
  type RateLimitConfig = Types.RateLimitConfig
9
9
 
10
- -- Constants --------------------------------------------------------------
10
+ -- Constants ----------------------------------------------------------
11
11
 
12
12
  local DEFAULT_MAX_DEPTH = 16
13
13
 
@@ -15,7 +15,7 @@ local isfinite = math.isfinite
15
15
  local min = math.min
16
16
  local clock = os.clock
17
17
 
18
- -- State ------------------------------------------------------------------
18
+ -- State --------------------------------------------------------------
19
19
 
20
20
  type Bucket = {
21
21
  tokens: number,
@@ -27,7 +27,7 @@ local _buckets = {} :: { [Player]: { [number]: Bucket } }
27
27
  local _dropHandlers =
28
28
  {} :: { (player: Player, reason: string, packetName: string, data: any?) -> () }
29
29
 
30
- -- Private ----------------------------------------------------------------
30
+ -- Private ------------------------------------------------------------
31
31
 
32
32
  local function fireDrop (player: Player, reason: string, packetName: string, data: any?): ()
33
33
  for _, handler in _dropHandlers do
@@ -47,7 +47,7 @@ local function isClean (value: any, depth: number): boolean
47
47
  return isfinite (value)
48
48
  end
49
49
 
50
- -- String, boolean, nil are always clean . Exit before table/vector/userdata checks
50
+ -- String, boolean, nil are always clean. Exit before table/vector/userdata checks.
51
51
  if t == "string" or t == "boolean" or t == "nil" then
52
52
  return true
53
53
  end
@@ -152,7 +152,7 @@ local function checkRate (player: Player, reg: Registration): boolean
152
152
  return false
153
153
  end
154
154
 
155
- -- Public -----------------------------------------------------------------
155
+ -- Public -------------------------------------------------------------
156
156
 
157
157
  local Gate = {}
158
158
 
@@ -11,14 +11,14 @@ local registryGet = Registry.get
11
11
  local gateCheck = Gate.check
12
12
  local gateReportDrop = Gate.reportDrop
13
13
 
14
- -- Constants --------------------------------------------------------------
14
+ -- Constants ----------------------------------------------------------
15
15
 
16
16
  local KIND_PACKET = Registry.KIND_PACKET
17
17
  local KIND_REQUEST = Registry.KIND_REQUEST
18
18
 
19
19
  local MAX_INCOMING = 65536
20
20
 
21
- -- Public -----------------------------------------------------------------
21
+ -- Public -------------------------------------------------------------
22
22
 
23
23
  local Reader = {}
24
24
 
@@ -126,7 +126,7 @@ function Reader.process (
126
126
  end
127
127
  else
128
128
  -- Query frame: id(u8, already read) + correlationId(u16) + status(u8) = 3 more bytes
129
- if pos + 2 >= length then
129
+ if pos + 3 > length then
130
130
  break
131
131
  end
132
132
 
@@ -8,11 +8,6 @@ local RunService = game:GetService ("RunService")
8
8
  local Baseline = require (script.Parent.Parent.internal.Baseline)
9
9
  local Bridge = require (script.Parent.Bridge)
10
10
  local Channel = require (script.Parent.Parent.internal.Channel)
11
-
12
- local channelWriteBatch = Channel.writeBatch
13
- local channelWriteBatchRaw = Channel.writeBatchRaw
14
- local channelSetPacket = Channel.setCurrentPacket
15
-
16
11
  local Gate = require (script.Parent.Gate)
17
12
  local Middleware = require (script.Parent.Parent.internal.Middleware)
18
13
  local Pool = require (script.Parent.Parent.internal.Pool)
@@ -22,7 +17,11 @@ local Types = require (script.Parent.Parent.Types)
22
17
  type ChannelState = Types.ChannelState
23
18
  type Codec<T> = Types.Codec<T>
24
19
 
25
- -- State ------------------------------------------------------------------
20
+ local channelWriteBatch = Channel.writeBatch
21
+ local channelWriteBatchRaw = Channel.writeBatchRaw
22
+ local channelSetPacket = Channel.setCurrentPacket
23
+
24
+ -- State --------------------------------------------------------------
26
25
 
27
26
  type PlayerState = {
28
27
  reliable: ChannelState,
@@ -34,7 +33,7 @@ local _prevRecv = {} :: { [Player]: buffer }
34
33
  local _isStarted = false
35
34
  local _broadScratch = Channel.create ()
36
35
 
37
- -- Private ----------------------------------------------------------------
36
+ -- Private ------------------------------------------------------------
38
37
 
39
38
  local function onPlayerAdded (player: Player): ()
40
39
  _players[player] = {
@@ -227,7 +226,7 @@ local function broadcastToSet (
227
226
  end
228
227
  end
229
228
 
230
- -- Public -----------------------------------------------------------------
229
+ -- Public -------------------------------------------------------------
231
230
 
232
231
  local Server = {}
233
232