Exemple #1
0
    def updateUserInfo(self, mi, request):
        nick = mi.get_param('nick')
        avatar = mi.get_param('avatar')
        if not Entity.logined(request):
            return MsgPack.Error(0, Const.E_NOT_LOGIN, Const.ES_NOT_LOGIN)

        uid = request.getSession().userId
        kvs = {}
        if nick:
            if not Entity.checkNick(nick):
                return MsgPack.Error(0, 1, 'param nick invalid')
            if Context.KeywordFilter.isContains(nick):
                return MsgPack.Error(0, 2, 'key word filter')
            kvs['nick'] = nick

        if avatar:
            if avatar in Const.AVATAR_MAN:
                kvs['avatar'] = avatar
                kvs['sex'] = Const.SEX_MAN
            elif avatar in Const.AVATAR_WOMAN:
                kvs['avatar'] = avatar
                kvs['sex'] = Const.SEX_WOMAN
            else:
                return MsgPack.Error(0, 3, 'param avatar invalid')

        if kvs:
            Account.updateUserInfo(uid, **kvs)

        return MsgPack(0, kvs)
Exemple #2
0
    def loginByUserName(self, mi, request):
        param = self.getParam(mi, 'userName', 'passwd')
        if not Entity.checkUserName(param['userName']):
            return MsgPack.Error(0, self.error_invalid_username,
                                 self.desc_invalid_username)
        if not Entity.checkPassword(param['passwd']):
            return MsgPack.Error(0, self.error_invalid_passwd,
                                 self.desc_invalid_passwd)

        idType = Const.IDTYPE_USERNAME
        userId = Account.getUserIDByUserName(param['userName'], idType)
        if not userId:
            return MsgPack.Error(0, self.error_user_not_exist,
                                 self.desc_user_not_exist)

        userInfo = Account.getUserInfo(userId)
        if not userInfo['userName']:
            return MsgPack.Error(0, self.error_user_not_exist,
                                 self.desc_user_not_exist)

        # 进行密码比较
        strMd5Pass = Entity.encodePassword(param['userName'], param['passwd'])
        if strMd5Pass != userInfo['token']:
            return MsgPack.Error(0, self.error_pwd_not_right,
                                 self.desc_pwd_not_right)

        return self.getLoginInfo(request, 0, userId, param['gameId'], param,
                                 userInfo, True)
Exemple #3
0
    def registerByMobile(self, mi, request):
        gid = mi.get_param('gameId')
        mobile = mi.get_param('mobile', '')
        passwd = mi.get_param('passwd', '')
        deviceId = mi.get_param('deviceId', '')
        nick = mi.get_param('nick', '')
        verifyCode = mi.get_param('verifyCode', '')
        platform = mi.get_param('platform', 'android')
        channel = mi.get_param('channel', 'jiyu')
        if not Entity.checkMobile(mobile):
            return MsgPack.Error(0, 1, 'param mobile invalid')
        if not Entity.checkPassword(passwd):
            return MsgPack.Error(0, 2, 'param passwd invalid')
        if not Entity.checkNick(nick):
            return MsgPack.Error(0, 3, 'param nick invalid')

        # 先查表,判断用户存不存在
        idType = Const.IDTYPE_MOBILE
        userId = Account.getUserIDByUserName(mobile, idType)
        if userId:
            return MsgPack.Error(0, 4, 'mobile exist')

        if not Mobile.checkVerifyCode(gid, mobile, verifyCode):
            return MsgPack.Error(0, 5, 'verifycode not right')

        # nick 唯一
        nick_unique_key = 'game.%d.unique.nick' % gid
        if not Context.RedisMix.hash_setnx(nick_unique_key, nick, 0):
            return MsgPack.Error(0, 6, 'nick not unique')

        # 插入用户数据
        strMd5Pass = Entity.encodePassword(mobile, passwd)
        dictInfo = {
            'idType': idType,
            'deviceId': deviceId,
            'userName': mobile,
            'nick': nick,
            'createIp': request.getClientIP(),
            'token': strMd5Pass,
            'guest': 0,
            'channel': channel,
            'platform': platform
        }
        userId = Account.createUser(dictInfo)
        if not userId:
            Context.RedisMix.hash_del(nick_unique_key, nick)
            return MsgPack.Error(0, Const.E_BAD_REDIS, Const.ES_BAD_REDIS)

        Context.RedisMix.hash_set(nick_unique_key, nick, userId)
        key, field = 'game.%d.info.hash' % gid, '%s.new.user.count' % channel
        Context.RedisMix.hash_incrby(key, field, 1)
        Context.Stat.incr_daily_data(gid, field, 1)

        return MsgPack(0)
