Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lostcity/routes/about/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import Environment from '#lostcity/util/Environment.js';

export default function (f, opts, next) {
f.get('/', async (req, res) => {
return res.view('about/index');
return res.view('about/index', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/getstart', async (req, res) => {
return res.view('about/getstart');
return res.view('about/getstart', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/virtual', async (req, res) => {
return res.view('about/virtual');
return res.view('about/virtual', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/whatisrs', async (req, res) => {
return res.view('about/whatisrs');
return res.view('about/whatisrs', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

next();
Expand Down
7 changes: 6 additions & 1 deletion src/lostcity/routes/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { toDisplayName, toSafeName } from '#jagex2/jstring/JString.js';

import { db } from '#lostcity/db/query.js';

import Environment from '#lostcity/util/Environment.js';

enum CreateStep {
USERNAME,
TERMS,
Expand Down Expand Up @@ -37,22 +39,25 @@ export default function (f: any, opts: any, next: any) {
delete req.session.createUsername;

return res.view('create/username', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
error: createError
});
} else if (createStep === CreateStep.TERMS) {
return res.view('create/terms', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
username: createUsername
});
} else if (createStep === CreateStep.PASSWORD) {
return res.view('create/password', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
username: createUsername,
error: createError
});
} else if (createStep === CreateStep.FINISH) {
delete req.session.createStep;
delete req.session.createUsername;

return res.view('create/finish');
return res.view('create/finish', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/lostcity/routes/mod/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from '#lostcity/db/query.js';
import Environment from '#lostcity/util/Environment.js';

export default function (f: any, opts: any, next: any) {
f.get('/session/:username', async (req: any, res: any) => {
Expand All @@ -8,6 +9,7 @@ export default function (f: any, opts: any, next: any) {
const account = await db.selectFrom('account').where('username', '=', username).selectAll().executeTakeFirstOrThrow();

return res.view('mod/session', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
account,
logs: await db.selectFrom('account_session').where('account_id', '=', account.id).orderBy('timestamp desc').limit(100).selectAll().execute()
});
Expand Down
7 changes: 7 additions & 0 deletions src/lostcity/routes/news/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function (f: any, opts: any, next: any) {
newsposts = newsposts.limit(17);

return res.view('news/index', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
category,
page,
more,
Expand All @@ -78,6 +79,7 @@ export default function (f: any, opts: any, next: any) {
const next = await db.selectFrom('newspost').where('id', '>', req.params.id).where('category_id', '=', newspost.category_id).orderBy('id', 'asc').select('id').executeTakeFirst();

return res.view('news/post', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
newspost,
category,
date: niceDate(newspost.date),
Expand Down Expand Up @@ -105,6 +107,7 @@ export default function (f: any, opts: any, next: any) {
const newspost = await db.selectFrom('newspost').where('id', '=', post).selectAll().executeTakeFirst();
if (newspost) {
return res.view('news/create', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
categories,
date: niceDate(newspost.date),
post,
Expand All @@ -114,6 +117,7 @@ export default function (f: any, opts: any, next: any) {
}

return res.view('news/create', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
categories
});
});
Expand Down Expand Up @@ -160,6 +164,7 @@ export default function (f: any, opts: any, next: any) {
const categories = await db.selectFrom('newspost_category').selectAll().execute();

return res.view('news/create', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
categories,
post,
date: niceDate(new Date()),
Expand All @@ -183,6 +188,7 @@ export default function (f: any, opts: any, next: any) {
const newspost = await db.selectFrom('newspost').where('id', '=', post).selectAll().executeTakeFirst();
if (newspost) {
return res.view('news/create', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
categories,
post,
newspost,
Expand All @@ -195,6 +201,7 @@ export default function (f: any, opts: any, next: any) {
}

return res.view('news/create', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
categories,
post,
date: niceDate(new Date()),
Expand Down
2 changes: 2 additions & 0 deletions src/lostcity/routes/player/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from '#lostcity/db/query.js';
import Environment from '#lostcity/util/Environment.js';
import LoggerEventType from '#lostcity/util/LoggerEventType.js';

export default function (f: any, opts: any, next: any) {
Expand All @@ -9,6 +10,7 @@ export default function (f: any, opts: any, next: any) {
const account = await db.selectFrom('account').where('username', '=', username).selectAll().executeTakeFirstOrThrow();

return res.view('player/adventurelog', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
account,
logs: await db.selectFrom('account_session').where('account_id', '=', account.id).where('event_type', '=', LoggerEventType.ADVENTURE).orderBy('timestamp desc').limit(100).selectAll().execute()
});
Expand Down
18 changes: 10 additions & 8 deletions src/lostcity/routes/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import Environment from '#lostcity/util/Environment.js';

export default function (f, opts, next) {
f.get('/', async (req, res) => {
return res.view('index');
return res.view('index', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/disclaimer', async (req, res) => {
return res.view('disclaimer');
return res.view('disclaimer', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/title', async (req, res) => {
Expand All @@ -21,6 +21,7 @@ export default function (f, opts, next) {

const latestNews = Environment.DB_HOST ? await db.selectFrom('newspost').orderBy('id', 'desc').limit(5).selectAll().execute() : [];
return res.view('title', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
playerCount,
newsposts: latestNews
});
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function (f, opts, next) {
}

return res.view('serverlist', {
HTTPS_ENABLED: Environment.HTTPS_ENABLED,
detail: typeof req.query['hires.x'] !== 'undefined' ? 'high' : 'low',
method: req.query.method,
worlds: WorldList,
Expand All @@ -74,43 +76,43 @@ export default function (f, opts, next) {
});

f.get('/cookies', async (req, res) => {
return res.view('cookies');
return res.view('cookies', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/copyright', async (req, res) => {
return res.view('copyright');
});

f.get('/detail', async (req, res) => {
return res.view('detail');
return res.view('detail', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/manual', async (req, res) => {
return res.view('manual');
});

f.get('/privacy', async (req, res) => {
return res.view('privacy');
return res.view('privacy', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/support', async (req, res) => {
return res.view('support');
});

f.get('/terms', async (req, res) => {
return res.view('terms');
return res.view('terms', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/whychoosers', async (req, res) => {
return res.view('whychoosers');
return res.view('whychoosers', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

f.get('/worldmap', async (req, res) => {
return res.view('worldmap/applet');
});

f.get('/downloads', async (req, res) => {
return res.view('downloads');
return res.view('downloads', {HTTPS_ENABLED: Environment.HTTPS_ENABLED});
});

next();
Expand Down
29 changes: 29 additions & 0 deletions src/lostcity/util/dockerWorldsConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @fileoverview
* This script dynamically loads a world configuration file from the Server repo.
*
* Purpose:
* - This script loads worlds file dynamically from server repo
* - Its meant to be used only with docker production build
*
* Why?
* - You don't have to pull and modify Website repository just to configure your worlds
* - Simplifies running prod setup
* - Keeps the Server repo as the single source
*/

import fs from 'fs';
import path from 'path';
import worldConfig from '/usr/src/prodWorldsConf.js';

const filePath = path.resolve('/usr/src/app/data/config/worlds.json');

fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, JSON.stringify(worldConfig, null, 2));

console.log('[INFO] Worlds config generated! Much wow ');
console.log(`
(\\(\\
( -.-) ☆彡
o_(")(") You're a star!\n`
);
8 changes: 7 additions & 1 deletion view/_partial/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
<body bgcolor=black text="white" link=#90c040 alink=#90c040 vlink=#90c040 topmargin=0 leftmargin=0>
<% // https://stackoverflow.com/a/4723302 %>
<% // https://stackoverflow.com/a/6222280 %>
<img style="display: none;" src="https://2004scape.org/img/blank.gif" onload="if (location.protocol !== 'https:') { location.replace(`https:${location.href.substring(location.protocol.length)}`); }">
<% if (HTTPS_ENABLED) { %>
<img
style="display: none;"
src="https://2004scape.org/img/blank.gif"
onload="if (location.protocol !== 'https:') { location.replace(`https:${location.href.substring(location.protocol.length)}`); }"
>
<% } %>
<table width=100% height=100% cellpadding=0 cellspacing=0>
<tr>
<td valign=middle>
Expand Down