From 7573b2b88f103e50ac8e2935ed848edcb92ba682 Mon Sep 17 00:00:00 2001 From: Billy Bryant <3013565+billyjbryant@users.noreply.github.com> Date: Tue, 29 Dec 2020 22:13:47 -0800 Subject: [PATCH 1/5] Enhancing Default Page layout, adding Discord Guild Details for Private Servers --- package.json | 1 + src/index.ts | 34 ++++++++++++++------- views/index.pug | 80 ++++++++++++++++++++++++++++++++++++++----------- yarn.lock | 12 ++++++++ 4 files changed, 99 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 6f7cb1b..95c1dd9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "main": "index.js", "license": "GPL-3.0-or-later", "dependencies": { + "axios": "^0.21.1", "express": "^4.17.1", "morgan": "^1.10.0", "pug": "^3.0.0", diff --git a/src/index.ts b/src/index.ts index d5ae0ab..502de73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,13 +6,15 @@ import { join } from 'path'; import socketIO from 'socket.io'; import Tracer from 'tracer'; import morgan from 'morgan'; +import axios from 'axios'; const supportedCrewLinkVersions = new Set(['1.2.0']); const httpsEnabled = !!process.env.HTTPS; const port = process.env.PORT || (httpsEnabled ? '443' : '9736'); - +const name = process.env.NAME || "CrewLink Server"; const sslCertificatePath = process.env.SSLPATH || process.cwd(); +const guildId = process.env.GUILD || null; const logger = Tracer.colorConsole({ format: "{{timestamp}} <{{title}}> {{message}}" @@ -28,6 +30,14 @@ if (httpsEnabled) { } else { server = new Server(app); } + +async function getDiscord(guildId:string=null) { + if (guildId) { + const response = await axios.get(`https://discord.com/api/guilds/${guildId}/widget.json`) + return (response.data) ? response.data : null; + } +} + const io = socketIO(server); const clients = new Map(); @@ -52,8 +62,9 @@ if (!address) { process.exit(1); } -app.get('/', (_, res) => { - res.render('index', { connectionCount, address }); +app.get('/', async (_, res) => { + const discord = await getDiscord(guildId); + res.render('index', { name, connectionCount, address, discord }); }); app.get('/health', (req, res) => { @@ -91,7 +102,7 @@ io.on('connection', (socket: socketIO.Socket) => { socket.on('join', (c: string, id: number, clientId: number) => { if (typeof c !== 'string' || typeof id !== 'number' || typeof clientId !== 'number') { socket.disconnect(); - logger.error(`Socket %s sent invalid join command: %s %d %d`, socket.id, c, id, clientId); + logger.error(`Socket ${socket.id} sent invalid join command: ${c} ${id} ${clientId}`); return; } @@ -101,7 +112,7 @@ io.on('connection', (socket: socketIO.Socket) => { for (let s of socketsInLobby) { if (clients.has(s) && clients.get(s).clientId === clientId) { socket.disconnect(); - logger.error(`Socket %s sent invalid join command, attempted spoofing another client`); + logger.error(`Socket ${socket.id} sent invalid join command, attempted spoofing another client`); return; } if (s !== socket.id) @@ -120,13 +131,13 @@ io.on('connection', (socket: socketIO.Socket) => { socket.on('id', (id: number, clientId: number) => { if (typeof id !== 'number' || typeof clientId !== 'number') { socket.disconnect(); - logger.error(`Socket %s sent invalid id command: %d %d`, socket.id, id, clientId); + logger.error(`Socket ${socket.id} sent invalid id command: ${id} ${clientId}`); return; } let client = clients.get(socket.id); if (client != null && client.clientId != null && client.clientId !== clientId) { socket.disconnect(); - logger.error(`Socket %s sent invalid id command, attempted spoofing another client`); + logger.error(`Socket ${socket.id} sent invalid id command, attempted spoofing another client`); return; } client = { @@ -148,7 +159,7 @@ io.on('connection', (socket: socketIO.Socket) => { socket.on('signal', (signal: Signal) => { if (typeof signal !== 'object' || !signal.data || !signal.to || typeof signal.to !== 'string') { socket.disconnect(); - logger.error(`Socket %s sent invalid signal command: %j`, socket.id, signal); + logger.error(`Socket ${socket.id} sent invalid signal command: ${signal}`); return; } const { to, data } = signal; @@ -161,12 +172,15 @@ io.on('connection', (socket: socketIO.Socket) => { socket.on('disconnect', () => { clients.delete(socket.id); connectionCount--; - logger.info("Total connected: %d", connectionCount); + logger.info(`Total connected: ${connectionCount}`); }) }) server.listen(port); (async () => { - logger.info('CrewLink Server started: %s', address); + logger.info(`CrewLink Server started: ${address}:${port}`); + (httpsEnabled) ? logger.info(`SSL Certificate Path: ${sslCertificatePath}`) : null; + logger.info(`Server Name: ${name}`); + logger.info(`Discord Guild Id: ${guildId}`); })(); \ No newline at end of file diff --git a/views/index.pug b/views/index.pug index aa1d301..33737f3 100644 --- a/views/index.pug +++ b/views/index.pug @@ -1,22 +1,27 @@ doctype html head - title CrewLink Server + title #{name} link(rel="icon", href="https://github.com/ottomated/CrewLink/raw/master/logo.png", type="image/x-icon") - meta(property='og:title' content='CrewLink Server') + meta(property='og:title' content='RMDash.fr CrewLink Server') meta(property='og:description' content='Voice server for Among Us proximity chat') meta(property='og:image' content='https://github.com/ottomated/CrewLink/raw/master/logo.png') style. + html, body { + height: 100%; + } body { - background-color: #23272a; - color: white; - font-family: sans-serif; - text-align: center; + background: #23272a url('https://wallpapercave.com/wp/wp7864479.png') no-repeat fixed center; + color: white; + font-family: sans-serif; + text-align: center; + display: flex; + flex-direction: column; } img { - height: 128px; - width: 128px; - margin: 32px auto; - display: block; + height: 128px; + width: 128px; + margin: 32px auto; + display: block; } a { text-decoration: none; @@ -25,11 +30,50 @@ head a:hover { text-decoration: underline; } -img(src="https://github.com/ottomated/CrewLink/raw/master/logo.png") -h1 CrewLink Server -p This is a CrewLink Server running on #{address}. -p There #{connectionCount === 1 ? 'is' : 'are'} currently #{connectionCount} connected user#{connectionCount === 1 ? '' : 's'}. -p - | To launch your own server, - a(href="https://github.com/ottomated/CrewLink-server", target="_blank") click here - | . \ No newline at end of file + #wrapper { + flex: 1 0 auto; + } + #details, #discord, #download { + background-color: rgba(40, 40, 40, 0.7); + border-radius: 10px; + border-color: rgba(48,48,48, 0.8); + border-width: 1px; + width: 600px; + display: block; + margin: 20px auto; + padding: 20px; + } + #footer { + min-width: 100%; + flex-shrink: 0; + background-color: rgb(30,30,30); + padding: 20px; + } + +#wrapper + img(src="https://github.com/ottomated/CrewLink/raw/master/logo.png") + #details + h1 #{name} + p This is a CrewLink Server running on #{address}. + p There #{connectionCount === 1 ? 'is' : 'are'} currently #{connectionCount} connected user#{connectionCount === 1 ? '' : 's'}. + + if discord + console.log(`Discord Name: ${discord.name} - ${discord.instant_invite}`) + #discord + p To find out more, join the + | + br + a(href=discord.instant_invite, target="_blank", rel="noopener noreferrer nofollow") #[b #{discord.name}] + | + br + | Discord Server! + + #download + p + a(href="https://github.com/ottomated/CrewLink/releases/latest", target="_blank", rel="noopener noreferrer nofollow") Download CrewLink from GitHub! + +#footer + footer Copyright © #{new Date().getFullYear()}. #{name} + | | CrewLink & CrewLink-Server created by + a(href="https://ottomated.net/", target="_blank", rel="noopener noreferrer nofollow") Ottomated + | | Distributed under the GNU General Public License v3.0. diff --git a/yarn.lock b/yarn.lock index 49fbdf8..aa9a492 100644 --- a/yarn.lock +++ b/yarn.lock @@ -148,6 +148,13 @@ async-limiter@~1.0.0: resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd" integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ== +axios@^0.21.1: + version "0.21.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== + dependencies: + follow-redirects "^1.10.0" + babel-walk@3.0.0-canary-5: version "3.0.0-canary-5" resolved "https://registry.yarnpkg.com/babel-walk/-/babel-walk-3.0.0-canary-5.tgz#f66ecd7298357aee44955f235a6ef54219104b11" @@ -442,6 +449,11 @@ finalhandler@~1.1.2: statuses "~1.5.0" unpipe "~1.0.0" +follow-redirects@^1.10.0: + version "1.13.1" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.1.tgz#5f69b813376cee4fd0474a3aba835df04ab763b7" + integrity sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg== + forwarded@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" From 391c6a700123ad2b8be3cb8a81ef497fec194fd5 Mon Sep 17 00:00:00 2001 From: Billy Bryant <3013565+billyjbryant@users.noreply.github.com> Date: Tue, 29 Dec 2020 22:29:46 -0800 Subject: [PATCH 2/5] Made Discord Console Log only show if GUILD is provided --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 502de73..6e3e4d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -182,5 +182,5 @@ server.listen(port); logger.info(`CrewLink Server started: ${address}:${port}`); (httpsEnabled) ? logger.info(`SSL Certificate Path: ${sslCertificatePath}`) : null; logger.info(`Server Name: ${name}`); - logger.info(`Discord Guild Id: ${guildId}`); + (guildId) ? logger.info(`Discord Guild Id: ${guildId}`) : null; })(); \ No newline at end of file From 82a97399741856f0b828836e919b94597cad4e47 Mon Sep 17 00:00:00 2001 From: Billy Bryant <3013565+billyjbryant@users.noreply.github.com> Date: Tue, 29 Dec 2020 22:44:30 -0800 Subject: [PATCH 3/5] Adding ull response to getDiscord() if guildId not provided --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 6e3e4d0..ce802a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,7 +35,7 @@ async function getDiscord(guildId:string=null) { if (guildId) { const response = await axios.get(`https://discord.com/api/guilds/${guildId}/widget.json`) return (response.data) ? response.data : null; - } + } else { return null } } const io = socketIO(server); From 8b29d7988ae148636d1540cd1d5a59525737bbc1 Mon Sep 17 00:00:00 2001 From: Billy Bryant <3013565+billyjbryant@users.noreply.github.com> Date: Wed, 30 Dec 2020 12:39:53 -0800 Subject: [PATCH 4/5] Fixing branding issue in index.pug --- views/index.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.pug b/views/index.pug index 33737f3..c609861 100644 --- a/views/index.pug +++ b/views/index.pug @@ -2,7 +2,7 @@ doctype html head title #{name} link(rel="icon", href="https://github.com/ottomated/CrewLink/raw/master/logo.png", type="image/x-icon") - meta(property='og:title' content='RMDash.fr CrewLink Server') + meta(property='og:title' content='CrewLink Server') meta(property='og:description' content='Voice server for Among Us proximity chat') meta(property='og:image' content='https://github.com/ottomated/CrewLink/raw/master/logo.png') style. From 3326d8e1fecb9beab67a35941dfbdee842b5f253 Mon Sep 17 00:00:00 2001 From: Billy Bryant <3013565+billyjbryant@users.noreply.github.com> Date: Wed, 30 Dec 2020 12:50:18 -0800 Subject: [PATCH 5/5] Moving background to github repo for hosting --- views/index.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.pug b/views/index.pug index c609861..590953a 100644 --- a/views/index.pug +++ b/views/index.pug @@ -10,7 +10,7 @@ head height: 100%; } body { - background: #23272a url('https://wallpapercave.com/wp/wp7864479.png') no-repeat fixed center; + background: #23272a url('https://github.com/ottomated/CrewLink-Server/background.png') no-repeat fixed center; color: white; font-family: sans-serif; text-align: center;