-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
66 lines (52 loc) · 1.5 KB
/
Copy pathmain.js
File metadata and controls
66 lines (52 loc) · 1.5 KB
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
const { InSim } = require('node-insim');
const { IS_ISI_ReqI, PacketType } = require('node-insim/packets');
// Host 1
const inSimHost1 = new InSim('Local Host');
inSimHost1.connect({
IName: 'Node InSim App',
Host: '127.0.0.1',
Port: 29999,
ReqI: IS_ISI_ReqI.SEND_VERSION,
Admin: '',
});
inSimHost1.on('connect', onConnect);
inSimHost1.on('disconnect', onDisconnect);
inSimHost1.on(PacketType.ISP_VER, onVersion);
inSimHost1.on(PacketType.ISP_MSO, onMessage);
// Host 2
const inSimHost2 = new InSim('Host Two');
inSimHost2.connect({
IName: 'Node InSim App',
Host: '127.0.0.2',
Port: 29998,
ReqI: IS_ISI_ReqI.SEND_VERSION,
Admin: '',
});
inSimHost2.on('connect', onConnect);
inSimHost2.on('disconnect', onDisconnect);
inSimHost2.on(PacketType.ISP_VER, onVersion);
inSimHost2.on(PacketType.ISP_MSO, onMessage);
// Event handlers
function onConnect(inSim) {
console.log(
`Connected to ${inSim.options.Host}:${inSim.options.Port} (${inSim.id})`,
);
}
function onDisconnect(inSim) {
console.log(
`Disconnected from ${inSim.options.Host}:${inSim.options.Port} (${inSim.id})`,
);
}
function onVersion(packet, inSim) {
console.log(
`Connected to LFS ${packet.Product} ${packet.Version} at ${inSim.options.Host}:${inSim.options.Port} (${inSim.id})`,
);
}
function onMessage(packet, inSim) {
console.log(
`${inSim.options.Host}:${inSim.options.Port} (${inSim.id}) - message received: ${packet.Msg}`,
);
}
process.on('uncaughtException', (error) => {
console.log(error);
});