From 60e4c1a7fed94270a5064d960e33d25dc3d8f277 Mon Sep 17 00:00:00 2001 From: expiteRz Date: Sat, 12 Aug 2023 02:52:17 +0900 Subject: [PATCH] Add pid and wbz id --- utils/structs.go | 2 ++ web/wiimmfi.go | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/utils/structs.go b/utils/structs.go index 44bab93..7dd6bed 100644 --- a/utils/structs.go +++ b/utils/structs.go @@ -11,9 +11,11 @@ type RoomSetting struct { GameMode int `json:"game_mode"` Engine int `json:"engine"` Course string `json:"course"` + CourseId int `json:"course_id"` } type RoomMember struct { + Pid int `json:"pid"` FriendCode string `json:"friend_code"` Name string `json:"name"` GuestName string `json:"guest_name,omitempty"` diff --git a/web/wiimmfi.go b/web/wiimmfi.go index 51c518c..a486470 100644 --- a/web/wiimmfi.go +++ b/web/wiimmfi.go @@ -4,6 +4,7 @@ import ( "app.rz-public.xyz/wiimmfi-room-watcher/utils" "encoding/json" "fmt" + "github.com/spf13/cast" "io" "log" "net/http" @@ -17,6 +18,12 @@ func StartParseRoom() { err error data utils.RoomData ) + checkSelf := func(i, j int) string { + if i == j { + return ">" + } + return " " + } // Initialize JSONByte JSONByte, err = json.Marshal(data) if err != nil { @@ -80,24 +87,27 @@ func StartParseRoom() { /// Current track/arena fmt.Printf("Track: %s\n", test.([]interface{})[2].(map[string]interface{})["track"].([]interface{})[1]) data.Setting.Course = test.([]interface{})[2].(map[string]interface{})["track"].([]interface{})[1].(string) + data.Setting.CourseId = cast.ToInt(test.([]interface{})[2].(map[string]interface{})["track"].([]interface{})[0]) /// Players players := test.([]interface{})[2].(map[string]interface{})["members"].([]interface{}) for _, player := range players { fmt.Printf( - "%-15s %-20s %4sVR\n", + "%s %-15s %-20s %4sVR\n", + checkSelf(utils.LoadedConfig.Pid, cast.ToInt(player.(map[string]interface{})["pid"])), player.(map[string]interface{})["fc"], player.(map[string]interface{})["name"].([]interface{})[0].([]interface{})[0], strconv.FormatFloat(player.(map[string]interface{})["ev"].(float64), 'f', 0, 64), ) member := utils.RoomMember{ + Pid: cast.ToInt(player.(map[string]interface{})["pid"]), FriendCode: player.(map[string]interface{})["fc"].(string), Name: player.(map[string]interface{})["name"].([]interface{})[0].([]interface{})[0].(string), - RaceRating: int(player.(map[string]interface{})["ev"].(float64)), - BattleRating: int(player.(map[string]interface{})["eb"].(float64)), + RaceRating: cast.ToInt(player.(map[string]interface{})["ev"]), + BattleRating: cast.ToInt(player.(map[string]interface{})["eb"]), } // If guest exists then print guest name if player.(map[string]interface{})["name"].([]interface{})[1].([]interface{})[0] != nil { - fmt.Printf("%-15s %-20s\n", "", player.(map[string]interface{})["name"].([]interface{})[1].([]interface{})[0]) + fmt.Printf("%s %-15s %-20s\n", checkSelf(utils.LoadedConfig.Pid, cast.ToInt(player.(map[string]interface{})["pid"])), "", player.(map[string]interface{})["name"].([]interface{})[1].([]interface{})[0]) member.GuestName = player.(map[string]interface{})["name"].([]interface{})[1].([]interface{})[0].(string) } data.Members = append(data.Members, member)