Menu with broken exit and settings
This commit is contained in:
@ -61,11 +61,26 @@ func HandleServerCommunication(conn net.Conn, playerID int32, player *types.Play
|
||||
|
||||
actionTicker := time.NewTicker(types.ClientTickRate)
|
||||
defer actionTicker.Stop()
|
||||
defer conn.Close()
|
||||
defer close(player.QuitDone)
|
||||
|
||||
// Create a channel to signal when goroutines are done
|
||||
done := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-quitChan:
|
||||
// Send disconnect message to server
|
||||
disconnectMsg := &pb.ActionBatch{
|
||||
PlayerId: playerID,
|
||||
Actions: []*pb.Action{{
|
||||
Type: pb.Action_DISCONNECT,
|
||||
PlayerId: playerID,
|
||||
}},
|
||||
}
|
||||
writeMessage(conn, disconnectMsg)
|
||||
done <- struct{}{}
|
||||
return
|
||||
case <-actionTicker.C:
|
||||
player.Lock()
|
||||
@ -96,6 +111,9 @@ func HandleServerCommunication(conn net.Conn, playerID int32, player *types.Play
|
||||
for {
|
||||
select {
|
||||
case <-quitChan:
|
||||
<-done // Wait for action goroutine to finish
|
||||
close(done)
|
||||
time.Sleep(100 * time.Millisecond) // Give time for disconnect message to be sent
|
||||
return
|
||||
default:
|
||||
// Read message length (4 bytes)
|
||||
|
Reference in New Issue
Block a user