Ejemplo n.º 1
0
def multi(request, db):
    ws = dbselectors.get('weapon', db, {'recentsums': [pastgames]})
    weapons = ws.multi()
    totalwielded = sum(w['timewielded'] for w in list(weapons.values()))
    ret = web.displays.weaponstable(
        weapons, totalwielded, redeclipse().weaponlist, pastgames).html(True)
    return web.page(ret, title="Weapons")
Ejemplo n.º 2
0
def multi(request, db):
    gs = dbselectors.get('game', db)
    gs.flags_none()
    gs.weakflags(["server"], True)
    games = gs.multi()
    pager = web.Pager(request, onpagecount, reversed(list(games.keys())))
    table = web.Table(
        ["ID", "Mode", "Mutators", "Server",
            "Map", "Duration", "Played"])
    for gid in pager.list():
        game = games[gid]
        with table.tr as tr:
            tr(web.link('/game/', gid, "Game #%d" % gid))
            tr(web.link('/mode/', game["mode"],
                redeclipse(game).modeimg(game["mode"])))
            tr(redeclipse(game).mutslist(game, True) or '-')
            row = db.execute(
                "SELECT version FROM game_servers WHERE game = %d" % gid
                ).fetchone()
            version = row[0]
            tr("%s [%s]" % (
                web.link('/server/', game["server"], game["server"]),
                version))
            tr(web.link('/map/', game["map"], game["map"], True))
            tr(timeutils.durstr(round(game["timeplayed"])))
            tr(timeutils.agohtml(game["time"]))
    ret = """
    <div class="center display-table">
        <h2>Games</h2>
        <h3>{gamenum} Recorded</h3>
        {table}
        {pages}
    </div>
    """.format(table=table.html(), pages=pager.html(), gamenum=len(games))
    return web.page(ret, title="Games")
Ejemplo n.º 3
0
 def page(self, request):
     ret = """
     <div class='display-table small-table'>
         <h3>{title}</h3>
         {table}
     </div>
     """.format(table=self.table(limit=None).html(),
         title=self.pagetitle)
     return web.page(ret, self.pagetitle)
Ejemplo n.º 4
0
 def __init__(self, body="", title="", css="",
     status=200, debug="", cache=True):
         super(
             type(self), self).__init__(
                 body=web.page(body, title, css, debug),
                 status=status, headers={
                         'Content-type': 'text/html',
                     },
                 cache=cache)
Ejemplo n.º 5
0
 def page(self, request):
     data = self.get()
     pager = web.Pager(request, 10, data)
     ret = """
     <div class='display-table'>
         <h3>{title}</h3>
         {table}
         {pager}
     </div>
     """.format(table=self.table(pager=pager).html(),
         pager=pager.html(), title=self.pagetitle)
     return web.page(ret, self.pagetitle)
Ejemplo n.º 6
0
def single(request, db, specific):
    ws = dbselectors.get('weapon', db, {'recentsums': [pastgames]})
    weapons = ws.multi()
    weapon = ws.single(specific)
    if utils.sok(weapon):
        totalwielded = sum(w['timewielded'] for w in list(weapons.values()))
        ret = web.displays.weapontable(
            weapon,
            totalwielded, pastgames).html(True)
    else:
        ret = "<div class='center'><h2>No such mutator.</h2></div>"
    return web.page(ret, title=specific.capitalize())
Ejemplo n.º 7
0
 def page(self, request):
     data = self.get()
     pager = web.Pager(request, 20, sorted(data, key=lambda x: -data[x]))
     ret = """
     <div class='display-table'>
         <h3>{title}</h3>
         {table}
         {pager}
     </div>
     """.format(table=self.table(pager=pager).html(),
         pager=pager.html(), title=self.pagetitle)
     return web.page(ret, self.pagetitle)
