Example #1
0
def short_message_to_self(dynamic_id, message):
    response = room_pb2.m_3101_toc()
    response.message = message
    func.log_info('[game] 3101 short_message_to_self dynamic_id: {}, message: {}'.format(
        dynamic_id, message
    ))
    forward.push_object_game(3101, response.SerializeToString(), [dynamic_id])
Example #2
0
def get_wechat_prepay_info(dynamic_id, money):
    func.log_info('[gate] get_wechat_prepay_info money: {}'.format(money))
    if not money or not isinstance(money, int):
        send.system_notice(dynamic_id, content.RECHARGE_MONEY_IS_NEED)
        return
    user = UserManager().get_user_by_dynamic(dynamic_id)
    if not user:
        send.system_notice(dynamic_id, content.ENTER_DYNAMIC_LOGIN_EXPIRE)
        return
    if not user.proxy_id:
        send.system_notice(dynamic_id, content.RECHARGE_PROXY_ID_NEED)
        return
    proxy_id = user.proxy_id
    pay = recharge_wechat.WechatPay()
    money = int(money * 100)
    pay.init(
            nonce_str=func.random_string_r(16, 30),
            attach='{}/{}'.format(proxy_id, user.account_id),
            order_id=recharge_wechat.generator_unique_order_id(money),
            total_fee=money,
            spbill_create_ip=user.ip
    )
    prepay_info = pay.re_finall()
    func.log_info('[gate] get_wechat_prepay_info account_id: {}, order_id: {}, prepay_info: {}'.format(
        user.account_id, pay.order_id, prepay_info
    ))
    send.recharge_wechat_prepay_info(dynamic_id, money, proxy_id, prepay_info)
Example #3
0
def dispatch_mahjong_to_room(room, **kwargs):
    func.log_info('[game] dispatch_mahjong_to_room')
    room.random_cards()
    # execute_account_id = room.get_original_execute()
    room.room_player_status(status.PLAYER_STATUS_NORMAL)
    if 'crap_list' in kwargs:
        craps_1, craps_2 = kwargs['crap_list']
    else:
        craps_1 = func.random_get(1, 6)
        craps_2 = func.random_get(1, 6)
    room.craps = [craps_1, craps_2]
    original_count = room.original_count * room.player_count
    room.mahjong_start = original_count
    room.mahjong_end = 1
    room.execute_account_id = room.maker_account_id
    mahjong_craps = {
        'maker_account_id': room.execute_account_id,
        'craps': [craps_1, craps_2],
        'mahjong_start_num': room.mahjong_start,
        'mahjong_end_num': room.mahjong_end
    }
    ready_list = room.room_ready_list
    for account_id in ready_list:
        player = room.get_player(account_id)
        send.send_mahjong_craps(player.dynamic_id, **mahjong_craps)
        send.player_dispatch_cards(room.execute_account_id, player)
        if player.account_id == room.execute_account_id:
            mahjong.dispatch_mahjong_card(player.dynamic_id, True)
Example #4
0
def account_register(dynamic_id, address, user_name, password):
    if not user_name or not password:
        send.system_notice(dynamic_id, content.ACCOUNT_NULL)
        return
    if not func.check_english(user_name):
        send.system_notice(dynamic_id, content.ACCOUNT_ENGLISH)
        return
    sql = 'select * from {} where user_name="{}"'.format(
        dbname.DB_ACCOUNT, user_name)
    if dbexecute.query_one(sql):
        send.system_notice(dynamic_id, content.ACCOUNT_EXIST)
        return
    uuid = user_name
    sex = func.random_get(1, 2)
    name = user_name
    head_frame = ''
    head_icon = ''
    account_id = _register_process(user_name, password, name, uuid, '',
                                   channel.CHANNEL_ZERO, sex, head_frame,
                                   head_icon)
    if account_id:
        func.log_info(
            '[Auth] user_name: {}, account_id: {}, address: {} register success'
            .format(user_name, account_id, address))
        send.account_register(dynamic_id, user_name, password, account_id)
    else:
        func.log_error(
            '[Auth] user_name: {} register failed'.format(user_name))
