Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleyrs committed Jul 11, 2024
1 parent 2e057a5 commit 584cd91
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ When worker=1 is set in the url it will load the server inside the browser on lo
To update server code you have to:
1. pack server caches in the main branch, copy `data/pack` and `data/players` from server to `src/public` in client
2. run `npm run bundle` in server, this will turn LoginThread into a worker blob and copies the server to `../Client2/src/public`
3. `npm run local` or `npm run prod`
3. run `npm run dev`/`npm run local` or `npm run prod` for release build

NOTE:
- modpow, crc, randomuuid and compression are disabled, crypto.randomuuid() needs https. Cache+midis are fetched locally, but crcs are an http request.
Expand Down
75 changes: 36 additions & 39 deletions src/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class Packet extends Hashable {
}
static checkcrc(src, offset, length, expected = 0) {
const checksum = Packet.getcrc(src, offset, length);
console.log(checksum, expected);
return checksum == expected;
}
static alloc(type) {
Expand Down Expand Up @@ -15784,7 +15785,7 @@ class ClientSocket {
inCount = new Uint8Array(256);
out = new Packet(new Uint8Array(5000));
player = null;
constructor(remoteAddress = '0', state = -1) {
constructor(remoteAddress = '127.0.0.1', state = -1) {
this.remoteAddress = remoteAddress;
this.state = state;
}
Expand Down Expand Up @@ -20706,28 +20707,29 @@ async function makeCrc(path) {
}
const packet = await Packet.load(path);
const crc = Packet.getcrc(packet.data, 0, packet.data.length);
console.log(crc);
CrcTable.push(crc);
CrcBuffer.p4(crc);
}
function makeCrcs() {
async function makeCrcs() {
CrcTable = [];
CrcBuffer.pos = 0;
CrcBuffer.p4(0);
makeCrc('data/pack/client/title');
makeCrc('data/pack/client/config');
makeCrc('data/pack/client/interface');
makeCrc('data/pack/client/media');
makeCrc('data/pack/client/models');
makeCrc('data/pack/client/textures');
makeCrc('data/pack/client/wordenc');
makeCrc('data/pack/client/sounds');
await makeCrc('data/pack/client/title');
await makeCrc('data/pack/client/config');
await makeCrc('data/pack/client/interface');
await makeCrc('data/pack/client/media');
await makeCrc('data/pack/client/models');
await makeCrc('data/pack/client/textures');
await makeCrc('data/pack/client/wordenc');
await makeCrc('data/pack/client/sounds');
CrcBuffer32 = Packet.getcrc(CrcBuffer.data, 0, CrcBuffer.data.length);
}
var CrcBuffer = new Packet(new Uint8Array(4 * 9));
var CrcTable = [];
var CrcBuffer32 = 0;
if ((await fetch('data/pack/client/')).ok) {
makeCrcs();
await makeCrcs();
}

// src/lostcity/server/LoginThreadWorker.ts
Expand Down Expand Up @@ -20891,6 +20893,7 @@ class Packet extends Hashable {
}
static checkcrc(src, offset, length, expected = 0) {
const checksum = Packet.getcrc(src, offset, length);
console.log(checksum, expected);
return checksum == expected;
}
static alloc(type) {
Expand Down Expand Up @@ -21624,12 +21627,8 @@ self.onmessage = async (msg) => {
let save = new Uint8Array;
const safeName = toSafeName(username);
const url = new URL("data/players/" + safeName + ".sav", self.location.origin);
if (!(await fetch(url)).ok) {
if ((await fetch(url)).ok) {
save = new Uint8Array(await (await fetch(url)).arrayBuffer());
console.log(save);
} else {
console.log(await fetch(url));
console.log("???");
}
self.postMessage({
type: "loginreply",
Expand Down Expand Up @@ -21950,50 +21949,50 @@ class World35 {
async reload() {
let transmitted = false;
if (this.shouldReload('varp', true)) {
VarPlayerType.load('data/pack');
await VarPlayerType.load('data/pack');
transmitted = true;
}
if (this.shouldReload('param')) {
ParamType.load('data/pack');
await ParamType.load('data/pack');
}
if (this.shouldReload('obj', true)) {
ObjType.load('data/pack');
await ObjType.load('data/pack');
transmitted = true;
}
if (this.shouldReload('loc', true)) {
LocType.load('data/pack');
await LocType.load('data/pack');
transmitted = true;
}
if (this.shouldReload('npc', true)) {
NpcType.load('data/pack');
await NpcType.load('data/pack');
transmitted = true;
}
if (this.shouldReload('idk', true)) {
IdkType.load('data/pack');
await IdkType.load('data/pack');
transmitted = true;
}
if (this.shouldReload('frame_del')) {
SeqFrame.load('data/pack');
await SeqFrame.load('data/pack');
}
if (this.shouldReload('seq', true)) {
SeqType.load('data/pack');
await SeqType.load('data/pack');
transmitted = true;
}
if (this.shouldReload('spotanim', true)) {
SpotanimType.load('data/pack');
await SpotanimType.load('data/pack');
transmitted = true;
}
if (this.shouldReload('category')) {
CategoryType.load('data/pack');
await CategoryType.load('data/pack');
}
if (this.shouldReload('enum')) {
EnumType.load('data/pack');
await EnumType.load('data/pack');
}
if (this.shouldReload('struct')) {
StructType.load('data/pack');
await StructType.load('data/pack');
}
if (this.shouldReload('inv')) {
InvType.load('data/pack');
await InvType.load('data/pack');
this.invs.clear();
for (let i = 0; i < InvType.count; i++) {
const inv = InvType.get(i);
Expand All @@ -22003,22 +22002,22 @@ class World35 {
}
}
if (this.shouldReload('mesanim')) {
MesanimType.load('data/pack');
await MesanimType.load('data/pack');
}
if (this.shouldReload('dbtable')) {
DbTableType.load('data/pack');
await DbTableType.load('data/pack');
}
if (this.shouldReload('dbrow')) {
DbRowType.load('data/pack');
await DbRowType.load('data/pack');
}
if (this.shouldReload('hunt')) {
HuntType.load('data/pack');
await HuntType.load('data/pack');
}
if (this.shouldReload('varn')) {
VarNpcType.load('data/pack');
await VarNpcType.load('data/pack');
}
if (this.shouldReload('vars')) {
VarSharedType.load('data/pack');
await VarSharedType.load('data/pack');
if (this.vars.length !== VarSharedType.count) {
const old = this.vars;
this.vars = new Int32Array(VarSharedType.count);
Expand All @@ -22033,7 +22032,7 @@ class World35 {
}
}
if (this.shouldReload('interface')) {
Component.load('data/pack');
await Component.load('data/pack');
transmitted = true;
}
if (this.shouldReload('script')) {
Expand All @@ -22044,8 +22043,7 @@ class World35 {
this.broadcastMes(`Reloaded ${count} scripts.`);
}
}
makeCrcs();
preloadClient();
await preloadClient();
}
broadcastMes(message) {
for (const player of this.players) {
Expand All @@ -22059,7 +22057,6 @@ class World35 {
await WordEnc2.load('data/pack');
await this.reload();
if (!skipMaps) {
await this.gameMap.init(this.zoneMap);
}
Login_default.loginThread.postMessage({
type: 'reset'
Expand Down

0 comments on commit 584cd91

Please sign in to comment.