Commit 072ddf11 authored by mamat-rahmat's avatar mamat-rahmat
Browse files

benerin dikit

parent e0e93ba1
......@@ -4,6 +4,8 @@ import hashlib
import pymongo
import threading
from pymongo import MongoClient
import datetime
from random import randint
# informasi port dan socket
hostTracker = "167.205.32.46"
......@@ -252,7 +254,7 @@ def handler(a, c):
else:
response = '{"status" : "fail", "description" : "still available"}'
else:
response = "{'status' : 'fail','description':'not exists'}"
response = '{"status" : "fail", "description" : "not exists"}'
elif (method == "move"):
#from client
......@@ -305,8 +307,49 @@ def handler(a, c):
else:
response = '{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
elif (method == "map"):
response = '{"status" : "ok", "name" : "Bandar Behari", "width" : 5, "height" : 5}'
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=(',', ': '))
#for update
#kriteria1Object = {"$set":{"width":5}}
#kriteria2Object = {"$set":{"height":5}}
#database.playerCollection.update(kriteriaObject,kriteria1Object)
#database.playerCollection.update(kriteriaObject,kriteria2Object)
#response = '{"status" : "ok", "name" : ' + username + ', "width" : ' + str(width) + ', "height" : ' + str(height) + '}'
response = '{"status" : "ok", "name" : ' + username + ', "width" : 5, "height" : 5}'
elif (method == "offer"):
token = dataJSON["token"]
......@@ -356,13 +399,16 @@ def handler(a, c):
dictResponse = { "status" : "ok", "offers" : offer_self }
response = str(dictResponse)
elif (method == 'sendfind'):
token = dataJSON['token']
item = dataJSON['item']
kriteria1Object = {"offered_item" : item}
elif (method == "sendfind"):
# TODO : AMBIL DARI SEMUA SERVER
token = dataJSON["token"]
item = dataJSON["item"]
kriteria1Object = {"offered_item" : item}
offer_all = []
for temp in database.marketCollection.find(kriteria1Object):
for temp in database.offerCollection.find(kriteria1Object):
data = []
data.append( temp["offered_item"] )
data.append( temp["n_item1"] )
......@@ -370,14 +416,12 @@ def handler(a, c):
data.append( temp["n_item2"] )
data.append( temp["availability"] )
data.append( temp["offer_token"] )
offer_self.append(data)
offer_all.append(data)
dictResponse = { "status" : "ok", "offers" : offer_self }
dictResponse = { "status" : "ok", "offers" : offer_all }
response = str(dictResponse)
elif (method == 'findoffer'):
# TODO : AMBIL DARI SEMUA SERVER
item = dataJSON['item']
kriteria1Object = {"offered_item" : item}
......@@ -390,9 +434,9 @@ def handler(a, c):
data.append( temp["n_item2"] )
data.append( temp["availability"] )
data.append( temp["offer_token"] )
offer_self.append(data)
offer_all.append(data)
dictResponse = { "status" : "ok", "offers" : offer_self }
dictResponse = { "status" : "ok", "offers" : offer_all }
response = str(dictResponse)
elif (method == 'canceloffer'):
......
{
"height": 5,
"name": "tiga",
"map": [
[
9,
4,
6,
9,
2
],
[
2,
8,
4,
7,
0,
1,
4
9
],
[
2,
5,
0,
6,
7,
4
6,
1
],
[
1,
8,
7,
7,
2
3,
1,
1,
1
],
[
0,
1,
7,
5,
8,
3,
0
],
[
5,
9,
9,
4,
3
]
],
"name": "pulpen",
"width": 5,
"height": 5
"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