-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
backend.go
109 lines (100 loc) · 3.74 KB
/
backend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package phase
import (
"go.minekube.com/gate/pkg/edition/java/proto/packet/plugin"
"go.minekube.com/gate/pkg/gate/proto"
)
var (
// VanillaBackendPhase is a vanilla backend connection.
VanillaBackendPhase BackendConnectionPhase = &unimplementedBackendPhase{}
// UnknownBackendPhase indicated the backend connection is unknown at this time.
UnknownBackendPhase BackendConnectionPhase = &unknownBackendPhase{}
// InTransitionBackendPhase is a special backend phase used to indicate that this connection is about to become
// obsolete (transfer to a new server, for instance) and that Forge messages ought to be
// forwarded on to an in-flight connection instead.
InTransitionBackendPhase BackendConnectionPhase = &inTransitionBackendPhase{}
)
// BackendConnectionPhase allows for simple tracking of the
// phase that the Legacy Forge handshake is in (server side).
type BackendConnectionPhase interface {
// Handle a plugin message in the context of this phase.
Handle(
player PacketWriter,
backend BackendConnectionPhaseSetter,
server ConnectionTypeSetter,
resetter LegacyForgeHandshakeResetter,
msg *plugin.Message,
) bool
// ConsideredComplete indicates whether the connection is considered complete.
ConsideredComplete() bool
// OnDepartForNewServer fired when the provided server connection is about to be terminated
// because the provided player is connecting to a new server.
OnDepartForNewServer(
player PacketWriter,
phase ClientConnectionPhase,
setter ClientConnectionPhaseSetter,
)
}
type (
BackendConnectionPhaseSetter interface {
SetPhase(BackendConnectionPhase)
}
ClientConnectionPhaseSetter interface {
SetPhase(ClientConnectionPhase)
}
ConnectionTypeSetter interface {
SetType(ConnectionType)
}
PacketWriter interface {
WritePacket(proto.Packet) error
}
LegacyForgeHandshakeResetter interface {
SendLegacyForgeHandshakeResetPacket()
}
)
type (
unknownBackendPhase struct{ unimplementedBackendPhase }
inTransitionBackendPhase struct{ unimplementedBackendPhase }
unimplementedBackendPhase struct{}
)
func (unimplementedBackendPhase) ConsideredComplete() bool { return true }
func (inTransitionBackendPhase) ConsideredComplete() bool { return true }
func (unknownBackendPhase) ConsideredComplete() bool { return false }
func (notStartedBackend) ConsideredComplete() bool { return false }
func (helloBackend) ConsideredComplete() bool { return false }
func (sentModListBackend) ConsideredComplete() bool { return false }
func (sentServerDataBackend) ConsideredComplete() bool { return false }
func (waitingAckBackend) ConsideredComplete() bool { return false }
func (completeBackend) ConsideredComplete() bool { return true }
func (unknownBackendPhase) Handle(
player PacketWriter,
backend BackendConnectionPhaseSetter,
server ConnectionTypeSetter,
resetter LegacyForgeHandshakeResetter,
msg *plugin.Message,
) bool {
// The connection may be legacy forge. If so, the Forge handler will deal with this
// for us. Otherwise, we have nothing to do.
return NotStartedLegacyForgeHandshakeBackendPhase.Handle(player, backend, server, resetter, msg)
}
func (unimplementedBackendPhase) Handle(
player PacketWriter,
backend BackendConnectionPhaseSetter,
server ConnectionTypeSetter,
resetter LegacyForgeHandshakeResetter,
msg *plugin.Message,
) bool {
return false
}
func (unimplementedBackendPhase) OnDepartForNewServer(
player PacketWriter,
phase ClientConnectionPhase,
setter ClientConnectionPhaseSetter,
) {
// If the server we are departing is modded, we must always reset the client's handshake.
phase.ResetConnectionPhase(player, setter)
}
func (unimplementedBackendPhase) onTransitionToNewPhase(
server ConnectionTypeSetter,
resetter LegacyForgeHandshakeResetter,
) {
}