Exemple #4
0
    def upgradeByMobile(self, mi, request):
        gid = mi.get_param('gameId')
        nick = mi.get_param('nick', '')
        mobile = mi.get_param('mobile', '')
        passwd = mi.get_param('passwd', '')
        verifyCode = mi.get_param('verifyCode', '')

        if not Entity.logined(request):
            return MsgPack.Error(0, Const.E_NOT_LOGIN, Const.ES_NOT_LOGIN)

        if not Entity.checkMobile(mobile):
            return MsgPack.Error(0, 1, 'mobile invalid')

        if not Entity.checkPassword(passwd):
            return MsgPack.Error(0, 2, 'password invalid')

        if not Entity.checkNick(nick):
            return MsgPack.Error(0, 6, 'nick invalid')

        userId = request.getSession().userId
        # 先判断是不是游客
        userInfo = Account.getUserInfo(userId)
        if int(userInfo['idType']) != Const.IDTYPE_GUEST:
            return MsgPack.Error(0, 3, 'not guest')

        # 先查表,判断用户存不存在
        if Account.getUserIDByUserName(mobile, Const.IDTYPE_MOBILE):
            return MsgPack.Error(0, 4, 'mobile exist')

        if not Mobile.checkVerifyCode(gid, mobile, verifyCode):
            return MsgPack.Error(0, 5, 'verifycode not right')

        # nick 唯一
        if not Context.RedisMix.hash_setnx('game.%d.unique.nick' % gid, nick,
                                           0):
            return MsgPack.Error(0, 7, 'nick not unique')

        if not Account.createUserName(Const.IDTYPE_MOBILE, mobile, userId):
            Context.RedisMix.hash_del('game.%d.unique.nick' % gid, nick)
            return MsgPack.Error(0, Const.E_BAD_REDIS, Const.ES_BAD_REDIS)

        if not Account.deleteUserName(userInfo['userName'],
                                      Const.IDTYPE_GUEST):
            Context.Log.error(userId, 'DeleteUserName failed,userName:'******'userName'])

        Context.RedisMix.hash_set('game.%d.unique.nick' % gid, nick, userId)
        Account.updateUserInfo(userId,
                               userName=mobile,
                               nick=nick,
                               idType=Const.IDTYPE_MOBILE,
                               token=Entity.encodePassword(mobile, passwd))
        return MsgPack(0)
Exemple #5
0
    def registerByUserName(self, mi, request):
        gid = mi.get_param('gameId')
        username = mi.get_param('userName', '')
        passwd = mi.get_param('passwd', '')
        deviceId = mi.get_param('deviceId', '')
        platform = mi.get_param('platform', 'android')
        channel = mi.get_param('channel', 'jiyu')
        if not Entity.checkUserName(username):
            return MsgPack.Error(0, 1, 'username invalid')
        if not Entity.checkPassword(passwd):
            return MsgPack.Error(0, 2, 'password invalid')

        nick = username
        if Context.KeywordFilter.isContains(nick):
            return MsgPack.Error(0, 3, 'keyword filter')

        # 先查表,判断用户存不存在
        idType = Const.IDTYPE_USERNAME
        userId = Account.getUserIDByUserName(username, idType)
        if userId:
            return MsgPack.Error(0, 5, 'username exist')

        # nick 唯一
        nick_unique_key = 'game.%d.unique.nick' % gid
        if not Context.RedisMix.hash_setnx(nick_unique_key, nick, 0):
            return MsgPack.Error(0, 6, 'nick not unique')

        # 插入用户数据
        strMd5Pass = Entity.encodePassword(username, passwd)
        dictInfo = {
            'idType': idType,
            'deviceId': deviceId,
            'userName': username,
            'nick': nick,
            'createIp': request.getClientIP(),
            'token': strMd5Pass,
            'guest': 0,
            'channel': channel,
            'platform': platform
        }
        userId = Account.createUser(dictInfo)
        if not userId:
            Context.RedisMix.hash_del(nick_unique_key, nick)
            return MsgPack.Error(0, Const.E_BAD_REDIS, Const.ES_BAD_REDIS)

        Context.RedisMix.hash_set(nick_unique_key, nick, userId)
        key, field = 'game.%d.info.hash' % gid, '%s.new.user.count' % channel
        Context.RedisMix.hash_incrby(key, field, 1)
        Context.Stat.incr_daily_data(gid, field, 1)

        return MsgPack(0)
Exemple #6
0
    def upgradeByUserName(self, mi, request):
        gid = mi.get_param('gameId')
        username = mi.get_param('userName', '')
        passwd = mi.get_param('passwd', '')

        if not Entity.logined(request):
            return MsgPack.Error(0, Const.E_NOT_LOGIN, Const.ES_NOT_LOGIN)

        if not Entity.checkUserName(username):
            return MsgPack.Error(0, 1, 'username invalid')

        if not Entity.checkPassword(passwd):
            return MsgPack.Error(0, 2, 'password invalid')

        nick = username
        if Context.KeywordFilter.isContains(nick):
            return MsgPack.Error(0, 3, 'keyword filter')

        userId = request.getSession().userId
        # 先判断是不是游客
        userInfo = Account.getUserInfo(userId)
        if int(userInfo['idType']) != Const.IDTYPE_GUEST:
            return MsgPack.Error(0, 4, 'not guest')

        # 先查表,判断用户存不存在
        if Account.getUserIDByUserName(username, Const.IDTYPE_USERNAME):
            return MsgPack.Error(0, 5, 'username exist')

        # nick 唯一
        if not Context.RedisMix.hash_setnx('game.%d.unique.nick' % gid,
                                           username, 0):
            return MsgPack.Error(0, 6, 'nick not unique')

        if not Account.createUserName(Const.IDTYPE_USERNAME, username, userId):
            Context.RedisMix.hash_del('game.%d.unique.nick' % gid, username)
            return MsgPack.Error(0, Const.E_BAD_REDIS, Const.ES_BAD_REDIS)

        if not Account.deleteUserName(userInfo['userName'],
                                      Const.IDTYPE_GUEST):
            Context.Log.error(userId, 'DeleteUserName failed,userName:'******'userName'])

        Context.RedisMix.hash_set('game.%d.unique.nick' % gid, username,
                                  userId)
        Account.updateUserInfo(userId,
                               userName=username,
                               nick=nick,
                               idType=Const.IDTYPE_USERNAME,
                               token=Entity.encodePassword(username, passwd))
        return MsgPack(0)
Exemple #7
0
    def deliverOrder(self, mi, request):
        gid = mi.get_param('gameId')
        order_list = mi.get_param('orders')
        if not Entity.logined(request):
            return MsgPack.Error(0, Const.E_NOT_LOGIN, Const.ES_NOT_LOGIN)

        uid = request.getSession().userId
        orders = []
        for orderId in order_list:
            orderInfo = self.getOrderInfo(orderId)
            if not orderInfo:
                continue

            userId = int(orderInfo['userId'])
            gameId = int(orderInfo['gameId'])
            state = int(orderInfo['state'])
            if userId != uid:
                Context.Log.warn('userId not match', userId, uid, orderId)
                continue

            if gameId != gid:
                Context.Log.warn('gameId not match', gameId, gid, orderId)
                continue

            if state == self.state_create:
                create_ts = Time.str_to_timestamp(orderInfo['createTime'],
                                                  '%Y-%m-%d %X.%f')
                now_ts = Time.current_ts()
                if now_ts - create_ts > 3600:
                    state = self.state_timeout
            orders.append({'id': orderId, 'state': state})
        return MsgPack(0, {'orders': orders})
