259 lines
11 KiB
Python
259 lines
11 KiB
Python
# coding:utf-8
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
from typing import Optional, Union
|
||
|
||
from pydantic import BaseSettings, Field
|
||
|
||
|
||
class GlobalConfig(BaseSettings):
|
||
"""Global configurations."""
|
||
|
||
# This variable will be loaded from the .env file. However, if there is a
|
||
# shell environment variable having the same name, that will take precedence.
|
||
|
||
# the class Field is necessary while defining the global variables
|
||
ENV_STATE: Optional[str] = Field(..., env="ENV_STATE")
|
||
|
||
class Config:
|
||
"""Loads the dotenv file."""
|
||
|
||
env_file: str = ".env"
|
||
|
||
# 事件映射 legu->shoumeng
|
||
legu_to_sm_event = {'pay': 'role_pay',
|
||
'create_account': 'role_create',
|
||
'login': 'role_login',
|
||
'animation': 'animation',
|
||
'guide': 'guide_flow',
|
||
'ping': 'role_logout',
|
||
'level_up': 'role_rank',
|
||
'vip_level': 'vip_rank',
|
||
'fight': 'role_power',
|
||
'mission_completed': 'task_flow',
|
||
'enter_stage': 'dungeon_flow',
|
||
'end_stage': 'dungeon_flow',
|
||
'resource_change': 'item_flow',
|
||
'summon': 'recruit',
|
||
'ask_for_join_guild': 'guild_apply',
|
||
'leave_guild': 'guild_quit',
|
||
'create_guild': 'guild_set',
|
||
'get_hero': 'hero_get',
|
||
'hero_up': 'hero_rank',
|
||
'hero_star_up': 'hero_advanced',
|
||
'hero_skill_get': 'hero_skill_get',
|
||
'hero_equip': 'equip_get',
|
||
'equip_level_up': 'hero_equip_rank',
|
||
'rune_forge': 'rune_flow',
|
||
'event_participate': 'activity_flow',
|
||
'event_centered': 'activity_flow',
|
||
'event_finish': 'activity_flow',
|
||
'home_rank': 'home_rank',
|
||
'fishing_flow': 'fishing_flow'}
|
||
# 公共属性映射 legu->shoumeng
|
||
legu_to_sm_attr_base = {
|
||
# 基础属性
|
||
'channel': 'channel_name',
|
||
'svrindex': 'game_server',
|
||
'#os': 'platform_id',
|
||
'binduid': 'sm_user_id',
|
||
'user_id': 'user_id', # 避免重复key,使用的是binduid
|
||
'#account_id': 'role_id',
|
||
'role_name': 'role_name',
|
||
'ghid': 'guild_id',
|
||
'ghname': 'guild',
|
||
'zhanli': 'power',
|
||
'lv': 'role_rank',
|
||
'vip': 'role_vip',
|
||
# '':'castle_rank', # 城堡等级
|
||
'exp': 'exp',
|
||
'data_id': 'data_id'
|
||
|
||
}
|
||
# 事件属性映射
|
||
legu_to_sm_attr = {'pay': {'unitPrice': 'pay_amount',
|
||
'orderid': 'pay_product_id',
|
||
'proid': 'pay_product',
|
||
'pay_product_json': 'pay_product_json'},
|
||
'create_account': {},
|
||
'login': {},
|
||
'ta_app_end': {},
|
||
'animation': {'animation_seconds': 'animation_seconds',
|
||
'animation_result': 'result'},
|
||
'guide': {'step_id': 'guide_id', 'step_name': 'guide_name'},
|
||
'ping': {'online_ts': 'online_time'},
|
||
'level_up': {'role_level': 'rank',
|
||
'before_level': 'rank_before',
|
||
'after_level': 'rank_change'},
|
||
'vip_level': {'before_vip': 'vip_rank_before',
|
||
'after_vip': 'vip_rank_before'},
|
||
'fight': {'fighting_capacity': 'power',
|
||
'fighting_before': 'power_before',
|
||
'after_fighting': 'power_change'},
|
||
'mission_completed': {'mission_type': 'task_type',
|
||
'mission_id': 'task_id',
|
||
'mission_name': 'task_name',
|
||
'reward_list': 'task_reward_content',
|
||
'reward_type': 'task_result'},
|
||
'enter_stage': {'stage_id': 'dungeon_id',
|
||
'stage_name': 'dungeon_name',
|
||
'stage_type': 'dungeon_type'},
|
||
'end_stage': {'reward_list': 'dungeon_result', 'chapter': 'chapter'},
|
||
'shopping': {},
|
||
'idle_reward': {},
|
||
'online_reward': {},
|
||
'sign': {},
|
||
'resource_change': {'resource_id': 'item_id',
|
||
'resource_name': 'item_name',
|
||
'change_type': 'item_type',
|
||
'change_num': 'count_change',
|
||
'change_before': 'count_before',
|
||
'change_after': 'count',
|
||
'change_reason': 'sub_reason'},
|
||
'summon': {'summon_type': 'recruit_type',
|
||
'item_list': 'item_id',
|
||
'item_name': 'reward_content',
|
||
'summon_cost_type': 'cost_name',
|
||
'summon_cost_num': 'cost_count'},
|
||
'ask_for_join_guild': {'guild_level': 'guiild_rank',
|
||
'guild_id': 'guild_id',
|
||
'guild_position': 'guild_position'},
|
||
'leave_guild': {'guild_level': 'guiild_rank',
|
||
'guild_id': 'guild_id',
|
||
'guild_position': 'guild_position'},
|
||
'create_guild': {'guild_level': 'guiild_rank',
|
||
'guild_fighting_capacity': 'guild_position'},
|
||
'guild_donate': {},
|
||
'get_hero': {'hero_name': 'hero_name',
|
||
'hero_job': 'hero_type',
|
||
'get_type': 'reason'},
|
||
'hero_up': {'hero_name': 'hero_name',
|
||
'hero_job': 'hero_type',
|
||
'original_level': 'hero_rank_before',
|
||
'new_level': 'hero_rank_before',
|
||
'item_name': 'item_name',
|
||
'cost_count': 'cost_count'},
|
||
'hero_star_up': {'hero_name': 'hero_name',
|
||
'hero_job': 'hero_type',
|
||
'before_awake': 'hero_rank_before',
|
||
'after_awake': 'hero_rank_before',
|
||
'item_name': 'item_name',
|
||
'cost_count': 'cost_count'},
|
||
'hero_skill_get': {'hero_name': 'hero_name',
|
||
'hero_job': 'hero_job',
|
||
'skill_id': 'skill_id',
|
||
'skill_name': 'skill_name'},
|
||
'hero_equip': {'equip_id': 'equip_id',
|
||
'after_fight': 'equip_name',
|
||
'equip_quality': 'equip_quality'},
|
||
'equip_level_up': {'equip_name': 'equip_name',
|
||
'equip_quality': 'equip_id',
|
||
'strength_level': 'equip_rank_before',
|
||
'equip_rank': 'equip_rank'},
|
||
'rune_forge': {'rune_id': 'rune_id',
|
||
'rune_type': 'rune_type',
|
||
'rune_name': 'rune_name'},
|
||
'event_participate': {'activity_id': 'activity_id',
|
||
'activity_name': 'activity_name',
|
||
'activity_type': 'activity_type'},
|
||
'event_centered': {},
|
||
'event_finish': {'mission_start_time': 'activity_reward_content'},
|
||
'home_rank': {'home_rank_before': 'home_rank_before',
|
||
'home_rank': 'home_rank_before'},
|
||
'fishing_flow': {'fishing_result': 'result',
|
||
'reward_content': 'reward_content',
|
||
'fish_time_rest': 'fish_time_rest'},
|
||
'training_room': {},
|
||
'plant': {},
|
||
'loot': {},
|
||
'harvest': {},
|
||
'banquet': {},
|
||
'home_hero_list': {},
|
||
'mine_layer': {},
|
||
'buy_strength': {},
|
||
'expend_strength': {},
|
||
'decoration_recycle': {},
|
||
'complete_build': {},
|
||
'binfen_participate': {},
|
||
'binfen_finish': {}}
|
||
# 手盟上报模板
|
||
template_data = {
|
||
"cp_game_id": 682,
|
||
"category": "cp_api",
|
||
"event": {
|
||
'event_access': 'realtime',
|
||
"event_time": 0,
|
||
"event_name": ""
|
||
},
|
||
"data": {
|
||
|
||
}
|
||
}
|
||
|
||
|
||
class DevConfig(GlobalConfig):
|
||
"""Development configurations."""
|
||
SM_API = 'https://data.910app.com/cp_test'
|
||
SM_CHECK_API = 'http://datacheck.910app.com:8099/cp/check'
|
||
|
||
KAFKA_CONSUMER_CONF: dict = {
|
||
'bootstrap_servers': ["192.168.0.30:9092", "192.168.0.71:9092", "192.168.0.229:9092"],
|
||
'value_deserializer': json.loads,
|
||
'auto_offset_reset': 'earliest',
|
||
'max_poll_interval_ms': 3600000,
|
||
'session_timeout_ms': 3600000,
|
||
'connections_max_idle_ms': 3650000,
|
||
'request_timeout_ms': 3605000,
|
||
'enable_auto_commit': False,
|
||
|
||
# 每个游戏不一样
|
||
'group_id': 'shoumeng_xiangsu_debug' # '测试'
|
||
}
|
||
SUBSCRIBE_TOPIC: str = 'debug'
|
||
|
||
class Config:
|
||
env_prefix: str = "DEV_"
|
||
|
||
|
||
class ProdConfig(GlobalConfig):
|
||
"""Production configurations."""
|
||
|
||
SM_API = 'https://data.910app.com/cp'
|
||
|
||
KAFKA_CONSUMER_CONF = {
|
||
'bootstrap_servers': ["192.168.0.30:9092", "192.168.0.71:9092", "192.168.0.229:9092"],
|
||
'value_deserializer': json.loads,
|
||
'auto_offset_reset': 'earliest',
|
||
'max_poll_interval_ms': 3600000,
|
||
'session_timeout_ms': 3600000,
|
||
'connections_max_idle_ms': 3650000,
|
||
'request_timeout_ms': 3605000,
|
||
'enable_auto_commit': False,
|
||
|
||
# 每个游戏不一样
|
||
'group_id': 'shou_meng_xiangsu2' # '正式的'
|
||
}
|
||
SUBSCRIBE_TOPIC = 'xiangsu'
|
||
|
||
class Config:
|
||
env_prefix: str = "PROD_"
|
||
|
||
|
||
class FactoryConfig:
|
||
"""Returns a config instance dependending on the ENV_STATE variable."""
|
||
|
||
def __init__(self, env_state: Optional[str]) -> None:
|
||
self.env_state = env_state
|
||
|
||
def __call__(self) -> Union[DevConfig, ProdConfig]:
|
||
if self.env_state == "dev":
|
||
return DevConfig()
|
||
|
||
elif self.env_state == "prod":
|
||
return ProdConfig()
|
||
|
||
|
||
settings = FactoryConfig(GlobalConfig().ENV_STATE)()
|
||
print(11)
|