Пример #1
0
    def on_exchange(self, uid, gid, mi):
        mo = MsgPack(Message.MSG_SYS_EXCHANGE | Message.ID_ACK)
        _id = mi.get_param('id')
        if not isinstance(_id, int):
            return mo.set_error(1, 'error param')

        conf = Context.Configure.get_game_item_json(gid, 'exchange.config')
        if _id >= len(conf):
            return mo.set_error(1, 'error id')

        info = conf[_id]
        to_type = info['type']
        if to_type not in ('diamond', 'props', 'phone'):
            raise Exception(
                str(to_type) + '<----error type, please check config')

        real, final = Context.UserAttr.incr_coupon(uid, gid, -info['cost'],
                                                   'exchange.' + to_type)
        if real != -info['cost']:
            return mo.set_error(2, 'not enough')
        mo.set_param('coupon', final)
        record = {
            'uid': uid,
            'type': 'exchange',
            'ts': Time.current_ts(),
            'from': 'coupon',
            'to': to_type,
            'cost': info['cost'],
            'count': info['count'],
            'desc': info['desc']
        }
        if info['type'] == 'diamond':  # 兑换钻石
            real, final = Context.UserAttr.incr_diamond(
                uid, gid, info['count'], 'exchange.diamond')
            mo.set_param('diamond', final)
            state = 1
        elif info['type'] == 'props':  # 兑换道具
            real, final = FishProps.incr_props(uid, gid, info['id'],
                                               info['count'], 'exchange.props')
            mo.set_param('id', info['id'])
            mo.set_param('count', final)
            state = 1
            record['id'] = info['id']
        elif info['type'] == 'phone':
            state = 0
            record['phone'] = mi.get_param('phone')
        else:
            raise Exception('something error, please check config')

        seq_num = Context.RedisMix.hash_incrby('game.%d.info.hash' % gid,
                                               'exchange.history.seq', 1)
        Context.RedisCluster.hash_set(uid, 'history:%d:%d' % (gid, uid),
                                      seq_num, state)

        record = Context.json_dumps(record)
        Context.RedisMix.hash_mset('game.%d.exchange.record' % gid, seq_num,
                                   record)
        fmt = Time.current_time('%Y-%m-%d')
        Context.RedisStat.hash_set('history:%d:%s' % (gid, fmt), seq_num, uid)
        return mo
Пример #2
0
 def on_consume_cdkey(self, uid, gid, mi):
     code = mi.get_param('code')
     imei = mi.get_param('imei')
     timestamp = (int(time.time()))
     # data = {'appId': 1002, 'code': code, 'userChannel': 0, 'imei': imei, 'userId': uid,'timestamp': timestamp ,'token':'asdsd'}
     data = 'code=' + str(code) + '&' + 'userId=' + str(
         uid) + '&' + 'timestamp=' + str(timestamp) + '&token=asdsd'
     cdkey_server_url = Context.Configure.get_game_item(
         gid, 'cdkey.server.url')
     Context.Log.info("cdkey_server_url:", cdkey_server_url)
     result = Context.WebPage.wait_for_json(cdkey_server_url, postdata=data)
     mo = MsgPack(Message.MSG_SYS_CONSUME_CDKEY | Message.ID_ACK)
     if result['result'] != 1:  # 错误
         mo.set_error(result['result'])
     else:
         try:
             Context.Log.info("desc:", result['desc'])
             reward = self.__convert_cdkey_desc(result['desc'])
             rewards = FishProps.issue_rewards(uid, gid, reward,
                                               'cdkey.reward')
             _rewards = FishProps.convert_reward(rewards)
             mo.update_param(_rewards)
         except Exception, e:
             Context.Log.exception(uid, gid, result)
             return
Пример #3
0
    def on_join_table(self, gid, msg):
        ack = MsgPack(Message.MSG_SYS_JOIN_TABLE | Message.ID_ACK)
        tid = msg.get_param('tableId')
        self._info('player req to join table', tid)
        self.offline = False
        if self.tid > 0 and self.tid != tid:
            self.offline = True
            return ack.set_error(Enum.join_table_failed_multi)

        registry = Context.get_module(gid, 'registry')
        table = registry.create_table(gid, tid)
        if not table:
            self.offline = True
            return ack.set_error(Enum.join_table_failed_id)

        result = table.join_table(self.uid)
        if result != 0:
            self.offline = True
            return ack.set_error(result)

        self.table = table
        self.online_ts = Time.current_ts()

        sid = msg.get_param('seatId')
        if sid is not None:
            return self.on_sit_down(msg)
        return result
Пример #4
0
    def on_use_props(self, uid, gid, mi):
        _id = mi.get_param('id')
        _count = mi.get_param('count')
        mo = MsgPack(Message.MSG_SYS_USE_PROPS | Message.ID_ACK)
        if _id not in [
                FishProps.PROP_EGG_BRONZE, FishProps.PROP_EGG_SILVER,
                FishProps.PROP_EGG_GOLD, FishProps.PROP_EGG_COLOR
        ]:
            return mo.set_error(1, 'can not use')

        if not isinstance(_count, int) or _count <= 0:
            return mo.set_error(2, 'count error')

        conf = FishProps.get_config_by_id(gid, _id)
        if not conf:
            Context.Log.error('not found props:', uid, gid, _id, _count)
            return mo.set_error(4, 'not found props')

        real, final = FishProps.incr_props(uid, gid, _id, -_count,
                                           'entity.use')
        if real != -_count:
            return mo.set_error(3, 'not enough')

        if _count == 1:
            reward = conf['content']
        else:
            reward = FishProps.merge_reward(*[conf['content']] * _count)
        reward = Context.copy_json_obj(reward)
        reward = self.deal_reward(reward)
        reward = FishProps.issue_rewards(uid, gid, reward, 'entity.use')
        reward = FishProps.convert_reward(reward)
        mo.update_param(reward)
        return mo
Пример #5
0
    def on_leave_table(self, msg):
        self._info('player req to leave table', self.tid)
        ack = MsgPack(Message.MSG_SYS_LEAVE_TABLE | Message.ID_ACK)
        table = Context.GData.online_table.get(self.tid)
        if not table:
            self._error('not exists the table', self.tid)
            return ack.set_error(Enum.leave_table_failed_id)

        result = table.leave_table(self.uid)
        if result != 0:
            return ack.set_error(result)

        return result
Пример #6
0
    def on_sit_down(self, msg):
        sid = msg.get_param('seatId')
        self._info('player req to sit table %d at %d' % (self.tid, sid))
        ack = MsgPack(Message.MSG_SYS_SIT_DOWN | Message.ID_ACK)
        table = Context.GData.online_table.get(self.tid)
        if not table:
            self._error('not exists the table', self.tid)
            return ack.set_error(Enum.sit_down_failed_id)
        result = table.sit_down(self.uid, sid)
        if result != 0:
            return ack.set_error(result)

        return result
Пример #7
0
    def on_resolve_stone(self, uid, gid, mi):
        # 分解强化石
        mo = MsgPack(Message.MSG_SYS_RESOLVE_STONE | Message.ID_ACK)

        stone_id = mi.get_param('id')
        if stone_id not in [215, 216, 217, 218]:
            return mo.set_error(1, 'id error')
        conf = FishProps.get_config_by_id(gid, stone_id)
        count = -conf['count']
        if not FishProps.mincr_props(uid, gid, 'on_resolve_stone', stone_id,
                                     count):
            return mo.set_error(2, 'lack stone')
        gem_count = random.randint(conf['resolve'][0], conf['resolve'][1])
        FishProps.mincr_props(uid, gid, 'on_resolve_stone', 219, gem_count)
        mo.set_param('num', gem_count)
        return mo
Пример #8
0
    def onGameInfo(self, uid, gid, mi):
        gid = mi.get_param('gameId')
        mo = MsgPack(Message.MSG_SYS_GAME_INFO | Message.ID_ACK)
        account = Context.get_module(gid, 'account', Account)
        is_new, data = account.get_game_info(uid, gid)
        if not data:
            mo.set_error(-1, 'no game info')
        else:
            mo.update_param(data)
            if is_new:
                mo.set_param('new', 1)

        info = Context.RedisCache.hash_mget('global.notice', 'led', 'start',
                                            'end')
        led = info[0]
        if led:
            now_ts = Time.current_ts()
            start = int(info[1])
            end = int(info[2])
            if start < now_ts < end:
                mo.set_param('global_notice', {
                    'list': [led],
                    'end': end,
                    'now_ts': now_ts
                })

        Context.GData.send_to_connect(uid, mo)

        if is_new:
            account.on_create_user(uid, gid)

        if account.auto_issue_benefit:
            benefit_config = Context.Configure.get_game_item_json(
                gid, 'benefit.config')
            if benefit_config and benefit_config['limit'] > data['chip']:
                benefit = Context.Daily.issue_benefit(uid, gid)
                mo = MsgPack(Message.MSG_SYS_BENEFIT | Message.ID_NTF)
                if not benefit:
                    benefit = {
                        'which': 0,
                        'total': 0,
                        'reward': 0,
                        'chip': data['chip'],
                    }
                mo.update_param(benefit)
                Context.GData.send_to_connect(uid, mo)