Ejemplo n.º 8
0
def multi(request, db):
    mapselector = dbselectors.get('map', db)
    mapselector.flags_none()
    mapselector.weakflags(["race"], True)

    gameselector = dbselectors.get('game', db)
    gameselector.flags_none()

    maps = mapselector.multi()
    pager = web.Pager(request, onpagecount,
        sorted(maps, key=lambda x: -maps[x]["games"][-1]))
    maptable = web.Table(["Name", "Games",
        "First Game", "Latest Game", '<a href="/racemaps">Best Race Time</a>'])
    for mapname in pager.list():
        gmap = maps[mapname]
        firstgame = gameselector.single(gmap["games"][0])
        latestgame = gameselector.single(gmap["games"][-1])
        with maptable.tr as tr:
            tr(web.link('/map/', gmap["name"], gmap["name"], True))
            tr(len(gmap["games"]))
            tr("%s: %s" % (
                web.link('/game/', firstgame['id'], "#%d" % firstgame["id"]),
                timeutils.agohtml(firstgame["time"])
                ))
            tr("%s: %s" % (
                web.link('/game/', latestgame['id'], "#%d" % latestgame["id"]),
                timeutils.agohtml(latestgame["time"])
                ))
            if gmap["toprace"]["time"]:
                tr("%s by %s" % (timeutils.durstr(
                    gmap["toprace"]["time"] / 1000, dec=True, full=True),
                    web.linkif("/player/",
                        gmap["toprace"]["gameplayer"]["handle"],
                        gmap["toprace"]["gameplayer"]["handle"]
                        or gmap["toprace"]["gameplayer"]["name"])
                        )
                    )
            else:
                tr()
    ret = """
    <div class="center">
        <h2>Maps</h2>
        <div class='display-table'>
            {maptable}
            {pages}
        </div>
    </div>
    """.format(maptable=maptable.html(), pages=pager.html())
    return web.page(ret, title="Maps")
Ejemplo n.º 9
0
def single(request, db, specific):
    ret = ""
    serverselector = dbselectors.get('server', db)
    serverselector.flags_none()
    serverselector.weakflags(["games"], True)
    server = serverselector.single(specific)
    if utils.sok(server):
        # Game List
        pager = web.Pager(request, onpagecount, reversed(server["games"]))
        recentgames = web.Table(
            ["ID", "Mode", "Mutators", "Map", "Duration", "Played"])
        gs = dbselectors.get('game', db)
        gs.flags_none()
        firstgame = gs.single(server["games"][0])
        for gid in pager.list():
            game = gs.single(gid)
            with recentgames.tr as tr:
                tr(web.link("/game/", gid, "Game #%d" % gid))
                tr(web.link("/mode/", game["mode"],
                    redeclipse(game).modeimg(game["mode"])))
                tr(redeclipse(game).mutslist(game, True) or '-')
                tr(web.link("/map/", game["map"], game["map"], True))
                tr(timeutils.durstr(round(game["timeplayed"])))
                tr(timeutils.agohtml(game["time"]))

        ret += """
        <div class="center">
            <h2>{server[desc]}</h2>
            <h3>{server[handle]} <i>[{server[authflags]}]</i>:
                Version {server[version]}</h3>
            <a href="redeclipse://{server[host]}:{server[port]}">
            {server[host]}:{server[port]}</a><br>
            {servergames} games recorded.<br>
            First Recorded: {fgtime} with
            <a href="/game/{fgid}">Game #{fgid}</a>.<br>
            <div class='display-table'>
                <h3>Recent Games</h3>
                {recentgames}
                {pages}
            </div>
        </div>
        """.format(server=server, recentgames=recentgames.html(),
            servergames=len(server["games"]),
            fgtime=timeutils.agohtml(firstgame["time"]), fgid=firstgame["id"],
            pages=pager.html())
    else:
        ret = "<div class='center'><h2>No such server.</h2></div>"
    return web.page(ret, title="Server %s" % specific)
