commit 805beac1
Add recent games
Changed files
| M | src/oastat_static_web_generator.cpp before |
| M | templates/game.tpl before |
| M | templates/index.tpl before |
diff --git a/src/oastat_static_web_generator.cpp b/src/oastat_static_web_generator.cpp
index b894d8d..188faba 100644
--- a/src/oastat_static_web_generator.cpp
+++ b/src/oastat_static_web_generator.cpp
@@ -216,6 +216,28 @@ OastatPlayer getPlayer(cppdb::session& database, int playerid) {
return ret;
}
+struct OastatGame {
+ int gamenumber = 0;
+ int gametype = 0;
+ std::string mapname;
+ tm time = {};
+ std::string basegame;
+ int second = 0;
+ std::string servername;
+};
+
+void getRecentGames(cppdb::session& database, std::vector<OastatGame>& games) {
+ std::string sql = "select gamenumber, gametype, mapname, time, basegame, second, servername from oastat.oastat_games order by gamenumber desc limit 10";
+ cppdb::statement st = database.prepare(sql);
+ cppdb::result res = st.query();
+ while(res.next()) {
+ OastatGame game;
+ res >> game.gamenumber >> game.gametype >> game.mapname >> game.time >> game.basegame >> game.second >> game.servername;
+ write_html_game(database, game.gamenumber);
+ games.push_back(game);
+ }
+}
+
void write_html_game(cppdb::session& database, int game_number) {
ctemplate::TemplateDictionary game_tpl("templates/game.tpl");
game_tpl.SetValue("GENERATION_DATE", timestamp_now_as_string(database));
@@ -235,6 +257,8 @@ void write_html_index(cppdb::session& database) {
populate_player_deaths(database, player_list);
populate_player_awards(database, player_list);
populate_player_kills(database, player_list);
+ std::vector<OastatGame> games;
+ getRecentGames(database, games);
for (size_t i = 0; i < player_list.size(); ++i) {
OastatPlayer p = getPlayer(database, player_list.at(i));
ctemplate::TemplateDictionary* sub_dict = index_tpl.AddSectionDictionary("PLAYER_LIST");
@@ -280,6 +304,15 @@ void write_html_index(cppdb::session& database) {
sub_dict->SetValue("TIMES_PLAYED", std::to_string(info.times_played));
sub_dict->SetValue("LAST_PLAYED", getTimeStamp(info.last_played));
}
+ for (size_t i = 0; i < games.size(); ++i) {
+ const OastatGame& game = games[i];
+ ctemplate::TemplateDictionary* sub_dict = index_tpl.AddSectionDictionary("RECENT_GAMES");
+ sub_dict->SetValue("EVEN_LINE", (i%2)?"1":"0");
+ sub_dict->SetValue("GAMENUMBER", std::to_string(game.gamenumber) );
+ sub_dict->SetValue("MAPNAME", game.mapname);
+ sub_dict->SetValue("TIME", getTimeStamp(game.time));
+ sub_dict->SetValue("SERVERNAME", game.servername);
+ }
std::string output;
ctemplate::ExpandTemplate("templates/index.tpl", ctemplate::DO_NOT_STRIP, &index_tpl, &output);
std::ofstream myfile;
diff --git a/templates/game.tpl b/templates/game.tpl
index 72f0d47..8d4e787 100644
--- a/templates/game.tpl
+++ b/templates/game.tpl
@@ -6,8 +6,9 @@
<meta http-equiv="Content-Language" content="en">
<meta name="description" content="OpenArena stats by oastats">
<meta rel="stylesheet" href="../static/css/oastat.css" type="text/css">
- <title>OpenArena Stats - {{GAME_NUMBER}}</title>
+ <title>OpenArena Stats - Game {{GAME_NUMBER}}</title>
</head>
<body>
+ <div class="intro">OpenArena Stats - Game {{GAME_NUMBER}}</div>
</body>
</html>
diff --git a/templates/index.tpl b/templates/index.tpl
index 11cec69..06856d2 100644
--- a/templates/index.tpl
+++ b/templates/index.tpl
@@ -92,12 +92,30 @@
</tr>
{{#MAP_LIST}}
<tr>
- <td><div class="jugador{{EVEN_LINE}}">{{MAP_NAME}}</div></td>
+ <td><div class="dato{{EVEN_LINE}}">{{MAP_NAME}}</div></td>
<td><div class="dato{{EVEN_LINE}}">{{TIMES_PLAYED}}</div></td>
<td><div class="dato{{EVEN_LINE}}">{{LAST_PLAYED}}</div></td>
</tr>
{{/MAP_LIST}}
</table>
+
+<table class="tabladatos">
+<tr>
+<TH><DIV class="tituloup">Game</DIV></TH>
+<TH><DIV class="tituloup">Map</DIV></TH>
+<TH><DIV class="tituloup">Played at</DIV></TH>
+<TH><DIV class="tituloup">Server name</DIV></TH>
+</tr>
+{{#RECENT_GAMES}}
+<tr>
+ <td><div class="dato{{EVEN_LINE}}"><a class="dato{{EVEN_LINE}}" href="game/{{GAMENUMBER}}.html">{{GAMENUMBER}}</a></div></td>
+ <td><div class="dato{{EVEN_LINE}}">{{MAPNAME}}</div></td>
+ <td><div class="dato{{EVEN_LINE}}">{{TIME}}</div></td>
+ <td><div class="dato{{EVEN_LINE}}">{{SERVERNAME}}</div></td>
+</tr>
+{{/RECENT_GAMES}}
+</table>
+
</DIV>
</DIV>
</BODY>