Exemple #1
0
def doWelfarePatchSign(redis, session):
    """ 
        补签
    """
    sid = request.forms.get('sid', '').strip()
    date = request.forms.get('date', '').strip()

    SessionTable, account, uid, verfiySid = getInfoBySid(redis, sid)
    if verfiySid and sid != verfiySid:
        return {'code': -4, 'msg': '账号已在其他地方登录', 'osid': sid}
    userTable = getUserByAccount(redis, account)

    if not redis.exists(SessionTable):
        return {'code': -3, 'msg': 'sid 超时'}

    if not redis.exists(userTable):
        return {'code': -5, 'msg': '该用户不存在'}
    picUrl, gender, groupId, isVolntExitGroup, maxScore, baseScore = \
        redis.hmget(userTable, ('headImgUrl', 'sex', 'parentAg', 'isVolntExitGroup', 'maxScore', 'baseScore'))
    if not groupId:
        return {'code': -7, 'msg': '您已被移出公会,请重新加入公会'}

    if not date:
        return {'code': 1, 'msg': "补签失败"}

    return doPatchSign(redis, account, date)
Exemple #2
0
def doWelfareSign(redis, session):
    """ 
        签到
    """
    sid = request.forms.get('sid', '').strip()

    SessionTable, account, uid, verfiySid = getInfoBySid(redis, sid)
    if verfiySid and sid != verfiySid:
        return {'code': -4, 'msg': '账号已在其他地方登录', 'osid': sid}
    userTable = getUserByAccount(redis, account)

    if not redis.exists(SessionTable):
        return {'code': -3, 'msg': 'sid 超时'}

    if not redis.exists(userTable):
        return {'code': -5, 'msg': '该用户不存在'}
    picUrl, gender, groupId, isVolntExitGroup, maxScore, baseScore = \
        redis.hmget(userTable, ('headImgUrl', 'sex', 'parentAg', 'isVolntExitGroup', 'maxScore', 'baseScore'))
    if not groupId:
        return {'code': -7, 'msg': '您已被移出公会,请重新加入公会'}

    res = do_PlayerWelfareSign(redis, account)

    if not res:
        return {'code': 1, 'msg': "今日已签到"}
    else:
        return {'code': 0, 'msg': "签到成功,获得 {0} 金币".format(res)}
Exemple #3
0
def do_NotJoinGoldRoom(redis, session):
    """
        取消加入金币场
    """
    sid = request.forms.get('sid', '').strip()
    SessionTable, account, uid, verfiySid = getInfoBySid(redis, sid)

    try:
        print '[on notJoinPartyRoom]sid[%s] account[%s]' % (sid, account)
    except Exception as e:
        print 'print error File', e

    if verfiySid and sid != verfiySid:
        return {'code': -4, 'msg': '账号已在其他地方登录', 'osid': sid}
    if not redis.exists(SessionTable):
        return {'code': -3, 'msg': 'sid 超时'}
    userTable = getUserByAccount(redis, account)
    if not redis.exists(userTable):
        return {'code': -5, 'msg': '该用户不存在'}
    return {'code': 0}
Exemple #4
0
def onGetRank(redis, session):
    """
        获取排行榜数据
    """
    sid = request.GET.get('sid', '').strip()
    SessionTable, account, uid, verfiySid = getInfoBySid(redis, sid)
    if verfiySid and sid != verfiySid:
        return {'code': -4, 'msg': '账号已在其他地方登录', 'osid': sid}
    userTable = getUserByAccount(redis, account)

    if not redis.exists(SessionTable):
        return {'code': -3, 'msg': 'sid 超时'}

    if not redis.exists(userTable):
        return {'code': -5, 'msg': '该用户不存在'}
    picUrl, gender, groupId, isVolntExitGroup, maxScore, baseScore = \
        redis.hmget(userTable, ('headImgUrl', 'sex', 'parentAg', 'isVolntExitGroup', 'maxScore', 'baseScore'))
    if not groupId:
        return {'code': -7, 'msg': '您已被移出公会,请重新加入公会'}
    data = get_gold_rank(redis, groupId, account)
    return {'code': 0, 'data': data}
def xiaoxiaole_setting(redis, session):
    uid = request.GET.get('uid', '').strip()
    sid = request.GET.get('sid', '').strip()
    if not uid:
        if not sid:
            return {'code': -5, 'msg': '该用户不存在'}
        SessionTable, account, uid, verfiySid = getInfoBySid(redis, sid)
        userTable = getUserByAccount(redis, account)
        uid = userTable.split(':')[-1]
    else:
        userTable = 'users:%s' % (uid)
    if not redis.exists(userTable):
        return {'code': -5, 'msg': '该用户不存在'}
    gold = int(redis.hget('users:%s' % (uid), 'gold') or 0)

    oddsTable = getXxlOdds(redis)
    return {
        'code': 0,
        'gameinfo': oddsTable,
        'max': int(gold / Proportion),
        'money': 'gold'
    }
