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)
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)
def gm_reward_chip(self, gid, mi, request): uid = mi.get_param('userId') if not Context.UserAttr.check_exist(uid, gid): return MsgPack.Error(0, 1, 'not exist') chip = mi.get_param('chip') real, final = Context.UserAttr.incr_chip(uid, gid, chip, 'gm.reward') if real != chip: MsgPack.Error(0, 1, 'not enough') return MsgPack(0, {'chip': final, 'delta': real})
def gm_exchange_phone(self, gid, mi, request): uid = mi.get_param('userId') seq = mi.get_param('seq') state = Context.RedisCluster.hash_get_int(uid, 'history:%d:%d' % (gid, uid), seq) if state is None: return MsgPack.Error(0, 1, 'error seq') if state == 1: return MsgPack.Error(0, 2, 'already exchange') Context.RedisCluster.hash_set(uid, 'history:%d:%d' % (gid, uid), seq, 1) return MsgPack(0)
def gm_reward_diamond(self, gid, mi, request): uid = mi.get_param('userId') if not Context.UserAttr.check_exist(uid, gid): return MsgPack.Error(0, 1, 'not exist') diamond = mi.get_param('diamond') real, final = Context.UserAttr.incr_diamond(uid, gid, diamond, 'gm.reward') if real != diamond: MsgPack.Error(0, 1, 'not enough') return MsgPack(0, {'diamond': final, 'delta': real})
def gm_account_block(self, gid, mi, request): uid = mi.get_param('userId') odds = mi.get_param('odds') if odds is None: Context.Data.del_game_attrs(uid, gid, 'block') else: if not Context.UserAttr.check_exist(uid, gid): return MsgPack.Error(0, 1, 'not exist') if odds <= 0 or odds > 1: return MsgPack.Error(0, 2, 'odds limit (0, 1]') Context.Data.set_game_attr(uid, gid, 'block', odds) return MsgPack(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)
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
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)
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})
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})
def gm_reward_egg(self, gid, mi, request): uid = mi.get_param('userId') _id = mi.get_param('id') _count = mi.get_param('count') if _id not in (201, 202, 203, 204, 205, 211, 212, 213, 214, 215, 216, 217, 218, 219): return MsgPack.Error(0, 1, 'error id') if not Context.UserAttr.check_exist(uid, gid): return MsgPack.Error(0, 3, 'user not exist') real, final = FishProps.incr_props(uid, gid, _id, _count, 'gm.reward') mo = MsgPack(0) mo.set_param('delta', real) mo.set_param('id', _id) mo.set_param('count', final) return mo
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)
def product_deliver(self, gid, mi, request): userId = mi.get_param('userId') orderId = mi.get_param('orderId') productId = mi.get_param('productId') appKey = Context.Configure.get_game_item(gid, 'appKey', '') data = '%s-%s-%s' % (orderId, appKey, productId) sign = Algorithm.md5_encode(data) if sign != mi.get_param('sign'): return MsgPack.Error(0, 1, 'error sign') from lemon import classMap entity = classMap.get(gid, {}).get('entity') if not entity: Context.Log.error('game %d have no processor for order' % gid) return MsgPack.Error(0, 2, 'no processor') return entity.on_product_deliver(userId, gid, mi)
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)
def disable_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') disable = mi.get_param('disable') if disable: Context.RedisMix.set_add('game.%d.disable.user' % gid, uid) else: Context.RedisMix.set_rem('game.%d.disable.user' % gid, uid) return MsgPack(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
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)
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)
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
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)
def on_product_deliver(self, uid, gid, mi): orderId = mi.get_param('orderId') productId = mi.get_param('productId') payType = mi.get_param('payType') channel = mi.get_param('channel') cost = mi.get_param('cost') param = { 'orderId': orderId, 'productId': productId, 'payType': payType, 'channel': channel, 'cost': cost } Context.Log.report('product.issue: [%d, %d, %s, %s]' % (uid, gid, orderId, param)) all_product = Context.Configure.get_game_item_json( gid, 'product.config') if productId not in all_product: Context.Log.error('productId not exist', orderId, productId, all_product) return MsgPack.Error(0, 1, 'no product found') shop_config = Context.Configure.get_game_item_json(gid, 'shop.config') pipe_args = ['product_%s' % productId, 1] times = Context.Data.hincr_game(uid, gid, 'product_%s' % productId, 1) # 记录充值相关字段 pay_total = FishProps.incr_pay(uid, gid, cost, 'buy.product', orderId=orderId) today_pay_times, _ = Context.Daily.mincr_daily_data( uid, gid, 'pay_times', 1, 'pay_total', cost) is_reset_chance, is_first_double = False, False if productId in shop_config['chip']: if times == 1: is_first_double = True else: reset_choice = Context.Data.get_game_attr_int( uid, gid, 'reset_' + str(productId), 0) if reset_choice: is_reset_chance = True product = all_product[productId] if is_reset_chance: # reset chance reward = self.__rebate_reward(gid, pay_total, product['first'], channel) FishProps.issue_rewards(uid, gid, reward, 'buy.product', orderId=orderId, reset=1) Context.Data.del_game_attrs(uid, gid, 'reset_' + str(productId)) elif is_first_double: reward = self.__rebate_reward(gid, pay_total, product['first'], channel) FishProps.issue_rewards(uid, gid, reward, 'buy.product', orderId=orderId, first=1) elif productId in shop_config['card']: state, days = FishProps.incr_vip(uid, gid, 30, 'buy.product', orderId=orderId) if state == 0: # 今日未领取 sign_in = Context.Daily.get_daily_data(uid, gid, 'sign_in') if sign_in: success, left_days = FishProps.use_vip(uid, gid) if success: conf = Context.Configure.get_game_item_json( gid, 'month.card.reward') FishProps.issue_rewards(uid, gid, conf, 'month.card.reward') else: reward = self.__rebate_reward(gid, pay_total, product['content'], channel) FishProps.issue_rewards(uid, gid, reward, 'buy.product', orderId=orderId) if today_pay_times == 1: # today first pay pipe_args.append(channel + '.pay.user.count') pipe_args.append(1) pipe_args.append(channel + '.pay.user.pay_total') pipe_args.append(cost) pipe_args.append(channel + '.user.pay.times') pipe_args.append(1) if pay_total == cost: # life first pay pipe_args.append(channel + '.new.pay.user.count') pipe_args.append(1) pipe_args.append('new_pay_user') pipe_args.append(1) new_pay_user = 1 else: new_pay_user = Context.Daily.get_daily_data( uid, gid, 'new_pay_user') if new_pay_user: pipe_args.append(channel + '.new.pay.user.pay_total') pipe_args.append(cost) Context.Stat.mincr_daily_data(gid, *pipe_args) key = 'game.%d.info.hash' % gid pipe_args = [] if pay_total == cost: pipe_args.append(channel + '.pay.user.count') pipe_args.append(1) pipe_args.append(channel + '.pay.user.pay_total') pipe_args.append(cost) pipe_args.append(channel + '.user.pay.times') pipe_args.append(1) Context.RedisMix.hash_mincrby(key, *pipe_args) self.__handle_pay_effect(uid, gid, cost, today_pay_times) return MsgPack(0, {'msg': u'已到货'})
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)
class User(object): error_invalid_username = 1 error_invalid_passwd = 2 error_invalid_access_token = 3 error_user_not_exist = 4 error_pwd_not_right = 5 error_version_too_low = 6 desc_invalid_username = "******" desc_invalid_passwd = "param invalid" desc_invalid_access_token = "param invalid" desc_user_not_exist = "user not exists" desc_pwd_not_right = "password not right" desc_version_too_low = "version too low" @classmethod def getParam(cls, mi, *args): param = { 'cmd': mi.get_cmd(), 'gameId': mi.get_param('gameId'), 'deviceId': mi.get_param('deviceId', ''), 'deviceId2': mi.get_param('deviceId2', ''), 'mac': mi.get_param('mac', ''), 'imei': mi.get_param('imei', ''), 'imsi': mi.get_param('imsi', ''), 'ip': mi.get_param('ip', ''), 'model': mi.get_param('model', ''), 'releaseVer': mi.get_param('releaseVer', ''), 'location': mi.get_param('location', ''), 'phoneType': mi.get_param('phoneType', ''), 'resolution': mi.get_param('resolution', ''), 'versionName': mi.get_param('versionName', ''), 'umengToken': mi.get_param('umengToken', ''), 'networkType': mi.get_param('networkType', ''), 'channel': mi.get_param('channel', 'jiyu'), 'platform': mi.get_param('platform', 'platform'), 'clientId': mi.get_param('clientId', 'JYBY001'), } for arg in args: param[arg] = mi.get_param(arg, '') return param @classmethod 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:'******'mobile', 'passwd') if not Entity.checkMobile(param['mobile']): 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_MOBILE userId = Account.getUserIDByUserName(param['mobile'], 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['mobile'], 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) 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) 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) if 'uid' not in decoded: return MsgPack.Error(0, self.error_invalid_access_token, self.desc_invalid_access_token) userId = decoded['uid'] token = Context.Data.get_attr(userId, 'accessToken') if token != param['accessToken']: return MsgPack.Error(0, self.error_invalid_access_token, self.desc_invalid_access_token) userInfo = Account.getUserInfo(userId) if not userInfo['userName']: return MsgPack.Error(0, self.error_user_not_exist, self.desc_user_not_exist) if param['clientId']: clientId = param['clientId'] c_key = 'client:%s' % (clientId) Context.RedisMix.set_add(c_key, userId) return self.getLoginInfo(request, 0, userId, param['gameId'], param, userInfo, False)