Exemple #8
0
    def getLoginInfo(cls,
                     request,
                     cmd,
                     uid,
                     gid,
                     param,
                     userInfo,
                     freshAccessToken,
                     openid=None,
                     open_token=None):
        session = Algorithm.md5_encode(Time.asctime() + request.getClientIP() +
                                       userInfo['userName'])
        Account.setUserToken(uid, gid, session)

        conn_server = Context.json_loads(
            Context.RedisCache.get('connect.server'))
        internet = conn_server[uid % len(conn_server)]

        dictInfo = {
            "session": session,
            "userId": uid,
            "sex": int(userInfo['sex']),
            "nick": userInfo['nick'],
            "avatar": userInfo['avatar'],
            "host": internet["domain"],
            "port": internet["port"],
        }

        if openid:
            dictInfo['openid'] = openid
        if open_token:
            dictInfo['open_token'] = open_token

        if freshAccessToken:
            data = '{"uid":%d,"ct":%d}' % (uid, Time.current_ts())
            accessToken = Entity.encrypt(data)
            Account.updateUserInfo(uid, accessToken=accessToken)
            dictInfo['accessToken'] = accessToken

        kvs = {
            'session_platform': param['platform'] or 'android',
            'session_channel': param['channel'] or 'jiyu',
            'session_ver': param['releaseVer'] or '1.0.1'
        }
        Context.Data.set_game_attrs_dict(uid, gid, kvs)

        Context.Log.report('user.login:', [uid, gid, kvs])

        # 登录成功设置session值
        session = request.getSession()
        session.setLogined(uid)

        return MsgPack(cmd, dictInfo)
Exemple #9
0
    def loginByAccessToken(self, mi, request):
        param = self.getParam(mi, 'accessToken')

        if len(param['accessToken']) <= 1:
            return MsgPack.Error(0, self.error_invalid_access_token,
                                 self.desc_invalid_access_token)

        try:
            decrptData = Entity.decrypt(param['accessToken'])
            decoded = Context.json_loads(decrptData)
        except Exception, e:
            return MsgPack.Error(0, self.error_invalid_access_token,
                                 self.desc_invalid_access_token)
Exemple #10
0
    def resetPasswd(self, mi, request):
        gid = mi.get_param('gameId')
        mobile = mi.get_param('mobile', '')
        verifyCode = mi.get_param('verifyCode', '')
        passwd = mi.get_param('passwd', '')
        if not Mobile.checkVerifyCode(gid, mobile, verifyCode):
            return MsgPack.Error(0, 1, 'verifycode not right')

        idType = Const.IDTYPE_MOBILE
        userId = Account.getUserIDByUserName(mobile, idType)
        if not userId:
            return MsgPack.Error(0, 2, 'user not exist')

        Account.updateUserInfo(userId,
                               token=Entity.encodePassword(mobile, passwd))
        return MsgPack(0, {'newPwd': passwd})
Exemple #11
0
    def getVerifyCode(self, mi, request):
        gid = mi.get_param('gameId')
        mobile = mi.get_param('mobile')
        isCheck = int(mi.get_param('isCheck', 0))
        if not Entity.checkMobile(mobile):
            return MsgPack.Error(0, 1, 'mobile invalid')

        if isCheck == 1:
            idType = Const.IDTYPE_MOBILE
            userId = Account.getUserIDByUserName(mobile, idType)
            if userId:
                return MsgPack.Error(0, 2, 'mobile exists')

        if not self.__request_verify_code(gid, mobile):
            return MsgPack.Error(0, 3, 'send failed')

        return MsgPack(0)
Exemple #12
0
    def createOrder(self, mi, request):
        gameId = mi.get_param('gameId')
        channel = mi.get_param('channel', 'jiyu')
        platform = mi.get_param('platform', 'android')
        productId = mi.get_param('productId')

        if not Entity.logined(request):
            return MsgPack.Error(0, Const.E_NOT_LOGIN, Const.ES_NOT_LOGIN)

        userId = request.getSession().userId
        code, desc = self.__create_order(userId,
                                         gameId,
                                         channel,
                                         productId,
                                         platform=platform)
        if code != 0:
            return MsgPack.Error(0, code, desc)
        return MsgPack(0, desc)