298 lines
11 KiB
Go
298 lines
11 KiB
Go
package gameapi
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
gamev1 "hyapp.local/api/proto/game/v1"
|
|
)
|
|
|
|
type gameListData struct {
|
|
Games []gameItemData `json:"games"`
|
|
ServerTimeMS int64 `json:"server_time_ms"`
|
|
}
|
|
|
|
type gameItemData struct {
|
|
GameID string `json:"game_id"`
|
|
PlatformCode string `json:"platform_code"`
|
|
NameKey string `json:"name_key"`
|
|
Name string `json:"name"`
|
|
IconURL string `json:"icon_url"`
|
|
CoverURL string `json:"cover_url"`
|
|
Category string `json:"category"`
|
|
LaunchMode string `json:"launch_mode"`
|
|
Orientation string `json:"orientation"`
|
|
SafeHeight int32 `json:"safe_height"`
|
|
SafeHeightV2 int32 `json:"safeHeight"`
|
|
MinCoin int64 `json:"min_coin"`
|
|
Enabled bool `json:"enabled"`
|
|
Maintenance bool `json:"maintenance"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
}
|
|
|
|
type gameLaunchData struct {
|
|
SessionID string `json:"session_id"`
|
|
LaunchURL string `json:"launch_url"`
|
|
ExpiresAtMS int64 `json:"expires_at_ms"`
|
|
Orientation string `json:"orientation"`
|
|
SafeHeight int32 `json:"safe_height"`
|
|
SafeHeightV2 int32 `json:"safeHeight"`
|
|
ServerTimeMS int64 `json:"server_time_ms"`
|
|
}
|
|
|
|
type gameBridgeScriptData struct {
|
|
BridgeScriptURL string `json:"bridge_script_url"`
|
|
BridgeScriptURLV2 string `json:"bridgeScriptUrl"`
|
|
BridgeScriptVersion string `json:"bridge_script_version"`
|
|
BridgeScriptVersionV2 string `json:"bridgeScriptVersion"`
|
|
BridgeScriptSHA256 string `json:"bridge_script_sha256"`
|
|
BridgeScriptSHA256V2 string `json:"bridgeScriptSha256"`
|
|
ServerTimeMS int64 `json:"server_time_ms"`
|
|
}
|
|
|
|
type diceMatchData struct {
|
|
Match diceMatchItemData `json:"match"`
|
|
ServerTimeMS int64 `json:"server_time_ms"`
|
|
}
|
|
|
|
type diceConfigData struct {
|
|
Config diceConfigItemData `json:"config"`
|
|
ServerTimeMS int64 `json:"server_time_ms"`
|
|
}
|
|
|
|
type diceConfigItemData struct {
|
|
AppCode string `json:"app_code"`
|
|
GameID string `json:"game_id"`
|
|
Status string `json:"status"`
|
|
StakeOptions []diceStakeOptionData `json:"stake_options"`
|
|
FeeBPS int32 `json:"fee_bps"`
|
|
PoolBPS int32 `json:"pool_bps"`
|
|
MinPlayers int32 `json:"min_players"`
|
|
MaxPlayers int32 `json:"max_players"`
|
|
RobotEnabled bool `json:"robot_enabled"`
|
|
RobotMatchWaitMS int64 `json:"robot_match_wait_ms"`
|
|
PoolBalanceCoin int64 `json:"pool_balance_coin"`
|
|
}
|
|
|
|
type diceStakeOptionData struct {
|
|
StakeCoin int64 `json:"stake_coin"`
|
|
Enabled bool `json:"enabled"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
}
|
|
|
|
type diceMatchItemData struct {
|
|
AppCode string `json:"app_code"`
|
|
MatchID string `json:"match_id"`
|
|
GameID string `json:"game_id"`
|
|
RoomID string `json:"room_id"`
|
|
RegionID int64 `json:"region_id"`
|
|
MinPlayers int32 `json:"min_players"`
|
|
MaxPlayers int32 `json:"max_players"`
|
|
CurrentPlayers int32 `json:"current_players"`
|
|
StakeCoin int64 `json:"stake_coin"`
|
|
RoundNo int32 `json:"round_no"`
|
|
Status string `json:"status"`
|
|
Result string `json:"result"`
|
|
Participants []diceParticipantItemData `json:"participants"`
|
|
JoinDeadlineMS int64 `json:"join_deadline_ms"`
|
|
ReadyAtMS int64 `json:"ready_at_ms"`
|
|
CreatedAtMS int64 `json:"created_at_ms"`
|
|
UpdatedAtMS int64 `json:"updated_at_ms"`
|
|
SettledAtMS int64 `json:"settled_at_ms"`
|
|
CanceledAtMS int64 `json:"canceled_at_ms"`
|
|
Phase string `json:"phase"`
|
|
PhaseDeadlineMS int64 `json:"phase_deadline_ms"`
|
|
FeeBPS int32 `json:"fee_bps"`
|
|
PoolBPS int32 `json:"pool_bps"`
|
|
MatchMode string `json:"match_mode"`
|
|
ForcedResult string `json:"forced_result"`
|
|
PoolDeltaCoin int64 `json:"pool_delta_coin"`
|
|
}
|
|
|
|
type diceParticipantItemData struct {
|
|
UserID string `json:"user_id"`
|
|
UserIDNumber int64 `json:"user_id_number"`
|
|
SeatNo int32 `json:"seat_no"`
|
|
Status string `json:"status"`
|
|
StakeCoin int64 `json:"stake_coin"`
|
|
DicePoints []int32 `json:"dice_points"`
|
|
Result string `json:"result"`
|
|
PayoutCoin int64 `json:"payout_coin"`
|
|
BalanceAfter int64 `json:"balance_after"`
|
|
JoinedAtMS int64 `json:"joined_at_ms"`
|
|
UpdatedAtMS int64 `json:"updated_at_ms"`
|
|
ParticipantType string `json:"participant_type"`
|
|
IsRobot bool `json:"is_robot"`
|
|
User diceUserData `json:"user"`
|
|
AvatarFrame map[string]any `json:"avatar_frame"`
|
|
}
|
|
|
|
type diceUserData struct {
|
|
UserID string `json:"user_id"`
|
|
DisplayUserID string `json:"display_user_id"`
|
|
Nickname string `json:"nickname"`
|
|
Avatar string `json:"avatar"`
|
|
}
|
|
|
|
func gameListDataFromProto(resp *gamev1.ListGamesResponse) gameListData {
|
|
if resp == nil {
|
|
return gameListData{}
|
|
}
|
|
items := make([]gameItemData, 0, len(resp.GetGames()))
|
|
for _, item := range resp.GetGames() {
|
|
items = append(items, gameItemData{
|
|
GameID: item.GetGameId(),
|
|
PlatformCode: item.GetPlatformCode(),
|
|
NameKey: item.GetNameKey(),
|
|
Name: item.GetName(),
|
|
IconURL: item.GetIconUrl(),
|
|
CoverURL: item.GetCoverUrl(),
|
|
Category: item.GetCategory(),
|
|
LaunchMode: item.GetLaunchMode(),
|
|
Orientation: item.GetOrientation(),
|
|
SafeHeight: item.GetSafeHeight(),
|
|
SafeHeightV2: item.GetSafeHeight(),
|
|
MinCoin: item.GetMinCoin(),
|
|
Enabled: item.GetEnabled(),
|
|
Maintenance: item.GetMaintenance(),
|
|
SortOrder: item.GetSortOrder(),
|
|
})
|
|
}
|
|
return gameListData{Games: items, ServerTimeMS: resp.GetServerTimeMs()}
|
|
}
|
|
|
|
func gameLaunchDataFromProto(resp *gamev1.LaunchGameResponse) gameLaunchData {
|
|
if resp == nil {
|
|
return gameLaunchData{}
|
|
}
|
|
return gameLaunchData{
|
|
SessionID: resp.GetSessionId(),
|
|
LaunchURL: resp.GetLaunchUrl(),
|
|
ExpiresAtMS: resp.GetExpiresAtMs(),
|
|
Orientation: resp.GetOrientation(),
|
|
SafeHeight: resp.GetSafeHeight(),
|
|
SafeHeightV2: resp.GetSafeHeight(),
|
|
ServerTimeMS: resp.GetServerTimeMs(),
|
|
}
|
|
}
|
|
|
|
func diceConfigDataFromProto(resp *gamev1.DiceConfigResponse) diceConfigData {
|
|
if resp == nil {
|
|
return diceConfigData{}
|
|
}
|
|
config := resp.GetConfig()
|
|
options := make([]diceStakeOptionData, 0, len(config.GetStakeOptions()))
|
|
for _, option := range config.GetStakeOptions() {
|
|
options = append(options, diceStakeOptionData{
|
|
StakeCoin: option.GetStakeCoin(),
|
|
Enabled: option.GetEnabled(),
|
|
SortOrder: option.GetSortOrder(),
|
|
})
|
|
}
|
|
return diceConfigData{
|
|
Config: diceConfigItemData{
|
|
AppCode: config.GetAppCode(),
|
|
GameID: config.GetGameId(),
|
|
Status: config.GetStatus(),
|
|
StakeOptions: options,
|
|
FeeBPS: config.GetFeeBps(),
|
|
PoolBPS: config.GetPoolBps(),
|
|
MinPlayers: config.GetMinPlayers(),
|
|
MaxPlayers: config.GetMaxPlayers(),
|
|
RobotEnabled: config.GetRobotEnabled(),
|
|
RobotMatchWaitMS: config.GetRobotMatchWaitMs(),
|
|
PoolBalanceCoin: config.GetPoolBalanceCoin(),
|
|
},
|
|
ServerTimeMS: resp.GetServerTimeMs(),
|
|
}
|
|
}
|
|
|
|
func diceMatchDataFromProto(resp *gamev1.DiceMatchResponse) diceMatchData {
|
|
if resp == nil {
|
|
return diceMatchData{}
|
|
}
|
|
return diceMatchData{
|
|
Match: diceMatchItemDataFromProto(resp.GetMatch()),
|
|
ServerTimeMS: resp.GetServerTimeMs(),
|
|
}
|
|
}
|
|
|
|
func diceMatchItemDataFromProto(match *gamev1.DiceMatch) diceMatchItemData {
|
|
if match == nil {
|
|
return diceMatchItemData{}
|
|
}
|
|
participants := make([]diceParticipantItemData, 0, len(match.GetParticipants()))
|
|
for _, participant := range match.GetParticipants() {
|
|
participants = append(participants, diceParticipantItemDataFromProto(participant))
|
|
}
|
|
return diceMatchItemData{
|
|
AppCode: match.GetAppCode(),
|
|
MatchID: match.GetMatchId(),
|
|
GameID: match.GetGameId(),
|
|
RoomID: match.GetRoomId(),
|
|
RegionID: match.GetRegionId(),
|
|
MinPlayers: match.GetMinPlayers(),
|
|
MaxPlayers: match.GetMaxPlayers(),
|
|
CurrentPlayers: match.GetCurrentPlayers(),
|
|
StakeCoin: match.GetStakeCoin(),
|
|
RoundNo: match.GetRoundNo(),
|
|
Status: match.GetStatus(),
|
|
Result: match.GetResult(),
|
|
Participants: participants,
|
|
JoinDeadlineMS: match.GetJoinDeadlineMs(),
|
|
ReadyAtMS: match.GetReadyAtMs(),
|
|
CreatedAtMS: match.GetCreatedAtMs(),
|
|
UpdatedAtMS: match.GetUpdatedAtMs(),
|
|
SettledAtMS: match.GetSettledAtMs(),
|
|
CanceledAtMS: match.GetCanceledAtMs(),
|
|
Phase: match.GetPhase(),
|
|
PhaseDeadlineMS: match.GetPhaseDeadlineMs(),
|
|
FeeBPS: match.GetFeeBps(),
|
|
PoolBPS: match.GetPoolBps(),
|
|
MatchMode: match.GetMatchMode(),
|
|
ForcedResult: match.GetForcedResult(),
|
|
PoolDeltaCoin: match.GetPoolDeltaCoin(),
|
|
}
|
|
}
|
|
|
|
func diceParticipantItemDataFromProto(participant *gamev1.DiceParticipant) diceParticipantItemData {
|
|
if participant == nil {
|
|
return diceParticipantItemData{}
|
|
}
|
|
return diceParticipantItemData{
|
|
UserID: int64String(participant.GetUserId()),
|
|
UserIDNumber: participant.GetUserId(),
|
|
SeatNo: participant.GetSeatNo(),
|
|
Status: participant.GetStatus(),
|
|
StakeCoin: participant.GetStakeCoin(),
|
|
DicePoints: participant.GetDicePoints(),
|
|
Result: participant.GetResult(),
|
|
PayoutCoin: participant.GetPayoutCoin(),
|
|
BalanceAfter: participant.GetBalanceAfter(),
|
|
JoinedAtMS: participant.GetJoinedAtMs(),
|
|
UpdatedAtMS: participant.GetUpdatedAtMs(),
|
|
ParticipantType: participant.GetParticipantType(),
|
|
IsRobot: participant.GetIsRobot(),
|
|
AvatarFrame: map[string]any{},
|
|
}
|
|
}
|
|
|
|
func gameBridgeScriptDataFromProto(resp *gamev1.GetBridgeScriptResponse) gameBridgeScriptData {
|
|
if resp == nil {
|
|
return gameBridgeScriptData{}
|
|
}
|
|
config := resp.GetConfig()
|
|
return gameBridgeScriptData{
|
|
BridgeScriptURL: config.GetBridgeScriptUrl(),
|
|
BridgeScriptURLV2: config.GetBridgeScriptUrl(),
|
|
BridgeScriptVersion: config.GetBridgeScriptVersion(),
|
|
BridgeScriptVersionV2: config.GetBridgeScriptVersion(),
|
|
BridgeScriptSHA256: config.GetBridgeScriptSha256(),
|
|
BridgeScriptSHA256V2: config.GetBridgeScriptSha256(),
|
|
ServerTimeMS: resp.GetServerTimeMs(),
|
|
}
|
|
}
|
|
|
|
func int64String(value int64) string {
|
|
return fmt.Sprintf("%d", value)
|
|
}
|