Commit 79a8e39a authored by Rafi Ramadhan's avatar Rafi Ramadhan
Browse files

edit clientHandler

parent f674d6ce
......@@ -13,6 +13,7 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.parser.ParseException;
/**
*
......@@ -30,13 +31,58 @@ public class ClientHandler extends Thread {
public void run() {
String response;
JSONParse parse = new JSONParse();
MethodHandler handler = new MethodHandler();
while(true) {
try {
DataInputStream in = new DataInputStream(socketListener.getInputStream());
response = in.readUTF();
System.out.println(response);
DataOutputStream out = new DataOutputStream(socketListener.getOutputStream());
out.writeUTF("Thank you for connecting to " + socketListener.getLocalSocketAddress() + "\nGoodbye!");
if(parse.parseJSON(response, "method").equals("login")) {
out.writeUTF(handler.Login(response));
}
else if(parse.parseJSON(response, "method").equals("signup")) {
out.writeUTF(handler.Signup(response));
}
else if(parse.parseJSON(response, "method").equals("inventory")) {
out.writeUTF(handler.Inventory(response));
}
else if(parse.parseJSON(response, "method").equals("mixitem")) {
out.writeUTF(handler.MixItem(response));
}
else if(parse.parseJSON(response, "method").equals("map")) {
out.writeUTF(handler.Map(response));
}
else if(parse.parseJSON(response, "method").equals("move")) {
out.writeUTF(handler.Move(response));
}
else if(parse.parseJSON(response, "method").equals("field")) {
out.writeUTF(handler.Field(response));
}
else if(parse.parseJSON(response, "method").equals("offer")) {
out.writeUTF(handler.Offer(response));
}
else if(parse.parseJSON(response, "method").equals("tradebox")) {
out.writeUTF(handler.TradeBox(response));
}
else if(parse.parseJSON(response, "method").equals("sendfind")) {
out.writeUTF(handler.sendFind(response));
}
else if(parse.parseJSON(response, "method").equals("findoffer")) {
out.writeUTF(handler.sendFind(response));
}
else if(parse.parseJSON(response, "method").equals("sendaccept")) {
out.writeUTF(handler.sendFind(response));
}
else if(parse.parseJSON(response, "method").equals("accept")) {
out.writeUTF(handler.sendFind(response));
}
else {
out.writeUTF("Thank you for connecting to "
+ socketListener.getLocalSocketAddress() + "\nGoodbye!");
}
} catch (IOException ex) {
Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex);
try {
......@@ -44,6 +90,8 @@ public class ClientHandler extends Thread {
} catch (IOException ex1) {
Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex1);
}
} catch (ParseException ex) {
Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
......
......@@ -36,9 +36,6 @@ public class Server extends Thread {
String response;
JSONParse parse = new JSONParse();
String response;
JSONParse parse = new JSONParse();
MethodHandler handler = new MethodHandler();
while(true)
......@@ -60,9 +57,6 @@ public class Server extends Thread {
new DataOutputStream(server.getOutputStream());
if(parse.parseJSON(response, "method").equals("login")) {
out.writeUTF(Login(response));
}
out.writeUTF(handler.Login(response));
}
else if(parse.parseJSON(response, "method").equals("signup")) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment