@netifyjs/protocol 1.0.0-alpha.2 → 1.0.0-beta.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 (183) hide show
  1. package/package.json +2 -2
  2. package/src/codec/index.ts +82 -157
  3. package/src/dispatch/dispatcher/index.ts +116 -33
  4. package/src/dispatch/session/index.ts +9 -3
  5. package/src/index.ts +2 -4
  6. package/src/photon/balancing/codec/index.ts +27 -53
  7. package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
  8. package/src/photon/balancing/format/friends/request/index.ts +21 -5
  9. package/src/photon/balancing/format/game/create/request/index.ts +45 -8
  10. package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
  11. package/src/photon/balancing/format/game/join/request/index.ts +65 -13
  12. package/src/photon/balancing/format/game/list/request/index.ts +29 -3
  13. package/src/photon/balancing/format/game/random/request/index.ts +58 -10
  14. package/src/photon/balancing/format/groups/request/index.ts +19 -3
  15. package/src/photon/balancing/format/index.ts +7 -0
  16. package/src/photon/balancing/format/leave/request/index.ts +19 -3
  17. package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
  18. package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
  19. package/src/photon/balancing/format/once/request/index.ts +31 -8
  20. package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
  21. package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
  22. package/src/photon/balancing/format/raise/request/index.ts +76 -10
  23. package/src/photon/balancing/format/reader/index.ts +75 -6
  24. package/src/photon/balancing/format/regions/request/index.ts +16 -1
  25. package/src/photon/balancing/format/rpc/request/index.ts +26 -3
  26. package/src/photon/balancing/format/settings/request/index.ts +15 -2
  27. package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
  28. package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
  29. package/src/photon/balancing/format/shared/options/index.ts +56 -24
  30. package/src/photon/balancing/format/table/index.ts +399 -0
  31. package/src/photon/balancing/index.ts +11 -1
  32. package/src/photon/balancing/travel/index.ts +15 -12
  33. package/src/photon/binary/v18/index.ts +26 -1
  34. package/src/photon/binary/value/index.ts +52 -3
  35. package/src/photon/client/connection/index.ts +6 -6
  36. package/src/photon/cluster/back/index.ts +32 -45
  37. package/src/photon/cluster/dresser/index.ts +7 -8
  38. package/src/photon/cluster/front/index.ts +25 -49
  39. package/src/photon/cluster/grid/index.ts +1 -1
  40. package/src/photon/cluster/mover/index.ts +12 -12
  41. package/src/photon/cluster/press/index.ts +2 -18
  42. package/src/photon/cluster/route/game/index.ts +9 -11
  43. package/src/photon/cluster/route/master/index.ts +15 -34
  44. package/src/photon/cluster/route/name/index.ts +4 -21
  45. package/src/photon/cluster/seat/game/index.ts +6 -26
  46. package/src/photon/cluster/seat/master/index.ts +1 -1
  47. package/src/photon/cluster/sessions/index.ts +5 -6
  48. package/src/photon/cluster/spread/index.ts +8 -147
  49. package/src/photon/enet/client/index.ts +1 -8
  50. package/src/photon/enet/gateway/index.ts +5 -15
  51. package/src/photon/enet/index.ts +1 -1
  52. package/src/photon/enet/link/index.ts +34 -15
  53. package/src/photon/enet/outbound/index.ts +279 -0
  54. package/src/photon/enet/peer/index.ts +59 -0
  55. package/src/photon/enet/transport/index.ts +8 -24
  56. package/src/photon/game/admission/index.ts +353 -0
  57. package/src/photon/game/bag/index.ts +13 -0
  58. package/src/photon/game/broadcast/index.ts +79 -0
  59. package/src/photon/game/editor/index.ts +446 -0
  60. package/src/photon/game/gate/index.ts +9 -8
  61. package/src/photon/game/handler/index.ts +30 -3
  62. package/src/photon/game/history/index.ts +234 -0
  63. package/src/photon/game/hooked/index.ts +16 -15
  64. package/src/photon/game/index.ts +12 -1
  65. package/src/photon/game/lifecycle/index.ts +193 -0
  66. package/src/photon/game/peer/index.ts +1 -10
  67. package/src/photon/game/properties/index.ts +342 -0
  68. package/src/photon/game/room/index.ts +435 -1793
  69. package/src/photon/game/rooms/index.ts +2 -1
  70. package/src/photon/game/seats/index.ts +237 -0
  71. package/src/photon/game/server/index.ts +12 -2
  72. package/src/photon/game/services/index.ts +41 -0
  73. package/src/photon/game/settings/index.ts +22 -0
  74. package/src/photon/game/snapshot/index.ts +133 -0
  75. package/src/photon/game/throttle/index.ts +60 -0
  76. package/src/photon/game/touch/index.ts +2 -5
  77. package/src/photon/game/venue/index.ts +31 -0
  78. package/src/photon/master/application/index.ts +7 -0
  79. package/src/photon/master/gate/index.ts +12 -8
  80. package/src/photon/master/handler/index.ts +36 -748
  81. package/src/photon/master/index.ts +5 -0
  82. package/src/photon/master/list/sql/index.ts +37 -3
  83. package/src/photon/master/listing/index.ts +133 -0
  84. package/src/photon/master/lobby/index.ts +9 -0
  85. package/src/photon/master/login/index.ts +424 -0
  86. package/src/photon/master/matchmaking/index.ts +282 -0
  87. package/src/photon/master/query/index.ts +45 -0
  88. package/src/photon/master/redirect/index.ts +8 -7
  89. package/src/photon/master/services/index.ts +35 -0
  90. package/src/photon/master/settings/index.ts +44 -0
  91. package/src/photon/master/sql/cost/index.ts +263 -0
  92. package/src/photon/master/sql/index.ts +1 -0
  93. package/src/photon/message/binary/index.ts +35 -1
  94. package/src/photon/message/client/index.ts +14 -11
  95. package/src/photon/message/format/index.ts +9 -0
  96. package/src/photon/message/handler/index.ts +48 -63
  97. package/src/photon/message/pipeline/index.ts +12 -12
  98. package/src/photon/message/server/index.ts +87 -43
  99. package/src/photon/message/watch/index.ts +127 -15
  100. package/src/photon/server/config/index.ts +5 -0
  101. package/src/photon/server/deferral/index.ts +57 -0
  102. package/src/photon/server/host/index.ts +36 -10
  103. package/src/photon/server/index.ts +1 -0
  104. package/src/photon/server/listeners/index.ts +11 -0
  105. package/src/photon/tcp/client/index.ts +1 -1
  106. package/src/photon/tcp/codec/index.ts +41 -38
  107. package/src/photon/tcp/framing/index.ts +24 -4
  108. package/src/photon/tcp/server/index.ts +4 -4
  109. package/src/photon/websocket/bridge/index.ts +16 -20
  110. package/src/photon/websocket/message/index.ts +27 -39
  111. package/src/photon/websocket/path/index.ts +2 -5
  112. package/src/scale/batch/index.ts +14 -6
  113. package/src/scale/fanout/index.ts +6 -6
  114. package/src/scale/index.ts +2 -4
  115. package/src/scale/outbound/index.ts +192 -0
  116. package/src/scale/relay/index.ts +24 -16
  117. package/src/scale/sink/index.ts +6 -11
  118. package/src/scale/transport/index.ts +27 -44
  119. package/src/scale/tunnel/index.ts +56 -86
  120. package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
  121. package/src/smartfox/common/bluebox/index.ts +4 -0
  122. package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
  123. package/src/smartfox/common/index.ts +5 -0
  124. package/src/smartfox/common/strikes/index.ts +74 -0
  125. package/src/smartfox/pro/bluebox/index.ts +176 -4
  126. package/src/smartfox/pro/codec/index.ts +8 -7
  127. package/src/smartfox/pro/escalation/index.ts +28 -20
  128. package/src/smartfox/pro/flood/index.ts +2 -2
  129. package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
  130. package/src/smartfox/pro/handler/chat/index.ts +11 -8
  131. package/src/smartfox/pro/handler/login/index.ts +2 -25
  132. package/src/smartfox/pro/handler/shared/index.ts +4 -3
  133. package/src/smartfox/pro/index.ts +11 -5
  134. package/src/smartfox/pro/login/gate/index.ts +166 -0
  135. package/src/smartfox/pro/login/index.ts +1 -0
  136. package/src/smartfox/pro/moderation/index.ts +220 -0
  137. package/src/smartfox/pro/options/index.ts +5 -5
  138. package/src/smartfox/pro/protocol/index.ts +62 -8
  139. package/src/smartfox/pro/web/index.ts +33 -26
  140. package/src/smartfox/pro/zone/index.ts +59 -282
  141. package/src/smartfox/pro/zones/index.ts +3 -3
  142. package/src/smartfox/x2/bluebox/index.ts +149 -4
  143. package/src/smartfox/x2/chat/index.ts +9 -19
  144. package/src/smartfox/x2/codec/index.ts +34 -40
  145. package/src/smartfox/x2/config/index.ts +6 -1
  146. package/src/smartfox/x2/data/array/index.ts +96 -60
  147. package/src/smartfox/x2/data/object/index.ts +144 -82
  148. package/src/smartfox/x2/data/serializer/index.ts +41 -23
  149. package/src/smartfox/x2/flood/gate/index.ts +19 -13
  150. package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
  151. package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
  152. package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
  153. package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
  154. package/src/smartfox/x2/format/login/response/index.ts +4 -3
  155. package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
  156. package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
  157. package/src/smartfox/x2/games/index.ts +35 -8
  158. package/src/smartfox/x2/hall/index.ts +0 -6
  159. package/src/smartfox/x2/handler/session/index.ts +1 -1
  160. package/src/smartfox/x2/index.ts +8 -3
  161. package/src/smartfox/x2/member/index.ts +10 -3
  162. package/src/smartfox/x2/packet/login/response/index.ts +12 -0
  163. package/src/smartfox/x2/protocol/index.ts +11 -1
  164. package/src/smartfox/x2/rooms/index.ts +1 -2
  165. package/src/smartfox/x2/sessions/index.ts +6 -0
  166. package/src/smartfox/x2/udp/index.ts +61 -24
  167. package/src/smartfox/x2/web/index.ts +35 -17
  168. package/src/smartfox/x2/websocket/index.ts +18 -36
  169. package/src/smartfox/x2/zone/index.ts +77 -28
  170. package/src/smartfox/x2/zones/index.ts +17 -5
  171. package/src/photon/enet/handler/index.ts +0 -65
  172. package/src/scale/hosted/index.ts +0 -68
  173. package/src/scale/outlet/index.ts +0 -121
  174. package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
  175. package/src/smartfox/pro/bluebox/session/index.ts +0 -63
  176. package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
  177. package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
  178. /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
  179. /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
  180. /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
  181. /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
  182. /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
  183. /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
@@ -3,7 +3,6 @@ import {
3
3
  DuplexHandlerAdapter,
4
4
  type HandlerContext,
5
5
  IdleStateEvent,
6
- pending,
7
6
  } from '@netifyjs/netify'
8
7
 
9
8
  import { ConnectionProtocol } from '../../crypto/protocol/index.ts'
@@ -43,13 +42,13 @@ export class BackBridge extends DuplexHandlerAdapter {
43
42
  * @param context the connection
44
43
  * @param message packed messages, or anything else
45
44
  */
46
- public override channelRead(
47
- context: HandlerContext,
48
- message: unknown,
49
- ): void | Promise<void> {
50
- if (!(message instanceof ByteBuf)) return context.fireChannelRead(message)
45
+ public override channelRead(context: HandlerContext, message: unknown): void {
46
+ if (!(message instanceof ByteBuf)) {
47
+ context.fireChannelRead(message)
48
+ return
49
+ }
51
50
 
52
- return this.pass(
51
+ this.pass(
53
52
  context,
54
53
  Carriage.unpack(message.readBytes(message.readableBytes)),
55
54
  0,
@@ -57,7 +56,7 @@ export class BackBridge extends DuplexHandlerAdapter {
57
56
  }
58
57
 
59
58
  /**
60
- * Hands on everything a run of bytes carried, in order
59
+ * Hands on everything a run of bytes carried in order, stopping while reads are paused
61
60
  * @param context the connection
62
61
  * @param cargoes what was unpacked
63
62
  * @param from the first one still to go
@@ -66,17 +65,19 @@ export class BackBridge extends DuplexHandlerAdapter {
66
65
  context: HandlerContext,
67
66
  cargoes: readonly Cargo[],
68
67
  from: number,
69
- ): void | Promise<void> {
70
- for (let index = from; index < cargoes.length; index++) {
71
- const cargo = cargoes[index]
72
- if (cargo === undefined) continue
68
+ ): void {
69
+ const channel = context.channel
73
70
 
74
- const handed = pending(this.hand(context, cargo))
75
- if (handed !== null) {
76
- return handed.then((): void | Promise<void> =>
77
- this.pass(context, cargoes, index + 1),
78
- )
71
+ for (let index = from; index < cargoes.length; index++) {
72
+ if (index > from && channel.isReadPaused && channel.isActive) {
73
+ channel.deferRead((): void => {
74
+ this.pass(context, cargoes, index)
75
+ })
76
+ return
79
77
  }
78
+
79
+ const cargo = cargoes[index]
80
+ if (cargo !== undefined) this.hand(context, cargo)
80
81
  }
81
82
  }
82
83
 
@@ -85,29 +86,31 @@ export class BackBridge extends DuplexHandlerAdapter {
85
86
  * @param context the connection
86
87
  * @param cargo a message or a note
87
88
  */
88
- private hand(context: HandlerContext, cargo: Cargo): void | Promise<void> {
89
+ private hand(context: HandlerContext, cargo: Cargo): void {
89
90
  if (cargo instanceof EnetClosure) {
90
91
  EnetClosure.note(context.channel, cargo)
91
92
  return
92
93
  }
93
94
 
94
95
  if (cargo === 'introduction') {
95
- return context.fireUserEventTriggered(this.init)
96
+ context.fireUserEventTriggered(this.init)
97
+ return
96
98
  }
97
99
 
98
100
  if (cargo === 'idle') {
99
- return context.fireUserEventTriggered(new IdleStateEvent('reader', true))
101
+ context.fireUserEventTriggered(new IdleStateEvent('reader', true))
102
+ return
100
103
  }
101
104
 
102
105
  const envelope = BackBridge.opened(context, cargo)
103
- if (envelope !== null) return context.fireChannelRead(envelope)
106
+ if (envelope !== null) context.fireChannelRead(envelope)
104
107
  }
105
108
 
106
109
  /**
107
110
  * Notes an ending this shard chose for a client on reliable UDP
108
111
  * @param context the connection
109
112
  */
110
- public override channelInactive(context: HandlerContext): Promise<void> {
113
+ public override channelInactive(context: HandlerContext): void {
111
114
  const channel = context.channel
112
115
  const datagrams =
113
116
  PhotonPeer.of(channel)?.transport === ConnectionProtocol.UDP
@@ -115,7 +118,7 @@ export class BackBridge extends DuplexHandlerAdapter {
115
118
  EnetClosure.note(channel, EnetClosure.local(DisconnectReason.LOGIC))
116
119
  }
117
120
 
118
- return context.fireChannelInactive()
121
+ context.fireChannelInactive()
119
122
  }
120
123
 
121
124
  /**
@@ -123,29 +126,13 @@ export class BackBridge extends DuplexHandlerAdapter {
123
126
  * @param context where the write goes
124
127
  * @param message an envelope, or anything else
125
128
  */
126
- public override write(
127
- context: HandlerContext,
128
- message: unknown,
129
- ): Promise<void> {
130
- if (!(message instanceof Envelope)) return context.write(message)
131
-
132
- return context.write(
133
- ByteBuf.wrap(BackBridge.packed(context, message as Envelope)),
134
- )
135
- }
136
-
137
- /**
138
- * Packs a message for the client's shard, without a promise
139
- * @param context where the write goes
140
- * @param message an envelope, or anything else
141
- */
142
- public writeSync(context: HandlerContext, message: unknown): boolean {
143
- if (!(message instanceof Envelope)) return false
129
+ public override write(context: HandlerContext, message: unknown): void {
130
+ if (!(message instanceof Envelope)) {
131
+ context.write(message)
132
+ return
133
+ }
144
134
 
145
- context.writeSync(
146
- ByteBuf.wrap(BackBridge.packed(context, message as Envelope)),
147
- )
148
- return true
135
+ context.write(BackBridge.packed(context, message as Envelope))
149
136
  }
150
137
 
151
138
  /**
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  type Channel,
3
- type ChannelHandler,
4
3
  type ChannelSetup,
5
4
  type HandlerContext,
6
5
  InboundHandlerAdapter,
@@ -59,8 +58,8 @@ export class Dresser extends InboundHandlerAdapter {
59
58
  * @param outfit adds the cluster's handlers
60
59
  */
61
60
  private static after(setup: ChannelSetup, outfit: Outfit): ChannelSetup {
62
- return async (channel: Channel): Promise<void> => {
63
- await setup(channel)
61
+ return (channel: Channel): void => {
62
+ setup(channel)
64
63
  channel.pipeline.addLast<Dresser>(Dresser.NAME, new Dresser(outfit))
65
64
  }
66
65
  }
@@ -69,15 +68,15 @@ export class Dresser extends InboundHandlerAdapter {
69
68
  * Dresses the pipeline once the message layer is in it
70
69
  * @param context the connection
71
70
  */
72
- public override async channelActive(context: HandlerContext): Promise<void> {
71
+ public override channelActive(context: HandlerContext): void {
73
72
  const pipeline = context.pipeline
74
- if (pipeline.get<ChannelHandler>(MessagePipeline.handler) === null) {
75
- await context.fireChannelActive()
73
+ if (pipeline.get(MessagePipeline.handler) === null) {
74
+ context.fireChannelActive()
76
75
  return
77
76
  }
78
77
 
79
78
  this.outfit(context.channel)
80
- await context.fireChannelActive()
81
- pipeline.remove<Dresser>(context.name)
79
+ context.fireChannelActive()
80
+ pipeline.remove(context.name)
82
81
  }
83
82
  }
@@ -70,27 +70,29 @@ export class FrontBridge extends DuplexHandlerAdapter {
70
70
  * @param context the connection
71
71
  * @param message an envelope, or anything else
72
72
  */
73
- public override channelRead(
74
- context: HandlerContext,
75
- message: unknown,
76
- ): void | Promise<void> {
73
+ public override channelRead(context: HandlerContext, message: unknown): void {
77
74
  if (this.moved && message instanceof WireMessage) {
78
- return message.body instanceof Uint8Array
79
- ? context.fireChannelRead(
80
- ByteBuf.wrap(Carriage.forward(message, message.body)),
81
- )
82
- : context.fireChannelRead(message)
75
+ context.fireChannelRead(
76
+ message.body instanceof Uint8Array
77
+ ? ByteBuf.wrap(Carriage.forward(message, message.body))
78
+ : message,
79
+ )
80
+ return
83
81
  }
84
82
 
85
- if (!(message instanceof Envelope)) return context.fireChannelRead(message)
83
+ if (!(message instanceof Envelope)) {
84
+ context.fireChannelRead(message)
85
+ return
86
+ }
86
87
 
87
88
  const envelope = message as Envelope
88
89
  if (this.moved) {
89
- return context.fireChannelRead(ByteBuf.wrap(Carriage.pack(envelope)))
90
+ context.fireChannelRead(ByteBuf.wrap(Carriage.pack(envelope)))
91
+ return
90
92
  }
91
93
 
92
94
  this.last = envelope
93
- return context.fireChannelRead(message)
95
+ context.fireChannelRead(message)
94
96
  }
95
97
 
96
98
  /**
@@ -98,35 +100,33 @@ export class FrontBridge extends DuplexHandlerAdapter {
98
100
  * @param context the connection
99
101
  * @param event whatever happened
100
102
  */
101
- public override async userEventTriggered(
103
+ public override userEventTriggered(
102
104
  context: HandlerContext,
103
105
  event: unknown,
104
- ): Promise<void> {
106
+ ): void {
105
107
  if (
106
108
  this.moved &&
107
109
  event instanceof IdleStateEvent &&
108
110
  event.state === 'reader'
109
111
  ) {
110
- await context.fireChannelRead(ByteBuf.wrap(Carriage.idle()))
112
+ context.fireChannelRead(ByteBuf.wrap(Carriage.idle()))
111
113
  return
112
114
  }
113
115
 
114
- await context.fireUserEventTriggered(event)
116
+ context.fireUserEventTriggered(event)
115
117
  }
116
118
 
117
119
  /**
118
120
  * Tells a moved session's shard how its client's connection ended
119
121
  * @param context the connection
120
122
  */
121
- public override async channelInactive(
122
- context: HandlerContext,
123
- ): Promise<void> {
123
+ public override channelInactive(context: HandlerContext): void {
124
124
  const closure = EnetPeer.of(context.channel)?.closure ?? null
125
125
  if (this.moved && closure !== null) {
126
- await context.fireChannelRead(ByteBuf.wrap(Carriage.farewell(closure)))
126
+ context.fireChannelRead(ByteBuf.wrap(Carriage.farewell(closure)))
127
127
  }
128
128
 
129
- await context.fireChannelInactive()
129
+ context.fireChannelInactive()
130
130
  }
131
131
 
132
132
  /**
@@ -134,42 +134,18 @@ export class FrontBridge extends DuplexHandlerAdapter {
134
134
  * @param context where the write goes
135
135
  * @param message packed messages, or anything else
136
136
  */
137
- public override write(
138
- context: HandlerContext,
139
- message: unknown,
140
- ): Promise<void> {
141
- if (!(message instanceof ByteBuf)) return context.write(message)
142
-
143
- const plain = FrontBridge.plain(context)
144
- const writes: Promise<void>[] = []
145
- for (const cargo of this.unpack(message)) {
146
- if (!(cargo instanceof Parcel)) continue
147
-
148
- writes.push(context.write(FrontBridge.outbound(cargo, plain)))
149
- }
150
-
151
- return Promise.all(writes).then((): void => undefined)
152
- }
153
-
154
- /**
155
- * Unpacks what a moved session's shard sent, without a promise
156
- * @param context where the write goes
157
- * @param message packed messages, or anything else
158
- */
159
- public writeSync(context: HandlerContext, message: unknown): boolean {
137
+ public override write(context: HandlerContext, message: unknown): void {
160
138
  if (!(message instanceof ByteBuf)) {
161
- context.writeSync(message)
162
- return true
139
+ context.write(message)
140
+ return
163
141
  }
164
142
 
165
143
  const plain = FrontBridge.plain(context)
166
144
  for (const cargo of this.unpack(message)) {
167
145
  if (cargo instanceof Parcel) {
168
- context.writeSync(FrontBridge.outbound(cargo, plain))
146
+ context.write(FrontBridge.outbound(cargo, plain))
169
147
  }
170
148
  }
171
-
172
- return true
173
149
  }
174
150
 
175
151
  /**
@@ -336,10 +336,10 @@ export class Grid {
336
336
  const seat = new GameSeat(
337
337
  server,
338
338
  this.shared ? this.mover : null,
339
- this.spreader,
340
339
  authority,
341
340
  clock,
342
341
  )
342
+ server.broadcaster.reroute(this.spreader)
343
343
  this.sessions.game(seat)
344
344
  this.reporting?.attach((): void => {
345
345
  server.replicate()
@@ -1,8 +1,8 @@
1
1
  import type { Channel, HandlerContext } from '@netifyjs/netify'
2
2
 
3
- import type { PacketDispatcher } from '../../../dispatch/dispatcher/index.ts'
3
+ import { PacketDispatcher } from '../../../dispatch/dispatcher/index.ts'
4
+ import { Session } from '../../../dispatch/session/index.ts'
4
5
  import type { Mesh } from '../../../scale/mesh/index.ts'
5
- import { Tunnel } from '../../../scale/tunnel/index.ts'
6
6
  import { PhotonPeer } from '../../message/peer/index.ts'
7
7
  import { Carriage } from '../carriage/index.ts'
8
8
  import { FrontBridge } from '../front/index.ts'
@@ -117,22 +117,22 @@ export class SessionMover {
117
117
  * @param scope an application or a room
118
118
  * @param luggage what goes along
119
119
  */
120
- public async move(
120
+ public move(
121
121
  context: HandlerContext,
122
122
  scope: string,
123
123
  luggage: Luggage,
124
- ): Promise<boolean> {
124
+ ): boolean {
125
125
  const channel = context.channel
126
126
  const owner = this.mesh.ownerOf(scope)
127
- if (owner === this.mesh.link.id || Tunnel.carries(channel)) return false
127
+ if (owner === this.mesh.link.id || Session.of(channel).moved) return false
128
128
 
129
- const bridge = channel.pipeline.get<FrontBridge>(FrontBridge.NAME)
129
+ const bridge = channel.pipeline.get(FrontBridge.NAME)
130
130
  const photon = PhotonPeer.of(channel)
131
- if (bridge === null || photon === null) return false
131
+ if (!(bridge instanceof FrontBridge) || photon === null) return false
132
132
 
133
133
  const bytes = SessionMover.opening(bridge, luggage)
134
134
  Seeds.stash(channel, Seeds.of(luggage.role, photon, luggage.ticket))
135
- await SessionMover.release(channel)
135
+ SessionMover.release(channel)
136
136
 
137
137
  bridge.engage()
138
138
  photon.forward()
@@ -161,13 +161,13 @@ export class SessionMover {
161
161
  * Tells this shard's server the session is gone
162
162
  * @param channel the client's connection
163
163
  */
164
- private static async release(channel: Channel): Promise<void> {
164
+ private static release(channel: Channel): void {
165
165
  const pipeline = channel.pipeline
166
166
  const name = SessionMover.DISPATCHER
167
- const dispatcher = pipeline.get<PacketDispatcher<unknown>>(name)
167
+ const dispatcher = pipeline.get(name)
168
168
  const context = pipeline.context(name)
169
- if (dispatcher === null || context === null) return
169
+ if (!(dispatcher instanceof PacketDispatcher) || context === null) return
170
170
 
171
- await dispatcher.channelInactive(context)
171
+ dispatcher.channelInactive(context)
172
172
  }
173
173
  }
@@ -34,24 +34,8 @@ class Catch extends OutboundHandlerAdapter {
34
34
  * @param _context unused
35
35
  * @param message what the codec wrote
36
36
  */
37
- public override write(
38
- _context: HandlerContext,
39
- message: unknown,
40
- ): Promise<void> {
41
- this.writeSync(_context, message)
42
-
43
- return Promise.resolve()
44
- }
45
-
46
- /**
47
- * Keeps an envelope and drops everything else, without a promise
48
- * @param _context unused
49
- * @param message what the codec wrote
50
- */
51
- public writeSync(_context: HandlerContext, message: unknown): boolean {
37
+ public override write(_context: HandlerContext, message: unknown): void {
52
38
  this.caught = message instanceof Envelope ? (message as Envelope) : null
53
-
54
- return true
55
39
  }
56
40
  }
57
41
 
@@ -89,7 +73,7 @@ export class PacketPress {
89
73
  if (!(packet instanceof PacketAdapter)) return null
90
74
 
91
75
  this.output.caught = null
92
- this.channel.pipeline.writeSync(packet)
76
+ this.channel.pipeline.write(packet)
93
77
 
94
78
  return this.output.caught
95
79
  }
@@ -55,18 +55,16 @@ export class GameRouter extends InboundHandlerAdapter {
55
55
  * @param context the connection
56
56
  * @param message a packet, or anything else
57
57
  */
58
- public override channelRead(
59
- context: HandlerContext,
60
- message: unknown,
61
- ): void | Promise<void> {
58
+ public override channelRead(context: HandlerContext, message: unknown): void {
62
59
  if (
63
60
  message instanceof CreateGameRequest ||
64
61
  message instanceof JoinGameRequest
65
62
  ) {
66
- return this.enter(context, message)
63
+ this.enter(context, message)
64
+ return
67
65
  }
68
66
 
69
- return context.fireChannelRead(message)
67
+ context.fireChannelRead(message)
70
68
  }
71
69
 
72
70
  /**
@@ -74,22 +72,22 @@ export class GameRouter extends InboundHandlerAdapter {
74
72
  * @param context the connection
75
73
  * @param message the create or join request
76
74
  */
77
- private async enter(
75
+ private enter(
78
76
  context: HandlerContext,
79
77
  message: CreateGameRequest | JoinGameRequest,
80
- ): Promise<void> {
78
+ ): void {
81
79
  const room = message.roomName
82
80
  const token = GamePeer.of(context.channel, this.clock.now()).token
83
81
  const moved =
84
82
  room !== null &&
85
83
  token !== null &&
86
- (await this.mover.move(
84
+ this.mover.move(
87
85
  context,
88
86
  `${MasterRouter.SCOPE}${room}`,
89
87
  Luggage.game(this.authority.seal(token, false)),
90
- ))
88
+ )
91
89
  if (moved) return
92
90
 
93
- await context.fireChannelRead(message)
91
+ context.fireChannelRead(message)
94
92
  }
95
93
  }
@@ -75,17 +75,15 @@ export class MasterRouter extends DuplexHandlerAdapter {
75
75
  * @param context the connection
76
76
  * @param message a packet, or anything else
77
77
  */
78
- public override channelRead(
79
- context: HandlerContext,
80
- message: unknown,
81
- ): void | Promise<void> {
78
+ public override channelRead(context: HandlerContext, message: unknown): void {
82
79
  if (message instanceof CreateGameRequest) this.asked = message.roomName
83
80
  if (message instanceof JoinGameRequest) this.asked = message.roomName
84
81
  if (message instanceof AuthenticateRequest) {
85
- return this.login(context, message)
82
+ this.login(context, message)
83
+ return
86
84
  }
87
85
 
88
- return context.fireChannelRead(message)
86
+ context.fireChannelRead(message)
89
87
  }
90
88
 
91
89
  /**
@@ -93,21 +91,18 @@ export class MasterRouter extends DuplexHandlerAdapter {
93
91
  * @param context the connection
94
92
  * @param message the login
95
93
  */
96
- private async login(
97
- context: HandlerContext,
98
- message: AuthenticateRequest,
99
- ): Promise<void> {
94
+ private login(context: HandlerContext, message: AuthenticateRequest): void {
100
95
  const application = this.application(message)
101
96
  const moved =
102
97
  application !== null &&
103
- (await this.mover.move(
98
+ this.mover.move(
104
99
  context,
105
100
  `${NameRouter.SCOPE}${application}`,
106
101
  Luggage.master(true),
107
- ))
102
+ )
108
103
  if (moved) return
109
104
 
110
- await context.fireChannelRead(message)
105
+ context.fireChannelRead(message)
111
106
  }
112
107
 
113
108
  /**
@@ -115,22 +110,22 @@ export class MasterRouter extends DuplexHandlerAdapter {
115
110
  * @param context the connection
116
111
  * @param event whatever happened
117
112
  */
118
- public override async userEventTriggered(
113
+ public override userEventTriggered(
119
114
  context: HandlerContext,
120
115
  event: unknown,
121
- ): Promise<void> {
116
+ ): void {
122
117
  const token =
123
118
  event instanceof InitRequest ? TokenGate.admitted(context.channel) : null
124
119
  const moved =
125
120
  token !== null &&
126
- (await this.mover.move(
121
+ this.mover.move(
127
122
  context,
128
123
  `${NameRouter.SCOPE}${token.applicationId ?? ''}`,
129
124
  Luggage.master(false),
130
- ))
125
+ )
131
126
  if (moved) return
132
127
 
133
- await context.fireUserEventTriggered(event)
128
+ context.fireUserEventTriggered(event)
134
129
  }
135
130
 
136
131
  /**
@@ -138,22 +133,8 @@ export class MasterRouter extends DuplexHandlerAdapter {
138
133
  * @param context the connection
139
134
  * @param message a packet, or anything else
140
135
  */
141
- public override write(
142
- context: HandlerContext,
143
- message: unknown,
144
- ): Promise<void> {
145
- return context.write(this.directed(context.channel, message))
146
- }
147
-
148
- /**
149
- * Points an answer at the shard that owns the room without waiting
150
- * @param context the connection
151
- * @param message a packet, or anything else
152
- */
153
- public writeSync(context: HandlerContext, message: unknown): boolean {
154
- context.writeSync(this.directed(context.channel, message))
155
-
156
- return true
136
+ public override write(context: HandlerContext, message: unknown): void {
137
+ context.write(this.directed(context.channel, message))
157
138
  }
158
139
 
159
140
  /**
@@ -68,10 +68,7 @@ export class NameRouter extends DuplexHandlerAdapter {
68
68
  * @param context the connection
69
69
  * @param message a packet, or anything else
70
70
  */
71
- public override channelRead(
72
- context: HandlerContext,
73
- message: unknown,
74
- ): void | Promise<void> {
71
+ public override channelRead(context: HandlerContext, message: unknown): void {
75
72
  if (message instanceof AuthenticateRequest) {
76
73
  this.application = message.credentials?.applicationId ?? null
77
74
  } else if (message instanceof AuthenticateOnceRequest) {
@@ -81,7 +78,7 @@ export class NameRouter extends DuplexHandlerAdapter {
81
78
  this.application = message.applicationId
82
79
  }
83
80
 
84
- return context.fireChannelRead(message)
81
+ context.fireChannelRead(message)
85
82
  }
86
83
 
87
84
  /**
@@ -89,22 +86,8 @@ export class NameRouter extends DuplexHandlerAdapter {
89
86
  * @param context the connection
90
87
  * @param message a packet, or anything else
91
88
  */
92
- public override write(
93
- context: HandlerContext,
94
- message: unknown,
95
- ): Promise<void> {
96
- return context.write(this.directed(context.channel, message))
97
- }
98
-
99
- /**
100
- * Points an answer at the owning shard's Master without waiting
101
- * @param context the connection
102
- * @param message a packet, or anything else
103
- */
104
- public writeSync(context: HandlerContext, message: unknown): boolean {
105
- context.writeSync(this.directed(context.channel, message))
106
-
107
- return true
89
+ public override write(context: HandlerContext, message: unknown): void {
90
+ context.write(this.directed(context.channel, message))
108
91
  }
109
92
 
110
93
  /**