-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.go
101 lines (85 loc) · 2.07 KB
/
font.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
package main
import (
"goMUD2/figletlib"
"os"
"strings"
)
const (
MAX_CRAZY_INPUT = 128
MAX_CRAZY_OUTPUT = 6000
)
func cmdCrazyTalk(player *characterData, input string) {
args := strings.SplitN(input, " ", 2)
numArgs := len(args)
if numArgs < 2 {
player.sendWW(fontListText)
player.send("What font?")
return
}
if len(args[1]) > MAX_CRAZY_INPUT {
player.send("That message is too long.")
return
}
lowerArg := strings.ToLower(args[0])
asciiMsg, err := figletlib.TXTToAscii(args[1], fontList[lowerArg], "left", 0)
if err != nil {
player.send("Sorry, that isn't a valid font.")
return
}
asciiLen := len(asciiMsg)
if asciiLen < 1 {
player.send("Sorry, something went wrong rendering that font.")
}
if asciiLen > MAX_CRAZY_OUTPUT {
player.send("That message is too long.")
return
}
sendToChannel(player, input, CHAT_CRAZY)
}
func handleCrazy(player *characterData, input string) string {
width := 80
if player.desc != nil &&
player.desc.telnet.Options != nil &&
!player.Config.hasFlag(CONFIG_NOWRAP) {
width = player.desc.telnet.Options.TermWidth
}
args := strings.SplitN(input, " ", 2)
numArgs := len(args)
if numArgs < 2 {
return "Error."
}
asciiMsg, _ := figletlib.TXTToAscii(args[1], args[0], "left", width)
return asciiMsg
}
var fontList map[string]string
var fontListText string
func updateFontList() error {
dir, err := os.ReadDir(figletlib.FONT_DIR)
if err != nil {
critLog("Unable to read font directory: %v -- %v", figletlib.FONT_DIR, err.Error())
return err
}
fontList = make(map[string]string)
fontListText = ""
itemNum := 0
for _, item := range dir {
if item.IsDir() {
continue
}
name := item.Name()
if strings.HasSuffix(name, ".flf") {
fname := strings.TrimSuffix(name, ".flf")
fname = strings.ToLower(fname)
fname = strings.ReplaceAll(fname, " ", "")
fname = strings.ReplaceAll(fname, "-", "")
fname = strings.ReplaceAll(fname, "_", "")
fontList[fname] = name
if itemNum > 0 {
fontListText = fontListText + ", "
}
itemNum++
fontListText = fontListText + fname
}
}
return nil
}