-
Notifications
You must be signed in to change notification settings - Fork 2
/
realmspy.ts
296 lines (287 loc) · 8.42 KB
/
realmspy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import {
Client,
Library,
Runtime,
PacketHook,
TextPacket,
PlayerData
} from "nrelay";
import { PlayerTracker } from "nrelay/lib/stdlib/player-tracker";
import * as RealmData from "./modules/realm-data";
/**
* Import the Discord bot functions
* Import the Redis database functions
*/
import { DiscordBot, External } from "./modules/discord";
import { Database } from "./modules/database";
@Library({
name: "RealmSpy plugin",
author: "him#1337",
enabled: true,
})
class RealmSpy {
private runtime: Runtime;
private bot = new DiscordBot();
private external = new External();
private alphaRegex = /^[A-z]+$/g;
//private database = new Database();
/**
* Called when a text packet is received by a client
* Used to track key pops or event notifications
*
* @param client the client that received the packet
* @param textPacket the data from the text packet
*/
@PacketHook()
onText(client: Client, textPacket: TextPacket): void {
if (client.mapInfo.name === "Nexus") {
if (
textPacket.text.startsWith('{"key":"server.dungeon_opened_by"')
) {
var keypop = JSON.parse(textPacket.text);
this.bot.callKey(
keypop.tokens.dungeon,
client.server.name,
keypop.tokens.name
);
}
}
}
/**
* The constructor object - waits for all player tracking events
*
* @param playerTracker the player tracker module
* @param runtime the current account runtime
* @param external the databse interface
*/
constructor(
playerTracker: PlayerTracker,
runtime: Runtime,
external: External
) {
this.runtime = runtime;
this.startPlayerTracker(playerTracker)
}
/**
* Start hooking events when players join and leave the nexus
*
* @param tracker the PlayerTracker module
*/
startPlayerTracker(tracker: PlayerTracker): void {
tracker.on('enter', (player) => {
/**
* Check if the player's username is unset or null and send a notification
*/
if (!player.name || player.name == "") {
this.bot.callNullName(player);
return;
}
/**
* Check if the player's username is invalid (non-alphanumeric) and send a notification
*/
if (!player.name.match(this.alphaRegex)) {
this.bot.callInvalidName(player);
return;
}
this.external.addLocation(player.name, player.server, "nexus");
/**
* Return a list of discord users tracking the player and send a notification with the area
*/
this.external.getTrackers(player.name, (trackers) => {
if (trackers.length > 0) {
trackers.forEach((tracker) => {
this.bot.callPlayer(player.name, tracker);
});
}
});
/**
* Check if the player's gold increased since the last time they were spotted
*/
this.external.checkGold(player, (playerData, oldGold) => {
if (playerData !== null) {
this.bot.callGoldPurchase(playerData, oldGold);
}
});
/**
* Check if the player has high char fame and send a notification
*/
if (player.currentFame > 30000) {
this.bot.callBaller(player);
}
/**
* Check if the player gold is high and send a notification
*/
if (player.gold > 20000) {
this.bot.callRichPlayer(player.name, player.gold);
}
/**
* Check if the player is in the DecaGMs guild
* Exclude MrEyeball as he spams the channel
*/
if (
RealmData.gmNames.includes(player.name) ||
player.guildName == "DecaGMs"
) {
if (player.name !== "MrEyeball") {
this.bot.callGameManager(player);
}
}
});
/**
* Called when a player leaves the nexus
*
* @param player the player's PlayerData
*/
tracker.on('leave', (player) => {
/*
* Fixes a weird bug where the players username gets unset and StatData can't be parsed
*/
if (!player.name || player.name == "") return;
/* Don't send notifications for default name accounts */
if (!player.nameChosen) return;
/**
* Check the players previous username by accountId
* If there's a username difference, call a username change
*/
this.external.checkNameChange(
player.accountId,
player.name,
(result) => {
if (result !== null) {
this.bot.callNameChange(result, player);
}
}
);
/**
* Parse the location the player left the nexus
*/
let area = this.getPlayerArea(player);
if (!area) {
let lowerCaseName = player.name.toLowerCase();
this.external.addLocation(player.name, player.server, area);
/**
* If the player entered a realm or bazaar, check discord staff lists
*/
if (area !== "vault" && area !== "ghall") {
this.callDiscordStaff(player, area);
}
/**
* Return a list of discord users tracking the player and send a notification with the area
*/
this.external.getTrackers(player.name, (trackers) => {
if (trackers.length > 0) {
trackers.forEach((tracker) => {
this.bot.callPlayer(player.name, tracker);
});
}
});
// TODO: FIX CALLBACK HELL!
}
})
}
/**
* Get the area where the player left the nexus based on their X,Y coordinates
*
* @param player the PlayerData
*/
public getPlayerArea(player: PlayerData): string {
let area: string = "";
let px: number = player.worldPos.x;
let py: number = player.worldPos.y;
/**
* Return a portal name based on player leave WorldPos
*/
if (py < 142 && py > 137) {
if (px < 117 && px > 110) area = "left";
if (px < 157 && px > 152) area = "right";
}
if (py < 144 && py > 140) {
if (px < 140 && px > 136) area = "vault";
if (px < 133 && px > 129) area = "ghall";
}
if (py > 102 && py < 116) {
if (px < 145 && px > 123) area = "realm";
}
if (area == '') return null;
return area;
}
/**
* If a discord staff member enters a realm or a bazaar, send a message in the
* appropriate channel
*
* @param player the PlayerData
* @param location the location i.e 'left' 'right' 'realm'
*/
public callDiscordStaff(player: PlayerData, location: string): void {
let lowerCaseName = player.name.toLowerCase();
/**
* Only check staff members who start raids in cloth bazaars
*/
if (location == "left" || location == "right") {
if (RealmData.pubhallsStaff.includes(lowerCaseName)) {
this.bot.callStaffLocation(
"pubhalls",
player.name,
player.server,
location
);
}
if (RealmData.fungalStaff.includes(lowerCaseName)) {
this.bot.callStaffLocation(
"fungal",
player.name,
player.server,
location
);
}
if (RealmData.shattersStaff.includes(lowerCaseName)) {
this.bot.callStaffLocation(
"shatters",
player.name,
player.server,
location
);
}
}
/**
* Only check staff members who start Oryx 3 raids
*/
if (location == "realm") {
if (RealmData.divinityStaff.includes(lowerCaseName)) {
this.bot.callStaffLocation(
"divinty",
player.name,
player.server,
location
);
}
if (RealmData.oryxSanctuaryStaff.includes(lowerCaseName)) {
this.bot.callStaffLocation(
"sanctuary",
player.name,
player.server,
location
);
}
if (RealmData.dungeoneerStaff.includes(lowerCaseName)) {
this.bot.callStaffLocation(
"dungeoneer",
player.name,
player.server,
location
);
}
}
/**
* Except SBC as they do clot bazaar and Oryx 3 runs
*/
if (RealmData.sbcStaff.includes(lowerCaseName)) {
this.bot.callStaffLocation(
"sbc",
player.name,
player.server,
location
);
}
}
}