Example #5
0
def broad_player_enter_mahjong(dynamic_id_list, user_info, operator_account_id, operators_list):
    response = room_pb2.m_3007_toc()
    response.user_room.position = user_info['position']
    response.user_room.account_id = user_info['account_id']
    response.user_room.name = user_info['name']
    response.user_room.head_frame = user_info['head_frame']
    response.user_room.head_icon = user_info['head_icon']
    response.user_room.sex = user_info['sex']
    response.user_room.ip = user_info['ip']
    response.user_room.point = user_info['point']
    response.user_room.status = user_info['status']
    for card_id in user_info.get('pre_cards', []):
        response.user_room.pre_cards.append(card_id)
    for card_list in user_info.get('award_cards', []):
        award_cards = response.user_room.award_cards.add()
        for card_id in card_list:
            award_cards.cards.append(card_id)
    response.user_room.card_count = user_info['card_count']
    response.user_room.operator_able = user_info['account_id'] == operator_account_id
    if operators_list:
        for operator_id in operators_list:
            response.user_room.operators.append(operator_id)
    func.log_info('[game] 3007 broad_player_enter_mahjong dynamic_id_list: {}, response: {}'.format(
        dynamic_id_list, response))
    forward.push_object_game(3007, response.SerializeToString(), dynamic_id_list)
Example #6
0
def broad_room_all_in(dynamic_id_list, room_type):
    response = room_pb2.m_3008_toc()
    response.room_type = room_type
    func.log_info('[game] 3008 broad_room_all_in dynamic_id_list: {}, response: {}'.format(
        dynamic_id_list, response
    ))
    forward.push_object_game(3008, response.SerializeToString(), dynamic_id_list)
Example #7
0
def online_match_success(dynamic_id_list, room_id):
    response = room_pb2.m_3203_toc()
    response.room_id = room_id
    func.log_info('[gate] 3203 online_match_success dynamic_id_list: {}, room_id: {}'.format(
        dynamic_id_list, room_id
    ))
    forward.push_object_gate(3203, response.SerializeToString(), dynamic_id_list)
Example #8
0
def bind_proxy(dynamic_id, proxy_id):
    if not proxy_id:
        send.system_notice(dynamic_id, content.PROXY_ID_LACK)
        return
    sql = 'select account_id from {} where account_id = {}'.format(dbname.DB_ACCOUNT, proxy_id)
    if not dbexecute.query_one(sql):
        send.system_notice(dynamic_id, content.PROXY_ID_ERROR)
        return
    user = UserManager().get_user_by_dynamic(dynamic_id)
    if not user:
        send.system_notice(dynamic_id, content.ENTER_DYNAMIC_LOGIN_EXPIRE)
        return
    if user.proxy_id > 0:
        send.system_notice(dynamic_id, content.PROXY_ID_EXIST)
        return
    if user.account_id == proxy_id:
        send.system_notice(dynamic_id, content.PROXY_ID_ERROR)      # PROXY_ID_SELF
        return
    user.proxy_id = proxy_id
    try:
        proxy_stastics(proxy_id)
    except Exception as e:
        func.log_error('[gate] bind_proxy proxy_id: {}, failed: {}'.format(proxy_id, e.message))
    change.award_gold(user, constant.GOLD_BIND_PROXY, origins.ORIGIN_PROXY_ACTIVE)
    # save
    user.user_save()
    send.bind_success(dynamic_id, proxy_id)
    send.system_notice(dynamic_id, content.PROXY_ID_SUCCESS)
    func.log_info('[gate] bind_proxy account_id: {} bind proxy_id: {}'.format(user.account_id, proxy_id))
Example #9
0
def send_play_history(user):
    response = room_pb2.m_3201_toc()
    response.poker_point = user.poker_point
    response.mahjong_point = user.mahjong_point
    response.gold_point = user.gold_point
    history_list = user.get_play_history_list()
    # None
    if history_list:
        for info in history_list:
            history_info = response.history_info.add()
            history_info.room_id = info['room_id']
            history_info.room_type = info['room_type']
            history_info.win_account_id = info['win_account_id']
            history_info.server_t = info['server_t']
            history_info.round = info['round']
            history_info.max_round = info['max_round']
            player_info_list = info['history_player']
            for player_info in player_info_list:
                history_player = history_info.history_player.add()
                history_player.account_id = player_info['account_id']
                history_player.name = player_info['name']
                history_player.point_changes = player_info['point_changes']
                history_player.room_point = player_info['room_point']
                history_player.all_point = player_info['all_point']
    func.log_info('[gate] 3201 send_play_history dynamic_id: {}, response: {}'.format(user.dynamic_id, response))
    forward.push_object_gate(3201, response.SerializeToString(), [user.dynamic_id])
Example #10
0
 def unpack(self, bytes):
     try:
         length, _, command = struct.unpack('!Ibh', bytes)[:3]
     except DataPackError as e:
         func.log_info('[unpack] failed: {}'.format(e.message))
         return {'result': False, 'command': 0, 'length': 0}
     return {'result': True, 'command': command, 'length': length}
Example #11
0
 def _parse_infomation(self, result):
     try:
         self._infomations[result['id']] = result['content']
     except Exception as e:
         func.log_info('[config] _load_from_infomation failed, error: {}, result: {}'.format(
                 e.message, result
         ))
Example #12
0
def voice_message_to_self(dynamic_id, voice_url):
    response = room_pb2.m_3103_toc()
    response.voice_url = voice_url
    func.log_info('[game] 3103 voice_message_to_self dynamic_id: {}, voice_url: {}'.format(
        dynamic_id, voice_url
    ))
    forward.push_object_game(3103, response.SerializeToString(), [dynamic_id])
Example #13
0
def user_ready(dynamic_id, operator):
    account_id = PlayerManager().query_account_id(dynamic_id)
    if not account_id:
        send.system_notice(dynamic_id, content.ENTER_DYNAMIC_LOGIN_EXPIRE)
        return False
    room_manager = RoomManager()
    room_id = room_manager.query_player_room_id(account_id)
    if not room_id:
        send.system_notice(dynamic_id, content.ROOM_UN_ENTER)
        return False
    room = room_manager.get_room(room_id)
    if not room:
        send.system_notice(dynamic_id, content.ROOM_UN_FIND)
        return False
    room.player_ready(account_id)
    func.log_info('[game] user ready room_id: {}, account_id: {}, flag: {}'.format(
        room_id, account_id, room.is_all_ready()
    ))

    if operator == operators.USER_OPERATOR_SWITCH:
        room.switch_account_id = account_id
    notice_all_room_user_operator(room, account_id, operators.USER_OPERATOR_READY)
    if room.is_all_ready():
        func.log_info('[game] all ready room_id: {}'.format(room.room_id))
        # if not room.is_online_match():
        #     if not check_owner_in(room):
        #         notice_owner_must_in(room)
        #         return False
        reduce_bail_gold(room)
        if check_switch(room):
            switch_cards(room)
        spend_room_per_price(room)
        dispatch_cards_to_room(room)
    return True
Example #14
0
def user_change_9003(request):
    argument = system_pb2.m_9003_toc()
    argument.ParseFromString(request)
    change_list = [c for c in argument.role_change]
    role_change_list = [{'change_type': info.change_type, 'change_value': info.change_value} for info in change_list]
    func.log_info('[user_change_9003] role_change_list: {}'.format(role_change_list))
    return None
Example #15
0
def backup_db():
    today = datetime.date.today()
    backup_path = os.getcwd() + '/backup/'
    if not os.path.exists(backup_path):
        os.makedirs(backup_path)
    backup_file_name_tar = '{}{}_{}.tar.gz'.format(backup_path, constant.DB_NAME, today)
    if os.path.isfile(backup_file_name_tar):
        func.log_info('[gate] backup_db file: {} is exist'.format(backup_file_name_tar))
        return
    backup_file_name = '{}{}_{}.sql'.format(backup_path, constant.DB_NAME, today)
    try:
        cmd = 'mysqldump -h{} -u{} -p{} {} --default_character-set={} > {}'.format(
                constant.DB_HOST, constant.DB_USER, constant.DB_PASSWD, constant.DB_NAME, 'utf8', backup_file_name)
        os.system(cmd)
        # tar
        tar = tarfile.open(backup_file_name_tar, 'w:gz')
        for root, _, files in os.walk(backup_path):
            for f in files:
                if 'sql' not in f:
                    continue
                full_path = os.path.join(root, f)
                tar.add(full_path, arcname=f)
        tar.close()
    except Exception as e:
        func.log_error('[gate] backup_db failed: {}'.format(e.message))
    finally:
        os.system('rm -rf {}'.format(backup_file_name))
Example #16
0
def user_login_2001(request):
    argument = login_pb2.m_2001_toc()
    argument.ParseFromString(request)
    client = Client()
    # user info
    client.account_id = argument.user_info.account_id
    client.uuid = argument.user_info.uuid
    client.user_name = argument.user_info.name
    client.gold = argument.user_info.gold
    client.point = argument.user_info.point
    client.add_last_room(argument.user_info.room_id, argument.user_info.room_type)
    # room info
    room_data = dict()
    for room_info in argument.room_info:
        prices = dict()
        for room_price in room_info.room_price:
            prices[room_price.rounds] = room_price.gold_price
        room_data[room_info.room_type] = {
            'room_id': room_info.room_id,
            'price': prices
        }
    client.room_data = room_data
    func.log_info('[user_enter_2002]')
    client.display_user()
    # ================ test create room
    # create_room(client, rule.GAME_TYPE_PDK, 10)
    # ================ test enter room
    # enter_room(client, 902360)
    # ================ test query play history
    # query_play_history(client)
    # ================ bind proxy
    # bind_proxy(client, 380001)
    return None
Example #17
0
 def render(self, request):
     old_account_id = int(request.args.get('id')[0])
     cur_account_id = int(request.args.get('id')[1])
     func.log_info('[gate] ModifyAccountId old_account_id: {}, cur_account_id: {}'.format(
         old_account_id, cur_account_id
     ))
     return infomation.modify_account_id(old_account_id, cur_account_id)
Example #18
0
def notice_user_channel_login_verify(account_id, verify_key, address, **kwargs):
    func.log_info('[user channel verify] account_id: {} \t verify_key: {}, address: {}'.format(
            account_id, verify_key, address))
    UserManager().record_verify_key(account_id, verify_key, address)
    user = UserManager().get_user(account_id)
    if user:
        user.sync_information(**kwargs)
    else:
        try:
            change_info = dict()
            if kwargs.get('name'):
                change_info['name'] = kwargs.get('name')
            if kwargs.get('sex'):
                change_info['sex'] = kwargs.get('sex')
            if kwargs.get('head_frame'):
                change_info['head_frame'] = kwargs.get('head_frame')
            if kwargs.get('head_icon'):
                change_info['head_icon'] = kwargs.get('head_icon')
            if change_info:
                dbexecute.update_record(
                    table=dbname.DB_ACCOUNT,
                    where={'account_id': account_id},
                    data=change_info
                )
        except Exception as e:
            func.log_error('[gate] notice_user_channel_login_verify account_id: {}, failed: {}'.format(
                    account_id, e.message))
    return None
Example #19
0
 def _parse_infomation(self, result):
     try:
         self._infomations[result['id']] = result['content']
     except Exception as e:
         func.log_info(
             '[config] _load_from_infomation failed, error: {}, result: {}'.
             format(e.message, result))
Example #20
0
def register_account_1001(request):
    argument = login_pb2.m_1001_toc()
    argument.ParseFromString(request)
    client = Client()
    client.account_id = argument.account_id
    func.log_info('[register_account_1001] account_id: {}'.format(client.account_id))
    return None
Example #21
0
def dispatch_user_operator(account_id, operator, dynamic_id_list):
    response = play_pb2.m_4002_toc()
    response.account_id = account_id
    response.operate = operator
    func.log_info('[game] 4002 dispatch_user_operator dynamic_id_list: {}, response: {}'.format(
        dynamic_id_list, response))
    forward.push_object_game(4002, response.SerializeToString(), dynamic_id_list)
Example #22
0
def broad_mahjong_dispatch_card(dynamic_id_list, account_id):
    response = game_mahjong_pb2.m_5208_toc()
    response.account_id = account_id
    func.log_info('[game] 5208 broad_mahjong_dispatch_card dynamic_id_list: {}, account_id: {}'.format(
        dynamic_id_list, account_id
    ))
    forward.push_object_game(5208, response.SerializeToString(), dynamic_id_list)
Example #23
0
def enter_poker_room(dynamic_id, room_id, room_type, room_help, room_data):
    response = room_pb2.m_3002_toc()
    response.room_id = room_id
    response.room_type = room_type
    response.room_help = room_help
    if room_data:
        for user_info in room_data['user_room']:
            user_room = response.user_room.add()
            user_room.position = user_info['position']
            user_room.account_id = user_info['account_id']
            user_room.name = user_info['name']
            user_room.head_frame = user_info['head_frame']
            user_room.head_icon = user_info['head_icon']
            user_room.sex = user_info['sex']
            user_room.ip = user_info['ip']
            user_room.point = user_info['point']
            user_room.status = user_info['status']

        for card_id in room_data['user_cards']:
            response.user_cards.append(card_id)
        response.execute_account_id = room_data['execute_account_id']
        response.last_account_id = room_data['last_account_id']
        for card_id in room_data['last_cards']:
            response.last_cards.append(card_id)
        response.user_id = room_data['user_id']
        response.rounds = room_data['rounds']
        response.max_rounds = room_data['max_rounds']

    func.log_info('[gate] 3002 response: {}'.format(response))
    forward.push_object_gate(3002, response.SerializeToString(), [dynamic_id])
Example #24
0
def mahjong_switch_over(dynamic_id, craps):
    crap_list = [crap_id for crap_id in craps]
    func.log_info('[game] mahjong_switch_over dynamic_id: {}, crap_list: {}'.format(dynamic_id, crap_list))
    if not crap_list or len(crap_list) != 2:
        send.system_notice(dynamic_id, content.PLAY_MAHJONG_UNVALID_CRAPS)
        return
    if user_switch_over(dynamic_id, crap_list=crap_list):
        send.mahjong_switch_over(dynamic_id)
