def _getLastGameId(userId): ''' 取得用户最后进入的gameId ''' value = daobase.executeUserCmd(userId, 'HGET', UserSessionSchema.mkey(userId), UserSessionSchema.LAST_GAME) return UserSessionSchema.checkData(UserSessionSchema.LAST_GAME, value)
def _getOnlineState(userId): ''' 取得用户的在线状态,即TCP的链接状态 ''' val = daobase.executeUserCmd(userId, 'HGET', UserSessionSchema.mkey(userId), UserSessionSchema.ONLINE_STATE) return UserSessionSchema.checkData(UserSessionSchema.ONLINE_STATE, val)
def _getSessionDataRedis(userId, dataKey): values = daobase.executeUserCmd(userId, 'HMGET', dataKey, *UserSessionSchema.FIELD_GROUP_SESSION) if values[0] == None: # 补丁, 数据上线期间, 有些用户还没有建立session数据, 重主数据中获取 values = daobase.executeUserCmd(userId, 'HMGET', UserDataSchema.mkey(userId), *UserDataSchema.FIELD_GROUP_SESSION) datas = UserSessionSchema.checkDataDict(UserSessionSchema.FIELD_GROUP_SESSION, values, None) return datas
def _setOnlineState(userId, state): ''' 设置用户的在线状态,即TCP的链接状态 用户ID将添加再online数据库的online:users集合 注意: 此方法通常由CONN服务进行调用,其他人禁止调用 ''' if state == daoconst.OFFLINE: dbplaytime._cleanalltime(userId) daobase.sendUserCmd(userId, 'DEL', UserOnlineGameSchema.mkey(userId)) daobase.sendUserCmd(userId, 'HDEL', UserSessionSchema.mkey(userId), UserSessionSchema.ONLINE_STATE) daobase.sendUserCmd(userId, 'HDEL', UserSessionSchema.mkey(userId), UserSessionSchema.LAST_GAME) else: daobase.sendUserCmd(userId, 'HSET', UserSessionSchema.mkey(userId), UserSessionSchema.ONLINE_STATE, daoconst.ONLINE) dbonline._setOnlineState(userId, state)
def _setGameLeave(userId, gameId): ''' 设置用户离开一个游戏 通常再leave_game时调用此方法 数据库中, 存储的键值为: og:<userId> ''' daobase.sendUserCmd(userId, 'HSET', UserSessionSchema.mkey(userId), UserSessionSchema.LAST_GAME, 9999) daobase.sendUserCmd(userId, 'SREM', UserOnlineGameSchema.mkey(userId), gameId)
def _setGameEnter(userId, gameId): ''' 设置用户进入一个游戏 通常再bind_game时调用此方法 数据库中, 存储的键值为: og:<userId> ''' daobase.sendUserCmd(userId, 'SADD', UserOnlineGameSchema.mkey(userId), gameId) daobase.sendUserCmd(userId, 'HSET', UserSessionSchema.mkey(userId), UserSessionSchema.LAST_GAME, gameId)
def _setSessionDatas(userId, datas): # TODO 补充user表中的几个数据至用户的session中sessionAppId, sessionDevId,city_code atts = [ UserDataSchema.SESSION_APPID, UserDataSchema.SESSION_DEVID, UserDataSchema.SESSION_CITY_CODE, UserDataSchema.SESSION_IP ] values = daobase.executeUserCmd(userId, 'HMGET', UserDataSchema.mkey(userId), *atts) values = UserDataSchema.checkDataList(atts, values, None) if not UserSessionSchema.APPID in datas: datas[UserSessionSchema.APPID] = values[0] if not UserSessionSchema.DEVICEID in datas: datas[UserSessionSchema.DEVICEID] = values[1] if not UserSessionSchema.CITYCODE in datas: datas[UserSessionSchema.CITYCODE] = values[2] datas[UserSessionSchema.IPADDRESS] = values[ 3] # TODO 加了阿里云代理后,CO服务的带的IP都是阿里的IP地址,只能在重SDK的数据中再取一次 dataKey = UserSessionSchema.mkey(userId) params = UserSessionSchema.paramsDict2List(datas) ret = daobase.sendUserCmd(userId, 'HMSET', dataKey, *params) return ret
def _setSessionDatas(userId, datas): ret = _dbuser._setSessionDatas(userId, datas) if _CACHE_USER_ENABLE: dataKey = UserSessionSchema.mkey(userId) _cacheSession.update_group_dict_data(userId, dataKey, datas) return ret
def _getSessionDatas(userId): dataKey = UserSessionSchema.mkey(userId) if _CACHE_USER_ENABLE: return _cacheSession(userId, dataKey) else: return _getSessionDataRedis(userId, dataKey)
def _getSessionDatas(userId): dataKey = UserSessionSchema.mkey(userId) return _cacheSession(userId, dataKey)