diff --git a/gpcm/login.go b/gpcm/login.go index 0023dd6..e429732 100644 --- a/gpcm/login.go +++ b/gpcm/login.go @@ -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) diff --git a/gpcm/motd.go b/gpcm/motd.go index 3a0c657..b0b6c04 100644 --- a/gpcm/motd.go +++ b/gpcm/motd.go @@ -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 } diff --git a/nas/main.go b/nas/main.go index e2f03fe..30d7228 100644 --- a/nas/main.go +++ b/nas/main.go @@ -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))) diff --git a/nas/profanity.go b/nas/profanity.go index 587bee1..ce425a9 100644 --- a/nas/profanity.go +++ b/nas/profanity.go @@ -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) {