Example #1
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")
Example #2
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)
Example #3
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")
Example #4
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")
Example #5
0
def map(sel):
    ret = ""
    gs = dbselectors.MapSelector()
    gs.copyfrom(sel)
    gamemap = gs.single(sel.pathid)
    if gamemap is None:
        ret = "<div class='center'><h2>No such Map.</h2></div>"
    else:
        recentgames = ""
        for gid, game in list(reversed(list(gamemap["recentgames"].items())))[:10]:
            recentgames += "<tr>"
            recentgames += tdlink("game", gid, "#%d" % gid)
            recentgames += tdlink("mode", game["mode"], dbselectors.modestr[game["mode"]])
            recentgames += "<td>%s</td>" % timeutils.durstr(round(game["timeplayed"]))
            recentgames += "<td>%s</td>" % timeutils.agohtml(game["time"])
            recentgames += "</tr>"
        toprace = ""
        if gamemap["toprace"]["time"]:
            toprace = """<h3>%s by %s (%s)</h3>""" % (
                timeutils.durstr(gamemap["toprace"]["time"] / 1000, dec=True),
                alinkp("player", gamemap["toprace"]["gameplayer"]["handle"], gamemap["toprace"]["gameplayer"]["name"]),
                alink("game", gamemap["toprace"]["game"]["id"], "Game #%d" % gamemap["toprace"]["game"]["id"]),
            )
        ret += """
        <div class="center">
            <h2>{map[name]}</h2>
            {toprace}
            <div class='display-table'>
                <h3>Recent Games</h3>
                <table>
                    <tr>
                        <th>ID</th>
                        <th>Mode</th>
                        <th>Duration</th>
                        <th>Played</th>
                    </tr>
                    {recentgames}
                </table>
            </div>
        </div>
        """.format(
            map=gamemap, recentgames=recentgames, toprace=toprace
        )
    return base.page(sel, ret, title="Game %s" % sel.pathid)
Example #6
0
def server(sel):
    ret = ""
    ss = dbselectors.ServerSelector()
    ss.copyfrom(sel)
    server = ss.single(sel.pathid)
    if server is None:
        ret = "<div class='center'><h2>No such server.</h2></div>"
    else:
        recentgames = ""
        for gid, game in list(reversed(list(server["recentgames"].items())))[:10]:
            recentgames += "<tr>"
            recentgames += tdlink("game", gid, "#%d" % gid)
            recentgames += tdlink("mode", game["mode"], dbselectors.modestr[game["mode"]])
            recentgames += tdlink("map", game["map"], game["map"])
            recentgames += "<td>%s</td>" % timeutils.durstr(round(game["timeplayed"]))
            recentgames += "<td>%s</td>" % timeutils.agohtml(game["time"])
            recentgames += "</tr>"
        server["desc"] = cgi.escape(server["desc"])
        ret += """
        <div class="center">
            <h2>{server[desc]}</h2>
            <h4>{server[handle]} [{server[flags]}]:
                Version {server[version]}</h4>
            <a href="redeclipse://{server[host]}:{server[port]}">
            {server[host]}:{server[port]}</a><br>
            <div class='display-table'>
                <h3>Recent Games</h3>
                <table>
                    <tr>
                        <th>ID</th>
                        <th>Mode</th>
                        <th>Map</th>
                        <th>Duration</th>
                        <th>Played</th>
                    </tr>
                    {recentgames}
                </table>
            </div>
        </div>
        """.format(
            server=server, recentgames=recentgames
        )
    return base.page(sel, ret, title="Server %s" % sel.pathid)
