Commit c19d82de authored by Rafi Ramadhan's avatar Rafi Ramadhan
Browse files

server field

parent b0976c8d
......@@ -50,20 +50,20 @@ public class DBHandler {
return time;
}
public Long getPosX(String username) throws SQLException {
Long x = 0l;
public int getPosX(String username) throws SQLException {
int x = 0;
ResultSet result = statement.executeQuery("select posisi_x from user where username='"+username+"'");
while(result.next()) {
x = result.getLong("posisi_x");
x = result.getInt("posisi_x");
}
return x;
}
public Long getPosY(String username) throws SQLException {
Long y = 0l;
public int getPosY(String username) throws SQLException {
int y = 0;
ResultSet result = statement.executeQuery("select posisi_y from user where username='"+username+"'");
while(result.next()) {
y = result.getLong("posisi_y");
y = result.getInt("posisi_y");
}
return y;
}
......@@ -134,6 +134,15 @@ public class DBHandler {
return amount;
}
public int pickItem(String code) throws SQLException {
int item = 0;
ResultSet result = statement.executeQuery("select id from items where id_map='"+code+"'");
while(result.next()) {
item = result.getInt("id");
}
return item;
}
public void removefromInventory() {
}
......
......@@ -44,7 +44,7 @@ public class JSONParse {
}
//Respon JSON untuk login
public Map loginJSON(boolean valid, String token, Long x, Long y, Long time) {
public Map loginJSON(boolean valid, String token, int x, int y, Long time) {
Map response = new LinkedHashMap();
if (valid) {
......
......@@ -133,8 +133,8 @@ public class MethodHandler {
String password = parse.parseJSON(input, "password");
String token = genToken(username);
Long time = db.getTime(username);
Long x = db.getPosX(username);
Long y = db.getPosY(username);
int x = db.getPosX(username);
int y = db.getPosY(username);
log.setUsername(username); log.setToken(token);
session.add(log);
......@@ -249,7 +249,6 @@ public class MethodHandler {
height = json.getLong("height");
// loop array
field_map = json.getJSONArray("map");
System.out.println(field_map.getJSONArray(1).getString(1));
//externalMap.getJSONARRAY("map").getJSONARRAY(1).getString(2);
// String location = parse.parseJSON(input, "name");
......@@ -287,12 +286,20 @@ public class MethodHandler {
return JSONValue.toJSONString(response);
}
public String Field(String input) throws ParseException {
public String Field(String input) throws ParseException, SQLException, JSONException {
JSONParse parse = new JSONParse();
DBHandler db = new DBHandler();
Map response = new LinkedHashMap();
String token = parse.parseJSON(input, "token");
int item = 4;
String username = session.get(searchToken(token)).getUsername();
int x = db.getPosX(username);
int y = db.getPosY(username);
String s = field_map.getJSONArray(y).getString(x);
System.out.println(s);
int item = db.pickItem(s);
response = parse.fieldJSON(token, item, true);
System.out.println(JSONValue.toJSONString(response));
......
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