Exemple #1
0
    def get_ranks(self, uid, gid, mi):
        rank_name = mi.get_param('rank')
        if not rank_name:
            rank_name = ['chip', 'exp']
        elif isinstance(rank_name, (str, unicode)):
            rank_name = [rank_name]

        start = mi.get_param('start', 0)
        end = mi.get_param('end', 49)
        if start < 0 or end < start:
            return
        if end - start > 49:
            end = start + 49

        mo = MsgPack(Message.MSG_SYS_RANK_LIST | Message.ID_ACK)
        rank_list, mine = {}, {}
        if 'chip' in rank_name:
            _, rank_list['chip'] = self.get_chip_rank_list(
                uid, gid, start, end)
        if 'exp' in rank_name:
            _, rank_list['exp'] = self.get_exp_rank_list(uid, gid, start, end)

        mo.update_param(rank_list)
        if 'chip' in rank_list or 'exp' in rank_list:
            _info = self.__get_user_info(uid, gid)
            mine.update(_info)
        if mine:
            mo.set_param('mine', mine)
        return mo
Exemple #2
0
 def query_diamond_consume(self, gid, mi, request):
     start = mi.get_param('start')
     end = mi.get_param('end')
     start_day = Time.str_to_datetime(start, '%Y-%m-%d')
     end_day = Time.str_to_datetime(end, '%Y-%m-%d')
     mo = MsgPack(0)
     while start_day <= end_day:
         fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
         kvs = Context.Stat.get_day_data(gid, fmt)
         _kvs, total = {}, 0
         for k, v in kvs.iteritems():
             if k.startswith('out.diamond.'):
                 if k.startswith('out.diamond.inner.buy.'):
                     k = 'out.diamond.buy.' + k[-3:]
                 elif k.startswith('out.diamond.table.buy.'):
                     k = 'out.diamond.buy.' + k[-3:]
                 if k in _kvs:
                     _kvs[k] += int(v)
                 else:
                     _kvs[k] = int(v)
                 total += int(v)
         _kvs['total'] = total
         mo.set_param(fmt, _kvs)
         start_day = Time.next_days(start_day)
     return mo
Exemple #3
0
 def query_pay_detail(self, gid, mi, request):
     conf = Context.Configure.get_game_item_json(gid, 'product.config')
     pids = []
     for pid in conf.iterkeys():
         pids.append('product_' + pid)
     start = mi.get_param('start')
     end = mi.get_param('end')
     start_day = Time.str_to_datetime(start, '%Y-%m-%d')
     end_day = Time.str_to_datetime(end, '%Y-%m-%d')
     mo = MsgPack(0)
     while start_day <= end_day:
         fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
         timess = Context.Stat.get_day_data(gid, fmt, *pids)
         kvs = {'product_100646': 0, 'product_100710': 0}
         for k, v in zip(pids, timess):
             pid = k.replace('product_', '')
             if pid in ('100646', '100647', '100648', '100649', '100650', '100651',
                        '100652', '100653', '100654', '100655'):
                 kvs['product_100646'] += Tool.to_int(v, 0)
             elif pid in ('100710', '100711', '100712', '100713', '100714', '100715', '100716'):
                 kvs['product_100710'] += Tool.to_int(v, 0)
             else:
                 kvs[k] = Tool.to_int(v, 0)
         mo.set_param(fmt, kvs)
         start_day = Time.next_days(start_day)
     return mo
