201 lines
6.9 KiB
Go
201 lines
6.9 KiB
Go
package gamemanagement
|
||
|
||
import (
|
||
"strconv"
|
||
|
||
gamev1 "hyapp.local/api/proto/game/v1"
|
||
)
|
||
|
||
type platformDTO struct {
|
||
AppCode string `json:"appCode"`
|
||
PlatformCode string `json:"platformCode"`
|
||
PlatformName string `json:"platformName"`
|
||
Status string `json:"status"`
|
||
APIBaseURL string `json:"apiBaseUrl"`
|
||
// adapterType 决定服务端按哪家厂商协议拼启动 URL 和处理回调。
|
||
AdapterType string `json:"adapterType"`
|
||
// callbackSecret 是后台配置页可见的厂商 key/AppSecret;只对有 game:view 权限的管理员返回。
|
||
CallbackSecret string `json:"callbackSecret"`
|
||
CallbackSecretSet bool `json:"callbackSecretSet"`
|
||
CallbackIPWhitelist []string `json:"callbackIpWhitelist"`
|
||
// adapterConfigJson 承载 uid_mode/default_lang/token_ttl_seconds 等可热更新配置。
|
||
AdapterConfigJSON string `json:"adapterConfigJson"`
|
||
SortOrder int32 `json:"sortOrder"`
|
||
CreatedAtMS int64 `json:"createdAtMs"`
|
||
UpdatedAtMS int64 `json:"updatedAtMs"`
|
||
}
|
||
|
||
type catalogDTO struct {
|
||
AppCode string `json:"appCode"`
|
||
GameID string `json:"gameId"`
|
||
PlatformCode string `json:"platformCode"`
|
||
ProviderGameID string `json:"providerGameId"`
|
||
GameName string `json:"gameName"`
|
||
Category string `json:"category"`
|
||
IconURL string `json:"iconUrl"`
|
||
CoverURL string `json:"coverUrl"`
|
||
// launchUrl 只在厂商列表预览时返回,正式目录仍由 platform.adapterConfigJson.game_urls 按 providerGameId 解析。
|
||
LaunchURL string `json:"launchUrl,omitempty"`
|
||
LaunchMode string `json:"launchMode"`
|
||
Orientation string `json:"orientation"`
|
||
SafeHeight int32 `json:"safeHeight"`
|
||
MinCoin int64 `json:"minCoin"`
|
||
Status string `json:"status"`
|
||
SortOrder int32 `json:"sortOrder"`
|
||
Tags []string `json:"tags"`
|
||
CreatedAtMS int64 `json:"createdAtMs"`
|
||
UpdatedAtMS int64 `json:"updatedAtMs"`
|
||
}
|
||
|
||
type diceConfigDTO struct {
|
||
AppCode string `json:"appCode"`
|
||
GameID string `json:"gameId"`
|
||
Status string `json:"status"`
|
||
StakeOptions []diceStakeDTO `json:"stakeOptions"`
|
||
FeeBPS int32 `json:"feeBps"`
|
||
PoolBPS int32 `json:"poolBps"`
|
||
MinPlayers int32 `json:"minPlayers"`
|
||
MaxPlayers int32 `json:"maxPlayers"`
|
||
RobotEnabled bool `json:"robotEnabled"`
|
||
RobotMatchWaitMS int64 `json:"robotMatchWaitMs"`
|
||
PoolBalanceCoin int64 `json:"poolBalanceCoin"`
|
||
CreatedAtMS int64 `json:"createdAtMs"`
|
||
UpdatedAtMS int64 `json:"updatedAtMs"`
|
||
}
|
||
|
||
type diceStakeDTO struct {
|
||
StakeCoin int64 `json:"stakeCoin"`
|
||
Enabled bool `json:"enabled"`
|
||
SortOrder int32 `json:"sortOrder"`
|
||
}
|
||
|
||
type dicePoolAdjustmentDTO struct {
|
||
AdjustmentID string `json:"adjustmentId"`
|
||
GameID string `json:"gameId"`
|
||
AmountCoin int64 `json:"amountCoin"`
|
||
Direction string `json:"direction"`
|
||
Reason string `json:"reason"`
|
||
BalanceAfter int64 `json:"balanceAfter"`
|
||
CreatedAtMS int64 `json:"createdAtMs"`
|
||
}
|
||
|
||
type diceRobotDTO struct {
|
||
AppCode string `json:"appCode"`
|
||
GameID string `json:"gameId"`
|
||
UserID string `json:"userId"`
|
||
UserIDNumber int64 `json:"userIdNumber"`
|
||
ShortID string `json:"shortId"`
|
||
Nickname string `json:"nickname"`
|
||
Avatar string `json:"avatar"`
|
||
Status string `json:"status"`
|
||
CreatedByAdminID int64 `json:"createdByAdminId"`
|
||
CreatedAtMS int64 `json:"createdAtMs"`
|
||
UpdatedAtMS int64 `json:"updatedAtMs"`
|
||
}
|
||
|
||
func platformFromProto(item *gamev1.GamePlatform) platformDTO {
|
||
if item == nil {
|
||
return platformDTO{}
|
||
}
|
||
return platformDTO{
|
||
AppCode: item.GetAppCode(),
|
||
PlatformCode: item.GetPlatformCode(),
|
||
PlatformName: item.GetPlatformName(),
|
||
Status: item.GetStatus(),
|
||
APIBaseURL: item.GetApiBaseUrl(),
|
||
AdapterType: item.GetAdapterType(),
|
||
CallbackSecret: item.GetCallbackSecret(),
|
||
CallbackSecretSet: item.GetCallbackSecretSet(),
|
||
CallbackIPWhitelist: item.GetCallbackIpWhitelist(),
|
||
AdapterConfigJSON: item.GetAdapterConfigJson(),
|
||
SortOrder: item.GetSortOrder(),
|
||
CreatedAtMS: item.GetCreatedAtMs(),
|
||
UpdatedAtMS: item.GetUpdatedAtMs(),
|
||
}
|
||
}
|
||
|
||
func catalogFromProto(item *gamev1.GameCatalogItem) catalogDTO {
|
||
if item == nil {
|
||
return catalogDTO{}
|
||
}
|
||
return catalogDTO{
|
||
AppCode: item.GetAppCode(),
|
||
GameID: item.GetGameId(),
|
||
PlatformCode: item.GetPlatformCode(),
|
||
ProviderGameID: item.GetProviderGameId(),
|
||
GameName: item.GetGameName(),
|
||
Category: item.GetCategory(),
|
||
IconURL: item.GetIconUrl(),
|
||
CoverURL: item.GetCoverUrl(),
|
||
LaunchMode: item.GetLaunchMode(),
|
||
Orientation: item.GetOrientation(),
|
||
SafeHeight: item.GetSafeHeight(),
|
||
MinCoin: item.GetMinCoin(),
|
||
Status: item.GetStatus(),
|
||
SortOrder: item.GetSortOrder(),
|
||
Tags: item.GetTags(),
|
||
CreatedAtMS: item.GetCreatedAtMs(),
|
||
UpdatedAtMS: item.GetUpdatedAtMs(),
|
||
}
|
||
}
|
||
|
||
func diceConfigFromProto(item *gamev1.DiceConfig) diceConfigDTO {
|
||
if item == nil {
|
||
return diceConfigDTO{}
|
||
}
|
||
options := make([]diceStakeDTO, 0, len(item.GetStakeOptions()))
|
||
for _, option := range item.GetStakeOptions() {
|
||
options = append(options, diceStakeDTO{
|
||
StakeCoin: option.GetStakeCoin(),
|
||
Enabled: option.GetEnabled(),
|
||
SortOrder: option.GetSortOrder(),
|
||
})
|
||
}
|
||
return diceConfigDTO{
|
||
AppCode: item.GetAppCode(),
|
||
GameID: item.GetGameId(),
|
||
Status: item.GetStatus(),
|
||
StakeOptions: options,
|
||
FeeBPS: item.GetFeeBps(),
|
||
PoolBPS: item.GetPoolBps(),
|
||
MinPlayers: item.GetMinPlayers(),
|
||
MaxPlayers: item.GetMaxPlayers(),
|
||
RobotEnabled: item.GetRobotEnabled(),
|
||
RobotMatchWaitMS: item.GetRobotMatchWaitMs(),
|
||
PoolBalanceCoin: item.GetPoolBalanceCoin(),
|
||
CreatedAtMS: item.GetCreatedAtMs(),
|
||
UpdatedAtMS: item.GetUpdatedAtMs(),
|
||
}
|
||
}
|
||
|
||
func dicePoolAdjustmentFromProto(item *gamev1.DicePoolAdjustment) dicePoolAdjustmentDTO {
|
||
if item == nil {
|
||
return dicePoolAdjustmentDTO{}
|
||
}
|
||
return dicePoolAdjustmentDTO{
|
||
AdjustmentID: item.GetAdjustmentId(),
|
||
GameID: item.GetGameId(),
|
||
AmountCoin: item.GetAmountCoin(),
|
||
Direction: item.GetDirection(),
|
||
Reason: item.GetReason(),
|
||
BalanceAfter: item.GetBalanceAfter(),
|
||
CreatedAtMS: item.GetCreatedAtMs(),
|
||
}
|
||
}
|
||
|
||
func diceRobotFromProto(item *gamev1.DiceRobot) diceRobotDTO {
|
||
if item == nil {
|
||
return diceRobotDTO{}
|
||
}
|
||
return diceRobotDTO{
|
||
AppCode: item.GetAppCode(),
|
||
GameID: item.GetGameId(),
|
||
UserID: strconv.FormatInt(item.GetUserId(), 10),
|
||
UserIDNumber: item.GetUserId(),
|
||
Status: item.GetStatus(),
|
||
CreatedByAdminID: item.GetCreatedByAdminId(),
|
||
CreatedAtMS: item.GetCreatedAtMs(),
|
||
UpdatedAtMS: item.GetUpdatedAtMs(),
|
||
}
|
||
}
|