Commit 95427309 authored by Zak Stephens's avatar Zak Stephens

Update routes to v2 to reflect incompatible API changes, add funny message censor.

parent 6c3c2394
const naughtyWords = require('./naughty-words.json');
module.exports = text =>
text
.split(/(\W)/)
.map(word => {
if (word.toLowerCase() in naughtyWords) {
let replacement = naughtyWords[word.toLowerCase()];
/* Match case to original word. Good for sentence-starting capitals. */
// If the whole word was capitalised, just capitalise the whole replacement.
if (word === word.toUpperCase()) {
return replacement.toUpperCase();
}
// Otherwise, match case character-by-character.
for (let i = 0; i < word.length; ++i) {
const originalCharacter = word.charAt(i);
const upperCase = (originalCharacter === originalCharacter.toUpperCase());
if (upperCase) {
replacement = replacement.substr(0, i) + replacement.charAt(i).toUpperCase() + replacement.substr(i+1);
}
}
return replacement;
}
return word;
})
.join('');
......@@ -12,6 +12,8 @@
"tileSize": 16,
"censorMessageContent": true,
"sqliteDatabaseFilePath": "db.sqlite3",
"port": 8000,
......
......@@ -51,10 +51,10 @@ const sqlite3 = require('sqlite3');
const app = express();
app.use(cors({ credentials: true, origin: true })); // Free love.
app.use('/api/v1/microtransactions', require('./routes/microtransactions'));
app.use('/api/v1/messages', require('./routes/messages')(gameState, playerRepository));
app.use('/api/v1/players', require('./routes/players')(gameState, playerRepository));
app.use('/api/v1/snapshot', require('./routes/snapshot')(gameState, playerRepository));
app.use('/api/v2/microtransactions', require('./routes/microtransactions'));
app.use('/api/v2/messages', require('./routes/messages')(gameState, playerRepository));
app.use('/api/v2/players', require('./routes/players')(gameState, playerRepository));
app.use('/api/v2/snapshot', require('./routes/snapshot')(gameState, playerRepository));
const options = {
cert: fs.readFileSync(config.get('tls.certFilePath')),
......
{
"ass": "butt",
"asshole": "poopy butt",
"bitch": "unsatisfied customer",
"cunt": "lady of esteem",
"cunts": "ladies of esteem",
"damn": "darn",
"damned": "darned",
"dammed": "darned",
"faggot": "one unsubscribed to notions of fashion",
"faggots": "those unsubscribed to notions of fashion",
"fuck": "frick",
"fucker": "fricker",
"fucks": "frickers",
"fucking": "fricking",
"god": "gosh",
"goddamn": "goshdarn",
"hell": "heck",
"motherfucker": "NEET",
"nigga": "gentleman scholar",
"nigger": "gentleman scholar",
"niggas": "gentlemen scholars",
"niggers": "gentlemen scholars",
"prick": "unsatisfied customer",
"shit": "poop",
"shitty": "poopy",
"slut": "experienced woman",
"sluts": "experienced women"
}
'use strict';
const censor = require('../censor');
const config = require('config');
const express = require('express');
const playerUtil = require('../player-util');
......@@ -44,6 +46,13 @@ module.exports = (gameState, playerRepository) => {
validatePostJsonSchema,
validatePostSender,
async (req, res, next) => (await playerUtil.basicAuthExpectPlayer(req.body.sender.username, playerRepository))(req, res, next),
(req, res, next) => {
if (config.get('censorMessageContent')) {
req.body.content = censor(req.body.content);
}
next();
},
(req, res) => {
gameState.messages.push({
sender: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment