Skip to content

Commit

Permalink
Remove hardcoded URLs in favor of Config.routes (#5557)
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibo authored Jul 1, 2019
1 parent df083d7 commit a61c10e
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 78 deletions.
12 changes: 11 additions & 1 deletion config/config-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ exports.ssl = null;

/*
// example:
const fs = require('fs');
exports.ssl = {
port: 443,
options: {
Expand Down Expand Up @@ -136,6 +135,17 @@ Y929lRybWEiKUr+4Yw2O1W0CAwEAAQ==
-----END PUBLIC KEY-----
`;

/**
* routes - where Pokemon Showdown is hosted.
* Don't change this setting - there aren't any other options right now
*/
exports.routes = {
root: 'pokemonshowdown.com',
client: 'play.pokemonshowdown.com',
dex: 'dex.pokemonshowdown.com',
replays: 'replay.pokemonshowdown.com',
};

/**
* crashguardemail - if the server has been running for more than an hour
* and crashes, send an email using these settings, rather than locking down
Expand Down
2 changes: 1 addition & 1 deletion data/mods/ssb/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ let BattleStatuses = {
this.add(`c|@Morfent ( _̀> ̀)|Every 60 seconds in Africa, a minute passes. Together we can stop this. Please spread the word.`);
} else {
this.add(`c|@Morfent ( _̀> ̀)|!dt morfent's husbando`);
this.add(`raw|<ul class="utilichart"><li class="result"><span class="col numcol">UU</span> <span class="col iconcol"><span class="picon" style="background: transparent url(&quot;//play.pokemonshowdown.com/sprites/smicons-sheet.png?a4&quot;) no-repeat scroll -400px -210px"></span></span> <span class="col pokemonnamecol" style="white-space: nowrap"><a href="https://pokemonshowdown.com/dex/pokemon/gengar" target="_blank" rel="noopener">Gengar</a></span> <span class="col typecol"><img src="https://play.pokemonshowdown.com/sprites/types/Ghost.png" alt="Ghost" height="14" width="32"><img src="https://play.pokemonshowdown.com/sprites/types/Poison.png" alt="Poison" height="14" width="32"></span> <span style="float: left ; min-height: 26px"><span class="col abilitycol">Cursed Body</span><span class="col abilitycol"></span></span><span style="float: left ; min-height: 26px"><span class="col statcol"><em>HP</em><br>60</span> <span class="col statcol"><em>Atk</em><br>65</span> <span class="col statcol"><em>Def</em><br>60</span> <span class="col statcol"><em>SpA</em><br>130</span> <span class="col statcol"><em>SpD</em><br>75</span> <span class="col statcol"><em>Spe</em><br>110</span> <span class="col bstcol"><em>BST<br>500</em></span> </span></li><li style="clear: both"></li></ul>`);
this.add(`raw|<ul class="utilichart"><li class="result"><span class="col numcol">UU</span> <span class="col iconcol"><span class="picon" style="background: transparent url(&quot;//${Config.routes.client}/sprites/smicons-sheet.png?a4&quot;) no-repeat scroll -400px -210px"></span></span> <span class="col pokemonnamecol" style="white-space: nowrap"><a href="https://${Config.routes.dex}/pokemon/gengar" target="_blank" rel="noopener">Gengar</a></span> <span class="col typecol"><img src="https://${Config.routes.client}/sprites/types/Ghost.png" alt="Ghost" height="14" width="32"><img src="https://${Config.routes.client}/sprites/types/Poison.png" alt="Poison" height="14" width="32"></span> <span style="float: left ; min-height: 26px"><span class="col abilitycol">Cursed Body</span><span class="col abilitycol"></span></span><span style="float: left ; min-height: 26px"><span class="col statcol"><em>HP</em><br>60</span> <span class="col statcol"><em>Atk</em><br>65</span> <span class="col statcol"><em>Def</em><br>60</span> <span class="col statcol"><em>SpA</em><br>130</span> <span class="col statcol"><em>SpD</em><br>75</span> <span class="col statcol"><em>Spe</em><br>110</span> <span class="col bstcol"><em>BST<br>500</em></span> </span></li><li style="clear: both"></li></ul>`);
this.add(`raw|<font size="1"><font color="#686868">Dex#:</font> 94&nbsp;| <font color="#686868">Gen:</font> 1&nbsp;| <font color="#686868">Height:</font> 1.5 m&nbsp;| <font color="#686868">Weight:</font> 40.5 kg <em>(60 BP)</em>&nbsp;| <font color="#686868">Dex Colour:</font> Purple&nbsp;| <font color="#686868">Egg Group(s):</font> Amorphous&nbsp;| <font color="#686868">Does Not Evolve</font></font>`);
}
},
Expand Down
8 changes: 4 additions & 4 deletions server/chat-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ const commands = {
user.avatar = avatar;
let avatarUrl = avatar.startsWith('#') ? `trainers-custom/${avatar.slice(1)}.png` : `trainers/${avatar}.png`;
if (!parts[1]) {
this.sendReply(`Avatar changed to:\n|raw|<img src="//play.pokemonshowdown.com/sprites/${avatarUrl}" alt="${avatar}" width="80" height="80" />`);
this.sendReply(`Avatar changed to:\n|raw|<img src="//${Config.routes.client}/sprites/${avatarUrl}" alt="${avatar}" width="80" height="80" />`);
}
},
avatarhelp: [`/avatar [avatar number 1 to 293] - Change your trainer sprite.`],
Expand Down Expand Up @@ -852,7 +852,7 @@ const commands = {
modjoin: parent ? null : '+',
parentid: parent,
auth: {},
introMessage: `<div style="text-align: center"><table style="margin:auto;"><tr><td><img src="//play.pokemonshowdown.com/fx/groupchat.png" width=120 height=100></td><td><h2>${titleMsg}</h2><p>Follow the <a href="/rules">Pokémon Showdown Global Rules</a>!<br>Don't be disruptive to the rest of the site.</p></td></tr></table></div>`,
introMessage: `<div style="text-align: center"><table style="margin:auto;"><tr><td><img src="//${Config.routes.client}/fx/groupchat.png" width=120 height=100></td><td><h2>${titleMsg}</h2><p>Follow the <a href="/rules">Pokémon Showdown Global Rules</a>!<br>Don't be disruptive to the rest of the site.</p></td></tr></table></div>`,
staffMessage: `<p>Groupchats are temporary rooms, and will expire if there hasn't been any activity in 40 minutes.</p><p>You can invite new users using <code>/invite</code>. Be careful with who you invite!</p><p>Commands: <button class="button" name="send" value="/roomhelp">Room Management</button> | <button class="button" name="send" value="/roomsettings">Room Settings</button> | <button class="button" name="send" value="/tournaments help">Tournaments</button></p><p>As creator of this groupchat, <u>you are entirely responsible for what occurs in this chatroom</u>. Global rules apply at all times.</p><p>If this room is used to break global rules or disrupt other areas of the server, <strong>you as the creator will be held accountable and punished</strong>.</p>`,
});
if (targetRoom) {
Expand Down Expand Up @@ -1746,7 +1746,7 @@ const commands = {
if (!target) return this.parse('/help join');
if (target.startsWith('http://')) target = target.slice(7);
if (target.startsWith('https://')) target = target.slice(8);
if (target.startsWith('play.pokemonshowdown.com/')) target = target.slice(25);
if (target.startsWith(`${Config.routes.client}/`)) target = target.slice(Config.routes.client.length + 1);
if (target.startsWith('psim.us/')) target = target.slice(8);
user.tryJoinRoom(target, connection).then(ret => {
if (ret === Rooms.RETRY_AFTER_LOGIN) {
Expand Down Expand Up @@ -2824,7 +2824,7 @@ const commands = {
if (!reason) {
return this.errorReply(`Battle bans require a reason.`);
}
const includesUrl = reason.includes('.pokemonshowdown.com/'); // lgtm [js/incomplete-url-substring-sanitization]
const includesUrl = reason.includes(`.${Config.routes.root}/`); // lgtm [js/incomplete-url-substring-sanitization]
if (!room.battle && !includesUrl && cmd !== 'forcebattleban') {
return this.errorReply(`Battle bans require a battle replay if used outside of a battle; if the battle has expired, use /forcebattleban.`);
}
Expand Down
8 changes: 4 additions & 4 deletions server/chat-plugins/datasearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ function runDexsearch(target, cmd, canAll, message) {
notShown = results.length - RESULTS_MAX_LENGTH;
results = results.slice(0, RESULTS_MAX_LENGTH);
}
resultsStr += results.map(result => `<a href="//dex.pokemonshowdown.com/pokemon/${toID(result)}" target="_blank" class="subtle" style="white-space:nowrap"><psicon pokemon="${result}" style="vertical-align:-7px;margin:-2px" />${result}</a>`).join(", ");
resultsStr += results.map(result => `<a href="//${Config.routes.dex}/pokemon/${toID(result)}" target="_blank" class="subtle" style="white-space:nowrap"><psicon pokemon="${result}" style="vertical-align:-7px;margin:-2px" />${result}</a>`).join(", ");
if (notShown) {
resultsStr += `, and ${notShown} more. <span style="color:#999999;">Redo the search with ', all' at the end to show all results.</span>`;
}
Expand Down Expand Up @@ -1303,7 +1303,7 @@ function runMovesearch(target, cmd, canAll, message) {
results = results.slice(0, RESULTS_MAX_LENGTH);
}
resultsStr += results.map(result =>
`<a href="//dex.pokemonshowdown.com/moves/${toID(result)}" target="_blank" class="subtle" style="white-space:nowrap">${result}</a>` +
`<a href="//${Config.routes.dex}/moves/${toID(result)}" target="_blank" class="subtle" style="white-space:nowrap">${result}</a>` +
(sort ? ' (' + (dex[toID(result)][sort.slice(0, -1)] === true ? '-' : dex[toID(result)][sort.slice(0, -1)]) + ')' : '')
).join(", ");
if (notShown) {
Expand Down Expand Up @@ -1515,7 +1515,7 @@ function runItemsearch(target, cmd, canAll, message) {
notShown = foundItems.length - RESULTS_MAX_LENGTH;
foundItems = foundItems.slice(0, RESULTS_MAX_LENGTH);
}
resultsStr += foundItems.map(result => `<a href="//dex.pokemonshowdown.com/items/${toID(result)}" target="_blank" class="subtle" style="white-space:nowrap"><psicon item="${result}" style="vertical-align:-7px" />${result}</a>`).join(", ");
resultsStr += foundItems.map(result => `<a href="//${Config.routes.dex}/items/${toID(result)}" target="_blank" class="subtle" style="white-space:nowrap"><psicon item="${result}" style="vertical-align:-7px" />${result}</a>`).join(", ");
if (notShown) {
resultsStr += `, and ${notShown} more. <span style="color:#999999;">Redo the search with ', all' at the end to show all results.</span>`;
}
Expand Down Expand Up @@ -1694,7 +1694,7 @@ const PM = new QueryProcessManager(module, async query => {

if (!PM.isParentProcess) {
// This is a child process!
global.Config = require('../../config/config');
global.Config = require('../../.server-dist/config-loader').Config;
// @ts-ignore ???
global.Monitor = {
/**
Expand Down
2 changes: 1 addition & 1 deletion server/chat-plugins/hangman.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Hangman extends Rooms.RoomGame {
}

hangingMan() {
return `<img width="120" height="120" src="//play.pokemonshowdown.com/fx/hangman${this.incorrectGuesses === -1 ? 7 : this.incorrectGuesses}.png" />`;
return `<img width="120" height="120" src="//${Config.routes.client}/fx/hangman${this.incorrectGuesses === -1 ? 7 : this.incorrectGuesses}.png" />`;
}

generateWindow() {
Expand Down
16 changes: 8 additions & 8 deletions server/chat-plugins/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,10 @@ const commands = {
}[move.target] || "Unknown";

if (move.id === 'snatch' && mod.gen >= 3) {
details['<a href="https://pokemonshowdown.com/dex/moves/snatch">Snatchable Moves</a>'] = '';
details['<a href="https://${Config.routes.dex}/moves/snatch">Snatchable Moves</a>'] = '';
}
if (move.id === 'mirrormove') {
details['<a href="https://pokemonshowdown.com/dex/moves/mirrormove">Mirrorable Moves</a>'] = '';
details['<a href="https://${Config.routes.dex}/moves/mirrormove">Mirrorable Moves</a>'] = '';
}
if (move.isUnreleased) {
details["Unreleased in Gen " + mod.gen] = "";
Expand Down Expand Up @@ -983,7 +983,7 @@ const commands = {
let buffer = '<div class="scrollable"><table cellpadding="1" width="100%"><tr><th></th>';
let icon = {};
for (let type in mod.data.TypeChart) {
icon[type] = '<img src="https://play.pokemonshowdown.com/sprites/types/' + type + '.png" width="32" height="14">';
icon[type] = `<img src="https://${Config.routes.client}/sprites/types/' + type + '.png" width="32" height="14">`;
// row of icons at top
buffer += '<th>' + icon[type] + '</th>';
}
Expand Down Expand Up @@ -1441,7 +1441,7 @@ const commands = {
`- We log PMs so you can report them - staff can't look at them without permission unless there's a law enforcement reason.<br />` +
`- We log IPs to enforce bans and mutes.<br />` +
`- We use cookies to save your login info and teams, and for Google Analytics and AdSense.<br />` +
`- For more information, you can read our <a href="https://pokemonshowdown.com/privacy">full privacy policy.</a>`
`- For more information, you can read our <a href="https://${Config.routes.root}/privacy">full privacy policy.</a>`
);
},

Expand Down Expand Up @@ -1555,7 +1555,7 @@ const commands = {
}
this.sendReplyBox(
`Pok&eacute;mon Showdown! damage calculator. (Courtesy of Honko &amp; Austin)<br />` +
`- <a href="https://pokemonshowdown.com/damagecalc/">Damage Calculator</a>`
`- <a href="https://${Config.routes.root}/damagecalc/">Damage Calculator</a>`
);
},
calchelp: [
Expand Down Expand Up @@ -1796,7 +1796,7 @@ const commands = {
this.sendReplyBox(
`${room ? this.tr("Please follow the rules:") + '<br />' : ``}` +
(room && room.rulesLink ? Chat.html`- <a href="${room.rulesLink}">${this.tr `${room.title} room rules`}</a><br />` : ``) +
`- <a href="${this.tr('https://pokemonshowdown.com/rules')}">${this.tr("Global Rules")}</a>`
`- <a href="${this.tr('https://${Config.routes.root}/rules')}">${this.tr("Global Rules")}</a>`
);
return;
}
Expand Down Expand Up @@ -1853,7 +1853,7 @@ const commands = {
buffer.push(`<a href="https://www.smogon.com/forums/threads/3508013/">What is COIL?</a>`);
}
if (showAll || target === 'ladder' || target === 'ladderhelp' || target === 'decay') {
buffer.push(`<a href="https://pokemonshowdown.com/pages/ladderhelp">How the ladder works</a>`);
buffer.push(`<a href="https://${Config.routes.root}/pages/ladderhelp">How the ladder works</a>`);
}
if (showAll || target === 'tiering' || target === 'tiers' || target === 'tier') {
buffer.push(`<a href="https://www.smogon.com/ingame/battle/tiering-faq">Tiering FAQ</a>`);
Expand All @@ -1862,7 +1862,7 @@ const commands = {
buffer.push(`<a href="https://www.smogon.com/badge_faq">Badge FAQ</a>`);
}
if (showAll || target === 'rng') {
buffer.push(`<a href="https://pokemonshowdown.com/pages/rng">How Pokémon Showdown's RNG works</a>`);
buffer.push(`<a href="https://${Config.routes.root}/pages/rng">How Pokémon Showdown's RNG works</a>`);
}
if (showAll || !buffer.length) {
buffer.unshift(`<a href="https://www.smogon.com/forums/posts/6774128/">Frequently Asked Questions</a>`);
Expand Down
Loading

0 comments on commit a61c10e

Please sign in to comment.