Commit 61ae1a2d authored by adwisatya's avatar adwisatya
Browse files

Revisi terima koneksi tanpa enter

parent cc3c237b
......@@ -3,12 +3,17 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMixItem.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/gui/AlcLogon.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMap.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/engine/Main.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/engine/Response.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/engine/Connection.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcOffer.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcFindItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMap.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/engine/Connection.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/engine/Main.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcTradeBox.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcTradeItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcLogon.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMixItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/ImagePanel.java</file>
</group>
</open-files>
</project-private>
......@@ -170,7 +170,11 @@ public class AlcLogon extends javax.swing.JFrame {
try {
pass = new String(txtPassword.getPassword());
hasilRespon = respon.loginOK(connection.login(txtAccount.getText(), pass));
try {
hasilRespon = respon.loginOK(connection.login(txtAccount.getText(), pass));
} catch (IOException ex) {
Logger.getLogger(AlcLogon.class.getName()).log(Level.SEVERE, null, ex);
}
if(connection.JSONtoString("status", hasilRespon).equals("ok")){
System.out.println("ok");
connection.setToken(connection.JSONtoString("token", hasilRespon));
......
{"name" : "Bandar Behari","width" : 4,"height" : 4,"map" :[["R13", "R13", "R13", "R13"],["R13", "R13", "R14", "R14"],["R13", "R14", "R14", "R14"],["R13", "R14", "R14", "R14"]]}
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/folder/map.json</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/thealchemist/Client.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/thealchemist/Database.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/thealchemist/TCPServer.java</file>
</group>
</open-files>
</project-private>
......@@ -7,6 +7,7 @@ package thealchemist;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
......@@ -39,17 +40,13 @@ public class Client extends Thread{
public static int defPort = 8000;
public static int dbPort = 8025;
public static int myPort = 6789;
private static int MAX_BUFFER = 1024;
/* Client attributes */
public String token;
public String tmpStr;
public String time;
public ArrayList<String> location = new ArrayList<String>(Arrays.asList("0", "0"));
NetworkInterface networkinterface = NetworkInterface.getByIndex(13);
//public int item;
// public int heigth;
// public int width;
// public String name;
// public String inventory;
public ArrayList<Integer> items;
public ArrayList<String> servers;
public String offers;
......@@ -60,17 +57,17 @@ public class Client extends Thread{
}
public void run(){
getIP();
//getIP();
/* Testing database */
clientSentence = "";
char[] buffer = new char[MAX_BUFFER];
while(!clientSentence.equals("dead")){
try{
fromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
toClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = fromClient.readLine();
toClient.writeBytes("Anda mengirimkan " + clientSentence + "\n");
checkCommand(clientSentence.toString());
fromClient.read(buffer);
clientSentence = new String(buffer);
checkCommand(clientSentence);
}catch(IOException e){
System.out.println(e);
} catch (NoSuchAlgorithmException ex) {
......@@ -87,7 +84,7 @@ public class Client extends Thread{
public void checkCommand(String cmd) throws IOException, NoSuchAlgorithmException, JSONException {
cmdJoin();
System.out.println("Request: " + cmd);
if(isJSONValid(cmd)){
//if(isJSONValid(cmd)){
switch (JSONtoString("method",cmd)){
case "getServer":
System.out.println(database.getServers().toString());
......@@ -154,7 +151,7 @@ public class Client extends Thread{
cmdCancelOffer(JSONtoString("token",cmd), JSONtoString("offer_token",cmd));
break;
}
}
//}
}
public String JSONtoString(String param, String JSON) throws JSONException{
......@@ -219,6 +216,7 @@ public class Client extends Thread{
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
sendToClient(obj.toString());
System.out.println(obj.toString());
}
public void cmdLogin(String username, String password) throws IOException, NoSuchAlgorithmException, JSONException{
......@@ -613,13 +611,19 @@ public class Client extends Thread{
}
public void loadMap(){
String filename = "map.json";
try {
JSONObject objMap = new JSONObject(new FileReader("folder/"+filename));
System.out.println(objMap.toString());
} catch (FileNotFoundException ex) {
System.out.println("gagal load");
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
File f = new File("file.json");
if(f.exists()){
System.out.println("ada");
}else{
System.out.println("tidak ada");
}
// try {
// JSONObject objMap = new JSONObject(new FileReader("folder/"+filename));
// System.out.println(objMap.toString());
// } catch (FileNotFoundException ex) {
// System.out.println("gagal load");
// Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
// }
}
}
......@@ -26,7 +26,7 @@ import static thealchemist.Client.myPort;
public class TCPServer {
static int portNumber = 6789;
public static void main(String argv[]) throws Exception{
ServerSocket mainSocket;
ServerSocket mainSocket ;
mainSocket = new ServerSocket(portNumber);
System.out.println("Start listening...");
cmdJoin();
......@@ -38,6 +38,15 @@ public class TCPServer {
}
}
// ServerSocket mainSocket ;
// Socket clientSocket = null;
// mainSocket = new ServerSocket(portNumber);
// System.out.println("Start listening...");
//
// while(true){
// clientSocket = mainSocket.accept();
// new Thread(new Client(clientSocket)).start();
// }
}
public static void cmdJoin() throws IOException, JSONException{
......
{"name" : "Bandar Behari","width" : 4,"height" : 4,"map" :[["R13", "R13", "R13", "R13"],["R13", "R13", "R14", "R14"],["R13", "R14", "R14", "R14"],["R13", "R14", "R14", "R14"]]}
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