Example #25
0
def check_switch(room):
    if room.room_type in rule.GAME_LIST_MAHJONG:
        room.switch_account_id = room.maker_account_id
        func.log_info('[game] check_switch MAHJONG switch_account_id: {}, maker_account_id: {}'.format(
            room.switch_account_id, room.maker_account_id
        ))
        return True
    return room.switch_account_id > 0
Example #26
0
def mahjong_publish_5201(request):
    argument = game_mahjong_pb2.m_5201_toc()
    argument.ParseFromString(request)
    client = Client()
    craps_list = [craps_id for craps_id in argument.craps]
    func.log_info('[mahjong_publish_5201] maker_account_id: {}, craps: {}, mahjong_start_num: {}, mahjong_end_num: {}'.format(
        argument.maker_account_id, craps_list, argument.mahjong_start_num, argument.mahjong_end_num
    ))
Example #27
0
def user_publish_card_4003(request):
    argument = play_pb2.m_4003_toc()
    argument.ParseFromString(request)
    client = Client()
    card_list = [card_id for card_id in argument.cards]
    func.log_info('[user_publish_card_4003] execute_account_id: {}, card_list: {}'.format(
        argument.execute_account_id, card_list
    ))
Example #28
0
def send_few_card_count(dynamic_id_list, account_id, card_count):
    response = game_poker_pb2.m_5104_toc()
    response.account_id = account_id
    response.card_count = card_count
    func.log_info('[game] 5104 send_few_card_count dynamic_id_list: {}, response: {}'.format(
        dynamic_id_list, response
    ))
    forward.push_object_game(5104, response.SerializeToString(), dynamic_id_list)
Example #29
0
def player_dispatch_cards(execute_account_id, player):
    response = play_pb2.m_4003_toc()
    response.execute_account_id = execute_account_id
    for card_id in player.card_list:
        response.cards.append(card_id)
    func.log_info('[game] 4003, dynamic_id: {}, response: {}'.format(
        player.dynamic_id, response))
    forward.push_object_game(4003, response.SerializeToString(), [player.dynamic_id])
Example #30
0
def enter_room_3002(request):
    argument = room_pb2.m_3002_toc()
    argument.ParseFromString(request)
    client = Client()
    func.log_info('[enter_room_3002] room_id: {}, user_id: {}, rounds: {}, max_rounds: {}'.format(
            argument.room_id, argument.user_id, argument.rounds, argument.max_rounds))
    # 准备
    user_ready(client)
Example #31
0
 def do(self):
     interval = func.next_interval(5, 0, 0)
     self.start(interval)
     func.log_info('[gate] ClearTimer check do, next: {}'.format(interval))
     #system.clear_logs()
     #system.clear_db_backup()
     #system.backup_db()
     RoomProxyManager().clear_unvalid_room()
Example #32
0
def voice_message_to_all(dynamic_id_list, account_id, voice_url):
    response = room_pb2.m_3104_toc()
    response.account_id = account_id
    response.voice_url = voice_url
    func.log_info('[game] 3104 voice_message_to_all dynamic_id_list: {}, voice_url: {}'.format(
        dynamic_id_list, voice_url
    ))
    forward.push_object_game(3104, response.SerializeToString(), dynamic_id_list)
Example #33
0
def poker_publish_all_5102(request):
    argument = game_poker_pb2.m_5102_toc()
    argument.ParseFromString(request)
    client = Client()
    card_list = [card_id for card_id in argument.cards]
    func.log_info('[poker_publish_all_5102] execute_account_id: {}, next_account_id: {}, cards: {}'.format(
        argument.execute_account_id, argument.next_account_id, card_list
    ))
Example #34
0
def spend_point(user, count, origin):
    if count < 0:
        return
    user.spend_point(count)
    send.user_change(user.dynamic_id, {changes.CHANGE_USER_POINT: user.point})
    func.log_info('[gate] spend_point account_id: {}, count: {}, now: {}, origin: {}'.format(
            user.account_id, count, user.gold, origin
    ))
Example #35
0
def mahjong_publish_5204(request):
    argument = game_mahjong_pb2.m_5204_toc()
    argument.ParseFromString(request)
    operator_list = [operator for operator in argument.operator]
    card_list = [card_id for card_id in argument.card_list]
    func.log_info('[mahjong_publish_5204] execute_account_id: {}, card: {}, card_list: {}, operator_able: {}, operator_list: {}'.format(
        argument.execute_account_id, argument.card, card_list, argument.operator_able, operator_list
    ))
