-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (50 loc) · 1.25 KB
/
main.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
#!/usr/bin/env python
import threading
import socket
import tcpserver
import webserver
import game_db
class TcpThread(threading.Thread):
def __init__(self, opts, db, port):
threading.Thread.__init__(self)
self.server = tcpserver.TCPGameServer( opts, db, port )
def run(self):
self.server.serve()
class WebThread(threading.Thread):
def __init__(self, opts, db, port):
threading.Thread.__init__(self)
self.server = webserver.AntsGameServer(('', port), webserver.AntsGameHandler)
self.server.db = db
self.server.opts = opts
def run(self):
self.server.serve_forever()
def main():
web_port = 2080
tcp_port = 2081
tcp_opts = {
'turns':350,
'loadtime': 3000,
'turntime': 2000,
'viewradius2': 55,
'spawnradius2': 1,
'attackradius2': 5,
'attack': 'power',
'food': 'symmetric',
# non-game args
'db_max_games': 100, #how many games should be kept on the webserver
}
web_opts = {
'style': 'light',
'host': socket.gethostname(),
}
db = game_db.load()
tcp = TcpThread( tcp_opts, db, tcp_port )
web = WebThread( web_opts, db, web_port )
try:
tcp.start()
web.start()
except:
game_db.save( db )
raise
if __name__ == "__main__":
main()