remove non-printable unicode from name
This commit is contained in:
11
main.go
11
main.go
@@ -10,6 +10,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TF2Stat struct {
|
type TF2Stat struct {
|
||||||
@@ -59,11 +60,17 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var enc lineprotocol.Encoder
|
cleanName := strings.Map(func(r rune) rune {
|
||||||
|
if unicode.IsPrint(r) {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}, tStat.Name)
|
||||||
|
|
||||||
|
var enc lineprotocol.Encoder
|
||||||
enc.StartLine("tf2server")
|
enc.StartLine("tf2server")
|
||||||
enc.AddTag("address", string(ip))
|
enc.AddTag("address", string(ip))
|
||||||
enc.AddTag("name", tStat.Name)
|
enc.AddTag("name", cleanName)
|
||||||
enc.AddField("player", lineprotocol.IntValue(int64(tStat.NumPlayers)))
|
enc.AddField("player", lineprotocol.IntValue(int64(tStat.NumPlayers)))
|
||||||
enc.AddField("maxplayer", lineprotocol.IntValue(int64(tStat.MaxPlayers)))
|
enc.AddField("maxplayer", lineprotocol.IntValue(int64(tStat.MaxPlayers)))
|
||||||
enc.AddField("ping", lineprotocol.IntValue(int64(tStat.Ping)))
|
enc.AddField("ping", lineprotocol.IntValue(int64(tStat.Ping)))
|
||||||
|
Reference in New Issue
Block a user