# 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': 'resource_flow', 'get_item': 'item_flow', 'cost_item': '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_sudden':'hero_sudden', 'hero_skill_get': 'hero_skill_get', 'hero_equip': 'equip_get', 'equip_level_up': 'hero_equip_rank', 'rune_forge': 'rune_flow', 'rune_strengthen':'rune_flow', 'refine_rune':'rune_flow', 'event_participate': 'activity_flow', 'event_centered': 'activity_flow', 'event_finish': 'activity_flow', 'home_rank': 'home_rank', 'fishing_flow': 'fishing_flow', 'binfen_participate': 'activity_flow', 'binfen_finish': 'activity_flow', 'xitian_road_participate': 'activity_flow', 'xitian_road_finish': 'activity_flow', 'leiyin_participate': 'activity_flow', 'leiyin_finish': 'activity_flow', 'tyemple_soul': 'tyemple_soul', 'hell_gate': 'hell_gate', 'dzsf_participate': 'activity_flow', 'dzsf_finish': 'activity_flow', 'dzsftiaozhan_participate': 'dzsftiaozhan_participate', 'dzsftiaozhan_finish': 'dzsftiaozhan_finish', 'baoxiang':'activity_flow', 'yuanxiao':'activity_flow', 'yxxq_cunjie':'activity_flow', 'drhz':'activity_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', 'pay_ip': 'pay_ip'}, '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'}, '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': {}, 'end_stage': {'stage_id': 'dungeon_id', 'stage_name': 'dungeon_name', 'stage_type': 'dungeon_type', 'reward_list': 'dungeon_result'}, 'shopping': {}, 'idle_reward': {}, 'online_reward': {}, 'sign': {}, 'resource_change': {'resource_id': 'resource_id', 'resource_name': 'resource_name', 'change_type': 'add_or_reduce', 'change_num': 'count_change', 'change_before': 'count_before', 'change_after': 'count', 'change_reason': 'sub_reason'}, 'get_item': {'item_id': 'item_id', 'item_name': 'item_name', 'change_type': 'add_or_reduce', 'change_num': 'count_change', 'change_before': 'count_before', 'change_after': 'count', 'change_reason': 'sub_reason'}, 'cost_item': {'item_id': 'item_id', 'item_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_name': 'guild_name', 'guild_position': 'guild_position'}, 'leave_guild': {'guild_level': 'guiild_rank', 'guild_id': 'guild_id', 'guild_name': 'guild_name', 'guild_position': 'guild_position'}, 'create_guild': {'guild_level': 'guiild_rank', 'guild_id': 'guild_id', 'guild_name': 'guild_name', '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_status_before', 'new_level': 'hero_rank', 'item_name': 'item_name', 'cost_count': 'cost_count'}, 'hero_star_up': {'hero_name': 'hero_name', 'hero_id': 'hero_id', 'before_awake': 'hero_status_before', 'after_awake': 'hero_status', 'item_name': 'item_name', 'cost_count': 'cost_count'}, 'hero_sudden': {'hero_name': 'hero_name', 'hero_id': 'hero_id', 'hero_status': 'hero_status', 'hero_status_before': 'hero_status_before', 'item_name': 'item_name', 'cost_count': 'cost_count'}, 'hero_skill_get': {'hero_name': 'hero_name', 'hero_job': 'hero_job', 'skill_rank_before': 'skill_rank_before', 'skill_rank': 'skill_rank', 'skill_name': 'skill_name'}, 'hero_equip': {'equip_id': 'equip_id', 'after_fight': 'equip_name', 'equip_quality': 'equip_quality', 'reason': 'sub_reason'}, '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', 'reason': 'reason', 'sub_reason': 'sub_reason'}, 'rune_strengthen': {'rune_id': 'rune_id', 'rune_type': 'rune_type', 'rune_name': 'rune_name', 'item_name': 'item_name', 'cost_count': 'cost_count', 'rune_rank': 'rune_rank'}, 'event_participate': {'activity_id': 'activity_id', 'activity_name': 'activity_name', 'activity_type': 'activity_type'}, 'event_centered': {'activity_id': 'activity_id', 'activity_name': 'activity_name', 'activity_type': 'activity_type'}, 'event_finish': {'activity_id': 'activity_id', 'activity_name': 'activity_name', 'activity_type': 'activity_type', 'reward_list': 'activity_reward_content' }, 'home_rank': {'home_rank_before': 'home_rank_before', 'new_home_rank': 'home_rank'}, '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': {'activity_id':'activity_id', 'activity_name':'activity_name', 'turntable_type': 'turntable_type', 'cost_count': 'cost_count', 'reward_list': 'activity_reward_content'}, 'binfen_finish': {'activity_id':'activity_id', 'activity_name':'activity_name', 'turntable_type': 'turntable_type', 'cost_count': 'cost_count', 'reward_list': 'activity_reward_content'}, 'xitian_road_participate': {'gaolaozhuang': 'gaolaozhuang'}, 'xitian_road_finish': {'huaguoshan': 'huaguoshan'}, 'leiyin_participate': {'activity_id':'activity_id', 'activity_name':'activity_name', 'turntable_type': 'turntable_type', 'cost_count': 'cost_count', 'reward_list': 'activity_reward_content'}, 'leiyin_finish': {'activity_id':'activity_id', 'activity_name':'activity_name', 'turntable_type': 'turntable_type', 'cost_count': 'cost_count', 'reward_list': 'activity_reward_content'}, 'tyemple_soul': {'zhanchang_name': 'zhanchang_name', 'zhanchang_type': 'zhanchang_type', 'reward_list': 'reward_list'}, 'hell_gate': {'stage_id': 'stage_id', 'stage_name': 'stage_name', 'reward_list': 'reward_list'}, 'dzsf_participate': {'activity_id':'activity_id', 'activity_name':'activity_name', 'turntable_type': 'turntable_type', 'cost_count': 'cost_count', 'reward_list': 'activity_reward_content'}, 'dzsf_finish': {'activity_id':'activity_id', 'activity_name':'activity_name', 'turntable_type': 'turntable_type', 'cost_count': 'cost_count', 'reward_list': 'activity_reward_content'}, 'dzsftiaozhan_participate': {'butianzhidi': 'butianzhidi'}, 'dzsftiaozhan_finish': {'jzzk': 'jzzk'}, 'baoxiang':{'activity_id':'activity_id', 'activity_name':'activity_name', 'reward_list':'activity_reward_content'}, 'yuanxiao':{'yuanxiao_finish':'activity_reward_content'}, 'yxxq_cunjie':{'activity_id':'activity_id', 'activity_name':'activity_name', 'reward_list':'activity_reward_content'}, 'drhz':{'activity_id':'activity_id', 'activity_name':'activity_name', 'reward_list':'activity_reward_content'} } # 手盟上报模板 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': 600000, 'session_timeout_ms': 600000, 'connections_max_idle_ms': 655000, 'request_timeout_ms': 605000, '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': 600000, 'session_timeout_ms': 600000, 'connections_max_idle_ms': 655000, 'request_timeout_ms': 605000, '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)