Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/engine/Inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,19 @@ export class Inventory {

return remove;
}

pack(): BigInt64Array {
const result = new BigInt64Array(this.capacity);
for (let index = 0; index < this.capacity; index++) {
const obj = this.get(index);
if (obj) {
const id: bigint = BigInt(obj.id) & 0xffffn;
const count: bigint = BigInt(obj.count) & 0x7fffffffn;
result[index] = (id << 31n) | count;
} else {
result[index] = -1n;
}
}
return result;
}
}
54 changes: 26 additions & 28 deletions src/engine/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ import WorldStat from '#/engine/WorldStat.js';
import Zone from '#/engine/zone/Zone.js';
import Isaac from '#/io/Isaac.js';
import Packet from '#/io/Packet.js';
import { ReportAbuseReason } from '#/network/client/model/ReportAbuse.js';
import MessagePrivate from '#/network/server/model/MessagePrivate.js';
import UpdateFriendList from '#/network/server/model/UpdateFriendList.js';
import UpdateIgnoreList from '#/network/server/model/UpdateIgnoreList.js';
import UpdateRebootTimer from '#/network/server/model/UpdateRebootTimer.js';
import ClientSocket from '#/server/ClientSocket.js';
import { FriendsServerOpcodes } from '#/server/friend/FriendServer.js';
import { FriendThreadMessage } from '#/server/friend/FriendThread.js';
Expand All @@ -92,6 +87,7 @@ import Environment from '#/util/Environment.js';
import { fromBase37, toBase37, toSafeName } from '#/util/JString.js';
import LinkList from '#/util/LinkList.js';
import { printDebug, printError, printInfo } from '#/util/Logger.js';
import { ReportAbuseReason } from '#/util/ReportAbuse.js';
import WalkTriggerSetting from '#/util/WalkTriggerSetting.js';
import { createWorker } from '#/util/WorkerFactory.js';

Expand Down Expand Up @@ -609,11 +605,7 @@ class World {
player.masks |= player.entitymask;
}

if (!player.busy() && player.opcalled) {
player.moveClickRequest = false;
} else {
player.moveClickRequest = true;
}
player.moveClickRequest = !(!player.busy() && player.opcalled);

if (!followingPlayer && player.opcalled && (player.userPath.length === 0 || !Environment.NODE_CLIENT_ROUTEFINDER)) {
player.pathToTarget();
Expand All @@ -630,6 +622,14 @@ class World {
}
}

// if (player.username.startsWith('bot')) {
// if (this.currentTick % 2 === 0) {
// player.queueWaypoint(player.x + 1, player.z);
// } else {
// player.queueWaypoint(player.x - 1, player.z);
// }
// }

// - client input tracking
player.processInputTracking();

