Only send last 5 chat messages
This commit is contained in:
parent
67e08c5d1e
commit
a48fef0186
6
main.go
6
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user