Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
lancarjodoh
IF3230-Tugas-Besar-Sister-2015
Commits
56881e9f
Commit
56881e9f
authored
Apr 26, 2015
by
Linda Sekawati
Browse files
Bentar
parents
daaf65d9
2e1c3f42
Changes
2
Hide whitespace changes
Inline
Side-by-side
bin/server/mainserver_thread.py
View file @
56881e9f
...
...
@@ -4,6 +4,10 @@ import hashlib
import
pymongo
import
threading
from
pymongo
import
MongoClient
<<<<<<<
HEAD
=======
import
datetime
>>>>>>>
2e1
c3f425d37b26acefb8d5cf9ad75f7635538c1
from
random
import
randint
# informasi port dan socket
...
...
@@ -114,7 +118,8 @@ def handler(a, c):
#process request
method
=
dataJSON
[
'method'
]
response
=
""
# response from server to client
response
=
'{"status" : "error"}'
# response from server to client
if
(
method
==
"signup"
):
username
=
dataJSON
[
"username"
]
password
=
dataJSON
[
"password"
]
...
...
@@ -253,11 +258,22 @@ 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"
]
>>>>>>>
2e1
c3f425d37b26acefb8d5cf9ad75f7635538c1
#from database
kriteriaObject
=
{
"token"
:
token
}
user
=
database
.
playerCollection
.
find_one
(
kriteriaObject
)
...
...
@@ -345,7 +361,51 @@ def handler(a, c):
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}'
>>>>>>>
2e1
c3f425d37b26acefb8d5cf9ad75f7635538c1
elif
(
method
==
"offer"
):
token
=
dataJSON
[
"token"
]
offered_item
=
dataJSON
[
"offered_item"
]
...
...
@@ -394,13 +454,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
.
market
Collection
.
find
(
kriteria1Object
):
for
temp
in
database
.
offer
Collection
.
find
(
kriteria1Object
):
data
=
[]
data
.
append
(
temp
[
"offered_item"
]
)
data
.
append
(
temp
[
"n_item1"
]
)
...
...
@@ -408,14 +471,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
}
...
...
@@ -428,9 +489,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'
):
...
...
bin/server/map
View file @
56881e9f
...
...
@@ -3,6 +3,7 @@
"name": "pulpen",
"map": [
[
<<<<<<< HEAD
3,
7,
9,
...
...
@@ -39,4 +40,44 @@
]
],
"width": 5
=======
7,
7,
7,
0,
1
],
[
0,
5,
5,
9,
8
],
[
2,
9,
5,
5,
6
],
[
9,
0,
4,
6,
1
],
[
4,
1,
9,
4,
3
]
],
"height": 5,
"width": 5,
"name": "tujuh"
>>>>>>> 2e1c3f425d37b26acefb8d5cf9ad75f7635538c1
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment