Only send last 5 chat messages
This commit is contained in:
		
							
								
								
									
										6
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								main.go
									
									
									
									
									
								
							| @ -154,8 +154,10 @@ func processActions() { | |||||||
| 	currentTick := time.Now().UnixNano() / int64(tickRate) | 	currentTick := time.Now().UnixNano() / int64(tickRate) | ||||||
| 	state := &pb.ServerMessage{ | 	state := &pb.ServerMessage{ | ||||||
| 		CurrentTick: currentTick, | 		CurrentTick: currentTick, | ||||||
|  | 		Players:     make([]*pb.PlayerState, 0, len(players)), | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	// Convert players to PlayerState | ||||||
| 	for id, p := range players { | 	for id, p := range players { | ||||||
| 		p.Lock() | 		p.Lock() | ||||||
| 		state.Players = append(state.Players, &pb.PlayerState{ | 		state.Players = append(state.Players, &pb.PlayerState{ | ||||||
| @ -166,9 +168,9 @@ func processActions() { | |||||||
| 		p.Unlock() | 		p.Unlock() | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Add chat messages to the server message | 	// Add new chat messages to the state | ||||||
| 	chatMutex.RLock() | 	chatMutex.RLock() | ||||||
| 	state.ChatMessages = chatHistory | 	state.ChatMessages = chatHistory[max(0, len(chatHistory)-5):] // Only send last 5 messages | ||||||
| 	chatMutex.RUnlock() | 	chatMutex.RUnlock() | ||||||
|  |  | ||||||
| 	data, err := proto.Marshal(state) | 	data, err := proto.Marshal(state) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user