-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiz_cmd.go
205 lines (180 loc) · 4.76 KB
/
wiz_cmd.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package main
import (
"fmt"
"goMUD2/figletlib"
"strconv"
"strings"
"syscall"
"time"
"github.com/hako/durafmt"
)
func cmdShutdown(player *characterData, input string) {
signalHandle <- syscall.SIGINT
}
func cmdPanic(player *characterData, input string) {
panic("test")
}
func cmdForce(player *characterData, input string) {
args := strings.SplitN(input, " ", 2)
if input == "" {
player.send("force <player name/all> <command>")
}
if len(args) < 2 {
player.send("But what command?")
return
}
if strings.EqualFold(args[1], "force") {
player.send("You can't use force to run force.")
return
}
if strings.EqualFold(args[0], "all") {
for _, target := range charList {
if target == player {
//Don't force yourself
continue
}
goForce(target, args[1])
target.send("%v forced you to: %v", player.Name, args[1])
}
player.send("Forced everyone to: %v", args[1])
critLog("%v forced everyone to: %v", player.Name, args[1])
return
}
if target := checkPlaying(args[0]); target != nil {
if target == player {
player.send("You can't force youself")
return
}
goForce(target, args[1])
target.send("%v forced you to: %v", player.Name, args[1])
player.send("You forced %v to: %v", target.Name, args[1])
critLog("%v forced %v to: %v", player.Name, target.Name, args[1])
} else {
player.send("They don't seem to be online.")
}
}
/* To do: remove dupe code */
func goForce(player *characterData, input string) {
cmdStr, args, _ := strings.Cut(input, " ")
cmdStr = strings.ToLower(cmdStr)
var command *commandData
for _, cmd := range cmdList {
if strings.EqualFold(cmd.name, cmdStr) {
command = cmd
break
}
}
if command != nil {
if command.disabled {
player.send("That command is disabled.")
return
}
if command.checkCommandLevel(player) {
if command.forceArg != "" {
command.goDo(player, command.forceArg)
} else {
command.goDo(player, args)
}
}
} else {
if cmdChat(player, input) {
if !findCommandMatch(cmdList, player, cmdStr, args) {
player.listCommands("")
}
}
}
}
func cmdBoom(player *characterData, input string) {
buf := fmt.Sprintf("%v booms: %v", player.Name, input)
boom, err := figletlib.TXTToAscii(buf, "standard", "left", 0)
if err != nil {
player.send("Sorry, unable to load the font.")
return
}
for _, target := range charList {
target.send(boom)
}
}
func cmdConInfo(player *characterData, input string) {
player.send("Descriptors:")
for _, item := range descList {
player.send(NEWLINE+"ID: %-32v IP: %v", item.id, item.ip)
player.send("State: %-29v DNS: %v", cEllip(stateName[item.state], 29), item.dns)
player.send("Idle: %-30v Connected: %v",
cEllip(durafmt.ParseShort(time.Since(item.idleTime)).String(), 30),
durafmt.ParseShort(time.Since(item.connectTime)))
charmap := item.telnet.charMap.String()
if item.telnet.Options != nil && item.telnet.Options.MTTS.hasFlag(MTTS_UTF8) {
charmap = "UTF"
}
player.send("Client: %-28v Charmap: %v", cEllip(strings.Join(item.telnet.termTypeStrings, ","), 28), charmap)
if item.character != nil {
player.send("Char: %-30v Account: %v", cEllip(item.character.Name, 30), item.account.Login)
}
if item.telnet.Options.HasMTTS {
buf := ""
for i, mtts := range MTTSNames {
if item.telnet.Options.MTTS.hasFlag(i) {
if buf != "" {
buf = buf + ", "
}
buf = buf + mtts.Name
}
}
player.send("MTTS: %v (%v)", item.telnet.Options.MTTS, buf)
}
}
}
func cmdPset(player *characterData, input string) {
var target *characterData
if input == "" {
cmdHelp(player, "pset")
}
args := strings.Split(input, " ")
numArgs := len(args)
name := args[0]
if target = checkPlaying(name); target == nil {
player.send("They aren't online at the moment.")
return
}
if numArgs < 2 {
cmdHelp(player, "pset")
return
}
command := strings.ToLower(args[1])
if command == "level" {
if numArgs < 3 {
cmdHelp(player, "pset")
return
}
level, err := strconv.Atoi(args[2])
if err != nil {
player.send("That isn't a number.")
return
} else {
if level > player.Level {
player.send("You can't set a player's level to a level higher than your own.")
return
}
target.Level = level
player.send("%v's level is now %v.", target.Name, target.Level)
target.dirty = true
return
}
}
}
func cmdTransport(player *characterData, input string) {
if input == "" {
player.send("Send who where?")
return
}
if target := checkPlayingPMatch(input); target != nil {
target.leaveRoom()
target.sendToRoom("%v suddenly vanishes!", target.Name)
target.send("You have been forced to recall.")
target.goTo(LocData{AreaUUID: sysAreaUUID, RoomUUID: sysRoomUUID})
player.send("Forced %v to recall.", target.Name)
return
}
player.send("I don't see anyone by that name.")
}