Use secret key from game list

This commit is contained in:
Sketch 2023-11-11 11:49:45 -05:00
parent 8dd9c62187
commit 32c128c0fe
3 changed files with 33 additions and 47 deletions

View File

@ -15,53 +15,35 @@ type GameInfo struct {
}
var (
gameListReady = false
gameList = []GameInfo{}
gameList []GameInfo
gameListIDLookup = map[int]int{}
gameListNameLookup = map[string]int{}
mutex = sync.RWMutex{}
)
func GetGameList() []GameInfo {
if !gameListReady {
ReadGameList()
}
return gameList
}
func GetGameInfoByID(gameId int) (GameInfo, bool) {
if !gameListReady {
ReadGameList()
}
if index, ok := gameListIDLookup[gameId]; ok && index < len(gameList) {
return gameList[index], true
}
return GameInfo{}, false
}
func GetGameInfoByName(name string) (GameInfo, bool) {
if !gameListReady {
ReadGameList()
}
if index, ok := gameListNameLookup[name]; ok && index < len(gameList) {
return gameList[index], true
}
return GameInfo{}, false
}
func ReadGameList() {
func GetGameInfoByID(gameId int) *GameInfo {
mutex.Lock()
defer mutex.Unlock()
if gameListReady {
return
if index, ok := gameListIDLookup[gameId]; ok && index < len(gameList) {
return &gameList[index]
}
return nil
}
func GetGameInfoByName(name string) *GameInfo {
mutex.Lock()
defer mutex.Unlock()
if index, ok := gameListNameLookup[name]; ok && index < len(gameList) {
return &gameList[index]
}
return nil
}
func ReadGameList() {
file, err := os.Open("game_list.tsv")
if err != nil {
panic(err)
@ -101,6 +83,4 @@ func ReadGameList() {
}
gameListNameLookup[entry[1]] = index
}
gameListReady = true
}

View File

@ -180,8 +180,8 @@ func handleStorageRequest(moduleName string, w http.ResponseWriter, r *http.Requ
}
func getRequestIdentity(moduleName string, request StorageRequestData) (uint32, common.GameInfo, bool) {
gameInfo, ok := common.GetGameInfoByID(request.GameID)
if !ok {
gameInfo := common.GetGameInfoByID(request.GameID)
if gameInfo == nil {
logging.Error(moduleName, "Invalid game ID:", aurora.Cyan(request.GameID))
panic("Invalid game ID")
}
@ -197,13 +197,13 @@ func getRequestIdentity(moduleName string, request StorageRequestData) (uint32,
logging.Info(moduleName, "Game:", aurora.Cyan(request.GameID), "-", aurora.BrightCyan(gameInfo.Name))
logging.Info(moduleName, "Table ID:", aurora.Cyan(request.TableID))
return profileId, gameInfo, true
return profileId, *gameInfo, true
}
func binaryDataValue(value []byte) StorageValue {
return StorageValue{
XMLName: xml.Name{"", "binaryDataValue"},
Value: base64.StdEncoding.EncodeToString([]byte(value)),
Value: base64.StdEncoding.EncodeToString(value),
}
}
@ -244,7 +244,7 @@ func getMyRecords(moduleName string, profileId uint32, gameInfo common.GameInfo,
case "mariokartwii/FriendInfo":
// Mario Kart Wii friend info
values = map[string]StorageValue{
"ownerid": uintValue(uint32(profileId)),
"ownerid": uintValue(profileId),
"recordid": intValue(int32(profileId)),
"info": binaryDataValueBase64(database.GetMKWFriendInfo(pool, ctx, profileId)),
}
@ -327,7 +327,7 @@ func searchForRecords(moduleName string, profileId uint32, gameInfo common.GameI
// TODO: Check if the two are friends maybe
values = []map[string]StorageValue{
map[string]StorageValue{
{
"ownerid": uintValue(uint32(ownerId)),
"recordid": intValue(int32(ownerId)),
"info": binaryDataValueBase64(database.GetMKWFriendInfo(pool, ctx, uint32(ownerId))),

View File

@ -62,6 +62,12 @@ func handleServerListRequest(conn net.Conn, buffer []byte) {
logging.Info(ModuleName, "queryGame:", aurora.Cyan(queryGame).String(), "- gameName:", aurora.Cyan(gameName).String(), "- filter:", aurora.Cyan(filter).String(), "- fields:", aurora.Cyan(fields).String())
gameInfo := common.GetGameInfoByName(gameName)
if gameInfo == nil {
// Game doesn't exist in the game list.
return
}
var output []byte
for _, s := range strings.Split(strings.Split(conn.RemoteAddr().String(), ":")[0], ".") {
val, err := strconv.Atoi(s)
@ -90,7 +96,7 @@ func handleServerListRequest(conn net.Conn, buffer []byte) {
// Write the encrypted reply
// TODO: Key is currently hardcoded to Mario Kart Wii
conn.Write(common.EncryptTypeX([]byte("9r3Rmy"), challenge, output))
conn.Write(common.EncryptTypeX([]byte(gameInfo.SecretKey), challenge, output))
return
}
@ -231,7 +237,7 @@ func handleServerListRequest(conn net.Conn, buffer []byte) {
output = append(output, []byte{0x00, 0xff, 0xff, 0xff, 0xff}...)
// Write the encrypted reply
conn.Write(common.EncryptTypeX([]byte("9r3Rmy"), challenge, output))
conn.Write(common.EncryptTypeX([]byte(gameInfo.SecretKey), challenge, output))
}
func handleSendMessageRequest(conn net.Conn, buffer []byte) {