Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. DataInputStream ins;
  2. DataOutputStream outs;
  3. InputStream in;
  4. OutputStream out;
  5.  
  6. public void send(byte[] send) throws IOException {
  7.     outs.write(send, 0, send.length);
  8. }
  9.  
  10. public void send(int send) throws IOException {
  11.     outs.writeByte(send);
  12. }
  13.  
  14. public void send(String send) throws IOException {
  15.     outs.writeUTF(send);
  16. }
  17.  
  18. public void handle() throws IOException {
  19.     byte ID = ins.readByte();
  20.     boolean flush = true;
  21.     System.out.println("Handling packet of id " + Integer.toHexString(ID));
  22.     switch (ID) {
  23.         case 0x00:
  24.             System.out.println("Recived keepalive, sending back.");
  25.             send(0x00);
  26.         case 0x01:
  27.             if(Mode<2){
  28.                 System.out.println("Recived loginrequest, responding.");
  29.                 ins.readInt();
  30.                 username = ins.readUTF();
  31.                 System.out.println("User " + username + " connected!");
  32.                 ins.readUTF();
  33.                 ins.readLong();
  34.                 ins.readByte();
  35.                 send(0x01);
  36.                 send(ID);
  37.                 send("");
  38.                 send("");
  39.                 outs.writeLong((long) 0);
  40.                 send(0);
  41.                 outs.flush();
  42.                 flush = false;
  43.                 Mode=2;
  44.             } else{
  45.                 System.err.println("Whoops, client send login request. Something happened, kicking.");
  46.                 send(0xFF);
  47.                 send("Either you, or I did something wrong. Try again maybe?");
  48.             }
  49.         case 0x02:
  50.             if(Mode<1){
  51.                 System.out.println("Recived handshake, responding.");
  52.                 ins.readUTF();
  53.                 send(0x02);
  54.                 send("-");
  55.                 Mode=1;
  56.             } else{
  57.                 System.err.println("Whoops... client tried to handshake *again*");
  58.                 send(0xFF);
  59.                 send("Either you, or I did something wrong. Try again maybe?");
  60.             }
  61.     }
  62.     //if(flush){
  63.         outs.flush();
  64.     //}
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement