This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Game.js
88 lines (77 loc) · 2.3 KB
/
Game.js
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
const EventSystem = require("./EventSystem");
const child_process = require("child_process");
class Game extends EventSystem {
constructor(version, session, ip, port, characterId, runScript, botUI, characterName) {
super();
this.process = null;
this.version = version;
this.session = session;
this.ip = ip;
this.port = port;
this.characterId = characterId;
this.runScript = runScript;
this.botUI = botUI;
this.characterName = characterName;
}
start() {
let data = {};
const args = [this.version, this.session, this.ip, this.port, this.characterId, this.runScript];
this.process = child_process.fork("./app/_Game", args, {
stdio: [0, 1, 2, 'ipc'],
execArgv: [
//'--inspect-brk',
//"--max_old_space_size=4096",
]
});
if (this.botUI) {
this.botUI.setDataSource(() => {
return data;
});
}
this.process.on("message", (m) => {
switch (m.type) {
case "bwiUpdate":
data = m.data;
break;
case "bwiPush":
if (this.botUI)
this.botUI.pushData(m.name, m.data);
break;
case "cm":
this.emit("cm", m.data);
break;
case "config":
this.emit("config", m.data);
break;
}
});
this.process.on("exit", () => {
this.emit("stop");
})
}
send_cm(message) {
if (message.receiver === this.characterName) {
this.process.send({
type: "on_cm",
from: message.data[0],
data: message.data[1],
date: message.data[2],
id: message.data[3]
})
return true;
}
return false;
}
send_cm_failed(data) {
this.process.send({
type: "send_cm_failed",
characterName: data.characterName,
data: data.data,
});
}
stop() {
if (this.process)
this.process.kill(15);
}
}
module.exports = Game;