summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/robots.txt2
-rw-r--r--server.js95
-rw-r--r--views/games_active.pug33
-rw-r--r--views/games_finished.pug15
-rw-r--r--views/games_public.pug (renamed from views/games.pug)4
-rw-r--r--views/header.pug4
-rw-r--r--views/index.pug2
-rw-r--r--views/info.pug2
-rw-r--r--views/profile.pug21
9 files changed, 129 insertions, 49 deletions
diff --git a/public/robots.txt b/public/robots.txt
index 0ba70da..d5c191c 100644
--- a/public/robots.txt
+++ b/public/robots.txt
@@ -1,5 +1,7 @@
User-agent: *
Disallow: /join
Disallow: /login
+Disallow: /signup
Disallow: /user
+Disallow: /games
Disallow: /*play*
diff --git a/server.js b/server.js
index 8b2a31d..9cc2a9c 100644
--- a/server.js
+++ b/server.js
@@ -250,7 +250,19 @@ const SQL_SELECT_USER_INFO = SQL(`
to_id = user_id
and is_read = 0
and is_deleted_from_inbox = 0
- ) as unread
+ ) as unread,
+ (
+ select
+ count(*)
+ from
+ players
+ join games using(game_id)
+ join game_state using(game_id)
+ where
+ status = 1
+ and players.user_id = users.user_id
+ and active in ( players.role, 'Both', 'All' )
+ ) as active
from
users
where user_id = ?
@@ -942,10 +954,22 @@ const QUERY_LIST_GAMES_OF_TITLE = SQL(`
LIMIT ?
`);
-const QUERY_LIST_GAMES_OF_USER = SQL(`
- SELECT * FROM game_view
- WHERE owner_id=$user_id OR game_id IN ( SELECT game_id FROM players WHERE players.user_id=$user_id )
- ORDER BY status ASC, mtime DESC
+const QUERY_LIST_ACTIVE_GAMES_OF_USER = SQL(`
+ select * from game_view
+ where
+ ( owner_id=$user_id or game_id in ( select game_id from players where players.user_id=$user_id ) )
+ and
+ ( status < 2 or mtime > datetime('now', '-7 days') )
+ order by status asc, mtime desc
+ `);
+
+const QUERY_LIST_FINISHED_GAMES_OF_USER = SQL(`
+ select * from game_view
+ where
+ ( owner_id=$user_id or game_id in ( select game_id from players where players.user_id=$user_id ) )
+ and
+ status = 2
+ order by status asc, mtime desc
`);
function is_active(game, players, user_id) {
@@ -1020,35 +1044,29 @@ function annotate_games(games, user_id) {
}
}
-app.get('/games', function (req, res) {
- let open_games = QUERY_LIST_GAMES.all(0);
- let active_games = QUERY_LIST_GAMES.all(1);
- if (req.user) {
- annotate_games(open_games, req.user.user_id);
- annotate_games(active_games, req.user.user_id);
- } else {
- annotate_games(open_games, 0);
- annotate_games(active_games, 0);
- }
- res.render('games.pug', {
+app.get('/profile', must_be_logged_in, function (req, res) {
+ req.user.notify = SQL_SELECT_USER_NOTIFY.get(req.user.user_id);
+ let avatar = get_avatar(req.user.mail);
+ res.render('profile.pug', {
user: req.user,
- open_games: open_games.filter(g => !g.is_ready),
- ready_games: open_games.filter(g => g.is_ready),
- active_games: active_games,
+ avatar: avatar,
});
});
-app.get('/profile', must_be_logged_in, function (req, res) {
+app.get('/games', function (req, res) {
+ res.redirect('/games/public');
+});
+
+app.get('/games/active', must_be_logged_in, function (req, res) {
req.user.notify = SQL_SELECT_USER_NOTIFY.get(req.user.user_id);
- let avatar = get_avatar(req.user.mail);
- let games = QUERY_LIST_GAMES_OF_USER.all({user_id: req.user.user_id});
+ let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({user_id: req.user.user_id});
annotate_games(games, req.user.user_id);
let open_games = games.filter(game => game.status === 0);
let active_games = games.filter(game => game.status === 1);
let finished_games = games.filter(game => game.status === 2);
- res.render('profile.pug', {
+ res.render('games_active.pug', {
+ title: "Your Active Games",
user: req.user,
- avatar: avatar,
open_games: open_games.filter(g => !g.is_ready),
ready_games: open_games.filter(g => g.is_ready),
active_games: active_games,
@@ -1056,6 +1074,35 @@ app.get('/profile', must_be_logged_in, function (req, res) {
});
});
+app.get('/games/finished', must_be_logged_in, function (req, res) {
+ req.user.notify = SQL_SELECT_USER_NOTIFY.get(req.user.user_id);
+ let games = QUERY_LIST_FINISHED_GAMES_OF_USER.all({user_id: req.user.user_id});
+ annotate_games(games, req.user.user_id);
+ res.render('games_finished.pug', {
+ title: "Your Finished Games",
+ user: req.user,
+ finished_games: games,
+ });
+});
+
+app.get('/games/public', function (req, res) {
+ let open_games = QUERY_LIST_GAMES.all(0);
+ let active_games = QUERY_LIST_GAMES.all(1);
+ if (req.user) {
+ annotate_games(open_games, req.user.user_id);
+ annotate_games(active_games, req.user.user_id);
+ } else {
+ annotate_games(open_games, 0);
+ annotate_games(active_games, 0);
+ }
+ res.render('games_public.pug', {
+ user: req.user,
+ open_games: open_games.filter(g => !g.is_ready),
+ ready_games: open_games.filter(g => g.is_ready),
+ active_games: active_games,
+ });
+});
+
app.get('/info/:title_id', function (req, res) {
return res.redirect('/' + req.params.title_id);
});
diff --git a/views/games_active.pug b/views/games_active.pug
new file mode 100644
index 0000000..768a92d
--- /dev/null
+++ b/views/games_active.pug
@@ -0,0 +1,33 @@
+//- vim:ts=4:sw=4:
+doctype html
+html
+ head
+ include head
+ title= title
+ if active_games.length > 0
+ meta(http-equiv="refresh" content=300)
+ body
+ include header
+ article
+ h1= title
+
+ if ready_games.length > 0
+ h2 Ready to start
+ +gametable(0,ready_games)
+
+ if open_games.length > 0
+ h2 Open
+ +gametable(0,open_games)
+
+ if active_games.length > 0
+ h2 Active
+ +gametable(1,active_games)
+
+ if finished_games.length > 0
+ h2 Recently finished
+ +gametable(2,finished_games)
+
+ p <a href="/games/finished">All finished games</a>
+
+ if open_games.length === 0 && ready_games.length === 0 && active_games.length === 0 && finished_games.length === 0
+ p Nothing here.
diff --git a/views/games_finished.pug b/views/games_finished.pug
new file mode 100644
index 0000000..9ae27c4
--- /dev/null
+++ b/views/games_finished.pug
@@ -0,0 +1,15 @@
+//- vim:ts=4:sw=4:
+doctype html
+html
+ head
+ include head
+ title= title
+ body
+ include header
+ article
+ h1= title
+
+ if finished_games.length > 0
+ +gametable(2,finished_games)
+ else
+ p Nothing here.
diff --git a/views/games.pug b/views/games_public.pug
index 14ea168..267c8f7 100644
--- a/views/games.pug
+++ b/views/games_public.pug
@@ -5,11 +5,11 @@ html
include head
title= SITE_NAME
if user
- meta(http-equiv="refresh" content=300)
+ meta(http-equiv="refresh" content=600)
body
include header
article
- h1= SITE_NAME
+ h1 All Public Games
h2 Open
+gametable(0, open_games)
diff --git a/views/header.pug b/views/header.pug
index 7eb357b..9d869f0 100644
--- a/views/header.pug
+++ b/views/header.pug
@@ -5,6 +5,10 @@ header
a(href="/about") About
a(href="/forum") Forum
if user
+ if user.active > 0
+ a(href="/games/active") Games (#{user.active})
+ else
+ a(href="/games/active") Games
if user.unread > 0
a(href="/inbox") Inbox (#{user.unread})
else
diff --git a/views/index.pug b/views/index.pug
index ec07e03..acfcbc2 100644
--- a/views/index.pug
+++ b/views/index.pug
@@ -45,6 +45,6 @@ html
+gamecover(title.title_id)
| #{title.title_name}
- p: a(href="/games") List of all open and active games.
+ p: a(href="/games/public") List of all open and active games.
p!= process.env.SITE_INVITE
diff --git a/views/info.pug b/views/info.pug
index 7c84dca..47367ab 100644
--- a/views/info.pug
+++ b/views/info.pug
@@ -6,7 +6,7 @@ html
+social(title.title_name, "Play " + title.title_name + " on the web.", title.title_id)
title= title.title_name
if user
- meta(http-equiv="refresh" content=300)
+ meta(http-equiv="refresh" content=600)
body
include header
article
diff --git a/views/profile.pug b/views/profile.pug
index 5c98743..fc9b36b 100644
--- a/views/profile.pug
+++ b/views/profile.pug
@@ -4,8 +4,6 @@ html
head
include head
title= SITE_NAME
- if active_games.length > 0
- meta(http-equiv="refresh" content=300)
body
include header
article
@@ -32,22 +30,3 @@ html
| &#xbb; <a href="/chat">Chat log</a>
br
| &#xbb; <a href="/logout">Logout</a>
-
- if ready_games.length > 0
- h2 Ready to start
- +gametable(0,ready_games)
-
- if open_games.length > 0
- h2 Open games
- +gametable(0,open_games)
-
- if active_games.length > 0
- h2 Active games
- +gametable(1,active_games)
-
- if finished_games.length > 0
- h2 Finished games
- +gametable(2,finished_games)
-
- if open_games.length === 0 && ready_games.length === 0 && active_games.length === 0 && finished_games.length === 0
- p You don't have any current or finished games.