This repository was archived by the owner on Jun 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexample.js
More file actions
64 lines (47 loc) · 1.62 KB
/
example.js
File metadata and controls
64 lines (47 loc) · 1.62 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
var BattleCon = require("./src/BattleCon.js"),
config = require("./config.json"),
repl = require("repl"),
bc = new BattleCon(config.host, config.port, config.pass).use("BF4");
bc.on("connect", function() {
console.log("# Connected to "+bc.host+":"+bc.port);
});
bc.on("login", function() {
console.log("# Login successful");
});
bc.on("ready", function() {
// Execute raw commands:
bc.exec("version", function(err, msg) {
console.log("# Server is running "+msg[0]+", version "+msg[1]);
});
// Execute module commands (core.js):
bc.serverInfo(function(err, info) {
console.log("Server info:", info);
});
bc.listPlayers(function(err, players) {
console.log("There are "+players.length+" connected players:");
for (var i=0; i<players.length; i++) {
console.log(players[i]);
}
});
// Handle raw events:
bc.on("event", function(msg) {
console.log("# "+msg.data.join(' '));
});
// Handle module events (BF.js):
bc.on("player.join", function(name, guid) {
console.log("# Player joined: "+name+" ("+guid+")");
});
bc.on("player.leave", function(name, info) {
console.log("# Player left: "+name+" ("+info.guid+")");
});
bc.on("player.chat", function(name, text, subset) {
console.log("# "+name+" -> "+subset.join(' ')+": "+text);
});
});
bc.on("close", function() {
console.log("# Disconnected.");
});
bc.on("error", function(err) {
console.log("# Error: "+err.message, err.stack);
});
bc.connect(); // Connects and logs in