Commit 3db96af5 authored by Rikysamuel's avatar Rikysamuel
Browse files

Merge branch 'master' of...

Merge branch 'master' of http://gitlab.informatika.org/sinambelajunita/IF3230-Tugas-Besar-Sister-2015
parents 1c886c46 13182a46
......@@ -11,6 +11,7 @@ import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import static com.mongodb.client.model.Filters.eq;
import java.awt.Point;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
......@@ -549,6 +550,11 @@ public class Database {
}
}
public static boolean fetchItem(String token, String offer_token)
{
return true;
}
/**
* Jika berhasil, return 1, jika already taken, return 0, jika tidak ada di database, return -1
* @param token
......@@ -581,6 +587,20 @@ public class Database {
}
}
public static JSONObject getPosition(String username)
{
MongoCollection<Document> collection = database.getCollection("user");
JSONObject position = null;
try {
JSONObject data = new JSONObject(collection.find(eq("username", username)).first().toJson());
System.out.println(data.toString());
position = data.getJSONObject("position");
} catch (JSONException ex) {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
}
return position;
}
/**
* Mengembalikan token, username, dan password dari username yang dimasukkan
* @param username
......
......@@ -78,7 +78,9 @@ public class Message {
// System.out.println(receive("{\"item\": 0, \"method\": \"findoffer\"}"));
// System.out.println(move("553cd35d3c892b2c6768f77d", 4, 4));
// System.out.println(receive("{\"method\":\"field\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
System.out.println(receive("{\"method\":\"inventory\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
// System.out.println(receive("{\"method\":\"inventory\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
System.out.println(login("ja","j"));
// System.out.println(receive("{\"method\": \"canceloffer\",\"token\": \"553cf0913c892b417db5bd82\",\"offer_token\": \"553cf11f3c892b417db5bd83\"}"));
}
public static String callURL(String myURL) {
......@@ -198,11 +200,24 @@ public class Message {
}
case "sendaccept":
{
String token = jsonObj.getString("token");
String offer_token = jsonObj.getString("offer_token");
sendAccept(token, offer_token);
break;
}
case "canceloffer":
{
String token = jsonObj.getString("token");
String offer_token = jsonObj.getString("offer_token");
cancelOffer(token, offer_token);
break;
}
case "serverStatus":
{
response = serverStatus(jsonString);
break;
}
}
if(log)
System.out.println(jsonObj);
......@@ -253,12 +268,20 @@ public class Message {
if(password.equals(person.password))
{
JSONObject jObj = new JSONObject();
jObj.put("status", "ok");
jObj.put("token", person.token);
jObj.put("x", 0);
jObj.put("y", 0);
jObj.put("time", Database.getTime(0,0,0,0));
response = jObj.toString();
JSONObject position = Database.getPosition(username);
if(position!=null)
{
jObj.put("status", "ok");
jObj.put("token", person.token);
jObj.put("x", position.getInt("x"));
jObj.put("y", position.getInt("y"));
jObj.put("time", Database.getTime(0,0,0,0));
response = jObj.toString();
}
else
{
response = fail("Failed get last position");
}
}
else
{
......@@ -779,6 +802,7 @@ public class Message {
public static String fetchItem(String token, String offer_token) //15
{
return "";
}
......
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