Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
def _getGameEnterIds(userId):
    '''
    取得用户进入的游戏列表
    '''
    return daobase.executeUserCmd(userId, 'SMEMBERS',
                                  UserOnlineGameSchema.mkey(userId))