mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-08-06 02:18:37 -05:00
API: More information in groups
This commit is contained in:
parent
61221bddea
commit
b1849bb68e
|
|
@ -25,8 +25,8 @@ func HandleGroups(w http.ResponseWriter, r *http.Request) {
|
|||
for i, player := range group.Players {
|
||||
filtered := map[string]string{}
|
||||
|
||||
filtered["dwc_pid"] = player["dwc_pid"]
|
||||
filtered["ingamename"] = player["ingamename"]
|
||||
filtered["pid"] = player["dwc_pid"]
|
||||
filtered["name"] = player["name"]
|
||||
|
||||
if player["gamename"] == "mariokartwii" {
|
||||
filtered["ev"] = player["ev"]
|
||||
|
|
|
|||
42
qr2/group.go
42
qr2/group.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/logrusorgru/aurora/v3"
|
||||
"strconv"
|
||||
"strings"
|
||||
"wwfc/common"
|
||||
"wwfc/logging"
|
||||
)
|
||||
|
|
@ -12,6 +13,8 @@ type Group struct {
|
|||
GroupID uint32
|
||||
GroupName string
|
||||
GameName string
|
||||
MatchType string
|
||||
MKWRegion string
|
||||
Server *Session
|
||||
Players map[*Session]bool
|
||||
}
|
||||
|
|
@ -30,6 +33,8 @@ func processResvOK(moduleName string, cmd common.MatchCommandDataResvOK, sender,
|
|||
GroupID: cmd.GroupID,
|
||||
GroupName: "",
|
||||
GameName: sender.Data["gamename"],
|
||||
MatchType: sender.Data["dwc_mtype"],
|
||||
MKWRegion: "",
|
||||
Server: sender,
|
||||
Players: map[*Session]bool{sender: true},
|
||||
}
|
||||
|
|
@ -44,6 +49,18 @@ func processResvOK(moduleName string, cmd common.MatchCommandDataResvOK, sender,
|
|||
break
|
||||
}
|
||||
|
||||
if group.GameName == "mariokartwii" {
|
||||
rk := sender.Data["rk"]
|
||||
|
||||
// Check and remove regional searches due to the limited player count
|
||||
// China (ID 6) gets a pass because it was never released
|
||||
if len(rk) == 4 && (strings.HasPrefix(rk, "vs_") || strings.HasPrefix(rk, "bt_")) && rk[3] >= '0' && rk[3] < '6' {
|
||||
rk = rk[:2]
|
||||
}
|
||||
|
||||
group.MKWRegion = rk
|
||||
}
|
||||
|
||||
sender.GroupPointer = group
|
||||
groups[group.GroupName] = group
|
||||
|
||||
|
|
@ -123,7 +140,10 @@ func ProcessGPStatusUpdate(senderIP uint64, status string) {
|
|||
type GroupInfo struct {
|
||||
GroupName string `json:"id"`
|
||||
GameName string `json:"gamename"`
|
||||
ServerPID string `json:"host"`
|
||||
MatchType string `json:"type"`
|
||||
Suspend bool `json:"suspend"`
|
||||
ServerPID string `json:"host,omitempty"`
|
||||
MKWRegion string `json:"rk,omitempty"`
|
||||
Players []map[string]string `json:"players"`
|
||||
}
|
||||
|
||||
|
|
@ -140,20 +160,38 @@ func GetGroups(gameName string) []GroupInfo {
|
|||
groupInfo := GroupInfo{
|
||||
GroupName: group.GroupName,
|
||||
GameName: group.GameName,
|
||||
Suspend: true,
|
||||
ServerPID: "",
|
||||
MKWRegion: "",
|
||||
Players: []map[string]string{},
|
||||
}
|
||||
|
||||
if group.Server != nil {
|
||||
if group.MatchType == "0" || group.MatchType == "1" {
|
||||
groupInfo.MatchType = "anybody"
|
||||
} else if group.MatchType == "2" || group.MatchType == "3" {
|
||||
groupInfo.MatchType = "private"
|
||||
} else {
|
||||
groupInfo.MatchType = "unknown"
|
||||
}
|
||||
|
||||
if groupInfo.MatchType == "private" && group.Server != nil {
|
||||
groupInfo.ServerPID = group.Server.Data["dwc_pid"]
|
||||
}
|
||||
|
||||
if groupInfo.GameName == "mariokartwii" {
|
||||
groupInfo.MKWRegion = group.MKWRegion
|
||||
}
|
||||
|
||||
for session, _ := range group.Players {
|
||||
mapData := map[string]string{}
|
||||
for k, v := range session.Data {
|
||||
mapData[k] = v
|
||||
}
|
||||
groupInfo.Players = append(groupInfo.Players, mapData)
|
||||
|
||||
if mapData["dwc_hoststate"] == "2" && mapData["dwc_suspend"] == "0" {
|
||||
groupInfo.Suspend = false
|
||||
}
|
||||
}
|
||||
|
||||
groupsCopy = append(groupsCopy, groupInfo)
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ func (session *Session) setProfileID(moduleName string, newPID string) bool {
|
|||
|
||||
for _, sessionID := range outdated {
|
||||
logging.Notice(moduleName, "Removing outdated session", aurora.BrightCyan(sessionID), "with PID", aurora.Cyan(newPID))
|
||||
delete(sessions, sessionID)
|
||||
removeSession(sessionID)
|
||||
}
|
||||
|
||||
session.Data["dwc_pid"] = newPID
|
||||
|
|
@ -232,7 +232,7 @@ func GetSessionServers() []map[string]string {
|
|||
// Remove unreachable sessions
|
||||
for _, sessionID := range unreachable {
|
||||
logging.Notice("QR2", "Removing unreachable session", aurora.BrightCyan(sessionID))
|
||||
delete(sessions, sessionID)
|
||||
removeSession(sessionID)
|
||||
}
|
||||
|
||||
return servers
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user