Expand Down Expand Up @@ -992,12 +992,17 @@ class World {
player.uid = ((Number(player.username37 & 0x1fffffn) << 11) | player.pid) >>> 0;
player.tele = true;
player.moveClickRequest = false;

if (player.username.startsWith('bot')) {
const x = Math.floor(Math.random() * 32) + 3200;
const z = Math.floor(Math.random() * 32) + 3200;
player.x = x;
player.z = z;
}
this.gameMap.getZone(player.x, player.z, player.level).enter(player);
player.onLogin();

if (this.shutdownTick != -1) {
player.write(new UpdateRebootTimer(this.shutdownTick - this.currentTick));
player.write(rsbuf.updateRebootTimer(player.pid, this.shutdownTicksRemaining));
}

this.friendThread.postMessage({
Expand Down Expand Up @@ -1597,11 +1602,6 @@ class World {
});
}

addPlayer(player: Player): void {
this.newPlayers.add(player);
player.isActive = true;
}

sendPrivateChatModeToFriendsServer(player: Player): void {
this.friendThread.postMessage({
type: 'player_chat_setmode',
Expand Down Expand Up @@ -1820,7 +1820,7 @@ class World {
this.shutdownTick = this.currentTick + duration;

for (const player of this.players) {
player.write(new UpdateRebootTimer(this.shutdownTick - this.currentTick));
player.write(rsbuf.updateRebootTimer(player.pid, this.shutdownTicksRemaining));
}
}

Expand Down Expand Up @@ -1995,7 +1995,7 @@ class World {

for (let i = 0; i < data.friends.length; i++) {
const [world, friendUsername37] = data.friends[i];
player.write(new UpdateFriendList(BigInt(friendUsername37), world));
player.write(rsbuf.updateFriendList(player.pid, BigInt(friendUsername37), world));
}
} else if (opcode === FriendsServerOpcodes.UPDATE_IGNORELIST) {
const username37 = BigInt(data.username37);
Expand All @@ -2010,7 +2010,7 @@ class World {
const ignored: bigint[] = data.ignored.map((i: string) => BigInt(i));

if (ignored.length > 0) {
player.write(new UpdateIgnoreList(ignored));
player.write(rsbuf.updateIgnoreList(player.pid, BigInt64Array.from(ignored)));
}
} else if (opcode == FriendsServerOpcodes.PRIVATE_MESSAGE) {
// username37: username.toString(),
Expand All @@ -2030,9 +2030,7 @@ class World {
return;
}

const chat = data.chat;

player.write(new MessagePrivate(fromPlayer, pmId, fromPlayerStaffLvl, chat));
player.write(rsbuf.messagePrivateOut(fromPlayer, pmId, fromPlayerStaffLvl, rsbuf.packWords(data.chat)));
} else if (opcode === FriendsServerOpcodes.RELAY_MUTE) {
const { username, muted_until } = data;

Expand Down Expand Up @@ -2189,11 +2187,11 @@ class World {
return;
}

if (this.getTotalPlayers() > Environment.NODE_MAX_CONNECTED) {
client.send(Uint8Array.from([7]));
client.close();
return;
}
// if (this.getTotalPlayers() > Environment.NODE_MAX_CONNECTED) {
// client.send(Uint8Array.from([7]));
// client.close();
// return;
// }

if (this.logoutRequests.has(username)) {
// still trying to log out from the last session on this world!
Expand Down
46 changes: 43 additions & 3 deletions src/engine/entity/BuildArea.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import * as rsbuf from '@2004scape/rsbuf';

import { PRELOADED_CRC } from '#/cache/PreloadedPacks.js';
import { CoordGrid } from '#/engine/CoordGrid.js';
import Player from '#/engine/entity/Player.js';
import World from '#/engine/World.js';
import ZoneMap from '#/engine/zone/ZoneMap.js';
import RebuildNormal from '#/network/server/model/RebuildNormal.js';

export default class BuildArea {
// constructor
readonly player: Player;
readonly loadedZones: Set<number>;
readonly activeZones: Set<number>;

readonly mapsquares: Set<number>;

lastBuild: number = -1;

constructor(player: Player) {
this.player = player;
this.loadedZones = new Set();
this.activeZones = new Set();
this.mapsquares = new Set();
}

clear(reconnecting: boolean): void {
if (!reconnecting) {
this.activeZones.clear();
this.loadedZones.clear();
this.mapsquares.clear();
}
}

Expand Down Expand Up @@ -62,7 +67,42 @@ export default class BuildArea {

// if the build area should be regenerated, do so now
if (this.player.x < reloadLeftX || this.player.z < reloadBottomZ || this.player.x > reloadRightX - 1 || this.player.z > reloadTopZ - 1 || reconnect) {
this.player.write(new RebuildNormal(CoordGrid.zone(this.player.x), CoordGrid.zone(this.player.z)));
const zoneX: number = CoordGrid.zone(this.player.x);
const zoneZ: number = CoordGrid.zone(this.player.z);

const mapsquares = [];
this.mapsquares.clear();
const minX: number = zoneX - 6;
const maxX: number = zoneX + 6;
const minZ: number = zoneZ - 6;
const maxZ: number = zoneZ + 6;

// build area is 13x13 zones (8*13 = 104 tiles), so we need to load 6 zones in each direction
for (let x: number = minX; x <= maxX; x++) {
const mx: number = CoordGrid.mapsquare(x << 3);
for (let z: number = minZ; z <= maxZ; z++) {
const mz: number = CoordGrid.mapsquare(z << 3);
const mapsquare: number = (mx << 8) | mz;
if (!this.mapsquares.has(mapsquare)) {
mapsquares.push(mapsquare);
}
this.mapsquares.add(mapsquare);
}
}

const maps: Int32Array = Int32Array.from(mapsquares.map(packed => {
const x: number = (packed >> 8) & 0xff;
const z: number = packed & 0xff;
return PRELOADED_CRC.get(`m${x}_${z}`) ?? 0;
}));

const locs: Int32Array = Int32Array.from(mapsquares.map(packed => {
const x: number = (packed >> 8) & 0xff;
const z: number = packed & 0xff;
return PRELOADED_CRC.get(`l${x}_${z}`) ?? 0;
}));

this.player.write(rsbuf.rebuildNormal(zoneX, zoneZ, Uint16Array.from(mapsquares), maps, locs));

this.player.originX = this.player.x;
this.player.originZ = this.player.z;
Expand Down
5 changes: 2 additions & 3 deletions src/engine/entity/CameraInfo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { CameraProt } from '#/network/rs225/server/prot/ServerProt.js';
import Linkable from '#/util/Linkable.js';

export default class CameraInfo extends Linkable {
readonly type: CameraProt;
readonly type: number;
readonly camX: number;
readonly camZ: number;
readonly height: number;
readonly rotationSpeed: number;
readonly rotationMultiplier: number;

constructor(type: CameraProt, camX: number, camZ: number, height: number, rotationSpeed: number, rotationMultiplier: number) {
constructor(type: number, camX: number, camZ: number, height: number, rotationSpeed: number, rotationMultiplier: number) {
super();
this.type = type;
this.camX = camX;
Expand Down
Loading