Skip to content

Commit

Permalink
Merge branch 'master' of github.com-theblackparade:rune-js/server
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlackParade committed Mar 19, 2020
2 parents c858fd9 + 1aa02f6 commit 8641fc4
Show file tree
Hide file tree
Showing 60 changed files with 281 additions and 288 deletions.
Binary file removed cache/377/main_file_cache.dat
Binary file not shown.
Binary file removed cache/377/main_file_cache.idx0
Binary file not shown.
Binary file removed cache/377/main_file_cache.idx1
Binary file not shown.
Binary file removed cache/377/main_file_cache.idx2
Binary file not shown.
Binary file removed cache/377/main_file_cache.idx3
Binary file not shown.
Binary file removed cache/377/main_file_cache.idx4
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"license": "GPL-3.0",
"dependencies": {
"@hapi/joi": "^16.1.8",
"@runejs/cache-parser": "0.4.5",
"@runejs/cache-parser": "0.5.0",
"@runejs/logger": "^1.0.0",
"bigi": "^1.4.2",
"body-parser": "^1.19.0",
Expand Down
11 changes: 5 additions & 6 deletions src/data-dump.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { join } from 'path';
import { writeFileSync } from 'fs';
import { gameCache } from '@server/game-server';
import { cache } from '@server/game-server';
import { logger } from '@runejs/logger/dist/logger';
import { ItemDefinition, NpcDefinition } from '@runejs/cache-parser';
import { WidgetDefinition } from '@runejs/cache-parser/dist/cache-new-format/screen/widgets';
import { ItemDefinition, NpcDefinition, Widget } from '@runejs/cache-parser';

function dump<T>(fileName: string, definitions: Map<number, T>): boolean {
const filePath = join('data/dump', fileName);
Expand All @@ -23,13 +22,13 @@ function dump<T>(fileName: string, definitions: Map<number, T>): boolean {
}

export function dumpNpcs(): boolean {
return dump<NpcDefinition>('npcs.json', gameCache.npcDefinitions);
return dump<NpcDefinition>('npcs.json', cache.npcDefinitions);
}

export function dumpItems(): boolean {
return dump<ItemDefinition>('items.json', gameCache.itemDefinitions);
return dump<ItemDefinition>('items.json', cache.itemDefinitions);
}

export function dumpWidgets(): boolean {
return dump<WidgetDefinition>('widgets.json', gameCache.widgetDefinitions);
return dump<Widget>('widgets.json', cache.widgets);
}
15 changes: 8 additions & 7 deletions src/game-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RsBuffer } from './net/rs-buffer';
import { World } from './world/world';
import { ClientConnection } from './net/client-connection';
import { logger } from '@runejs/logger';
import { EarlyFormatGameCache, NewFormatGameCache } from '@runejs/cache-parser';
import { Cache } from '@runejs/cache-parser';
import { parseServerConfig, ServerConfig } from '@server/world/config/server-config';

import { loadPlugins } from '@server/plugins/plugin-loader';
Expand All @@ -28,8 +28,7 @@ import { setQuestPlugins } from '@server/world/config/quests';


export let serverConfig: ServerConfig;
export let gameCache377: EarlyFormatGameCache;
export let gameCache: NewFormatGameCache;
export let cache: Cache;
export let world: World;
export let crcTable: Buffer;

Expand Down Expand Up @@ -63,13 +62,13 @@ export async function injectPlugins(): Promise<void> {
}

function generateCrcTable(): void {
const index = gameCache.metaChannel;
const index = cache.metaChannel;
const indexLength = index.getBuffer().length;
const buffer = RsBuffer.create(4048);
buffer.writeByte(0);
buffer.writeIntBE(indexLength);
for(let file = 0; file < (indexLength / 6); file++) {
const crcValue = CRC32.buf(gameCache.getRawCacheFile(255, file).getBuffer());
const crcValue = CRC32.buf(cache.getRawFile(255, file).getBuffer());
buffer.writeIntBE(crcValue);
}

Expand All @@ -84,9 +83,11 @@ export function runGameServer(): void {
return;
}

gameCache377 = new EarlyFormatGameCache('cache/377', { loadMaps: true, loadDefinitions: false, loadWidgets: false });
gameCache = new NewFormatGameCache('cache/435');
cache = new Cache('cache', {
items: true, npcs: true, locationObjects: true, mapData: true, widgets: true
});
generateCrcTable();

world = new World();
injectPlugins().then(() => {
world.init();
Expand Down
4 changes: 2 additions & 2 deletions src/net/data-parser/update-server-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RsBuffer } from '@server/net/rs-buffer';
import { DataParser } from './data-parser';
import { crcTable, gameCache } from '@server/game-server';
import { crcTable, cache } from '@server/game-server';

/**
* Handles the cache update server.
Expand Down Expand Up @@ -49,7 +49,7 @@ export class UpdateServerParser extends DataParser {
crcTable.copy(crcBuffer, 0, 0);
cacheFile = new RsBuffer(crcBuffer);
} else {
cacheFile = gameCache.getRawCacheFile(index, file);
cacheFile = cache.getRawFile(index, file);
}

if(!cacheFile || cacheFile.getBuffer().length === 0) {
Expand Down
23 changes: 9 additions & 14 deletions src/net/incoming-packets/item-on-npc-packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import { Player } from '../../world/actor/player/player';
import { RsBuffer } from '@server/net/rs-buffer';
import { widgets } from '@server/world/config/widget';
import { logger } from '@runejs/logger/dist/logger';
import { itemOnItemAction } from '@server/world/actor/player/action/item-on-item-action';
import { Position } from '@server/world/position';
import { gameCache, world } from '@server/game-server';
import { objectAction } from '@server/world/actor/player/action/object-action';
import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action';
import { world } from '@server/game-server';
import { World } from '@server/world/world';
import { npcAction } from '@server/world/actor/player/action/npc-action';
import { itemOnNpcAction } from '@server/world/actor/player/action/item-on-npc-action';

export const itemOnNpcPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => {
Expand All @@ -20,38 +15,38 @@ export const itemOnNpcPacket: incomingPacket = (player: Player, packetId: number
const itemContainerId = packet.readShortBE();

let usedItem;
if (itemWidgetId === widgets.inventory.widgetId && itemContainerId === widgets.inventory.containerId) {
if (itemSlot < 0 || itemSlot > 27) {
if(itemWidgetId === widgets.inventory.widgetId && itemContainerId === widgets.inventory.containerId) {
if(itemSlot < 0 || itemSlot > 27) {
return;
}

usedItem = player.inventory.items[itemSlot];
if (!usedItem) {
if(!usedItem) {
return;
}

if (usedItem.itemId !== itemId) {
if(usedItem.itemId !== itemId) {
return;
}
} else {
logger.warn(`Unhandled item on object case using widget ${itemWidgetId}:${itemContainerId}`);
logger.warn(`Unhandled item on object case using widget ${ itemWidgetId }:${ itemContainerId }`);
}


if (npcIndex < 0 || npcIndex > World.MAX_NPCS - 1) {
if(npcIndex < 0 || npcIndex > World.MAX_NPCS - 1) {
return;
}

const npc = world.npcList[npcIndex];
if (!npc) {
if(!npc) {
return;
}

const position = npc.position;
const distance = Math.floor(position.distanceBetween(player.position));

// Too far away
if (distance > 16) {
if(distance > 16) {
return;
}

Expand Down
16 changes: 7 additions & 9 deletions src/net/incoming-packets/item-on-object-packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { Player } from '../../world/actor/player/player';
import { RsBuffer } from '@server/net/rs-buffer';
import { widgets } from '@server/world/config/widget';
import { logger } from '@runejs/logger/dist/logger';
import { itemOnItemAction } from '@server/world/actor/player/action/item-on-item-action';
import { Position } from '@server/world/position';
import { gameCache, world } from '@server/game-server';
import { objectAction } from '@server/world/actor/player/action/object-action';
import { cache, world } from '@server/game-server';
import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action';

export const itemOnObjectPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => {
Expand Down Expand Up @@ -41,12 +39,12 @@ export const itemOnObjectPacket: incomingPacket = (player: Player, packetId: num
const objectChunk = world.chunkManager.getChunkForWorldPosition(objectPosition);
let cacheOriginal: boolean = true;

let landscapeObject = objectChunk.getCacheObject(objectId, objectPosition);
if (!landscapeObject) {
landscapeObject = objectChunk.getAddedObject(objectId, objectPosition);
let locationObject = objectChunk.getCacheObject(objectId, objectPosition);
if (!locationObject) {
locationObject = objectChunk.getAddedObject(objectId, objectPosition);
cacheOriginal = false;

if (!landscapeObject) {
if (!locationObject) {
return;
}
}
Expand All @@ -55,9 +53,9 @@ export const itemOnObjectPacket: incomingPacket = (player: Player, packetId: num
return;
}

const landscapeObjectDefinition = gameCache.landscapeObjectDefinitions.get(objectId);
const locationObjectDefinition = cache.locationObjectDefinitions.get(objectId);


itemOnObjectAction(player, landscapeObject, landscapeObjectDefinition, objectPosition, usedItem, itemWidgetId, itemContainerId, cacheOriginal);
itemOnObjectAction(player, locationObject, locationObjectDefinition, objectPosition, usedItem, itemWidgetId, itemContainerId, cacheOriginal);

};
24 changes: 12 additions & 12 deletions src/net/incoming-packets/object-interaction-packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { incomingPacket } from '../incoming-packet';
import { Player } from '../../world/actor/player/player';
import { RsBuffer } from '@server/net/rs-buffer';
import { Position } from '@server/world/position';
import { gameCache, world } from '@server/game-server';
import { cache, world } from '@server/game-server';
import { objectAction } from '@server/world/actor/player/action/object-action';
import { logger } from '@runejs/logger/dist/logger';

Expand Down Expand Up @@ -63,12 +63,12 @@ export const objectInteractionPacket: incomingPacket = (player: Player, packetId
const objectChunk = world.chunkManager.getChunkForWorldPosition(objectPosition);
let cacheOriginal: boolean = true;

let landscapeObject = objectChunk.getCacheObject(objectId, objectPosition);
if(!landscapeObject) {
landscapeObject = objectChunk.getAddedObject(objectId, objectPosition);
let locationObject = objectChunk.getCacheObject(objectId, objectPosition);
if(!locationObject) {
locationObject = objectChunk.getAddedObject(objectId, objectPosition);
cacheOriginal = false;

if(!landscapeObject) {
if(!locationObject) {
return;
}
}
Expand All @@ -77,23 +77,23 @@ export const objectInteractionPacket: incomingPacket = (player: Player, packetId
return;
}

const landscapeObjectDefinition = gameCache.landscapeObjectDefinitions.get(objectId);
const locationObjectDefinition = cache.locationObjectDefinitions.get(objectId);

const actionIdx = options[packetId].index;
let optionName = `action-${actionIdx + 1}`;
if(landscapeObjectDefinition.options && landscapeObjectDefinition.options.length >= actionIdx) {
if(!landscapeObjectDefinition.options[actionIdx] || landscapeObjectDefinition.options[actionIdx].toLowerCase() === 'hidden') {
if(locationObjectDefinition.options && locationObjectDefinition.options.length >= actionIdx) {
if(!locationObjectDefinition.options[actionIdx] || locationObjectDefinition.options[actionIdx].toLowerCase() === 'hidden') {
// Invalid action
logger.error(`1: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(landscapeObjectDefinition.options)}`);
logger.error(`1: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(locationObjectDefinition.options)}`);
return;
}

optionName = landscapeObjectDefinition.options[actionIdx];
optionName = locationObjectDefinition.options[actionIdx];
} else {
// Invalid action
logger.error(`2: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(landscapeObjectDefinition.options)}`);
logger.error(`2: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(locationObjectDefinition.options)}`);
return;
}

objectAction(player, landscapeObject, landscapeObjectDefinition, objectPosition, optionName.toLowerCase(), cacheOriginal);
objectAction(player, locationObject, locationObjectDefinition, objectPosition, optionName.toLowerCase(), cacheOriginal);
};
16 changes: 8 additions & 8 deletions src/net/outgoing-packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Packet, PacketType } from '@server/net/packet';
import { ItemContainer } from '@server/world/items/item-container';
import { Item } from '@server/world/items/item';
import { Position } from '@server/world/position';
import { LandscapeObject } from '@runejs/cache-parser';
import { LocationObject } from '@runejs/cache-parser';
import { Chunk, ChunkUpdateItem } from '@server/world/map/chunk';
import { WorldItem } from '@server/world/items/world-item';

Expand Down Expand Up @@ -87,7 +87,7 @@ export class OutgoingPackets {
if(update.object) {
const offset = this.getChunkPositionOffset(update.object.x, update.object.y, chunk);
packet.writeUnsignedByte(241);
packet.writeByteInverted((update.object.type << 2) + (update.object.rotation & 3));
packet.writeByteInverted((update.object.type << 2) + (update.object.orientation & 3));
packet.writeUnsignedShortBE(update.object.objectId);
packet.writeUnsignedOffsetByte(offset);
} else if(update.worldItem) {
Expand All @@ -101,7 +101,7 @@ export class OutgoingPackets {
const offset = this.getChunkPositionOffset(update.object.x, update.object.y, chunk);
packet.writeUnsignedByte(143);
packet.writeUnsignedOffsetByte(offset);
packet.writeByteInverted((update.object.type << 2) + (update.object.rotation & 3));
packet.writeByteInverted((update.object.type << 2) + (update.object.orientation & 3));
}
});

Expand Down Expand Up @@ -139,23 +139,23 @@ export class OutgoingPackets {
this.queue(packet);
}

public setLandscapeObject(landscapeObject: LandscapeObject, position: Position, offset: number = 0): void {
public setLocationObject(locationObject: LocationObject, position: Position, offset: number = 0): void {
this.updateReferencePosition(position);

const packet = new Packet(241);
packet.writeByteInverted((landscapeObject.type << 2) + (landscapeObject.rotation & 3));
packet.writeUnsignedShortBE(landscapeObject.objectId);
packet.writeByteInverted((locationObject.type << 2) + (locationObject.orientation & 3));
packet.writeUnsignedShortBE(locationObject.objectId);
packet.writeUnsignedOffsetByte(offset);

this.queue(packet);
}

public removeLandscapeObject(landscapeObject: LandscapeObject, position: Position, offset: number = 0): void {
public removeLocationObject(locationObject: LocationObject, position: Position, offset: number = 0): void {
this.updateReferencePosition(position);

const packet = new Packet(143);
packet.writeUnsignedOffsetByte(offset);
packet.writeByteInverted((landscapeObject.type << 2) + (landscapeObject.rotation & 3));
packet.writeByteInverted((locationObject.type << 2) + (locationObject.orientation & 3));

this.queue(packet);
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/commands/give-item-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionType, RunePlugin } from '@server/plugins/plugin';
import { commandAction } from '@server/world/actor/player/action/input-command-action';
import { gameCache } from '@server/game-server';
import { cache } from '@server/game-server';

const action: commandAction = (details) => {
const { player, args } = details;
Expand All @@ -19,7 +19,7 @@ const action: commandAction = (details) => {
throw new Error(`Unable to give more than 2,000,000,000.`);
}

const itemDefinition = gameCache.itemDefinitions.get(itemId);
const itemDefinition = cache.itemDefinitions.get(itemId);
if(!itemDefinition) {
throw new Error(`Item ID ${itemId} not found!`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/items/buckets/fill-container-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action';
import { gameCache } from '@server/game-server';
import { cache } from '@server/game-server';
import { itemIds } from '@server/world/config/item-ids';
import { animationIds } from '@server/world/config/animation-ids';
import { soundIds } from '@server/world/config/sound-ids';
Expand All @@ -10,7 +10,7 @@ const SinkIds: number[] = [14878, 873];
const WellIds: number[] = [878];
export const action: itemOnObjectAction = (details) => {
const {player, objectDefinition, item} = details;
const itemDef = gameCache.itemDefinitions.get(item.itemId);
const itemDef = cache.itemDefinitions.get(item.itemId);
if (item.itemId !== itemIds.bucket && WellIds.indexOf(objectDefinition.id) > -1) {
player.sendMessage(`If I drop my ${itemDef.name.toLowerCase()} down there, I don't think I'm likely to get it back.`);
return;
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/objects/cows/cow-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { objectAction } from '@server/world/actor/player/action/object-action';
import { gameCache } from '@server/game-server';
import { cache } from '@server/game-server';
import { ActionType, RunePlugin } from '@server/plugins/plugin';
import { dialogueAction, DialogueEmote } from '@server/world/actor/player/action/dialogue-action';
import { npcIds } from '@server/world/config/npc-ids';
Expand All @@ -8,12 +8,12 @@ import { soundIds } from '@server/world/config/sound-ids';
import { itemIds } from '@server/world/config/item-ids';
import { objectIds } from '@server/world/config/object-ids';
import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action';
import { LandscapeObjectDefinition } from '@runejs/cache-parser';
import { LocationObjectDefinition } from '@runejs/cache-parser';
import { Player } from '@server/world/actor/player/player';

function milkCow(details: {objectDefinition: LandscapeObjectDefinition, player: Player}): void {
function milkCow(details: { objectDefinition: LocationObjectDefinition, player: Player }): void {
const { player, objectDefinition } = details;
const emptyBucketItem = gameCache.itemDefinitions.get(itemIds.bucket);
const emptyBucketItem = cache.itemDefinitions.get(itemIds.bucket);

if (player.hasItemInInventory(itemIds.bucket)) {
player.playAnimation(animationIds.milkCow);
Expand Down
Loading

0 comments on commit 8641fc4

Please sign in to comment.