Пример #9
0
    def onLed(self, uid, gid, mi):
        mo = MsgPack(Message.MSG_SYS_LED | Message.ID_ACK)
        action = mi.get_param('action', 'get')
        if action == 'get':
            last_ts = mi.get_param('last_ts', 0)
            led_list = Context.RedisCache.list_range('global.led.list', 0, 9)
            _list, ts = [], 0
            for led in led_list:
                led = Context.json_loads(led)
                if led['ts'] > last_ts:
                    _list.append(led['led'])
                    ts = led['ts']
            if _list:
                mo.set_param('global', {'ts': ts, 'list': _list})

            led_list = Context.RedisCache.list_range('game.%d.led.list' % gid,
                                                     0, 9)
            _list, ts = [], 0
            for led in led_list:
                led = Context.json_loads(led)
                if led['ts'] > last_ts:
                    _list.append(led['led'])
                    ts = led['ts']

            if _list:
                mo.set_param('game', {'ts': ts, 'list': _list})
        elif action == 'put':
            conf = Context.Configure.get_game_item_json(gid, 'led.config')
            if not conf or not conf.get('enable'):
                mo.set_error(101, 'led not available')
            else:
                msg = mi.get_param('msg')
                cost = conf['cost']
                real, final = Context.UserAttr.incr_diamond(
                    uid, gid, -cost, 'led.put')
                if real != -cost:
                    mo.set_error(102, 'no enough diamond')
                else:
                    led = Context.json_dumps({
                        'led': msg,
                        'ts': Time.current_ts()
                    })
                    Context.RedisCache.list_lpush('game.%d.led.list' % gid,
                                                  led)

        return Context.GData.send_to_connect(uid, mo)
Пример #10
0
    def on_raffle(self, uid, gid, mi):
        _id = mi.get_param('i')
        _button = mi.get_param('bt')
        mo = MsgPack(Message.MSG_SYS_RAFFLE | Message.ID_ACK)
        raffle_config = Context.Configure.get_game_item_json(
            gid, 'raffle.config')
        raffle_config = Context.copy_json_obj(raffle_config)
        loop_config = raffle_config['loop']
        raffle_config = raffle_config['config']
        class_pool, loop_times = Context.Daily.get_daily_data(
            uid, gid, 'fake.bonus.count', 'bonus.loop.times')
        class_pool = Tool.to_int(class_pool, 0)
        loop_times = Tool.to_int(loop_times, 0)
        if loop_times > len(loop_config) - 1:
            this_count = loop_config[-1]
        else:
            this_count = loop_config[loop_times]
        if class_pool < this_count:
            return mo.set_error(1, 'lack fish')

        for item in raffle_config:
            if item['id'] == _id:
                bonus_pool = Context.Data.get_game_attr_int(
                    uid, gid, 'bonus_pool', 0)
                if bonus_pool < item['limit']:
                    return mo.set_error(2, 'lack chip')
                # 发放奖励
                index, which = Algorithm.choice_by_ratio(item['reward'],
                                                         10000,
                                                         func=lambda l: l[0])
                reward = FishProps.issue_rewards(uid, gid, which[1],
                                                 'bonus.raffle')
                mo.set_param('bt', _button)
                mo.set_param('i', index + 1)
                rw = FishProps.convert_reward(reward)
                mo.update_param(rw)
                # 重置数据
                pipe_args = [
                    'fake.bonus.count', -class_pool, 'bonus.loop.times', 1
                ]
                Context.Daily.mincr_daily_data(uid, gid, *pipe_args)
                Context.Data.hincr_game(uid, gid, 'bonus_pool', -bonus_pool)
                self.__pub_raffle_led(uid, gid, item['name'], reward)
                return mo

        return mo.set_error(3, 'error id')
