示例#1
0
    def on_close(self):
        if self.user:
            self.emit_for_room('user_quit', { 'user_id' : self.user_id })

        db_modifier.execute("UPDATE rooms_room SET online_amount = online_amount - 1 WHERE id = %s", self.room_id)

        connection_manager.remove_connection(self)
示例#2
0
    def process_login(self, user_id):
        if not user_id:
            self.emit('login_result', { 'result' : 0 })
        else:
            db_modifier.execute("UPDATE rooms_room SET online_amount = online_amount + 1 WHERE id = %s", self.room_id)

            self.user_id = int(user_id)

            user = user_manager.get_user_by_id(user_id)

            self.user = user

            connection_manager.add_user_room_connection(self)

            self.emit('login_result', { 'result' : 1, 'user_id' : self.user_id })
            self.on_room_state_request()

            self.emit_for_room('joined_user', user.json_representation)
示例#3
0
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)