Esempio n. 1
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)
Esempio n. 2
0
    def register(self, param, request, openid, idType, channel):
        gid = param['gameId']
        l = []
        if param['deviceId']:
            l.append(param['deviceId'])
        if param['deviceId2']:
            l.append(param['deviceId2'])
        if param['mac']:
            l.append(param['mac'])
        if param['imei']:
            l.append(param['imei'])
        if param['imsi']:
            l.append(param['imsi'])

        if l:
            deviceId = l[0]
        else:
            deviceId = 'DEVID' + str(Time.current_ms())

        platform = param['platform']
        # channel = param['channel']
        nickName = param['devName']
        if param.get('nickName'):
            nickName = param.get('nickName')
        dictInfo = {
            'idType': idType,
            'deviceId': deviceId,
            'userName': openid,
            'nick': nickName,
            'createIp': request.getClientIP(),
            'token': '',
            'platform': platform,
            'channel': channel,
            'openid': openid
        }
        uid = Account.createUser(dictInfo)
        if uid is None:
            return None

        key = 'game.%d.info.hash' % gid
        pipe_args = []
        if l:
            field = '%s.new.device.count' % channel
            pipe_args.append(field)
            pipe_args.append(1)

        field = '%s.new.user.count' % channel
        pipe_args.append(field)
        pipe_args.append(1)
        Context.RedisMix.hash_mincrby(key, *pipe_args)
        Context.Stat.mincr_daily_data(gid, *pipe_args)
        return uid
Esempio n. 3
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)
Esempio n. 4
0
    def loginByGuest(self, mi, request):
        param = self.getParam(mi, 'devName')
        l = []
        if param['deviceId']:
            l.append(param['deviceId'])
        if param['deviceId2']:
            l.append(param['deviceId2'])
        if param['mac']:
            l.append(param['mac'])
        if param['imei']:
            l.append(param['imei'])
        if param['imsi']:
            l.append(param['imsi'])

        gid = param['gameId']
        idType = Const.IDTYPE_GUEST
        for dev in l:
            uid = Account.getUserIDByUserName(dev, idType)
            if uid:
                break
        else:
            if l:
                deviceId = l[0]
            else:
                deviceId = 'DEVID' + str(Time.current_ms())

            platform = param['platform']
            channel = param['channel']
            clientId = param['clientId']
            dictInfo = {
                'idType': idType,
                'deviceId': deviceId,
                'userName': deviceId,
                'nick': param['devName'],
                'createIp': request.getClientIP(),
                'token': '',
                'platform': platform,
                'channel': channel,
                'clientId': clientId
            }
            Context.Log.info("dictInfo::", dictInfo)
            uid = Account.createUser(dictInfo)
            nick_name = "游客" + str(uid)
            Account.updateUserInfo(uid, nick=nick_name)
            if uid is None:
                return MsgPack.Error(0, Const.E_BAD_REDIS, Const.ES_BAD_REDIS)

            key = 'game.%d.info.hash' % gid
            pipe_args = []
            if l:
                field = '%s.new.device.count' % channel
                pipe_args.append(field)
                pipe_args.append(1)

            field = '%s.new.user.count' % channel
            pipe_args.append(field)
            pipe_args.append(1)
            Context.RedisMix.hash_mincrby(key, *pipe_args)
            Context.Stat.mincr_daily_data(gid, *pipe_args)

        c_key = 'client:%s' % (clientId)
        Context.RedisMix.set_add(c_key)
        userInfo = Account.getUserInfo(uid)
        return self.getLoginInfo(request, 0, uid, gid, param, userInfo, True)