Пример #11
0
    def on_consume_task(self, uid, gid, mi):
        _id = mi.get_param('id')
        mo = MsgPack(Message.MSG_SYS_CONSUME_TASK | Message.ID_ACK)
        task_list = Context.Daily.get_daily_data(uid, gid, 'task.list')
        if not task_list:
            return mo.set_error(1, 'no task')

        task_list = Context.json_loads(task_list)
        degree = 0
        for task in task_list:
            if task['type'] == 1:
                count = Context.Daily.get_daily_data(uid, gid, 'fish.' + str(task['fish_type']))
                task['count'] = Tool.to_int(count, 0)
            elif task['type'] == 2:
                count = Context.Daily.get_daily_data(uid, gid, 'class.boss')
                task['count'] = Tool.to_int(count, 0)
            elif task['type'] == 3:
                count = Context.Daily.get_daily_data(uid, gid, 'class.bonus')
                task['count'] = Tool.to_int(count, 0)
            elif task['type'] == 11:
                count = Context.Daily.get_daily_data(uid, gid, 'win.chip')
                task['count'] = Tool.to_int(count, 0)
            elif task['type'] == 21:
                degree += task['degree']

            if 'count' in task and task['count'] >= task['total']:
                task['done'] = 1
                degree += task['degree']

        conf = Context.Configure.get_game_item_json(gid, 'task.config')
        for i, reward in enumerate(conf['reward']):
            if i == _id:
                if degree < reward['degree']:
                    return mo.set_error(2, 'not done')
                state = Context.Daily.incr_daily_data(uid, gid, 'task.reward.%d' % _id, 1)
                if state > 1:
                    return mo.set_error(3, 'received')
                reward = FishProps.issue_rewards(uid, gid, reward['reward'], 'task.reward.%d' % _id)
                _reward = FishProps.convert_reward(reward)
                mo.update_param(_reward)
                break
        else:
            mo.set_error(4, 'error id')

        return mo
Пример #12
0
 def onServerInfo(self, uid, gid, mi):
     mo = MsgPack(Message.MSG_SYS_SERVER_INFO | Message.ID_ACK)
     game_room = Context.GData.map_room_type.get(gid)
     if game_room is None:
         mo.set_error(1, 'not found game')
     else:
         total, online_list = 0, []
         room_types = sorted(game_room.keys())
         onlines = Context.Online.get_online(gid, *room_types)
         for _type, _online in zip(room_types, onlines):
             _online = Tool.to_int(_online, 0)
             if _online < 1000:
                 _online = 1000 + random.randint(0, 10)
             total += _online
             online_list.append([_type, _online])
         mo.set_param('gameId', gid)
         mo.set_param('list', online_list)
         mo.set_param('online', total)
     return Context.GData.send_to_connect(uid, mo)
Пример #13
0
    def on_benefit(self, uid, gid, mi):
        mo = MsgPack(Message.MSG_SYS_BENEFIT | Message.ID_ACK)
        conf = Context.Configure.get_game_item_json(gid, 'benefit.config')
        total_times = len(conf['reward'])
        benefit_times, bankrupt_ts = Context.Daily.get_daily_data(
            uid, gid, 'benefit_times', 'bankrupt_ts')
        benefit_times = Tool.to_int(benefit_times, 0)
        if benefit_times >= total_times:
            return mo.set_error(1, 'none')
        now_ts = Time.current_ts()
        if not bankrupt_ts or int(bankrupt_ts) > now_ts:
            return mo.set_error(2, 'wait')

        result = Context.Daily.issue_benefit(uid, gid)
        if not result:
            return mo.set_error(3, 'failed')

        Context.Daily.del_daily_data(uid, gid, 'bankrupt_ts')
        mo.update_param(result)
        return mo
