cache buster
This commit is contained in:
@@ -58,7 +58,6 @@ func handleWsError(err error, conn *websocket.Conn) {
|
||||
func broadcastMessage(message string) {
|
||||
wsMutex.Lock()
|
||||
defer wsMutex.Unlock()
|
||||
|
||||
for conn := range wsConnections {
|
||||
err := websocket.Message.Send(conn, message)
|
||||
handleWsError(err, conn)
|
||||
@@ -66,6 +65,22 @@ func broadcastMessage(message string) {
|
||||
}
|
||||
}
|
||||
|
||||
func randomizeBoxes(count int) []Box {
|
||||
boxes := make([]Box, count)
|
||||
for i := 0; i < count; i++ {
|
||||
index := random.Int() % 1000
|
||||
box, err := getBox(index)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
box.Value = !box.Value
|
||||
box.persist()
|
||||
boxes[i] = box
|
||||
}
|
||||
return boxes
|
||||
|
||||
}
|
||||
|
||||
func handleMessage(msg string, ws *websocket.Conn) error {
|
||||
if msg == "gol" {
|
||||
matrix := make(map[string]Box)
|
||||
@@ -77,7 +92,6 @@ func handleMessage(msg string, ws *websocket.Conn) error {
|
||||
index++
|
||||
}
|
||||
}
|
||||
log.Error(matrix)
|
||||
nextGen := make([]Box, 0)
|
||||
for id, item := range matrix {
|
||||
nextItem := shouldBeAlive(matrix, id)
|
||||
@@ -94,16 +108,17 @@ func handleMessage(msg string, ws *websocket.Conn) error {
|
||||
}
|
||||
broadcastMessage(nextMessage)
|
||||
|
||||
} else if msg == "random" {
|
||||
index := random.Int() % 1000
|
||||
box, err := getBox(index)
|
||||
} else if strings.Contains(msg, "r:") {
|
||||
count, err := strconv.Atoi(strings.Split(msg, ":")[1])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Failed to parse randomize count: %v", err)
|
||||
}
|
||||
boxes := randomizeBoxes(count)
|
||||
message := ""
|
||||
for _, box := range boxes {
|
||||
message += box.serialize()
|
||||
}
|
||||
box.Value = !box.Value
|
||||
box.persist()
|
||||
|
||||
message := box.serialize()
|
||||
broadcastMessage(message)
|
||||
|
||||
} else if strings.Contains(msg, "b:") {
|
||||
|
||||
Reference in New Issue
Block a user