Ejemplo n.º 10
0
def single(request, db, specific):
    ps = dbselectors.get('player', db)
    ps.flags_none()
    ps.weakflags(['games'], True)
    gs = dbselectors.get('game', db)
    gs.flags_none()
    gs.weakflags(['players'], True)
    player = ps.single(specific)
    if utils.sok(player):
        table = web.Table(["Game", "Mode", "Mutators",
            "Map", "Time", "Played As", "Score", "Frags", "Deaths"])
        pager = web.Pager(request, onpagecount, reversed(player["games"]))
        for gid in pager.list():
            game = gs.single(gid)
            entry = [p for p in list(game["players"].values())
            if p["handle"] == player["handle"]][0]
            with table.tr as tr:
                tr(web.link('/game/', gid, "Game #%d" % gid))
                tr(web.link('/mode/', game["mode"],
                    redeclipse(game).modeimg(game["mode"])))
                tr(redeclipse(game).mutslist(game, True) or '-')
                tr(web.link("/map/", game["map"], game["map"], True))
                tr(timeutils.agohtml(game["time"]))
                tr(cgi.escape(entry["name"]))
                tr(redeclipse(game).scorestr(game, entry["score"]))
                tr(entry["frags"])
                tr(entry["deaths"])

        ret = """
        <div class="center">
            <h2><a href="/player/{player[handle]}">
            {player[handle]}</a>: Games</h2>
            <div class='display-table'>
                {table}
                {pages}
            </div>
        </div>
        """.format(player=player, table=table.html(), pages=pager.html())
    else:
        ret = "<div class='center'><h2>No such player.</h2></div>"
    return web.page(ret, title="%s: Games" % specific)
Ejemplo n.º 11
0
def multi(request, db):
    playerselector = dbselectors.get('player', db)
    playerselector.flags_none()
    playerselector.weakflags(['games'], True)

    gameselector = dbselectors.get('game', db)
    gameselector.flags_none()

    players = playerselector.multi()
    pager = web.Pager(request, onpagecount,
        sorted(players, key=lambda x: -players[x]["games"][-1]))
    playertable = web.Table(
        ["Name", "Handle", "Games", "First Game", "Latest Game"])
    for handle in pager.list():
        player = players[handle]
        firstgame = gameselector.single(player["games"][0])
        latestgame = gameselector.single(player["games"][-1])
        with playertable.tr as tr:
            tr(web.linkif('/player/', player["handle"], player["name"], True))
            tr(web.linkif('/player/', player["handle"], player["handle"], True))
            tr(len(player["games"]))
            tr("%s: %s" % (
                web.link('/game/', firstgame['id'], "#%d" % firstgame["id"]),
                timeutils.agohtml(firstgame["time"])
                ))
            tr("%s: %s" % (
                web.link('/game/', latestgame['id'], "#%d" % latestgame["id"]),
                timeutils.agohtml(latestgame["time"])
                ))
    ret = """
    <div class="center">
        <h2>Players</h2>
        <div class='display-table'>
            {playertable}
            {pages}
        </div>
    </div>
    """.format(playertable=playertable.html(), pages=pager.html())
    return web.page(ret, title="Players")
Ejemplo n.º 12
0
def single(request, db, specific):
    ret = ""
    mutselector = dbselectors.get('mut', db)
    mutselector.flags_none()
    mut = mutselector.single(specific)
    if utils.sok(mut):
        # Game List
        pager = web.Pager(request, onpagecount, reversed(mut["games"]))
        recentgames = web.Table(
            ["ID", "Mode", "Mutators", "Map", "Duration", "Played"])
        gs = dbselectors.get('game', db)
        gs.flags_none()
        for gid in pager.list():
            game = gs.single(gid)
            with recentgames.tr as tr:
                tr(web.link("/game/", gid, "Game #%d" % gid))
                tr(web.link("/mode/", game["mode"],
                    redeclipse(game).modeimg(game["mode"])))
                tr(redeclipse(game).mutslist(game, True) or '-')
                tr(web.link("/map/", game["map"], game["map"], True))
                tr(timeutils.durstr(round(game["timeplayed"])))
                tr(timeutils.agohtml(game["time"]))

        ret += """
        <div class="center">
            <h2>{mut[id]}</h2>
            <div class='display-table'>
                <h3>Recent Games</h3>
                {recentgames}
                {pages}
            </div>
        </div>
        """.format(mut=mut,
            recentgames=recentgames.html(),
            pages=pager.html())
    else:
        ret = "<div class='center'><h2>No such mutator.</h2></div>"
    return web.page(ret, title="Mutator %s" % specific)
