-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
28 lines (23 loc) · 807 Bytes
/
server.py
File metadata and controls
28 lines (23 loc) · 807 Bytes
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
import tornado.tcpserver
from connection import Connection
from messages import EventHandler
class StorymodeTCPServer(tornado.tcpserver.TCPServer):
"""
TCPServer and in-memory world representation of the current daily
dungeon floor
"""
def __init__(self):
super().__init__()
self.connections = []
# handles location of the players so we only need
# to distribute messages to floors instead of everyone
self.floors = {}
self.event_handler = EventHandler(self)
@tornado.gen.coroutine
def handle_stream(self, stream, address):
"""
Called for each new connection, stream.socket is
a reference to socket object
"""
connection = Connection(self, stream)
yield connection.on_connect()