Advertisement
Guest User

Untitled

a guest
May 25th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.29 KB | None | 0 0
  1. process.on('uncaughtException', function (err) {
  2. console.log(err);
  3. })
  4.  
  5. global.colors = require("colors");
  6.  
  7. global.fs = require("fs");
  8.  
  9. global.ws = require('ws');
  10.  
  11. global.socks = require('socks');
  12.  
  13. global.HTTP = require('https-proxy-agent');
  14.  
  15. global.binaryReader = require("./binaryReader.js");
  16.  
  17. global.phantom = require("phantom");
  18.  
  19. global.phantomServer = require('./phantomServer.js');
  20.  
  21. global.json_corrector = require("json-pretty");
  22.  
  23. global.request = require("request");
  24.  
  25. global.facebookManger = require("./facebookManager.js");
  26.  
  27. global.writer = require("./BinaryWriter.js");
  28.  
  29. const userJS = require("./user.js");
  30.  
  31. global.database = global.fs.readFileSync("./database.json", "utf-8");
  32.  
  33. let conUsers = 0;
  34.  
  35. global.users = [];
  36.  
  37. global.protocolVersion = 20;
  38.  
  39. global.protocolKey = 30410;
  40.  
  41. global.phantomServer.onReady = () => {
  42.  
  43. process.stdout.write('\x1B[2J\x1B[0f');
  44.  
  45. console.log(`[PhantomJS]`.green, `Patching ready!`.yellow);
  46.  
  47. global.phantomServer.onProtocolVersion = pVersion => {
  48.  
  49. global.protocolVersion = pVersion;
  50. console.log(`[PhantomJS]`.green, `Agar.io protocol version ${global.protocolVersion}`.yellow);
  51.  
  52. global.phantomServer.on255 = pKey => {
  53.  
  54. global.protocolKey = Buffer.from(pKey).readUInt32LE(1);
  55. console.log(`[PhantomJS]`.green, `Agar.io protocol key ${global.protocolKey}`.yellow);
  56.  
  57. global.facebookManger.getCheckAccs(undefined, function() {
  58.  
  59. console.log(`\n[FaceBookManager]`.green, `Account checking done ${global.facebookManger.activeAccounts.length}`.yellow);
  60.  
  61. const wss = new global.ws.Server({
  62. port : 8081
  63. });
  64.  
  65. wss.on("connection", function(ws, req) {
  66. conUsers++;
  67. if(ws.upgradeReq == null && req != null) ws.upgradeReq = req;
  68. if(ws.upgradeReq == null) throw Error("WTF IS THIS");
  69.  
  70. ws.getIP = ws.upgradeReq.connection.remoteAddress;
  71. ws.getUUID = null;
  72. ws.auth = false;
  73.  
  74. ws.sendBuf = function(buf) {
  75. if(ws && ws.readyState == 1) ws.send(buf);
  76. }
  77.  
  78. for(let i = 0; i < global.users.length; i++) {
  79. if(global.users[i]._IP == ws.getIP) {
  80. ws.sendBuf(Buffer.from([0, 2])), ws.close();
  81. console.log("[ServerJS]".green, "IP Limited".yellow, ws.getIP);
  82. }
  83. }
  84.  
  85. ws.on("message", (msg) => {
  86. let buf = new global.binaryReader(msg);
  87. let opcode = buf.readUInt8();
  88. switch(opcode) {
  89. case 0: {
  90. ws.sendBuf(Buffer.from([0, 3]));
  91. let UUID = buf.readStringZeroUtf8();
  92. if(!ws.auth) {
  93. global.database = global.fs.readFileSync("./database.json", "utf-8");
  94. let read_database = JSON.parse(global.database);
  95. let user = {}
  96. for(let i = 0; i < read_database.length; i++) {
  97. if(read_database[i].UUID == UUID) {
  98. ws.auth = true;
  99. ws.sendBuf(Buffer.from([0, 4]));
  100. user.UUID = read_database[i].UUID;
  101. user.COINS = read_database[i].coins;
  102. user.IP = ws.getIP;
  103. }
  104. }
  105. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  106. console.log("[ServerJS]".green, "Authorizate user".yellow, ws.getIP);
  107. global.users.push(new userJS(user.IP, user.UUID, user.COINS));
  108. ws.getUUID = user.UUID;
  109. } else if(ws.auth) {
  110. console.log("[ServerJS]".green, "Authorizate user".yellow, ws.getIP);
  111. global.users.push(new userJS(ws.getIP, UUID, 5));
  112. ws.getUUID = UUID;
  113. ws.sendBuf(Buffer.from([0, 4]));
  114. }
  115. } break;
  116. case 1: { // bot mode change
  117. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  118. } break;
  119. case 2: {
  120. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  121. let agarServer = buf.readStringZeroUtf8();
  122. //buf.readStringZeroUnicode();
  123. let botAmount = 1000; // 1000 BOTS LIMIT OR SERVER DIE SO FAST !!!!!!!!!
  124. if(!agarServer.split("?")[1]) { //.split("?")[0]
  125. ws.sendBuf(Buffer.from([0, 10]));
  126. break;
  127. }
  128. for(let i = 0; i < global.users.length; i++) {
  129. if(ws.auth && global.users[i]._UUID == ws.getUUID && global.users[i]._IP == ws.getIP) {
  130. global.users[i].startBots(botAmount, agarServer.split("?")[0]);//
  131. ws.sendBuf(Buffer.from([0, 7]));
  132. console.log("[ServerJS]".green, "Start bots".yellow, ws.getIP);
  133. }
  134. }
  135.  
  136. } break;
  137. case 3: {
  138. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  139.  
  140. for(let i = 0; i < global.users.length; i++) {
  141. if(ws.auth && global.users[i]._UUID == ws.getUUID && global.users[i]._IP == ws.getIP) {
  142. global.users[i].stopBots();
  143. ws.sendBuf(Buffer.from([0, 4]));
  144. console.log("[ServerJS]".green, "Stop bots".yellow, ws.getIP);
  145. }
  146. }
  147.  
  148. } break;
  149. case 4: {
  150. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  151. let xPos = buf.readInt32();
  152. let yPos = buf.readInt32();
  153.  
  154. for(let i = 0; i < global.users.length; i++) {
  155. if(ws.auth && global.users[i]._UUID == ws.getUUID && global.users[i]._IP == ws.getIP) {
  156. global.users[i].moveBots(xPos, yPos);
  157. let information = global.users[i].getInformation();
  158. let buffer = new Buffer.alloc(21);
  159. buffer.writeUInt8(1, 0);
  160. buffer.writeUInt16LE(0, 1);
  161. buffer.writeUInt16LE(information.sB, 3);
  162. buffer.writeUInt16LE(information.cB, 5);
  163. buffer.writeDoubleLE(information.uC, 7);
  164. ws.sendBuf(buffer);
  165. }
  166. }
  167.  
  168. } break;
  169. case 5: {
  170. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  171.  
  172. for(let i = 0; i < global.users.length; i++) {
  173. if(ws.auth && global.users[i]._UUID == ws.getUUID && global.users[i]._IP == ws.getIP) {
  174. global.users[i].splitBots();
  175. }
  176. }
  177.  
  178. } break;
  179. case 6: {
  180. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  181.  
  182. for(let i = 0; i < global.users.length; i++) {
  183. if(ws.auth && global.users[i]._UUID == ws.getUUID && global.users[i]._IP == ws.getIP) {
  184. global.users[i].ejectBots();
  185. }
  186. }
  187.  
  188. } break;
  189. default: {
  190. if(!ws.auth) return ws.sendBuf(Buffer.from([0, 8])), ws.close();
  191. } break;
  192. }
  193. });
  194.  
  195.  
  196. ws.on("close", () => {
  197. conUsers--;
  198. if(!ws.auth) return;
  199. for(let i = 0; i < global.users.length; i++) {
  200. if(ws.auth && global.users[i]._UUID == ws.getUUID && global.users[i]._IP == ws.getIP) {
  201. global.users[i].stopBots();
  202. global.users.splice(i, 1);
  203. console.log("[ServerJS]".green, "unauthorizate user (disconnect)".yellow, ws.getIP);
  204. }
  205. }
  206. });
  207.  
  208. ws.on("error", (e) => {
  209. console.log(e);
  210. });
  211. });
  212. });
  213. };
  214. };
  215. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement