From fee2d2be8618d022222553fb31948dbd8ff0d763 Mon Sep 17 00:00:00 2001 From: MikeIsAStar <99037623+MikeIsAStar@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:15:30 -0500 Subject: [PATCH] GPCM: Append the "Message Of The Day" to a "Login Challenge" message --- common/strings.go | 9 +++++++++ gpcm/error.go | 5 ++++- gpcm/login.go | 29 ++++++++++++++++++++--------- gpcm/motd.go | 20 ++++++++++++++++++++ motd.txt | 2 ++ 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 gpcm/motd.go create mode 100644 motd.txt diff --git a/common/strings.go b/common/strings.go index 0474c90..c434465 100644 --- a/common/strings.go +++ b/common/strings.go @@ -28,6 +28,15 @@ func RandomHexString(n int) string { return string(b) } +func UTF16ToByteArray(wideString []uint16) []byte { + byteArray := make([]byte, len(wideString)*2) + for i, b := range wideString { + byteArray[(i*2)+0] = byte(b >> 8) + byteArray[(i*2)+1] = byte(b >> 0) + } + return byteArray +} + func GetString(buf []byte) (string, error) { nullTerminator := bytes.IndexByte(buf, 0) diff --git a/gpcm/error.go b/gpcm/error.go index b383311..350347e 100644 --- a/gpcm/error.go +++ b/gpcm/error.go @@ -3,6 +3,7 @@ package gpcm import ( "fmt" "strconv" + "unicode/utf16" "wwfc/common" "wwfc/logging" ) @@ -392,9 +393,11 @@ func (err GPError) GetMessageTranslate(gameName string, region byte, lang byte, } errMsg = fmt.Sprintf(errMsg, err.WWFCMessage.ErrorCode, ngid) + errMsgUTF16 := utf16.Encode([]rune(errMsg)) + errMsgByteArray := common.UTF16ToByteArray(errMsgUTF16) command.OtherValues["wwfc_err"] = strconv.Itoa(err.WWFCMessage.ErrorCode) - command.OtherValues["wwfc_errmsg"] = errMsg + command.OtherValues["wwfc_errmsg"] = common.Base64DwcEncoding.EncodeToString(errMsgByteArray) } } diff --git a/gpcm/login.go b/gpcm/login.go index abf0200..bc8701d 100644 --- a/gpcm/login.go +++ b/gpcm/login.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" "time" + "unicode/utf16" "wwfc/common" "wwfc/database" "wwfc/logging" @@ -303,18 +304,28 @@ func (g *GameSpySession) login(command common.GameSpyCommand) { replyUserId = 0 } + otherValues := map[string]string{ + "sesskey": strconv.FormatInt(int64(g.SessionKey), 10), + "proof": proof, + "userid": strconv.FormatUint(replyUserId, 10), + "profileid": strconv.FormatUint(uint64(g.User.ProfileId), 10), + "uniquenick": g.User.UniqueNick, + "lt": g.LoginTicket, + "id": command.OtherValues["id"], + } + + if g.GameName == "mariokartwii" { + if motd, err := GetMessageOfTheDay(); err == nil { + motdUTF16 := utf16.Encode([]rune(motd)) + motdByteArray := common.UTF16ToByteArray(motdUTF16) + otherValues["wwfc_motd"] = common.Base64DwcEncoding.EncodeToString(motdByteArray) + } + } + payload := common.CreateGameSpyMessage(common.GameSpyCommand{ Command: "lc", CommandValue: "2", - OtherValues: map[string]string{ - "sesskey": strconv.FormatInt(int64(g.SessionKey), 10), - "proof": proof, - "userid": strconv.FormatUint(replyUserId, 10), - "profileid": strconv.FormatUint(uint64(g.User.ProfileId), 10), - "uniquenick": g.User.UniqueNick, - "lt": g.LoginTicket, - "id": command.OtherValues["id"], - }, + OtherValues: otherValues, }) g.Conn.Write([]byte(payload)) diff --git a/gpcm/motd.go b/gpcm/motd.go new file mode 100644 index 0000000..3a0c657 --- /dev/null +++ b/gpcm/motd.go @@ -0,0 +1,20 @@ +package gpcm + +import ( + "os" + "strings" +) + +var motdFilepath = "./motd.txt" + +func GetMessageOfTheDay() (string, error) { + contents, err := os.ReadFile(motdFilepath) + if err != nil { + return "", err + } + + strContents := string(contents) + strContents = strings.TrimSpace(strContents) + + return strContents, nil +} diff --git a/motd.txt b/motd.txt new file mode 100644 index 0000000..d21e28c --- /dev/null +++ b/motd.txt @@ -0,0 +1,2 @@ +Welcome to +WiiLink Wi-Fi Connection! \ No newline at end of file