-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlobby.py
91 lines (81 loc) · 2.7 KB
/
lobby.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import socket,os,thread,sys
from socket import *
from urllib import urlopen as get
envars = {}
f = open("lobby.cfg","r")
for i in f.readlines():
if i[0]!="#" and i!="\n":
g = i.split(": ")
envars[g[0]] = g[1].strip()
f.close()
sock = socket(AF_INET,SOCK_DGRAM)
sock.bind(('',int(envars["Port"])))
users = {}
addrs = {}
ready = False
ingame = False
status = "Lobby"
def run_game(pnum):
global ingame
ingame = True
for i in users.keys():
users[i][3] = "InGame"
for j in users:
for k in users:
sock.sendto("/player "+j+" "+users[j][1]+" "+users[j][2]+" "+users[j][3]+" "+users[j][4]+" "+str(users[j][5]).replace(" ","~"),users[k][0])
if sys.platform[0] == "w":
os.system("Python27\python.exe srv.py "+str(pnum))
else:
os.system("python srv.py "+str(pnum))
print "in"
ingame = False
for i in users.keys():
users[i][3] = "Prep"
for j in users:
for k in users:
sock.sendto("/player "+j+" "+users[j][1]+" "+users[j][2]+" "+users[j][3]+" "+users[j][4]+" "+str(users[j][5]).replace(" ","~"),users[k][0])
global status
status = "Lobby"
update(status)
def update(status):
try:
get("http://starfury.eu5.org/alter.php?name="+envars["Name"]+"&gamemode="+envars["Gamemode"]+"&map="+envars["Map"]+"&players="+str(len(users))+"/"+envars["Player Limit"]+"&status="+status+"&ip="+envars["IPv4"]+"&port="+envars["Port"])
except:
pass
update("Lobby")
while True:
inp,addr = sock.recvfrom(1024)
g = inp.split(" ")
if g[0][0] == "/":
if g[0] == "/player":
users[g[1]] = [addr,"fighter","1","Prep","0",["-1"]*14]
addrs[addr] = g[1]
for j in users:
sock.sendto("/player "+j+" "+users[j][1]+" "+users[j][2]+" "+users[j][3]+" "+users[j][4]+" "+str(users[j][5]).replace(" ","~"),addr)
update("Lobby")
if g[0] == "/team":
users[addrs[addr]][2] = g[1]
users[addrs[addr]][3] = "Prep"
if g[0] == "/class":
users[addrs[addr]][1] = g[1]
users[addrs[addr]][3] = "Prep"
if g[0] == "/hull":
users[addrs[addr]][4] = str(g[1])
users[addrs[addr]][3] = "Prep"
if g[0] == "/comp":
users[addrs[addr]][5][int(g[1])] = str(g[2])
users[addrs[addr]][3] = "Prep"
if g[0] == "/ready" and not ingame:
users[addrs[addr]][3] = g[1]
ready = True
for j in users:
sock.sendto("/player "+addrs[addr]+" "+users[addrs[addr]][1]+" "+users[addrs[addr]][2]+" "+users[addrs[addr]][3]+" "+users[addrs[addr]][4]+" "+str(users[addrs[addr]][5]).replace(" ","~"),users[j][0])
if users[j][3] == "Prep":
ready = False
if ready == True:
print "Game Starting..."
status = "In Game"
update("In Game")
for j in users:
sock.sendto("/start 8000",users[j][0])
thread.start_new(run_game,(len(users),))