Пример #14
0
    def process_login(self, mi):
        uid = mi.get_param('userId')
        gid = mi.get_param('gameId')
        session = mi.get_param('session')
        result, desc = Account.check_forbidden(uid, gid, session)
        if result:
            mo = MsgPack(Message.MSG_SYS_USER_INFO | Message.ID_ACK)
            mo.set_error(result, desc)
            return Context.GData.send_to_client(uid, mo, self.connection)

        if uid in Context.GData.map_client_connect:  # 多点登陆
            # 清除原来的client
            connection = Context.GData.map_client_connect[uid]
            mo = MsgPack(Message.MSG_SYS_MULTIPLE_LOGIN | Message.ID_NTF)
            Context.Log.info('multi login', uid)
            Context.GData.send_to_client(connection.userId, mo, connection)
            connection.terminate_connection()

        Context.GData.map_client_connect[uid] = self.connection
        self.connection.login(uid, gid)
        return True
Пример #15
0
    def onUserInfo(self, uid, gid, mi):
        mo = MsgPack(Message.MSG_SYS_USER_INFO | Message.ID_ACK)
        account = Context.get_module(gid, 'account', Account)
        data = account.get_user_info(uid, gid)
        if not data:
            mo.set_error(-1, 'no user info')
        else:
            mo.update_param(data)

        login = mi.get_param('login')
        if login:
            account.on_user_login(uid, gid)
            result, loc = Online.get_location(uid, gid)
            if result and loc:
                loc = {
                    'roomType': loc['room_type'],
                    'tableId': loc['table_id'],
                    'seatId': loc['seat_id']
                }
                mo.set_param('loc', loc)
        return Context.GData.send_to_connect(uid, mo)
Пример #16
0
    def on_inner_buy(self, uid, gid, mi):
        mo = MsgPack(Message.MSG_SYS_INNER_BUY | Message.ID_ACK)
        _id = mi.get_param('id')
        if not isinstance(_id, int):
            return mo.set_error(1, 'error param')
        _count = mi.get_param('count')
        if not isinstance(_count, int) or _count <= 0:
            return mo.set_error(2, 'error param')
        if _id not in [201, 202, 203, 204, 205]:
            return mo.set_error(3, 'error id')
        conf = FishProps.get_config_by_id(gid, _id)
        if conf:
            if 'count' in conf:
                if _count % conf['count'] != 0:
                    return mo.set_error(5, 'error count')
            real, final = Context.UserAttr.incr_diamond(
                uid, gid, -conf['diamond'], 'inner.buy.%d' % _id)
            if real != -conf['diamond']:
                return mo.set_error(6, 'not enough')
            mo.set_param('diamond', final)
            real, final = FishProps.incr_props(uid, gid, _id, _count,
                                               'inner.buy')
            mo.set_param('id', _id)
            mo.set_param('count', final)
            return mo

        Context.Log.error('no props config found', _id)
        return mo.set_error(7, 'unknown')
Пример #17
0
    def on_up_barrel(self, uid, gid, mi):
        # 强化万倍炮
        # up type 1 石头 2 精华
        mo = MsgPack(Message.MSG_SYS_UP_BARREL | Message.ID_ACK)
        up_type = mi.get_param('up_ty')
        conf = Context.Configure.get_game_item_json(gid,
                                                    'barrel.unlock.config')
        if not conf:
            return mo.set_error(1, 'system error')

        next_level = Context.Data.get_game_attr_int(uid, gid, 'barrel_level',
                                                    1) + 1
        # if next_level > len(conf):
        if next_level <= 36 or next_level > 54:
            return mo.set_error(2, 'level error')
        level_conf = conf[next_level - 1]

        diamond_count = level_conf['diamond']
        real, final = Context.UserAttr.incr_diamond(uid, gid, -diamond_count,
                                                    'up.barrel')
        if real != -diamond_count:
            return mo.set_error(3, 'lack diamond')

        if up_type == 1:
            count = -level_conf['stone']
            if not FishProps.mincr_props(uid, gid, 'on_up_barrel', 215, count,
                                         216, count, 217, count, 218, count):
                Context.UserAttr.incr_diamond(uid, gid, diamond_count,
                                              'up.barrel.error')
                return mo.set_error(3, 'lack stone')
            res, gem = self.do_up_barrel(level_conf)
            if res:
                Context.Data.set_game_attr(uid, gid, 'barrel_level',
                                           next_level)
            else:
                FishProps.mincr_props(uid, gid, 'on_up_barrel.fail_reurn', 219,
                                      gem)
                mo.set_param('num', gem)
        elif up_type == 2:
            count = -level_conf['stone']
            count_gem = -level_conf['gem']
            if not FishProps.mincr_props(uid, gid, 'on_up_barrel', 215, count,
                                         216, count, 217, count, 218, count,
                                         219, count_gem):
                Context.UserAttr.incr_diamond(uid, gid, diamond_count,
                                              'up.barrel.error')
                return mo.set_error(3, 'lack item')
            Context.Data.set_game_attr(uid, gid, 'barrel_level', next_level)
        else:
            return mo.set_error(4, 'type error')
        return mo
