Commit 2d331d21 authored by Stephen's avatar Stephen
Browse files

Merged

parents d37cf799 3c69b2b7
......@@ -13,5 +13,11 @@ src/client/nbbuild/
src/client/nbdist/
src/client/nbactions.xml
src/client/nb-configuration.xml
<<<<<<< HEAD
src/client/build/classes/tcpclient/LoginPage.class
src/client/build/classes/tcpclient/TCPClient.class
.nb-gradle/
/src/client/dist/
\ No newline at end of file
=======
.nb-gradle/
/src/client/dist/
>>>>>>> bc4556fff5c99bc4b898c7dd8720e7cf066d81a5
......@@ -15,6 +15,6 @@ user.properties.file=C:\\Users\\susanti_2\\AppData\\Roaming\\NetBeans\\8.0.2\\bu
>>>>>>> 43e41c8c08f84039568ca701a584f38f9911e548
=======
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
>>>>>>> 4425b3f14619792ceebdcdb264cb7c61d1d9d38c
......@@ -3,9 +3,20 @@
<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>
<<<<<<< HEAD
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/MainPage.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/LoginPage.java</file>
=======
<<<<<<< HEAD
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
=======
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/LoginPage.java</file>
>>>>>>> bc4556fff5c99bc4b898c7dd8720e7cf066d81a5
>>>>>>> 3c69b2b796de9bf56585767f5594f0a0341a48ac
</group>
</open-files>
</project-private>
This diff is collapsed.
This diff is collapsed.
......@@ -148,6 +148,7 @@ public class TCPClient {
}
public JSONObject tradeboxJSON(String token) {
JSONObject obj = new JSONObject();
try {
......@@ -160,6 +161,19 @@ public class TCPClient {
return obj;
}
private JSONObject sendAcceptJSON(String offerToken) {
JSONObject obj = new JSONObject();
try {
obj.put("method", "sendaccept");
obj.put("token", token);
obj.put("offer_token", offerToken);
} catch(Exception e) {
e.printStackTrace();
}
return obj;
}
public JSONObject cancelofferJSON(String token, String offer_token) {
JSONObject obj = new JSONObject();
......@@ -174,6 +188,43 @@ public class TCPClient {
return obj;
}
public JSONObject sendFindJSON(String token,int FindId) {
JSONObject obj = new JSONObject();
try {
obj.put("method","sendfind");
obj.put("token",token);
obj.put("item", FindId);
}
catch (Exception e) {
e.printStackTrace();
}
return obj;
}
public JSONObject sendFind(String token,int FindId) throws Exception {
System.out.println("sendFind");
String toSend = sendFindJSON(token,FindId).toString();
//throw ioexception
DataOutputStream outToServer;
try {
outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes(toSend + '\n');
}
catch (IOException ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
throw new Exception("outtoserver login exception");
}
//ambil balasan server
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject responseJSON = new JSONObject(response);
return responseJSON;
}
public JSONObject register(String username, String password) throws Exception
{
System.out.println("Register");
......@@ -251,9 +302,12 @@ public class TCPClient {
//throw ioexception
DataOutputStream outToServer;
try {
System.out.println("mix mantap");
outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes(toSend + '\n');
System.out.println("harusnya udah nambah");
} catch (IOException ex) {
System.out.println("error woi mix nya");
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
throw new Exception("outtoserver mix item exception");
}
......@@ -382,6 +436,52 @@ public class TCPClient {
return responseJSON;
}
public JSONObject tradebox() throws Exception
{
System.out.println("Tradebox");
String toSend = tradeboxJSON(token).toString();
//throw ioexception
DataOutputStream outToServer;
try {
outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes(toSend + '\n');
} catch (IOException ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
throw new Exception("outtoserver tradebox exception");
}
//ambil balasan server
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject responseJSON = new JSONObject(response);
return responseJSON;
}
public JSONObject sendAccept(String offerToken) throws Exception
{
System.out.println("Send Accept");
String toSend = sendAcceptJSON(offerToken).toString();
//throw ioexception
DataOutputStream outToServer;
try {
outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes(toSend + '\n');
} catch (IOException ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
throw new Exception("outtoserver send accept exception");
}
//ambil balasan server
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject responseJSON = new JSONObject(response);
return responseJSON;
}
public JSONObject canceloffer(String token, String offer_token) throws Exception
{
System.out.println("Cancel Offer");
......@@ -532,4 +632,6 @@ public class TCPClient {
// System.out.println(response.toString());
// }
}
......@@ -26,7 +26,7 @@ user.properties.file=C:\\Users\\susanti_2\\AppData\\Roaming\\NetBeans\\8.0.2\\bu
=======
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
>>>>>>> 4425b3f14619792ceebdcdb264cb7c61d1d9d38c
......@@ -3,9 +3,19 @@
<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>
<<<<<<< HEAD
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/server/src/tcpserver/TCPServer.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/server/src/tcpserver/Host.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/server/src/tcpserver/MySQLAccess.java</file>
=======
<<<<<<< HEAD
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/server/src/tcpserver/TCPServer.java</file>
=======
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/server/map.txt</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/server/src/tcpserver/MySQLAccess.java</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/server/src/tcpserver/TCPServer.java</file>
>>>>>>> bc4556fff5c99bc4b898c7dd8720e7cf066d81a5
>>>>>>> 3c69b2b796de9bf56585767f5594f0a0341a48ac
</group>
</open-files>
</project-private>
......@@ -24,7 +24,8 @@ public class MySQLAccess {
private Statement statement;
private PreparedStatement preparedStatement;
private ResultSet resultSet;
private boolean ada = true;
public MySQLAccess() {}
private void open() {
......@@ -137,9 +138,9 @@ public class MySQLAccess {
array.put(resultSet.getString("potion"));
array.put(resultSet.getString("incense"));
array.put(resultSet.getString("gems"));
array.put(resultSet.getString("elixir"));
array.put(resultSet.getString("crystal"));
array.put(resultSet.getString("stone"));
array.put(resultSet.getString("life_elixir"));
array.put(resultSet.getString("mana_crystal"));
array.put(resultSet.getString("philosopher_stone"));
response.put("inventory", array);
}
} catch (SQLException e) {
......@@ -171,21 +172,21 @@ public class MySQLAccess {
+ "id_item=" + item1 + ";");
resultSet2 = preparedStatement.executeQuery();
if(resultSet2.first())
itemName1 = resultSet2.getString("item_name").toLowerCase();
itemName1 = resultSet2.getString("item_name").toLowerCase().replace(' ','_');
// Cek apa nama dari item 2
preparedStatement = connect.prepareStatement("SELECT * FROM items WHERE "
+ "id_item=" + item2 + ";");
resultSet2 = preparedStatement.executeQuery();
if(resultSet2.first())
itemName2 = resultSet2.getString("item_name").toLowerCase();
itemName2 = resultSet2.getString("item_name").toLowerCase().replace(' ','_');
// Cek apa nama dari item hasil
preparedStatement = connect.prepareStatement("SELECT * FROM items WHERE "
+ "id_item=" + item_result + ";");
resultSet2 = preparedStatement.executeQuery();
if(resultSet2.first())
itemNameResult = resultSet2.getString("item_name").toLowerCase();
itemNameResult = resultSet2.getString("item_name").toLowerCase().replace(' ','_');
// Cek apakah pengguna memiliki jumlah barang yang cukup (masing - masing 3)
preparedStatement = connect.prepareStatement("SELECT * FROM inventory WHERE "
......@@ -246,6 +247,8 @@ public class MySQLAccess {
preparedStatement.executeUpdate();
response.put("status", "ok");
response.put("time", System.currentTimeMillis()/1000 + 5);
//barang menjadi ada lagi karena berpindah tempat
ada = true;
}
} else {
response.put("status", "error");
......@@ -275,25 +278,32 @@ public class MySQLAccess {
//System.out.println("nih map :"+TCPServer.map[curr_x][curr_y]);
String id_other = TCPServer.map[curr_x][curr_y];
if(id_other.equalsIgnoreCase(""))
{
response.put("status", "fail");
response.put("description", "Item has been taken");
}
else //item belom diambil
{
preparedStatement = connect.prepareStatement("SELECT id_item FROM items WHERE "+ "id_other=\"" + id_other + "\";");
preparedStatement = connect.prepareStatement("SELECT * FROM items WHERE "+ "id_other=\"" + id_other + "\";");
resultSet = preparedStatement.executeQuery();
if(resultSet.first()) {
int item_taken = resultSet.getInt("id_item");
//map dijadikan kosong
TCPServer.map[curr_x][curr_y] = "";
//kembalikan response
response.put("status", "ok");
response.put("item", item_taken);
//masukkan ke inventory
if(ada)
{
preparedStatement = connect.prepareStatement("UPDATE inventory SET "
+ resultSet.getString("item_name").toLowerCase() + "="
+ resultSet.getString("item_name").toLowerCase() + "+1"
+ " WHERE id_user=" + userID + ";");
preparedStatement.executeUpdate();
//kembalikan response
response.put("status", "ok");
response.put("item", item_taken);
ada = false;
}
else
{
response.put("status", "fail");
response.put("description", "Item has been taken");
}
}
}
}
} catch (SQLException e) {
response.put("status", "error");
......
......@@ -29,7 +29,7 @@ public class TCPServer implements Runnable {
System.out.println("Server running!");
serverClientSocket = new ServerSocket(port);
servers = new ArrayList<Host>();
sql = new MySQLAccess();
}
......
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