@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.
- package/package.json +2 -2
- package/src/codec/index.ts +82 -157
- package/src/dispatch/dispatcher/index.ts +116 -33
- package/src/dispatch/session/index.ts +9 -3
- package/src/index.ts +2 -4
- package/src/photon/balancing/codec/index.ts +27 -53
- package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
- package/src/photon/balancing/format/friends/request/index.ts +21 -5
- package/src/photon/balancing/format/game/create/request/index.ts +45 -8
- package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
- package/src/photon/balancing/format/game/join/request/index.ts +65 -13
- package/src/photon/balancing/format/game/list/request/index.ts +29 -3
- package/src/photon/balancing/format/game/random/request/index.ts +58 -10
- package/src/photon/balancing/format/groups/request/index.ts +19 -3
- package/src/photon/balancing/format/index.ts +7 -0
- package/src/photon/balancing/format/leave/request/index.ts +19 -3
- package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
- package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
- package/src/photon/balancing/format/once/request/index.ts +31 -8
- package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
- package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
- package/src/photon/balancing/format/raise/request/index.ts +76 -10
- package/src/photon/balancing/format/reader/index.ts +75 -6
- package/src/photon/balancing/format/regions/request/index.ts +16 -1
- package/src/photon/balancing/format/rpc/request/index.ts +26 -3
- package/src/photon/balancing/format/settings/request/index.ts +15 -2
- package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
- package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
- package/src/photon/balancing/format/shared/options/index.ts +56 -24
- package/src/photon/balancing/format/table/index.ts +399 -0
- package/src/photon/balancing/index.ts +11 -1
- package/src/photon/balancing/travel/index.ts +15 -12
- package/src/photon/binary/v18/index.ts +26 -1
- package/src/photon/binary/value/index.ts +52 -3
- package/src/photon/client/connection/index.ts +6 -6
- package/src/photon/cluster/back/index.ts +32 -45
- package/src/photon/cluster/dresser/index.ts +7 -8
- package/src/photon/cluster/front/index.ts +25 -49
- package/src/photon/cluster/grid/index.ts +1 -1
- package/src/photon/cluster/mover/index.ts +12 -12
- package/src/photon/cluster/press/index.ts +2 -18
- package/src/photon/cluster/route/game/index.ts +9 -11
- package/src/photon/cluster/route/master/index.ts +15 -34
- package/src/photon/cluster/route/name/index.ts +4 -21
- package/src/photon/cluster/seat/game/index.ts +6 -26
- package/src/photon/cluster/seat/master/index.ts +1 -1
- package/src/photon/cluster/sessions/index.ts +5 -6
- package/src/photon/cluster/spread/index.ts +8 -147
- package/src/photon/enet/client/index.ts +1 -8
- package/src/photon/enet/gateway/index.ts +5 -15
- package/src/photon/enet/index.ts +1 -1
- package/src/photon/enet/link/index.ts +34 -15
- package/src/photon/enet/outbound/index.ts +279 -0
- package/src/photon/enet/peer/index.ts +59 -0
- package/src/photon/enet/transport/index.ts +8 -24
- package/src/photon/game/admission/index.ts +353 -0
- package/src/photon/game/bag/index.ts +13 -0
- package/src/photon/game/broadcast/index.ts +79 -0
- package/src/photon/game/editor/index.ts +446 -0
- package/src/photon/game/gate/index.ts +9 -8
- package/src/photon/game/handler/index.ts +30 -3
- package/src/photon/game/history/index.ts +234 -0
- package/src/photon/game/hooked/index.ts +16 -15
- package/src/photon/game/index.ts +12 -1
- package/src/photon/game/lifecycle/index.ts +193 -0
- package/src/photon/game/peer/index.ts +1 -10
- package/src/photon/game/properties/index.ts +342 -0
- package/src/photon/game/room/index.ts +435 -1793
- package/src/photon/game/rooms/index.ts +2 -1
- package/src/photon/game/seats/index.ts +237 -0
- package/src/photon/game/server/index.ts +12 -2
- package/src/photon/game/services/index.ts +41 -0
- package/src/photon/game/settings/index.ts +22 -0
- package/src/photon/game/snapshot/index.ts +133 -0
- package/src/photon/game/throttle/index.ts +60 -0
- package/src/photon/game/touch/index.ts +2 -5
- package/src/photon/game/venue/index.ts +31 -0
- package/src/photon/master/application/index.ts +7 -0
- package/src/photon/master/gate/index.ts +12 -8
- package/src/photon/master/handler/index.ts +36 -748
- package/src/photon/master/index.ts +5 -0
- package/src/photon/master/list/sql/index.ts +37 -3
- package/src/photon/master/listing/index.ts +133 -0
- package/src/photon/master/lobby/index.ts +9 -0
- package/src/photon/master/login/index.ts +424 -0
- package/src/photon/master/matchmaking/index.ts +282 -0
- package/src/photon/master/query/index.ts +45 -0
- package/src/photon/master/redirect/index.ts +8 -7
- package/src/photon/master/services/index.ts +35 -0
- package/src/photon/master/settings/index.ts +44 -0
- package/src/photon/master/sql/cost/index.ts +263 -0
- package/src/photon/master/sql/index.ts +1 -0
- package/src/photon/message/binary/index.ts +35 -1
- package/src/photon/message/client/index.ts +14 -11
- package/src/photon/message/format/index.ts +9 -0
- package/src/photon/message/handler/index.ts +48 -63
- package/src/photon/message/pipeline/index.ts +12 -12
- package/src/photon/message/server/index.ts +87 -43
- package/src/photon/message/watch/index.ts +127 -15
- package/src/photon/server/config/index.ts +5 -0
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +36 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/server/listeners/index.ts +11 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +41 -38
- package/src/photon/tcp/framing/index.ts +24 -4
- package/src/photon/tcp/server/index.ts +4 -4
- package/src/photon/websocket/bridge/index.ts +16 -20
- package/src/photon/websocket/message/index.ts +27 -39
- package/src/photon/websocket/path/index.ts +2 -5
- package/src/scale/batch/index.ts +14 -6
- package/src/scale/fanout/index.ts +6 -6
- package/src/scale/index.ts +2 -4
- package/src/scale/outbound/index.ts +192 -0
- package/src/scale/relay/index.ts +24 -16
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +56 -86
- package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
- package/src/smartfox/common/bluebox/index.ts +4 -0
- package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
- package/src/smartfox/common/index.ts +5 -0
- package/src/smartfox/common/strikes/index.ts +74 -0
- package/src/smartfox/pro/bluebox/index.ts +176 -4
- package/src/smartfox/pro/codec/index.ts +8 -7
- package/src/smartfox/pro/escalation/index.ts +28 -20
- package/src/smartfox/pro/flood/index.ts +2 -2
- package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
- package/src/smartfox/pro/handler/chat/index.ts +11 -8
- package/src/smartfox/pro/handler/login/index.ts +2 -25
- package/src/smartfox/pro/handler/shared/index.ts +4 -3
- package/src/smartfox/pro/index.ts +11 -5
- package/src/smartfox/pro/login/gate/index.ts +166 -0
- package/src/smartfox/pro/login/index.ts +1 -0
- package/src/smartfox/pro/moderation/index.ts +220 -0
- package/src/smartfox/pro/options/index.ts +5 -5
- package/src/smartfox/pro/protocol/index.ts +62 -8
- package/src/smartfox/pro/web/index.ts +33 -26
- package/src/smartfox/pro/zone/index.ts +59 -282
- package/src/smartfox/pro/zones/index.ts +3 -3
- package/src/smartfox/x2/bluebox/index.ts +149 -4
- package/src/smartfox/x2/chat/index.ts +9 -19
- package/src/smartfox/x2/codec/index.ts +34 -40
- package/src/smartfox/x2/config/index.ts +6 -1
- package/src/smartfox/x2/data/array/index.ts +96 -60
- package/src/smartfox/x2/data/object/index.ts +144 -82
- package/src/smartfox/x2/data/serializer/index.ts +41 -23
- package/src/smartfox/x2/flood/gate/index.ts +19 -13
- package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
- package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
- package/src/smartfox/x2/format/login/response/index.ts +4 -3
- package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
- package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
- package/src/smartfox/x2/games/index.ts +35 -8
- package/src/smartfox/x2/hall/index.ts +0 -6
- package/src/smartfox/x2/handler/session/index.ts +1 -1
- package/src/smartfox/x2/index.ts +8 -3
- package/src/smartfox/x2/member/index.ts +10 -3
- package/src/smartfox/x2/packet/login/response/index.ts +12 -0
- package/src/smartfox/x2/protocol/index.ts +11 -1
- package/src/smartfox/x2/rooms/index.ts +1 -2
- package/src/smartfox/x2/sessions/index.ts +6 -0
- package/src/smartfox/x2/udp/index.ts +61 -24
- package/src/smartfox/x2/web/index.ts +35 -17
- package/src/smartfox/x2/websocket/index.ts +18 -36
- package/src/smartfox/x2/zone/index.ts +77 -28
- package/src/smartfox/x2/zones/index.ts +17 -5
- package/src/photon/enet/handler/index.ts +0 -65
- package/src/scale/hosted/index.ts +0 -68
- package/src/scale/outlet/index.ts +0 -121
- package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
- package/src/smartfox/pro/bluebox/session/index.ts +0 -63
- package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
- package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
- /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
- /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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
public override channelRead(context: HandlerContext, message: unknown): void {
|
|
46
|
+
if (!(message instanceof ByteBuf)) {
|
|
47
|
+
context.fireChannelRead(message)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
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
|
|
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
|
|
70
|
-
|
|
71
|
-
const cargo = cargoes[index]
|
|
72
|
-
if (cargo === undefined) continue
|
|
68
|
+
): void {
|
|
69
|
+
const channel = context.channel
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
this.pass(context, cargoes, index
|
|
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
|
|
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
|
-
|
|
96
|
+
context.fireUserEventTriggered(this.init)
|
|
97
|
+
return
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
if (cargo === 'idle') {
|
|
99
|
-
|
|
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)
|
|
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):
|
|
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
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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.
|
|
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
|
|
63
|
-
|
|
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
|
|
71
|
+
public override channelActive(context: HandlerContext): void {
|
|
73
72
|
const pipeline = context.pipeline
|
|
74
|
-
if (pipeline.get
|
|
75
|
-
|
|
73
|
+
if (pipeline.get(MessagePipeline.handler) === null) {
|
|
74
|
+
context.fireChannelActive()
|
|
76
75
|
return
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
this.outfit(context.channel)
|
|
80
|
-
|
|
81
|
-
pipeline.remove
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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))
|
|
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
|
-
|
|
90
|
+
context.fireChannelRead(ByteBuf.wrap(Carriage.pack(envelope)))
|
|
91
|
+
return
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
this.last = envelope
|
|
93
|
-
|
|
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
|
|
103
|
+
public override userEventTriggered(
|
|
102
104
|
context: HandlerContext,
|
|
103
105
|
event: unknown,
|
|
104
|
-
):
|
|
106
|
+
): void {
|
|
105
107
|
if (
|
|
106
108
|
this.moved &&
|
|
107
109
|
event instanceof IdleStateEvent &&
|
|
108
110
|
event.state === 'reader'
|
|
109
111
|
) {
|
|
110
|
-
|
|
112
|
+
context.fireChannelRead(ByteBuf.wrap(Carriage.idle()))
|
|
111
113
|
return
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
|
|
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
|
|
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
|
-
|
|
126
|
+
context.fireChannelRead(ByteBuf.wrap(Carriage.farewell(closure)))
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
|
|
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.
|
|
162
|
-
return
|
|
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.
|
|
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
|
|
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
|
|
120
|
+
public move(
|
|
121
121
|
context: HandlerContext,
|
|
122
122
|
scope: string,
|
|
123
123
|
luggage: Luggage,
|
|
124
|
-
):
|
|
124
|
+
): boolean {
|
|
125
125
|
const channel = context.channel
|
|
126
126
|
const owner = this.mesh.ownerOf(scope)
|
|
127
|
-
if (owner === this.mesh.link.id ||
|
|
127
|
+
if (owner === this.mesh.link.id || Session.of(channel).moved) return false
|
|
128
128
|
|
|
129
|
-
const bridge = channel.pipeline.get
|
|
129
|
+
const bridge = channel.pipeline.get(FrontBridge.NAME)
|
|
130
130
|
const photon = PhotonPeer.of(channel)
|
|
131
|
-
if (bridge
|
|
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
|
-
|
|
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
|
|
164
|
+
private static release(channel: Channel): void {
|
|
165
165
|
const pipeline = channel.pipeline
|
|
166
166
|
const name = SessionMover.DISPATCHER
|
|
167
|
-
const dispatcher = pipeline.get
|
|
167
|
+
const dispatcher = pipeline.get(name)
|
|
168
168
|
const context = pipeline.context(name)
|
|
169
|
-
if (dispatcher
|
|
169
|
+
if (!(dispatcher instanceof PacketDispatcher) || context === null) return
|
|
170
170
|
|
|
171
|
-
|
|
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.
|
|
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
|
-
|
|
63
|
+
this.enter(context, message)
|
|
64
|
+
return
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
|
|
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
|
|
75
|
+
private enter(
|
|
78
76
|
context: HandlerContext,
|
|
79
77
|
message: CreateGameRequest | JoinGameRequest,
|
|
80
|
-
):
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
82
|
+
this.login(context, message)
|
|
83
|
+
return
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
113
|
+
public override userEventTriggered(
|
|
119
114
|
context: HandlerContext,
|
|
120
115
|
event: unknown,
|
|
121
|
-
):
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
/**
|