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
fc044b86
Commit
fc044b86
authored
Apr 28, 2015
by
Steve Immanuel Harnadi
Browse files
Pindah server
parent
48e17521
Changes
3
Hide whitespace changes
Inline
Side-by-side
bin/server/mainserver_thread_v2.py
View file @
fc044b86
...
...
@@ -21,6 +21,7 @@ marketCollection = ""
listActiveServer
=
[]
# jenis item
items
=
[
"honey"
,
"herbs"
,
"clay"
,
"mineral"
,
"potion"
,
"incense"
,
"gems"
,
"elixir"
,
"crystal"
,
"stone"
]
canField
=
False
def
createDatabase
():
global
database
...
...
@@ -62,7 +63,7 @@ def join(portLaptop):
# update list server aktif
listActiveServer
=
tmJSON
[
"value"
]
print
(
listActiveServer
)
s
.
close
()
# jalankan thread server utama
...
...
@@ -315,25 +316,32 @@ def handler(a, c):
if
(
current_time_ep
>
time
):
#comparing position
if
((
posisiX
>=
0
)
and
(
posisiY
>=
0
)
and
(
posisiXnew
<
5
)
and
(
posisiYnew
<
5
)):
if
((
posisiX
new
>=
0
)
and
(
posisiY
new
>=
0
)
and
(
posisiXnew
<
5
)
and
(
posisiYnew
<
5
)):
#datetime
move_time
=
1
delta_second
=
(
move_time
*
(
abs
(
posisiXnew
-
posisiX
)
+
abs
(
posisiYnew
-
posisiY
)))
delta_milisecond
=
delta_second
*
1000
time
=
current_time_ep
+
datetime
.
timedelta
(
seconds
=
delta_second
)
#delta_second = (move_time * (abs(posisiXnew-posisiX) + abs(posisiYnew-posisiY)))
time
=
current_time_ep
+
10
global
canField
canField
=
True
#update database for player_time
database
.
playerCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
"player_time"
:
time
}})
response
=
'{"status" : "ok", "time" : '
+
time
+
'}'
database
.
playerCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
"player_time"
:
time
}})
database
.
playerCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
"posisiX"
:
posisiXnew
}})
database
.
playerCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
"posisiY"
:
posisiYnew
}})
response
=
'{"status" : "ok", "time" : '
+
str
(
time
)
+
'}'
else
:
response
=
'{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
elif
(
method
==
'field'
):
#from client
token
=
dataJSON
[
'token'
]
posisiX
=
dataJSON
[
'x'
]
posisiY
=
dataJSON
[
'y'
]
# Dapatkan posisi X dan Y pemain
playerStatus
=
database
.
playerCollection
.
find_one
({
"token"
:
token
})
X
=
playerStatus
[
"posisiX"
]
Y
=
playerStatus
[
"posisiY"
]
#Datetime
current_time
=
datetime
.
datetime
.
now
()
current_time_ep
=
(
current_time
-
datetime
.
datetime
(
1970
,
1
,
1
)).
total_seconds
()
...
...
@@ -345,7 +353,7 @@ def handler(a, c):
#from map.json
with
open
(
'map'
,
'r'
)
as
f
:
field_item
=
json
.
load
(
f
)
item_here
=
field_item
[
"map"
][
posisiY
][
posisi
X
]
item_here
=
field_item
[
"map"
][
Y
][
X
]
#item
name_item_here
=
getItemName
(
item_here
)
...
...
@@ -355,10 +363,11 @@ def handler(a, c):
#update database inventory
kriteriaObject
=
{
"token"
:
token
}
if
(
current_time_ep
>=
time
):
if
(
(
current_time_ep
>=
time
)
and
canField
)
:
new_n_item
=
n_item
+
1
;
database
.
inventoriCollection
.
update
(
kriteriaObject
,
{
"$set"
:{
name_item_here
:
new_n_item
}})
response
=
'{"status" : "ok", "item" : item_here}'
canField
=
False
response
=
'{"status" : "ok", "item" :'
+
str
(
item_here
)
+
'}'
else
:
response
=
'{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
...
...
@@ -543,6 +552,7 @@ def handler(a, c):
response
=
"{'status' : 'ok'}"
else
:
response
=
"{'status' : 'fail', 'description' : 'not exists'}"
s2
.
close
()
elif
(
method
==
'accept'
):
offer_token
=
dataJSON
[
'offer_token'
]
...
...
bin/server/map
View file @
fc044b86
{
"
width
": 5,
"
height
": 5,
"map": [
[
4,
6,
3,
5,
8
7,
9,
7,
7
],
[
1
,
7
,
6,
4,
5,
8,
9
2
],
[
2
,
1
,
8
,
9
,
0
,
6
,
7,
9
1
],
[
0
,
7
,
7
,
1
,
2
6
,
6
,
6
,
3
,
5
],
[
8
,
7
,
1
,
5
,
1
3
,
9
,
6
,
3
,
5
]
],
"name": "
hihi
",
"
height
": 5
"name": "
kamu3
",
"
width
": 5
}
\ No newline at end of file
doc/~$poran Tugas Besar Grand Quest.docx
0 → 100644
View file @
fc044b86
File added
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