Skip to content

Commit

Permalink
Add pid and wbz id
Browse files Browse the repository at this point in the history
  • Loading branch information
expiteRz committed Aug 11, 2023
1 parent 31d309c commit 60e4c1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions utils/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
18 changes: 14 additions & 4 deletions web/wiimmfi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"app.rz-public.xyz/wiimmfi-room-watcher/utils"
"encoding/json"
"fmt"
"github.com/spf13/cast"
"io"
"log"
"net/http"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 60e4c1a

Please sign in to comment.