Commit 934410e4 authored by Tegar Aji Pangestu's avatar Tegar Aji Pangestu
Browse files
parents 03005122 5a257e08
......@@ -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) and (server['port'] == portLaptop)):
status = "ok"
response = "{'status':'" + status + "'}"
listActiveServer.append(server["ip"])
response = "{'status':'ok'}"
print(listActiveServer)
elif (method == 'login'):
username = dataJSON['username']
password = dataJSON['password']
......
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