Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/game-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NpcActionPlugin, setNpcPlugins } from '@server/world/mob/player/action/
import { ObjectActionPlugin, setObjectPlugins } from '@server/world/mob/player/action/object-action';
import { loadPlugins } from '@server/plugins/plugin-loader';
import { ItemOnItemActionPlugin, setItemOnItemPlugins } from '@server/world/mob/player/action/item-on-item-action';
import { ButtonActionPlugin, setButtonPlugins } from '@server/world/mob/player/action/button-action';

const GAME_SERVER_PORT = 43594;
export let gameCache: GameCache;
Expand All @@ -20,6 +21,7 @@ export async function injectPlugins(): Promise<void> {
await loadPlugins<NpcActionPlugin>('npc').then(plugins => setNpcPlugins(plugins));
await loadPlugins<ObjectActionPlugin>('object').then(plugins => setObjectPlugins(plugins));
await loadPlugins<ItemOnItemActionPlugin>('item-on-item').then(plugins => setItemOnItemPlugins(plugins));
await loadPlugins<ButtonActionPlugin>('buttons').then(plugins => setButtonPlugins(plugins));
}

export function runGameServer(): void {
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/buttons/dialogue-action-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { buttonAction, ButtonActionPlugin } from '@server/world/mob/player/action/button-action';

const dialogueActions: { [key: number]: number } = {
2494: 1, 2495: 2, 2496: 3, 2497: 4, 2498: 5,
2482: 1, 2483: 2, 2484: 3, 2485: 4,
2471: 1, 2472: 2, 2473: 3,
2461: 1, 2462: 2
};

const buttonIds = Object.keys(dialogueActions).map(Number);

export const action: buttonAction = (details) => {
const { player, buttonId } = details;
player.dialogueInteractionEvent.next(dialogueActions[buttonId]);
};

export default { buttonIds, action } as ButtonActionPlugin;
8 changes: 8 additions & 0 deletions src/plugins/buttons/logout-button-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { buttonAction, ButtonActionPlugin } from '@server/world/mob/player/action/button-action';

export const action: buttonAction = (details) => {
const { player } = details;
player.logout();
};

export default { buttonIds: 2458, action } as ButtonActionPlugin;
20 changes: 20 additions & 0 deletions src/plugins/buttons/player-setting-button-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { buttonAction, ButtonActionPlugin } from '@server/world/mob/player/action/button-action';

const buttonIds: number[] = [
152, 153, // walk/run
930, 931, 932, 933, 934, // music volume
941, 942, 943, 944, 945, // sound effect volume
957, 958, // split private chat
913, 914, // mouse buttons
906, 908, 910, 912, // screen brightness
915, 916, // chat effects
12464, 12465, // accept aid
150, 151, // auto retaliate
];

export const action: buttonAction = (details) => {
const { player, buttonId } = details;
player.settingChanged(buttonId);
};

export default { buttonIds, action } as ButtonActionPlugin;
28 changes: 28 additions & 0 deletions src/plugins/buttons/skill-guide-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { buttonAction, ButtonActionPlugin } from '@server/world/mob/player/action/button-action';

const attackGuide = [
{
itemId: 1321,
text: 'Bronze Weapons',
level: 1
},
{
itemId: 1323,
text: 'Iron Weapons',
level: 1
}
];

const guides = {
8654: attackGuide,
//8668 firemaking
};

const buttonIds = Object.keys(guides).map(Number);

export const action: buttonAction = (details) => {
const { player } = details;
player.packetSender.chatboxMessage(`Skill guide button clicked`);
};

export default { buttonIds, action } as ButtonActionPlugin;
18 changes: 11 additions & 7 deletions src/plugins/plugin-loader.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import * as fs from 'fs';

export const pluginFilter = (ids: number | number[], id: number, options: string | string[], option: string): boolean => {
if(Array.isArray(ids)) {
if(ids.indexOf(id) === -1) {
export const pluginFilter = (pluginIds: number | number[], searchId: number, pluginOptions?: string | string[], searchOption?: string): boolean => {
if(Array.isArray(pluginIds)) {
if(pluginIds.indexOf(searchId) === -1) {
return false;
}
} else {
if(ids !== id) {
if(pluginIds !== searchId) {
return false;
}
}

if(Array.isArray(options)) {
return options.indexOf(option) !== -1;
if(pluginOptions !== undefined && searchOption !== undefined) {
if(Array.isArray(pluginOptions)) {
return pluginOptions.indexOf(searchOption) !== -1;
} else {
return pluginOptions === searchOption;
}
} else {
return options === option;
return true;
}
};

Expand Down
57 changes: 57 additions & 0 deletions src/world/mob/player/action/button-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Player } from '@server/world/mob/player/player';
import { pluginFilter } from '@server/plugins/plugin-loader';

/**
* The definition for a button action function.
*/
export type buttonAction = (details: ButtonActionDetails) => void;

/**
* Details about a button action.
*/
export interface ButtonActionDetails {
player: Player;
buttonId: number;
}

/**
* Defines a button interaction plugin.
*/
export interface ButtonActionPlugin {
buttonIds: number | number[];
action: buttonAction;
cancelActions?: boolean;
}

/**
* A directory of all button interaction plugins.
*/
let buttonInteractions: ButtonActionPlugin[] = [
];

/**
* Sets the list of button interaction plugins.
* @param plugins The plugin list.
*/
export const setButtonPlugins = (plugins: ButtonActionPlugin[]): void => {
buttonInteractions = plugins;
};

export const buttonAction = (player: Player, buttonId: number): void => {
// Find all item on item action plugins that match this action
const interactionPlugins = buttonInteractions.filter(plugin => pluginFilter(plugin.buttonIds, buttonId));

if(interactionPlugins.length === 0) {
player.packetSender.chatboxMessage(`Unhandled button interaction: ${buttonId}`);
return;
}

// Immediately run the plugins
interactionPlugins.forEach(plugin => {
if(plugin.cancelActions) {
player.actionsCancelled.next();
}

plugin.action({ player, buttonId });
});
};
16 changes: 15 additions & 1 deletion src/world/mob/player/action/input-command-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,21 @@ const commands: { [key: string]: commandHandler } = {
}

player.packetSender.playQuickSong(songId, previousSongId);
}
},

anim: (player, args) => {
if(args.length !== 1) {
throw `anim animationId`;
}

const animationId: number = parseInt(args[0]);

if(isNaN(animationId)) {
throw `anim animationId`;
}

player.playAnimation(animationId);
},

};

Expand Down
4 changes: 2 additions & 2 deletions src/world/mob/player/action/item-on-item-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let itemOnItemInteractions: ItemOnItemActionPlugin[] = [
];

/**
* Sets the list of NPC interaction plugins.
* Sets the list of item on item interaction plugins.
* @param plugins The plugin list.
*/
export const setItemOnItemPlugins = (plugins: ItemOnItemActionPlugin[]): void => {
Expand All @@ -56,7 +56,7 @@ export const itemOnItemAction = (player: Player,

player.actionsCancelled.next();

// Immediately the plugins
// Immediately run the plugins
interactionPlugins.forEach(plugin => plugin.action({ player, usedItem, usedWithItem, usedSlot, usedWithSlot,
usedInterfaceId, usedWithInterfaceId }));
};
30 changes: 3 additions & 27 deletions src/world/mob/player/packet/impl/button-click-packet.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
import { incomingPacket } from '../incoming-packet';
import { Player } from '../../player';
import { RsBuffer } from '@server/net/rs-buffer';
import { buttonAction } from '@server/world/mob/player/action/button-action';

const ignoreButtons: number[] = [
3651 // character design accept button
];

const settingButtons: number[] = [
152, 153, // walk/run
930, 931, 932, 933, 934, // music volume
941, 942, 943, 944, 945, // sound effect volume
957, 958, // split private chat
913, 914, // mouse buttons
906, 908, 910, 912, // screen brightness
915, 916, // chat effects
12464, 12465, // accept aid
150, 151, // auto retaliate
];

const dialogueActions: { [key: number]: number } = {
2494: 1, 2495: 2, 2496: 3, 2497: 4, 2498: 5,
2482: 1, 2483: 2, 2484: 3, 2485: 4,
2471: 1, 2472: 2, 2473: 3,
2461: 1, 2462: 2
};

export const buttonClickPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => {
const buttonId = packet.readShortBE();

if(buttonId === 2458) {
player.logout();
} else if(settingButtons.indexOf(buttonId) !== -1) {
player.settingChanged(buttonId);
} else if(dialogueActions.hasOwnProperty(buttonId)) {
player.dialogueInteractionEvent.next(dialogueActions[buttonId]);
} else if(ignoreButtons.indexOf(buttonId) === -1) {
console.log(`Unhandled button ${buttonId} clicked.`);
if(ignoreButtons.indexOf(buttonId) === -1) {
buttonAction(player, buttonId);
}
};