Exemple #4
0
 def query_diamond_produce(self, gid, mi, request):
     start = mi.get_param('start')
     end = mi.get_param('end')
     start_day = Time.str_to_datetime(start, '%Y-%m-%d')
     end_day = Time.str_to_datetime(end, '%Y-%m-%d')
     mo = MsgPack(0)
     while start_day <= end_day:
         fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
         kvs = Context.Stat.get_day_data(gid, fmt)
         _kvs = {}
         total, task_total, fall_total = 0, 0, 0
         for k, v in kvs.iteritems():
             if k.startswith('in.diamond.'):
                 if k.startswith('in.diamond.task.reward.'):
                     task_total += int(v)
                 elif k.startswith('in.diamond.fish.fall.'):
                     fall_total += int(v)
                 else:
                     _kvs[k] = int(v)
                 total += int(v)
         _kvs['in.diamond.task.reward'] = task_total
         _kvs['in.diamond.fish.fall'] = fall_total
         _kvs['in.diamond.buy.product'] = int(kvs.get('in.diamond.buy.product', 0))
         _kvs['total'] = total
         mo.set_param(fmt, _kvs)
         start_day = Time.next_days(start_day)
     return mo
Exemple #5
0
 def query_chip_consume(self, gid, mi, request):
     room_types = (201, 202, 203)
     mini_games = (10002, 10003)
     fields = ['out.chip.attack']
     for room_type in room_types:
         fields.append('out.chip.game.shot.bullet.%d' % room_type)
     for game in mini_games:
         fields.append('out.chip.game.%d' % game)
     start = mi.get_param('start')
     end = mi.get_param('end')
     start_day = Time.str_to_datetime(start, '%Y-%m-%d')
     end_day = Time.str_to_datetime(end, '%Y-%m-%d')
     mo = MsgPack(0)
     while start_day <= end_day:
         fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
         chips = Context.Stat.get_day_data(gid, fmt, *fields)
         attack = Tool.to_int(chips[0], 0)
         info = []
         for chip in chips[1:]:
             if chip:
                 info.append(int(chip))
             else:
                 info.append(0)
         info[2] += attack
         mo.set_param(fmt, info)
         start_day = Time.next_days(start_day)
     return mo
Exemple #6
0
 def query_chip_produce(self, gid, mi, request):
     start = mi.get_param('start')
     end = mi.get_param('end')
     start_day = Time.str_to_datetime(start, '%Y-%m-%d')
     end_day = Time.str_to_datetime(end, '%Y-%m-%d')
     mo = MsgPack(0)
     while start_day <= end_day:
         fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
         kvs = Context.Stat.get_day_data(gid, fmt)
         task_total, catch_total = 0, 0
         _kvs = {}
         for k, v in kvs.iteritems():
             if k.startswith('in.chip.'):
                 if k.startswith('in.chip.task.reward.'):
                     task_total += int(v)
                 elif k.startswith('in.chip.catch.fish.'):
                     catch_total += int(v)
                 else:
                     _kvs[k] = int(v)
         _kvs['in.chip.task.reward'] = task_total
         _kvs['in.chip.catch.fish'] = catch_total
         _kvs['in.chip.buy.product'] = int(kvs.get('in.chip.buy.product', 0))
         mo.set_param(fmt, _kvs)
         start_day = Time.next_days(start_day)
     return mo
Exemple #7
0
    def on_get_config(self, uid, gid, mi):
        which = mi.get_param('which')
        if isinstance(which, (str, unicode)):
            which = [which]

        mo = MsgPack(Message.MSG_SYS_CONFIG | Message.ID_ACK)
        for name in which:
            if name == 'vip':
                conf = self.get_vip_config(uid, gid)
            elif name == 'shop':
                conf = self.get_shop_config(uid, gid)
            elif name == 'raffle':
                conf = self.get_raffle_config(uid, gid)
            elif name == 'props':
                conf = FishProps.get_props_config(gid)
            elif name == 'unlock':
                conf = self.get_unlock_config(uid, gid)
            elif name == 'barrel':
                conf = self.get_barrel_config(uid, gid)
            elif name == 'exchange':
                conf = self.get_exchange_config(uid, gid)
            elif name == 'benefit':
                conf = self.get_benefit_config(uid, gid)
            elif name == 'html':
                conf = self.get_html_config(uid, gid)
            elif name == 'exp':
                conf = self.get_exp_config(uid, gid)
            elif name == 'upbrrel':
                conf = self.get_upbrrel_config(uid, gid)
            else:
                continue
            mo.set_param(name, conf)
        return mo
