Skip to content

Commit

Permalink
check switch
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Dec 28, 2023
1 parent 279fb54 commit 65464e6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion pkg/edition/java/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ func (s *serverConnection) startHandshake(
// Set server's protocol & state
// after writing handshake, but before writing ServerLogin
serverMc.SetProtocol(protocol)
serverMc.SwitchSessionHandler(state.Login)
if !serverMc.SwitchSessionHandler(state.Login) {
return nil, fmt.Errorf("error switching session handler to login in server connection")
}

serverLogin := &packet.ServerLogin{
Username: s.player.Username(),
Expand Down
6 changes: 5 additions & 1 deletion pkg/edition/java/proxy/session_backend_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ func (b *backendConfigSessionHandler) handleFinishedUpdate(p *config.FinishedUpd
smc.SetState(state.Play)
configHandler.handleBackendFinishUpdate(b.serverConn, p, func() {
if b.serverConn == player.connectedServer() {
smc.SwitchSessionHandler(state.Play)
if !smc.SwitchSessionHandler(state.Play) {
err := errors.New("failed to switch session handler")
b.log.Error(err, "expected to switch session handler to play state")
}

header, footer := player.tabList.HeaderFooter()
err := tablist.SendHeaderFooter(player, header, footer)
if err != nil {
b.log.Error(err, "error sending tab list header/footer")
return
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/edition/java/proxy/session_backend_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ func (b *backendLoginSessionHandler) handleServerLoginSuccess() {
_ = serverMc.WritePacket(pkt)
}
if csh, ok := player.MinecraftConn.ActiveSessionHandler().(*clientPlaySessionHandler); ok {
// TODO serverMc.SetAutoReading(false)
// TODO 1.20.2+ serverMc.SetAutoReading(false)
csh.doSwitch().DoWhenTrue(func() {
// TODO serverMc.SetAutoReading(true)
// TODO 1.20.2+ serverMc.SetAutoReading(true)
})
}
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/edition/java/proxy/session_client_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,9 @@ func (c *clientPlaySessionHandler) updateTimeKeeper(t time.Time) bool {

func (c *clientPlaySessionHandler) handleFinishUpdate(p *config.FinishedUpdate) {
// Complete client switch
c.player.MinecraftConn.SwitchSessionHandler(state.Config)
if !c.player.MinecraftConn.SwitchSessionHandler(state.Config) {
panic("expected client to have config session handler")
}
serverConn := c.player.connectedServer()
if serverConn != nil {
smc, ok := serverConn.ensureConnected()
Expand All @@ -778,7 +780,10 @@ func (c *clientPlaySessionHandler) handleFinishUpdate(p *config.FinishedUpdate)
}
go func() {
_ = smc.WritePacket(p)
smc.SwitchSessionHandler(state.Config)
if !smc.SwitchSessionHandler(state.Config) {
err := errors.New("failed to switch session handler")
c.log.Error(err, "expected to switch session handler to config state")
}
}()
}
c.configSwitchDone.SetTrue()
Expand Down

0 comments on commit 65464e6

Please sign in to comment.