Example #36
0
    def do(self):
        self.start(30 * 60)

        func.log_info('[gate] MarqueeTimer do')
        content = i(informations.INFOMATION_TYPE_MARQUEE)
        if not content:
            return
        send.marquee_to_all(content)
Example #37
0
    def do(self):
        self.start(30 * 60)

        func.log_info('[gate] MarqueeTimer do')
        content = i(informations.INFOMATION_TYPE_MARQUEE)
        if not content:
            return
        send.marquee_to_all(content)
Example #38
0
def create_room(dynamic_id, room_id, room_type, room_help, rounds):
    response = room_pb2.m_3001_toc()
    response.room_id = room_id
    response.room_type = room_type
    response.room_help = room_help
    response.rounds = rounds
    func.log_info('[gate] 3001 create_room response: {}'.format(response))
    forward.push_object_gate(3001, response.SerializeToString(), [dynamic_id])
Example #39
0
 def do(self):
     interval = func.next_interval(5, 0, 0)
     self.start(interval)
     func.log_info('[gate] ClearTimer check do, next: {}'.format(interval))
     system.clear_logs()
     system.clear_db_backup()
     system.backup_db()
     RoomProxyManager().clear_unvalid_room()
Example #40
0
def short_message_to_all(dynamic_id_list, account_id, message):
    response = room_pb2.m_3102_toc()
    response.account_id = account_id
    response.message = message
    func.log_info('[game] 3102 short_message_to_all dynamic_id_list: {}, message: {}'.format(
        dynamic_id_list, message
    ))
    forward.push_object_game(3102, response.SerializeToString(), dynamic_id_list)
Example #41
0
 def do(self):
     #interval = 5 * 60
     interval = 5 * 60
     self.start(interval)
     func.log_info(
         '[gate] StaticsTimer check do, next: {}'.format(interval))
     user_count = UserManager().get_user_count()
     func.log_info('[gate] StaticsTimer user count: {}'.format(user_count))
Example #42
0
def cancel_online_match(dynamic_id):
    user = UserManager().get_user_by_dynamic(dynamic_id)
    if not user:
        send.system_notice(dynamic_id, content.ENTER_DYNAMIC_LOGIN_EXPIRE)
        return
    func.log_info('[gate] cancel_online_match account_id: {}'.format(user.account_id))
    OnlineMatchManager().remove_user(user.account_id)
    send.cancel_online_match(dynamic_id)
Example #43
0
 def init_db_pool(self, max_active=5, max_wait=5, init_size=1, db_type='mysql', **config):
     func.log_info('[DBPool] init_db_pool {}'.format(config))
     self._free_connections = Queue.Queue(max_active)
     self._max_wait = max_wait
     self._db_type = db_type
     self._config = config
     for _ in xrange(init_size):
         self.free_conn(self.create_conn())
     self._cur_conn = None
Example #44
0
def account_verify_channel(client, user_name):
    func.log_info('[account_verify] user_name: {}'.format(user_name))
    response = login_pb2.m_1003_tos()
    response.user_name = user_name
    response.channel_id = channel.CHANNEL_WE_CHAT
    response.uuid = user_name
    response.name = user_name
    response.head_frame = '123'
    response.head_icon = '22222'
    response.sex = 1
    client.push_object(1003, response.SerializeToString())
Example #45
0
def create_room_3001(request):
    argument = room_pb2.m_3001_toc()
    argument.ParseFromString(request)
    client = Client()

    func.log_info('[create_room_3001] room_id: {}, room_type: {}, rounds: {}'.format(
        argument.room_id, argument.room_type, argument.rounds
    ))
    # enter room
    enter_room(client, argument.room_id)
    return None
Example #46
0
 def verify(self):
     self._xml_json.pop('sign')
     self.get_sign(self._xml_json)
     func.log_info('[gate] pre_sign: {}'.format(self._sign))
     func.log_info('[gate] cur_sign: {}'.format(self._xml_json['sign']))
     if self._sign != self._xml_json['sign']:
         func.log_error(
             '[gate] WechatResponse xml_sign: {} != sgin: {}'.format(
                 self._xml_json['sign'], self._sign))
         return False
     return True
Example #47
0
 def do(self):
     interval = 30 * 60
     self.start(interval)
     func.log_info('[gate] SaveTimer check do, next: {}'.format(interval))
     all_users = UserManager().get_all_users()
     for account_id, user in all_users.iteritems():
         try:
             user.user_save()
         except Exception as e:
             func.log_error(
                 '[gate] SaveTimer account_id: {}, failed: {}'.format(
                     account_id, e.message))
