-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
92 lines (74 loc) · 1.66 KB
/
command.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"strconv"
"strings"
)
var (
userMap map[int64]*TCPClient
)
func init() {
userMap = make(map[int64]*TCPClient)
}
func StartCommand(msgstr interface{}) {
str, ok := msgstr.(string)
if !ok {
fmt.Println("不能正常转换成 string 消息")
return
}
strarr := strings.Split(str, " ")
sUid, err := strconv.Atoi(strarr[0])
if err != nil {
fmt.Println("命令格式错误, 第一个参数需要是数字...", strarr[0])
return
}
eUid, err := strconv.Atoi(strarr[1])
if err != nil {
fmt.Println("命令格式错误, 第二个参数需要是数字...", strarr[1])
return
}
if eUid <= sUid {
fmt.Println("命令格式错误, 第二个参数不能小于等于第一个参数....")
return
}
for uid := sUid; uid<= eUid; uid ++ {
user := &TCPClient{
Host: "127.0.0.1",
Port: 8888,
UserId: int64(uid),
}
user.Start()
userMap[int64(uid)] = user
}
}
func SendCommand(msgstr interface{}) {
str, ok := msgstr.(string)
if !ok {
fmt.Println("不能正常转换成 string 消息")
return
}
strarr := strings.Split(str, " ")
sUid, err := strconv.Atoi(strarr[0])
if err != nil {
fmt.Println("命令格式错误, 第一个参数需要是数字...", strarr[0])
return
}
eUid, err := strconv.Atoi(strarr[1])
if err != nil {
fmt.Println("命令格式错误, 第二个参数需要是数字...", strarr[1])
return
}
if eUid <= sUid {
fmt.Println("命令格式错误, 第二个参数不能小于等于第一个参数....")
return
}
for uid := sUid; uid<= eUid; uid ++ {
user, ok := userMap[int64(uid)]
if ok {
user.IntoGame()
}
}
}
func OpenLogPrint(msgstr interface{}) {
print = true
}