Advertisement
Guest User

Untitled

a guest
May 25th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.12 KB | None | 0 0
  1.  
  2. const colors = require("colors");
  3.  
  4. let kitay = ["乾", "神", "盘", "五", "岳", "喜", "双", "喜", "蟠", "桃", "果", "熟", "三",
  5. "千", "岁", "福", "寿", "双", "😎", "😝", "😈", "😎", "😝", "😂", "😈", "😲", "😳",
  6. "🍔", "🍟", "🍩", "🎃", "🎄", "🎅", "🐣", "🐤", "👻", "👽", "👮", "இ", "💋",
  7. "👣", "💀", "🔥", "😾", "🏆", "🎁", "🐺", "🐍", "🍧", "🍪", "🍮", "🎈", "🐧",
  8. "👌", "🐨", "🉑", "🉐", "🈺", "🈹", "🈸", "🈶", "🈵", "🈴", "🈳", "🈲", "🈯",
  9. "🈚", "🈳"
  10. ];
  11.  
  12. const names = [
  13. //"H҉a҉c҉k҉e҉r҉"
  14. "Litu-Client"
  15. //"YT:ToxoidGuy",
  16. //"SizRex",
  17. // "FbreetzYT"
  18. ];
  19. var eKey = 1773838882;
  20. const defaultBorders = {
  21. minX: -7071.067811865475,
  22. minY: -7071.067811865475,
  23. maxX: 7071.067811865475,
  24. maxY: 7071.067811865475
  25. };
  26.  
  27. class user {
  28. constructor(IP, UUID, COINS) {
  29. this._IP = IP;
  30. this._UUID = UUID;
  31. this._COINS = COINS;
  32. this._bots = [];
  33. this._startTimeInt = 0;
  34. this.ProxyManager = null;
  35. this._coinsSave = 0;
  36. this.resetProxy();
  37. }
  38. startBots(botCount, agarServer) {
  39. if(this._COINS <= 0) return;
  40. this.startTimeTick();
  41. for(let i = 0; i < botCount; i++) {
  42. this._bots.push(new bot(i, this, agarServer));
  43. }
  44. }
  45. stopBots() {
  46. this.resetProxy();
  47. for(let i = 0; i < this._bots.length; i++) {
  48. if(this._bots[i]) {
  49. if(this._bots[i]._ws) {
  50. this._bots[i].reconnecting = false;
  51. try {
  52. this._bots[i]._ws.close();
  53. } catch(e) {}
  54. }
  55. }
  56. }
  57. this._bots = [];
  58. this.saveCoins();
  59. }
  60. splitBots() {
  61. for(let i = 0; i < this._bots.length; i++) {
  62. if(this._bots[i]) {
  63. this._bots[i].split();
  64. }
  65. }
  66. }
  67. ejectBots() {
  68. for(let i = 0; i < this._bots.length; i++) {
  69. if(this._bots[i]) {
  70. this._bots[i].eject();
  71. }
  72. }
  73. }
  74. moveBots(x, y) {
  75. for(let i = 0; i < this._bots.length; i++) {
  76. this._bots[i].handleBotAI(x, y);
  77. }
  78. }
  79. saveCoins() {
  80. clearInterval(this._startTimeInt);
  81. global.database = global.fs.readFileSync("./database.json", "utf-8");
  82. let check_database = JSON.parse(global.database);
  83. for(let i = 0; i < check_database.length; i++) {
  84. if(check_database[i].UUID == this._UUID) {
  85. check_database[i].coins = this._COINS;
  86. global.fs.writeFileSync("./database.json", global.json_corrector(check_database))
  87. }
  88. }
  89. }
  90. getCoins() {
  91. return this._COINS;
  92. }
  93. getCoinsDown() {
  94. this._COINS -= 5;
  95. }
  96. startTimeTick() {
  97. this._startTimeInt = setInterval(function(){
  98. this._COINS--;
  99. if(this._COINS <= 0) {
  100. this.stopBots();
  101. clearInterval(this._startTimeInt);
  102. }
  103. }.bind(this),1000);
  104. }
  105. getInformation() {
  106. let connected = 0;
  107. let spawned = 0;
  108. let coins = this._COINS;
  109. for(let i = 0; i < this._bots.length; i++) {
  110. if(this._bots[i] && this._bots[i]._ws) {
  111. if(this._bots[i]._ws.readyState == 1) {
  112. connected++;
  113. if(this._bots[i]._spawned) spawned++;
  114. }
  115. }
  116. }
  117. return {
  118. cB: connected,
  119. sB: spawned,
  120. uC: coins
  121. }
  122. }
  123. resetProxy() {
  124. this.ProxyManager = {
  125. socksProxies: [],
  126. httpProxies: [],
  127. usedAgents: {},
  128. agents: [],
  129.  
  130. loadProxies() {
  131. this.socksProxies = global.fs.readFileSync('./socksProxies.txt', 'utf8').split('\n');
  132. this.httpProxies = global.fs.readFileSync('./httpProxies.txt', 'utf8').split('\n');
  133. },
  134.  
  135. loadAgents() {
  136. this.loadProxies();
  137. for (let i = 0; i < this.socksProxies.length; i++) {
  138. if (this.socksProxies[i] == '') continue;
  139. let proxyInfo = this.socksProxies[i].split(':');
  140. for (let a = 0; a < 1; a++) {
  141. this.agents.push(new global.socks.Agent({
  142. proxy: {
  143. ipaddress: proxyInfo[0],
  144. port: proxyInfo[1] >>> 0,
  145. type: 5
  146. }
  147. }));
  148. }
  149. }
  150. for (let i = 0; i < this.httpProxies.length; i++) {
  151. let proxyInfo = this.httpProxies[i];
  152. this.agents.push(new global.HTTP(`http://${proxyInfo}`));
  153. }
  154. },
  155.  
  156. getAgent(id, unuseableProxy) {
  157. const agent = this.usedAgents[id];
  158. if (agent && !unuseableProxy) this.agents.push(agent);
  159. const newAgent = this.agents.shift();
  160. this.usedAgents[id] = newAgent;
  161. return newAgent;
  162. }
  163. };
  164. this.ProxyManager.loadAgents();
  165. }
  166. }
  167.  
  168.  
  169.  
  170. function deflate(input, output, sIdx, eIdx) {
  171. sIdx = sIdx || 0;
  172. eIdx = eIdx || (input.length - sIdx);
  173. for (let i = sIdx, n = eIdx, j = 0; i < n;) {
  174. let token = input[i++];
  175. let literals_length = (token >> 4);
  176. if (literals_length > 0) {
  177. let l = literals_length + 240;
  178. while (l === 255) {
  179. l = input[i++];
  180. literals_length += l;
  181. };
  182. let end = i + literals_length;
  183. while (i < end) output[j++] = input[i++];
  184. if (i === n) return output;
  185. };
  186. let offset = input[i++] | (input[i++] << 8);
  187. if (offset === 0 || offset > j) return -(i - 2);
  188. let match_length = (token & 0xf);
  189. let l = match_length + 240;
  190. while (l === 255) {
  191. l = input[i++];
  192. match_length += l;
  193. };
  194. let pos = j - offset;
  195. let end = j + match_length + 4;
  196. while (j < end) output[j++] = output[pos++];
  197. };
  198. return output;
  199. };
  200.  
  201. class bot {
  202. constructor(id, user, server) {
  203. this._userJS = user;
  204. this.agerServer = server;
  205. this.id = id;
  206. this._lastBorderTime = Date.now();
  207. this._borders = Object.assign(defaultBorders);
  208. this._MyWorldCell_IDS = [];
  209. this._WorldCells = {};
  210. this._protocolVersion = global.protocolVersion;
  211. this._protocolKey = global.protocolKey;
  212. this._encryptionKey = eKey;
  213. this._decryptionKey = 0;
  214. this._xPos = 0;
  215. this._yPos = 0;
  216. this._waitingForToken = false;
  217. this.reconnecting = true;
  218. this._offsetX = 0;
  219. this._offsetY = 0;
  220. this._fSpawn = false;
  221. this._unuseableProxy = false;
  222. this._onceSplit = false;
  223. this._spawned = false;
  224. this._ws = null;
  225. this._sendFBdata = false;
  226. this._switchMove = false;
  227. this._switchMoveInt = null;
  228. this.auth_token = null;
  229. this.switchMovingIntervalTimout = 2500;
  230. this._goLoggedIn = false;
  231. this._splitOnPlayer = {
  232. splited: false,
  233. cellID: null
  234. }
  235. this._fbAccInformation = {
  236. coins: 0,
  237. lvl: 0,
  238. skin: null
  239. }
  240. this.log_lvl = 6;
  241. setTimeout(function() {
  242. this.connect();
  243. }.bind(this), 5 * this.id);
  244. }
  245.  
  246. connect() {
  247. let proxyServer = this._userJS.ProxyManager.getAgent(this.id, this._unuseableProxy);
  248. this._ws = new global.ws(this.agerServer, {
  249. 'headers': {
  250. 'origin': 'https://agar.io',
  251. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
  252. },
  253. 'agent': proxyServer
  254. });
  255. this._ws.binaryType = 'nodebuffer';
  256. this._ws.onopen = this.onopen.bind(this);
  257. this._ws.onmessage = this.onmessage.bind(this);
  258. this._ws.onclose = this.onclose.bind(this);
  259. this._ws.onerror = this.onerror.bind(this);
  260. this._unuseableProxy = true;
  261. }
  262.  
  263. onopen() {
  264.  
  265. let buf = new Buffer.alloc(5);
  266. buf.writeUInt8(254, 0);
  267. buf.writeUInt32LE(this._protocolVersion, 1);
  268. this.send(buf);
  269.  
  270. buf = new Buffer.alloc(5);
  271. buf.writeUInt8(255, 0);
  272. buf.writeUInt32LE(this._protocolKey, 1);
  273. this.send(buf);
  274.  
  275. this.sendFBLogin();
  276. this.spawn();
  277. }
  278.  
  279. sendFBLogin() {
  280. var hasAccs = global.facebookManger.hasAvailableToken();
  281. if(hasAccs == true) {
  282. this.auth_token = global.facebookManger.getToken();
  283. }
  284. if(this.auth_token) {
  285. let c = this;
  286. let check_l = this.auth_token.length + 25;
  287. let bytes = [];
  288. if(check_l > 255) {
  289. setTimeout(function() { this.sendFBLogin() }.bind(this),100);
  290. } else {
  291. if(this.auth_token.length > 255) {
  292.  
  293. bytes = [102, 8, 1, 18, this.auth_token.length - 103, 2, 8, 10, 82, this.auth_token.length - 138, 2, 8, 2, 18, 14, 8, 5, 18, 6, 50, 46, 49, 48, 46, 53, 24, 0, 32, 0, 26, this.auth_token.length - 128, 2];
  294.  
  295. } else if(this.auth_token.length < 255) {
  296.  
  297. bytes = [102, 8, 1, 18, this.auth_token.length + 26, 1, 8, 10, 82, this.auth_token.length + 21, 1, 8, 2, 18, 14, 8, 5, 18, 6, 50, 46, 49, 48, 46, 53, 24, 0, 32, 0, 26, this.auth_token.length, 1];
  298.  
  299. };
  300. function compile() {
  301.  
  302. for(var i = 0; i <= c.auth_token.length - 1; i++) {
  303.  
  304. bytes.push(c.auth_token.charCodeAt(i));
  305.  
  306. };
  307.  
  308. build();
  309.  
  310. };
  311.  
  312. function build() {
  313.  
  314. var buf = new Buffer.alloc(bytes.length);
  315.  
  316.  
  317. for(var i = 0; i <= bytes.length - 1; i++) {
  318.  
  319. var byte = bytes[i];
  320.  
  321. if(byte > 255) {
  322.  
  323. buf.writeUInt16LE(byte, i);
  324.  
  325. } else {
  326.  
  327. buf.writeUInt8(byte, i);
  328.  
  329. };
  330.  
  331. };
  332.  
  333.  
  334. var buffer = buf;
  335.  
  336. c.send(buffer, true);
  337.  
  338. };
  339.  
  340. compile();
  341. }
  342. }
  343. }
  344.  
  345. onmessage(msg) {
  346. let buf = null;
  347.  
  348. if (this._decryptionKey)
  349. buf = this.xorBuffer(msg.data, this._decryptionKey ^ this._protocolKey);
  350. else
  351. buf = msg.data;
  352.  
  353. let offset = 0;
  354. let opcode = null;
  355. try {
  356. opcode = buf.readUInt8(offset++);
  357. } catch (e) {
  358. return;
  359. }
  360. switch (opcode) {
  361. case 18:
  362. if (!this._decryptionKey) break;
  363. this._decryptionKey = eKey;
  364. this._MyWorldCell_IDS = [];
  365. this._WorldCells = {};
  366. break;
  367. case 32:
  368. if(this._switchMoveInt == null) {
  369. this._switchMoveInt = setInterval(function() {
  370. if(this._switchMove) {
  371. this._switchMove = false;
  372. this.switchMovingIntervalTimout = 2500;
  373. } else if(!this._switchMove) {
  374. this._switchMove = true;
  375. this.switchMovingIntervalTimout = 500;
  376. }
  377. }.bind(this), this.switchMovingIntervalTimout);
  378. }
  379. if (!this._fSpawn) {
  380. this._fSpawn = true;
  381. this.sendFBLogin();
  382. }
  383. try {
  384. this._MyWorldCell_IDS.push(buf.readUInt32LE(offset));
  385. this._spawned = true;
  386. } catch (e) {}
  387. break;
  388. case 85:
  389. if (this._userJS.getCoins() <= 0) return this.reconnecting = false, this._ws.close();
  390. this.unuseableProxy = true;
  391. this._ws.close();
  392. //this._waitingForToken = true;
  393. //this.sendRecaptchaResponse("FUCK YOU AGAR")
  394. //this.requestCaptcha();
  395. break;
  396. case 102:
  397.  
  398. /*let ShopType = 0;
  399. let Terminal = 0;
  400. let offset = 2;
  401. //console.log(buf);
  402. Terminal = buf.readUInt16LE(offset);
  403. offset += 2;
  404. ShopType = buf.readUInt8(offset++);
  405. console.log(ShopType, Terminal, offset);*/
  406.  
  407.  
  408. break;
  409. case 103: // FB LOGIN
  410. //console.log("Login done");
  411.  
  412. this.collectFreeCoins();
  413. //this.buy_mass_boost();
  414. //this.activate_mass_boost();
  415. break;
  416. case 104: // FB LOGOUT
  417. if(this.auth_token) global.facebookManger.returnToken(this.auth_token);
  418. this.auth_token = null;
  419. break;
  420. case 105:
  421. this.unuseableProxy = true;
  422. this._ws.close();
  423. break;
  424. case 112:
  425. buf = Buffer.from(buf);
  426. const packet112 = new Buffer.alloc(buf.byteLength + 2);
  427. for (let i = 0; i < buf.byteLength; i++) packet112.writeUInt8(buf.readUInt8(i), i);
  428. packet112.writeUInt16LE(this.id, buf.byteLength);
  429. this.send(packet112, true);
  430. break;
  431. case 113:
  432. const botID = buf.readUInt16LE(buf.byteLength - 2);
  433. const packet113 = new Buffer.alloc(buf.byteLength - 2);
  434. for (let i = 0; i < buf.byteLength - 2; i++) packet113.writeUInt8(buf.readUInt8(i), i);
  435. this.send(packet113, true);
  436. break;
  437. case 161:
  438. //console.log(new Uint8Array(buf));
  439. break;
  440. case 226:
  441. buf.writeUInt8(227, 0);
  442. this.send(buf, true);
  443. break;
  444. case 241:
  445. try {
  446. this._decryptionKey = buf.readInt32LE(offset);
  447. } catch (e) {}
  448. break;
  449. case 242:
  450. //console.log(buf.readUInt32LE(1));
  451. break;
  452. case 255:
  453. buf = this.decompressBuffer(buf);
  454. let n_offset = 0;
  455. let n_opcode = null;
  456. try {
  457. n_opcode = buf.readUInt8(n_offset++);
  458. } catch (e) {
  459. break;
  460. }
  461. switch (n_opcode) {
  462. case 16:
  463. this.handleCells(buf);
  464. break;
  465. case 64:
  466. this.handleBorders(buf);
  467. break;
  468. }
  469. if (!this._waitingForToken && Date.now() - this._lastBorderTime > 2000) {
  470. clearInterval(this._switchMoveInt);
  471. this._switchMoveInt = null;
  472. this._MyWorldCell_IDS = [];
  473. this._WorldCells = {};
  474. this._spawned = false;
  475. this._onceSplit = false;
  476. this._splitOnPlayer.splited = false;
  477. this.changeSkin("skin_fly");
  478. this.spawn();
  479. this._lastBorderTime = Date.now();
  480. }
  481. break;
  482. default:
  483. //console.log(this.id, opcode, buf);
  484. }
  485. }
  486.  
  487. changeSkin(skin) {
  488.  
  489. if(typeof(skin) == "string") {
  490. // OMG UR BYTES NOT WORK CHANGE SKIN IT - 102 FIRST BYTE.. OMG
  491. var bytes = [102, 8, 1, 18, 21, 8, 80, 130, 5, 16, 10, 14, 8, 1, 16, 1, 26, 8];
  492.  
  493. for(let i = 0; i < skin.length; i++ ){
  494. bytes.push(skin.charCodeAt(i));
  495. }
  496.  
  497. let buf = Buffer.from(bytes);
  498.  
  499. this.send(buf, true);
  500.  
  501. } else {
  502.  
  503. console.log("Invalid skin");
  504.  
  505. };
  506. }
  507.  
  508. collectFreeCoins() {
  509.  
  510. var name = "hourlyBonus";
  511. var buf = new global.writer(23); //LENGHT
  512.  
  513. buf.writeUInt8(102); //OPCODE
  514. buf.writeUInt8(8); //FB VERSION
  515. buf.writeUInt8(1); //TYPE 1 = FB 2 = GOOGLE
  516. buf.writeUInt8(18); //IDK
  517. buf.writeUInt8(18); //Something IDK
  518. buf.writeUInt8(8); //FB VERSION
  519. buf.writeUInt8(110); //IDK
  520. buf.writeUInt8(242); //IDK
  521. buf.writeUInt8(6); //Version?
  522. buf.writeUInt8(13); //IDK
  523. buf.writeUInt8(10); //IDK
  524. buf.writeUInt8(11); //IDK
  525. buf.writeStringUtf8(name, true);
  526.  
  527. this.send(buf.toBuffer(), true);
  528. /*setInterval(collectFreeCoins(), 3600000);
  529. console.log("freecoin collected.")*/
  530.  
  531. }
  532.  
  533. buy_mass_boost() {
  534.  
  535. let bytes = [102, 8, 1, 18, 25, 8, 70, 178, 4, 20, 10, 18];
  536.  
  537. let massBoostName = "1_mass_boost_3x_1h";
  538.  
  539. for(let i = 0; i < massBoostName.length; i++) {
  540. bytes.push(massBoostName.charCodeAt(i));
  541. }
  542.  
  543. let buf = Buffer.from(bytes);
  544.  
  545. this.send(buf, true);
  546.  
  547. }
  548.  
  549. activate_mass_boost() {
  550.  
  551. let bytes = [102, 8, 1, 18, 23, 8, 112, 130, 7, 18, 10, 16];
  552.  
  553. let massBoostName = "mass_boost_3x_1h";
  554.  
  555. for(let i = 0; i < massBoostName.length; i++) {
  556. bytes.push(massBoostName.charCodeAt(i));
  557. }
  558.  
  559. let buf = Buffer.from(bytes);
  560.  
  561. this.send(buf, true);
  562.  
  563. }
  564.  
  565. requestCaptcha() {
  566. if (this._userJS.getCoins() <= 0) return this.reconnecting = false, this._ws.close();
  567. /*let ran_id = Math.floor(Math.random() * 1000000);
  568. request(`http://api.captchacoder.com/imagepost.ashx?action=upload&key=PO3LLHK2I1FB9Z6YDQUWFGVUIYYINTIJ43J4RENY&captchatype=3&gen_task_id=${ran_id}&sitekey=6LfjUBcUAAAAAF6y2yIZHgHIOO5Y3cU5osS2gbMl&pageurl=http://agar.io`, (err, res, body) => {
  569. if (err || res.statusCode !== 200) {
  570. this._unuseableProxy = true;
  571. this._ws.close();
  572. console.log('Failed to send request to generate captcha token');
  573. return;
  574. }
  575. if(body === "Error Queue_Limited" || body === "Error Timeout" || body === "Error Not_Enough_Fund") return this.requestCaptcha();
  576. coinsToMinus += 5;
  577. this.sendRecaptchaResponse(body);
  578. console.log(`Got recaptcрa response token`, `${body}`.green);
  579. this._waitingForToken = false;
  580. });*/
  581. global.request('http://2captcha.com/in.php?key=&method=userrecaptcha&googlekey=6LfjUBcUAAAAAF6y2yIZHgHIOO5Y3cU5osS2gbMl&pageurl=agar.io', (err, res, body) => {
  582. if (err || res.statusCode !== 200) {
  583. this._unuseableProxy = true;
  584. this._ws.close();
  585. console.log('Failed to send request to generate captcha token');
  586. return;
  587. }
  588. this._userJS.getCoinsDown();
  589. const id = body.split('|')[1];
  590. this.log(`Uploaded captcha, got response ID ${id} starting wait interval.`, 6);
  591. const requestInterval = setInterval(() => {
  592. global.request(`http://2captcha.com/res.php?key=&action=get&id=${id}`, (err, res, body) => {
  593. if (err || res.statusCode !== 200 || !/OK/.test(body)) return;
  594. const recaptchaResponse = body.split('|')[1];
  595. this.sendRecaptchaResponse(recaptchaResponse);
  596. this.log(`Got recaptcрa response token ${recaptchaResponse}`, 6);
  597. clearInterval(requestInterval);
  598. this._waitingForToken = false;
  599. });
  600. }, 5000);
  601. });
  602.  
  603. /*let that = this;
  604.  
  605. anticaptcha.getBalance(function (err, balance) {
  606. if (err) {
  607. that._unuseableProxy = true;
  608. that._ws.close();
  609. return;
  610. }
  611. if (balance > 0) {
  612. anticaptcha.createTaskProxyless(function (err, taskId) {
  613. if (err) {
  614. that._unuseableProxy = true;
  615. that._ws.close();
  616. return;
  617. }
  618.  
  619. anticaptcha.getTaskSolution(taskId, function (err, taskSolution) {
  620. if (err) {
  621. return;
  622. }
  623.  
  624. that.sendRecaptchaResponse(taskSolution);
  625. console.log(`Got recaptcрa response token`, `${taskSolution}`.green);
  626. that._waitingForToken = false;
  627. });
  628. });
  629. }
  630. });*/
  631. }
  632.  
  633. decompressBuffer(buf) {
  634. try {
  635. let buf_ = buf.readUInt32LE(1);
  636. let out = new Buffer.alloc(buf_);
  637. return deflate(buf.slice(5), out);
  638. } catch (e) {}
  639. }
  640.  
  641. log(msg, lvl) {
  642. if (lvl != this.log_lvl) return;
  643. console.log(`[bot ${this.id}] get message -> `, (msg).green);
  644. }
  645.  
  646. sendRecaptchaResponse(response) {
  647. let buf = new Buffer.alloc(2 + response.length);
  648. buf.writeUInt8(86, 0);
  649. buf.write(response, 1);
  650. this.send(buf, true);
  651. //this.spawn();
  652. }
  653.  
  654. handleBorders(buf) {
  655. let offset = 1;
  656. this._lastBorderTime = Date.now();
  657. this._borders.minX = buf.readDoubleLE(offset);
  658. offset += 8;
  659. this._borders.minY = buf.readDoubleLE(offset);
  660. offset += 8;
  661. this._borders.maxX = buf.readDoubleLE(offset);
  662. offset += 8;
  663. this._borders.maxY = buf.readDoubleLE(offset);
  664. if (this._borders.maxX - this._borders.minX > 14E3) {
  665. this._offsetX = (this._borders.maxX + this._borders.minX) / 2;
  666. }
  667. if (this._borders.maxY - this._borders.minY > 14E3) {
  668. this._offsetY = (this._borders.maxY + this._borders.minY) / 2;
  669. }
  670. }
  671.  
  672. handleCells(buf) {
  673. try {
  674. let offset = 1;
  675. let eatQueueLength = buf.readUInt16LE(offset);
  676. offset += 2;
  677. for (let i = 0; i < eatQueueLength; i++) {
  678. let eater = buf.readUInt32LE(offset);
  679. offset += 4;
  680. let victim = buf.readUInt32LE(offset);
  681. offset += 4;
  682. if (this._WorldCells[victim]) delete this._WorldCells[victim];
  683. }
  684. while (true) {
  685. let cell = new Cell();
  686. cell.id = buf.readUInt32LE(offset);
  687. offset += 4;
  688. if (cell.id == 0) break;
  689. cell.xPos = buf.readInt32LE(offset);
  690. offset += 4;
  691. cell.yPos = buf.readInt32LE(offset);
  692. offset += 4;
  693. cell.size = buf.readUInt16LE(offset);
  694. offset += 2;
  695. let flags = buf.readUInt8(offset++);
  696. let flags2 = 0;
  697. if (flags & 128) flags2 = buf.readUInt8(offset++);
  698. if (flags & 1) cell.isVirus = true;
  699. if (flags & 2) offset += 3;
  700. if (flags & 4)
  701. while (buf.readInt8(offset++) !== 0) {}
  702. if (flags & 8)
  703. while (buf.readInt8(offset++) !== 0) {}
  704. if (flags2 & 4) offset += 4;
  705. if (flags2 & 1) cell.isFood = true;
  706. this._WorldCells[cell.id] = cell;
  707. }
  708. let removeQueueLength = buf.readUInt16LE(offset);
  709. offset += 2;
  710. for (let i = 0; i < removeQueueLength; i++) {
  711. let removeID = buf.readUInt32LE(offset);
  712. offset += 4;
  713. if (this._WorldCells[removeID]) delete this._WorldCells[removeID];
  714. }
  715. } catch (e) {};
  716. }
  717.  
  718. handleBotAI(x, y) {
  719. let bX = 0;
  720. let bY = 0;
  721. let bC = 0;
  722. let bS = 0;
  723.  
  724. for (let i in this._MyWorldCell_IDS) {
  725. if (this._WorldCells.hasOwnProperty(this._MyWorldCell_IDS[i])) {
  726. let gN = this._WorldCells[this._MyWorldCell_IDS[i]];
  727. bX += gN.xPos;
  728. bY += gN.yPos;
  729. bS += gN.size;
  730. bC++;
  731. }
  732. }
  733.  
  734. bX /= bC;
  735. bY /= bC;
  736.  
  737. let botConfig = {
  738. bX: bX,
  739. bY: bY,
  740. bS: bS,
  741. bC: bC
  742. }
  743.  
  744. if (botConfig) {
  745. if (!this._onceSplit) {
  746. if(this._switchMove) {
  747. if (!botConfig.bX && !botConfig.bY) {
  748. return;
  749. } else {
  750. let nX = null;
  751. let nY = null;
  752. let random = Math.random();
  753. if(random >= 0.2) {
  754. nX = botConfig.bX + Math.floor(Math.random() * (-450) + (450) - (450));
  755. nY = botConfig.bY - Math.floor(Math.random() * (-450) + (450) - (450));
  756. } else if(random >= 0.4) {
  757. nX = botConfig.bX - Math.floor(Math.random() * (-450) + (450) - (450));
  758. nY = botConfig.bY + Math.floor(Math.random() * (-450) + (450) - (450));
  759. } else if(random >= 0.6) {
  760. nX = botConfig.bX + Math.floor(Math.random() * (450) + (450) - (450));
  761. nY = botConfig.bY - Math.floor(Math.random() * (450) + (450) - (450));
  762. } else if(random >= 0.8) {
  763. nX = botConfig.bX - Math.floor(Math.random() * (450) + (450) - (450));
  764. nY = botConfig.bY + Math.floor(Math.random() * (450) + (450) - (450));
  765. } else {
  766. nX = botConfig.bX - Math.floor(Math.random() * (450) + (450) - (450));
  767. nY = botConfig.bY + Math.floor(Math.random() * (-450) + (450) - (450));
  768. }
  769. this.moveTo(nX - this._offsetX, nY - this._offsetY);
  770. }
  771. } else {
  772. if (botConfig.bS < 73) {
  773. this._onceSplit = false;
  774. if (!botConfig.bX && !botConfig.bY) {
  775. return;
  776. } else {
  777. let calcBestPlayerForEat = this.calcBestPlayerForEat(botConfig.bX, botConfig.bY, botConfig.bS);
  778. let bestNode = this.calcBestEatEvent(botConfig.bX, botConfig.bY, botConfig.bS);
  779. if(!calcBestPlayerForEat) {
  780. if (!bestNode.eatEvent) {
  781. this.moveTo(x, y);
  782. return;
  783. } else {
  784. this.moveTo((bestNode.eatEvent.xPos - this._offsetX) + Math.floor(Math.random() * (-35) + (35) - (35)), (bestNode.eatEvent.yPos - this._offsetY) + Math.floor(Math.random() * (-35) + (35) - (35)));
  785. return;
  786. }
  787. } else if(calcBestPlayerForEat) {
  788. if(calcBestPlayerForEat.eatEvent) {
  789. if(calcBestPlayerForEat.eatEvent.xPos && calcBestPlayerForEat.eatEvent.yPos) {
  790. this.moveTo((calcBestPlayerForEat.eatEvent.xPos - this._offsetX), (calcBestPlayerForEat.eatEvent.yPos - this._offsetY));
  791. if(this._splitOnPlayer.cellID != calcBestPlayerForEat.eatEvent.id) {
  792. this._splitOnPlayer.cellID = calcBestPlayerForEat.eatEvent.id;
  793. console.log(this.id, "detect player for eat! bot mass - ", botConfig.bS, "player mass", calcBestPlayerForEat.eatEvent.size, "last cell id", this._splitOnPlayer.cellID, "new cell id", calcBestPlayerForEat.eatEvent.id);
  794. this.send(Buffer.from([17]), true);
  795. };
  796. return;
  797. } else {
  798. if (bestNode.eatEvent) {
  799. if(bestNode.eatEvent.xPos && bestNode.eatEvent.yPos) {
  800. this.moveTo((bestNode.eatEvent.xPos - this._offsetX) + Math.floor(Math.random() * (-35) + (35) - (35)), (bestNode.eatEvent.yPos - this._offsetY) + Math.floor(Math.random() * (-35) + (35) - (35)));
  801. return;
  802. } else {
  803. this.moveTo(x + Math.floor(Math.random() * (-35) + (35) - (35)), y + Math.floor(Math.random() * (-35) + (35) - (35)));
  804. }
  805. }
  806. }
  807. } else {
  808. if (bestNode.eatEvent) {
  809. if(bestNode.eatEvent.xPos && bestNode.eatEvent.yPos) {
  810. this.moveTo((bestNode.eatEvent.xPos - this._offsetX) + Math.floor(Math.random() * (-35) + (35) - (35)), (bestNode.eatEvent.yPos - this._offsetY) + Math.floor(Math.random() * (-35) + (35) - (35)));
  811. return;
  812. } else {
  813. this.moveTo(x + Math.floor(Math.random() * (-35) + (35) - (35)), y + Math.floor(Math.random() * (-35) + (35) - (35)));
  814. }
  815. }
  816. }
  817. }
  818. }
  819. } else {
  820. this.moveTo(x + Math.floor(Math.random() * (-35) + (35) - (35)), y + Math.floor(Math.random() * (-35) + (35) - (35)));
  821. if (!this._onceSplit) {
  822. this._onceSplit = true;
  823. return;
  824. }
  825. }
  826. }
  827. } else if (this._onceSplit) {
  828. this.moveTo(x, y);
  829. return;
  830. }
  831. }
  832. }
  833.  
  834.  
  835. calcBestPlayerForEat(bX, bY, bS) {
  836. let bestDistance = 10000.0;
  837. let eatEvent = null;
  838. Object.keys(this._WorldCells).forEach(key => {
  839. let node = this._WorldCells[key];
  840. if(node.isFood == false && node.isVirus == false) {
  841. if (node.size < ((bS / 2) * 0.75)) {
  842. let dist = this.calcDist(bX, bY, node.xPos, node.yPos);
  843. if (dist < bestDistance) {
  844. bestDistance = dist;
  845. eatEvent = node;
  846. }
  847. }
  848. }
  849. });
  850. return {
  851. bestDistance: bestDistance,
  852. eatEvent: eatEvent
  853. }
  854. }
  855.  
  856.  
  857. calcBestEatEvent(bX, bY, bS) {
  858. let bestDistance = 10000.0;
  859. let eatEvent = null;
  860. Object.keys(this._WorldCells).forEach(key => {
  861. let node = this._WorldCells[key];
  862. if (node.isFood) {
  863. if (node.size < bS * 0.75) {
  864. let dist = this.calcDist(bX, bY, node.xPos, node.yPos);
  865. if (dist < bestDistance) {
  866. bestDistance = dist;
  867. eatEvent = node;
  868. setTimeout(function() {
  869. if (this._WorldCells[eatEvent.id]) {
  870. delete this._WorldCells[eatEvent.id];
  871. return;
  872. } else {
  873. return;
  874. }
  875. }.bind(this), 3000);
  876. }
  877. }
  878. }
  879. });
  880. return {
  881. bestDistance: bestDistance,
  882. eatEvent: eatEvent
  883. }
  884. }
  885.  
  886. calcDist(botX, botY, nodeX, nodeY) {
  887. let dist = null;
  888. dist = Math.abs(nodeX - botX) + Math.abs(nodeY - botY);
  889. return dist;
  890. }
  891.  
  892. split() {
  893. if (!this._onceSplit) return;
  894. this.send(Buffer.from([17]), true);
  895. }
  896.  
  897. eject() {
  898. if (!this._onceSplit) return;
  899. this.send(Buffer.from([21]), true);
  900. }
  901.  
  902. spawn() {
  903. let newbotNick = names[Math.floor(Math.random() * names.length)];
  904. let buf = new Buffer.alloc(2 + Buffer.byteLength(newbotNick));
  905. buf.writeUInt8(0, 0);
  906. buf.write(newbotNick, 1);
  907. buf.writeUInt8(0, buf.length - 1);
  908. this.send(buf, true);
  909. }
  910.  
  911. onclose(e) {
  912. this._lastBorderTime = Date.now();
  913. this._borders = Object.assign(defaultBorders);
  914. this._encryptionKey = eKey;
  915. this._decryptionKey = 0;
  916. this._offsetX = 0;
  917. this._offsetY = 0;
  918. this._unuseableProxy = false;
  919. this._spawned = false;
  920. this._ws = null;
  921. if(this._switchMoveInt != null) {
  922. clearInterval(this._switchMoveInt);
  923. this._switchMoveInt = null;
  924. }
  925. this._fSpawn = false;
  926. this._sendFBdata = false;
  927. if(this.auth_token) global.facebookManger.returnToken(this.auth_token);
  928. this.auth_token = null;
  929. if (this.reconnecting) setTimeout(this.connect.bind(this, 50));
  930. }
  931.  
  932. onerror(e) {
  933. this._lastBorderTime = Date.now();
  934. this._borders = Object.assign(defaultBorders);
  935. this._encryptionKey = eKey;
  936. this._decryptionKey = 0;
  937. this._offsetX = 0;
  938. this._offsetY = 0;
  939. this._unuseableProxy = false;
  940. this._spawned = false;
  941. this._ws = null;
  942. this._sendFBdata = false;
  943. }
  944.  
  945. moveTo(xPos, yPos) {
  946. if (!this._ws || this._ws.readyState != 1) return;
  947. try {
  948. let buf = new Buffer.alloc(13);
  949. buf.writeUInt8(16, 0);
  950. buf.writeInt32LE(xPos + this._offsetX, 1);
  951. buf.writeInt32LE(yPos + this._offsetY, 5);
  952. buf.writeInt32LE(this._decryptionKey, 9);
  953. this.send(buf, true);
  954. } catch (e) {
  955.  
  956. }
  957. }
  958.  
  959. send(buf, runEncryption, fb) {
  960. if (!this._ws || this._ws.readyState != 1) return;
  961. if (runEncryption) {
  962. buf = this.xorBuffer(buf, this._encryptionKey);
  963. this._encryptionKey = this.rotateKey(this._encryptionKey);
  964. }
  965. this._ws.send(buf);
  966. }
  967.  
  968. xorBuffer(buf, xorKey) {
  969. try {
  970. const newBuf = new Buffer.alloc(buf.byteLength);
  971. for (let i = 0; i < buf.byteLength; i++) newBuf.writeUInt8(buf.readUInt8(i) ^ xorKey >>> i % 4 * 8 & 255, i);
  972. return newBuf;
  973. } catch (e) {}
  974. }
  975.  
  976. rotateKey(key) {
  977. key = Math.imul(key, eKey) >> 0;
  978. key = (Math.imul(key >>> 24 ^ key, eKey) >> 0) ^ 114296087;
  979. key = Math.imul(key >>> 13 ^ key, eKey) >> 0;
  980. return key >>> 15 ^ key;
  981. }
  982. }
  983.  
  984. class Cell {
  985. constructor() {
  986. this.isVirus = false;
  987. this.isFood = false;
  988. this.xPos = 0;
  989. this.yPos = 0;
  990. this.size = 0;
  991. this.id = 0;
  992. }
  993. }
  994.  
  995. module.exports = user;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement