Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.98 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package mctest;
  6.  
  7. import java.io.DataInputStream;
  8. import java.io.DataOutput;
  9. import java.io.DataOutputStream;
  10. import java.io.IOException;
  11. import java.net.ServerSocket;
  12. import java.net.Socket;
  13. import java.util.Random;
  14.  
  15. /**
  16.  *
  17.  * @author JGomes
  18.  */
  19. public class Main
  20. {
  21.  
  22.       /**
  23.        * @param args the command line arguments
  24.        */
  25.       public static void main(String[] args)
  26.       {
  27.             System.out.println("Starting...");
  28.             try
  29.             {
  30.  
  31.                   Random randGen = new Random();
  32.                   ServerSocket serverSocket = new ServerSocket(25565);
  33.                   System.out.println("Listening on port 25565...");
  34.                   Socket socket = serverSocket.accept();
  35.                   System.out.println("New connection...");
  36.                   DataInputStream in = new DataInputStream(socket.getInputStream());
  37.                   DataOutputStream out = new DataOutputStream(socket.getOutputStream());
  38.  
  39.                   //1.receive handshake packet
  40.                   byte id = in.readByte();
  41.                   System.out.println("ID pacote: " + id);
  42.                  
  43.                   //2.send handshake packet
  44.                   if (id == 0x02)
  45.                   {
  46.                         String username = in.readUTF();
  47.                         System.out.println("Username: " + username);
  48.  
  49.                         out.writeByte(0x02);
  50.                         //String hash = "45cd46d72801d50";//Long.toHexString(Math.abs(randGen.nextLong()));
  51.                         //System.out.println("Output hash: " +  hash);
  52.                         out.writeUTF("-");
  53.                         out.flush();
  54.                        
  55.                         //3. receive login packet
  56.                         id = in.readByte();
  57.                         System.out.println("ID pacote: " + id);
  58.                         if (id == 0x01)
  59.                         {
  60.                              
  61.                               int protocolVersion = in.readInt();
  62.                               System.out.println("Protocol version: " + protocolVersion);
  63.                               username = in.readUTF();
  64.                               System.out.println("Username: " + username);
  65.                               String password = in.readUTF();
  66.                               System.out.println("password: " + password);
  67.                               long mapseed = in.readLong();
  68.                               System.out.println("mapseed: " + mapseed);
  69.                               byte dimension = in.readByte();
  70.                               System.out.println("dimension: " + dimension);
  71.  
  72.                               //4. send the login package (answer) [or kick]
  73.                               out.writeByte(0x01);
  74.                               out.writeUTF("");
  75.                               out.writeUTF("");
  76.                               out.writeLong(randGen.nextLong());
  77.                               out.writeByte(0x00);
  78.  
  79.                               //5. send 49 pre-chunks
  80.  
  81.                               //6. send 49 chunks
  82.  
  83.                               //7. send spawn position
  84.  
  85.                               //8. send inventory
  86.  
  87.                               //9. send position and look
  88.  
  89.                               //10. receive position and look pack
  90.  
  91.                               //11. ?????
  92.  
  93.                               //12. profit!
  94.  
  95.  
  96.                         }
  97.                   }
  98.  
  99.                   //Thread.sleep(10000);
  100.                   socket.close();
  101.                   serverSocket.close();
  102.                   System.out.println("Done!");
  103.  
  104.  
  105.             } catch (IOException ex)
  106.             {
  107.                   System.out.println("IO exception: " + ex.getMessage());
  108.             } catch (Exception ex)
  109.             {
  110.                   System.out.println("Exception:" + ex.getMessage());
  111.             }
  112.       }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement