Fix a validation error caused by jquery munging urls

This commit is contained in:
Eric Fredricksen
2021-12-09 09:40:53 -08:00
committed by Eric Fredricksen
parent 09a5e8479b
commit 13e0640280
2 changed files with 10900 additions and 10 deletions
Vendored
+10881 -2
View File
File diff suppressed because one or more lines are too long
+19 -8
View File
@@ -1174,6 +1174,19 @@ function LFSR(pt, salt) {
return result; return result;
} }
function StandardizeUrl(url) {
// This shit fucks up some special characters. JQuery is going to do this anyway so
// we need it standardized before we compute a validator.
let a = document.createElement('a');
a.href = url;
return a.href;
// TODO we could probably remove all those UrlEncode's before this is called
}
function Validator(url) {
url = url.substr(url.indexOf("cmd="));
return IntToStr(LFSR(url, game.online.passkey));
}
function Brag(trigger, andSeeIt) { function Brag(trigger, andSeeIt) {
SaveGame(); SaveGame();
@@ -1185,7 +1198,7 @@ function Brag(trigger, andSeeIt) {
// alert(data.alert); // alert(data.alert);
// }, "json"); // }, "json");
let url = 'cmd=b&t=' + trigger; let url = game.online.host + 'cmd=b&t=' + trigger;
for (trait in game.Traits) { for (trait in game.Traits) {
url += '&' + LowerCase(trait.substr(0,1)) + '=' + UrlEncode(game.Traits[trait]); url += '&' + LowerCase(trait.substr(0,1)) + '=' + UrlEncode(game.Traits[trait]);
} }
@@ -1197,12 +1210,10 @@ function Brag(trigger, andSeeIt) {
url += '&a=' + UrlEncode(game.bestplot); url += '&a=' + UrlEncode(game.bestplot);
url += '&h=' + UrlEncode(game.online.realm); url += '&h=' + UrlEncode(game.online.realm);
url += RevString; url += RevString;
let validator = LFSR(url, game.online.passkey); url = StandardizeUrl(url);
console.log("val", url, validator); url += '&p=' + Validator(url);
url += '&p=' + IntToStr(validator);
url += '&m=' + UrlEncode(game.motto || ''); url += '&m=' + UrlEncode(game.motto || '');
url = game.online.host + url;
$.ajax(url) $.ajax(url)
.then(body => { .then(body => {
if (LowerCase(Split(body,0)) == 'report') { if (LowerCase(Split(body,0)) == 'report') {
@@ -1221,16 +1232,16 @@ function Guildify(guild) {
game.guild = guild; game.guild = guild;
let url = 'cmd=guild'; let url = game.online.host + 'cmd=guild';
for (trait in game.Traits) { for (trait in game.Traits) {
url += '&' + LowerCase(trait.substr(0,1)) + '=' + UrlEncode(game.Traits[trait]); url += '&' + LowerCase(trait.substr(0,1)) + '=' + UrlEncode(game.Traits[trait]);
} }
url += '&h=' + UrlEncode(game.online.realm); url += '&h=' + UrlEncode(game.online.realm);
url += RevString; url += RevString;
url += '&guild=' + UrlEncode(game.guild); url += '&guild=' + UrlEncode(game.guild);
url += '&p=' + IntToStr(LFSR(url, game.online.passkey)); url = StandardizeUrl(url);
url += '&p=' + Validator(url);
url = game.online.host + url;
$.ajax(url) $.ajax(url)
.then(body => { .then(body => {
let parts = body.split('|'); let parts = body.split('|');