def browse(self, offset=0, limit=30): sql = ('SELECT count(id) ' 'FROM profiles WHERE deleted = 0') rows = yield self.dbController.dbRead(0, sql) total = int(rows[0][0]) sql = ('SELECT id,user_id,ordinal,name,`rank`,' 'rating,points,disconnects,updated_on,seconds_played,comment ' 'FROM profiles WHERE deleted = 0 ' 'ORDER BY name LIMIT %s OFFSET %s') rows = yield self.dbController.dbRead(0, sql, limit, offset) results = [] for row in rows: (id, userId, ordinal, name, rank, rating, points, disconnects, updatedOn, secondsPlayed, comment) = row playTime = timedelta(seconds=secondsPlayed) p = user.Profile(ordinal) p.id = id p.userId = userId p.name = name p.rank = rank p.rating = rating p.points = points p.disconnects = disconnects p.updatedOn = updatedOn p.playTime = playTime p.comment = comment results.append(p) defer.returnValue((total, results))
def createUser(self, username, serial, hash, nonce): results = yield self.userData.findByHash(hash) if nonce in [None, '']: if results: raise Exception('duplicate user hash!') usr = user.User(hash) usr.id = None usr.username = username usr.serial = serial usr.hash = hash usr.nonce = nonce usr.profiles = [] yield self.userData.store(usr) for i in range(3): profile = user.Profile(i) profile.id = -1 usr.profiles.append(profile) defer.returnValue(usr) else: # modification results = yield self.userData.findByNonce(nonce) if not results: raise Exception('User not found for nonce: %s' % nonce) usr = results[0] usr.hash = hash usr.serial = serial usr.username = username usr.nonce = None yield self.userData.store(usr) defer.returnValue(usr)
def getUser(self, hash): users = yield self.userData.findByHash(hash) if not users: raise errors.UnknownUserError('Unknown user: %s' % hash) profiles = yield self.profileData.getByUserId(users[0].id) users[0].profiles = [None, None, None] for profile in profiles: users[0].profiles[profile.index] = profile for i in range(3): if users[0].profiles[i] is None: users[0].profiles[i] = user.Profile(i) users[0].profiles[i].userId = users[0].id defer.returnValue(users[0])
def get(self, id): sql = ('SELECT id,user_id,ordinal,name,fav_player,fav_team,`rank`,' 'points,disconnects,updated_on,seconds_played ' 'FROM profiles WHERE deleted = 0 AND id = %s') rows = yield self.dbController.dbRead(0, sql, id) results = [] for row in rows: p = user.Profile(row[2]) p.id = row[0] p.userId = row[1] p.name = row[3] p.favPlayer = row[4] p.favTeam = row[5] p.rank = row[6] p.points = row[7] p.disconnects = row[8] p.updatedOn = row[9] p.playTime = timedelta(seconds=row[10]) results.append(p) defer.returnValue(results)
def get(self, id): sql = ('SELECT id,user_id,ordinal,name,`rank`,' 'rating,points,disconnects,updated_on,seconds_played,comment ' 'FROM profiles WHERE deleted = 0 AND id = %s') rows = yield self.dbController.dbRead(0, sql, id) results = [] for row in rows: (id, userId, ordinal, name, rank, rating, points, disconnects, updatedOn, secondsPlayed, comment) = row playTime = timedelta(seconds=secondsPlayed) p = user.Profile(ordinal) p.id = id p.userId = userId p.name = name p.rank = rank p.rating = rating p.points = points p.disconnects = disconnects p.updatedOn = updatedOn p.playTime = playTime p.comment = comment results.append(p) defer.returnValue(results)
def browse(self, offset=0, limit=30): sql = ('SELECT count(id) ' 'FROM profiles WHERE deleted = 0') rows = yield self.dbController.dbRead(0, sql) total = int(rows[0][0]) sql = ('SELECT id,user_id,ordinal,name,fav_player,fav_team,`rank`,' 'points,disconnects,updated_on,seconds_played ' 'FROM profiles WHERE deleted = 0 ' 'ORDER BY name LIMIT %s OFFSET %s') rows = yield self.dbController.dbRead(0, sql, limit, offset) results = [] for row in rows: p = user.Profile(row[2]) p.id = row[0] p.userId = row[1] p.name = row[3] p.favPlayer = row[4] p.favTeam = row[5] p.rank = row[6] p.points = row[7] p.disconnects = row[8] p.updatedOn = row[9] p.playTime = timedelta(seconds=row[10]) results.append(p) defer.returnValue((total, results))
""" Lobby and related classes """ from datetime import datetime, timedelta import struct import random from fiveserver import log from fiveserver.model import util, user MAX_MESSAGES = 50 MAX_AGE_DAYS = 5 SYSTEM_PROFILE = user.Profile(0) SYSTEM_PROFILE.name = 'SYSTEM' SYSTEM_PROFILE.id = 0 SECONDS_CANCELLED_FORCED_PARTICIATION = 10 class ChatMessage: def __init__(self, fromProfile, text, toProfile=None, special=None): self.fromProfile = fromProfile self.text = text self.toProfile = toProfile self.special = special self.timestamp = datetime.now()