Exemple #8
0
 def query_chip_pump(self, gid, mi, request):
     room_types = (201, 202, 203)
     fields = []
     for room_type in room_types:
         fields.append('out.chip.pump.%d' % room_type)
         fields.append('out.chip.buff.pump.%d' % room_type)
         fields.append('out.chip.red.pump.%d' % room_type)
     start = mi.get_param('start')
     end = mi.get_param('end')
     start_day = Time.str_to_datetime(start, '%Y-%m-%d')
     end_day = Time.str_to_datetime(end, '%Y-%m-%d')
     mo = MsgPack(0)
     while start_day <= end_day:
         fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
         chips = Context.Stat.get_day_data(gid, fmt, *fields)
         info = []
         for i in range(0, len(chips), 3):
             total = 0
             for j in range(3):
                 if chips[i + j]:
                     total += int(chips[i + j])
             info.append(total)
         mo.set_param(fmt, info)
         start_day = Time.next_days(start_day)
     return mo
Exemple #9
0
 def __pub_raffle_led(self, uid, gid, level, reward_info):
     if 'reward' in reward_info:
         reward = reward_info['reward']
         name = None
         if 'chip' in reward:
             Context.Data.hincr_game(uid, gid, 'chip_pool', -reward['chip'])
         elif 'coupon' in reward:
             name = u'%d鱼券' % reward['coupon']
         elif 'diamond' in reward:
             name = u'%d钻石' % reward['diamond']
         elif 'props' in reward:
             props = reward['props']
             for one in props:
                 name = FishProps.get_props_desc(one['id'])
                 break
         if name:
             nick = Context.Data.get_attr(uid, 'nick')
             if nick:
                 led = u'恭喜%s玩家,在%s中抽中%s' % (nick.decode('utf-8'), level,
                                             name)
                 mo = MsgPack(Message.MSG_SYS_LED | Message.ID_NTF)
                 mo.set_param('game', {
                     'list': [led],
                     'ts': Time.current_ts()
                 })
                 Context.GData.broadcast_to_system(mo)
Exemple #10
0
    def query_summary(self, gid, mi, request):
        # 新增设备, 新增用户, 活跃用户, (新)付费玩家, (新)用户付费, 充值次数
        start = mi.get_param('start')
        end = mi.get_param('end')
        start_day = Time.str_to_datetime(start, '%Y-%m-%d')
        end_day = Time.str_to_datetime(end, '%Y-%m-%d')
        mo = MsgPack(0)
        while start_day <= end_day:
            fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
            kvs = Context.Stat.get_day_data(gid, fmt)
            channel_info = {}
            for k, v in kvs.iteritems():
                if (k.endswith('.new.device.count')
                        or k.endswith('.new.user.count')
                        or k.endswith('.login.user.count')
                        or k.endswith('.new.pay.user.count')
                        or k.endswith('.new.pay.user.pay_total')
                        or k.endswith('.pay.user.count')
                        or k.endswith('.pay.user.pay_total')
                        or k.endswith('.user.pay.times')):
                    channel, key = k.split('.', 1)
                    if channel not in channel_info:
                        channel_info[channel] = {}
                    channel_info[channel][key] = int(v)

            mo.set_param(fmt, channel_info)
            start_day = Time.next_days(start_day)
        return mo
Exemple #11
0
    def on_room_list(self, uid, gid, mi):
        room_config = Context.Configure.get_room_config(gid)
        if not room_config:
            Context.Log.error(uid, 'req room list, but no config fetch')
            return False

        conf = Context.copy_json_obj(room_config)
        mo = MsgPack(Message.MSG_SYS_ROOM_LIST | Message.ID_ACK)
        mo.set_param('room_list', conf)
        return Context.GData.send_to_connect(uid, mo)