Ejemplo n.º 13
0
def multi(request, db):
    gs = dbselectors.get('games', db)
    gs.flags_none()
    gs.weakflags(['server'], True)

    #Top Weapons
    ws = dbselectors.get('weapons', db, {'recentsums': [5000]})
    weapons = {}
    for name in redeclipse().loadoutweaponlist:
        weapon = ws.single(name)
        weapons[name] = weapon

    topweapons = {
        'wield': (redeclipse().weaponlist[0], 0),
        'dpm': (redeclipse().weaponlist[0], 0),
        'totalwielded': 0,
        }
    if weapons:
        best = sorted(list(weapons.items()), key=lambda weapon: -(
            weapon[1]["damage1"]
            / (max(weapon[1]["timewielded"], 1) / 60) +
            weapon[1]["damage2"]
            / (max(weapon[1]["timewielded"], 1) / 60)))[0]
        topweapons['dpm'] = (best[0], (best[1]["damage1"]
            / (max(best[1]["timewielded"], 1) / 60) +
            best[1]["damage2"]
            / (max(best[1]["timewielded"], 1) / 60)))
        topweapons['totalwielded'] = sum([w['timewielded']
            for w in list(weapons.values())])
        best = sorted(list(weapons.items()), key=lambda weapon: -(
            max(weapon[1]["timewielded"], 1)))[0]
        topweapons['wield'] = (best[0], best[1]["timewielded"])

    # Recent Games
    gamestable = web.Table(
        ["ID", "Mode", "Mutators", "Server", "Map", "Duration", "Played"])
    games = gs.multi()
    for gid in sorted(list(games.keys()), reverse=True)[:10]:
        game = games[gid]
        with gamestable.tr as tr:
            tr(web.link('/game/', gid, "Game #%d" % gid))
            tr(web.link('/mode/', game["mode"],
                redeclipse(game).modeimg(game["mode"])))
            tr(redeclipse(game).mutslist(game, True) or '-')
            tr("%s [%s]" % (
                web.link('/server/', game["server"], game["server"]),
                game["version"]))
            tr(web.link('/map/', game["map"], game["map"], True))
            tr(timeutils.durstr(round(game["timeplayed"])))
            tr(timeutils.agohtml(game["time"]))

    ranks = {
        "spf": rankselectors.get('spf', db, 7).table().html(),
        "captures": rankselectors.get('captures', db, 7).table().html(),
        "bombings": rankselectors.get('bombings', db, 7).table().html(),
        "affmvp": rankselectors.get('mvp', db, 7, "affmvp").table().html(),
        "dmmvp": rankselectors.get('mvp', db, 7, "dmmvp").table().html(),
        "sword": rankselectors.get('weapon', db, 7,
            {"weapon": ('sword', 0)}).best(),
        "sniper": rankselectors.get('weapon', db, 7,
            {"weapon": ('rifle', 2)}).best(),

        "spm": rankselectors.get('spm', db, 30).table().html(),
        "dpm": rankselectors.get('dpm', db, 30).table().html(),
        "fpm": rankselectors.get('fpm', db, 30).table().html(),
        "games": rankselectors.get('games', db, 30).table().html(),

        "maps": rankselectors.get('maps', db, 90).table().html(),
        "servers": rankselectors.get('servers', db, 90).table().html(),
        "ffa": rankselectors.get(
            'winners', db, 90, 'ffa').table().html(),
        "ffasurv": rankselectors.get(
            'winners', db, 90, 'ffasurv').table().html(),
    }

    ret = """
    <h2>Recent Overview</h2>

    <h5><a href="/players">Players</a></h5>
    <h3>Last 7 Days</h3>
    <div class='display-table float-table'>
        <h5>Score/Frags</h5>
        {ranks[spf]}
    </div>
    <div class='display-table float-table'>
        <h5>
        <span class="explain" title="Most Flag Captures">Captures</span></h5>
        {ranks[captures]}
    </div>
    <div class='display-table float-table'>
        <h5>
        <span class="explain" title="Most Base Bombings">Bombings</span></h5>
        {ranks[bombings]}
    </div>
    <div class='display-table float-table'>
        <h5><span class="explain"
        title="Scores from CTF and BB">CTF/BB Team Scores</span></h5>
        {ranks[affmvp]}
    </div>
    <div class='display-table float-table'>
        <h5><span class="explain"
        title="Scores from DM">DM Team Scores</span></h5>
        {ranks[dmmvp]}
    </div>
    <div class='display-table float-table'>
        <h5>Best</h5>
        <table>
            <tr>
                <td><span class="explain"
title="Best Damage and Frags with the Sword">Knight</span></td>
                <td>{ranks[sword]}</td>
            </tr>
            <tr>
                <td><span class="explain"
title="Best Damage and Frags with the Rifle Secondary">
Sniper</span></td>
                <td>{ranks[sniper]}</td>
            </tr>
        </table>
    </div>

    <div style="clear: both;"></div>
    <h3>Last 30 Days</h3>
    <div class='display-table float-table'>
        <h5><a href="/ranks/spm/180"
            class="explain" title="Score per Minute">SPM</a></h5>
        {ranks[spm]}
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/dpm/180"
            class="explain" title="Damage per Minute">DPM</a></h5>
        {ranks[dpm]}
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/fpm/180"
            class="explain" title="Frags per Minute">FPM</a></h5>
        {ranks[fpm]}
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/games/365">Games</a></h5>
        {ranks[games]}
    </div>

    <div style="clear: both;"></div>
    <h3>Last 90 Days</h3>
    <div class='display-table float-table'>
        <h5><a href="/maps">Maps</a></h5>
        {ranks[maps]}
    </div>
    <div class='display-table float-table'>
        <h5><a href="/servers">Servers</a></h5>
        {ranks[servers]}
    </div>
    <div class='display-table float-table'>
        <h5><a href="/weapons">Weapons</a></h5>
        <table>
            <tr>
                <td>Best DPM</td>
                <td>{weapdpm}</td>
            </tr>
            <tr>
                <td>Most Wielded</td>
                <td>{weapwield}</td>
            </tr>
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/winners/180?opts=ffa">
        FFA Win Ratio</a></h5>
        {ranks[ffa]}
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/winners/180?&opts=ffasurv">
        FFA Survivor Win Ratio</a></h5>
        {ranks[ffasurv]}
    </div>

    <div style="clear: both;"></div>
    <div class='display-table'>
        <h5><a href="/games">Latest Games</a></h5>
        {games}
    </div>
    <div style="clear: both;"></div>
    """.format(
        weapdpm="%s %s [%d DPM]" % (
            redeclipse().weaponimg(topweapons['dpm'][0]),
            web.link('/weapon/', topweapons['dpm'][0], topweapons['dpm'][0]),
            topweapons['dpm'][1]),
        weapwield="%s %s [%d%%]" % (
            redeclipse().weaponimg(topweapons['wield'][0]),
            web.link('/weapon/', topweapons['wield'][0],
                topweapons['wield'][0]),
            topweapons['wield'][1]
                / max(topweapons['totalwielded'], 1) * 100),
        games=gamestable.html(),
        ranks=ranks,
        )
    return web.page(ret, title="Overview")
