-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayground.py
92 lines (71 loc) · 2.67 KB
/
playground.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
'''
battle.ai
playground is ai battle framework for
1:1:1:1: ... turn game.
'''
import os.path
import sys
import tornado.ioloop
import tornado.options
import tornado.web
import pymongo
sys.path.insert(0, '../')
# TODO : find out how to control path and error
from server.db.dbhelper import DBHelper
from server.handler.playerhandler import PlayerHandler
from server.handler.gameobserverhandler import GameObserverHandler
from server.handler.observerhandler import ObserverHandler
from server.conf.conf_reader import ConfigReader
from server.handler.webpagehandler import *
from server.handler.lobbyhandler import LobbyHandler
from pymongo import MongoClient
class Playground(tornado.web.Application):
def __init__(self):
# TODO: game_logic selection must be added, tcp_port, web_port, playing game will be argument of playground.py
self.game_server = PlayerHandler()
self.db = pymongo.MongoClient()
self.handler = [
# websocket handler
(r"/websocket", ObserverHandler),
(r"/game/socket", GameObserverHandler),
(r"/lobby/socket", LobbyHandler),
# web page handler
(r"/", LoginPageHandler),
(r"/lobby", LobbyPageHandler),
(r"/mypage", MyPageHandler),
(r"/game", GamePageHandler),
# lobby request handler
(r"/lobby/game/request", MatchHandler),
# signup signin logout request
(r"/auth/signin", SignInHandler),
(r"/auth/signup", SignUpHandler),
(r"/auth/logout", LogoutHandler),
]
self.setting = dict(
title=u"Battle.ai",
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
# will be xsrf_cookies=True...... soon
cookie_secret="123",
login_url="/auth/login",
debug=True,
)
super(Playground, self).__init__(self.handler, **self.setting)
self.db = MongoClient()["battle"]
DBHelper.instance().initialize(self.db)
def main():
config = ConfigReader()
config_value = config.read()
tcp_port = config_value["tcp_port"]
web_port = config_value["web_port"]
tornado.options.parse_command_line()
tornado.options.parse_config_file("my.conf")
app = Playground()
app.game_server.listen(tcp_port)
app.listen(web_port)
print("******************* Battle.AI operate *******************")
print(" ...... Created By GreedyOsori ......\n")
print("Version 0.0")
tornado.ioloop.IOLoop.current().start()
if __name__ == "__main__":
main()