游戏修复
This commit is contained in:
parent
36833deb15
commit
bea31229ce
@ -42,10 +42,10 @@ type baishunAdapterConfig struct {
|
|||||||
TokenTTLSeconds int64 `json:"token_ttl_seconds"`
|
TokenTTLSeconds int64 `json:"token_ttl_seconds"`
|
||||||
|
|
||||||
// 以下字段是 NativeBridge.getConfig 需要返回给 H5 的配置,同时也会拼在启动 URL query 中给壳层复用。
|
// 以下字段是 NativeBridge.getConfig 需要返回给 H5 的配置,同时也会拼在启动 URL query 中给壳层复用。
|
||||||
GameMode string `json:"game_mode"`
|
GameMode baishunGameModeValue `json:"game_mode"`
|
||||||
SceneMode int64 `json:"scene_mode"`
|
SceneMode int64 `json:"scene_mode"`
|
||||||
CurrencyIcon string `json:"currency_icon"`
|
CurrencyIcon string `json:"currency_icon"`
|
||||||
GSP int64 `json:"gsp"`
|
GSP int64 `json:"gsp"`
|
||||||
|
|
||||||
// 可选用户管控字段;配置后会随 get_sstoken/get_user_info 一起返回给百顺。
|
// 可选用户管控字段;配置后会随 get_sstoken/get_user_info 一起返回给百顺。
|
||||||
UserType int `json:"user_type"`
|
UserType int `json:"user_type"`
|
||||||
@ -77,7 +77,7 @@ func baishunConfigFromPlatform(value any) baishunAdapterConfig {
|
|||||||
config.AppChannel = strings.TrimSpace(config.AppChannel)
|
config.AppChannel = strings.TrimSpace(config.AppChannel)
|
||||||
config.UIDMode = strings.ToLower(strings.TrimSpace(config.UIDMode))
|
config.UIDMode = strings.ToLower(strings.TrimSpace(config.UIDMode))
|
||||||
config.DefaultLang = strings.TrimSpace(config.DefaultLang)
|
config.DefaultLang = strings.TrimSpace(config.DefaultLang)
|
||||||
config.GameMode = strings.TrimSpace(config.GameMode)
|
config.GameMode = baishunGameModeValue(strings.TrimSpace(string(config.GameMode)))
|
||||||
config.CurrencyIcon = strings.TrimSpace(config.CurrencyIcon)
|
config.CurrencyIcon = strings.TrimSpace(config.CurrencyIcon)
|
||||||
config.Extend = strings.TrimSpace(config.Extend)
|
config.Extend = strings.TrimSpace(config.Extend)
|
||||||
config.LaunchURLTemplate = strings.TrimSpace(config.LaunchURLTemplate)
|
config.LaunchURLTemplate = strings.TrimSpace(config.LaunchURLTemplate)
|
||||||
@ -101,11 +101,36 @@ func (c baishunAdapterConfig) LanguageValue() string {
|
|||||||
|
|
||||||
func (c baishunAdapterConfig) GameModeValue() string {
|
func (c baishunAdapterConfig) GameModeValue() string {
|
||||||
if c.GameMode != "" {
|
if c.GameMode != "" {
|
||||||
return c.GameMode
|
return string(c.GameMode)
|
||||||
}
|
}
|
||||||
return "3"
|
return "3"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type baishunGameModeValue string
|
||||||
|
|
||||||
|
func (v *baishunGameModeValue) UnmarshalJSON(raw []byte) error {
|
||||||
|
// 后台适配器配置是自由 JSON,历史上既可能保存 "2",也可能保存 2。
|
||||||
|
// 百顺启动 query 最终只需要文本值;在配置入口归一,避免数字类型被 Go string 字段吞掉后误走默认 gameMode=3。
|
||||||
|
decoder := json.NewDecoder(strings.NewReader(strings.TrimSpace(string(raw))))
|
||||||
|
decoder.UseNumber()
|
||||||
|
var value any
|
||||||
|
if err := decoder.Decode(&value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch typed := value.(type) {
|
||||||
|
case nil:
|
||||||
|
*v = ""
|
||||||
|
case string:
|
||||||
|
*v = baishunGameModeValue(strings.TrimSpace(typed))
|
||||||
|
case json.Number:
|
||||||
|
*v = baishunGameModeValue(strings.TrimSpace(typed.String()))
|
||||||
|
default:
|
||||||
|
// 复杂类型不是百顺协议值;按未配置处理,保留默认值兜底,同时不影响同一 JSON 中其它配置解析。
|
||||||
|
*v = ""
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func baishunLaunchBaseURL(game gamedomain.LaunchableGame, config baishunAdapterConfig) string {
|
func baishunLaunchBaseURL(game gamedomain.LaunchableGame, config baishunAdapterConfig) string {
|
||||||
for _, key := range []string{game.ProviderGameID, game.GameID, strings.ToLower(game.GameID)} {
|
for _, key := range []string{game.ProviderGameID, game.GameID, strings.ToLower(game.GameID)} {
|
||||||
if raw := strings.TrimSpace(config.GameURLs[strings.TrimSpace(key)]); raw != "" {
|
if raw := strings.TrimSpace(config.GameURLs[strings.TrimSpace(key)]); raw != "" {
|
||||||
|
|||||||
@ -396,6 +396,38 @@ func TestLaunchGameBuildsBaishunURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBaishunConfigGameModeAcceptsNumberAndString(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
raw string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string_value_from_existing_config",
|
||||||
|
raw: `{"game_mode":"2"}`,
|
||||||
|
want: "2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "numeric_value_from_admin_json_editor",
|
||||||
|
raw: `{"game_mode":2}`,
|
||||||
|
want: "2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing_value_keeps_baishun_default",
|
||||||
|
raw: `{}`,
|
||||||
|
want: "3",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
config := baishunConfigFromPlatform(gamedomain.LaunchableGame{AdapterConfigJSON: tc.raw})
|
||||||
|
if got := config.GameModeValue(); got != tc.want {
|
||||||
|
t.Fatalf("baishun gameMode mismatch: got %q want %q raw=%s", got, tc.want, tc.raw)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLaunchGameBuildsVivaGamesURL(t *testing.T) {
|
func TestLaunchGameBuildsVivaGamesURL(t *testing.T) {
|
||||||
repo := &fakeRepository{
|
repo := &fakeRepository{
|
||||||
launchable: gamedomain.LaunchableGame{
|
launchable: gamedomain.LaunchableGame{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user