Ejemplo n.º 14
0
def single(request, db, specific):
    playerselector = dbselectors.get('player', db, {'recentsums': [-1]})
    playerselector.flags_none()
    playerselector.weakflags(
        ['games', 'damage', 'recentgames', 'recentsums', 'weapons'], True)

    recentplayerselector = dbselectors.get('player', db,
        {'recentsums': [recentlimit]})
    recentplayerselector.flags_none()
    recentplayerselector.weakflags(
        ['games', 'damage', 'recentsums', 'weapons'], True)

    gameselector = dbselectors.get('game', db)
    gameselector.flags_none()

    player = playerselector.single(specific)
    recentplayer = recentplayerselector.single(specific)
    if utils.sok(player) and utils.sok(recentplayer):
        #Top map
        topmap = "-"
        maps = {}
        for row in db.execute('''SELECT map FROM games
            WHERE id IN (SELECT game
            FROM game_players WHERE handle = ?
            ORDER by ROWID DESC LIMIT %d)''' % recentlimit,
                (player["handle"],)):
                    if row[0] not in maps:
                        maps[row[0]] = 0
                    maps[row[0]] += 1
        if maps:
            t = sorted(maps, key=lambda x: -maps[x])[0]
            topmap = web.link('/map/', t, t)
        # Play time
        timeplayed = timeutils.durstr(player["recent"]["timeactive"],
            skip="s", skiplow=False, full=True)
        #DPM
        try:
            dpm = "%d" % (round(player["recent"]["damage"]
                / (player["recent"]["timealive"] / 60)))
        except TypeError:
            dpm = "-"
        #Frag ratio
        try:
            fratio = "%.2f [%d / %d]" % ((player["recent"]["frags"] /
                max(1, player["recent"]["deaths"])),
                    player["recent"]["frags"],
                    player["recent"]["deaths"])
        except TypeError:
            fratio = "-"
        #Recent Games
        gamestable = web.Table(["Game", "Mode", "Mutators",
            "Map", "Time", "Played As", "Score", "Frags", "Deaths"])
        for gid in sorted(
            list(player["recentgames"].keys()), reverse=True)[:5]:
                game = player["recentgames"][gid]
                entry = game["player"]
                with gamestable.tr as tr:
                    tr(web.link('/game/', gid, "Game #%d" % gid))
                    tr(web.link('/mode/', game["mode"],
                        redeclipse(game).modeimg(game["mode"])))
                    tr(redeclipse(game).mutslist(game, True) or '-')
                    tr(web.link("/map/", game["map"], game["map"], True))
                    tr(timeutils.agohtml(game["time"]))
                    tr(cgi.escape(entry["name"]))
                    tr(redeclipse(game).scorestr(game, entry["score"]))
                    tr(entry["frags"])
                    tr(entry["deaths"])
        #Weapons
        totalwielded = sum([w['timewielded']
            for w in list(recentplayer['recent']['weapons'].values())
            if w['timewielded'] is not None])
        weaponstable = web.displays.weaponstable(
            recentplayer['recent']['weapons'],
            totalwielded, redeclipse().weaponlist)
        ret = """
        <div class="center">
            <h2>{player[name]}</h2>
            <h3>{player[handle]}</h3>
            <div class="colcontainer">
                <div class="leftcol">
                    First appeared: {firstago}<br>
                    Last appeared: {lastago}<br>
                </div>
                <div class="rightcol">
                    Most played map: {topmap}<br>
                    Playing time: {timeplayed}<br>
                </div>
            </div>
            <div style="clear: both;"></div>
            <h3>Last {recentnum} Games</h3>
            Frag Ratio: {fratio}<br>
            DPM: {dpm}<br>
            <div class='display-table'>
                {games}
                <h5 style="text-align: left;">
                <a href="/playergames/{player[handle]}">
                All Games...</a></h5>
            </div>
            <div class='display-table small-table'>
                <h3>Weapon Statistics</h3>
                {weapons}
            </div>
        </div>
        """.format(
            player=player,
            firstago=web.link("/game/", player["games"][0],
                timeutils.agohtml(
                    gameselector.single(player["games"][0])["time"])),
            lastago=web.link("/game/", player["games"][-1],
                timeutils.agohtml(
                    gameselector.single(player["games"][-1])["time"])),
            topmap=topmap,
            timeplayed=timeplayed,
            dpm=dpm,
            fratio=fratio,
            games=gamestable.html(),
            weapons=weaponstable.html(),
            recentnum=recentlimit,
            )
    else:
        ret = "<div class='center'><h2>No such player.</h2></div>"
    return web.page(ret, title="Player %s" % specific)
