Advertisement
Guest User

2B2T Sign Patch (BadPuns)

a guest
Feb 27th, 2019
2,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Username = "Email here, must include quotes"
  2. const Password = "Password here, must include quotes"
  3. const PlayerName = "MC Username here, must include quotes"
  4.  
  5. /*
  6.  
  7. 2B2T NodeJS proxy server
  8.  
  9. Developed by BadPuns
  10. Built upon rom1504's 'minecraft-protocol'
  11.  
  12. Below is the code to set up a minecraft server on localhost:25566 that will forward traffic onto a destination server.
  13. This performs a MITM-like role, where one can log the packets being sent between the client and the server.
  14.  
  15. I added my own functionality to the proxy to modify packets en-route to the destination (client or server),
  16. filter out all packets of a certain type, and several other packet-based tasks within Minecraft.  This is a stripped down version of my
  17. original proxy, which includes a lot of teleportation, item storage exploits, and chat features.  This program includes:
  18. - Block-entity remover to escape sign-banned chunks (toggle on/off with .removesigns)
  19. - Packet manager (.filter)
  20. - Chat formatter (.say [message], use % for color/format numbers)
  21. - Client-sided creative mode (.forcecreative)
  22. - Gamestate manager (.state [arg] [arg (optional)]) https://wiki.vg/Protocol#Change_Game_State
  23.  
  24. Before attempting to use this client, you must have NodeJS installed on your system.  You can do so at https://nodejs.org/en/
  25.  
  26. Once node is installed, you will need to install the dependancies for this proxy.  Here are the packages you'll need to install:
  27. - Minecraft protocol
  28. - readline
  29. - util
  30. - keypress
  31.  
  32. You can read more about each package on https://www.npmjs.com/
  33.  
  34. Detailed installation instructions below:
  35.  
  36. 1. Create a new folder on your desktop
  37. 2. Open command prompt and cd into that folder.  If you don't know how to do this you shouldn't own a computer.
  38. 3. Once in the correct folder/directory, you'll need to install the packages for this project.  Simply type the following into the prompt window
  39.  - "npm install [package]" (without quotes)
  40.  
  41.  Perform this command for each of the required packages listed above, replacing "[package]" with the name of the required package.
  42.  
  43. 4.  Next you'll want to create a text file.  Name it "proxy.js"
  44. 5.  Copy all the code from this file into that file, and save it.  Make sure it's actually saved as a .js file, and not "proxy.js.txt"
  45. 6.  You're almost done.  Next you're going to want to create the launcher for the proxy.  Create a new text file, and simply name it "start.txt"
  46. 7.  You're going to want to copy the following text and paste it into the file.
  47.  
  48. node proxy.js --dump-all -x keep_alive -x update_time -x block_break_animation -x advancements -x animation -x spawn_entity_living -x playerlist_header -x scoreboard_display_objective -x scoreboard_objective -x entity_update_attributes -x sound_effect -x map_chunk -x teams -x entity_equipment -x scoreboard_score -x world_particles -x entity_velocity -x rel_entity_move -x entity_look -x entity_move_look -x entity_teleport -x player_info -x entity_metadata -x entity_status -x entity_head_rotation 2b2t.org 1.12.2
  49. pause press [enter]
  50.  
  51. each entry with a -x in front of it shows a packet to exclude from the logger, because it's either spammy or useless.  Modify this as you please.
  52.  
  53. 8. Save the file with the text above as "start.bat", making sure it's not "start.bat.txt"
  54. 9. Run the .bat file, and it should open up a terminal.  If you don't get an error, your proxy should be up and running.
  55. 10. To connect to the proxy, add "localhost:25566" to your server list.  The connection will likely be slower than you're used to.
  56. 11. If you haven't input your login information into the variables above, you will get an error.  Make sure it's entered correctly if you're getting an invalid login error.
  57.  
  58. [FIXING THE SIGN BAN]
  59. 1. As soon as you log in, no signs should render.  If you get close to one, you'll still see the sign hitbox show up.  This is because the block is still there, but it is just a block without data.  It doesn't contain any more or less data than a cobblestone block.  Walk away from the signs, and once you're safe you can type ".removesigns" again to re-enable block entities.
  60.  
  61. 2. If you're still experiencing kicks, you're going to want to try the global chunk filter.  This will prevent all chunks from rendering.  Type ".filter add client map_chunk" to stop all chunks from being rendered.  From here, you will want to /kill.
  62.  
  63. */
  64.  
  65. const mc = require('minecraft-protocol')
  66. const readline = require('readline')
  67. const util = require('util')
  68. var keypress = require('keypress');
  69. const now = new Date();
  70. var prefix = "."
  71.  
  72. var chatForced = ".filter add client map_chunk"
  73. var AccountEntity;
  74. var teleID = 0
  75. var pearlIntercept = false
  76. var targetClient;
  77. var clientPosition;
  78. var targetPosition = {
  79.   x: 0,
  80.   y: 0,
  81.   z: 0
  82. }
  83. var onlineServer = true
  84. var loggingPackets = true
  85. var offlineUser = "Pablo" //Only used for offline servers
  86. var removeBlockEntities = true
  87.  
  88. var clientPackets = [
  89.       "spawn_entity_experience_orb",
  90.       "spawn_entity_weather",
  91.       "spawn_entity_living",
  92.       "spawn_entity_painting",
  93.       "named_entity_spawn",
  94.       "animation",
  95.       "statistics",
  96.       "advancements",
  97.       "block_break_animation",
  98.       "tile_entity_data",
  99.       "block_action",
  100.       "block_change",
  101.       "boss_bar",
  102.       "difficulty",
  103.       "tab_complete",
  104.       "chat",
  105.       "multi_block_change",
  106.       "transaction",
  107.       "close_window",
  108.       "open_window",
  109.       "window_items",
  110.       "craft_progress_bar",
  111.       "set_slot",
  112.       "set_cooldown",
  113.       "custom_payload",
  114.       "named_sound_effect",
  115.       "kick_disconnect",
  116.       "entity_status",
  117.       "explosion",
  118.       "unload_chunk",
  119.       "game_state_change",
  120.       "keep_alive",
  121.       "map_chunk",
  122.       "world_event",
  123.       "world_particles",
  124.       "login",
  125.       "map",
  126.       "rel_entity_move",
  127.       "entity_move_look",
  128.       "entity_look",
  129.       "entity",
  130.       "vehicle_move",
  131.       "open_sign_entity",
  132.       "craft_recipe_response",
  133.       "abilities",
  134.       "combat_event",
  135.       "player_info",
  136.       "position",
  137.       "bed",
  138.       "unlock_recipes",
  139.       "entity_destroy",
  140.       "remove_entity_effect",
  141.       "resource_pack_send",
  142.       "respawn",
  143.       "entity_head_rotation",
  144.       "world_border",
  145.       "camera",
  146.       "held_item_slot",
  147.       "scoreboard_display_objective",
  148.       "entity_metadata",
  149.       "attach_entity",
  150.       "entity_velocity",
  151.       "entity_equipment",
  152.       "experience",
  153.       "update_health",
  154.       "scoreboard_objective",
  155.       "set_passengers",
  156.       "teams",
  157.       "scoreboard_score",
  158.       "spawn_position",
  159.       "update_time",
  160.       "title",
  161.       "sound_effect",
  162.       "playerlist_header",
  163.       "collect",
  164.       "entity_teleport",
  165.       "entity_update_attributes",
  166.       "entity_effect",
  167.       "select_advancement_tab",
  168.       "spawn_entity",
  169.       "packet"
  170. ]
  171. var serverPackets = [
  172.         "teleport_confirm",
  173.         "tab_complete",
  174.         "chat",
  175.         "client_command",
  176.         "settings",
  177.         "transaction",
  178.         "enchant_item",
  179.         "window_click",
  180.         "close_window",
  181.         "custom_payload",
  182.         "use_entity",
  183.         "keep_alive",
  184.         "position",
  185.         "position_look",
  186.         "look",
  187.         "flying",
  188.         "vehicle_move",
  189.         "steer_boat",
  190.         "craft_recipe_request",
  191.         "abilities",
  192.         "block_dig",
  193.         "entity_action",
  194.         "steer_vehicle",
  195.         "crafting_book_data",
  196.         "resource_pack_receive",
  197.         "held_item_slot",
  198.         "set_creative_slot",
  199.         "update_sign",
  200.         "arm_animation",
  201.         "spectate",
  202.         "block_place",
  203.         "use_item",
  204.         "advancement_tab",
  205.         "packet"
  206. ]
  207. var clientFiltered = []
  208. var serverFiltered = []
  209.  
  210. const states = mc.states
  211. function printHelpAndExit (exitCode) {
  212.   console.log('usage: node proxy.js [<options>...] <target_srv> <version>')
  213.   console.log('options:')
  214.   console.log('  --dump name')
  215.   console.log('    print to stdout messages with the specified name.')
  216.   console.log('  --dump-all')
  217.   console.log('    print to stdout all messages, except those specified with -x.')
  218.   console.log('  -x name')
  219.   console.log('    do not print messages with this name.')
  220.   console.log('  name')
  221.   console.log('    a packet name as defined in protocol.json')
  222.   console.log('examples:')
  223.   console.log('  node proxy.js --dump-all -x keep_alive -x update_time -x entity_velocity -x rel_entity_move -x entity_look -x entity_move_look -x entity_teleport -x entity_head_rotation -x position localhost 1.8')
  224.   console.log('    print all messages except for some of the most prolific.')
  225.   console.log('  node examples/proxy.js --dump open_window --dump close_window --dump set_slot --dump window_items --dump craft_progress_bar --dump transaction --dump close_window --dump window_click --dump set_creative_slot --dump enchant_item localhost 1.8')
  226.   console.log('    print messages relating to inventory management.')
  227.  
  228.   process.exit(exitCode)
  229. }
  230.  
  231. if (process.argv.length < 4) {
  232.   console.log('Too few arguments!')
  233.   printHelpAndExit(1)
  234. }
  235.  
  236. process.argv.forEach(function (val) {
  237.   if (val === '-h') {
  238.     printHelpAndExit(0)
  239.   }
  240. })
  241.  
  242. const args = process.argv.slice(2)
  243. let host
  244. let port = 25565
  245. let version
  246.  
  247. let printAllNames = false
  248. const printNameWhitelist = {}
  249. const printNameBlacklist = {};
  250. (function () {
  251.   let i = 0
  252.   for (i = 0; i < args.length; i++) {
  253.     const option = args[i]
  254.     if (!/^-/.test(option)) break
  255.     if (option === '--dump-all') {
  256.       printAllNames = true
  257.       continue
  258.     }
  259.     i++
  260.     const name = args[i]
  261.     if (option === '--dump') {
  262.       printNameWhitelist[name] = 'io'
  263.     } else if (option === '-x') {
  264.       printNameBlacklist[name] = 'io'
  265.     } else {
  266.       printHelpAndExit(1)
  267.     }
  268.   }
  269.   if (!(i + 2 <= args.length && args.length <= i + 4)) printHelpAndExit(1)
  270.   host = args[i++]
  271.   version = args[i++]
  272. })()
  273.  
  274. if (host.indexOf(':') !== -1) {
  275.   port = host.substring(host.indexOf(':') + 1)
  276.   host = host.substring(0, host.indexOf(':'))
  277. }
  278.  
  279. //DEFAULT VIRTUAL SERVER
  280.  
  281. motds = ["§cPacket logging and injection at it's finest", "§c\"No mom I swear I'm not hacking please don't tell the admins\"", "§cNo homo", "§cOh it crashed again", "§cSounds like lag to me", "§cDeveloped by BadPuns. Don't take credit fags."]
  282. motdToUse = Math.floor(Math.random() * (+motds.length - +0)) + +0
  283.  
  284. const srv = mc.createServer({
  285.   'online-mode': false,
  286.   motd: motds[motdToUse],
  287.   port: 25566,
  288.   keepAlive: false,
  289.   version: version
  290. })
  291.  
  292. srv.on('login', function (client) {
  293.  
  294.  
  295.   keypress(process.stdin);
  296.  
  297.   process.stdin.on('keypress', function (ch, key) {
  298.  
  299.     if(key && key.name == 'p'){
  300.       if(loggingPackets == true){
  301.         loggingPackets = false
  302.         console.log("\x1b[43m" + "Toggled packet logging to false.  Press P to enable." + "\x1b[0m")
  303.       } else {
  304.         loggingPackets = true
  305.         console.log("\x1b[43m" + "Toggled packet logging to true.  Press P to disable." + "\x1b[0m")
  306.       }
  307.     }
  308.  
  309.     if(key && key.name == 'c'){
  310.       targetClient.write('chat', {message: chatForced});
  311.     }
  312.   });
  313.  
  314.   process.stdin.setRawMode(true);
  315.   process.stdin.resume();
  316.  
  317. })
  318.  
  319. srv.on('login', function (client) {
  320.   const addr = client.socket.remoteAddress
  321.   console.log('Incoming connection', '(' + addr + ')')
  322.   let endedClient = false
  323.   let endedTargetClient = false
  324.  
  325.   var loginMsg = {
  326.     translate: 'chat.type.admin',
  327.     "with": ["§3§lProxy", "§7Connected to §c" + host + ":" + port + "\n§7Online server: §c" + onlineServer + "\n§7Account: §c" + PlayerName + "\n§7Removing signs (§62B2T§7): §c" + removeBlockEntities + "\n\n§7For a list of commands, type " + prefix + "help"]
  328.   };
  329.  
  330. setTimeout(function(){
  331.   client.write("chat", { message: JSON.stringify(loginMsg), position: 0 });
  332. }, 1000);
  333.  
  334.   client.on('end', function () {
  335.     endedClient = true
  336.     console.log('Connection closed by client', '(' + addr + ')')
  337.     if (!endedTargetClient) { targetClient.end('§cHey! This is a Christian minecraft server, we don\'t appreciate language!') }
  338.   })
  339.   client.on('error', function (err) {
  340.     endedClient = true
  341.     console.log('Connection error by client', '(' + addr + ')')
  342.     console.log(err.stack)
  343.     if (!endedTargetClient) { targetClient.end('§c*robot noises* Base coordinates successfully exported.') }
  344.   })
  345.   if(onlineServer == false){
  346.       targetClient = mc.createClient({
  347.       host: host,
  348.       port: port,
  349.       username: client.username,
  350.       keepAlive: false,
  351.       version: version
  352.     })
  353.   } else {
  354.       targetClient = mc.createClient({
  355.       host: host,
  356.       port: port,
  357.       username: Username,
  358.       password: Password,
  359.       keepAlive: false,
  360.       version: version
  361.     })
  362.   }
  363.   client.on('packet', function (data, meta) {
  364.     var sendPacket = true
  365.     if (targetClient.state === states.PLAY && meta.state === states.PLAY) {
  366.     //if (targetClient.state && meta.state) {
  367.       if (shouldDump(meta.name, 'o')) {
  368.         if(loggingPackets == true){
  369.           console.log('client->server:',
  370.             client.state + ' ' + meta.name + ' :',
  371.             JSON.stringify(data))
  372.         }
  373.       }
  374.       if(data.message){
  375.         var words = data.message.split(' ');
  376. //Catch all messages that start with "."
  377.         if(data.message.toLowerCase().startsWith(prefix)){
  378.           sendPacket = false
  379.         }
  380.  
  381. //Help Command
  382.         if(data.message.toLowerCase().startsWith(prefix + "help")){
  383.  
  384.           var help = {
  385.             translate: 'chat.type.admin',
  386.             "with": ["§3§lProxy", "§7Help command coming soon.   I'm lazy."]
  387.           };
  388.  
  389.           client.write("chat", { message: JSON.stringify(help), position: 0 });
  390.           sendPacket = false
  391.         }
  392.  
  393. //Packet filter command.  Usage: 0/filter 1[add/remove/clear/list] 2[from:client/server] 3[packetName]
  394.         if(data.message.toLowerCase().startsWith(prefix + "filter")){
  395.           if(words[1]){
  396.  
  397.  
  398.             if(words[1].toLowerCase() == "list"){//SUBCOMMAND FINISHED
  399.               var serverStr = serverFiltered.join("\n§c")
  400.               var clientStr = clientFiltered.join("\n§c")
  401.               if(!serverFiltered[0]){
  402.                 serverStr = "§cThere are no packets currently being filtered from the server."
  403.               }
  404.               if(!clientFiltered[0]){
  405.                 clientStr = "§cThere are no packets currently being filtered from the client."
  406.               }
  407.  
  408.               var c = {
  409.                   translate: 'chat.type.admin',
  410.                   "with": ["§3§lProxy", "§7Packets from the client currently filtered:\n§c" + clientStr]
  411.                 };
  412.               client.write("chat", { message: JSON.stringify(c), position: 0 });
  413.               sendPacket = false
  414.  
  415.               var s = {
  416.                   translate: 'chat.type.admin',
  417.                   "with": ["§3§lProxy", "§7Packets from the server currently filtered:\n§c" + serverStr]
  418.                 };
  419.               client.write("chat", { message: JSON.stringify(s), position: 0 });
  420.               sendPacket = false
  421.             }
  422.  
  423.  
  424.  
  425.             if(words[1].toLowerCase() == "clear"){//SUBCOMMAND FINISHED
  426.               if(words[2]){
  427.                 if(words[2].toLowerCase() == "client"){
  428.                   clientFiltered = []
  429.  
  430.                   var help = {
  431.                       translate: 'chat.type.admin',
  432.                       "with": ["§3§lProxy", "§7All filters on traffic coming from the §cclient §7have been removed."]
  433.                     };
  434.                   client.write("chat", { message: JSON.stringify(help), position: 0 });
  435.                   sendPacket = false
  436.                 }
  437.                 if(words[2].toLowerCase() == "server"){
  438.                   serverFiltered = []
  439.  
  440.                   var help = {
  441.                       translate: 'chat.type.admin',
  442.                       "with": ["§3§lProxy", "§7All filters on traffic coming from the §cserver §7have been removed."]
  443.                     };
  444.                   client.write("chat", { message: JSON.stringify(help), position: 0 });
  445.                   sendPacket = false
  446.                 }
  447.               } else {
  448.                 clientFiltered = []
  449.                 serverFiltered = []
  450.  
  451.                 var help = {
  452.                     translate: 'chat.type.admin',
  453.                     "with": ["§3§lProxy", "§7All filters on traffic coming from both the §cclient and server §7have been removed."]
  454.                   };
  455.                 client.write("chat", { message: JSON.stringify(help), position: 0 });
  456.                 sendPacket = false
  457.               }
  458.             }
  459.  
  460.  
  461.  
  462.             if(words[1].toLowerCase() == "add"){
  463.               if(words[2]){
  464.                 if(words[2].toLowerCase() == "server"){
  465.                   if(words[3]){
  466.                     function serverFinder(item){
  467.                         return words[3].toLowerCase() == item.toLowerCase()
  468.                     }
  469.                     var foundPacket = serverPackets.find(serverFinder)
  470.                     if(foundPacket != undefined){
  471.                       serverFiltered.push(words[3].toLowerCase())
  472.  
  473.                       var yes = {
  474.                           translate: 'chat.type.admin',
  475.                           "with": ["§3§lProxy", "§7Added packet §c'" + words[3] + "'§7 to the " + words[2] + " filter"]
  476.                         };
  477.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  478.                       sendPacket = false
  479.                     } else {
  480.                       var err = {
  481.                           translate: 'chat.type.admin',
  482.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  483.                         };
  484.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  485.                       sendPacket = false
  486.                     }
  487.                   } else {
  488.                     var err = {
  489.                         translate: 'chat.type.admin',
  490.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  491.                       };
  492.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  493.                     sendPacket = false
  494.                   }
  495.                 }
  496.  
  497.                 if(words[2].toLowerCase() == "client"){
  498.                   if(words[3]){
  499.                     function clientFinder(item){
  500.                         return words[3].toLowerCase() == item.toLowerCase()
  501.                     }
  502.                     var foundPacket = clientPackets.find(clientFinder)
  503.                     if(foundPacket != undefined){
  504.                       clientFiltered.push(words[3].toLowerCase())
  505.  
  506.                       var yes = {
  507.                           translate: 'chat.type.admin',
  508.                           "with": ["§3§lProxy", "§7Added packet §c'" + words[3] + "'§7 to the " + words[2] + " filter"]
  509.                         };
  510.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  511.                       sendPacket = false
  512.                     } else {
  513.                       var err = {
  514.                           translate: 'chat.type.admin',
  515.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  516.                         };
  517.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  518.                       sendPacket = false
  519.                     }
  520.                   } else {
  521.                     var err = {
  522.                         translate: 'chat.type.admin',
  523.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  524.                       };
  525.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  526.                     sendPacket = false
  527.                   }
  528.                 }
  529.  
  530.               } else {
  531.                 var err = {
  532.                     translate: 'chat.type.admin',
  533.                     "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  534.                   };
  535.                 client.write("chat", { message: JSON.stringify(err), position: 0 });
  536.                 sendPacket = false
  537.               }
  538.             }
  539.  
  540.  
  541.             if(words[1].toLowerCase() == "remove"){
  542.               if(words[2]){
  543.                 if(words[2].toLowerCase() == "server"){
  544.                   if(words[3]){
  545.                     function serverFinder(item){
  546.                         return words[3].toLowerCase() == item.toLowerCase()
  547.                     }
  548.                     var foundPacket = serverPackets.find(serverFinder)
  549.                     if(foundPacket != undefined){
  550.                       //FIX THIS RIGHT HERE
  551.                       var index = serverFiltered.indexOf(words[3]);
  552.                       if (index > -1) {
  553.                         serverFiltered.splice(index, 1);
  554.                       }
  555.                       //
  556.                       var yes = {
  557.                           translate: 'chat.type.admin',
  558.                           "with": ["§3§lProxy", "§7Removed packet §c'" + words[3] + "'§7 from the " + words[2] + " filter"]
  559.                         };
  560.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  561.                       sendPacket = false
  562.                     } else {
  563.                       var err = {
  564.                           translate: 'chat.type.admin',
  565.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  566.                         };
  567.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  568.                       sendPacket = false
  569.                     }
  570.                   } else {
  571.                     var err = {
  572.                         translate: 'chat.type.admin',
  573.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  574.                       };
  575.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  576.                     sendPacket = false
  577.                   }
  578.                 }
  579.  
  580.                 if(words[2].toLowerCase() == "client"){
  581.                   if(words[3]){
  582.                     function clientFinder(item){
  583.                         return words[3].toLowerCase() == item.toLowerCase()
  584.                     }
  585.                     var foundPacket = clientPackets.find(clientFinder)
  586.                     if(foundPacket != undefined){
  587.                       //FIX THIS RIGHT HERE
  588.                       var index = clientFiltered.indexOf(words[3]);
  589.                       if (index > -1) {
  590.                         clientFiltered.splice(index, 1);
  591.                       }
  592.                       //
  593.                       var yes = {
  594.                           translate: 'chat.type.admin',
  595.                           "with": ["§3§lProxy", "§7Removed packet §c'" + words[3] + "'§7 from the " + words[2] + " filter"]
  596.                         };
  597.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  598.                       sendPacket = false
  599.                     } else {
  600.                       var err = {
  601.                           translate: 'chat.type.admin',
  602.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  603.                         };
  604.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  605.                       sendPacket = false
  606.                     }
  607.                   } else {
  608.                     var err = {
  609.                         translate: 'chat.type.admin',
  610.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  611.                       };
  612.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  613.                     sendPacket = false
  614.                   }
  615.                 }
  616.  
  617.               } else {
  618.                 var err = {
  619.                     translate: 'chat.type.admin',
  620.                     "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  621.                   };
  622.                 client.write("chat", { message: JSON.stringify(err), position: 0 });
  623.                 sendPacket = false
  624.               }
  625.             }
  626.  
  627.  
  628.  
  629.           } else {
  630.               var err = {
  631.                   translate: 'chat.type.admin',
  632.                   "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  633.                 };
  634.               client.write("chat", { message: JSON.stringify(err), position: 0 });
  635.               sendPacket = false
  636.           }
  637.         }
  638.  
  639. //Say command
  640.         if(data.message.toLowerCase().startsWith(prefix + "say")){
  641.           if(words[1] == undefined){
  642.           var help = {
  643.               translate: 'chat.type.admin',
  644.               "with": ["§3§lProxy", "§cError: Invalid syntax.\n§7§lUsage: " + prefix + "say [message]"]
  645.             };
  646.             client.write("chat", { message: JSON.stringify(help), position: 0 });
  647.             sendPacket = false
  648.           } else {
  649.             words.shift()
  650.             msgStr = words.join(' ')
  651.             var msg = msgStr.replace(/%/gi, '§')
  652.  
  653.             targetClient.write('chat', {message: msg});
  654.             sendPacket = false
  655.           }
  656.         }
  657.  
  658. //Client creative
  659.         if(data.message.toLowerCase().startsWith(prefix + "forcecreative")){
  660.           var help = {
  661.               translate: 'chat.type.admin',
  662.               "with": ["§3§lProxy", "§7Player gamemode set to §ccreatve §7§l(Client sided only)"]
  663.             };
  664.  
  665.             client.write("chat", { message: JSON.stringify(help), position: 0 });
  666.             client.write('game_state_change', {
  667.               reason: 3,
  668.               gameMode: 1
  669.             })
  670.             sendPacket = false
  671.         }
  672.  
  673. //Gamestate command
  674.         if(data.message.toLowerCase().startsWith(prefix + "state")){
  675.           if(words[1] == undefined){
  676.           var help = {
  677.               translate: 'chat.type.admin',
  678.               "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + prefix + "state [reason] [value (optional)]"]
  679.             };
  680.  
  681.             client.write("chat", { message: JSON.stringify(help), position: 0 });
  682.             sendPacket = false
  683.           } else {
  684.             if(words[2] == undefined){
  685.               var msg = {
  686.                   translate: 'chat.type.admin',
  687.                   "with": ["§3§lProxy", "§7Packet has been sent to client"]
  688.                 };
  689.  
  690.  
  691.               client.write("chat", { message: JSON.stringify(msg), position: 0 });
  692.               client.write('game_state_change', {
  693.                 reason: parseInt(words[1])
  694.               })
  695.               sendPacket = false
  696.             } else {
  697.               var msg = {
  698.                   translate: 'chat.type.admin',
  699.                   "with": ["§3§lProxy", "§7Packet has been sent to client"]
  700.                 };
  701.  
  702.  
  703.               client.write("chat", { message: JSON.stringify(msg), position: 0 });
  704.               client.write('game_state_change', {
  705.                 reason: parseInt(words[1]),
  706.                 gameMode: parseInt(words[2])
  707.               })
  708.               sendPacket = false
  709.             }
  710.         }
  711.       }
  712.  
  713. //removeBlockEntities
  714.       if(data.message.toLowerCase().startsWith(prefix + "removesigns")){
  715.         if(removeBlockEntities == true){
  716.           removeBlockEntities = false
  717.  
  718.           var msg = {
  719.               translate: 'chat.type.admin',
  720.               "with": ["§3§lProxy", "§7Sign rendering is now §c§lenabled! You can be sign banned!"]
  721.             };
  722.  
  723.  
  724.           client.write("chat", { message: JSON.stringify(msg), position: 0 });
  725.           sendPacket = false
  726.         } else {
  727.           removeBlockEntities = true
  728.  
  729.           var msg = {
  730.               translate: 'chat.type.admin',
  731.               "with": ["§3§lProxy", "§7Sign rendering is now §c§ldisabled!  You can't be sign banned!"]
  732.             };
  733.  
  734.  
  735.           client.write("chat", { message: JSON.stringify(msg), position: 0 });
  736.           sendPacket = false
  737.         }
  738.       }
  739.  
  740.  
  741.     }
  742.  
  743.     if(data.channel){
  744.       if(data.channel == "MC|BSign"){ //Add toggleable option too
  745.         var f = {
  746.           translate: 'chat.type.admin',
  747.           "with": ["§3§lProxy", "§7Book detected with data:\n§c" + data.data]
  748.         };
  749.         //client.write("chat", { message: JSON.stringify(f), position: 0 });
  750.         console.log("\n\nBOOK DATA: " + typeof(data.data) + "\n" + data.data + "\n\n")
  751.       }
  752.     }
  753.  
  754. var loop; //maybe?
  755. for(loop = 0; loop < serverFiltered.length; loop++){
  756.   if(meta.name.toLowerCase() == serverFiltered[loop].toLowerCase()){
  757.     sendPacket = false
  758.     console.log("\x1b[33m" + "\x1b[36m" + 'FILTERED PACKET DETECTED: ' + serverFiltered[loop] + "\x1b[0m")
  759.   }
  760. } //
  761.  
  762.       if(sendPacket == true){
  763.         if (!endedTargetClient) { targetClient.write(meta.name, data) }
  764.       }
  765.     }
  766.   })
  767.   targetClient.on('packet', function (data, meta) {
  768.     var sendPacket = true
  769.     if (meta.state === states.PLAY && client.state === states.PLAY) {
  770.     //if (meta.state && client.state) {
  771.       if (shouldDump(meta.name, 'i')) {
  772.         if(loggingPackets == true){
  773.         console.log("\x1b[36m" + "\x1b[47m" + 'server->client:' + "\x1b[0m" + "\x1b[36m",
  774.           "\x1b[4m" + targetClient.state + '.' + meta.name + "\x1b[0m" + "\x1b[36m" + ':' +
  775.           JSON.stringify(data) + "\x1b[0m")
  776.         }
  777.       }
  778.  
  779.       var loop; //Maybe?
  780.       for(loop = 0; loop < clientFiltered.length; loop++){
  781.         if(meta.name.toLowerCase() == clientFiltered[loop].toLowerCase()){
  782.           sendPacket = false
  783.           console.log("\x1b[33m" + "\x1b[36m" + 'FILTERED PACKET DETECTED: ' + clientFiltered[loop] + "\x1b[0m")
  784.         }
  785.       } //
  786.       if(sendPacket == true){ //maybe?
  787.         if (!endedClient) {
  788.           client.write(meta.name, data)
  789.           if (meta.name === 'set_compression') {
  790.             client.compressionThreshold = data.threshold
  791.           } // Set compression
  792.         }
  793.       } //
  794.     }
  795.   })
  796.  
  797.   targetClient.on('map_chunk', function (packet) {
  798.     if(removeBlockEntities == true) {
  799.       sendPacket = false
  800.  
  801.       client.write("map_chunk", {
  802.         x: packet.x,
  803.         z: packet.z,
  804.         groundUp: packet.groundUp,
  805.         bitMap: packet.bitMap,
  806.         chunkData: packet.chunkData,
  807.         blockEntities: []
  808.       })
  809.     }
  810.   })
  811.  
  812.   targetClient.on('login', function (packet) {
  813.     AccountEntity = packet.entityId
  814.     console.log("\x1b[43m" + "\n\n\nACCOUNT ENTITY ID: " + AccountEntity + "\n\n\n" + "\x1b[0m")
  815.   })
  816.  
  817.  
  818.   const bufferEqual = require('buffer-equal')
  819.   targetClient.on('raw', function (buffer, meta) {
  820.     if (client.state !== states.PLAY || meta.state !== states.PLAY) { return }
  821.     const packetData = targetClient.deserializer.parsePacketBuffer(buffer).data.params
  822.     const packetBuff = client.serializer.createPacketBuffer({ name: meta.name, params: packetData })
  823.     if (!bufferEqual(buffer, packetBuff)) {
  824.       console.log('server->client: Error in packet ' + meta.state + '.' + meta.name)
  825.       console.log('received buffer', buffer.toString('hex'))
  826.       console.log('produced buffer', packetBuff.toString('hex'))
  827.       console.log('received length', buffer.length)
  828.       console.log('produced length', packetBuff.length)
  829.     }
  830.     /* if (client.state === states.PLAY && brokenPackets.indexOf(packetId.value) !=== -1)
  831.      {
  832.      console.log(`client<-server: raw packet);
  833.      console.log(packetData);
  834.      if (!endedClient)
  835.      client.writeRaw(buffer);
  836.      } */
  837.   })
  838.   client.on('raw', function (buffer, meta) {
  839.     if (meta.state !== states.PLAY || targetClient.state !== states.PLAY) { return }
  840.     const packetData = client.deserializer.parsePacketBuffer(buffer).data.params
  841.     const packetBuff = targetClient.serializer.createPacketBuffer({ name: meta.name, params: packetData })
  842.     if (!bufferEqual(buffer, packetBuff)) {
  843.       console.log('client->server: Error in packet ' + meta.state + '.' + meta.name)
  844.       console.log('received buffer', buffer.toString('hex'))
  845.       console.log('produced buffer', packetBuff.toString('hex'))
  846.       console.log('received length', buffer.length)
  847.       console.log('produced length', packetBuff.length)
  848.     }
  849.   })
  850.   targetClient.on('end', function () {
  851.     endedTargetClient = true
  852.     console.log('Connection closed by server', '(' + addr + ')')
  853.     if (!endedClient) { client.end('§cYou have been banned from 2B2T for illegal modifications.') }
  854.   })
  855.   targetClient.on('error', function (err) {
  856.     endedTargetClient = true
  857.     console.log('Connection error by server', '(' + addr + ') ', err)
  858.     console.log(err.stack)
  859.     if (!endedClient) { client.end('§cNice job dumbass, you fucked something up.  Check the console.') }
  860.   })
  861.  
  862.  
  863.  
  864. })
  865.  
  866. function shouldDump (name, direction) {
  867.   if (matches(printNameBlacklist[name])) return false
  868.   if (printAllNames) return true
  869.   return matches(printNameWhitelist[name])
  870.  
  871.   function matches (result) {
  872.     return result !== undefined && result !== null && result.indexOf(direction) !== -1
  873.   }
  874. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement