Skip to content

Commit

Permalink
Merge pull request #258 from inada-s/website-userlist
Browse files Browse the repository at this point in the history
Add flycast version and group by battle code in user list
  • Loading branch information
inada-s authored Jul 15, 2023
2 parents 6b840c2 + 3d4191f commit fe21d93
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 43 deletions.
28 changes: 21 additions & 7 deletions gdxsv/lbs_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ func (lbs *Lbs) RegisterHTTPHandlers() {
UserID string `json:"user_id,omitempty"`
Name string `json:"name,omitempty"`
Team string `json:"team,omitempty"`
LobbyID uint16 `json:"lobby_id,omitempty"`
BattleCode string `json:"battle_code,omitempty"`
BattlePos uint8 `json:"battle_pos,omitempty"`
Platform string `json:"platform,omitempty"`
Disk string `json:"disk,omitempty"`
Flycast string `json:"flycast,omitempty"`
}

type activeGame struct {
BattleCode string `json:"battle_code,omitempty"`
Region string `json:"region,omitempty"`
Disk string `json:"disk,omitempty"`
State string `json:"state,omitempty"`
LobbyID uint16 `json:"lobby_id,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}

Expand All @@ -71,17 +75,24 @@ func (lbs *Lbs) RegisterHTTPHandlers() {
for _, u := range lbs.userPeers {
if !userAdded[u.UserID] {
userAdded[u.UserID] = true
lobbyID := uint16(0)
if u.Lobby != nil {
lobbyID = u.Lobby.ID
}
user := &onlineUser{
UserID: u.UserID,
Name: u.Name,
Team: teamName(int(u.Team)),
LobbyID: lobbyID,
BattleCode: "",
Platform: u.Platform,
Disk: u.GameDisk,
Flycast: u.PlatformInfo["flycast"],
}

if u.logout && u.Battle != nil {
user.BattleCode = u.Battle.BattleCode
user.BattlePos = u.Battle.GetPosition(u.UserID)
resp.BattleUsers = append(resp.BattleUsers, user)
} else {
resp.LobbyUsers = append(resp.LobbyUsers, user)
Expand All @@ -91,21 +102,17 @@ func (lbs *Lbs) RegisterHTTPHandlers() {
})

for _, u := range sharedData.GetMcsUsers() {
disk := "unknown"
b, ok := sharedData.GetBattleGameInfo(u.BattleCode)
if ok {
disk = b.GameDisk
}

if !userAdded[u.UserID] {
userAdded[u.UserID] = true
resp.BattleUsers = append(resp.BattleUsers, &onlineUser{
UserID: u.UserID,
Name: u.Name,
Team: teamName(int(u.Team)),
BattleCode: u.BattleCode,
BattlePos: uint8(u.Pos),
Platform: u.Platform,
Disk: disk,
Disk: u.GameDisk,
Flycast: "unknown",
})
}
}
Expand All @@ -115,8 +122,15 @@ func (lbs *Lbs) RegisterHTTPHandlers() {
BattleCode: g.BattleCode,
Disk: g.GameDisk,
State: gameStateName(g.State),
LobbyID: g.LobbyID,
UpdatedAt: g.UpdatedAt,
})

for _, u := range resp.BattleUsers {
if u.BattleCode == g.BattleCode {
u.LobbyID = g.LobbyID
}
}
}

return resp, nil
Expand Down
2 changes: 2 additions & 0 deletions gdxsv/lbs_lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ func (l *LbsLobby) checkLobbyBattleStart(force bool) {
BattleCode: b.BattleCode,
RuleBin: SerializeRule(b.Rule),
GameDisk: l.GameDisk,
LobbyID: l.ID,
UpdatedAt: time.Now(),
State: McsGameStateCreated,
McsAddr: mcsAddr,
Expand Down Expand Up @@ -997,6 +998,7 @@ func (l *LbsLobby) checkRoomBattleStart() {
BattleCode: b.BattleCode,
RuleBin: SerializeRule(b.Rule),
GameDisk: l.GameDisk,
LobbyID: l.ID,
UpdatedAt: time.Now(),
State: McsGameStateCreated,
McsAddr: mcsAddr,
Expand Down
1 change: 1 addition & 0 deletions gdxsv/shareddata.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type McsGame struct {
BattleCode string `json:"battle_code,omitempty"`
McsAddr string `json:"mcs_addr,omitempty"`
GameDisk string `json:"game_disk"`
LobbyID uint16 `json:"lobby_id"`
RuleBin []byte `json:"rule_bin,omitempty"`
PatchList *proto.GamePatchList `json:"patch_list,omitempty"`

Expand Down
10 changes: 10 additions & 0 deletions website/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ body {
background-color: whitesmoke;
}

.user-id {
color: chocolate;
font-family: monospace;
font-weight: bolder;
}

.user-name {
font-weight: bolder;
}

.btn {
border-radius: 0;
}
Expand Down
112 changes: 88 additions & 24 deletions website/src/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ type OnlineUser = {
user_id: string
name: string
team: string
battleCode: string
lobby_id: number
battle_code: string
battle_pos: number
disk: string
flycast: string
platform: string

users_in_battle: number
}

type ActiveGame = {
battle_code: string
region: string
disk: string
state: string
lobby_id: number
updated_at: Date
}

Expand Down Expand Up @@ -60,8 +67,16 @@ export default class Status extends React.Component<Props, State> {
if (a.user_id > b.user_id) return 1;
return 0;
};
const compByBattleCode = (a: OnlineUser, b: OnlineUser) => {
if (a.battle_code < b.battle_code) return -1;
if (a.battle_code > b.battle_code) return 1;
if (a.battle_pos < b.battle_pos) return -1;
if (a.battle_pos > b.battle_pos) return 1;
return 0;
};
lobby_users.sort(compByUserId);
battle_users.sort(compByUserId);
battle_users.sort(compByBattleCode);

this.setState({
lobby_users,
battle_users,
Expand Down Expand Up @@ -89,42 +104,91 @@ export default class Status extends React.Component<Props, State> {
const dc2_lobby_users = this.state.lobby_users.filter((u: OnlineUser) => u.disk === "dc2");
const dc2_battle_users = this.state.battle_users.filter((u: OnlineUser) => u.disk === "dc2");

const renderTeamIcon = (team: string) => <>
{team === "renpo" && (
<Image
className={"ml-2 mr-2 mb-2"}
src={renpoIcon}
style={{backgroundColor: "CornflowerBlue"}}
height="20" width="20"
roundedCircle/>
)}
{team === "zeon" && (
<Image
className={"ml-2 mr-2 mb-2"}
src={zeonIcon}
style={{backgroundColor: "mediumvioletred"}}
height="20" width="20"
roundedCircle/>
)}
{team === "" && (
<Image
className={"ml-2 mr-2 mb-2"}
src={renpoIcon}
style={{backgroundColor: "CornflowerBlue", opacity: "0"}}
height="20" width="20"
roundedCircle/>
)}
</>

const renderOnlineUser = (u: OnlineUser) =>
<tr key={u.user_id}>
<td>{u.user_id}</td>
<td>{u.name}</td>
<td className={"text-center"}>
{u.team === "renpo" && (
<Image
src={renpoIcon}
style={{backgroundColor: "CornflowerBlue"}}
height="26" width="26"
roundedCircle/>
)}
{u.team === "zeon" && (
<Image
src={zeonIcon}
style={{backgroundColor: "mediumvioletred"}}
height="26" width="26"
roundedCircle/>
)}
<td>
{renderTeamIcon(u.team)}
<span className={"user-id m-2"}>{u.user_id}</span>
<span className={"user-name m-2"}>{u.name}</span>
<span className={"badge m-1 float-right"}>{u.flycast}</span>
</td>
<td className={"text-center align-middle"} >
<FormattedMessage id={"game.lobby" + u.lobby_id} />
</td>
</tr>

const renderOnlineUserTable = (users: OnlineUser[]) =>
<Table striped bordered hover size="sm">
<thead>
<tr>
<th><FormattedMessage id="status.user-id" /></th>
<th><FormattedMessage id="status.user-name" /></th>
<th><FormattedMessage id="status.team" /></th>
<th className={"text-center"}><FormattedMessage id="status.user" /></th>
<th className={"text-center"} style={{width: "20%"}}><FormattedMessage id="status.user-place" /></th>
</tr>
</thead>
<tbody>
{users.map(renderOnlineUser)}
</tbody>
</Table>

const renderBattleUser = (u: OnlineUser, idx: number, arr: OnlineUser[]) =>
<tr key={u.user_id}>
<td>
{renderTeamIcon(u.team)}
<span className={"user-id m-2"}>{u.user_id}</span>
<span className={"user-name m-2"}>{u.name}</span>
<span className={"badge m-1 float-right"}>{u.flycast}</span>
</td>
{u.battle_pos === 1 && (
<td className={"text-center align-middle"} rowSpan={
arr.filter(o => u.battle_code === o.battle_code)
.map(o => o.battle_pos)
.reduce((prev, curr) => prev < curr ? curr : prev)
}>
<FormattedMessage id={"game.lobby" + u.lobby_id} /> <br/>
</td>
)}
</tr>

const renderBattleUserTable = (users: OnlineUser[]) =>
<Table striped bordered hover size="sm">
<thead>
<tr>
<th className={"text-center"}><FormattedMessage id="status.user" /></th>
<th className={"text-center"} style={{width: "20%"}}><FormattedMessage id="status.user-place" /></th>
</tr>
</thead>
<tbody>
{users.map(renderBattleUser)}
</tbody>
</Table>

return (
<Container>
<Container>
Expand All @@ -139,7 +203,7 @@ export default class Status extends React.Component<Props, State> {
<h3><FormattedMessage id="status.lobby" values={{ peopleCount: dc2_lobby_users.length }} /></h3>
{renderOnlineUserTable(dc2_lobby_users)}
<h3><FormattedMessage id="status.battle" values={{ peopleCount: dc2_battle_users.length }} /></h3>
{renderOnlineUserTable(dc2_battle_users)}
{renderBattleUserTable(dc2_battle_users)}
</Container>

<Container>
Expand All @@ -154,7 +218,7 @@ export default class Status extends React.Component<Props, State> {
<h3><FormattedMessage id="status.lobby" values={{ peopleCount: dc1_lobby_users.length }} /></h3>
{renderOnlineUserTable(dc1_lobby_users)}
<h3><FormattedMessage id="status.battle" values={{ peopleCount: dc1_battle_users.length }} /></h3>
{renderOnlineUserTable(dc1_battle_users)}
{renderBattleUserTable(dc1_battle_users)}
</Container>
</Container>
);
Expand Down
26 changes: 22 additions & 4 deletions website/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,27 @@

"footer.copyright": "© gdxsv project 2020",

"status.user-id": "UserID",
"status.user-name": "Name",
"status.team": "Team",
"status.user": "User",
"status.user-place": "Place",
"status.lobby": "Lobby {peopleCount} people",
"status.battle": "Battle {peopleCount} people"
"status.battle": "Battle {peopleCount} people",

"game.lobby0": "戦場選択",
"game.lobby2": "タクラマカン砂漠",
"game.lobby4": "黒海南岸森林地帯",
"game.lobby5": "オデッサ",
"game.lobby6": "ベルファスト",
"game.lobby9": "ニューヤーク",
"game.lobby10": "グレートキャニオン",
"game.lobby11": "ジャブロー",
"game.lobby12": "地下基地",
"game.lobby13": "ソロモン",
"game.lobby14": "ソロモン宙域",
"game.lobby15": "ア・バオア・クー宙域",
"game.lobby16": "ア・バオア・クー外部",
"game.lobby17": "ア・バオア・クー内部",
"game.lobby19": "衛星軌道1",
"game.lobby20": "衛星軌道2",
"game.lobby21": "サイド6宙域",
"game.lobby22": "サイド7内部"
}
26 changes: 22 additions & 4 deletions website/src/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,27 @@

"footer.copyright": "© gdxsv project 2020",

"status.user-id": "UserID",
"status.user-name": "Name",
"status.team": "Team",
"status.user": "ユーザー",
"status.user-place": "戦場",
"status.lobby": "ロビー {peopleCount} 人",
"status.battle": "対戦中 {peopleCount} 人"
"status.battle": "対戦中 {peopleCount} 人",

"game.lobby0": "戦場選択",
"game.lobby2": "タクラマカン砂漠",
"game.lobby4": "黒海南岸森林地帯",
"game.lobby5": "オデッサ",
"game.lobby6": "ベルファスト",
"game.lobby9": "ニューヤーク",
"game.lobby10": "グレートキャニオン",
"game.lobby11": "ジャブロー",
"game.lobby12": "地下基地",
"game.lobby13": "ソロモン",
"game.lobby14": "ソロモン宙域",
"game.lobby15": "ア・バオア・クー宙域",
"game.lobby16": "ア・バオア・クー外部",
"game.lobby17": "ア・バオア・クー内部",
"game.lobby19": "衛星軌道1",
"game.lobby20": "衛星軌道2",
"game.lobby21": "サイド6宙域",
"game.lobby22": "サイド7内部"
}
26 changes: 22 additions & 4 deletions website/src/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,27 @@

"footer.copyright": "© gdxsv project 2020",

"status.user-id": "UserID",
"status.user-name": "Name",
"status.team": "Team",
"status.user": "User",
"status.user-place": "Place",
"status.lobby": "Lobby {peopleCount} 人",
"status.battle": "Battle {peopleCount} 人"
"status.battle": "Battle {peopleCount} 人",

"game.lobby0": "戦場選択",
"game.lobby2": "タクラマカン砂漠",
"game.lobby4": "黒海南岸森林地帯",
"game.lobby5": "オデッサ",
"game.lobby6": "ベルファスト",
"game.lobby9": "ニューヤーク",
"game.lobby10": "グレートキャニオン",
"game.lobby11": "ジャブロー",
"game.lobby12": "地下基地",
"game.lobby13": "ソロモン",
"game.lobby14": "ソロモン宙域",
"game.lobby15": "ア・バオア・クー宙域",
"game.lobby16": "ア・バオア・クー外部",
"game.lobby17": "ア・バオア・クー内部",
"game.lobby19": "衛星軌道1",
"game.lobby20": "衛星軌道2",
"game.lobby21": "サイド6宙域",
"game.lobby22": "サイド7内部"
}

0 comments on commit fe21d93

Please sign in to comment.