MyBot Parallel Connections

MyBot Pixel Place Parallel Connections

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/479132/1275800/MyBot%20Parallel%20Connections.js

  1. // ==UserScript==
  2. // @name MyBot Parallel Connections
  3. // @description MyBot Pixel Place Parallel Connections
  4. // @version 1.6.2
  5. // @author SamaelWired
  6. // @namespace https://gf.qytechs.cn/users/976572
  7. // @match https://pixelplace.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
  9. // @license MIT
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13. (() => {
  14. const MyBot = window.MyBot || { modules: {} };
  15. window.MyBot = MyBot;
  16. if ('Connect' in MyBot.modules) return;
  17.  
  18. const pongAlive = () => {
  19. const { random } = Math;
  20. const word = 'gmbozcfxta';
  21.  
  22. function hash(size) {
  23. const arr = [];
  24. const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  25. for (var i = 0; i < size; i++) arr.push(str[random() * str.length | 0]);
  26. return arr.join('');
  27. }
  28.  
  29. function hash2(size) {
  30. const arr = [];
  31. const str = "gmbonjklezcfxtaGMBONJKLEZCFXTA";
  32. for (var i = 0; i < size; i++) arr.push(str[random() * str.length | 0]);
  33. return arr.join('');
  34. }
  35.  
  36. let result = '';
  37. const seed = (((new Date().getTime() / 1e3 | 0) + 1678) + '').split('');
  38. const arr = [hash(5), hash(7), hash2(3), hash(8), hash2(6), hash(3), hash(6), hash2(4), hash(7), hash(6)];
  39. for (const i in seed) {
  40. result += arr[i];
  41. result += !(random() * 2 | 0) ? word[+seed[i]].toUpperCase() : word[+seed[i]];
  42. }
  43. result += '0=';
  44.  
  45. return `42["pong.alive","${result}"]`;
  46. };
  47.  
  48. const module = {
  49. bots: [],
  50. settings: new Proxy(JSON.parse(localStorage.getItem('settings') || '{}'), {
  51. get(target, key) {
  52. return target[key];
  53. },
  54. set(target, key, value) {
  55. target[key] = value;
  56. localStorage.setItem('settings', JSON.stringify(target));
  57. return true;
  58. },
  59. remove(target, key) {
  60. delete target[key];
  61. localStorage.setItem('settings', JSON.stringify(target));
  62. return true;
  63. }
  64. })
  65. };
  66. module.args = {};
  67. module.config = ({ timer }) => Object.assign(module.args, { timer });
  68.  
  69. const { settings } = module;
  70. Object.assign(module, {
  71. async show() {
  72. return JSON.stringify([
  73. (await cookieStore.get('authId')).value,
  74. (await cookieStore.get('authToken')).value,
  75. (await cookieStore.get('authKey')).value
  76. ]);
  77. },
  78. async add(username, scheme) {
  79. settings.userlist[username] = typeof scheme == 'string' ? JSON.parse(scheme) : scheme;
  80. return true;
  81. },
  82. async remove(username) {
  83. delete settings.userlist[username];
  84. return true;
  85. },
  86.  
  87. async save() {
  88. settings.current = {
  89. authId: (await cookieStore.get('authId')).value,
  90. authToken: (await cookieStore.get('authToken')).value,
  91. authKey: (await cookieStore.get('authKey')).value
  92. };
  93. },
  94. async load(scheme = null) {
  95. await cookieStore.set('authId', scheme ? scheme[0] : settings.current.authId);
  96. await cookieStore.set('authToken', scheme ? scheme[1] : settings.current.authToken);
  97. await cookieStore.set('authKey', scheme ? scheme[2] : settings.current.authKey);
  98. },
  99.  
  100. async join(username, server) {
  101. if (!settings.userlist[username]) return null;
  102. const [id, token, key] = settings.userlist[username];
  103.  
  104. await module.save();
  105. await cookieStore.set('authId', id);
  106. await cookieStore.set('authToken', token);
  107. await cookieStore.set('authKey', key);
  108.  
  109. await fetch(`https://pixelplace.io/api/get-painting.php?id=${server}&connected=1`);
  110. if (!(await cookieStore.get('authToken'))) {
  111. console.log(
  112. username,
  113. "is banned or it has wrong data, please remove this account using MyBot.remove('",
  114. username,
  115. "');"
  116. );
  117. await module.load();
  118. return null;
  119. }
  120.  
  121. settings.userlist[username] = [
  122. (await cookieStore.get('authId')).value,
  123. (await cookieStore.get('authToken')).value,
  124. (await cookieStore.get('authKey')).value
  125. ];
  126. await module.load();
  127.  
  128. return settings.userlist[username];
  129. },
  130.  
  131. async connect(username, boardId) {
  132. const result = await module.join(username, boardId);
  133. if (!result) return null;
  134. if (module.bots.find(ws => ws.username == username)) return null;
  135. const [authId, authToken, authKey] = result;
  136.  
  137. const restart = () => {
  138. const { timer } = module.args;
  139. const user = new WebSocket('wss://pixelplace.io/socket.io/?EIO=3&transport=websocket');
  140. user.username = username;
  141. user.serverId = boardId;
  142. user.onmessage = ({ data }) => {
  143. const [code, msg] = data.split(/(?<=^\d+)(?=[^\d])/);
  144. if (code == '40') user.send('42' + JSON.stringify(
  145. ["init", { authKey, authToken, authId, boardId }]
  146. ));
  147.  
  148. const message = JSON.parse(msg || '[]');
  149. if (message.pingInterval) user.ping = timer.setInterval(() => user.send('2'), message.pingInterval);
  150.  
  151. if (!message.length) return arguments;
  152. const [event, json] = message;
  153. if (event == 'throw.error' && ![3].includes(json)) {
  154. user.kick = true;
  155. user.close();
  156. }
  157. if (event == 'canvas.alert' && json.includes('Your account')) {
  158. console.log('Banned, reason: ', json);
  159. user.kick = true;
  160. user.close();
  161. }
  162. if (event == 'ping.alive') user.send(pongAlive());
  163. if (event == 'canvas') {
  164. user.ready = true;
  165. console.log(username, 'bot connected');
  166. }
  167. if (event == 'p') user.count = MyBot.config.packetCount;
  168. };
  169. user.onclose = async () => {
  170. timer.clearInterval(user.ping);
  171. module.bots.splice(module.bots.indexOf(user), 1);
  172. if (!user.kick) {
  173. console.log(username, 'bot restarting');
  174. restart();
  175. } else {
  176. console.log(username, 'bot disconnected');
  177. }
  178. };
  179. user.set = (x, y, p) => user.send(`42["p",[${x},${y},${p},1]]`);
  180. module.bots.push(user);
  181.  
  182. return user;
  183. };
  184. return restart();
  185. },
  186.  
  187. async connectAll(serverId) {
  188. const names = Object.keys(settings.userlist);
  189. const arr = [];
  190.  
  191. let n = 0;
  192. for (let i = 0; i < names.length; i++) {
  193. let ws = null;
  194.  
  195. try {
  196. ws = await module.connect(names[i], serverId);
  197. } catch (e) {
  198. ws = null;
  199. }
  200.  
  201. if (!ws) {
  202. n++;
  203. continue;
  204. }
  205.  
  206. arr[i - n] = ws;
  207. ws.addEventListener('close', e => arr.splice(arr.indexOf(ws), 1));
  208. }
  209.  
  210. console.log(names.length - n, 'bots connected');
  211. return arr;
  212. },
  213.  
  214. async disconnect(...usernames) {
  215. usernames = usernames.flat();
  216. module.bots.filter(Boolean).map(ws => {
  217. if (!ws || !ws.close) return;
  218. ws.ignore = true;
  219. ws.kick = true;
  220. if (!usernames.length) return ws.close();
  221. if (usernames.includes(ws.username)) return ws.close();
  222. });
  223. }
  224. });
  225.  
  226. if (!settings.userlist) settings.userlist = {};
  227.  
  228. MyBot.connect = async (username) => await module.connect(username, MyBot.serverId);
  229. MyBot.connectAll = async () => await module.connectAll(MyBot.serverId);
  230. MyBot.disconnect = module.disconnect;
  231. MyBot.link = async (username) => await module.add(username, JSON.parse(await module.show()));
  232. MyBot.show = module.show;
  233. MyBot.add = module.add;
  234. MyBot.remove = module.remove;
  235. Object.defineProperty(MyBot, 'userlist', {
  236. enumerable: true,
  237. configurable: true,
  238. get() {
  239. return settings.userlist;
  240. }
  241. });
  242.  
  243. MyBot.modules.Connect = module;
  244. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址