def web_channel_handler(msg): if msg.kind == 'message': if msg.body == 'reload_games': game_manager.load_active_games() chat_manager.clear() user_manager.clear() connection_manager.emit_broadcast('reload') return m = re.match('room_deleted\:(\d+)', msg.body) if m: connection_manager.room_became_deleted(int(m.group(1))) m = re.match('room_private\:(\d+)', msg.body) if m: connection_manager.room_became_private(int(m.group(1))) m = re.match('kick_user_from_room\:(\d+)\:(\d+)', msg.body) if m: connection_manager.remove_user_from_room(int(m.group(1)), int(m.group(2)))
def start_server(): from app import settings game_manager.load_valid_words_from_file(settings.VALID_WORDS_FILENAME) game_manager.load_active_games() router = TornadioRouter(GameCatcher) app = tornado.web.Application(router.urls, socket_io_port=8001) from database import redis_subscriptions db_modifier.execute("UPDATE rooms_room SET online_amount = 0") tornado.ioloop.IOLoop.instance().add_callback( lambda: redis_subscriptions.subscribe('web_channel', lambda x: redis_subscriptions.listen(web_channel_handler)) ) #tornado.ioloop.IOLoop.instance().add_callback( # lambda: redis_subscriptions.subscribe('room_close', lambda x: redis_subscriptions.listen(room_close)) #) SocketServer(app)