Skip to content

Commit

Permalink
unbreak transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
olebeck committed Jul 20, 2024
1 parent 8ab8490 commit 6be3e7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
5 changes: 3 additions & 2 deletions handlers/worlds/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ func NewWorldsHandler(settings WorldSettings) *proxy.Handler {
log: logrus.WithField("part", "WorldsHandler"),
settings: settings,
}
w.mapUI = NewMapUI(w)
w.scripting = scripting.New()

h := &proxy.Handler{
Name: "Worlds",
Expand All @@ -129,6 +127,9 @@ func NewWorldsHandler(settings WorldSettings) *proxy.Handler {
biomes: world.DefaultBiomes.Clone(),
}

w.mapUI = NewMapUI(w)
w.scripting = scripting.New()

w.session.AddCommand(func(cmdline []string) bool {
return w.setWorldName(strings.Join(cmdline, " "))
}, protocol.Command{
Expand Down
2 changes: 1 addition & 1 deletion utils/proxy/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type errTransfer struct {
transfer *packet.Transfer
}

func (e errTransfer) Error() string {
func (e *errTransfer) Error() string {
return fmt.Sprintf("transfer to %s:%d", e.transfer.Address, e.transfer.Port)
}

Expand Down
24 changes: 6 additions & 18 deletions utils/proxy/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,7 @@ func (s *Session) Run(ctx context.Context, connect *utils.ConnectInfo) error {
if !errors.Is(err, context.Canceled) {
cancel(err)
}
return
}
if s.Client != nil {
s.Client.Close()
}
s.Server.Close()
}

// server to client
Expand All @@ -300,6 +295,11 @@ func (s *Session) Run(ctx context.Context, connect *utils.ConnectInfo) error {

wg.Wait()
err = context.Cause(ctx)
if !errors.Is(err, &errTransfer{}) {
if s.Client != nil {
s.Client.Close()
}
}
if err != nil {
s.disconnectReason = err.Error()
return err
Expand Down Expand Up @@ -460,18 +460,6 @@ func (s *Session) proxyLoop(ctx context.Context, toServer bool) (err error) {
c2 = s.Client
}

if false {
defer func() {
rec := recover()
if rec != nil {
if s, ok := rec.(string); ok {
rec = errors.New(s)
}
err = rec.(error)
}
}()
}

for {
if ctx.Err() != nil {
return ctx.Err()
Expand Down Expand Up @@ -524,7 +512,7 @@ func (s *Session) proxyLoop(ctx context.Context, toServer bool) (err error) {
}

if transfer != nil {
return errTransfer{transfer: transfer}
return &errTransfer{transfer: transfer}
}
}
}
Expand Down

0 comments on commit 6be3e7d

Please sign in to comment.