Пример #18
0
    def on_present(self, uid, gid, mi):
        mo = MsgPack(Message.MSG_SYS_PRESENT | Message.ID_ACK)
        _id = mi.get_param('id')
        if not isinstance(_id, int):
            return mo.set_error(1, 'error param')
        _count = mi.get_param('count')
        if not isinstance(_count, int) or _count <= 0:
            return mo.set_error(2, 'error param')
        if _id not in [
                201, 202, 203, 204, 205, 211, 212, 213, 214, 215, 216, 217,
                218, 219
        ]:
            return mo.set_error(3, 'error id')
        ta = mi.get_param('ta')
        if ta < 0 or not Context.UserAttr.check_exist(ta, gid):
            return mo.set_error(4, 'error uid')
        conf = FishProps.get_config_by_id(gid, _id)
        if conf:
            if 'count' in conf:
                if _count % conf['count'] != 0:
                    return mo.set_error(5, 'error count')
            if 'present' in conf:
                pay_total = Context.Data.get_game_attr_int(
                    uid, gid, 'pay_total', 0)
                if conf['present']['pay'] > pay_total:
                    return mo.set_error(7, 'pay limit')
            real, final = FishProps.incr_props(uid,
                                               gid,
                                               _id,
                                               -_count,
                                               'present.props',
                                               ta=ta)
            if real != -_count:
                return mo.set_error(6, 'not enough')
            mo.set_param('id', _id)
            mo.set_param('count', final)
            FishProps.incr_props(ta, gid, _id, _count, 'present.props', ta=uid)
            return mo

        Context.Log.error('no props config found', _id)
        return mo.set_error(7, 'unknown')
Пример #19
0
    def on_sign_in(self, uid, gid, mi):
        mo = MsgPack(Message.MSG_SYS_SIGN_IN | Message.ID_ACK)
        conf = Context.Configure.get_game_item_json(gid, 'login.reward')
        if not conf:
            Context.Log.error('miss config')
            return mo.set_error(1, 'miss config')

        now_day, last_login, ns_login = FishAccount.get_login_info(uid, gid)
        if now_day == last_login:
            return mo.set_error(2, 'already sign in')
        elif now_day == last_login + 1:  # 连续登陆
            ns_login += 1
        else:
            ns_login = 0
        FishAccount.set_login_info(uid, gid, now_day, ns_login)
        vip_level = FishAccount.get_vip_level(uid, gid)

        if vip_level:
            conf = conf['vip']
        else:
            conf = conf['common']
        reward = conf[ns_login % len(conf)]
        real, final = Context.UserAttr.incr_chip(uid, gid, reward,
                                                 'signin.reward')

        pipe_args = []
        delta_chip = real
        # 领取月卡奖励
        success, left_days = FishProps.use_vip(uid, gid)
        if success:
            conf = Context.Configure.get_game_item_json(
                gid, 'month.card.reward')
            reward = FishProps.issue_rewards(uid, gid, conf,
                                             'month.card.reward')
            if 'diamond' in reward:
                mo.set_param('diamond', reward['diamond'])
                pipe_args.append('login.carrying.volume.diamond')
                pipe_args.append(reward['reward']['diamond'])
            if 'coupon' in reward:
                mo.set_param('coupon', reward['coupon'])
                pipe_args.append('login.carrying.volume.coupon')
                pipe_args.append(reward['reward']['coupon'])
            if 'chip' in reward:
                final = reward['chip']
                delta_chip += reward['reward']['chip']

        pipe_args.append('login.carrying.volume.chip')
        pipe_args.append(delta_chip)
        pipe_args.append('carrying.volume.chip')
        pipe_args.append(delta_chip)
        Context.Daily.mincr_daily_data(uid, gid, *pipe_args)

        if vip_level:
            vip_conf = Context.Configure.get_game_item_json(
                gid, 'vip.config')[vip_level - 1]
            stone_count = vip_conf.get('stone', 0)
            if stone_count:
                FishProps.mincr_props(uid, gid, 'vip_reward', 215, stone_count,
                                      216, stone_count, 217, stone_count, 218,
                                      stone_count)
            chip_num = vip_conf.get('chip')
            if chip_num and chip_num > final:
                add_num = chip_num - final
                real, final = Context.UserAttr.incr_chip(
                    uid, gid, add_num, 'vip_reward')
        if final:
            mo.set_param('chip', final)
        return mo
Пример #20
0
    def __on_quick_start(self, uid, gid, mi):
        Context.Log.info(uid, 'req quick start with', mi)
        mo = MsgPack(Message.MSG_SYS_QUICK_START | Message.ID_ACK)

        result, location = Context.Online.get_location(uid, gid)
        if not result:
            return mo.set_error(Enum.quick_start_failed_unknown,
                                'info illegal')

        now_ts = Time.current_ts()
        if location:
            mo.set_param('serverId', location['serverId'])
            mo.set_param('roomType', location['room_type'])
            mo.set_param('tableId', location['table_id'])
            mo.set_param('seatId', location['seat_id'])
            return mo

        room_type = mi.get_param('roomType', 0)
        chip = Context.UserAttr.get_chip(uid, gid, 0)
        room_type, desc = self.__find_available_room(uid, gid, chip, room_type)
        if room_type not in (201, 202, 203):
            return mo.set_error(room_type, desc)

        play_mode = mi.get_param('playMode', Enum.play_mode_common)
        if play_mode != Enum.play_mode_common:
            return mo.set_error(110, 'error play mode')

        # 分配玩家
        for num in (3, 2, 1):
            table_list = self.__get_table_list(gid, room_type, play_mode, num)
            for table_id in table_list:
                key = 'table:%d:%d' % (gid, table_id)
                attrs = ['status', 'fresh_ts', 'serverId']
                kvs = Context.RedisCache.hash_mget_as_dict(key, *attrs)
                if len(attrs) != len(kvs):
                    Context.Log.error('get table info failed', uid, gid,
                                      room_type, table_id, num, kvs)
                    continue

                server_id = int(kvs['serverId'])
                if server_id < 0:
                    Context.Log.info('table server_id error', uid, gid,
                                     room_type, table_id, num, server_id)
                    continue

                seat_id = self.__join_table(uid, gid, room_type, play_mode,
                                            table_id)
                if seat_id < 0:
                    Context.Log.error('join_table failed!', uid, gid,
                                      room_type, table_id)
                    continue
                Context.Online.set_location(uid,
                                            gid,
                                            server_id,
                                            room_type,
                                            table_id,
                                            seat_id,
                                            0,
                                            now_ts,
                                            play_mode=play_mode)
                mo.set_param('serverId', server_id)
                mo.set_param('roomType', room_type)
                mo.set_param('tableId', table_id)
                mo.set_param('seatId', seat_id)
                Context.Log.info('join table', uid, gid, server_id, room_type,
                                 table_id, server_id, play_mode)
                return mo

        # new table
        table_id = self.get_free_table(gid)
        server_id = self.__select_server(uid, gid, table_id, room_type)
        if not server_id:
            Context.Log.error('select server failed', uid, gid, room_type)
            return mo.set_error(Enum.quick_start_failed_unknown,
                                'no server found')

        self.__create_table(gid, room_type, play_mode, table_id, server_id,
                            now_ts)
        seat_id = self.__join_table(uid, gid, room_type, play_mode, table_id)
        if seat_id < 0:
            Context.Log.error('join_table failed!', uid, gid, room_type,
                              table_id)
            return mo.set_error(Enum.quick_start_failed_unknown,
                                'json table failed')

        Context.Online.set_location(uid,
                                    gid,
                                    server_id,
                                    room_type,
                                    table_id,
                                    seat_id,
                                    0,
                                    now_ts,
                                    play_mode=play_mode)

        mo.set_param('serverId', server_id)
        mo.set_param('roomType', room_type)
        mo.set_param('tableId', table_id)
        mo.set_param('seatId', seat_id)
        Context.Log.info('create location info', uid, gid, server_id,
                         room_type, table_id, seat_id, play_mode)
        return mo