GPCM: Append the "Message Of The Day" to a "Login Challenge" message

This commit is contained in:
MikeIsAStar 2024-02-13 18:15:30 -05:00
parent 467d54b765
commit fee2d2be86
5 changed files with 55 additions and 10 deletions

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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))

20
gpcm/motd.go Normal file
View File

@ -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
}

2
motd.txt Normal file
View File

@ -0,0 +1,2 @@
Welcome to
WiiLink Wi-Fi Connection!