Example #48
0
def account_verify_1003(request):
    argument = login_pb2.m_1002_toc()
    argument.ParseFromString(request)
    client = Client()
    client.server_t = argument.time
    client.account_id = argument.account_id
    client.verify_key = argument.verify_key
    func.log_info('[account_verify_1003] account_id: {}, verify_key: {}, server_t: {}'.format(
            client.account_id, client.verify_key, client.server_t
    ))
    user_login(client)
    return None
Example #49
0
def enter_room_3003(request):
    argument = room_pb2.m_3003_toc()
    argument.ParseFromString(request)
    client = Client()
    func.log_info('[enter_room_3003] room_id: {}, user_id: {}, rounds: {}, max_rounds: {}'.format(
            argument.room_id, argument.user_id, argument.rounds, argument.max_rounds))
    func.log_info('mahjong ---- maker_account_id: {}, craps: {}, mahjong_start_num: {}, mahjong_end_num: {}'.format(
        argument.maker_account_id, [craps_id for craps_id in argument.craps],
        argument.mahjong_start_num, argument.mahjong_end_num
    ))
    # 准备
    user_ready(client)
Example #50
0
def do_when_stop():
    func.log_info(
        '[game] ---------------------------> node do_when_stop begin')
    for room_id, room in RoomManager().rooms.items():
        try:
            if not room:
                continue
            room.room_save()
        except Exception as e:
            func.log_error(
                '[game] room save room_id: {}, error: {} room_data: {}'.format(
                    room_id, e.message, room.get_save_data()))
    func.log_info('[game] node do_when_stop end <-----------------------')
Example #51
0
def do_when_stop():
    func.log_info(
        '[gate] ---------------------------> node do_when_stop begin')
    for account_id, user in UserManager().get_all_users().items():
        try:
            if not user:
                continue
            user.user_save()
        except Exception as e:
            func.log_error(
                '[gate] user save account_id: {}, error: {}, user_data: {}'.
                format(account_id, e.message, user.get_save_data()))
    func.log_info('[gate] node do_when_stop end <-----------------------')
Example #52
0
 def do_connect_made(self, conn):
     func.log_info('[ClientFactory] connect made: {}'.format(conn))
     self._client.conn = conn
     # 成功连接账号服务器
     if self._client.auth_node:
         # 裸包注册账号
         # register_account(self._client, self._client.user_name, self._client.password)
         # 裸包登陆
         # account_verify_official(self._client, self._client.user_name, self._client.password)
         # 渠道登陆
         account_verify_channel(self._client, self._client.user_name)
     # 成功连接游戏服务器
     else:
         user_login(self._client)
Example #53
0
 def init_db_pool(self,
                  max_active=5,
                  max_wait=5,
                  init_size=1,
                  db_type='mysql',
                  **config):
     func.log_info('[DBPool] init_db_pool {}'.format(config))
     self._free_connections = Queue.Queue(max_active)
     self._max_wait = max_wait
     self._db_type = db_type
     self._config = config
     for _ in xrange(init_size):
         self.free_conn(self.create_conn())
     self._cur_conn = None
Example #54
0
 def init(self, **kwargs):
     func.log_info('[game] WechatPay init kwargs: {}'.format(kwargs))
     self.order_id_ = str(kwargs['order_id'])
     self._params = {
         'appid': constant.WECHAT_APPID,
         'mch_id': constant.WECHAT_MCH_ID,
         'nonce_str': kwargs['nonce_str'],  # 随机字符串,不长于32位
         'body': constant.WECHAT_BODY,  # 商品或支付单简要描述
         'attach': kwargs['attach'],  # 商家附加数据, 127位
         'out_trade_no': str(kwargs['order_id']),  # 唯一商户订单号, 32位, 字母+数字均可
         'total_fee': str(int(kwargs['total_fee'])),  # 订单总金额,单位为分
         'spbill_create_ip': kwargs['spbill_create_ip'],  # 用户端实际ip
         'trade_type': 'APP',  # 支付类型
         'notify_url': constant.WECHAT_NOTIFY_URL,  # 接收微信支付异步通知回调地址
         'limit_pay': 'no_credit',  # 不能使用信用卡支付
     }
Example #55
0
def update_record(**kwargs):
    """
    更新, 如果不存在, 则失败
    :param kwargs:
            {
                'table': table_name
                'where': {field_name: field_value}
                'data': {field_name: field_value, ...}
            }
    :return:
    """
    where = _format_condition(kwargs.get('where'))
    update = _format_update_sql(kwargs.get('data'))
    sql = "update {} set {} {}".format(safestr(kwargs.get('table')),
                                       safestr(update), safestr(where))
    func.log_info('[execute] update_record {}'.format(sql))
    return execute(sql)
