// events.go package main type Event struct { ID int64 `json:"id"` Type string `json:"type"` // "chat" or "location" Timestamp int64 `json:"timestamp"` FromNick string `json:"fromNick,omitempty"` FromInternal string `json:"fromInternal,omitempty"` Message string `json:"message,omitempty"` ServerID string `json:"serverId,omitempty"` X float64 `json:"x,omitempty"` Y float64 `json:"y,omitempty"` Z float64 `json:"z,omitempty"` Dimension string `json:"dimension,omitempty"` } func (h *Hub) addEvent(e Event) { h.mu.Lock() defer h.mu.Unlock() e.ID = h.nextEventID h.nextEventID++ if len(h.events) >= h.maxEvents { copy(h.events, h.events[1:]) h.events[len(h.events)-1] = e } else { h.events = append(h.events, e) } } func (h *Hub) getEventsSince(since int64) []Event { h.mu.RLock() defer h.mu.RUnlock() if since <= 0 { out := make([]Event, len(h.events)) copy(out, h.events) return out } var res []Event for _, e := range h.events { if e.ID > since { res = append(res, e) } } return res }