Exemple #6
0
def do_JoinGoldRoom(redis, session):
    """
        加入金币场
    """
    log_debug('do_joinGoldRoom  *********** ')
    gameid = request.forms.get('gameid', '').strip()
    playid = request.forms.get('id', '').strip()
    sid = request.forms.get('sid', '').strip()
    need = request.forms.get('need', '').strip()  # 参与条件
    cost = request.forms.get('cost', '').strip()  # 报名费
    cost = int(cost)
    base_score = request.forms.get('baseScore', '').strip()  # 底分
    base_score = int(base_score)

    SessionTable, account, uid, verfiySid = getInfoBySid(redis, sid)

    if verfiySid and sid != verfiySid:
        return {'code': -4, 'msg': '账号已在其他地方登录', 'osid': sid}
    if not redis.exists(SessionTable):
        return {'code': -3, 'msg': 'sid 超时'}
    userTable = getUserByAccount(redis, account)
    if not redis.exists(userTable):
        return {'code': -5, 'msg': '该用户不存在'}

    groupId = redis.hget(userTable, 'parentAg')
    if not groupId:
        return {'code': -7, 'msg': '您已被移出公会,请重新加入公会'}

    gameTable = GAME_TABLE % gameid
    if not redis.exists(gameTable):
        return {'code': -1, 'msg': 'gameId 不存在'}

    serverList = redis.lrange(FORMAT_GAME_SERVICE_SET % gameid, 0, -1)
    if not serverList:
        return {'code': -1, 'msg': '服务器忙碌或维护中'}

    myroom_key = redis.get(GOLD_ROOM_ACCOUNT_KEY % account)
    if myroom_key:
        roomid, myplayid = redis.hmget(myroom_key, 'roomid', 'playid')
        ip, port, _gameid = redis.hmget(ROOM2SERVER % roomid,
                                        ('ip', 'port', 'gameid'))
        if ip and port and _gameid:
            if playid != myplayid or _gameid != gameid:
                return {'code': -1, 'msg': '您正在别的场次游戏中'}
            else:
                return {'code': 0, 'msg': '已经在金币场中'}
        else:
            redis.delete(GOLD_ROOM_ACCOUNT_KEY % account)

    coin = redis.hget(FORMAT_USER_TABLE % userTable.split(':')[1], 'gold')
    if not coin:
        coin = 0
    coin = int(coin)
    need = need.split(',')
    min_need = need[0]
    if not min_need:
        min_need = 0
    min_need = int(min_need)
    if len(need) == 1:
        max_need = 9999999999
    else:
        max_need = need[1]
    max_need = int(max_need)
    if coin < min_need:
        return {'code': -2, 'msg': u'您携带的金币数不足以进入本场次游戏,请充值后进入。'}
    if coin > max_need:
        return {'code': -1, 'msg': u'您携带的金币数超出本场次上限,请进入更高一级的场次游戏。'}

    _uuid = get_uuid()
    sendProtocol2GameService(
        redis, gameid, "joinGoldRoom|%s|%s|%s" % (account, playid, _uuid))
    redis.hmset(GOLD_ACCOUNT_WAIT_JOIN_TABLE % account, {
        'playid': playid,
        'gameid': gameid
    })
    redis.expire(GOLD_ACCOUNT_WAIT_JOIN_TABLE % account, 5)
    return {'code': 0, 'msg': '加入金币场成功'}
