Multiplayer code in place but not tested with server yet

This commit is contained in:
Eric Fredricksen
2021-12-08 15:52:37 -08:00
committed by Eric Fredricksen
parent d389d7d8df
commit 48cc250bff
7 changed files with 115 additions and 6326 deletions
+11
View File
@@ -234,6 +234,10 @@ function SqlStorage() {
}; };
} }
function UrlEncode(s) {
return encodeURIComponent(s).replace(/%20/g, "+");
}
var iPad = navigator.userAgent.match(/iPad/); var iPad = navigator.userAgent.match(/iPad/);
var iPod = navigator.userAgent.match(/iPod/); var iPod = navigator.userAgent.match(/iPod/);
var iPhone = navigator.userAgent.match(/iPhone/); var iPhone = navigator.userAgent.match(/iPhone/);
@@ -308,6 +312,13 @@ function LevelUpTime(level) { // seconds
} }
let RevString = '&rev=6';
// Rev strings known to server, probably:
// rev=3 is the minimum allowed by server, probably pq6.1
// rev=4 is pq6.2 the longstanding delphi client
// rev=5 is pq6.3 presumably the lazarus port or other unofficial release
// rev=6 is this here, pq-web multiplayer enabled
var K = {}; var K = {};
K.Traits = ["Name", "Race", "Class", "Level"]; K.Traits = ["Name", "Race", "Class", "Level"];
Vendored
+2 -6240
View File
File diff suppressed because one or more lines are too long
+36 -15
View File
@@ -962,7 +962,7 @@ function FormCreate() {
return "Are you sure you want to quit? All your progress will be lost!"; return "Are you sure you want to quit? All your progress will be lost!";
}); });
$(window).unload(function (event) { $(window).on('unload', function (event) {
StopTimer(); StopTimer();
SaveGame(); SaveGame();
if (storage.async) { if (storage.async) {
@@ -1075,8 +1075,8 @@ function LoadGame(sheet) {
function GameSaveName() { function GameSaveName() {
if (!game.saveName) { if (!game.saveName) {
game.saveName = Get(Traits, 'Name'); game.saveName = Get(Traits, 'Name');
if (game.realm) if (game.online)
game.saveName += ' [' + game.realm + ']'; game.saveName += ' [' + game.online.realm + ']';
} }
return game.saveName; return game.saveName;
} }
@@ -1121,11 +1121,11 @@ function FormKeyDown(e) {
if (game.online) { if (game.online) {
if (key === 'b') { if (key === 'b') {
Brag('brag'); Brag('brag');
//Navigate(GetHostAddr() + 'name=' + UrlEncode(Get(Traits,'Name'))); // Navigate(game.online.host + 'name=' + UrlEncode(Get(Traits,'Name')));
} }
if (key === 'g') { if (key === 'g') {
game.guild = InputBox('Choose a guild.\r\rMake sure you undestand the guild rules before you join one. To learn more about guilds, visit http://progressquest.com/guilds.php', game.guild); game.guild = InputBox('Choose a guild.\n\nMake sure you undestand the guild rules before you join one. To learn more about guilds, visit http://progressquest.com/guilds.php\n', game.guild);
Brag("guild"); Brag("guild");
} }
@@ -1168,20 +1168,41 @@ function Navigate(url) {
function LFSR(pt, salt) { function LFSR(pt, salt) {
var result = salt; var result = salt;
for (var k = 1; k <= Length(pt); ++k) for (var k = 1; k <= Length(pt); ++k)
result = Ord(pt[k]) ^ (result << 1) ^ (1 && ((result >> 31) ^ (result >> 5))); result = pt.charCodeAt(k) ^ (result << 1) ^ (1 && ((result >> 31) ^ (result >> 5)));
for (var kk = 1; kk <= 10; ++kk) for (var kk = 1; kk <= 10; ++kk)
result = (result << 1) ^ (1 && ((result >> 31) ^ (result >> 5))); result = (result << 1) ^ (1 && ((result >> 31) ^ (result >> 5)));
return result;
} }
function Brag(trigger) { function Brag(trigger) {
SaveGame(); SaveGame();
if (game.online) {
game.bragtrigger = trigger;
$.post("webrag.php", game, function (data, textStatus, request) {
if (data.alert)
alert(data.alert);
}, "json");
}
}
if (game.online) {
// game.bragtrigger = trigger;
// $.post("webrag.php", game, function (data, textStatus, request) {
// if (data.alert)
// alert(data.alert);
// }, "json");
let url = game.online.host + 'cmd=b&t=' + trigger;
for (trait in game.Traits) {
url += '&' + LowerCase(trait.substr(0,1)) + '=' + UrlEncode(game.Traits[trait]);
}
url += '&x=' + IntToStr(ExpBar.Position());
url += '&i=' + UrlEncode(game.bestequip);
url += '&z=' + UrlEncode(game.bestspell);
url += '&k=' + UrlEncode(game.beststat);
url += '&a=' + UrlEncode(game.bestplot);
url += '&h=' + UrlEncode(game.online.realm);
url += RevString;
url += '&p=' + IntToStr(LFSR(url, game.online.passkey));
url += '&m=' + UrlEncode(game.motto || '');
$.ajax(url)
.then(body => {
if (LowerCase(Split(body,0)) = 'report') {
ShowMessage(Split(body,1));
}
});
}
}
+9 -2
View File
@@ -42,13 +42,20 @@ fieldset table td {
width: 185px; width: 185px;
} }
#races, #classes, #stats { #races, #classes {
height: 372px; height: 372px;
} }
#stats { #stats, #gametype {
width: 109px; width: 109px;
} }
#stats {
height: 308px;
}
#gametype {
margin-top: 4px;
height: 58px;
}
.window#newguy .vbox button { .window#newguy .vbox button {
width: 75px; width: 75px;
+17 -10
View File
@@ -34,11 +34,6 @@ input, button { display: inline; }
Name Name
<input id="Name" spellcheck="false"> <input id="Name" spellcheck="false">
<button id="RandomName">?</button> <button id="RandomName">?</button>
<!--
<span style="float:right;padding-right:20px">
<input type="checkbox" checked id="multiplayer"/><label for="multiplayer">Play online</label>
</span>
-->
</div> </div>
<div class=hbox> <div class=hbox>
@@ -53,7 +48,8 @@ input, button { display: inline; }
<legend>Class</legend> <legend>Class</legend>
</fieldset> </fieldset>
<fieldset class="vbox groupbox" id="stats"> <div class="vbox">
<fieldset class="groupbox" id="stats">
<legend>Stats</legend> <legend>Stats</legend>
<table> <table>
@@ -67,9 +63,6 @@ input, button { display: inline; }
<tr> <th> Total <td id="Total">48</tr> <tr> <th> Total <td id="Total">48</tr>
</table> </table>
<br>
<br>
<br>
<br> <br>
<br> <br>
<br> <br>
@@ -81,11 +74,25 @@ input, button { display: inline; }
<br> <br>
</fieldset> </fieldset>
<fieldset class="groupbox" id="gametype">
<legend>Game Type</legend>
<div><input type=radio id=single name=online value=false checked/>
<label for=single>Single player</label></div>
<div><input type=radio id=multiplayer name=online value=true/>
<label for=multiplayer>Mulitplayer</label></div>
</fieldset>
</div> </div>
</div>
<div class=hbox>
</div>
<div class=hbox style="text-align:right;padding-top:15px"> <div class=hbox style="text-align:right;padding-top:15px">
<button id=Sold>Sold!</button>
<button id=Sold>Sold!</button>
</div> </div>
</div> </div>
</div> </div>
+36 -59
View File
@@ -108,53 +108,6 @@ function NewGuyFormLoad() {
if (document) if (document)
$(document).ready(NewGuyFormLoad); $(document).ready(NewGuyFormLoad);
/* Multiplayer:
function TNewGuyForm_ParseSoldResponse(body) {
if ((LowerCase(Split(body,0)) == 'ok')) {
MainForm.SetPasskey(Split(body,1));
MainForm.SetLogin(GetAccount);
MainForm.SetPassword(GetPassword);
ModalResult = mrOk;
} else {
ShowMessage(body);
}
}
function TNewGuyForm_GetAccount() {
return Account.Visible ? Account.Text : '';
}
function TNewGuyForm_GetPassword() {
return (Password.Visible) ? Password.Text : '';
}
function TNewGuyForm_SoldClick() {
if (MainForm.GetHostAddr == '') {
ModalResult = mrOk;
} else {
try {
Screen.Cursor = crHourglass;
try {
if ((MainForm.Label8.Tag && 16) == 0
) url = MainForm.GetHostAddr
else url = 'http://www.progressquest.com/create.php?';
// url = StringReplace(url, '.com/', '.com/dev/', []);
if ((GetAccount() != '') || (GetPassword != ''))
url = StuffString(url, 8, 0, GetAccount() + ':' + GetPassword() + '@');
args = 'cmd=create' +
'&name=' + escape(Name.Text) +
'&realm=' + escape(MainForm.GetHostName) +
RevString;
ParseSoldResponse(DownloadString(url + args));
} catch (EWebError) {
ShowMessage('Error connecting to server');
}
} finally {
Screen.Cursor = crDefault;
}
}
}
*/
function sold() { function sold() {
var newguy = { var newguy = {
@@ -191,15 +144,6 @@ function sold() {
] ]
}; };
/*
if ($("#multiplayer:checked").length > 0) {
newguy.online = {
realm: "Alpaquil",
host: "http://progressquest.com/alpa.php",
}
}
*/
if (document) { if (document) {
newguy.Traits.Name = $("#Name").val(); newguy.Traits.Name = $("#Name").val();
newguy.Traits.Race = $("input:radio[name=Race]:checked").val(); newguy.Traits.Race = $("input:radio[name=Race]:checked").val();
@@ -214,10 +158,43 @@ function sold() {
newguy.Equips.Weapon = newguy.bestequip; newguy.Equips.Weapon = newguy.bestequip;
newguy.Equips.Hauberk = "-3 Burlap"; newguy.Equips.Hauberk = "-3 Burlap";
storage.addToRoster(newguy, function () {
window.location.href = "main.html#" + escape(newguy.Traits.Name);
});
if ($("#multiplayer:checked").length > 0) {
newguy.online = {
realm: "Alpaquil",
// host: "http://progressquest.com/alpaquil.php?",
host: "http://localhost:9001/alpaquil.php?",
}
$("#sold").prop("disabled", true);
$("body").css("cursor", "progress");
let url = newguy.online.host;
url += 'cmd=create' +
'&name=' + UrlEncode(newguy.Traits.Name) +
'&realm=' + UrlEncode(newguy.online.realm) +
RevString;
$.ajax(url)
.done(body => {
if (body.split('|')[0].toLowerCase() == 'ok') {
newguy.online.passkey = body.split('|')[1];
charIsBorn(newguy);
} else {
$("#sold").prop("disabled", false);
$("body").css("cursor", "default");
alert(body);
}
});
} else {
charIsBorn(newguy);
}
}
function charIsBorn(newguy) {
storage.addToRoster(newguy, function () {
window.location.href = "main.html#" + UrlEncode(newguy.Traits.Name);
});
} }
function cancel() { function cancel() {
+4
View File
@@ -79,6 +79,10 @@ $(document).ready(function () {
window.location = "newguy.html"; window.location = "newguy.html";
}); });
$("#roll").click(function () {
window.location = "newguy.html?online";
});
$("#test").click(function () { $("#test").click(function () {
window.location = "newguy.html?sold"; window.location = "newguy.html?sold";
}); });