Add system messages to chat

This commit is contained in:
2025-01-20 00:03:50 +01:00
parent 4549ee7517
commit d5bb464d9f
3 changed files with 19 additions and 2 deletions

View File

@ -100,6 +100,9 @@ func HandleServerCommunication(conn net.Conn, playerID int32, player *types.Play
// Create a channel to signal when goroutines are done
done := make(chan struct{})
// Create a set of current players to track disconnects
currentPlayers := make(map[int32]bool)
go func() {
for {
select {
@ -194,6 +197,7 @@ func HandleServerCommunication(conn net.Conn, playerID int32, player *types.Play
player.Unlock()
for _, state := range serverMessage.Players {
currentPlayers[state.PlayerId] = true
if state.PlayerId == playerID {
player.Lock()
// Update initial position if not set
@ -216,6 +220,13 @@ func HandleServerCommunication(conn net.Conn, playerID int32, player *types.Play
}
}
// Remove players that are no longer in the server state
for id := range otherPlayers {
if !currentPlayers[id] {
delete(otherPlayers, id)
}
}
if handler, ok := player.UserData.(types.ChatMessageHandler); ok && len(serverMessage.ChatMessages) > 0 {
handler.HandleServerMessages(serverMessage.ChatMessages)
}