Example #56
0
 def callTargetSingle(self, target_key, *args, **kw):
     self._lock.acquire()
     target = self.getTarget(0)
     try:
         if not target:
             func.log_info('[Net callTargetSingle] the command ' +
                           str(target_key) + ' not Found on service')
             return None
         #if target_key not in self.unDisplay:
         #    func.log_info('[Net] call method {} on service'.format(target.__name__))
         defer_data = target(target_key, *args, **kw)
         if not defer_data:
             return None
         if isinstance(defer_data, defer.Deferred):
             return defer_data
         d = defer.Deferred()
         d.callback(defer_data)
     finally:
         self._lock.release()
     return d
Example #57
0
def account_verify_channel(dynamic_id, address, user_name, channel_id, uuid,
                           token, name, head_frame, head_icon, sex):
    func.log_info(
        '[auth] account_verify_channel dynamic_id: {}, user_name: {}, channel_id: {}, uuid: {}, head_frame: {}, head_icon: {}, sex: {}'
        .format(dynamic_id, user_name, channel_id, uuid, head_frame, head_icon,
                sex))
    if not user_name or not uuid or channel_id < 0:
        send.system_notice(dynamic_id, content.ACCOUNT_LOGIN_ARGUMENT)
        return
    password = uuid
    sql = 'select * from {} where user_name="{}"'.format(
        dbname.DB_ACCOUNT, user_name)
    result = dbexecute.query_one(sql)
    if not result:
        account_id = _register_process(user_name, password, name, uuid, token,
                                       channel_id, sex, head_frame, head_icon)
        if not account_id:
            send.system_notice(dynamic_id, content.LOGIN_USER_CREATE_FAILED_51)
            return
        result = dbexecute.query_one(sql)
        if not result:
            send.system_notice(dynamic_id, content.LOGIN_USER_CREATE_FAILED_52)
            return
    #encrypt_password = func.encrypt_password(user_name, password, result['token_key'])
    #if encrypt_password != result['password']:
    #    send.system_notice(dynamic_id, content.LOGIN_USER_CREATE_FAILED_53)
    #    return
    #if not _check_weixin_token(uuid, token):
    #    send.system_notice(dynamic_id, content.LOGIN_USER_CREATE_FAILED_54)
    #    return
    account_id = result['account_id']
    verify_key = _create_verify_key(account_id, result['token_key'])
    notice_gate_user_channel_login(account_id,
                                   verify_key,
                                   address,
                                   name=name,
                                   sex=sex,
                                   head_frame=head_frame,
                                   head_icon=head_icon)
    t = func.time_get()
    send.account_verify_channel(dynamic_id, t, account_id, verify_key)
Example #58
0
 def dataReceived(self, data):
     self._buffer += data
     length = self._factory.data_protocol.getHeadlength()       # 获取协议头的长度
     while self._buffer.__len__() >= length:
         un_pack_data = self._factory.unpack(self._buffer[:length])
         if not un_pack_data.get('result'):
             # 数据异常, 断开重连
             func.log_info('illegal data package --')
             self.transport.loseConnection()
             break
         command = un_pack_data.get('command')
         rlength = un_pack_data.get('length')
         request = self._buffer[length:length+rlength]
         if request.__len__() < rlength:
             func.log_info('Data is not complete, waiting for the data ...')
             break
         self._buffer = self._buffer[length+rlength:]
         key, d = self._factory.do_data_received(command, request)
         if not d:
             continue
         d.addCallback(self.safeToWriteData, command, key)
         d.addErrback(deferred_error_handle)
Example #59
0
 def calc_prepay_id(self):
     xml = self.get_req_xml()
     headers = {'Content-Type': 'application/xml'}
     r = requests.post(self._url, data=xml, headers=headers)
     func.log_info('[game] wechatpay ret: {} url: {} xml: {}'.format(
         r, self._url, xml))
     re_xml = ElementTree.fromstring(r.text.encode('utf8'))
     xml_status = re_xml.getiterator('result_code')[0].text
     func.log_info(
         '[game] WechatPay query_wechat_prepay_id xml_status: {}'.format(
             xml_status))
     if xml_status != 'SUCCESS':
         self._error = content.RECHARGE_WECHAT_CONNECT_FAILED
         return
     prepay_id = re_xml.getiterator('prepay_id')[0].text
     func.log_info('[game] WechatPay prepay_id: {}'.format(prepay_id))
     self._params['prepay_id'] = prepay_id
     self._params['package'] = 'Sign=WXPay'
     self._params['timestamp'] = str(func.time_get())