Skip to content

Commit 0355ab6

Browse files
EpicUsername12ppebb
authored andcommitted
Implement race teams/stage/finish time/reporting
1 parent 129550f commit 0355ab6

File tree

5 files changed

+430
-0
lines changed

5 files changed

+430
-0
lines changed

api/mkw_rr.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package api
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
"net/url"
7+
"strconv"
8+
"wwfc/qr2"
9+
)
10+
11+
type RaceResultInfo struct {
12+
Players map[uint32][]qr2.RacePlayer `json:"players"`
13+
Results map[int][]qr2.RaceResult `json:"results"`
14+
}
15+
16+
func HandleMKWRR(w http.ResponseWriter, r *http.Request) {
17+
u, err := url.Parse(r.URL.String())
18+
if err != nil {
19+
w.WriteHeader(http.StatusBadRequest)
20+
return
21+
}
22+
23+
query, err := url.ParseQuery(u.RawQuery)
24+
if err != nil {
25+
w.WriteHeader(http.StatusBadRequest)
26+
return
27+
}
28+
29+
groupNames := query["id"]
30+
if len(groupNames) != 1 {
31+
w.WriteHeader(http.StatusBadRequest)
32+
return
33+
}
34+
35+
results, players := qr2.GetRaceResultsForGroup(query["id"][0])
36+
if results == nil || players == nil {
37+
w.WriteHeader(http.StatusNotFound)
38+
return
39+
}
40+
41+
var jsonData []byte
42+
if len(results) == 0 {
43+
w.WriteHeader(http.StatusNotFound)
44+
return
45+
} else {
46+
jsonData, err = json.Marshal(RaceResultInfo{
47+
Players: players,
48+
Results: results,
49+
})
50+
if err != nil {
51+
w.WriteHeader(http.StatusInternalServerError)
52+
return
53+
}
54+
}
55+
56+
w.Header().Set("Content-Type", "application/json")
57+
w.Header().Set("Access-Control-Allow-Origin", "*")
58+
w.Header().Set("Content-Length", strconv.Itoa(len(jsonData)))
59+
w.Write(jsonData)
60+
}

gpcm/report.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ func (g *GameSpySession) handleWWFCReport(command common.GameSpyCommand) {
6363
}
6464

6565
qr2.ProcessMKWSelectRecord(g.User.ProfileId, key, value)
66+
67+
case "wl:mkw_extended_teams":
68+
if g.GameName != "mariokartwii" {
69+
logging.Warn(g.ModuleName, "Ignoring", keyColored, "from wrong game")
70+
continue
71+
}
72+
73+
qr2.ProcessMKWExtendedTeams(g.User.ProfileId, value)
74+
75+
case "wl:mkw_race_stage":
76+
if g.GameName != "mariokartwii" {
77+
logging.Warn(g.ModuleName, "Ignoring", keyColored, "from wrong game")
78+
continue
79+
}
80+
81+
qr2.ProcessMKWRaceStage(g.User.ProfileId, value)
82+
83+
case "wl:mkw_race_result":
84+
if g.GameName != "mariokartwii" {
85+
logging.Warn(g.ModuleName, "Ignoring", keyColored, "from wrong game")
86+
continue
87+
}
88+
89+
qr2.ProcessMKWRaceResult(g.User.ProfileId, value)
6690
}
6791
}
6892
}

nas/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
153153
return
154154
}
155155

156+
// Check for /api/mkw_rr
157+
if r.URL.Path == "/api/mkw_rr" {
158+
api.HandleMKWRR(w, r)
159+
return
160+
}
161+
156162
// Check for /api/stats
157163
if r.URL.Path == "/api/stats" {
158164
api.HandleStats(w, r)

0 commit comments

Comments
 (0)