Skip to content

Commit 8af36e0

Browse files
committed
Fixing the reload content functionality
1 parent b77e081 commit 8af36e0

File tree

5 files changed

+109
-84
lines changed

5 files changed

+109
-84
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"start:infra": "concurrently \"npm run start:update\" \"npm run start:login\"",
1313
"start:standalone": "concurrently \"npm run start:infra\" \"npm run start:game\"",
1414
"game": "npm run start:game",
15-
"game:dev": "npm run start:game",
15+
"game:dev": "npm run start:game:dev",
1616
"login": "npm run start:login",
1717
"update": "npm run start:update",
1818
"infra": "npm run start:infra",

src/engine/action/pipe/player-command.action.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Player } from '@engine/world/actor';
22
import { ActionHook, getActionHooks, ActionPipe, RunnableHooks } from '@engine/action';
3+
import { reloadContent, reloadContentCommands } from '@engine/plugins/reload-content';
4+
import { logger } from '@runejs/common';
35

46

57
/**
@@ -49,6 +51,12 @@ const playerCommandActionPipe = (player: Player, command: string, isConsole: boo
4951
inputArgs: string[]): RunnableHooks<PlayerCommandAction> => {
5052
command = command.toLowerCase();
5153

54+
// Reload game content
55+
if (reloadContentCommands.indexOf(command) !== -1) {
56+
reloadContent(player, isConsole).catch(logger.error);
57+
return;
58+
}
59+
5260
const actionArgs = {};
5361

5462
const plugins = getActionHooks<PlayerCommandActionHook>('player_command').filter(actionHook => {
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { sep } from 'path';
2+
import { loadGameConfigurations } from '@engine/config';
3+
import { loadPackets } from '@engine/net';
4+
import { loadPlugins } from '@engine/plugins/loader';
5+
import { logger } from '@runejs/common';
6+
import { Player } from '@engine/world/actor';
7+
8+
9+
export const reloadContentCommands = [
10+
'plugins', 'reload', 'content', 'hotload', 'refresh', 'restart', 'r'
11+
];
12+
13+
export const reloadContent = async (player: Player, isConsole: boolean = false) => {
14+
player.sendLogMessage(' ', isConsole);
15+
player.sendLogMessage('Deleting content cache...', isConsole);
16+
17+
const includeList = [
18+
'plugins'
19+
].map(p => sep + p + sep);
20+
21+
const ignoreList = [
22+
'node_modules',
23+
'engine',
24+
'server'
25+
].map(p => sep + p + sep);
26+
27+
const pluginCache = [];
28+
const cacheKeys = Object.keys(require.cache);
29+
30+
// Delete node cache for all the old JS plugins
31+
cacheLoop:
32+
for (const cacheKey of cacheKeys) {
33+
const cachedItem = require.cache[cacheKey];
34+
35+
if (!cachedItem) {
36+
continue;
37+
}
38+
39+
const path = typeof cachedItem === 'string' ? cachedItem : cachedItem?.path;
40+
41+
if (!path) {
42+
continue;
43+
}
44+
45+
for (const ignoreItem of ignoreList) {
46+
if (path.indexOf(ignoreItem) !== -1) {
47+
continue cacheLoop;
48+
}
49+
}
50+
51+
let includePath = false;
52+
53+
for (const includeItem of includeList) {
54+
if (path.indexOf(includeItem) !== -1) {
55+
includePath = true;
56+
break;
57+
}
58+
}
59+
60+
if (includePath) {
61+
pluginCache.push(cacheKey);
62+
}
63+
}
64+
65+
console.log(pluginCache);
66+
67+
for (const key of pluginCache) {
68+
delete require.cache[require.resolve(key)];
69+
}
70+
71+
try {
72+
player.sendLogMessage('Reloading plugins...', isConsole);
73+
await loadPlugins();
74+
} catch (error) {
75+
player.sendLogMessage('Error reloading content.', isConsole);
76+
logger.error(error);
77+
}
78+
79+
try {
80+
player.sendLogMessage('Reloading configurations...', isConsole);
81+
await loadGameConfigurations();
82+
} catch (error) {
83+
player.sendLogMessage('Error reloading configurations.', isConsole);
84+
logger.error(error);
85+
}
86+
87+
try {
88+
player.sendLogMessage('Reloading packets...', isConsole);
89+
await loadPackets();
90+
} catch (error) {
91+
player.sendLogMessage('Error reloading packets.', isConsole);
92+
logger.error(error);
93+
}
94+
95+
player.sendLogMessage('Reload completed.', isConsole);
96+
};

src/plugins/commands/reload-content-command.plugin.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/plugins/npcs/lumbridge/hans.plugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { dialogue, Emote, goto, execute, Achievements, giveAchievement } from '@engine/world/actor';
1+
import { Emote, goto, execute, Achievements, giveAchievement } from '@engine/world/actor';
22
import { animationIds } from '@engine/world/config';
3+
import { dialogue } from '@engine/world/actor/dialogue';
34

45

56
const handler = async ({ player, npc }) => {
67
let sadEnding = false;
78

89
const dialogueParticipants = [ player, { npc, key: 'hans' }];
910

10-
const dialogue = [
11+
const dialogueTree = [
1112
hans => [ Emote.GENERIC, `Welcome to RuneJS!` ],
1213
(hans, tag_Hans_Question) => [ Emote.HAPPY, `How do you feel about RuneJS so far?\n` +
1314
`Please take a moment to let us know what you think!` ],
@@ -36,7 +37,7 @@ const handler = async ({ player, npc }) => {
3637
])
3738
];
3839

39-
const dialogueSuccessful = await dialogue(dialogueParticipants, dialogue);
40+
const dialogueSuccessful = await dialogue(dialogueParticipants, dialogueTree);
4041

4142
npc.clearFaceActor();
4243
player.clearFaceActor();

0 commit comments

Comments
 (0)