Exemple #12
0
 def on_bind_game(self, cmd, raw):
     mi = MsgPack.unpack(cmd, raw)
     gid = mi.get_param('gameId')
     if gid > 0:
         room = mi.get_param('room')
         self.connection.bind_game(gid, room)
         mo = MsgPack(Message.MSG_SYS_BIND_GAME | Message.ID_ACK)
         mo.set_param('gameId', gid)
         Context.GData.send_to_client(self.connection.userId, mo,
                                      self.connection)
     return True
Exemple #13
0
 def terminate_connection(self):
     if self.userId > 0:
         if self.userId in Context.GData.map_client_connect:
             del Context.GData.map_client_connect[self.userId]
         msg = MsgPack(Message.MSG_INNER_BROKEN)
         msg.set_param('userId', self.userId)
         if self.gameId > 0:
             msg.set_param('gameId', self.gameId)
         tasklet = self.makeTasklet(Message.MSG_INNER_BROKEN, msg, self)
         TaskManager.run_task(tasklet)
         self.logout()
     self.transport.loseConnection()
Exemple #14
0
    def gm_reward_card(self, gid, mi, request):
        uid = mi.get_param('userId')
        days = mi.get_param('days')
        if days <= 0:
            return MsgPack.Error(0, 1, 'error days')

        if not Context.UserAttr.check_exist(uid, gid):
            return MsgPack.Error(0, 2, 'not exist')

        state, days = FishProps.incr_vip(uid, gid, days, 'gm.reward')
        mo = MsgPack(0)
        mo.set_param('days', days)
        return mo
Exemple #15
0
 def freeze_user(self, gid, mi, request):
     uid = mi.get_param('userId')
     if not Context.UserAttr.check_exist(uid, gid):
         return MsgPack.Error(0, 1, 'not exist')
     days = mi.get_param('days')
     mo = MsgPack(0)
     if days is None:
         Context.RedisMix.hash_del('game.%d.freeze.user' % gid, uid)
     else:
         end_ts = Time.today_start_ts() + days * 3600 * 24
         Context.RedisMix.hash_set('game.%d.freeze.user' % gid, uid, end_ts)
         mo.set_param('end_ts', end_ts)
     return mo
Exemple #16
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
Exemple #17
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
Exemple #18
0
 def query_carrying(self, gid, mi, request):
     start = mi.get_param('start')
     end = mi.get_param('end')
     start_day = Time.str_to_datetime(start, '%Y-%m-%d')
     end_day = Time.str_to_datetime(end, '%Y-%m-%d')
     mo = MsgPack(0)
     while start_day <= end_day:
         fmt = Time.datetime_to_str(start_day, '%Y-%m-%d')
         _login, _total = Context.Stat.get_day_data(gid, fmt, 'login.carrying.volume.chip', 'carrying.volume.chip')
         _login = Tool.to_int(_login, 0)
         _total = Tool.to_int(_total, 0)
         mo.set_param(fmt, {'carrying': _login, 'total': _total})
         start_day = Time.next_days(start_day)
     return mo
Exemple #19
0
    def process_broken(self, mi):
        uid = mi.get_param('userId')
        gid = mi.get_param('gameId')
        mo = MsgPack(Message.MSG_INNER_BROKEN | Message.ID_NTF)
        gids = set(Context.GData.game_list)
        if gid:
            gids.add(gid)

        for gid in gids:
            key = 'location:%d:%d' % (gid, uid)
            sid = Context.RedisCache.hash_get_int(key, 'serverId', 0)
            if sid > 0:
                mo.set_param('gameId', gid)
                Context.GData.send_to_game(uid, mo, sid, gid=gid)
        return True
