Commit 144160a2 authored by mamat-rahmat's avatar mamat-rahmat
Browse files

move to v2

parent 9ef63d65
......@@ -4,10 +4,7 @@ import hashlib
import pymongo
import threading
from pymongo import MongoClient
<<<<<<< HEAD
=======
import datetime
>>>>>>> 2e1c3f425d37b26acefb8d5cf9ad75f7635538c1
from random import randint
# informasi port dan socket
......@@ -258,22 +255,13 @@ def handler(a, c):
else:
response = '{"status" : "fail", "description" : "still available"}'
else:
<<<<<<< HEAD
response = "{'status' : 'fail','description':'not exists'}"
elif (method == "map"):
#tokem from client
token = dataJSON['token']
=======
response = '{"status" : "fail", "description" : "not exists"}'
elif (method == "move"):
#from client
token = dataJSON["token"]
posisiXnew = dataJSON["posisiX"]
posisiYnew = dataJSON["posisiY"]
>>>>>>> 2e1c3f425d37b26acefb8d5cf9ad75f7635538c1
#from database
kriteriaObject = {"token" : token}
user = database.playerCollection.find_one(kriteriaObject)
......@@ -301,7 +289,8 @@ def handler(a, c):
json.dump(data, f,
indent=4, separators=(',', ': '))
response = '{"status" : "ok", "name" : "' + username + '", "width" : 5, "height" : 5}'
elif (method == 'move'):
elif (method == "move"):
#from client
token = dataJSON['token']
posisiXnew = dataJSON['posisiX']
......@@ -331,11 +320,12 @@ def handler(a, c):
response = '{"status" : "ok", "time" : delta_milisecond}'
else:
response = '{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
elif (method == 'field'):
#from client
token = dataJSON['token']
posisiX = dataJSON['posisiX']
posisiY = dataJSON['posisiY']
posisiX = dataJSON['x']
posisiY = dataJSON['y']
#Datetime
current_time = datetime.datetime.now()
......@@ -358,54 +348,11 @@ def handler(a, c):
if (current_time >= time):
new_n_item = n_item+1;
database.inventoriCollection.update(kriteriaObject, {"$set":name_item_here:new_n_item}})
database.inventoriCollection.update(kriteriaObject, {"$set":{name_item_here:new_n_item}})
response = '{"status" : "ok", "item" : item_here}'
else:
<<<<<<< HEAD
response = '{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
=======
response = '{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
elif (method == "map"):
#random number for width and height
#width = randint(5,15)
#height = width
#tokem from client
token = dataJSON['token']
#from database
kriteriaObject = {"token" : token}
user = database.playerCollection.find_one(kriteriaObject)
username = user['username']
#kriteriaObject = {"token" : token}
#write json file
data={
'map' :
[
[randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9)],
[randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9)],
[randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9)],
[randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9)],
[randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9), randint(0, 9)]
],
'height' : 5,
'width' : 5,
'name' : username
}
map = json.dumps(data,
indent=4, separators=(',', ': '))
with open('map', 'w') as f:
json.dump(data, f,
indent=4, separators=(',', ': '))
response = '{"status" : "ok", "name" : "' + username + '", "width" : 5, "height" : 5}'
>>>>>>> 2e1c3f425d37b26acefb8d5cf9ad75f7635538c1
elif (method == "offer"):
token = dataJSON["token"]
offered_item = dataJSON["offered_item"]
......
192.168.0.113:8500
\ No newline at end of file
{
"name": "tujuh",
"height": 5,
"name": "pulpen",
"map": [
[
<<<<<<< HEAD
3,
7,
9,
8,
5
1,
1,
2
],
[
4,
0,
6,
9,
8,
3
6,
6
],
[
3,
8,
9,
0,
2
],
[
2,
1,
9,
1,
5
],
[
2,
9,
7,
2,
6,
5,
7
]
],
"width": 5
=======
7,
7,
7,
0,
1
],
[
0,
5,
5,
9,
8
],
[
2,
9,
5,
5,
3,
7,
0,
6
],
[
9,
0,
4,
5,
2,
6,
1
],
[
4,
1,
9,
4,
3
3,
0
]
],
"height": 5,
"width": 5,
"name": "tujuh"
>>>>>>> 2e1c3f425d37b26acefb8d5cf9ad75f7635538c1
"width": 5
}
\ No newline at end of file
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