-
Notifications
You must be signed in to change notification settings - Fork 0
/
mob_socket.go
54 lines (41 loc) · 927 Bytes
/
mob_socket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"bufio"
"fmt"
"log"
"strings"
"golang.org/x/net/websocket"
)
func getMob(ws *websocket.Conn) {
msg := make([]byte, 512)
n, err := ws.Read(msg)
if err != nil {
log.Println(err)
}
if i := strings.Index(string(msg[:n]), "map-id"); i == 0 {
mapID := strings.Split(string(msg[:n]), ":")[1]
if m, ok := maps[mapID]; ok {
n, err = ws.Read(msg)
if err != nil {
log.Println(err)
}
if i = strings.Index(string(msg[:n]), "mob-id"); i == 0 {
mobID := strings.Split(string(msg[:n]), ":")[1]
if mob, ok := m.getMob(mobID); ok {
ws.Write([]byte(fmt.Sprintf("info:%s\n", mob.getBasicInfo())))
addr := fmt.Sprintf("%p", ws)
mob.addSocket(addr, ws)
defer mob.delSocket(addr)
scanner := bufio.NewScanner(ws)
for scanner.Scan() {
cmd := scanner.Text()
switch cmd {
case "cmd":
}
}
}
}
}
}
ws.Close()
}