Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DataInputStream ins;
- DataOutputStream outs;
- InputStream in;
- OutputStream out;
- public void send(byte[] send) throws IOException {
- outs.write(send, 0, send.length);
- }
- public void send(int send) throws IOException {
- outs.writeByte(send);
- }
- public void send(String send) throws IOException {
- outs.writeUTF(send);
- }
- public void handle() throws IOException {
- byte ID = ins.readByte();
- boolean flush = true;
- System.out.println("Handling packet of id " + Integer.toHexString(ID));
- switch (ID) {
- case 0x00:
- System.out.println("Recived keepalive, sending back.");
- send(0x00);
- case 0x01:
- if(Mode<2){
- System.out.println("Recived loginrequest, responding.");
- ins.readInt();
- username = ins.readUTF();
- System.out.println("User " + username + " connected!");
- ins.readUTF();
- ins.readLong();
- ins.readByte();
- send(0x01);
- send(ID);
- send("");
- send("");
- outs.writeLong((long) 0);
- send(0);
- outs.flush();
- flush = false;
- Mode=2;
- } else{
- System.err.println("Whoops, client send login request. Something happened, kicking.");
- send(0xFF);
- send("Either you, or I did something wrong. Try again maybe?");
- }
- case 0x02:
- if(Mode<1){
- System.out.println("Recived handshake, responding.");
- ins.readUTF();
- send(0x02);
- send("-");
- Mode=1;
- } else{
- System.err.println("Whoops... client tried to handshake *again*");
- send(0xFF);
- send("Either you, or I did something wrong. Try again maybe?");
- }
- }
- //if(flush){
- outs.flush();
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement