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
b2b69cd2
Commit
b2b69cd2
authored
Apr 26, 2015
by
mamat-rahmat
Browse files
tambah punya linda
parent
63140f6c
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/server/mainserver_thread_v2.py
View file @
b2b69cd2
...
...
@@ -266,6 +266,11 @@ def handler(a, c):
kriteriaObject
=
{
"token"
:
token
}
user
=
database
.
playerCollection
.
find_one
(
kriteriaObject
)
username
=
user
[
'username'
]
#inisialisasi player_time
current_time
=
datetime
.
datetime
.
now
()
current_time_ep
=
(
current_time
-
datetime
.
datetime
(
1970
,
1
,
1
)).
total_seconds
()
database
.
playerCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
"player_time"
:
current_time_ep
}})
#write json file
data
=
{
...
...
@@ -289,7 +294,6 @@ def handler(a, c):
json
.
dump
(
data
,
f
,
indent
=
4
,
separators
=
(
','
,
': '
))
response
=
'{"status" : "ok", "name" : "'
+
username
+
'", "width" : 5, "height" : 5}'
elif
(
method
==
"move"
):
#from client
token
=
dataJSON
[
'token'
]
...
...
@@ -303,21 +307,24 @@ def handler(a, c):
height
=
5
posisiX
=
user
[
'posisiX'
]
posisiY
=
user
[
'posisiY'
]
time
=
user
[
'player_time'
]
#comparing datetime
if
(
current_time
>
time
):
current_time
=
datetime
.
datetime
.
now
()
current_time_ep
=
(
current_time
-
datetime
.
datetime
(
1970
,
1
,
1
)).
total_seconds
()
if
(
current_time_ep
>
time
):
#comparing position
if
((
posisiX
>=
0
)
and
(
posisiY
>=
0
)
and
(
posisiXnew
<
5
)
and
(
posisiYnew
<
5
)):
#datetime
current_time
=
datetime
.
datetime
.
now
()
move_time
=
1
delta_second
=
(
move_time
*
(
abs
(
posisiXnew
-
posisiX
)
+
abs
(
posisiYnew
-
posisiY
)))
delta_milisecond
=
delta_second
*
1000
time
=
current_time
+
datetime
.
timedelta
(
seconds
=
delta_second
)
time
=
current_time
_ep
+
datetime
.
timedelta
(
seconds
=
delta_second
)
#update database for player_time
database
.
playerCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
"player_time"
:
time
}})
response
=
'{"status" : "ok", "time" :
delta_milisecond
}'
response
=
'{"status" : "ok", "time" :
'
+
time
+
'
}'
else
:
response
=
'{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
...
...
@@ -329,6 +336,8 @@ def handler(a, c):
#Datetime
current_time
=
datetime
.
datetime
.
now
()
current_time_ep
=
(
current_time
-
datetime
.
datetime
(
1970
,
1
,
1
)).
total_seconds
()
kriteriaObject
=
{
'token'
:
token
}
user
=
database
.
playerCollection
.
find_one
(
kriteriaObject
)
time
=
user
[
'player_time'
]
...
...
@@ -346,7 +355,7 @@ def handler(a, c):
#update database inventory
kriteriaObject
=
{
"token"
:
token
}
if
(
current_time
>=
time
):
if
(
current_time
_ep
>=
time
):
new_n_item
=
n_item
+
1
;
database
.
inventoriCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
name_item_here
:
new_n_item
}})
response
=
'{"status" : "ok", "item" : item_here}'
...
...
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