Exemple #20
0
 def connectionLost(self, reason=connectionDone):
     try:
         Logger.info('ConnectionLost', 'userId =', self.userId)
         if self.userId > 0:
             msg = MsgPack(Message.MSG_INNER_BROKEN)
             if self.userId in Context.GData.map_client_connect:
                 del Context.GData.map_client_connect[self.userId]
             msg.set_param('userId', self.userId)
             if self.gameId > 0:
                 msg.set_param('gameId', self.gameId)
             tasklet = self.makeTasklet(Message.MSG_INNER_BROKEN, msg, self)
             TaskManager.add_task(tasklet.run)
         else:
             Logger.debug_network('empty user connection lost ... ')
     except Exception, e:
         Logger.exception()
Exemple #21
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
Exemple #22
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')
Exemple #23
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)
Exemple #24
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)
Exemple #25
0
    def gm_reward_vip(self, gid, mi, request):
        uid = mi.get_param('userId')
        rmb = mi.get_param('rmb')
        if not isinstance(rmb, int):
            return MsgPack.Error(0, 1, 'int please')

        if not Context.UserAttr.check_exist(uid, gid):
            return MsgPack.Error(0, 2, 'not exist')

        if rmb < 0:
            pay_total = Context.Data.get_game_attr_int(uid, gid, 'pay_total', 0)
            if pay_total < -rmb:
                return MsgPack.Error(0, 3, 'too much')

        final = FishProps.incr_pay(uid, gid, rmb, 'gm.reward')
        level = FishAccount.get_vip_level(uid, gid, final)
        mo = MsgPack(0)
        mo.set_param('level', level)
        mo.set_param('pay_total', final)
        return mo
Exemple #26
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')
Exemple #27
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)
Exemple #28
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')
Exemple #29
0
    def on_create_user(cls, uid, gid):
        super(FishAccount, cls).on_create_user(uid, gid)
        # 发放一级礼包
        conf = Context.Configure.get_game_item_json(gid, 'exp.level.reward')
        rewards_info = FishProps.issue_rewards(uid, gid, conf[0],
                                               'exp.upgrade')
        rewards_info = FishProps.convert_reward(rewards_info)
        mo = MsgPack(Message.FISH_MSG_EXP_UPGRADE | Message.ID_NTF)
        mo.set_param('exp', 0)
        mo.set_param('lv', 1)
        mo.set_param('df', [1, [0, conf[1]]])
        mo.update_param(rewards_info)
        Context.GData.send_to_connect(uid, mo)

        # new user carrying
        pipe_args = []
        for k in ('chip', 'diamond', 'coupon'):
            if k in rewards_info:
                pipe_args.append('login.carrying.volume.%s' % k)
                pipe_args.append(rewards_info[k])
        if 'chip' in rewards_info:
            pipe_args.append('carrying.volume.chip')
            pipe_args.append(rewards_info['chip'])
        if pipe_args:
            Context.Stat.mincr_daily_data(gid, *pipe_args)
Exemple #30
0
    def check_bankrupt(cls, uid, gid):
        benefit_times, bankrupt_ts = Context.Daily.get_daily_data(
            uid, gid, 'benefit_times', 'bankrupt_ts')
        benefit_times = Tool.to_int(benefit_times, 0)
        wait, which = None, None
        if bankrupt_ts:  # 已经在破产状态, 未领取
            which = benefit_times + 1
            wait = int(bankrupt_ts) - Time.current_ts()
            if wait < 0:
                wait = 0
        else:
            conf = Context.Configure.get_game_item_json(gid, 'benefit.config')
            if benefit_times < len(conf['reward']):
                reward = conf['reward'][benefit_times]
                bankrupt_ts = Time.current_ts() + reward['wait']
                Context.Daily.set_daily_data(uid, gid, 'bankrupt_ts',
                                             bankrupt_ts)
                wait = reward['wait']
                which = benefit_times + 1

        mo = MsgPack(Message.FISH_MSG_BANKRUPT | Message.ID_NTF)
        mo.set_param('userId', uid)
        if wait is not None:
            mo.set_param('wait', wait)
        if which is not None:
            mo.set_param('which', which)  # 可以领取哪一次
        return mo