Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package mctest;
- import java.io.DataInputStream;
- import java.io.DataOutput;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.Random;
- /**
- *
- * @author JGomes
- */
- public class Main
- {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- System.out.println("Starting...");
- try
- {
- Random randGen = new Random();
- ServerSocket serverSocket = new ServerSocket(25565);
- System.out.println("Listening on port 25565...");
- Socket socket = serverSocket.accept();
- System.out.println("New connection...");
- DataInputStream in = new DataInputStream(socket.getInputStream());
- DataOutputStream out = new DataOutputStream(socket.getOutputStream());
- //1.receive handshake packet
- byte id = in.readByte();
- System.out.println("ID pacote: " + id);
- //2.send handshake packet
- if (id == 0x02)
- {
- String username = in.readUTF();
- System.out.println("Username: " + username);
- out.writeByte(0x02);
- //String hash = "45cd46d72801d50";//Long.toHexString(Math.abs(randGen.nextLong()));
- //System.out.println("Output hash: " + hash);
- out.writeUTF("-");
- out.flush();
- //3. receive login packet
- id = in.readByte();
- System.out.println("ID pacote: " + id);
- if (id == 0x01)
- {
- int protocolVersion = in.readInt();
- System.out.println("Protocol version: " + protocolVersion);
- username = in.readUTF();
- System.out.println("Username: " + username);
- String password = in.readUTF();
- System.out.println("password: " + password);
- long mapseed = in.readLong();
- System.out.println("mapseed: " + mapseed);
- byte dimension = in.readByte();
- System.out.println("dimension: " + dimension);
- //4. send the login package (answer) [or kick]
- out.writeByte(0x01);
- out.writeUTF("");
- out.writeUTF("");
- out.writeLong(randGen.nextLong());
- out.writeByte(0x00);
- //5. send 49 pre-chunks
- //6. send 49 chunks
- //7. send spawn position
- //8. send inventory
- //9. send position and look
- //10. receive position and look pack
- //11. ?????
- //12. profit!
- }
- }
- //Thread.sleep(10000);
- socket.close();
- serverSocket.close();
- System.out.println("Done!");
- } catch (IOException ex)
- {
- System.out.println("IO exception: " + ex.getMessage());
- } catch (Exception ex)
- {
- System.out.println("Exception:" + ex.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement