mirror of
https://github.com/CosmicStar98/bedrocktool.git
synced 2024-06-02 23:35:15 +00:00
fix race condition because this code is badly architected
This commit is contained in:
parent
2157f5b67b
commit
b7cc0ff857
|
@ -156,8 +156,6 @@ func NewProxy(log *logrus.Logger) *ProxyContext {
|
||||||
var Client_addr net.Addr
|
var Client_addr net.Addr
|
||||||
|
|
||||||
func (p *ProxyContext) Run(ctx context.Context, server_address string) (err error) {
|
func (p *ProxyContext) Run(ctx context.Context, server_address string) (err error) {
|
||||||
c := make(chan struct{})
|
|
||||||
|
|
||||||
if strings.HasSuffix(server_address, ".pcap") {
|
if strings.HasSuffix(server_address, ".pcap") {
|
||||||
return fmt.Errorf("not supported anymore")
|
return fmt.Errorf("not supported anymore")
|
||||||
}
|
}
|
||||||
|
@ -165,8 +163,6 @@ func (p *ProxyContext) Run(ctx context.Context, server_address string) (err erro
|
||||||
return create_replay_connection(ctx, p.log, server_address, p.ConnectCB, p.PacketCB)
|
return create_replay_connection(ctx, p.log, server_address, p.ConnectCB, p.PacketCB)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer func() { c <- struct{}{} }()
|
|
||||||
GetTokenSource() // ask for login before listening
|
GetTokenSource() // ask for login before listening
|
||||||
var packs []*resource.Pack
|
var packs []*resource.Pack
|
||||||
if G_preload_packs {
|
if G_preload_packs {
|
||||||
|
@ -252,13 +248,5 @@ func (p *ProxyContext) Run(ctx context.Context, server_address string) (err erro
|
||||||
}()
|
}()
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
println("Cancelled")
|
|
||||||
return context.Canceled
|
|
||||||
case <-c:
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user