Ejemplo n.º 15
0
def single(request, db, specific):
    ret = ""
    mapselector = dbselectors.get('map', db)
    mapselector.flags_none()
    mapselector.weakflags(["race"], True)
    gmap = mapselector.single(specific)
    if utils.sok(gmap):
        # Game List
        pager = web.Pager(request, onpagecount, reversed(gmap["games"]))
        recentgames = web.Table(
            ["ID", "Mode", "Mutators", "Duration", "Played"])
        gs = dbselectors.get('game', db)
        gs.flags_none()
        for gid in pager.list():
            game = gs.single(gid)
            with recentgames.tr as tr:
                tr(web.link("/game/", gid, "Game #%d" % gid))
                tr(web.link("/mode/", game["mode"],
                    redeclipse(game).modeimg(game["mode"])))
                tr(redeclipse(game).mutslist(game, True) or '-')
                tr(timeutils.durstr(round(game["timeplayed"])))
                tr(timeutils.agohtml(game["time"]))

        # Race Times
        racetable = web.Table(["Time", "Player", "Handle", "Game", "When"])
        for race in gmap["topraces"][:3]:
            with racetable.tr as tr:
                tr(timeutils.durstr(race["time"] / 1000, dec=True, full=True))
                tr(web.linkif('/player/',
                    race["gameplayer"]["handle"], race["gameplayer"]["name"]))
                tr(web.linkif('/player/',
                    race["gameplayer"]["handle"],
                    race["gameplayer"]["handle"] or '-'))
                tr(web.link('/game/', race["game"]["id"],
                    "Game #%d" % race["game"]["id"]))
                tr(timeutils.agohtml(race["game"]["time"]))
        racetimes = """
        <div class='display-table small-table'>
            <h3>Top Race Times</h3>
            %s
        </div>
        """ % racetable.html()

        eracetable = web.Table(["Time", "Player", "Handle", "Game", "When"])
        for race in gmap["toperaces"][:3]:
            with eracetable.tr as tr:
                tr(timeutils.durstr(race["time"] / 1000, dec=True, full=True))
                tr(web.linkif('/player/',
                    race["gameplayer"]["handle"], race["gameplayer"]["name"]))
                tr(web.linkif('/player/',
                    race["gameplayer"]["handle"],
                    race["gameplayer"]["handle"] or '-'))
                tr(web.link('/game/', race["game"]["id"],
                    "Game #%d" % race["game"]["id"]))
                tr(timeutils.agohtml(race["game"]["time"]))
        eracetimes = """
        <div class='display-table small-table'>
            <h3>Top Endurance Race Times</h3>
            %s
        </div>
        """ % eracetable.html()

        ret += """
        <div class="center">
            <h2>{map[name]}</h2>
            {racetimes}
            {eracetimes}
            <div class='display-table'>
                <h3>Recent Games</h3>
                {recentgames}
                {pages}
            </div>
        </div>
        """.format(map=gmap,
            recentgames=recentgames.html(),
            racetimes=racetimes if gmap["toprace"]["time"] else '',
            eracetimes=eracetimes if gmap["toperace"]["time"] else '',
            pages=pager.html())
    else:
        ret = "<div class='center'><h2>No such map.</h2></div>"
    return web.page(ret, title="Map %s" % specific)
