forked from notbaab/TiledPlatformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_node.py
56 lines (51 loc) · 1.52 KB
/
render_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import networking as n
import displayplatformer
import time
import json
import socket
import sys
json_file = open('network_settings.json', "r+")
network_settings = json.load(json_file)
my_ip_address = ''
if network_settings['localhost'] == "True":
if len(sys.argv) != 3:
print ("Network_settings curretly set to localhost, need an x and a y argument. Run `python render_node.py x y")
sys.exit()
xindx = int(sys.argv[1])
yindx = int(sys.argv[2])
json_file.seek(0) # lazy pass to game.py
data = {"localhost": "True", "x":str(xindx), "y":str(yindx)}
json.dump(data, json_file)
json_file.close()
my_ip_address = 'localhost'
# TODO: Figure out tile location based on hostname
if __name__ == '__main__':
if not my_ip_address == 'localhost':
myhostname = socket.gethostname()
(_,xindx,yindx) = myhostname.split('-')
xindx = int(xindx)
yindx = int(yindx)
print (yindx)
print (xindx)
first_hit = False
for line in open('/etc/hosts').readlines():
if line.find(myhostname) > -1:
my_ip_address = line.split()[0]
break
if yindx == 2:
yindx = 0
elif yindx == 0:
yindx = 2
game = displayplatformer.ClientPlatformer([xindx, yindx])
connected = False
print (my_ip_address)
while not connected:
try:
server = n.Server(my_ip_address, 2000, game)
connected = True
except Exception:
time.sleep(.5)
print(server.socket)
server.open_connection() # open and receive the first data packet
while True:
server.recev_connection()