Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions session/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type Processor interface {
ProcessClientEncoded(ctx *Context, pk *[]byte)
// ProcessFlush is called before flushing the player's minecraft.Conn buffer in response to a downstream server request.
ProcessFlush(ctx *Context)
// ProcessDiscover is called to determine the primary server to send the player to.
ProcessDiscover(ctx *Context, target *string)
// ProcessDiscoverFallback is called to determine the fallback server to send the player to.
ProcessDiscoverFallback(ctx *Context, target *string)
// ProcessPreTransfer is called before transferring the player to a different server.
ProcessPreTransfer(ctx *Context, origin *string, target *string)
// ProcessTransferFailure is called when the player transfer to a different server fails.
Expand All @@ -63,6 +67,8 @@ func (NopProcessor) ProcessServerEncoded(_ *Context, _ *[]byte) {}
func (NopProcessor) ProcessClient(_ *Context, _ *packet.Packet) {}
func (NopProcessor) ProcessClientEncoded(_ *Context, _ *[]byte) {}
func (NopProcessor) ProcessFlush(_ *Context) {}
func (NopProcessor) ProcessDiscover(_ *Context, target *string) {}
func (NopProcessor) ProcessDiscoverFallback(_ *Context, target *string) {}
func (NopProcessor) ProcessPreTransfer(_ *Context, _ *string, _ *string) {}
func (NopProcessor) ProcessTransferFailure(_ *Context, _ *string, _ *string) {}
func (NopProcessor) ProcessPostTransfer(_ *Context, _ *string, _ *string) {}
Expand Down
4 changes: 4 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (s *Session) LoginContext(ctx context.Context) (err error) {
return err
}

s.Processor().ProcessDiscover(NewContext(), &serverAddr)

conn, err := s.dial(ctx, serverAddr)
if err != nil {
s.logger.Debug("dialer failed", "err", err)
Expand Down Expand Up @@ -325,6 +327,8 @@ func (s *Session) fallback() error {
return fmt.Errorf("discovery failed: %w", err)
}

s.Processor().ProcessDiscoverFallback(NewContext(), &addr)

s.logger.Debug("transferring session to a fallback server", "addr", addr)
if err := s.Transfer(addr); err != nil {
return fmt.Errorf("transfer failed: %w", err)
Expand Down