def xiaoxiaole_run(redis, session):
    uid = request.GET.get('uid', '').strip()
    sid = request.GET.get('sid', '').strip()
    Rtype = request.GET.get('Rtype', '').strip()
    try:
        Rtype = int(Rtype)
    except:
        Rtype = 0

    if not uid:
        if not sid:
            return {'code': -5, 'msg': '该用户不存在'}
        SessionTable, account, uid, verfiySid = getInfoBySid(redis, sid)
        userTable = getUserByAccount(redis, account)
        uid = userTable.split(':')[-1]
    else:
        userTable = 'users:%s' % (uid)
        account = redis.hget(userTable, 'account')
    if not redis.exists(userTable):
        return {'code': -5, 'msg': '该用户不存在'}
    bets = ast.literal_eval(request.GET.get('bets', '{}').strip())
    print '/xiaoxiaole/run', uid, bets
    try:
        bets = urllib.unquote(bets)
    except:
        pass
        # traceback.print_exc()

    if not isinstance(bets, dict):
        return {'code': -1, 'msg': u'参数错误'}

    nickname, gold = redis.hmget(userTable, ('nickname', 'coin'))
    print u'开始金币', gold

    totalPayGold = sum(bets.values())
    print u'总下注', totalPayGold

    if not gold or int(totalPayGold) > int(gold):
        return {'code': -1, 'msg': u'金币不足'}

    if not redis.exists(XXL_OODS_DEFAULT):
        return {'code': -1, 'msg': u'配置错误'}

    isMore100 = False
    moneyType = GOLD
    for _bet in bets.values():
        if _bet / 100 >= 1:
            isMore100 = True
            break

    if isMore100:
        moneyType = getMoneyType(redis, account, uid, totalPayGold)

    if moneyType == GOLD:
        Rtype = KIND_CHANCE
    else:
        Rtype = KIND_MATHS

    # Rtype = KIND_MATHS

    if Rtype == KIND_RANDOM:
        Mgr = xiaoxiaoleMgr(kind=KIND_RANDOM)
    elif Rtype == KIND_CHANCE:
        changeTableType = getXxlChangeTableType(redis)
        print '概率表%s' % (changeTableType)
        changeTable = getXxlChanceTable(redis, changeTableType)
        result, changeTable = dict_to_int_int(changeTable)
        Mgr = xiaoxiaoleMgr(kind=KIND_CHANCE, chance_table=changeTable)
    elif Rtype == KIND_MATHS:
        mathsDict_type_len = {5: 3, 4: 4, 3: 4, 2: 5, 1: 5}

        mathsList_type_len = []

        for _num in xrange(1, TYPECount + 1):
            if _num in bets.keys() or str(_num) in bets.keys():
                if bets[_num] / 100 >= 1:
                    mathsList_type_len.append((_num, mathsDict_type_len[_num]))
            else:
                for x in xrange(random.randint(0, 2)):
                    _tmp_num = random.choice([0, 3, 4, 5])
                    if _tmp_num >= 3:
                        mathsList_type_len.append((_num, _tmp_num))
        Rprint('mathsList_type_len:%s' % mathsList_type_len)
        Mgr = xiaoxiaoleMgr(kind=KIND_MATHS,
                            mathsList_type_len=mathsList_type_len)
    else:
        return {'code': -1, 'msg': u'参数错误'}

    results = Mgr.run()

    oddsTable = getXxlOdds(redis)

    datas = []
    winScore = 0
    for _result in results:
        numtype = int(_result["type"])
        numlen = int(_result["len"])
        rep = {
            'len': numlen,
            'coordinates': _result["coordinates"],
            'type': numtype,
        }
        if moneyType == GOLD:
            rep['score'] = (bets.get(numtype, 0) or bets.get(
                str(numtype), 0)) * getOdds(oddsTable, numtype, numlen)
        else:
            rep['score'] = (bets.get(numtype, 0) or bets.get(
                str(numtype), 0)) / 100 * getOdds(oddsTable, numtype, numlen)

        rep["score"] = int(rep["score"])
        winScore += rep["score"]
        # print rep
        datas.append(rep)
    matrix = Mgr.getCanvas().tolist()

    redis.hincrby(userTable, 'coin', -totalPayGold)
    print u'扣除金币', totalPayGold

    record_player_balance_change(bag_redis,
                                 userTable,
                                 2,
                                 -totalPayGold,
                                 redis.hget(userTable, 'coin'),
                                 9,
                                 game_id='xxl')

    redis.hincrby(userTable, moneyType, winScore)
    gold, honor = redis.hmget(userTable, 'coin', 'honor')
    if not honor:
        honor = 0
    if not gold:
        gold = 0

    if moneyType == HONOR:
        record_player_balance_change(bag_redis,
                                     userTable,
                                     16,
                                     winScore,
                                     honor,
                                     9,
                                     game_id='xxl')
    else:
        record_player_balance_change(bag_redis,
                                     userTable,
                                     2,
                                     winScore,
                                     gold,
                                     9,
                                     game_id='xxl')

    print u'增加%s=>%s个' % (moneyType, winScore)
    # print datas
    print u'剩余金币', gold
    print u'剩余荣誉', honor
    try:
        saveXxlRecord(redis,
                      get_gold=totalPayGold,
                      put_gold=winScore,
                      money=moneyType,
                      uid=uid)
    except:
        traceback.print_exc()
    if moneyType == HONOR:
        saveXxlHonorTrade(redis, uid=uid, winHonor=winScore)
    #游玩次数统计
    saveXxlPlayRecord(redis, uid, moneyType=moneyType)

    # 默认加金币
    gold = redis.hincrby('users:%s' % uid, 'coin', winScore)

    return {
        'code': 0,
        'msg': u'成功',
        'winScore': winScore,
        'money': (1 if moneyType == 'honor' else 0),
        'matrix': matrix,
        'datas': datas,
        'gold_coin': gold,
        'honor_coin': honor
    }