mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-04-24 15:37:58 -05:00
Merge pull request #46 from MikeIsAStar/do-not-consider-a-string-of-length-zero-as-profane
[NAS] Do not consider a string of length zero as profane
This commit is contained in:
commit
8ffcdcec5f
|
|
@ -315,7 +315,9 @@ func (g *GameSpySession) login(command common.GameSpyCommand) {
|
|||
}
|
||||
|
||||
if g.GameName == "mariokartwii" {
|
||||
if motd, err := GetMessageOfTheDay(); err == nil {
|
||||
if motd, err := GetMessageOfTheDay(); err != nil {
|
||||
logging.Info(g.ModuleName, err)
|
||||
} else {
|
||||
motdUTF16 := utf16.Encode([]rune(motd))
|
||||
motdByteArray := common.UTF16ToByteArray(motdUTF16)
|
||||
otherValues["wwfc_motd"] = common.Base64DwcEncoding.EncodeToString(motdByteArray)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package gpcm
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var motdFilepath = "./motd.txt"
|
||||
|
|
@ -13,8 +12,5 @@ func GetMessageOfTheDay() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
strContents := string(contents)
|
||||
strContents = strings.TrimSpace(strContents)
|
||||
|
||||
return strContents, nil
|
||||
return string(contents), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,10 @@ func StartServer() {
|
|||
go startHTTPSProxy(config)
|
||||
}
|
||||
|
||||
CacheProfanityFile()
|
||||
err = CacheProfanityFile()
|
||||
if err != nil {
|
||||
logging.Info("NAS", err)
|
||||
}
|
||||
|
||||
logging.Notice("NAS", "Starting HTTP server on", address)
|
||||
panic(nhttp.ListenAndServe(address, http.HandlerFunc(handleRequest)))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package nas
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -9,15 +10,29 @@ import (
|
|||
var profanityFilePath = "./profanity.txt"
|
||||
var profanityFileLines []string = nil
|
||||
|
||||
func CacheProfanityFile() bool {
|
||||
contents, err := os.ReadFile(profanityFilePath)
|
||||
func CacheProfanityFile() error {
|
||||
file, err := os.Open(profanityFilePath)
|
||||
if err != nil {
|
||||
return false
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
profanityFileLines = append(profanityFileLines, line)
|
||||
}
|
||||
|
||||
lines := strings.Split(string(contents), "\n")
|
||||
profanityFileLines = lines
|
||||
return true
|
||||
if profanityFileLines == nil {
|
||||
return errors.New("the file '" + profanityFilePath + "' is empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsBadWord(word string) (bool, error) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user