From a48fef0186faffb8f80fb871fcc7612057a063e7 Mon Sep 17 00:00:00 2001 From: bdnugget Date: Wed, 15 Jan 2025 10:36:36 +0100 Subject: [PATCH] Only send last 5 chat messages --- main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 6b91cd3..1159913 100644 --- a/main.go +++ b/main.go @@ -154,8 +154,10 @@ func processActions() { currentTick := time.Now().UnixNano() / int64(tickRate) state := &pb.ServerMessage{ CurrentTick: currentTick, + Players: make([]*pb.PlayerState, 0, len(players)), } + // Convert players to PlayerState for id, p := range players { p.Lock() state.Players = append(state.Players, &pb.PlayerState{ @@ -166,9 +168,9 @@ func processActions() { p.Unlock() } - // Add chat messages to the server message + // Add new chat messages to the state chatMutex.RLock() - state.ChatMessages = chatHistory + state.ChatMessages = chatHistory[max(0, len(chatHistory)-5):] // Only send last 5 messages chatMutex.RUnlock() data, err := proto.Marshal(state)