├── .gitignore
├── CODE
└── default.js
├── Config.js
├── EventSystem.js
├── Game.js
├── GameController.js
├── GameDataManager.js
├── LICENSE.txt
├── README.md
├── ServerList.js
├── app
├── Context.js
├── Extensions.js
├── GameContext.js
├── GameFiles.js
├── HttpWrapper.js
├── Logger.js
├── RunnerContext.js
├── UIGenerator.js
├── _Game.js
├── bwiUtil.js
├── defaultUI.json
├── html_vars.js
├── patches
│ ├── 0001-remove-log-spam.js
│ ├── 0002-add-localStorage.js
│ ├── 0003-add-sessionStorage.js
│ ├── 0004-add-null-check-localstorage-cm.js
│ ├── 0005-add-ipc-based-send-cm.js
│ └── 0006-fix-load_code.js
└── pngUtil.js
├── data
└── .gitignore
├── main.js
├── package-lock.json
├── package.json
├── pathfinding
├── Floor.js
├── MapProcessor.js
├── PathUtils.js
├── Pathfinding.js
├── PriorityQueue.js
├── World.js
├── _Pathfinding.js
├── cache
│ └── .gitignore
└── output.js
└── userData.example.json
/.gitignore:
--------------------------------------------------------------------------------
1 | userData.json
2 | /node_modules/
3 | .idea/
4 | ./package-lock.json
5 | /CODE/
6 | /app/localStorage/
7 | /app/sessionStorage/
--------------------------------------------------------------------------------
/CODE/default.js:
--------------------------------------------------------------------------------
1 | var reviving = false;
2 | var targetMonster = "crab";
3 | var fighting = false;
4 |
5 | if (character.rip) {
6 | setTimeout(function () {
7 | respawn();
8 | setTimeout(function () {
9 | smart_move(targetMonster, function () {
10 | fighting = true;
11 | });
12 | }, 1000);
13 | }, 12000);
14 | } else {
15 | smart_move(targetMonster, function () {
16 | fighting = true;
17 | });
18 | }
19 |
20 | setInterval(function () {
21 | if (!fighting) {
22 | return;
23 | }
24 |
25 | if (character.rip && !reviving) {
26 | reviving = true;
27 | fighting = false;
28 | var position = {
29 | x: character.real_x,
30 | y: character.real_y,
31 | map: character.map,
32 | };
33 | setTimeout(function () {
34 | respawn();
35 | setTimeout(function () {
36 | reviving = false;
37 | smart_move(position, function () {
38 | fighting = true;
39 | });
40 | }, 1000)
41 | }, 12000)
42 | }
43 |
44 | if (can_use("hp") && (character.hp / character.max_hp <= .50) || (character.max_hp - character.hp > 200)) {
45 | use("hp");
46 | }
47 |
48 | if (can_use("mp") && character.mp / character.max_mp <= .50 || (character.max_mp - character.mp > 300)) {
49 | use("mp");
50 | }
51 | loot();
52 |
53 |
54 | let target;
55 | target = get_nearest_monster({type: targetMonster});
56 | change_target(target);
57 | if (target) {
58 | if (can_attack(target)) {
59 | attack(target);
60 | } else {
61 | let dist = Math.sqrt(Math.pow(target.real_x - character.real_x, 2) + Math.pow(target.real_y - character.real_y, 2))
62 | if (dist > character.range - 20)
63 | move((target.real_x + character.real_x) / 2, (target.real_y + character.real_y) / 2);
64 | }
65 | }
66 | }, 1000 / 4);
67 |
--------------------------------------------------------------------------------
/Config.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | class UserData {
4 | constructor() {
5 | this.config = this.readConfig();
6 | }
7 |
8 | validate() {
9 | // check some common mistakes that can happen when you manually edit the config,
10 | // nothing special just helping out new users
11 | if (!this.config.bots) {
12 | console.error("Missing field \"bots\" in userData.json");
13 | if (!this.config.config.fetch)
14 | return false;
15 | }
16 |
17 | if (!this.config.login || !this.config.login.email || !this.config.login.password) {
18 | console.error("Missing Login Information");
19 | return false;
20 | }
21 | let botCount = 0;
22 | for (let i = 0; i < this.config.bots.length; i++) {
23 | if (!(this.config.bots[i] && this.config.bots[i].characterId && this.config.bots[i].runScript && this.config.bots[i].server && typeof this.config.bots[i].enabled === "boolean")) {
24 | console.error("One or more necessary fields are missing from userData.json \nThe following fields need to be present for a working executor:\n characterId\n runScript\n server\n enabled\nTo fix this automatically simply set fetch: true in userdata.json");
25 | return false;
26 | }
27 | if (this.config.bots[i].enabled)
28 | botCount++;
29 | }
30 |
31 | if (this.config.bots.length === 0) {
32 | console.warn("Couldn't find any bots to start you can set the fetch flag the pull all characters from the server.");
33 | }
34 | if (botCount === 0) {
35 | console.warn("Couldn't find any bots to start, make sure the enable flag is set to true");
36 | } else if (botCount > 4) {
37 | console.warn("You are starting more 4 than bots at once, this will lead to your characters getting disconnected Please refer to http://adventure.land/docs/guide/limits");
38 | }
39 | }
40 |
41 | getBots() {
42 | let bots = [];
43 | for (let i = 0; i < this.config.bots.length; i++) {
44 | if (this.config.bots[i].enabled) {
45 | bots.push(this.config.bots[i]);
46 | }
47 | }
48 | return bots;
49 | }
50 |
51 | isFetch() {
52 | return this.config.config.fetch;
53 | }
54 |
55 | toggleFetch() {
56 | this.config.config.fetch = !this.config.config.fetch;
57 | this.writeConfig(this.config);
58 | }
59 |
60 | setBots(bots) {
61 | this.config.bots = bots
62 | this.writeConfig(this.config);
63 | }
64 |
65 | getLogin() {
66 | return Object.assign({}, this.config.login)
67 | }
68 |
69 | getSession() {
70 | return this.config.login.session;
71 | }
72 |
73 | setSession(session) {
74 | this.config.login.session = session;
75 | this.writeConfig(this.config);
76 | }
77 |
78 | readConfig() {
79 | const text = fs.readFileSync("userData.json").toString("utf8");
80 | return JSON.parse(text);
81 | }
82 |
83 | writeConfig(data) {
84 | let json = JSON.stringify(data, null, 4);
85 | fs.writeFileSync("userData.json", json)
86 | }
87 |
88 | isPathfinding() {
89 | return this.config.config.pathfinding.enabled;
90 | }
91 | }
92 |
93 | module.exports = new UserData();
94 |
--------------------------------------------------------------------------------
/EventSystem.js:
--------------------------------------------------------------------------------
1 | class EventSystem {
2 |
3 | constructor() {
4 | this.listeners = new Map();
5 | }
6 |
7 | on(eventName, callback) {
8 | if (this.listeners.has(eventName)) {
9 | this.listeners.get(eventName).push(callback);
10 | } else {
11 | this.listeners.set(eventName, [callback]);
12 | }
13 | }
14 |
15 | async emit(eventName, data) {
16 | const listeners = this.listeners.get(eventName);
17 | if (!listeners) {
18 | return;
19 | }
20 |
21 | for (const listener of listeners) {
22 | try {
23 | await listener(data);
24 | } catch (e) {
25 | console.error(e);
26 | }
27 | }
28 | }
29 |
30 | remove(eventName, callback) {
31 | const listeners = this.listeners.get(eventName);
32 | const i = listeners.indexOf(callback);
33 | listeners.splice(i, 1);
34 | }
35 | }
36 |
37 | module.exports = EventSystem;
--------------------------------------------------------------------------------
/Game.js:
--------------------------------------------------------------------------------
1 | const EventSystem = require("./EventSystem");
2 | const child_process = require("child_process");
3 |
4 |
5 | class Game extends EventSystem {
6 | constructor(version, session, ip, port, characterId, runScript, botUI, characterName) {
7 | super();
8 | this.process = null;
9 | this.version = version;
10 | this.session = session;
11 | this.ip = ip;
12 | this.port = port;
13 | this.characterId = characterId;
14 | this.runScript = runScript;
15 | this.botUI = botUI;
16 | this.characterName = characterName;
17 |
18 | }
19 |
20 | start() {
21 | let data = {};
22 | const args = [this.version, this.session, this.ip, this.port, this.characterId, this.runScript];
23 | this.process = child_process.fork("./app/_Game", args, {
24 | stdio: [0, 1, 2, 'ipc'],
25 | execArgv: [
26 | //'--inspect-brk',
27 | //"--max_old_space_size=4096",
28 | ]
29 | });
30 | if (this.botUI) {
31 | this.botUI.setDataSource(() => {
32 | return data;
33 | });
34 | }
35 |
36 | this.process.on("message", (m) => {
37 | switch (m.type) {
38 | case "bwiUpdate":
39 | data = m.data;
40 | break;
41 | case "bwiPush":
42 | if (this.botUI)
43 | this.botUI.pushData(m.name, m.data);
44 | break;
45 | case "cm":
46 | this.emit("cm", m.data);
47 | break;
48 | case "config":
49 | this.emit("config", m.data);
50 | break;
51 |
52 | }
53 | });
54 | this.process.on("exit", () => {
55 | this.emit("stop");
56 | })
57 |
58 | }
59 |
60 | send_cm(message) {
61 | if (message.receiver === this.characterName) {
62 | this.process.send({
63 | type: "on_cm",
64 | from: message.data[0],
65 | data: message.data[1],
66 | date: message.data[2],
67 | id: message.data[3]
68 | })
69 | return true;
70 | }
71 | return false;
72 | }
73 |
74 | send_cm_failed(data) {
75 | this.process.send({
76 | type: "send_cm_failed",
77 | characterName: data.characterName,
78 | data: data.data,
79 | });
80 | }
81 |
82 | stop() {
83 | if (this.process)
84 | this.process.kill(15);
85 | }
86 | }
87 |
88 | module.exports = Game;
--------------------------------------------------------------------------------
/GameController.js:
--------------------------------------------------------------------------------
1 | const Game = require("./Game");
2 |
3 | async function sleep(ms) {
4 | return new Promise(function (res) {
5 | setTimeout(res, ms)
6 | })
7 | }
8 |
9 | class GameController {
10 | constructor(httpWrapper, serverList, gameDataManager, botWebInterface) {
11 | this.bots = new Map();
12 | this.serverList = serverList;
13 | this.httpWrapper = httpWrapper;
14 | this.gameDataManager = gameDataManager;
15 | this.botWebInterface = botWebInterface;
16 | }
17 |
18 | async startCharacter(characterId, server, runScript, characterName, gameVersion) {
19 | return new Promise(async (resolve) => {
20 | let serverInfo = await this.serverList.getServerInfo(server);
21 | while (!serverInfo) {
22 | console.log(`Unable to find server: ${server}, retrying in 10 seconds`);
23 | await sleep(10000);
24 | serverInfo = await this.serverList.getServerInfo(server);
25 | }
26 | let botUI = null;
27 | if (this.botWebInterface)
28 | botUI = this.botWebInterface.publisher.createInterface();
29 | const game = new Game(gameVersion, this.httpWrapper.sessionCookie, serverInfo.addr, serverInfo.port, characterId, runScript, botUI, characterName);
30 |
31 | game.on("start", resolve);
32 | game.on("stop", () => {
33 | let data = this.bots.get(characterId);
34 | if (data.botUI)
35 | data.botUI.destroy();
36 | this.bots.delete(characterId);
37 | if (!data.stopping) {
38 | console.log(`character: ${characterId} stopped unexpectedly, restarting ...`)
39 | this.bots.delete(characterId);
40 | setTimeout(() => {
41 | this.startCharacter(characterId, server, runScript, characterName, gameVersion)
42 | }, 1000);
43 | }
44 | });
45 |
46 | game.on("cm", (data) => {
47 | for (let [characterId, bot] of this.bots) {
48 | if (bot.game.send_cm(data)) {
49 | return;
50 | }
51 | }
52 | game.send_cm_failed(data)
53 | })
54 | game.on("config", async (data) => {
55 | console.log(data)
56 | switch (data.type) {
57 | case "switchServer":
58 | await this.stopCharacter(characterId);
59 | await this.startCharacter(characterId, data.server, runScript, characterName, gameVersion)
60 | break;
61 | }
62 | })
63 | this.bots.set(characterId, {
64 | characterId,
65 | server,
66 | runScript,
67 | botUI,
68 | game: game,
69 | stopping: false,
70 | });
71 | game.start();
72 | })
73 | }
74 |
75 | async stopCharacter(characterId) {
76 | return new Promise((resolve, reject) => {
77 | let bot = this.bots.get(characterId);
78 | if (bot) {
79 | bot.game.on("stop", resolve);
80 | bot.stopping = true;
81 | bot.game.stop();
82 | } else {
83 | resolve();
84 | }
85 | });
86 | }
87 |
88 |
89 | }
90 |
91 | module.exports = GameController;
--------------------------------------------------------------------------------
/GameDataManager.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const path = require("path")
3 | const gameFiles = [
4 | "/js/pixi/fake/pixi.min.js",
5 | "/js/libraries/combined.js",
6 | "/js/codemirror/fake/codemirror.js",
7 | "/js/common_functions.js",
8 | "/js/functions.js",
9 | "/js/game.js",
10 | "/js/html.js",
11 | "/js/payments.js",
12 | "/js/keyboard.js",
13 | "/data.js",
14 | "/js/common_functions.js",
15 | "/js/runner_functions.js",
16 | "/js/runner_compat.js"
17 | ];
18 | sleep = async function (num) {
19 | return new Promise(function (resolve) {
20 | setTimeout(resolve, num);
21 | });
22 | };
23 |
24 | class GameDataManager {
25 | constructor(httpWrapper) {
26 | this.httpWrapper = httpWrapper;
27 | this.currentGameVersion = -1
28 | this.lastUpdated = 0;
29 | }
30 |
31 | async currentVersion() {
32 | if (this.lastUpdated < Date.now() - 60 * 1000) {
33 | this.lastUpdated = Date.now();
34 | let version = 0;
35 | do {
36 | try {
37 | version = await this.httpWrapper.getGameVersion();
38 | } catch (e) {
39 | console.log(e);
40 | await sleep(15000);
41 | }
42 | } while (!version)
43 | this.currentGameVersion = version;
44 | return version;
45 | } else {
46 | return this.currentGameVersion;
47 | }
48 | }
49 |
50 | async isUpToDate() {
51 | const versions = this.getAvailableVersions();
52 | let gameVersion = await this.currentVersion();
53 | return versions.includes("" + gameVersion);
54 |
55 | }
56 |
57 | getAvailableVersions() {
58 | let files = fs.readdirSync("./data", {withFileTypes: true});
59 | let versions = [];
60 | for (let file of files) {
61 | if (file.isDirectory())
62 | versions.push(+file.name)
63 | }
64 | return versions.sort((a, b) => b - a).map((a) => "" + a);
65 | }
66 |
67 | async updateGameData() {
68 | let gameVersion = await this.currentVersion();
69 |
70 | for (let gameFile of gameFiles) {
71 | let data = await this.httpWrapper.getFile(gameFile);
72 | let localPath = path.join("data", "" + gameVersion, gameFile)
73 | fs.mkdirSync(path.parse(localPath).dir, {recursive: true})
74 | fs.writeFileSync(localPath, data)
75 | }
76 | return gameVersion;
77 | }
78 |
79 | async readPatches(gameVersion) {
80 | let localPath = path.join("data", "" + gameVersion, "/patches.json")
81 | let patches = [];
82 | try {
83 | patches = JSON.parse(fs.readFileSync(localPath).toString());
84 | } catch (e) {
85 | if (e.code !== "ENOENT")
86 | throw e;
87 | }
88 | return patches;
89 | }
90 |
91 | async writeAppliedPatches(gameVersion, patches) {
92 | let localPath = path.join("data", "" + gameVersion, "/patches.json")
93 | fs.writeFileSync(localPath, JSON.stringify(patches))
94 | }
95 |
96 | async readFiles(gameVersion) {
97 | let files = {};
98 |
99 | for (let gameFile of gameFiles) {
100 | let localPath = path.join("data", "" + gameVersion, gameFile)
101 | files[gameFile] = fs.readFileSync(localPath).toString();
102 | }
103 | return files;
104 | }
105 |
106 | async writeFiles(files, gameVersion) {
107 | for (let filePath in files) {
108 | let localPath = path.join("data", "" + gameVersion, filePath)
109 | fs.writeFileSync(localPath, files[filePath]);
110 | }
111 | return files;
112 | }
113 |
114 | async applyPatches(gameVersion) {
115 | let patches = fs.readdirSync("app/patches");
116 | let appliedPatches = await this.readPatches(gameVersion);
117 | let files = await this.readFiles(gameVersion);
118 | console.log("Applying patches to " + gameVersion);
119 | let failed = false;
120 | for (let patchPath of patches) {
121 | if (failed)
122 | break;
123 | let patch = require("./" + path.join("app/patches/", patchPath));
124 | try {
125 | if (!appliedPatches.includes(patchPath)) {
126 | console.log(" " + patchPath);
127 | patch.run(files);
128 | appliedPatches.push(patchPath);
129 | }
130 | } catch (e) {
131 | console.error("Failed to execute patch '" + patchPath + "'");
132 | console.error(e);
133 | failed = true;
134 | }
135 | }
136 | if (failed) {
137 | let error = new Error("Unable to apply all patches to game version:" + gameVersion);
138 | error.code = "PATCH_FAIL";
139 | throw error;
140 | }
141 | await this.writeAppliedPatches(gameVersion, appliedPatches)
142 | await this.writeFiles(files, gameVersion)
143 |
144 |
145 | }
146 | }
147 |
148 | module.exports = GameDataManager;
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ALBot
2 |
3 | ## Installation Debian 8
4 | 1. Update system
5 | ```
6 | sudo apt update
7 | sudo apt upgrade
8 | ```
9 | 2. Install packages
10 | ```
11 | sudo apt install git nano screen curl
12 | ```
13 | 3. Install nvm
14 | ```
15 | curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.37.2/install.sh | bash
16 | bash
17 | ```
18 | 4. Use nvm to install node 7.9.0
19 | ```
20 | nvm install stable
21 | ```
22 | 5. Download ALBot
23 | ```
24 | git clone https://github.com/NexusNull/ALBot.git
25 | ```
26 | 6. Install package dependencies
27 | ```
28 | cd ALBot
29 | npm install
30 | ```
31 | 7. Rename copy config file and enter credentials. If you don't know how, refer to Section [Understanding userData.json](#Understanding-userData.json)
32 | ```
33 | cp userData.example.json userData.json
34 | nano userData.json
35 | ```
36 | 8. Run the bot once with
37 | ```
38 | node main
39 | ```
40 | The bot will then try to log in to your account and save your character ids to userdata.json
41 | 9. Open userData.json again and delete all the character objects you don't want to run.
42 | However, there currently is no client side check for character limitations, if you forget this your bot will keep disconnecting.
43 |
44 | 10. Congratulations you now have a working copy of ALBot, if you experience unexpected behavior please raise an issue.
45 |
46 | ## Installation Windows
47 | 1. Install git
48 | [https://git-scm.com/download/win](https://git-scm.com/download/win)
49 |
50 | 2. Install node
51 | [https://nodejs.org/en/download/](https://nodejs.org/en/download/)
52 |
53 | 3. open folder in which you would like to install ALBot
54 |
55 | 4. shift + Right Click -> Open Command Window Here
56 |
57 | 5. execute the following commands in the console
58 | ```
59 | git clone https://github.com/NexusNull/ALBot.git
60 | cd ALBot
61 | npm install
62 | copy userData.json-example userData.json
63 | ```
64 |
65 | 6. Open the config file (userData.json) in your favorite editor and enter your credentials. If you don't know how, refer to Section [Understanding userData.json](#Understanding-userData.json)
66 |
67 | 7. Run the bot once with
68 | ```
69 | node main
70 | ```
71 | The bot will then try to log in to your account and save your character ids to userdata.json
72 |
73 | 9. Open userData.json again and delete all the character objects you don't want to run.
74 | However, there currently is no client side check for character limitations, if you forget this your bot will keep disconnecting.
75 |
76 | 10. Congratulations you now have a working copy of ALBot, if you experience unexpected behavior please raise an issue.
77 |
78 | ## Understanding userData.json
79 |
80 | ### Config
81 | With ongoing updates the properties of config are becoming more and more complex, so I want to take some time to explain them in detail here.
82 |
83 | #### fetch
84 | The fetch property sets the bot up in a way that it will discard any existing data about characters and then try to fetch them from the server. This is set to true when ever you recieve a fresh copy of ALBot simply because ALBot needs to get this information first before anything else can be done. The fetched data is then put into the the `"bots"` array ready for editing.
85 |
86 | #### botWebInterface
87 | Bot-web-interface or BWI is another module that I developed which displays data using a graphical interface.
88 | Granted it doesn't look as fancy as I would like it to, but it does its job. ALBot uses BWI to display basic information about the running characters, this information is constanty updated without requiring user interaction.
89 |
90 | 
91 |
92 | As you can see it contains the name and level but also TLU which stands for 'time to level up'. BWI also has the option to display and update pictures, we use this here to automatically display what the bot sees and what is happening around it. The green dot represent the current character, red dots are monsters and red lines are attacks. White lines are the collision boxes of the map.
93 |
94 | BWI can be enabled/disabled by setting the start property, by default this is set to false. One thing to note is that BWI uses 2 consecutive ports meaning with you want to expose BWI to the internet by port forwarding you will have to port forward the port listed here and one higher. If need be I can change that behaviour but as long as nobody complains it's staying that way.
95 | If you do decide to open BWI to the internet, there is still the option to protect it with a password so only you can access it. Such a setup can be useful if you have it running on a server but want to check up on it from work.
96 |
97 | First a word of caution, the mini map is a nice little feature that has been added recently and is still not as polished as I want it to be. The way the mini map is implemented is very hacky, it works by sending data url converted PNG images to the client, high frame rates can cause many issues such as high cpu usage on the server side and GPU crashes on the client side. I recommend a frame rate of 1.
98 |
99 | If you want to enable the mini map, set enable to true. The speed property determines the interval in which images are generated and send to the client, you can make it faster by decreasing the speed value.
100 | Size controls the resolution of the generated image.
101 |
102 |
103 |
104 | ```code
105 | {
106 | "config": {
107 | "fetch": true,
108 | "botKey": 1,
109 | "botWebInterface": {
110 | "start": false,
111 | "port": 2080,
112 | "password": "",
113 | "minimap": {
114 | "enable": false,
115 | "speed": 1000,
116 | "size": {
117 | "height": 200,
118 | "width": 376
119 | }
120 | }
121 | }
122 | },
123 | "login": {
124 | "email": "random@example.com",
125 | "password": "password123456"
126 | },
127 | "bots": []
128 | }
129 | ```
130 |
131 | If you have questions and/or suggestions please refer to [repo](https://github.com/NexusNull/bot-web-interface).
132 | If fetch is set to true, it will fetch your character data on the next run. This means previous entries in bots will be overwritten.
133 |
134 | By default, the bot will connect to the server, fetch the data for all available characters and then close again.
135 | After the fetch is complete, you can edit the CODE script that is run for each character, and the server it should connect to.
136 |
137 | The character name is irrelevant when running ALBot. The bot will use the character id to identify the character and only refer to its name if the id is missing.
138 | The `runScript` entry must contain a relative path to the script that should be run for the character. `server` is the server name the character should connect to, the possible servers are "US I", "US PVP".
139 | There used to be more but sadly they were taken down.
140 |
141 |
142 | ## Running your own code
143 | The default code located at `./CODE/default.js`, the runScript entry in `userData.json` corresponds with the name of the script that should be run for the character. The environment is fundamentally the same as a browser with some exceptions, for example references to window, document, and PIXI are not supported. Every character can run a different file, the default.js script will send characters to farm tiny crabs on the main beach.
144 |
145 | ## Contributing
146 | Feel free to make contributions, they are always welcome!
147 |
148 |
--------------------------------------------------------------------------------
/ServerList.js:
--------------------------------------------------------------------------------
1 | sleep = async function (num) {
2 | return new Promise(function (resolve) {
3 | setTimeout(resolve, num);
4 | });
5 | };
6 |
7 | class ServerList {
8 | constructor(httpWrapper) {
9 | this.httpWrapper = httpWrapper;
10 | this.lastUpdate = 0;
11 | this.serverList = [];
12 | }
13 |
14 | async getServerInfo(serverIdentifier) {
15 | await this.updateServerList();
16 | try {
17 | let [region, name] = serverIdentifier.split(" ");
18 | for (let server of this.serverList) {
19 | if (region === server.region && name === server.name) {
20 | return server;
21 | }
22 | }
23 | } catch (e) {
24 | return null;
25 | }
26 | }
27 |
28 | async updateServerList() {
29 | if (this.lastUpdate < (new Date().getTime()) - 60 * 1000) {
30 | let data;
31 | do {
32 | try {
33 | data = await this.httpWrapper.getServersAndCharacters();
34 | } catch (e) {
35 | console.log(e);
36 | await sleep(15000);
37 | }
38 | } while (!data);
39 | this.serverList = data.servers
40 | this.lastUpdate = new Date().getTime();
41 | }
42 | }
43 | }
44 |
45 | module.exports = ServerList;
--------------------------------------------------------------------------------
/app/Context.js:
--------------------------------------------------------------------------------
1 | const vm = require("vm");
2 | const node_query = require('jquery');
3 | const {JSDOM} = require("jsdom");
4 | const fs = require('fs').promises;
5 |
6 | const htmlSpoof = `
7 |
8 |
9 | Adventure Land
10 |
11 |
12 |
13 | `
14 |
15 | class Context {
16 | constructor(upperContext = null) {
17 | this.children = [];
18 | this.parent = null;
19 |
20 | const pre_context = new JSDOM(htmlSpoof, {url: "https://adventure.land/"}).window
21 | pre_context.$ = node_query(pre_context)
22 | pre_context.jQuery = node_query(pre_context);
23 | pre_context.require = require;
24 |
25 | if (upperContext && upperContext instanceof Context) {
26 | upperContext.addChild(this)
27 | this.parent = upperContext;
28 | Object.defineProperty(pre_context, "parent", {value: upperContext.context});
29 | }
30 |
31 | pre_context.eval = (arg) => {
32 | return vm.runInContext(arg, pre_context)
33 | };
34 |
35 | this.context = vm.createContext(pre_context);
36 | }
37 |
38 | addChild(context) {
39 | this.children.push(context);
40 | }
41 |
42 | eval(code) {
43 | vm.runInContext(code, this.context);
44 | }
45 |
46 | async evalFile(path) {
47 | if(typeof path != "string")
48 | throw new Error()
49 | let text = await fs.readFile(path, 'utf8');
50 | vm.runInContext(text + "\n//# sourceURL=file://" + path, this.context);
51 | }
52 | }
53 |
54 | module.exports = Context;
--------------------------------------------------------------------------------
/app/Extensions.js:
--------------------------------------------------------------------------------
1 | module.exports = (gameContext, runnerContext) => {
2 | return {
3 | shutdown: () => process.exit(0),
4 | reload: this.shutdown,
5 | send_cm: (receiver, data) => {
6 | process.send({type: "cm", data: {receiver: receiver, data: data}});
7 | },
8 | switchServer: (server) => {
9 | process.send({type: "config", data: {type: "switchServer", server: server}});
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/app/GameContext.js:
--------------------------------------------------------------------------------
1 | const Context = require("./Context");
2 | const gameFiles = new (require("./GameFiles"))();
3 | const _fs = require('fs');
4 | const io = require("socket.io-client");
5 | const Extensions = require("./Extensions");
6 | const path = require("path")
7 |
8 | class GameContext extends Context {
9 | constructor(version) {
10 | super();
11 | this.version = version;
12 | }
13 |
14 | async init(realm_addr, realm_port, session, characterId) {
15 | const sources = gameFiles.gameFiles
16 | .map(f => gameFiles.locate_game_file(f, this.version))
17 | .concat(["./app/html_vars.js"]);
18 | this.context.io = io;
19 | this.context.bowser = {};
20 | for (let path of sources) {
21 | await this.evalFile(path);
22 | }
23 | this.context.VERSION = "" + this.context.G.version;
24 | this.context.server_addr = realm_addr;
25 | this.context.server_port = realm_port;
26 | this.context.user_id = session.split("-")[0];
27 | this.context.user_auth = session.split("-")[1];
28 | this.context.character_to_load = characterId;
29 | this.context.get_code_function = (f_name) => {
30 | for (let context of this.children) {
31 | if (context.context[f_name]) {
32 | return context.context[f_name];
33 | }
34 | }
35 | return () => undefined;
36 | }
37 | this.context.get_code_file = (name_or_slot) => {
38 | if (typeof name_or_slot === "string") {
39 | let buffer;
40 | try {
41 | buffer = _fs.readFileSync(path.join(__dirname, "../CODE/", name_or_slot));
42 | } catch (e) {
43 | console.log("Unable to locate File");
44 | console.log(path.join(__dirname, "../CODE/", name_or_slot))
45 | }
46 |
47 | if (buffer)
48 | return buffer.toString();
49 | }
50 | }
51 | this.context.run_code = (code, onerror) => {
52 | if (typeof onerror != "function")
53 | onerror = (e) => undefined;
54 | try {
55 | this.children[0].eval(code)
56 | } catch (e) {
57 | try {
58 | onerror(e);
59 | } catch (e) {
60 | console.log(e)
61 | }
62 | }
63 | }
64 | const extensions = Extensions();
65 | this.context.caracAL = extensions;
66 | this.context.albot = extensions;
67 | let resolve, reject;
68 | const prom = new Promise((a, b) => {
69 | resolve = a;
70 | reject = b;
71 | });
72 | const old_game_logic = this.context.new_game_logic;
73 | this.context.new_game_logic = async () => {
74 | await old_game_logic();
75 | clearTimeout(extensions.reload_task);
76 | resolve();
77 | }
78 |
79 | const timeout = 10;
80 | extensions.reload_task = setTimeout(() => {
81 | console.log("game not loaded after " + timeout + " seconds, reloading");
82 | reject();
83 | }, timeout * 1000 + 100);
84 |
85 | const old_dc = this.context.disconnect;
86 | this.context.disconnect = () => {
87 | old_dc();
88 | extensions.relog();
89 | }
90 |
91 |
92 | this.eval("add_log = console.log");
93 | this.eval("the_game()");
94 | await prom;
95 | console.log("game instance constructed");
96 | }
97 |
98 | }
99 |
100 | module.exports = GameContext;
--------------------------------------------------------------------------------
/app/GameFiles.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs").promises;
2 |
3 | class GameFiles {
4 | constructor() {
5 | this.runnerFiles = [
6 | "/js/common_functions.js",
7 | "/js/runner_functions.js",
8 | "/js/runner_compat.js"
9 | ]
10 | this.gameFiles = [
11 | "/js/pixi/fake/pixi.min.js",
12 | "/js/libraries/combined.js",
13 | "/js/codemirror/fake/codemirror.js",
14 |
15 | "/js/common_functions.js",
16 | "/js/functions.js",
17 | "/js/game.js",
18 | "/js/html.js",
19 | "/js/payments.js",
20 | "/js/keyboard.js",
21 | "/data.js"
22 | ]
23 | }
24 |
25 | locate_game_file(resource, version) {
26 | return `./data/${version}${resource}`;
27 | }
28 |
29 | async available_versions() {
30 | return (await fs.readdir("./data",
31 | {withFileTypes: true}))
32 | .filter(dirent => dirent.isDirectory())
33 | .map(dirent => dirent.name)
34 | .filter(x => x.match(/^\d+$/))
35 | .map(x => parseInt(x))
36 | .sort().reverse();
37 | }
38 | }
39 |
40 | module.exports = GameFiles;
--------------------------------------------------------------------------------
/app/HttpWrapper.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by nexus on 15/05/17.
3 | */
4 | const glob_config = require("../Config");
5 | const axios = require("axios");
6 | const FormData = require('form-data');
7 | const base_url = glob_config.config.config.baseUrl || "https://adventure.land";
8 |
9 | /**
10 | *
11 | * @constructor
12 | */
13 | class HttpWrapper {
14 | constructor() {
15 | this.sessionCookie = "";
16 |
17 | }
18 |
19 | setSession(session) {
20 | this.sessionCookie = session;
21 | }
22 |
23 | /**
24 | *
25 | * @param email
26 | * @param password
27 | * @return {Object}
28 | */
29 | async login(email, password) {
30 | let error = "";
31 | let form = new FormData();
32 | form.append("method", "signup_or_login")
33 | form.append("arguments", '{"email":"' + email + '","password":"' + password + '","only_login":true}')
34 | let response = await axios.post(base_url + "/api/signup_or_login", form, {
35 | timeout: 2000,
36 | headers: form.getHeaders()
37 | });
38 |
39 | let data = response.data;
40 | let loginSuccessful = false;
41 | for (let i = 0; i < data.length; i++) {
42 | if (typeof data[i].type === "string") {
43 | if (data[i].type === "message") {
44 | if (typeof data[i].message === "string") {
45 | if (data[i].message === "Logged In!") {
46 | loginSuccessful = true;
47 | }
48 | }
49 | } else if (data[i].type === "ui_error") {
50 | if (typeof data[i].message === "string") {
51 | error = data[i].message;
52 | loginSuccessful = false;
53 | }
54 | }
55 | }
56 | }
57 | if (loginSuccessful) {
58 | let cookies = response.headers["set-cookie"];
59 | for (let i = 0; i < cookies.length; i++) {
60 | var match = /auth=([0-9]+-[a-zA-Z0-9]+)/g.exec(cookies[i]);
61 | if (match) {
62 | this.sessionCookie = match[1];
63 | }
64 | }
65 | } else {
66 | throw new Error("Not logged in: " + error)
67 | }
68 | return loginSuccessful;
69 | };
70 |
71 | async getServersAndCharacters() {
72 | let form = new FormData();
73 | form.append("method", "servers_and_characters")
74 | form.append("arguments", '{}');
75 | let response = await axios.post(base_url + "/api/servers_and_characters", form, {
76 | timeout: 2000,
77 | headers: Object.assign(form.getHeaders(), {cookie: "auth=" + this.sessionCookie})
78 | });
79 | let data = response.data[0];
80 | if (data.type === "servers_and_characters")
81 | return data;
82 | else
83 | throw new Error("Not logged in")
84 | };
85 |
86 | async checkLogin() {
87 | return new Promise(async (resolve) => {
88 | const form = new FormData();
89 | form.append("method", "servers_and_characters")
90 | form.append("arguments", '{}');
91 | const response = await axios.post(base_url + "/api/servers_and_characters", form, {
92 | timeout: 2000,
93 | headers: Object.assign(form.getHeaders(), {cookie: "auth=" + this.sessionCookie})
94 | });
95 |
96 | const data = response.data[0];
97 | if (data.args && data.args[0] === "Not logged in.") {
98 | resolve(false);
99 | } else if (data.type && data.type === "servers_and_characters") {
100 | resolve(true);
101 | }
102 | resolve(false);
103 | })
104 | };
105 |
106 | async getFile(path) {
107 | return (await axios.get(base_url + "/" + path, {headers: {"cookie": "auth=" + this.sessionCookie}})).data
108 | };
109 |
110 | async getGameVersion() {
111 | const response = await axios.get(base_url, {
112 | headers: {
113 | "cookie": "auth=" + this.sessionCookie,
114 | }
115 | });
116 | const match = /src="\/js\/game\.js\?v=([0-9]+)"/.exec(response.data);
117 | return match[1];
118 | };
119 |
120 | getUserId() {
121 | if (this.sessionCookie)
122 | return this.sessionCookie.split("-")[0];
123 | throw new Error("Not logged in")
124 | }
125 |
126 | getUserAuth() {
127 | if (this.sessionCookie)
128 | return this.sessionCookie.split("-")[1];
129 | throw new Error("Not logged in")
130 | };
131 | }
132 |
133 | module.exports = HttpWrapper;
134 |
--------------------------------------------------------------------------------
/app/Logger.js:
--------------------------------------------------------------------------------
1 | class Logger {
2 | constructor() {
3 | this.prefixString = "";
4 | this.characterName = "";
5 | this.characterId = "";
6 | this.runScript = "";
7 | this.serverRegion = "";
8 | this.serverIdentifier = "";
9 | }
10 |
11 | setPrefixString(prefixString) {
12 | this.prefixString = prefixString;
13 | }
14 |
15 | set({characterName, characterId, runScript, serverRegion, serverIdentifier}) {
16 | if (characterName != undefined)
17 | this.characterName = characterName;
18 | if (characterId != undefined)
19 | this.characterId = characterId;
20 | if (runScript != undefined)
21 | this.runScript = runScript;
22 | if (serverRegion != undefined)
23 | this.serverRegion = serverRegion;
24 | if (serverIdentifier != undefined)
25 | this.serverIdentifier = serverIdentifier;
26 | }
27 |
28 | log(message, color) {
29 | console.log(this.prefixBuilder() + message);
30 | }
31 |
32 | prefixBuilder() {
33 | const time = new Date();
34 | return this.prefixString.replace(/{{(\w+)}}/g, (fullMatch, group) => {
35 | switch (group) {
36 | case "characterName":
37 | return this.characterName.slice(0, 10).padEnd(10);
38 | case "serverRegion":
39 | return this.serverRegion;
40 | case "serverIdentifier":
41 | return this.serverIdentifier;
42 | case "runScript":
43 | return this.runScript;
44 | case "h":
45 | const h = time.getHours();
46 | return (h < 10) ? '0' + h : h;
47 | case "m":
48 | const m = time.getMinutes();
49 | return (m < 10) ? '0' + m : m;
50 | case "s":
51 | const s = time.getSeconds();
52 | return (s < 10) ? '0' + s : s;
53 | default:
54 | return "";
55 | }
56 | })
57 | }
58 | }
59 |
60 | module.exports = new Logger();
--------------------------------------------------------------------------------
/app/RunnerContext.js:
--------------------------------------------------------------------------------
1 | const Context = require("./Context")
2 | const gameFiles = new (require("./GameFiles"))();
3 | const vm = require("vm");
4 |
5 |
6 | class RunnerContext extends Context {
7 | constructor(version, gameContext) {
8 | super(gameContext);
9 | this.version = version;
10 |
11 |
12 |
13 | }
14 |
15 | async init() {
16 | vm.runInContext("var active=false,catch_errors=true,is_code=1,is_server=0,is_game=0,is_bot=parent.is_bot,is_cli=parent.is_cli;", this.context);
17 |
18 | const sources = gameFiles.runnerFiles
19 | .map(f => gameFiles.locate_game_file(f, this.version));
20 | for (let path of sources) {
21 | await this.evalFile(path);
22 | }
23 | }
24 |
25 | async run(fileName) {
26 | await this.evalFile(fileName)
27 | vm.runInContext("code_run=true;", this.context);
28 | }
29 | }
30 |
31 | module.exports = RunnerContext;
--------------------------------------------------------------------------------
/app/UIGenerator.js:
--------------------------------------------------------------------------------
1 | const pngUtil = require("./pngUtil");
2 | const config = require("../userData").config;
3 | const PNG = require('pngjs').PNG;
4 |
5 | function clamp(x, low, high) {
6 | return Math.min(Math.max(x, low), high);
7 | }
8 |
9 | function bSearch(search, arr) {
10 | let low = 0, high = arr.length - 1;
11 | while (low + 1 !== high) {
12 | let mid = Math.floor((low + high) / 2);
13 | if (arr[mid][0] >= search) {
14 | high = mid;
15 | } else {
16 | low = mid;
17 | }
18 | }
19 | return high;
20 | }
21 |
22 | function get(from, what) {
23 | if (from === undefined || from === null)
24 | return undefined;
25 | let current = from;
26 | do {
27 | try {
28 | let index = what.splice(0, 1)[0];
29 | current = current[index]
30 | } catch (e) {
31 | console.log(e);
32 | }
33 | } while (!(current === undefined) && what.length !== 0);
34 | return current;
35 | }
36 |
37 | class UIGenerator {
38 | constructor(gameContext) {
39 | this.gameContext = gameContext;
40 | this.miniMapHeight = get(config, ["botWebInterface", "minimap", "size", "height"]) || 200;
41 | this.miniMapWidth = get(config, ["botWebInterface", "minimap", "size", "width"]) || 376;
42 | this.enableMiniMap = get(config, ["botWebInterface", "minimap", "enabled"]) || false;
43 | this.enableBotWebInterface = get(config, ["botWebInterface", "enabled"]) || false;
44 | this.updateTiming = get(config, ["botWebInterface", "minimap", "speed"]) || 1000;
45 |
46 | };
47 |
48 |
49 |
50 | generateMiniMap(hitLog, entities) {
51 | //Minimap creation
52 | var png = new PNG({
53 | width: this.miniMapWidth,
54 | height: this.miniMapHeight,
55 | filterType: -1
56 | });
57 | for (let j = 0; j < Math.floor(png.data.length / 4); j++) {
58 | let idx = j << 2;
59 | png.data[idx] = 5;
60 | png.data[idx + 1] = 0;
61 | png.data[idx + 2] = 0;
62 | png.data[idx + 3] = 255;
63 | }
64 | if (this.gameContext.character) {
65 |
66 |
67 | var screenSize = {width: 800, height: 600};
68 | var pos = {
69 | x: this.gameContext.character.real_x - Math.floor(screenSize.width / 2),
70 | y: this.gameContext.character.real_y - Math.floor(screenSize.height / 2)
71 | };
72 | var map = this.gameContext.character.in;
73 |
74 | if (this.gameContext.G.maps[map]) {
75 | let xLines = this.gameContext.G.maps[map].data.x_lines;
76 | let yLines = this.gameContext.G.maps[map].data.y_lines;
77 |
78 | for (let i = bSearch(pos.x, xLines); i < xLines.length && xLines[i][0] < pos.x + screenSize.width; i++) {
79 | let line = xLines[i];
80 | let x = ((line[0] - pos.x) / screenSize.width) * png.width;
81 | let y1 = ((line[1] - pos.y) / screenSize.height) * png.height;
82 | let y2 = ((line[2] - pos.y) / screenSize.height) * png.height;
83 | pngUtil.draw_line(x, y1, x, y2, png, [255, 255, 255, 255]);
84 | }
85 |
86 | for (let i = bSearch(pos.y, yLines); i < yLines.length && yLines[i][0] < pos.y + screenSize.height; i++) {
87 | let line = yLines[i];
88 | let y = ((line[0] - pos.y) / screenSize.height) * png.height;
89 | let x1 = ((line[1] - pos.x) / screenSize.width) * png.width;
90 | let x2 = ((line[2] - pos.x) / screenSize.width) * png.width;
91 | pngUtil.draw_line(x1, y, x2, y, png, [255, 255, 255, 255]);
92 | }
93 | }
94 | // draw hit lines
95 | for (let hit of hitLog) {
96 | let source = entities[hit.hid];
97 | let target = entities[hit.id];
98 | if (hit.hid === this.gameContext.character.id)
99 | source = this.gameContext.character;
100 | if (hit.id === this.gameContext.character.id)
101 | target = this.gameContext.character;
102 |
103 | if (source && target) {
104 | let color = [255, 255, 255, 255];
105 | if (hit.anim === "heal") {
106 | color = [0, 250, 0, 255];
107 | } else
108 | color = [250, 0, 0, 255];
109 | pngUtil.draw_line(
110 | ((source.real_x - pos.x) / screenSize.width) * png.width,
111 | ((source.real_y - pos.y) / screenSize.height) * png.height,
112 | ((target.real_x - pos.x) / screenSize.width) * png.width,
113 | ((target.real_y - pos.y) / screenSize.height) * png.height,
114 | png, [200, 0, 0, 255]);
115 | }
116 | }
117 | //draw entities
118 | if (entities) {
119 | for (let id in entities) {
120 | let entity = entities[id];
121 | let color = [255, 255, 255, 255];
122 | if (entity.type === "monster") {
123 | if (!entity.dead) {
124 | color = [200, 0, 0, 255];
125 | } else {
126 | color = [100, 100, 100, 255];
127 | }
128 | } else {
129 | if (entity.npc) {
130 | color = [224, 221, 38, 255];
131 | } else {
132 | color = [38, 159, 224, 255];
133 | }
134 | }
135 |
136 | pngUtil.draw_dot(
137 | ((entity.real_x - pos.x) / screenSize.width) * png.width,
138 | ((entity.real_y - pos.y) / screenSize.height) * png.height,
139 | 2,
140 | png, color);
141 | if (entity.hp && !(entity.hp <= 0) && !entity.dead) {
142 | let percentage = Math.max(Math.min(Math.floor((entity.hp / entity.max_hp) * 11), 11), 1);
143 | let startX = ((entity.real_x - pos.x) / screenSize.width) * png.width - 5;
144 | pngUtil.draw_line(
145 | ((entity.real_x - pos.x) / screenSize.width) * png.width - 5,
146 | ((entity.real_y - pos.y) / screenSize.height) * png.height - 3,
147 | ((entity.real_x - pos.x) / screenSize.width) * png.width + 5,
148 | ((entity.real_y - pos.y) / screenSize.height) * png.height - 3,
149 | png,
150 | [100, 100, 100, 255]
151 | );
152 | pngUtil.draw_line(
153 | startX,
154 | ((entity.real_y - pos.y) / screenSize.height) * png.height - 3,
155 | startX + percentage,
156 | ((entity.real_y - pos.y) / screenSize.height) * png.height - 3,
157 | png,
158 | [255, 0, 0, 255]
159 | );
160 | }
161 | }
162 | }
163 |
164 | var targetIds = [];
165 | if (this.gameContext.character.target)
166 | targetIds.push(this.gameContext.character.target);
167 | for (let id in entities) {
168 | let entity = entities[id];
169 | if (entity.target === this.gameContext.character.id)
170 | if (!targetIds.includes(entity.id))
171 | targetIds.push(entity.id);
172 | }
173 |
174 | var targets = [];
175 | for (let id of targetIds) {
176 | if (entities[id])
177 | targets.push({
178 | name: entities[id].name,
179 | health: Math.floor(entities[id].hp * 10000 / entities[id].max_hp) / 100,
180 | level: entities[id].level,
181 | })
182 | }
183 |
184 |
185 | //draw this.game_context.character
186 | pngUtil.draw_dot(
187 | ((this.gameContext.character.real_x - pos.x) / screenSize.width) * png.width,
188 | ((this.gameContext.character.real_y - pos.y) / screenSize.height) * png.height,
189 | 2,
190 | png, [0, 200, 0, 255]);
191 |
192 | }
193 | return PNG.sync.write(png);
194 | };
195 |
196 | }
197 |
198 |
199 | module.exports = UIGenerator;
200 |
201 |
--------------------------------------------------------------------------------
/app/_Game.js:
--------------------------------------------------------------------------------
1 | const GameContext = require('./GameContext');
2 | const RunnerContext = require('./RunnerContext');
3 | const bwiUtil = require("./bwiUtil");
4 |
5 | process.on('unhandledRejection', (exception) => {
6 | console.log("promise rejected: \n", exception);
7 | });
8 |
9 |
10 | class Game {
11 | constructor(version, realm_addr, realm_port, session, characterId, script_file) {
12 | this.version = version
13 | this.realm_addr = realm_addr
14 | this.realm_port = realm_port
15 | this.session = session
16 | this.characterId = characterId
17 | this.script_file = script_file
18 |
19 | this.gameContext = new GameContext(this.version);
20 | this.runnerContext = new RunnerContext(this.version, this.gameContext);
21 |
22 | }
23 |
24 | async init() {
25 | try {
26 | await this.gameContext.init(this.realm_addr, this.realm_port, this.session, this.characterId);
27 | } catch (e) {
28 | process.exit();
29 | }
30 | await this.runnerContext.init();
31 | await this.runnerContext.run("./CODE/" + this.script_file)
32 |
33 | bwiUtil.registerListeners(this.gameContext.context);
34 |
35 | process.on("message", (m) => {
36 | switch (m.type) {
37 | case "on_cm":
38 | if (this.runnerContext.context && this.runnerContext.context.character)
39 | this.runnerContext.context.character.trigger("cm", {
40 | name: m.from,
41 | message: m.data,
42 | date: m.date,
43 | local: true
44 | });
45 | break;
46 | }
47 | })
48 |
49 | }
50 | }
51 |
52 | {
53 | let args = process.argv.slice(2);
54 | const version = args[0];
55 | const sess = args[1];
56 | const realm_addr = args[2];
57 | const realm_port = args[3];
58 | const cid = args[4];
59 | const script_file = args[5];
60 | (new Game(version, realm_addr, realm_port, sess, cid, script_file)).init();
61 | }
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/bwiUtil.js:
--------------------------------------------------------------------------------
1 | const UIGenerator = require("./UIGenerator");
2 |
3 | function toPrettyNum(a) {
4 | if (!a) {
5 | return "0"
6 | }
7 | a = Math.round(a);
8 | let sign = false;
9 | if (a < 0) {
10 | a = -1 * a;
11 | sign = true;
12 | }
13 | var b = "";
14 | while (a) {
15 | var c = a % 1000;
16 | if (!c) {
17 | c = "000"
18 | } else {
19 | if (c < 10 && c != a) {
20 | c = "00" + c
21 | } else {
22 | if (c < 100 && c != a) {
23 | c = "0" + c
24 | }
25 | }
26 | }
27 | if (!b) {
28 | b = c
29 | } else {
30 | b = c + "," + b
31 | }
32 | a = (a - a % 1000) / 1000
33 | }
34 | return (sign ? "-" : "") + b
35 | }
36 |
37 |
38 | function registerListeners(gameContext) {
39 | let uiGenerator = new UIGenerator(gameContext)
40 | var damage = 0;
41 | var timeFrame = 60 * 5;
42 | var goldTimeline = [],
43 | xpTimeline = [],
44 | damageTimeline = [];
45 | gameContext.socket.on("hit", function (data) {
46 | if (data.hid && data.damage && gameContext.character) {
47 | if (data.hid == gameContext.character.id) {
48 | damage += data.damage;
49 | }
50 | }
51 | });
52 | var hitLog = [];
53 | gameContext.socket.on("hit", function (data) {
54 | hitLog.push(data);
55 | });
56 | if (uiGenerator.enableMiniMap)
57 | setInterval(function () {
58 | let buffer = uiGenerator.generateMiniMap(hitLog, gameContext.entities);
59 | hitLog = [];
60 | process.send({
61 | type: "bwiPush",
62 | name: "minimap",
63 | data: "data:image/png;base64," + buffer.toString("base64"),
64 | });
65 | }, uiGenerator.updateTiming);
66 | if (uiGenerator.enableBotWebInterface)
67 | setInterval(function () {
68 | if(!gameContext.character)
69 | return;
70 | var targetName = "nothing";
71 | if (gameContext.character.target && gameContext.entities[gameContext.character.target]) {
72 | if (gameContext.entities[gameContext.character.target].player) {
73 | targetName = gameContext.entities[gameContext.character.target].id
74 | } else {
75 | targetName = gameContext.entities[gameContext.character.target].mtype;
76 | }
77 | }
78 | //calculate damage per second
79 | damageTimeline.push(damage);
80 | var thenDamage;
81 | if (damageTimeline.length < timeFrame)
82 | thenDamage = damageTimeline[0];
83 | else
84 | thenDamage = damageTimeline.shift();
85 | var dps = (damage - thenDamage) / damageTimeline.length;
86 | //calculate gold per second
87 | goldTimeline.push(gameContext.character.gold);
88 | var thenGold;
89 | if (goldTimeline.length < timeFrame)
90 | thenGold = goldTimeline[0];
91 | else
92 | thenGold = goldTimeline.shift();
93 | var gps = (gameContext.character.gold - thenGold) / goldTimeline.length;
94 | //calculate xp per second
95 | xpTimeline.push(gameContext.character.xp);
96 | var thenXP;
97 | if (xpTimeline.length < timeFrame)
98 | thenXP = xpTimeline[0];
99 | else
100 | thenXP = xpTimeline.shift();
101 | var xpps = (gameContext.character.xp - thenXP) / xpTimeline.length;
102 | //calculate time until level up
103 | let time = Math.floor((gameContext.character.max_xp - gameContext.character.xp) / xpps);
104 | if (time > 0) {
105 | //prettify time
106 | let tmpTime = time;
107 | var days = Math.floor(tmpTime / (3600 * 24)) || 0;
108 | tmpTime -= 3600 * 24 * days;
109 | var hours = Math.floor(tmpTime / 3600) || 0;
110 | tmpTime -= 3600 * hours;
111 | var minutes = Math.floor(tmpTime / 60) || 0;
112 | tmpTime -= 60 * minutes;
113 | var seconds = tmpTime || 0;
114 | if (hours < 10) {
115 | hours = "0" + hours;
116 | }
117 | if (minutes < 10) {
118 | minutes = "0" + minutes;
119 | }
120 | if (seconds < 10) {
121 | seconds = "0" + seconds;
122 | }
123 | }
124 | process.send({
125 | type: "bwiUpdate",
126 | data: {
127 | name: gameContext.character.id,
128 | level: gameContext.character.level,
129 | inv: [(gameContext.character.isize - gameContext.character.esize) / gameContext.character.isize,
130 | gameContext.character.isize - gameContext.character.esize + " / " + gameContext.character.isize],
131 | xp: Math.floor(gameContext.character.xp * 10000 / gameContext.character.max_xp) / 100,
132 | health: Math.floor(gameContext.character.hp * 10000 / gameContext.character.max_hp) / 100,
133 | mana: Math.floor(gameContext.character.mp * 10000 / gameContext.character.max_mp) / 100,
134 | status: gameContext.character.rip ? "Dead" : "Alive",
135 | gold: toPrettyNum(gameContext.character.gold),
136 | dps: Math.floor(dps),
137 | gph: toPrettyNum(Math.floor(gps) * 3600),
138 | xpph: toPrettyNum(Math.floor(xpps) * 3600),
139 | tlu: (time > 0) ? days + "d " + hours + ":" + minutes + ":" + seconds : "Infinity",
140 | party_leader: gameContext.character.party || "N/A",
141 | realm: gameContext.server_region + gameContext.server_identifier,
142 | }
143 | })
144 |
145 | }, 1000);
146 | }
147 |
148 | exports.registerListeners = registerListeners;
--------------------------------------------------------------------------------
/app/defaultUI.json:
--------------------------------------------------------------------------------
1 | [
2 | {"name": "name", "type": "text", "label": "name"},
3 | {"name": "inv", "type": "labelProgressBar", "label": "Inventory", "options": {"color": "brown"}},
4 | {"name": "level", "type": "text", "label": "Level"},
5 | {"name": "gold", "type": "text", "label": "Gold"},
6 | {"name": "xp", "type": "progressBar", "label": "Experience", "options": {"color": "green"}},
7 | {"name": "health", "type": "progressBar", "label": "Health", "options": {"color": "red"}},
8 | {"name": "mana", "type": "progressBar", "label": "Mana", "options": {"color": "blue"}},
9 | {"name": "targets", "type": "botUI", "label": "Targets"},
10 | {"name": "status", "type": "text", "label": "Status"},
11 | {"name": "dps", "type": "text", "label": "Damage/s"},
12 | {"name": "gph", "type": "text", "label": "Gold/h"},
13 | {"name": "xpph", "type": "text", "label": "XP/h"},
14 | {"name": "tlu", "type": "text", "label": "TLU"},
15 | {"name": "party_leader", "type": "text", "label": "Party Leader"},
16 | {"name": "realm", "type": "text", "label": "Realm"}
17 | ]
--------------------------------------------------------------------------------
/app/html_vars.js:
--------------------------------------------------------------------------------
1 | var inside = "login";
2 | var user_id = "", user_auth = "";
3 | var base_url = "https://adventure.land";
4 | var server_addr = "", server_port = "";
5 | var server_names = {"US": "Americas", "EU": "Europas", "ASIA": "Eastlands"};
6 | var sound_music = '', sound_sfx = '', xmas_tunes = false, music_level = 0.3;
7 | var perfect_pixels = '1';
8 | var screenshot_mode = '';
9 | var pro_mode = '1';
10 | var tutorial_ui = '1';
11 | var new_attacks = '1';
12 | var recording_mode = '';
13 | var cached_map = '1', scale = '2';
14 | var d_lines = '1';
15 | var sd_lines = '1';
16 | var is_sdk = '';
17 | var is_electron = '', electron_data = {};
18 | var is_comm = false;
19 | var no_eval = false;
20 | var VERSION = '';
21 | var platform = 'web';
22 | var engine_mode = '';
23 | var no_graphics = '1';
24 | var border_mode = ''; // use after adding a new monster
25 | var no_html = 'bot';
26 | var is_bot = '1';
27 | var is_cli = '', harakiri = '';
28 | var explicit_slot = '';
29 | var is_mobile = false;
30 | var is_bold = false;
31 | var c_enabled = '1', stripe_enabled = '';
32 | var auto_reload = "auto", reload_times = '0', character_to_load = '', mstand_to_load = null;
33 | // It's pretty complicated but there are 2 persistence, auto login routines, the above one is the first, the below one is the second, second one uses the URL data
34 | var url_ip = '', url_port = '', url_character = '';
35 | var update_notes = [];
36 | var server_regions = {"US": "Americas", "EU": "Europas", "ASIA": "Eastlands"};
37 | var X = {};
38 |
39 | function payment_logic() {
40 | };
41 |
42 |
43 | if (!is_sdk) {
44 | for (var f in log_flags) log_flags[f] = 0;
45 | }
46 |
47 | X.servers = [{
48 | "name": "I",
49 | "region": "EU",
50 | "players": 10,
51 | "key": "EUI",
52 | "port": 2053,
53 | "addr": "eu1.adventure.land"
54 | }, {
55 | "name": "II",
56 | "region": "EU",
57 | "players": 23,
58 | "key": "EUII",
59 | "port": 2083,
60 | "addr": "eu2.adventure.land"
61 | }, {
62 | "name": "PVP",
63 | "region": "EU",
64 | "players": 3,
65 | "key": "EUPVP",
66 | "port": 2087,
67 | "addr": "eupvp.adventure.land"
68 | }, {
69 | "name": "I",
70 | "region": "US",
71 | "players": 18,
72 | "key": "USI",
73 | "port": 2053,
74 | "addr": "us1.adventure.land"
75 | }, {
76 | "name": "II",
77 | "region": "US",
78 | "players": 10,
79 | "key": "USII",
80 | "port": 2083,
81 | "addr": "us2.adventure.land"
82 | }, {
83 | "name": "III",
84 | "region": "US",
85 | "players": 51,
86 | "key": "USIII",
87 | "port": 2053,
88 | "addr": "us3.adventure.land"
89 | }, {
90 | "name": "PVP",
91 | "region": "US",
92 | "players": 14,
93 | "key": "USPVP",
94 | "port": 2087,
95 | "addr": "uspvp.adventure.land"
96 | }, {"name": "I", "region": "ASIA", "players": 12, "key": "ASIAI", "port": 2053, "addr": "asia1.adventure.land"}];
97 | X.characters = [];
98 | X.tutorial = {"step": 0, "completed": []};
99 | X.unread = 0;
100 | X.codes = {}
101 |
102 | code_logic();
--------------------------------------------------------------------------------
/app/patches/0001-remove-log-spam.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * @param files
4 | */
5 | function run(files) {
6 | let haystack = files["/js/common_functions.js"].split("console.error(\"Weird resolve_deferred issue: \"+name),console.log(\"If you emit socket events manually, ignore this message\");")
7 | if (haystack.length === 2) {
8 | files["/js/common_functions.js"] = haystack.join(";")
9 | } else {
10 | throw new Error("Unable to find correct needle, aborting ...")
11 | }
12 |
13 | haystack = files["/js/common_functions.js"].split("console.error(\"Weird reject_deferred issue: \"+name),console.log(\"If you emit socket events manually, ignore this message\");")
14 | if (haystack.length === 2) {
15 | files["/js/common_functions.js"] = haystack.join(";")
16 | } else {
17 | throw new Error("Unable to find correct needle, aborting ...")
18 | }
19 |
20 | }
21 |
22 |
23 | module.exports = {run}
--------------------------------------------------------------------------------
/app/patches/0002-add-localStorage.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * @param files
4 | */
5 | function run(files) {
6 | files["/js/runner_functions.js"] =
7 | "{\n" +
8 | " const LocalStorage = require(\"node-localstorage-sync\").LocalStorage;\n" +
9 | " const localStorage = new LocalStorage('./app/localStorage');\n" +
10 | " setInterval(localStorage.sync.bind(localStorage), 1000);\n" +
11 | " Object.defineProperty(window, \"localStorage\", {\n" +
12 | " get: () => {\n" +
13 | " return localStorage;\n" +
14 | " }\n" +
15 | " })\n" +
16 | "}\n" + files["/js/runner_functions.js"]
17 |
18 | }
19 |
20 |
21 | module.exports = {run}
--------------------------------------------------------------------------------
/app/patches/0003-add-sessionStorage.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * @param files
4 | */
5 | function run(files) {
6 | files["/js/runner_functions.js"] =
7 | "{\n" +
8 | " const LocalStorage = require(\"node-localstorage-sync\").LocalStorage;\n" +
9 | " const sessionStorage = new LocalStorage('./app/sessionStorage');\n" +
10 | " setInterval(sessionStorage.sync.bind(sessionStorage), 1000);\n" +
11 | " Object.defineProperty(window, \"sessionStorage\", {\n" +
12 | " get: () => {\n" +
13 | " return sessionStorage;\n" +
14 | " }\n" +
15 | " })\n" +
16 | "}\n" + files["/js/runner_functions.js"]
17 |
18 | }
19 |
20 |
21 | module.exports = {run}
--------------------------------------------------------------------------------
/app/patches/0004-add-null-check-localstorage-cm.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * @param files
4 | */
5 | function run(files) {
6 | const safeCopy = files["/js/runner_functions.js"];
7 | let success = true;
8 |
9 | let tmp = files["/js/runner_functions.js"];
10 |
11 | tmp = tmp.split("data[2]=new Date(data[2]);\n\t\t\t\tmessages.push(data);")
12 | if (tmp.length === 2) {
13 | tmp = tmp.join("if(data){\n\t\t\t\t\tdata[2]=new Date(data[2]);\n\t\t\t\t\tmessages.push(data);\t\t\t\n}")
14 | } else success = false;
15 |
16 | tmp = tmp.split("var keys=Object.keys(localStorage);")
17 | if (tmp.length === 2) {
18 | tmp = tmp.join("var keys=localStorage._keys")
19 | } else success = false;
20 |
21 | if (!success) {
22 | console.error("Unable to find correct needle, aborting ...");
23 | files["/js/runner_functions.js"] = safeCopy;
24 | } else{
25 | files["/js/runner_functions.js"] = tmp;
26 | }
27 | }
28 |
29 |
30 | module.exports = {run}
--------------------------------------------------------------------------------
/app/patches/0005-add-ipc-based-send-cm.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | function run(files) {
5 | let asd = files["/js/runner_functions.js"].split("localStorage.setItem(\"cm_\"+name+\"_\"+randomStr(20),JSON.stringify([character.name,data,new Date(),++local_m_num]));")
6 | if (asd.length === 2) {
7 | files["/js/runner_functions.js"] = asd.join("parent.albot.send_cm(name, [character.name,data,new Date(),++local_m_num])")
8 | } else {
9 | console.error("Unable to find correct needle, aborting ...")
10 | }
11 | }
12 |
13 |
14 | module.exports = {run}
--------------------------------------------------------------------------------
/app/patches/0006-fix-load_code.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | function run(files) {
5 | let asd = files["/js/runner_functions.js"].split("\tvar library=document.createElement(\"script\");\n" +
6 | "\tlibrary.type=\"text/javascript\";\n" +
7 | "\tlibrary.text=code;\n" +
8 | "\tlibrary.onerror=onerror||function(){ game_log(\"load_code: Failed to load\",colors.code_error); };\n" +
9 | "\tdocument.getElementsByTagName(\"head\")[0].appendChild(library);")
10 | if (asd.length === 2) {
11 | files["/js/runner_functions.js"] = asd.join("parent.run_code(code, onerror)")
12 | } else {
13 | console.error("Unable to find correct needle, aborting ...")
14 | }
15 | }
16 |
17 |
18 | module.exports = {run}
--------------------------------------------------------------------------------
/app/pngUtil.js:
--------------------------------------------------------------------------------
1 | function draw_line(x1, y1, x2, y2, png, color) {
2 | x1 = Math.floor(x1);
3 | y1 = Math.floor(y1);
4 | x2 = Math.floor(x2);
5 | y2 = Math.floor(y2);
6 |
7 | var xs = x1,
8 | xl = x2,
9 | ys = y1,
10 | yl = y2;
11 |
12 | if (x1 > x2) {
13 | xl = x1;
14 | xs = x2;
15 | yl = y1;
16 | ys = y2;
17 | }
18 |
19 | if (!color) color = [0, 0, 0, 255];
20 | const xvec = xl - xs;
21 | const yvec = yl - ys;
22 |
23 | if (xvec > yvec) {
24 | const slope = yvec / xvec;
25 | for (let x = xs, i = 0; x < xl; i++, x++) {
26 | let y = ys + Math.round(slope * i);
27 | //out of bounds check
28 | if (x > png.width - 1 || x < 0 || y > png.height - 1 || y < 0) continue;
29 | let idx = (png.width * y + x) << 2;
30 | png.data[idx] = color[0];
31 | png.data[idx + 1] = color[1];
32 | png.data[idx + 2] = color[2];
33 | png.data[idx + 3] = color[3];
34 | }
35 | } else {
36 | const slope = xvec / yvec;
37 | for (let y = ys, i = 0; y < yl; i++, y++) {
38 | let x = xs + Math.round(slope * i);
39 | if (x > png.width - 1 || x < 0 || y > png.height - 1 || y < 0) continue;
40 | let idx = (png.width * y + x) << 2;
41 | png.data[idx] = color[0];
42 | png.data[idx + 1] = color[1];
43 | png.data[idx + 2] = color[2];
44 | png.data[idx + 3] = color[3];
45 | }
46 | }
47 | }
48 |
49 | function draw_dot(x, y, size, png, color) {
50 | x = Math.floor(x);
51 | y = Math.floor(y);
52 |
53 | for (let i = -size + 1; i < size; i++)
54 | for (let j = -size + 1; j < size; j++) {
55 | if (x + j > png.width - 1 || x + j < 0 || y + i > png.height - 1 || y + i < 0)
56 | continue;
57 | let idx = (png.width * (y + j) + x + i) << 2;
58 | png.data[idx] = color[0];
59 | png.data[idx + 1] = color[1];
60 | png.data[idx + 2] = color[2];
61 | png.data[idx + 3] = color[3];
62 | }
63 | }
64 |
65 | module.exports = {
66 | draw_line: draw_line,
67 | draw_dot: draw_dot,
68 | }
--------------------------------------------------------------------------------
/data/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | const config = require("./Config");
2 | const GameController = require("./GameController")
3 | const HttpWrapper = require("./app/HttpWrapper")
4 | const ServerList = require("./ServerList")
5 | const GameDataManager = require("./GameDataManager")
6 | const BotWebInterface = require("bot-web-interface");
7 | const uiGenerator = require("./app/UIGenerator");
8 | const Pathfinding = require("./pathfinding/Pathfinding");
9 | const fs = require("fs");
10 | const path = require("path");
11 |
12 |
13 | process.on('uncaughtException', function (exception) {
14 | console.log("Uncaught Exception");
15 | console.log(exception);
16 | console.log(exception.stack);
17 | process.exit(-1);
18 | });
19 |
20 | process.on('unhandledRejection', function (exception) {
21 | console.log("Unhandled Rejection");
22 | console.log(exception);
23 | console.log(exception.stack);
24 | process.exit(-1);
25 | });
26 |
27 |
28 | class ALBot {
29 | constructor() {
30 | this.httpWrapper = new HttpWrapper();
31 | this.serverList = new ServerList(this.httpWrapper);
32 | this.gameDataManager = new GameDataManager(this.httpWrapper);
33 | this.botWebInterface = null;
34 | this.gameController = null;
35 | this.currentGameVersion = null;
36 | }
37 |
38 | async start() {
39 | config.validate();
40 | if (config.config.config.botWebInterface && config.config.config.botWebInterface.enabled) {
41 | this.botWebInterface = new BotWebInterface({
42 | port: config.config.config.botWebInterface.port,
43 | password: (config.config.config.botWebInterface.password ? config.config.config.botWebInterface.password : null)
44 | });
45 | let defaultStructure = require("./app/defaultUI.json")
46 | if (config.config.config.botWebInterface.minimap.enabled) {
47 | defaultStructure.push({
48 | name: "minimap", type: "image", label: "Minimap", options:
49 | {
50 | width: config.config.config.botWebInterface.minimap.size.width,
51 | height: config.config.config.botWebInterface.minimap.size.height
52 | }
53 | })
54 | }
55 | this.botWebInterface.publisher.setDefaultStructure(defaultStructure);
56 | }
57 | this.gameController = new GameController(this.httpWrapper, this.serverList, this.gameDataManager, this.botWebInterface);
58 |
59 | let session = config.getSession();
60 | if (session && session !== "") {
61 | this.httpWrapper.setSession(session);
62 | }
63 | console.log("checking Login")
64 | if (!await this.httpWrapper.checkLogin()) {
65 | let login = config.getLogin();
66 | try {
67 | await this.httpWrapper.login(login.email, login.password);
68 | const session = this.httpWrapper.sessionCookie;
69 | config.setSession(session);
70 | } catch (e) {
71 | console.error("Unable to log in, aborting ...")
72 | process.exit(1);
73 | }
74 | }
75 | console.log("Logged in")
76 | if (config.isFetch()) {
77 | console.log("Populating config file with data.");
78 | const characters = (await this.httpWrapper.getServersAndCharacters()).characters;
79 | let bots = [];
80 | for (let char of characters) {
81 | bots.push({
82 | characterName: char.name,
83 | characterId: char.id,
84 | runScript: "default.js",
85 | server: "US I",
86 | enabled: false,
87 | })
88 | }
89 | config.setBots(bots)
90 | config.toggleFetch();
91 | process.exit();
92 | }
93 |
94 | if (config.isPathfinding()) {
95 | let pathFinding = new Pathfinding();
96 | await pathFinding.start();
97 | }
98 |
99 | // clear session Storage
100 | try {
101 | let files = [];
102 | do {
103 | files = fs.readdirSync("app/sessionStorage");
104 | for (let file of files) {
105 | fs.unlinkSync(path.join(__dirname, "app/sessionStorage", file))
106 | }
107 | } while (files.length !== 0)
108 | } catch (e) {
109 | }
110 | console.log("Starting characters");
111 | let bots = config.getBots();
112 |
113 | let promises = [];
114 | for (let bot of bots) {
115 | promises.push(this.gameController.startCharacter(bot.characterId, bot.server, bot.runScript, bot.characterName, this.currentGameVersion))
116 | }
117 | await Promise.all(promises);
118 | }
119 |
120 | async houseKeeping() {
121 | if (!await this.gameDataManager.isUpToDate()) {
122 | let gameVersion = await this.gameDataManager.updateGameData();
123 | await this.findRunningVersion();
124 | this.currentGameVersion = gameVersion;
125 | } else {
126 | this.currentGameVersion = await this.gameDataManager.currentVersion();
127 | }
128 | }
129 |
130 | async findRunningVersion(gameVersion) {
131 | if (typeof gameVersion === "undefined")
132 | gameVersion = Number.MAX_SAFE_INTEGER;
133 | let gameVersions = this.gameDataManager.getAvailableVersions().filter((elem) => elem < gameVersion);
134 | if (gameVersions.length == 0) {
135 | console.error("No runnable version detected, stopping")
136 | process.exit(0)
137 | } else {
138 | gameVersion = gameVersions[0]
139 | }
140 | try {
141 | await this.gameDataManager.applyPatches(gameVersion);
142 | } catch (e) {
143 | if (e.code === "PATCH_FAIL") {
144 | console.error(e.message)
145 | await this.findRunningVersion(gameVersion);
146 | } else {
147 | throw e;
148 | }
149 | return;
150 | }
151 | this.currentGameVersion = gameVersion;
152 | }
153 | }
154 |
155 | async function main() {
156 | const albot = new ALBot();
157 | await albot.houseKeeping();
158 | await albot.start();
159 | setInterval(() => {
160 | albot.houseKeeping();
161 | }, 1000 * 60)
162 | }
163 |
164 | main();
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "adventurelandbot",
3 | "version": "2.7.4",
4 | "description": "",
5 | "main": "main.js",
6 | "scripts": {
7 | "start": "node main.js",
8 | "update": "git checkout . && git pull && npm install",
9 | "pathfinding": "node /app/path"
10 | },
11 | "author": "Patric Wellershaus",
12 | "license": "GNU GPLv3.0",
13 | "dependencies": {
14 | "axios": "^0.21.2",
15 | "bot-web-interface": "^2.0.9",
16 | "extend": "3.0.2",
17 | "form-data": "^2.3.3",
18 | "jquery": "^3.6.0",
19 | "jsdom": "^16.5.3",
20 | "lodash": "^4.17.21",
21 | "node-fetch": "^2.6.7",
22 | "node-localstorage-sync": "2.2.4",
23 | "pngjs": "^6.0.0",
24 | "promise": "8.0.3",
25 | "socket.io": "^4.2.0",
26 | "socket.io-client": "^4.2.0",
27 | "sync-request": "6.1.0"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/pathfinding/Floor.js:
--------------------------------------------------------------------------------
1 | function bSearch(search, arr) {
2 | let low = 0, high = arr.length - 1;
3 | while (low + 1 !== high) {
4 | let mid = Math.floor((low + high) / 2);
5 | if (arr[mid][0] >= search) {
6 | high = mid;
7 | } else {
8 | low = mid;
9 | }
10 | }
11 | return high;
12 | }
13 |
14 | class Floor {
15 | constructor(name, mapData, keenness) {
16 | this.name = name
17 | this.mapData = mapData;
18 | this.size = {
19 | x: Math.ceil((this.mapData.geometry.max_x - this.mapData.geometry.min_x + 1) / keenness),
20 | y: Math.ceil((this.mapData.geometry.max_y - this.mapData.geometry.min_y + 1) / keenness)
21 | };
22 | this.matrices = {
23 | base: new Uint16Array(this.size.x * this.size.y).fill(0xffff),
24 | }
25 | this.offset = {
26 | x: this.mapData.geometry.min_x,
27 | y: this.mapData.geometry.min_y,
28 | }
29 | this.x_lines = [];
30 | this.y_lines = [];
31 |
32 | this.doors = [];
33 |
34 | }
35 |
36 | setBox(x1, y1, x2, y2, size, obj, value) {
37 | const lowX = Math.max(x1, 0);
38 | const lowY = Math.max(y1, 0);
39 | const highX = Math.min(x2, size.x - 1);
40 | const highY = Math.min(y2, size.y - 1);
41 | for (let x = lowX; x <= highX; x++)
42 | for (let y = lowY; y <= highY; y++)
43 | obj[this.size.x * y + x] = value;
44 | }
45 |
46 | fill(x, y, value) {
47 | const width = this.size.x;
48 | const open = new Uint32Array(0x4000);
49 | open[0] = (x + y * width) | 0xf0000000;
50 | let first = 0,
51 | last = 0;
52 | while (first !== last + 1) {
53 | const pos = open[first] & 0x0fffffff;
54 | const dir = open[first] & 0xf0000000;
55 |
56 | if (this.matrices.base[pos] === 0xffff) {
57 | this.matrices.base[pos] = value;
58 | if (dir & 0x80000000 && (pos + 1) % width !== 0) open[(last = (last + 1) % open.length)] = (pos + 1) | 0xb0000000; // going right set direction all but left
59 | if (dir & 0x40000000 && (pos - 1) % width !== width - 1) open[(last = (last + 1) % open.length)] = (pos - 1) | 0x70000000; // going left set direction all but right
60 | if (dir & 0x20000000) open[(last = (last + 1) % open.length)] = (pos + width) | 0xe0000000; // going down set direction all but up
61 | if (dir & 0x10000000) open[(last = (last + 1) % open.length)] = (pos - width) | 0xd0000000; // going up set direction all but down
62 | }
63 | first = (first + 1) % open.length;
64 | }
65 | }
66 |
67 | detectBoxSize(x, y) {
68 | if (this.matrices.base[x + y * this.size.x] !== 0xfffd) {
69 | return null;
70 | }
71 |
72 | let boxSize = {
73 | x: 0,
74 | y: 0
75 | };
76 | let canExpand = {
77 | x: true,
78 | y: true,
79 | };
80 | while (canExpand.x || canExpand.y) {
81 | if (x + boxSize.x >= this.size.x) {
82 | canExpand.x = false;
83 | canExpand.y = false;
84 | }
85 | if (y + boxSize.y >= this.size.y) {
86 | canExpand.y = false;
87 | canExpand.x = false;
88 | }
89 | if (canExpand.x) {
90 | for (let i = 0; i < boxSize.y; i++) {
91 | let lx = x + boxSize.x;
92 | let ly = (y + i);
93 | //console.log("x", lx, ly, boxSize)
94 | if (this.matrices.base[lx + ly * this.size.x] !== 0xfffd) {
95 | canExpand.x = false;
96 | canExpand.y = false;
97 |
98 | break;
99 | }
100 | }
101 | if (canExpand.x) {
102 | boxSize.x++;
103 | }
104 | }
105 | if (canExpand.y) {
106 | for (let i = 0; i < boxSize.x; i++) {
107 | let lx = x + i;
108 | let ly = (y + boxSize.y);
109 | //console.log("y", lx, ly, boxSize)
110 | if (this.matrices.base[lx + ly * this.size.x] !== 0xfffd) {
111 | canExpand.y = false;
112 | canExpand.x = false;
113 | break;
114 | }
115 | }
116 | if (canExpand.y) {
117 | boxSize.y++;
118 | }
119 | }
120 | }
121 | return boxSize
122 | }
123 |
124 | canMoveTo(x1, y1, x2, y2) {
125 | const x = Math.min(x1, x2);
126 | const y = Math.min(y1, y2);
127 | const X = Math.max(x1, x2);
128 | const Y = Math.max(y1, y2);
129 |
130 | for (let i = bSearch(x, this.x_lines); i < this.x_lines.length; i++) {
131 | const line = this.x_lines[i];
132 | if (line[0] > X)
133 | break;
134 | const y_com = ((y2 - y1) / (x2 - x1)) * (line[0] - x1);
135 | if (y_com + y1 < line[2] && y_com + y1 > line[1])
136 | return false;
137 | }
138 |
139 | for (let i = bSearch(y, this.y_lines); i < this.y_lines.length; i++) {
140 | const line = this.y_lines[i];
141 | if (line[0] > Y)
142 | break;
143 | const x_com = ((x2 - x1) / (y2 - y1)) * (line[0] - y1);
144 | if (x_com + x1 < line[2] && x_com + x1 > line[1])
145 | return false;
146 | }
147 |
148 | return true;
149 | };
150 | }
151 |
152 | module.exports = Floor;
--------------------------------------------------------------------------------
/pathfinding/MapProcessor.js:
--------------------------------------------------------------------------------
1 | const Floor = require("./Floor")
2 | const character = {
3 | h: 8, // left and right
4 | v: 7, // up
5 | vn: 2, // down
6 | };
7 | const World = require("./World");
8 |
9 | class MapProcessor {
10 | constructor(gameData, keenness = 1, padding = 1) {
11 | this.keenness = keenness;
12 | this.padding = padding;
13 | this.gameData = gameData;
14 | }
15 |
16 | setCollisionBoxes(world) {
17 | for (let [name, floor] of world.floors) {
18 | const x_lines = floor.mapData.geometry.x_lines
19 | const y_lines = floor.mapData.geometry.y_lines
20 | for (let pos in x_lines) {
21 | let x = x_lines[pos][0] - floor.offset.x;
22 | let yTop = x_lines[pos][1] - floor.offset.y;
23 | let yBot = x_lines[pos][2] - floor.offset.y;
24 | let x1 = Math.floor((x - character.h - this.padding) / this.padding);
25 | let y1 = Math.floor((yTop - character.vn - this.padding) / this.padding);
26 | let x2 = Math.ceil((x + character.h + this.padding) / this.padding);
27 | let y2 = Math.ceil((yBot + character.v + this.padding) / this.padding);
28 | floor.setBox(x1, y1, x2, y2, floor.size, floor.matrices.base, 0xfffe);
29 | }
30 |
31 | for (let pos in y_lines) {
32 | let y = y_lines[pos][0] - floor.offset.y;
33 | let xLeft = y_lines[pos][1] - floor.offset.x;
34 | let xRight = y_lines[pos][2] - floor.offset.x;
35 | let x1 = Math.floor((xLeft - character.h - this.padding) / this.padding);
36 | let y1 = Math.floor((y - character.vn - this.padding) / this.padding);
37 | let x2 = Math.ceil((xRight + character.h + this.padding) / this.padding);
38 | let y2 = Math.ceil((y + character.v + this.padding) / this.padding);
39 | floor.setBox(x1, y1, x2, y2, floor.size, floor.matrices.base, 0xfffe);
40 | }
41 | }
42 | console.log("Set collision boxes")
43 | }
44 |
45 | createBoxNeighborMap(world) {
46 | for (let [name, floor] of world.floors) {
47 | for (let i = 0; i < floor.boxes.length; i++) {
48 | let box = world.boxes[floor.boxes[i]];
49 | //TOP
50 | for (let j = 0; j < box.size.x; j++) {
51 | if (box.x + j > floor.size.x - 1 || (box.y - 1) < 0)
52 | break;
53 | let otherBoxId = floor.matrices.base[box.x + j + (box.y - 1) * floor.size.x];
54 | if (otherBoxId < 0xfffd) {
55 | let otherBox = world.boxes[otherBoxId];
56 |
57 | let left = Math.max(box.x, otherBox.x);
58 | let right = Math.min(box.x + box.size.x, otherBox.x + otherBox.size.x);
59 | let dist = Math.sqrt(Math.pow(box.x - otherBox.x, 2) + Math.pow(box.y - otherBox.y, 2));
60 | box.neighbors.push(otherBoxId, dist);
61 | otherBox.neighbors.push(floor.boxes[i], dist);
62 | j += right - left - 1;
63 | }
64 | }
65 | //Right
66 | for (let j = 0; j < box.size.y; j++) {
67 | if (box.x + box.size.x > floor.size.x - 1 || (box.y + j) > floor.size.y - 1)
68 | break;
69 | let otherBoxId = floor.matrices.base[box.x + box.size.x + (box.y + j) * floor.size.x];
70 | if (otherBoxId < 0xfffd) {
71 | let otherBox = world.boxes[otherBoxId];
72 |
73 | let top = Math.max(box.y, otherBox.y);
74 | let bottom = Math.min(box.y + box.size.y, otherBox.y + otherBox.size.y);
75 | let dist = Math.sqrt(Math.pow(box.x - otherBox.x, 2) + Math.pow(box.y - otherBox.y, 2));
76 | box.neighbors.push(otherBoxId, dist);
77 | otherBox.neighbors.push(floor.boxes[i], dist);
78 |
79 | j += bottom - top - 1;
80 | }
81 | }
82 | }
83 | }
84 | console.log("created box neighbour map")
85 | };
86 |
87 | createBoxMap(world) {
88 | let boxCount = 0;
89 | for (let [name, floor] of world.floors) {
90 | let boxes = [];
91 | let base = floor.matrices.base;
92 | for (let i = 0; i < floor.matrices.base.length; i++) {
93 | if (base[i] === 0xfffd) {
94 | const x = (i % floor.size.x);
95 | const y = Math.floor(i / floor.size.x);
96 | let boxSize;
97 | if ((boxSize = floor.detectBoxSize(x, y, base)) !== null) {
98 | for (let j = 0; j < boxSize.x; j++) {
99 | for (let k = 0; k < boxSize.y; k++) {
100 | base[x + j + (y + k) * floor.size.x] = boxCount;
101 | }
102 | }
103 | boxes.push(boxCount);
104 | world.boxes[boxCount] = {
105 | x: x,
106 | y: y,
107 | size: boxSize,
108 | neighbors: [],
109 | doors: [],
110 | };
111 | boxCount++;
112 | }
113 | }
114 | }
115 | floor.boxes = boxes;
116 | }
117 | console.log("created box map")
118 | };
119 |
120 | resetXYLines(world) {
121 | for (let [name, floor] of world.floors) {
122 | let xLineStart = null, yLineStart = null;
123 | const base = floor.matrices.base;
124 | for (let i = 0; i < base.length - 1; i++) {
125 | if (
126 | base[i] === 0xfffe &&
127 | base[i + floor.size.x] === 0xfffd
128 | ||
129 | base[i] === 0xfffd &&
130 | base[i + floor.size.x] === 0xfffe
131 | ) {
132 | if (yLineStart == null) {
133 | yLineStart = i;
134 | }
135 | } else {
136 | //create line
137 | if (yLineStart !== null) {
138 | let line = [Math.floor(i / floor.size.x), yLineStart % floor.size.x, i % floor.size.x];
139 | line[0] = line[0] * this.keenness + floor.offset.y;
140 | line[1] = line[1] * this.keenness + floor.offset.x - 1;
141 | line[2] = line[2] * this.keenness + floor.offset.x;
142 | floor.y_lines.push(line);
143 | yLineStart = null;
144 | }
145 | }
146 | let j = (i % floor.size.y) * floor.size.x + Math.floor(i / floor.size.y);
147 | if (
148 | base[j] === 0xfffe &&
149 | base[j + 1] === 0xfffd
150 | ||
151 | base[j] === 0xfffd &&
152 | base[j + 1] === 0xfffe
153 | ) {
154 | if (xLineStart == null) {
155 | xLineStart = j;
156 | }
157 | } else {
158 | //create line
159 | if (xLineStart !== null) {
160 | let line = [(j % floor.size.x), Math.floor(xLineStart / floor.size.x), Math.floor(j / floor.size.x)];
161 | line[0] = line[0] * this.keenness + floor.offset.x;
162 | line[1] = line[1] * this.keenness + floor.offset.y - 1;
163 | line[2] = line[2] * this.keenness + floor.offset.y;
164 | floor.x_lines.push(line);
165 | xLineStart = null;
166 | }
167 | }
168 | }
169 | }
170 | console.log("optimized xy Lines");
171 | }
172 |
173 | discoverWalkableArea(world) {
174 | for (let [name, floor] of world.floors) {
175 | for (let k in floor.mapData.spawns) {
176 | floor.fill(
177 | Math.floor((floor.mapData.spawns[k][0] - floor.offset.x)),
178 | Math.floor((floor.mapData.spawns[k][1] - floor.offset.y)),
179 | 0xfffd
180 | );
181 | }
182 | }
183 | console.log("Discover walkable area")
184 | }
185 |
186 | createFloors(world) {
187 | for (let name in this.gameData.maps) {
188 | let map = this.gameData.maps[name];
189 | map.geometry = this.gameData.geometry[name];
190 | if (!map.ignore) {
191 | world.floors.set(name, new Floor(name, map, this.keenness));
192 | }
193 | }
194 | console.log("Create floors");
195 | }
196 |
197 | detectingDoors(world) {
198 | let doorCount = 0;
199 | for (let [name, floor] of world.floors) {
200 | for (let doorData of floor.mapData.doors) {
201 | let doorId = doorCount++;
202 | const entryFloor = floor;
203 | const exitFloor = world.floors.get(doorData[4]);
204 | const entry = floor.mapData.spawns[doorData[6]];
205 | const entryX = Math.floor(entry[0] - floor.offset.x);
206 | const entryY = Math.floor(entry[1] - floor.offset.y);
207 | const exit = exitFloor.mapData.spawns[doorData[5]];
208 | const exitX = Math.floor(exit[0] - exitFloor.offset.x);
209 | const exitY = Math.floor(exit[1] - exitFloor.offset.y);
210 | if (!exitFloor)
211 | continue;
212 |
213 | let entryBoxId = floor.matrices.base[entryX + entryY * floor.size.x];
214 | let exitBoxId = exitFloor.matrices.base[exitX + exitY * exitFloor.size.x];
215 | if (world.boxes[entryBoxId] && world.boxes[exitBoxId]) {
216 | const door = {
217 | entryId: entryBoxId,
218 | exitId: exitBoxId,
219 | entry: {
220 | x: entry[0] - entryFloor.offset.x,
221 | y: entry[1] - entryFloor.offset.y
222 | },
223 | exit: {
224 | x: exit[0] - exitFloor.offset.x,
225 | y: exit[1] - exitFloor.offset.y,
226 | floor: exitFloor,
227 | s: doorData[5]
228 | }
229 | }
230 |
231 | world.boxes[entryBoxId].doors.push(doorId);
232 | world.doors[doorId] = door;
233 | } else {
234 | console.log(floor.name)
235 | console.log(" ", entry[0], entry[1])
236 | }
237 |
238 | }
239 | }
240 | console.log("add doors");
241 | }
242 |
243 | createWorld() {
244 | const world = new World();
245 | this.createFloors(world);
246 | this.setCollisionBoxes(world);
247 | this.discoverWalkableArea(world);
248 | this.resetXYLines(world);
249 | this.createBoxMap(world);
250 | this.createBoxNeighborMap(world)
251 | this.detectingDoors(world);
252 | return world;
253 | }
254 | }
255 |
256 | module.exports = MapProcessor;
--------------------------------------------------------------------------------
/pathfinding/PathUtils.js:
--------------------------------------------------------------------------------
1 | pathUtils = {
2 |
3 |
4 |
5 |
6 | }
7 |
8 | module.exports = pathUtils;
--------------------------------------------------------------------------------
/pathfinding/Pathfinding.js:
--------------------------------------------------------------------------------
1 | const EventSystem = require("../EventSystem");
2 | const child_process = require("child_process");
3 |
4 | class Pathfinding extends EventSystem {
5 | constructor() {
6 | super();
7 | this.process = null;
8 |
9 | }
10 |
11 | async start() {
12 | return new Promise((resolve) => {
13 | const args = [this.session, this.ip, this.port, this.characterId, this.runScript];
14 | this.process = child_process.fork("./pathfinding/_Pathfinding", args, {
15 | stdio: [0, 1, 2, 'ipc'],
16 | execArgv: [
17 | //'--inspect-brk',
18 | "--max_old_space_size=8096",
19 | ]
20 | });
21 |
22 | this.process.on("exit", (code) => {
23 | this.emit("stop");
24 | })
25 |
26 | this.process.on("message", (m) => {
27 | switch (m) {
28 | case "ready": {
29 | console.log("pathfinding ready");
30 | resolve();
31 | }
32 | }
33 | });
34 | })
35 | }
36 |
37 | async stop() {
38 | if (this.process)
39 | this.process.exit(1);
40 | }
41 |
42 | async restart() {
43 | await stop();
44 | await start();
45 | }
46 | }
47 |
48 | module.exports = Pathfinding;
--------------------------------------------------------------------------------
/pathfinding/PriorityQueue.js:
--------------------------------------------------------------------------------
1 | const top = 0;
2 | const parent = i => ((i + 1) >>> 1) - 1;
3 | const left = i => (i << 1) + 1;
4 | const right = i => (i + 1) << 1;
5 |
6 | class PriorityQueue {
7 | constructor(comparator = (a, b) => a > b) {
8 | this._heap = [];
9 | this._comparator = comparator;
10 | }
11 | size() {
12 | return this._heap.length;
13 | }
14 | isEmpty() {
15 | return this.size() === 0;
16 | }
17 | peek() {
18 | return this._heap[top];
19 | }
20 | push(...values) {
21 | values.forEach(value => {
22 | this._heap.push(value);
23 | this._siftUp();
24 | });
25 | return this.size();
26 | }
27 | pop() {
28 | const poppedValue = this.peek();
29 | const bottom = this.size() - 1;
30 | if (bottom > top) {
31 | this._swap(top, bottom);
32 | }
33 | this._heap.pop();
34 | this._siftDown();
35 | return poppedValue;
36 | }
37 | replace(value) {
38 | const replacedValue = this.peek();
39 | this._heap[top] = value;
40 | this._siftDown();
41 | return replacedValue;
42 | }
43 | _greater(i, j) {
44 | return this._comparator(this._heap[i], this._heap[j]);
45 | }
46 | _swap(i, j) {
47 | [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
48 | }
49 | _siftUp() {
50 | let node = this.size() - 1;
51 | while (node > top && this._greater(node, parent(node))) {
52 | this._swap(node, parent(node));
53 | node = parent(node);
54 | }
55 | }
56 | _siftDown() {
57 | let node = top;
58 | while (
59 | (left(node) < this.size() && this._greater(left(node), node)) ||
60 | (right(node) < this.size() && this._greater(right(node), node))
61 | ) {
62 | let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);
63 | this._swap(node, maxChild);
64 | node = maxChild;
65 | }
66 | }
67 | }
68 | module.exports = PriorityQueue;
--------------------------------------------------------------------------------
/pathfinding/World.js:
--------------------------------------------------------------------------------
1 | class World {
2 | constructor() {
3 | this.floors = new Map();
4 | this.boxes = [];
5 | this.doors = [];
6 |
7 | }
8 | }
9 |
10 | module.exports = World;
--------------------------------------------------------------------------------
/pathfinding/_Pathfinding.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const HttpWrapper = require("../app/HttpWrapper");
3 | const MapProcessor = require("./MapProcessor")
4 | const PriorityQueue = require("./PriorityQueue")
5 | const io = require("socket.io").Server;
6 | const server = new io({
7 | cors: {
8 | origin: ["http://adventure.land"],
9 | }
10 | });
11 |
12 |
13 | const vm = require("vm");
14 |
15 | class _Pathfinding {
16 | constructor() {
17 | this.httpWrapper = new HttpWrapper();
18 | this.gameData = null;
19 | this.world = null;
20 | }
21 |
22 | async loadCache() {
23 | throw new Error("Unable to load");
24 | }
25 |
26 | async loadData() {
27 | let gameVersion = await this.httpWrapper.getGameVersion();
28 | try {
29 | const buffer = fs.readFileSync(`data/${gameVersion}/data.js`);
30 | const context = {};
31 | vm.runInNewContext(buffer.toString("utf-8"), context);
32 | this.gameData = context.G;
33 | console.log("Reading game data from cache for pathfinding");
34 | } catch (e) {
35 | console.log(`Unable to read data form version: ${gameVersion} path finding instance stopping.`);
36 | process.exit(1);
37 | }
38 | }
39 |
40 | async createMesh() {
41 | this.mapProcessor = new MapProcessor(this.gameData, 1, 1);
42 | this.world = this.mapProcessor.createWorld();
43 | }
44 |
45 | findPath(startX, startY, startMap, endX, endY, endMap) {
46 | let startFloor = this.world.floors.get(startMap);
47 | let endFloor = this.world.floors.get(endMap);
48 | startX -= startFloor.offset.x
49 | startY -= startFloor.offset.y
50 | endX -= endFloor.offset.x
51 | endY -= endFloor.offset.y
52 |
53 |
54 | let startBox = startFloor.matrices.base[startX + startFloor.size.x * startY];
55 | let endBox = endFloor.matrices.base[endX + endFloor.size.x * endY];
56 |
57 | if (!startBox || startBox > 0xfffd)
58 | return [];
59 | if (!endBox || endBox > 0xfffd)
60 | return [];
61 |
62 |
63 | let open = new Uint8Array(this.world.boxes.length).fill(1);
64 | let openDoors = new Uint16Array(this.world.doors.length).fill(1);
65 | let previous = new Array(this.world.boxes.length).fill(undefined);
66 | let dist = new Uint16Array(this.world.boxes.length).fill(0xffff);
67 |
68 | let found = new PriorityQueue((boxA, boxB) => {
69 | return dist[boxA] < dist[boxB];
70 | });
71 |
72 | dist[startBox] = 0;
73 | found.push(startBox);
74 | while (found.size() > 0) {
75 | let currentId = found.pop();
76 | if (!open[currentId])
77 | continue;
78 | let current = this.world.boxes[currentId];
79 | for (let i = 0; i < current.neighbors.length; i += 2) {
80 | const neighborId = current.neighbors[i];
81 | if (!open[neighborId])
82 | continue;
83 | const nodeDist = current.neighbors[i + 1];
84 | if (dist[currentId] + nodeDist < dist[neighborId]) {
85 | dist[neighborId] = dist[currentId] + nodeDist;
86 | found.push(neighborId);
87 | previous[neighborId] = currentId;
88 | }
89 | if (neighborId == endBox)
90 | break;
91 | }
92 | for (let i = 0; i < current.doors.length; i++) {
93 | const doorId = current.doors[i];
94 | const door = this.world.doors[current.doors[i]];
95 | const neighborId = door.exitId;
96 | if (!open[neighborId])
97 | continue;
98 | openDoors[doorId] = 0;
99 | if (dist[currentId] < dist[neighborId]) {
100 | dist[neighborId] = dist[currentId];
101 | found.push(neighborId);
102 | previous[neighborId] = door;
103 | }
104 | }
105 | open[currentId] = 0;
106 | }
107 |
108 | let current = endBox;
109 | let path = [];
110 | while (current !== undefined) {
111 | if (typeof current == "object") {
112 | path.push(current)
113 | path.push(current.entryId)
114 | current = previous[current.entryId];
115 | } else {
116 | path.push(current);
117 | current = previous[current];
118 | }
119 | }
120 | return path.reverse();
121 | }
122 | }
123 |
124 | async function main() {
125 | let pathfinding = new _Pathfinding();
126 | try {
127 | await pathfinding.loadCache();
128 | } catch (e) {
129 | await pathfinding.loadData();
130 | await pathfinding.createMesh();
131 | }
132 | server.on("connection", (socket) => {
133 | socket.on("findPath", (data, cb) => {
134 | let {startX, startY, startMap, endX, endY, endMap} = data;
135 | let path = pathfinding.findPath(startX, startY, startMap, endX, endY, endMap);
136 | let currentMap = pathfinding.world.floors.get(startMap);
137 | for (let i = 0; i < path.length; i++) {
138 | if (typeof path[i] == "number") {
139 | let box = pathfinding.world.boxes[path[i]];
140 | path[i] = {
141 | x: box.x + currentMap.offset.x + box.size.x / 2,
142 | y: box.y + currentMap.offset.y + box.size.y / 2
143 | }
144 | } else {
145 | currentMap = path[i].exit.floor;
146 | path[i] = {
147 | entry: path[i].entry,
148 | transition: path[i].exit.floor.name,
149 | s: path[i].exit.s,
150 | }
151 | }
152 | }
153 | cb(path);
154 | }
155 | )
156 | })
157 | server.listen(3000);
158 | if (process.send)
159 | process.send("ready")
160 |
161 | }
162 |
163 | main();
--------------------------------------------------------------------------------
/pathfinding/cache/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
--------------------------------------------------------------------------------
/pathfinding/output.js:
--------------------------------------------------------------------------------
1 | const pngUtil = require("../app/pngUtil.js");
2 | var fs = require('fs'),
3 | PNG = require('pngjs').PNG;
4 | const colors = [[128, 0, 0], [139, 0, 0], [165, 42, 42], [178, 34, 34], [220, 20, 60], [255, 0, 0], [255, 99, 71], [255, 127, 80], [205, 92, 92], [240, 128, 128], [233, 150, 122], [250, 128, 114], [255, 160, 122], [255, 69, 0], [255, 140, 0], [255, 165, 0], [255, 215, 0], [184, 134, 11], [218, 165, 32], [238, 232, 170], [189, 183, 107], [240, 230, 140], [128, 128, 0], [255, 255, 0], [154, 205, 50], [85, 107, 47], [107, 142, 35], [124, 252, 0], [127, 255, 0], [173, 255, 47], [0, 100, 0], [0, 128, 0], [34, 139, 34], [0, 255, 0], [50, 205, 50], [144, 238, 144], [152, 251, 152], [143, 188, 143], [0, 250, 154], [0, 255, 127], [46, 139, 87], [102, 205, 170], [60, 179, 113], [32, 178, 170], [47, 79, 79], [0, 128, 128], [0, 139, 139], [0, 255, 255], [0, 255, 255], [224, 255, 255], [0, 206, 209], [64, 224, 208], [72, 209, 204], [175, 238, 238], [127, 255, 212], [176, 224, 230], [95, 158, 160], [70, 130, 180], [100, 149, 237], [0, 191, 255], [30, 144, 255], [173, 216, 230], [135, 206, 235], [135, 206, 250], [25, 25, 112], [0, 0, 128], [0, 0, 139], [0, 0, 205], [0, 0, 255], [65, 105, 225], [138, 43, 226], [75, 0, 130], [72, 61, 139], [106, 90, 205], [123, 104, 238], [147, 112, 219], [139, 0, 139], [148, 0, 211], [153, 50, 204], [186, 85, 211], [128, 0, 128], [216, 191, 216], [221, 160, 221], [238, 130, 238], [255, 0, 255], [218, 112, 214], [199, 21, 133], [219, 112, 147], [255, 20, 147], [255, 105, 180], [255, 182, 193], [255, 192, 203], [250, 235, 215], [245, 245, 220], [255, 228, 196], [255, 235, 205], [245, 222, 179], [255, 248, 220], [255, 250, 205], [250, 250, 210], [255, 255, 224], [139, 69, 19], [160, 82, 45], [210, 105, 30], [205, 133, 63], [244, 164, 96], [222, 184, 135], [210, 180, 140], [188, 143, 143], [255, 228, 181], [255, 222, 173], [255, 218, 185], [255, 228, 225], [255, 240, 245], [250, 240, 230], [253, 245, 230], [255, 239, 213], [255, 245, 238], [245, 255, 250], [112, 128, 144], [119, 136, 153], [176, 196, 222], [230, 230, 250], [255, 250, 240], [240, 248, 255], [248, 248, 255], [240, 255, 240], [255, 255, 240], [240, 255, 255], [255, 250, 250], [105, 105, 105], [128, 128, 128], [169, 169, 169], [192, 192, 192], [211, 211, 211], [220, 220, 220], [245, 245, 245], [255, 255, 255]];
5 |
6 | function draw_funny_boxes(floor, list) {
7 | var png = new PNG({
8 | width: floor.size.x,
9 | height: floor.size.y,
10 | filterType: -1
11 | });
12 | try {
13 | for (let j = 0; j < floor.matrices.base.length; j++) {
14 | if (floor.matrices.base[j] == 0xffff) {
15 | const idx = j << 2;
16 | png.data[idx] = 0;
17 | png.data[idx + 1] = 0;
18 | png.data[idx + 2] = 0;
19 | png.data[idx + 3] = 255;
20 | } else if (floor.matrices.base[j] == 0xfffe) {
21 | const idx = j << 2;
22 | png.data[idx] = 255;
23 | png.data[idx + 1] = 255;
24 | png.data[idx + 2] = 255;
25 | png.data[idx + 3] = 255;
26 | } else if (list.has(floor.matrices.base[j])) {
27 | const color = colors[((floor.matrices.base[j]) % 31)];
28 | const idx = j << 2;
29 | png.data[idx] = color[0];
30 | png.data[idx + 1] = color[1];
31 | png.data[idx + 2] = color[2];
32 | png.data[idx + 3] = 255;
33 | } else {
34 | const idx = j << 2;
35 | png.data[idx] = 0;
36 | png.data[idx + 1] = 0;
37 | png.data[idx + 2] = 0;
38 | png.data[idx + 3] = 255;
39 | }
40 | }
41 |
42 | } catch (e) {
43 | console.error(e)
44 | }
45 | let buffer = PNG.sync.write(png);
46 | fs.writeFileSync('./pathfinding/maps/' + floor.name + ".png", buffer);
47 | }
48 |
49 | function draw_funny_lines({boxMap, size, map, qtn, qtg, filename}) {
50 | var png = new PNG({
51 | width: size.x,
52 | height: size.y,
53 | filterType: -1
54 | });
55 | try {
56 | for (let j = 0; j < map.length; j++) {
57 | if (map[j] == 0xffff) {
58 | let idx = j << 2;
59 | png.data[idx] = 0;
60 | png.data[idx + 1] = 0;
61 | png.data[idx + 2] = 0;
62 | png.data[idx + 3] = 255;
63 | } else {
64 | let idx = j << 2;
65 | png.data[idx] = 255;
66 | png.data[idx + 1] = 255;
67 | png.data[idx + 2] = 255;
68 | png.data[idx + 3] = 255;
69 | }
70 | }
71 |
72 | for (let j = 0; j < qtn.length; j++) {
73 | let node = qtn[j];
74 | pngUtil.draw_dot(node.x, node.y, 1, png, [255, 0, 0, 255])
75 | }
76 |
77 | for (let j = 0; j < qtn.length; j++) {
78 | let node = qtn[j];
79 | if (qtg[node.x + ":" + node.y]) {
80 | for (let edge of qtg[node.x + ":" + node.y]) {
81 | pngUtil.draw_line(node.x, node.y, edge.x, edge.y, png, [255, 0, 0, 255])
82 | }
83 | }
84 | }
85 |
86 | console.log("Done " + filename + ".png");
87 | } catch (e) {
88 | console.error(e)
89 | }
90 |
91 | let buffer = PNG.sync.write(png);
92 | fs.writeFileSync('./maps/' + filename, buffer);
93 |
94 | }
95 |
96 |
97 | function draw_base(array, size) {
98 | var png = new PNG({
99 | width: size.x,
100 | height: size.y,
101 | filterType: -1
102 | });
103 | try {
104 | let idx = 0;
105 | for (let j = 0; j < size.y; j++) {
106 | for (let i = 0; i < size.x; i++) {
107 | if (array[i + size.x * j] === 1) {
108 | png.data[idx] = 255;
109 | png.data[idx + 1] = 255;
110 | png.data[idx + 2] = 255;
111 | png.data[idx + 3] = 255;
112 | } else if (array[i + size.x * j] === 2) {
113 | png.data[idx] = 125;
114 | png.data[idx + 1] = 125;
115 | png.data[idx + 2] = 125;
116 | png.data[idx + 3] = 255;
117 | } else {
118 | png.data[idx] = 0;
119 | png.data[idx + 1] = 0;
120 | png.data[idx + 2] = 0;
121 | png.data[idx + 3] = 255;
122 | }
123 | idx = idx + 4;
124 | }
125 | }
126 | } catch (e) {
127 | console.log(e);
128 | }
129 | return png;
130 | }
131 |
132 | function draw_lines(png, map) {
133 | let x_lines = map.optimizedLines.x_lines;
134 | for (let line of x_lines) {
135 | pngUtil.draw_line((line[0] - map.offset.x) / map.keenness, (line[1] - map.offset.y) / map.keenness, (line[0] - map.offset.x) / map.keenness, (line[2] - map.offset.y) / map.keenness, png, [225, 0, 0, 255])
136 | }
137 | let y_lines = map.optimizedLines.y_lines;
138 | for (let line of y_lines) {
139 | pngUtil.draw_line((line[1] - map.offset.x) / map.keenness, (line[0] - map.offset.y) / map.keenness, (line[2] - map.offset.x) / map.keenness, (line[0] - map.offset.y) / map.keenness, png, [225, 0, 0, 255])
140 | }
141 | return png;
142 | }
143 |
144 |
145 | function save(png, filename) {
146 | let buffer = PNG.sync.write(png);
147 | fs.writeFileSync('./pathfinding/maps/' + filename, buffer);
148 | }
149 |
150 |
151 | function draw_box_path({boxMap, size, map, qtn, qtg, filename, path}) {
152 | var fs = require('fs'),
153 | PNG = require('pngjs').PNG;
154 |
155 | var png = new PNG({
156 | width: size.x,
157 | height: size.y,
158 | filterType: -1
159 | });
160 | try {
161 | for (let j = 0; j < boxMap.length; j++) {
162 | if (boxMap[j] !== 0) {
163 | let position = path.indexOf(boxMap[j]);
164 | if (position !== -1) {
165 | let color = colors[position % (colors.length - 1)];
166 | let idx = j << 2;
167 | png.data[idx] = color[0];
168 | png.data[idx + 1] = color[1];
169 | png.data[idx + 2] = color[2];
170 | png.data[idx + 3] = 255;
171 | } else {
172 | let idx = j << 2;
173 | png.data[idx] = 100;
174 | png.data[idx + 1] = 100;
175 | png.data[idx + 2] = 100;
176 | png.data[idx + 3] = 255;
177 | }
178 | } else {
179 | let idx = j << 2;
180 | png.data[idx] = 0;
181 | png.data[idx + 1] = 0;
182 | png.data[idx + 2] = 0;
183 | png.data[idx + 3] = 255;
184 | }
185 | }
186 |
187 | console.log("Done " + filename + ".png");
188 |
189 | } catch (e) {
190 | console.error(e)
191 | }
192 |
193 | let buffer = PNG.sync.write(png);
194 | fs.writeFileSync('./maps/' + filename, buffer);
195 |
196 | }
197 |
198 | module.exports = {draw_funny_boxes, draw_funny_lines, draw_box_path, draw_base, save, draw_lines};
199 |
--------------------------------------------------------------------------------
/userData.example.json:
--------------------------------------------------------------------------------
1 | {
2 | "important": "do not show this file to anyone else! Session information can be used to login without the need of a password.",
3 | "config": {
4 | "fetch": true,
5 | "botKey": 1,
6 | "browserUserAgent": "{ALBot: (v1.7.0)}",
7 | "baseUrl": "https://adventure.land",
8 | "botWebInterface": {
9 | "enabled": false,
10 | "port": 2080,
11 | "password": "",
12 | "minimap": {
13 | "enabled": false,
14 | "speed": 1000,
15 | "size": {
16 | "height": 200,
17 | "width": 376
18 | }
19 | }
20 | },
21 | "pathfinding": {
22 | "enabled": false
23 | },
24 | "logging": {
25 | "enable": false,
26 | "prefixString": "{{h}}:{{m}}:{{s}} {{serverRegion}} {{serverIdentifier}} {{characterName}} [{{runScript}}]: "
27 | }
28 | },
29 | "login": {
30 | "email": "",
31 | "password": ""
32 | },
33 | "bots": []
34 | }
--------------------------------------------------------------------------------