blob: 3d0bdbfa5c8898bd5de806dc96e047a1cc928af0 (
plain)
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
|
package game
import (
"fmt"
"strconv"
"strings"
"thehouseoficarus/internal/net"
)
func (g *Game) executeSetPlayerFlag(sess *net.Session, args []string, rawInput string) {
if !g.checkAdmin(sess) {
sess.WriteLine("Unknown command.")
return
}
if len(args) < 2 {
sess.WriteLine("Usage: setplayerflag <player_name> <flag_name> [value]")
return
}
targetName := args[0]
flagName := args[1]
g.charsMu.Lock()
targetSess, ok := g.loggedInChars[targetName]
g.charsMu.Unlock()
if !ok {
for _, other := range g.Hub.AllSessions() {
if other.Player != nil && strings.EqualFold(other.Player.Name, targetName) {
targetSess = other
break
}
}
}
if targetSess == nil || targetSess.Player == nil {
sess.WriteLine("Player not found.")
return
}
tp := targetSess.Player
var value any = true
if len(args) > 2 {
valStr := args[2]
switch valStr {
case "true":
value = true
case "false":
value = false
default:
if n, err := strconv.Atoi(valStr); err == nil {
value = n
} else {
value = valStr
}
}
}
g.setPlayerFlag(tp, flagName, value)
g.AccountStore.SaveCharacter(tp)
sess.WriteLine(fmt.Sprintf("Player flag '%s' set to %v for %s.", flagName, value, tp.Name))
}
|