<reponame>LaudateCorpus1/realtime-server<gh_stars>100-1000
from core.common.EntityFactory import EntityFactory
from common.component.Component import Component
from common import gv


class CompDungeon(Component):
    VAR_NAME = 'CompDungeon'

    def __init__(self):
        super(CompDungeon, self).__init__()

        self.ip = None
        self.port = None
        self.bind_id = None
        self.token = None
        self.invalid_token = None
        self.battle_retry_time = 0

    def connect_to_battle_server_imp(self, reconnect=False):
        # gr.player.CompNewbie.close_newbie_check_confirm()
        # gr.logger.warn('connect_to_battle_server_imp %d %s %s %s %s', self.battle_retry_time, str(self.ip), str(self.port), str(self.bind_id), str(self.token))
        if not gv.bind_entity or gv.bind_entity.id != self.bind_id or gv.bind_entity.expired:
            if gv.bind_entity:
                gv.bind_entity.destroy()
            _entity = EntityFactory.instance().create_entity('PuppetBindEntity', self.bind_id)
        else:
            _entity = gv.bind_entity
        gv.bind_entity = _entity
        # _entity.server, is_old = create_direct_proxy(
        #     _entity,
        #     self.bind_id,
        #     (self.ip, self.port),
        #     self.CON_TYPE,
        #     key_content=cconst.RSA_PUB_KEY,
        #     bind_token=self.token,
        #     cb=self.battle_server_bind_result,
        # )

from core.common.EntityFactory import EntityFactory
from common.component.Component import Component
from common import gv


class CompDungeon(Component):
    VAR_NAME = 'CompDungeon'

    def __init__(self):
        super(CompDungeon, self).__init__()

        self.ip = None
        self.port = None
        self.bind_id = None
        self.token = None
        self.invalid_token = None
        self.battle_retry_time = 0

    def connect_to_battle_server_imp(self, reconnect=False):
        # gr.player.CompNewbie.close_newbie_check_confirm()
        # gr.logger.warn('connect_to_battle_server_imp %d %s %s %s %s', self.battle_retry_time, str(self.ip), str(self.port), str(self.bind_id), str(self.token))
        if not gv.bind_entity or gv.bind_entity.id != self.bind_id or gv.bind_entity.expired:
            if gv.bind_entity:
                gv.bind_entity.destroy()
            _entity = EntityFactory.instance().create_entity('PuppetBindEntity', self.bind_id)
        else:
            _entity = gv.bind_entity
        gv.bind_entity = _entity
        # _entity.server, is_old = create_direct_proxy(
        #     _entity,
        #     self.bind_id,
        #     (self.ip, self.port),
        #     self.CON_TYPE,
        #     key_content=cconst.RSA_PUB_KEY,
        #     bind_token=self.token,
        #     cb=self.battle_server_bind_result,
        # )
# gr.player.CompNewbie.close_newbie_check_confirm() # gr.logger.warn('connect_to_battle_server_imp %d %s %s %s %s', self.battle_retry_time, str(self.ip), str(self.port), str(self.bind_id), str(self.token)) # _entity.server, is_old = create_direct_proxy( #     _entity, #     self.bind_id, #     (self.ip, self.port), #     self.CON_TYPE, #     key_content=cconst.RSA_PUB_KEY, #     bind_token=self.token, #     cb=self.battle_server_bind_result, # )