fix race condition
This commit is contained in:
+4
-5
@@ -65,13 +65,9 @@ type Conn struct {
|
|||||||
Version string
|
Version string
|
||||||
ProtocolVersion int32
|
ProtocolVersion int32
|
||||||
DebugPrintPackets []string
|
DebugPrintPackets []string
|
||||||
|
|
||||||
sendTickAlways bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) StartConn() (err error) {
|
func (c *Conn) StartConn() (err error) {
|
||||||
c.sendTickAlways = c.State() != proto_base.Play
|
|
||||||
|
|
||||||
c.RegisterEventSource(c.ActivateReceiveRoutine())
|
c.RegisterEventSource(c.ActivateReceiveRoutine())
|
||||||
c.RegisterCritical(c.OnLoginTick)
|
c.RegisterCritical(c.OnLoginTick)
|
||||||
err = c.Loop.StartLoop()
|
err = c.Loop.StartLoop()
|
||||||
@@ -131,7 +127,7 @@ func (c *Conn) ActivateReceiveRoutine() (chSending <-chan any) {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
if c.sendTickAlways {
|
if c.State() != proto_base.Play {
|
||||||
ch <- LoginTick{}
|
ch <- LoginTick{}
|
||||||
} else {
|
} else {
|
||||||
packet, err := c.Receive()
|
packet, err := c.Receive()
|
||||||
@@ -224,6 +220,9 @@ func (c *Conn) Send(packet proto_base.EncodeDecodeAble) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Receive() (packet proto_base.EncodeDecodeAble, err error) {
|
func (c *Conn) Receive() (packet proto_base.EncodeDecodeAble, err error) {
|
||||||
|
if c.R == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
packetBytes, err := c.ReceiveRaw()
|
packetBytes, err := c.ReceiveRaw()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user