def render_GET(self, request): request.setHeader('Content-Type','text/xml') users = domish.Element((None,'users')) users['count'] = str(len(self.config.onlineUsers)) users['href'] = '/home' keys = self.config.onlineUsers.keys() keys.sort() for key in keys: usr = self.config.onlineUsers[key] e = users.addElement('user') try: e['username'] = usr.username except AttributeError: e['key'] = usr.key try: usr.state.lobbyId except AttributeError: pass else: if usr.state.lobbyId!=None: try: lobby = self.config.getLobbies()[usr.state.lobbyId] except IndexError: pass else: e['lobby'] = util.toUnicode(lobby.name) try: e['profile'] = util.toUnicode(usr.profile.name) except AttributeError: pass try: e['ip'] = usr.lobbyConnection.addr.host except AttributeError: pass return '%s%s' % (XML_HEADER, users.toXml().encode('utf-8'))
def _renderProfileInfo(x): profile, stats = x root = domish.Element((None, 'profile')) root['href'] = '/profiles' root['name'] = util.toUnicode(profile.name) root['id'] = str(profile.id) root.addElement('rank').addContent(str(profile.rank)) root.addElement('favPlayer').addContent(str(profile.favPlayer)) root.addElement('favPlayerId').addContent( str(profile.favPlayer & 0x0000ffff)) root.addElement('favPlayerTeamId').addContent( str((profile.favPlayer >> 16) & 0x0000ffff)) root.addElement('favTeam').addContent(str(profile.favTeam)) root.addElement('points').addContent(str(profile.points)) root.addElement('division').addContent( str(self.config.ratingMath.getDivision(profile.points))) root.addElement('disconnects').addContent( str(profile.disconnects)) root.addElement('playTime').addContent(str(profile.playTime)) games = stats.wins + stats.draws + stats.losses root.addElement('games').addContent(str(games)) root.addElement('wins').addContent(str(stats.wins)) root.addElement('draws').addContent(str(stats.draws)) root.addElement('losses').addContent(str(stats.losses)) root.addElement('goalsScored').addContent( str(stats.goals_scored)) root.addElement('goalsAllowed').addContent( str(stats.goals_allowed)) root.addElement('winningStreakCurrent').addContent( str(stats.streak_current)) root.addElement('winningStreakBest').addContent( str(stats.streak_best)) if games > 0: winPct = stats.wins / float(games) avglscr = stats.goals_scored / float(games) avglcon = stats.goals_allowed / float(games) else: winPct = 0.0 avglscr = 0.0 avglcon = 0.0 root.addElement('winningPct').addContent('%0.1f%%' % (winPct * 100.0)) root.addElement('goalsScoredAverage').addContent('%0.2f' % avglscr) root.addElement('goalsAllowedAverage').addContent('%0.2f' % avglcon) request.write( ('%s%s' % (XML_HEADER, root.toXml())).encode('utf-8')) request.finish()
def _renderProfileInfo((profile, stats)): root = domish.Element((None, 'profile')) root['href'] = '/profiles' root['name'] = util.toUnicode(profile.name) root['id'] = str(profile.id) root.addElement('rank').addContent(str(profile.rank)) root.addElement('favPlayer').addContent(str(profile.favPlayer)) root.addElement('favPlayerId').addContent( str(profile.favPlayer & 0x0000ffff)) root.addElement('favPlayerTeamId').addContent( str((profile.favPlayer >> 16) & 0x0000ffff)) root.addElement('favTeam').addContent(str(profile.favTeam)) root.addElement('points').addContent(str(profile.points)) root.addElement('division').addContent( str(self.config.ratingMath.getDivision(profile.rating))) root.addElement('disconnects').addContent( str(profile.disconnects)) root.addElement('playTime').addContent(str(profile.playTime)) games = stats.wins + stats.draws + stats.losses root.addElement('games').addContent(str(games)) root.addElement('wins').addContent(str(stats.wins)) root.addElement('draws').addContent(str(stats.draws)) root.addElement('losses').addContent(str(stats.losses)) root.addElement('goalsScored').addContent( str(stats.goals_scored)) root.addElement('goalsAllowed').addContent( str(stats.goals_allowed)) root.addElement('winningStreakCurrent').addContent( str(stats.streak_current)) root.addElement('winningStreakBest').addContent( str(stats.streak_best)) if games>0: winPct = stats.wins/float(games) avglscr = stats.goals_scored/float(games) avglcon = stats.goals_allowed/float(games) else: winPct = 0.0 avglscr = 0.0 avglcon = 0.0 root.addElement('winningPct').addContent( '%0.1f%%' % (winPct*100.0)) root.addElement('goalsScoredAverage').addContent( '%0.2f' % avglscr) root.addElement('goalsAllowedAverage').addContent( '%0.2f' % avglcon) request.write(('%s%s' % ( XML_HEADER, root.toXml())).encode('utf-8')) request.finish()
def _renderProfiles(results, offset, limit): total, records = results profiles = domish.Element((None,'profiles')) profiles['href'] = '/home' profiles['total'] = str(total) for profile in records: e = profiles.addElement('profile') e['name'] = util.toUnicode(profile.name) e['href'] = '/profiles/%s' % profile.id next = profiles.addElement('next') next['href'] = '/profiles?offset=%s&limit=%s' % ( offset+limit, limit) request.setHeader('Content-Type','text/xml') request.write(('%s%s' % ( XML_HEADER, profiles.toXml())).encode('utf-8')) request.finish()
def render_GET(self, request): request.setHeader('Content-Type','text/xml') root = domish.Element((None,'stats')) root['playerCount'] = str(len(self.config.onlineUsers)) root['href'] = '/home' lobbiesElem = root.addElement('lobbies') lobbiesElem['count'] = str(len(self.config.lobbies)) for lobby in self.config.lobbies: lobbyElem = lobbiesElem.addElement('lobby') lobbyElem['type'] = lobby.typeStr lobbyElem['showMatches'] = str(lobby.showMatches) lobbyElem['checkRosterHash'] = str(lobby.checkRosterHash) lobbyElem['name'] = util.toUnicode(lobby.name) lobbyElem['playerCount'] = str(len(lobby.players)) lobbyElem['roomCount'] = str(len(lobby.rooms)) m = len([room.match for room in lobby.rooms.values() if room is not None and room.match is not None]) lobbyElem['matchesInProgress'] = str(m) for usr in lobby.players.values(): userElem = lobbyElem.addElement('user') userElem['profile'] = util.toUnicode(usr.profile.name) try: userElem['ip'] = usr.lobbyConnection.addr.host except AttributeError: pass if m>0 and lobby.showMatches: matchesElem = lobbyElem.addElement('matches') matchRooms = [room for room in lobby.rooms.values() if room is not None and room.match is not None] matchRooms.sort() for room in matchRooms: matchElem = matchesElem.addElement('match') matchElem['roomName'] = util.toUnicode(room.name) matchElem['matchTime'] = str(room.matchTime) matchElem['score'] = '%d:%d' % ( room.match.score_home, room.match.score_away) matchElem['homeTeamId'] = str(room.match.home_team_id) matchElem['awayTeamId'] = str(room.match.away_team_id) if isinstance(room.match, Match): if room.match.home_profile: matchElem['homeProfile'] = util.toUnicode( room.match.home_profile.name) if room.match.away_profile: matchElem['awayProfile'] = util.toUnicode( room.match.away_profile.name) elif isinstance(room.match, Match6): matchElem['clock'] = str(room.match.clock) matchElem['state'] = MatchState.stateText.get( room.match.state, 'Unknown') homeTeam = matchElem.addElement('homeTeam') p = homeTeam.addElement('profile') p['name'] = "???" if room.teamSelection is not None: if room.teamSelection.home_captain is not None: p['name'] = util.toUnicode(room.teamSelection.home_captain.name) for prf in room.teamSelection.home_more_players: p = homeTeam.addElement('profile') p['name'] = util.toUnicode(prf.name) awayTeam = matchElem.addElement('awayTeam') p = awayTeam.addElement('profile') p['name'] = "???" if room.teamSelection is not None: if room.teamSelection.home_captain is not None: p['name'] = util.toUnicode(room.teamSelection.away_captain.name) for prf in room.teamSelection.away_more_players: p = awayTeam.addElement('profile') p['name'] = util.toUnicode(prf.name) return '%s%s' % (XML_HEADER, root.toXml().encode('utf-8'))