Example #7
0
def page(sel):
    recentgames = ""
    gs = dbselectors.GameSelector()
    gs.copyfrom(sel)
    gs.qopt = api.Qopt({
        "recent": [True],
        })
    games = gs.getdict()
    for gid, game in list(reversed(list(games.items())))[:10]:
        recentgames += '<tr>'
        recentgames += tdlink("game", gid, "#%d" % gid)
        recentgames += tdlink("mode",
            game["mode"],
            dbselectors.modestr[game["mode"]])
        ss = dbselectors.ServerSelector()
        ss.copyfrom(sel)
        desc = ss.single(game["server"])["desc"]
        recentgames += tdlink('server', game["server"], desc)
        recentgames += tdlink('map', game["map"], game["map"])
        recentgames += '<td>%s</td>' % timeutils.durstr(round(
            game["timeplayed"]))
        recentgames += '<td>%s</td>' % timeutils.agohtml(game["time"])
        recentgames += '</tr>'
    ret = """
    <h2 class='center'>Red Eclipse Statistics</h2>
    <div class='display-table'>
        <h3>Recent Games</h3>
        <table>
            <tr>
                <th>ID</th>
                <th>Mode</th>
                <th>Server</th>
                <th>Map</th>
                <th>Duration</th>
                <th>Played</th>
            </tr>
            {recentgames}
        </table>
    </div>
    """.format(recentgames=recentgames)
    return base.page(sel, ret, title="Overview")
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)
Example #9
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)
Example #10
0
def mode(sel):
    ret = ""
    gs = dbselectors.ModeSelector()
    gs.copyfrom(sel)
    mode = gs.single(sel.pathid)
    if mode is None:
        ret = "<div class='center'><h2>No such Mode.</h2></div>"
    else:
        recentgames = ""
        for gid, game in list(reversed(list(mode["recentgames"].items())))[:10]:
            recentgames += "<tr>"
            recentgames += tdlink("game", gid, "#%d" % gid)
            recentgames += tdlink("map", game["map"], game["map"])
            recentgames += "<td>%s</td>" % timeutils.durstr(round(game["timeplayed"]))
            recentgames += "<td>%s</td>" % timeutils.agohtml(game["time"])
            recentgames += "</tr>"
        ret += """
        <div class="center">
            <h2>{mode[name]}</h2>
            <div class='display-table'>
                <h3>Recent Games</h3>
                <table>
                    <tr>
                        <th>ID</th>
                        <th>Map</th>
                        <th>Duration</th>
                        <th>Played</th>
                    </tr>
                    {recentgames}
                </table>
            </div>
        </div>
        """.format(
            mode=mode, recentgames=recentgames
        )
    return base.page(sel, ret, title="Game %s" % sel.pathid)
Example #11
0
def player(sel):
    ret = ""
    gs = dbselectors.PlayerSelector()
    gs.copyfrom(sel)
    player = gs.single(sel.pathid)
    if player is None:
        ret = "<div class='center'><h2>No such player.</h2></div>"
    else:
        player["name"] = cgi.escape(player["name"])
        recentgames = ""
        for gid, game in list(reversed(list(player["recentgames"].items())))[:10]:
            entry = [p for p in game["players"] if p["handle"] == player["handle"]][0]
            recentgames += "<tr>"
            recentgames += tdlink("game", gid, "#%d (%s on %s)" % (gid, dbselectors.modestr[game["mode"]], game["map"]))
            recentgames += "<td>%s</td>" % timeutils.agohtml(game["time"])
            recentgames += "<td>%s</td>" % cgi.escape(entry["name"])
            recentgames += "<td>%s</td>" % dbselectors.scorestr(game, entry["score"])
            recentgames += "<td>%d</td>" % entry["frags"]
            recentgames += "<td>%d</td>" % entry["deaths"]
            recentgames += "</tr>"
        recentweapons = ""
        try:
            fratio = "%.2f" % (player["recent"]["frags"] / max(1, player["recent"]["deaths"]))
        except TypeError:
            fratio = "-"
        try:
            totalwielded = sum([w["timewielded"] for w in list(player["recent"]["weapons"].values())])
            for weap in sorted(dbselectors.weaponlist):
                weapon = player["recent"]["weapons"][weap]
                recentweapons += "<tr>"
                recentweapons += "<td>%s</td>" % cgi.escape(weap)
                recentweapons += "<td>%d%%</td>" % (weapon["timeloadout"] / max(1, totalwielded) * 100)
                recentweapons += "<td>%d%%</td>" % (weapon["timewielded"] / max(1, totalwielded) * 100)
                recentweapons += "<td>%d%%</td>" % (weapon["hits1"] / max(1, weapon["shots1"]) * 100)
                recentweapons += "<td>%d%%</td>" % (weapon["hits2"] / max(1, weapon["shots2"]) * 100)
                recentweapons += "<td>%d</td>" % weapon["frags1"]
                recentweapons += "<td>%d</td>" % weapon["frags2"]
                recentweapons += "</tr>"
        except TypeError:
            pass
        gs = dbselectors.GameSelector()
        gs.copyfrom(sel)
        firstago = timeutils.agohtml(gs.single(min(player["games"]))["time"])
        ret += """
        <div class="center">
            <h2>{player[name]}</h2>
            <h3>{player[handle]}</h3>
            First recorded game: {firstago}<br>
            Frag Ratio: {fratio}<br>
            <div class='display-table'>
                <h3>Recent Games</h3>
                <table>
                    <tr>
                        <th>Game</th>
                        <th>Time</th>
                        <th>Played As</th>
                        <th>Score</th>
                        <th>Frags</th>
                        <th>Deaths</th>
                    </tr>
                    {recentgames}
                </table>
            </div>
            <div class='display-table'>
                <h3>Weapon Statistics</h3>
                <table>
                    <tr>
                        <th>Name</th>
                        <th>Loadout</th>
                        <th>Wielded</th>
                        <th>Hit Ratio 1</th>
                        <th>Hit Ratio 2</th>
                        <th>Frags 1</th>
                        <th>Frags 2</th>
                    </tr>
                    {recentweapons}
                </table>
            </div>
        </div>
        """.format(
            recentgames=recentgames, player=player, firstago=firstago, fratio=fratio, recentweapons=recentweapons
        )
    return base.page(sel, ret, title="Game %s" % sel.pathid)