Ejemplo n.º 16
0
def single(request, db, specific):
    gs = dbselectors.get('game', db)
    gs.flags_none()
    gs.weakflags(["server", "teams",
        "affinities", "rounds", "players", "playerdamage", "weapons"], True)
    ss = dbselectors.get('server', db)
    ss.flags_none()

    game = gs.single(specific)
    ret = ""
    if utils.sok(game):
        server = ss.single(game["server"])
        # Display the server's desc & version from this game.
        serverrow = db.execute(
            """SELECT version,desc,host,port
            FROM game_servers WHERE game = %d""" % game["id"]
            ).fetchone()
        server["version"] = serverrow[0]
        server["desc"] = cgi.escape(serverrow[1]) or cgi.escape(
            "%s:%d" % (serverrow[2], serverrow[3]))

        playerstable = web.Table(
            ["Name", "Score", "Handle", "Alive", "Frags", "Deaths"],
            "Players", "display-table")
        for player in sorted(
            list(game["players"].values()), key=lambda x: (
                redeclipse(game).scorenum(game, x["score"]))):
                with playerstable.tr as tr:
                    tr(web.linkif('/player/', player["handle"], player["name"]))
                    tr(redeclipse(game).scorestr(game, player["score"]))
                    tr(web.linkif('/player/',
                        player["handle"], player["handle"]))
                    tr(timeutils.durstr(player["timealive"]))
                    tr(player["frags"])
                    tr(player["deaths"])

        teamstable = None
        teamlist = {}
        if len(game["teams"]) > 1:
            teamstable = web.Table(
                ["Name", "Score"],
                "Teams", "display-table small-table")
            # Sort depending on score, counting race times
            for team in sorted(sorted(game["teams"],
                key=lambda x: game["teams"][x]["score"] * (
                    1 if
                    game["mode"] == redeclipse(game).modes["race"]
                    and (game["mutators"] & redeclipse(game).mutators["timed"])
                    else -1
                    )), key=lambda x: game["teams"][x]["score"] == 0):
                        team = game["teams"][team]
                        teamlist[team["team"]] = team
                        with teamstable.tr as tr:
                            tr("%s %s" % (
                                redeclipse(game).teamimg(team["team"]),
                                cgi.escape(team["name"])
                                ))
                            tr(redeclipse(game).scorestr(game, team["score"]))

        ffarounds = web.Table(["Round", "Winner", "Versus"],
            "Rounds", "display-table small-table")
        if "ffarounds" in game:
            donerounds = []
            for ffaround in sorted(game["ffarounds"], key=lambda x: x["round"]):
                if ffaround["round"] in donerounds:
                    continue
                haswinner = False
                for ffaround_s in game["ffarounds"]:
                    if (ffaround_s["round"] == ffaround["round"]
                    and ffaround_s["winner"]):
                        haswinner = True
                        break
                versuslist = []
                for ffaround_s in game["ffarounds"]:
                    if (ffaround_s["round"] == ffaround["round"]
                    and not ffaround_s["winner"]):
                        versuslist.append(web.linkif(
                            "/player/", ffaround_s["playerhandle"],
                            game["players"][ffaround_s["player"]]["name"]))
                with ffarounds.tr as tr:
                    if haswinner and ffaround["winner"]:
                            tr(ffaround["round"])
                            tr(web.linkif(
                                "/player/", ffaround["playerhandle"],
                                game["players"][ffaround["player"]]["name"]))
                            if versuslist:
                                tr(", ".join(versuslist))
                            else:
                                tr("<i>AI</i>")
                    elif not haswinner:
                        donerounds.append(ffaround["round"])
                        if len(versuslist) == 1:
                            tr(ffaround["round"])
                            tr('<i>AI</i>')
                            tr(", ".join(versuslist))
                        else:
                            tr(ffaround["round"])
                            tr('<i>Epic fail!</i>')
                            tr(", ".join(versuslist))

        affinitiestable = None
        if "captures" in game:
            affinitiestable = web.Table(
                ["Player", "Capturing Team", "Captured Flag"],
                "Flag Captures", "display-table"
                )
            for capture in game["captures"]:
                with affinitiestable.tr as tr:
                    tr(web.linkif('/player/', capture["playerhandle"],
                        game["players"][capture["player"]]["name"]))
                    tr(cgi.escape(teamlist[capture["capturing"]]["name"]))
                    tr(cgi.escape(teamlist[capture["captured"]]["name"]))
        elif "bombings" in game:
            affinitiestable = web.Table(
                ["Player", "Bombing Team", "Bombed Base"],
                "Base Bombings", "display-table"
                )
            for bombing in game["bombings"]:
                with affinitiestable.tr as tr:
                    tr(web.linkif('/player/', bombing["playerhandle"],
                        game["players"][bombing["player"]]["name"]))
                    tr(cgi.escape(teamlist[bombing["bombing"]]["name"]))
                    tr(cgi.escape(teamlist[bombing["bombed"]]["name"]))

        totalwielded = sum([w['timewielded']
            for w in list(game['weapons'].values())
            if w['timewielded'] is not None])
        weaponstable = web.displays.weaponstable(game['weapons'],
            totalwielded, redeclipse(game).weaponlist, version=game)
        if game["mode"] == redeclipse(game).modes['race']:
            weaponstable = None

        ret = """
        <div class="center">
            <h2>Game #{game[id]}: {modestr} on {mapstr}</h2>
            {mutsstr}
            Duration: {duration}<br>
            Played: {agohtml}<br>
            Server: <a
                href="/server/{server[handle]}">{server[desc]}
                [{server[version]}] [{server[handle]}]</a>
            {teams}
            {players}
            {affinities}
            {ffarounds}
            {weapons}
        </div>
        """.format(
            game=game,
            modestr=web.link('/mode/', game["mode"],
                redeclipse(game).modeimg(game["mode"], 32)),
            mutsstr=("Mutators: %s<br>" % redeclipse(game).mutslist(
                game, True, True)) if game['mutators'] else '',
            mapstr=web.link('/map/', game["map"], game["map"]),
            server=server,
            agohtml=timeutils.agohtml(game["time"]),
            duration=timeutils.durstr(game["timeplayed"]),
            players=playerstable.html(True),
            teams=teamstable.html(True) if teamstable is not None else "",
            affinities=affinitiestable.html(True)
                if affinitiestable is not None else "",
            ffarounds=ffarounds.html(True) if "ffarounds" in game else "",
            weapons=weaponstable.html(True)
                if weaponstable is not None else "",
            )
    else:
        ret = "<div class='center'><h2>No such game.</h2></div>"
    return web.page(ret, title="Game %s" % specific)