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
934410e4
Commit
934410e4
authored
Apr 26, 2015
by
Tegar Aji Pangestu
Browse files
Merge branch 'master' of
http://gitlab.informatika.org/lancarjodoh/IF3230-Tugas-Besar-Sister-2015
parents
03005122
5a257e08
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/server/mainserver_nonthread.py
View file @
934410e4
...
...
@@ -10,12 +10,13 @@ hostTracker = "167.205.32.46"
portTracker
=
8000
hostLaptop
=
""
# config MongoDB
database
=
''
playerCollection
=
''
inventoriCollection
=
''
offerCollection
=
''
marketCollection
=
''
# list server yang aktif
listActiveServer
=
[]
def
createDatabase
():
...
...
@@ -65,6 +66,7 @@ def getItemName(index):
def
join
(
portLaptop
):
print
(
"join"
)
listActiveServer
=
[]
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
((
hostTracker
,
portTracker
))
...
...
@@ -74,7 +76,13 @@ def join(portLaptop):
s
.
send
(
str
.
encode
(
message
))
tm
=
s
.
recv
(
4096
)
print
(
tm
.
decode
(
'utf-8'
))
tmString
=
tm
.
decode
(
'utf-8'
)
tmJSON
=
json
.
JSONDecoder
().
decode
(
tmString
)
# update list server aktif
listServer
=
tmJSON
[
"value"
]
global
listActiveServer
for
ip
in
listServer
:
listActiveServer
.
append
(
ip
[
"ip"
])
s
.
close
()
...
...
@@ -88,12 +96,7 @@ def join(portLaptop):
#s.connect((,portTracker))
def
playserver
(
portLaptop
):
#global database
#global playerCollection
#global inventoriCollection
#global offerCollection
#global marketCollection
# config database mongodb
client
=
MongoClient
(
'localhost'
,
27107
)
database
=
client
[
'quest'
]
playerCollection
=
database
[
'player'
]
...
...
@@ -101,8 +104,8 @@ def playserver(portLaptop):
offerCollection
=
database
[
'offer'
]
marketCollection
=
database
[
'market'
]
# Mulai open socket server
print
(
"playserver"
)
print
(
hostLaptop
)
s
=
socket
.
socket
()
s
.
bind
((
hostLaptop
,
portLaptop
))
s
.
listen
(
5
)
# tunggu koneksi dari socket client
...
...
@@ -147,11 +150,13 @@ def playserver(portLaptop):
# tulis response
response
=
"{'status' : 'ok'}"
elif
(
method
==
'serverStatus'
):
status
=
"error"
global
listActiveServer
del
listActiveServer
[:]
# hapus list
#update ulang list server aktif
for
server
in
dataJSON
[
'server'
]:
if
((
server
[
'ip'
]
==
hostLaptop
)
a
nd
(
server
[
'port'
]
==
portLaptop
)):
status
=
"ok
"
response
=
"{'status':'"
+
status
+
"'}"
listActiveServer
.
appe
nd
(
server
[
"ip"
])
response
=
"{'status':'ok'}
"
print
(
listActiveServer
)
elif
(
method
==
'login'
):
username
=
dataJSON
[
'username'
]
password
=
dataJSON
[
'password'
]
...
...
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