Example #12
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")
Example #13
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)
Example #14
0
def page(sel):
    recentgames = ""
    gs = dbselectors.GameSelector()
    gs.copyfrom(sel)
    gs.pathid = None
    gs.qopt = api.Qopt({
        "recent": [True],
        })
    games = gs.getdict(last=10)
    for gid, game in sorted(list(games.items()), key=lambda x: -x[0]):
        recentgames += '<tr>'
        recentgames += tdlink("game", gid, "Game #%d" % gid)
        recentgames += tdlink("mode",
            game["mode"],
            redeclipse(game).modeimg(game["mode"]), e=False)
        recentgames += "<td>%s</td>" % (
            redeclipse(game).mutslist(game, True) or '-')
        ss = dbselectors.ServerSelector()
        ss.copyfrom(sel)
        desc = ss.single(game["server"])["desc"]
        recentgames += tdlink('server', game["server"], desc)
        recentgames += tdlink('map', game["map"], game["map"])
        recentgames += '<td>%s</td>' % timeutils.durstr(round(
            game["timeplayed"]))
        recentgames += '<td>%s</td>' % timeutils.agohtml(game["time"])
        recentgames += '</tr>'

    ws = dbselectors.WeaponSelector()
    ws.copyfrom(sel)
    ws.pathid = None

    weapons = {}
    for name in redeclipse().loadoutweaponlist:
        if sel.server.dbexists:
            weapon = ws.single(name)["recent"]
            weapons[name] = weapon

    topweapons = {
        'wield': ('melee', 0),
        'dpm': ('melee', 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"])

    def makeweapbest(e):
        if not e:
            return ""
        return alink("player", e[0][0], e[0][0])

    ptcounters = {
        "captures": pt.gamelist(caches.caches["plsingle"].get(
            "captures", 7), num=5),
        "bombings": pt.gamelist(caches.caches["plsingle"].get(
            "bombings", 7), num=5),
        "spf": pt.gamelist(caches.caches["spm"].get("spf", 7), num=5),
        "affmvp": pt.gamelist(caches.caches["mvp"].get(
            "affmvp", 7), num=5),
        "dmmvp": pt.gamelist(caches.caches["mvp"].get(
            "dmmvp", 7), num=5),
        "games": pt.gamelist(caches.caches["plsingle"].get(
            "games", 30), num=5),
        "dpm": pt.gamelist(caches.caches["spm"].get("dpm", 30), num=5),
        "spm": pt.gamelist(caches.caches["spm"].get("spm", 30), num=5),
        "fpm": pt.gamelist(caches.caches["spm"].get("fpm", 30), num=5),
        "maps": pt.mapnum(sel, 90),
        "servers": pt.servernum(sel, 90),
        "ffa": pt.gamedivlist(caches.caches["plwinner"].get(
            "ffa", 90), num=5),
        "ffasurv": pt.gamedivlist(caches.caches["plwinner"].get(
            "ffasurv", 90), num=5),
        "sword": makeweapbest(
            caches.caches['plweapon'].get(('sword', 0), 7)),
        "sniper": makeweapbest(
            caches.caches['plweapon'].get(('rifle', 2), 7))
        }
    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>
        <table>
            <tr>
                <th>Name</th>
                <th>S/F Ratio</th>
            </tr>
            {ptcounters[spf]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5>
        <span class="explain" title="Most Flag Captures">Captures</span></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Captures</th>
            </tr>
            {ptcounters[captures]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5>
        <span class="explain" title="Most Base Bombings">Bombings</span></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Bombings</th>
            </tr>
            {ptcounters[bombings]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><span class="explain"
        title="Scores from CTF and BB">CTF/BB Team Scores</span></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Score</th>
            </tr>
            {ptcounters[affmvp]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><span class="explain"
        title="Scores from DM">DM Team Scores</span></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Score</th>
            </tr>
            {ptcounters[dmmvp]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5>Best</h5>
        <table>
            <tr>
                <td><span class="explain"
title="Best Damage and Frags with the Sword per minute">Knight</span></td>
                <td>{ptcounters[sword]}</td>
            </tr>
            <tr>
                <td><span class="explain"
title="Best Damage and Frags with the Rifle Secondary per minute">
Sniper</span></td>
                <td>{ptcounters[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" class="explain"
        title="Score Per Minute">SPM</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>SPM</th>
            </tr>
            {ptcounters[spm]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/dpm" class="explain"
        title="Damage Per Minute">DPM</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>DPM</th>
            </tr>
            {ptcounters[dpm]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><a class="explain" href="/ranks/fpm"
        title="Frags Per Minute">FPM</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>FPM</th>
            </tr>
            {ptcounters[fpm]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/games">Games</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Games</th>
            </tr>
            {ptcounters[games]}
        </table>
    </div>
    <div style="clear: both;"></div>
    <h3>Last 90 Days</h3>
    <div class='display-table float-table'>
        <h5><a href="/maps">Maps</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Games</th>
            </tr>
            {ptcounters[maps]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><a href="/servers">Servers</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Games</th>
            </tr>
            {ptcounters[servers]}
        </table>
    </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/ffa">FFA Win Ratio</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Games</th>
            </tr>
            {ptcounters[ffa]}
        </table>
    </div>
    <div class='display-table float-table'>
        <h5><a href="/ranks/ffasurv">FFA Survivor Win Ratio</a></h5>
        <table>
            <tr>
                <th>Name</th>
                <th>Games</th>
            </tr>
            {ptcounters[ffasurv]}
        </table>
    </div>
    <div style="clear: both;"></div>
    <div class='display-table'>
        <h5><a href="/games">Latest Games</a></h5>
        <table>
            <tr>
                <th>ID</th>
                <th>Mode</th>
                <th>Mutators</th>
                <th>Server</th>
                <th>Map</th>
                <th>Duration</th>
                <th>Played</th>
            </tr>
            {recentgames}
        </table>
    </div>
    <div style="clear: both;"></div>
    """.format(recentgames=recentgames,
        ptcounters=ptcounters,
        topweapon="\n".join(topweapons),
        weapdpm="%s %s [%d DPM]" % (
            redeclipse().weaponimg(topweapons['dpm'][0]),
            alink('weapon', topweapons['dpm'][0], topweapons['dpm'][0]),
            topweapons['dpm'][1]),
        weapwield="%s %s [%d%%]" % (
            redeclipse().weaponimg(topweapons['wield'][0]),
            alink('weapon', topweapons['wield'][0], topweapons['wield'][0]),
            topweapons['wield'][1]
                / max(topweapons['totalwielded'], 1) * 100))
    return base.page(sel, ret, title="Overview")
Example #15
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)
Example #16
0
def game(sel):
    ret = ""
    gs = dbselectors.GameSelector()
    gs.copyfrom(sel)
    game = gs.single(sel.pathid)
    if game is None:
        ret = "<div class='center'><h2>No such game.</h2></div>"
    else:
        game["map"] = cgi.escape(game["map"])
        ss = dbselectors.ServerSelector()
        ss.copyfrom(sel)
        server = ss.single(game["server"])
        server["desc"] = cgi.escape(server["desc"])
        teamsstr = ""
        for team in game["teams"]:
            team = game["teams"][team]
            teamsstr += "<tr>"
            teamsstr += "<td>%s</td>" % cgi.escape(team["name"])
            teamsstr += "<td>%s</td>" % (dbselectors.scorestr(game, team["score"]))
            teamsstr += "</tr>"
        playersstr = ""
        for player in game["players"]:
            playersstr += "<tr>"
            playersstr += tdlinkp("player", player["handle"], player["name"])
            playersstr += "<td>%s</td>" % (dbselectors.scorestr(game, player["score"]))
            playersstr += tdlinkp("player", player["handle"], player["handle"])
            playersstr += "<td>%s</td>" % (timeutils.durstr(player["timealive"]))
            playersstr += "<td>%d</td>" % player["frags"]
            playersstr += "<td>%d</td>" % player["deaths"]
            playersstr += "</tr>"
        ret += """
        <div class="center">
            <h2>Game #{game[id]}: {modestr} on {mapstr}</h2>
            Duration: {duration}<br>
            Played: {agohtml}<br>
            Server: <a
            href="/display/server/{server[handle]}">{server[desc]}</a><br>
            <div class='display-table'>
                <h3>Teams</h3>
                <table>
                    <tr>
                        <th>Name</th>
                        <th>Score</th>
                    </tr>
                    {teams}
                </table>
            </div>
            <div class='display-table'>
                <h3>Players</h3>
                <table>
                    <tr>
                        <th>Name</th>
                        <th>Score</th>
                        <th>Handle</th>
                        <th>Alive</th>
                        <th>Frags</th>
                        <th>Deaths</th>
                    </tr>
                    {players}
                </table>
            </div>
        </div>
        """.format(
            modestr=alink("mode", game["mode"], dbselectors.modestr[game["mode"]]),
            mapstr=alink("map", game["map"], game["map"]),
            agohtml=timeutils.agohtml(game["time"]),
            duration=timeutils.durstr(game["timeplayed"]),
            game=game,
            server=server,
            teams=teamsstr,
            players=playersstr,
        )
    return base.page(sel, ret, title="Game %s" % sel.pathid)
Example #17
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)