def show_map_callback():
    for p in DataStore.instance().data["all_players"]:
        conn = DataStore.instance().data["account_connection"][p.get_account()]
        for item in show_map(p):
            dest, msg = item
            if msg["map"] != {}:
                conn.push(dest, msg)
Exemple #2
0
def show_map_callback():
    for p in DataStore.instance().data["all_players"]:
        conn = DataStore.instance().data["account_connection"][p.get_account()]
        for item in show_map(p):
            dest, msg = item
            if msg["map"] != {}:
                conn.push(dest, msg)
Exemple #3
0
def login_handler(conn):
    while True:
        signed_username = yield
        signed_username = signed_username.replace('"', '')
        username = tornado.web.decode_signed_value(conn.application.settings["cookie_secret"], "user", signed_username)
        print(username.decode("utf-8"))
        acc = get(username.decode("utf-8"))
        if not acc == None:
            DataStore.instance().data["account_connection"][acc] = conn
            p = DataStore.instance().data["default_player"]
            DataStore.instance().add_player(p)
            p.set_account(acc)
            conn.set_data_handler(command_handler(p, conn))
Exemple #4
0
def login_handler(conn):
    while True:
        signed_username = yield
        signed_username = signed_username.replace('"', '')
        username = tornado.web.decode_signed_value(
            conn.application.settings["cookie_secret"], "user",
            signed_username)
        print(username.decode("utf-8"))
        acc = get(username.decode("utf-8"))
        if not acc == None:
            DataStore.instance().data["account_connection"][acc] = conn
            p = DataStore.instance().data["default_player"]
            DataStore.instance().add_player(p)
            p.set_account(acc)
            conn.set_data_handler(command_handler(p, conn))
Exemple #5
0
def show_map(p, size = (33, 20), args = None):
    pos = p.location
    cache_map = generate(pos, size, DataStore.instance().data["game_map"])
    norm_map = normalize(cache_map, p.get_location(), size)
    diff_map = diff(p.cache_map, norm_map)
    p.set_cache_map(norm_map)
    
    return ("gamemap", {"map": diff_map, "dir":p.direction}),
}

application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/websocket", EchoWebSocket),
    (r"/login", LoginHandler),
], **settings)


if __name__ == "__main__":
    ##Init
    
    gmap = GameMap(generate_sector, DataMap)
    
    #Global state
    DataStore.instance().data["game_map"] = gmap
    DataStore.instance().data["default_player"] = Player("Nicholas", (0, 0), gmap)
    DataStore.instance().data["default_player"].add_upgrade(Jetpack()) 
    DataStore.instance().data["all_players"] = []
    DataStore.instance().data["account_connection"] = {}
    
    
    application.listen(8888)
    gravity = tornado.ioloop.PeriodicCallback(gravity_callback, 500, tornado.ioloop.IOLoop.instance())
    send_map = tornado.ioloop.PeriodicCallback(show_map_callback, 50, tornado.ioloop.IOLoop.instance())
    send_inventory = tornado.ioloop.PeriodicCallback(inventory_callback, 1000, tornado.ioloop.IOLoop.instance())
    #db_dump = tornado.ioloop.PeriodicCallback(dump_to_db, 5000, tornado.ioloop.IOLoop.instance())
    #gravity.start()
    send_inventory.start()
    send_map.start()
    #db_dump.start()
Exemple #7
0
def gravity_callback():
    for p in DataStore.instance().data["all_players"]:
        gravity(p)
    "login_url": "/login",
}

application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/websocket", EchoWebSocket),
    (r"/login", LoginHandler),
], **settings)

if __name__ == "__main__":
    ##Init

    gmap = GameMap(generate_sector, DataMap)

    #Global state
    DataStore.instance().data["game_map"] = gmap
    DataStore.instance().data["default_player"] = Player(
        "Nicholas", (0, 0), gmap)
    DataStore.instance().data["default_player"].add_upgrade(Jetpack())
    DataStore.instance().data["all_players"] = []
    DataStore.instance().data["account_connection"] = {}

    application.listen(8888)
    gravity = tornado.ioloop.PeriodicCallback(gravity_callback, 500,
                                              tornado.ioloop.IOLoop.instance())
    send_map = tornado.ioloop.PeriodicCallback(
        show_map_callback, 50, tornado.ioloop.IOLoop.instance())
    send_inventory = tornado.ioloop.PeriodicCallback(
        inventory_callback, 1000, tornado.ioloop.IOLoop.instance())
    #db_dump = tornado.ioloop.PeriodicCallback(dump_to_db, 5000, tornado.ioloop.IOLoop.instance())
    #gravity.start()
def inventory_callback():
    for p in DataStore.instance().data["all_players"]:
        conn = DataStore.instance().data["account_connection"][p.get_account()]
        dest, msg = inv(p)
        conn.push(dest, msg)
        
Exemple #10
0
def inventory_callback():
    for p in DataStore.instance().data["all_players"]:
        conn = DataStore.instance().data["account_connection"][p.get_account()]
        dest, msg = inv(p)
        conn.push(dest, msg)