Skip to content

Commit 686f837

Browse files
committedDec 22, 2022
feat: send user mouse pos
1 parent 25b101f commit 686f837

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed
 

‎README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ action: CREATE_GAME, FLAG, UNFLAG, DIG
2121
## response
2222

2323
```
24-
byte: board[][]
24+
board[][]
2525
2626
```
27+
28+
## mouse update
29+
30+
```json
31+
{
32+
"id": "id",
33+
"name": "name",
34+
"mouseX": 0,
35+
"mouseY": 0
36+
}
37+
```
38+
39+
This data is send by a user and received by all other users

‎pkg/main.go

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package main
66

77
import (
88
"flag"
9-
"fmt"
109
"log"
1110
"net/http"
1211

@@ -25,7 +24,6 @@ func main() {
2524
r := mux.NewRouter()
2625
r.HandleFunc("/ws/{name}", func(w http.ResponseWriter, r *http.Request) {
2726
name := mux.Vars(r)["name"]
28-
fmt.Println(name)
2927
serveWs(hub, w, r, name)
3028
})
3129

‎pkg/message.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const (
55
FLAG = "FLAG"
66
UNFLAG = "UNFLAG"
77
DIG = "DIG"
8-
JOIN = "JOIN"
8+
MOUSE = "MOUSE"
99
)
1010

1111
type Action struct {
@@ -40,6 +40,8 @@ func (c *Client) parse(message []byte) {
4040
json.Unmarshal(message, &actionSquare)
4141

4242
c.dig(actionSquare.Row, actionSquare.Column)
43+
case MOUSE:
44+
c.hub.broadcast <- message
4345
}
4446

4547
}

0 commit comments

Comments
 (0)
Please sign in to comment.