示例#1
0
    def DownloadMap(self, mapName, current=None):
        self.refresh_action()

        self.report("%s wants to download the map, %s." % (self.name, mapName))
        map = Map_Manager.get_manager().get_map_by_filename(mapName)
        if not map:
            raise BadInformationException("That map does not exist.")

        vtank_map = VTankObject.Map()
        tiles = []
        for tile in map.tiles:
            tiles.append(
                VTankObject.Tile(tile.tile_id, tile.object_id, tile.event_id,
                                 tile.collision, tile.height, tile.type,
                                 tile.effect))

        vtank_map.version = map.version
        vtank_map.title = map.get_title()
        vtank_map.filename = mapName
        vtank_map.width = map.map_width
        vtank_map.height = map.map_height
        vtank_map.tileData = tiles
        vtank_map.supportedGameModes = map.game_modes

        return vtank_map
示例#2
0
 def update_game_server_maps(self):
     """
     Get the list of game play servers and notify them of the new map list.
     """
     clients = self.client_tracker.get_everyone();
     for client in clients.values():
         if client.get_type() == THEATRE_CLIENT_TYPE:
             c = client.get();
             c.get_callback().UpdateMapList(Map_Manager.get_manager().get_map_list());
示例#3
0
 def update_game_server_maps(self):
     """
     Get the list of game play servers and notify them of the new map list.
     """
     clients = self.client_tracker.get_everyone()
     for client in clients.values():
         if client.get_type() == THEATRE_CLIENT_TYPE:
             c = client.get()
             c.get_callback().UpdateMapList(
                 Map_Manager.get_manager().get_map_list())
示例#4
0
    def Join(self, servername, secret, port, usingGlacier2, 
             glacier2Host, glacier2Port, client, current=None):
        if client == None:
            # Client callback class cannot be null.
            raise BadInformationException("No callback is set.");
        
        host = Utils.extract_remote_addr(current);
        allowed = self.config.allow_unapproved_game_servers;
        
        self.report("Attempted connection from a game server from %s: %s" % (str(host), servername));
        
        approved = True;
        if host not in self.config.approved:
            # Unapproved game server.
            approved = False;
            
        if not allowed:
            # Unapproved game servers are not allowed.
            Log.quick_log("Server %s tried to log in as a game server but is not allowed." % servername);
            raise PermissionDeniedException("Unauthorized login attempt.");
        
        # Compare the secrets.
        if secret != self.config.server_secret:
            # Secret does not match.
            Log.quick_log("Server %s tried to log in as a game server but had a bad secret." % servername);
            raise PermissionDeniedException("Bad secret.");
        
        session = MTGSession(servername, port, approved, usingGlacier2, glacier2Host, glacier2Port, 
                             client, current.con.toString(), self.reporter);
                             
        ice_object = current.adapter.addWithUUID(session);
        id = ice_object.ice_getIdentity();
        
        session.set_id(id);
        
        self.add(id, Client(THEATRE_CLIENT_TYPE, session, servername));
        
        self.report("%s (%s) logged in." % (session, THEATRE_CLIENT_TYPE));
        Log.quick_log("%s joined as a game server." % servername);
        
        client.UpdateMapList(Map_Manager.get_manager().get_map_list());
        client.UpdateUtilities(Equipment_Manager.get_manager().get_utilities_list());
        
        return MainToGameSession.MTGSessionPrx.uncheckedCast(ice_object);
    
	def HealthMonitorLogin(username, password, current=None):
		if not password:
            raise BadInformationException("Bad username or password.");
			
		self.helper_validate_name(username);
		
		ice_object = current.adapter.addWithUUID(session);
 def UploadMap(self, map, current=None):
     self.report("%s wants to upload the map, %s." % (self.name, map.filename));
     # Validate.
     if not map.title:
         raise BadInformationException("Map is corrupted: Title cannot be blank.");
     
     if map.width <= 0 or map.height <= 0:
         raise BadInformationException("Map is corrupted: width/height <= 0.");
     
     if not len(map.tileData):
         raise BadInformationException("Map is corrupted: has no tiles!");
     
     map_obj = _Map.Map(self.reporter);
     map_obj.create_from_ice_object(map);
     
     if not Map_Manager.get_manager().save(map.filename, map_obj):
         raise BadInformationException("Database upload failed: error unknown.");
 def DownloadMap(self, mapName, current=None):
     self.report("%s wants to download the map, %s." % (self.name, mapName));
     map = Map_Manager.get_manager().get_map_by_filename(mapName);
     if not map:
         raise BadInformationException("That map does not exist.");
     
     vtank_map = Map();
     tiles = [];
     for tile in map.tiles:
         tiles.append(Tile(tile.tile_id, tile.object_id, tile.event_id, tile.collision,
                           tile.height, tile.type, tile.effect));
     
     vtank_map.title = map.get_title();
     vtank_map.filename = mapName;
     vtank_map.width = map.map_width;
     vtank_map.height = map.map_height;
     vtank_map.tileData = tiles;
     vtank_map.supportedGameModes = map.game_modes;
     
     return vtank_map;
示例#7
0
    def UploadMap(self, map, current=None):
        self.report("%s wants to upload the map, %s." %
                    (self.name, map.filename))
        # Validate.
        if not map.title:
            raise BadInformationException(
                "Map is corrupted: Title cannot be blank.")

        if map.width <= 0 or map.height <= 0:
            raise BadInformationException(
                "Map is corrupted: width/height <= 0.")

        if not len(map.tileData):
            raise BadInformationException("Map is corrupted: has no tiles!")

        map_obj = _Map.Map(self.reporter)
        map_obj.create_from_ice_object(map)

        if not Map_Manager.get_manager().save(map.filename, map_obj):
            raise BadInformationException(
                "Database upload failed: error unknown.")
示例#8
0
    def HashIsValid(self, mapFileName, hash, current=None):
        self.refresh_action()

        return Map_Manager.get_manager().check_hash(mapFileName, hash)
示例#9
0
    def GetMapList(self, current=None):
        self.refresh_action()

        return Map_Manager.get_manager().get_map_list()
示例#10
0
def main(argv=[]):
    """
    This is the first function called when the program starts.  Do all initialization here.
    @param argv Optionally pass the command-line arguments.
    @return Exit code.  0 for success, non-zero for unnatural exit.
    """
    # Write pid to file.
    if not os.path.exists("./logs"):
        os.mkdir("logs");
    
    run_unit_tests  = False;
    config_file     = os.path.abspath("config.cfg");
    debug_mode      = False;
    
    # The first argument isn't important to us -- it's the program's name.
    del argv[0];
    
    for arg in argv:
        if arg == "--test" or arg == "-t":
            # Testing mode enabled.  The server will not run; it will perform unit tests.
            run_unit_tests = True;
            
        elif arg.startswith("-p") or arg.startswith("--port"):
            # Let user know how to set a port.
            print "Port cannot be set through command line, look in the config file.";
            return 1;
        
        elif arg == "-d" or arg == "--debug":
            # Enable debugging.
            debug_reporter("Debug mode enabled.");
            debug_mode = True;
        
        elif arg == "--generate-config" or arg == "-g":
            # Generate a configuration file.
            temp_config = Config.VTank_Config();
            result = temp_config.generate_config(os.path.abspath(".") + os.sep + "config.cfg");
            debug_reporter("Result: %s" % result);
            return int(result);
        
        elif arg == "--load-slice" or arg == "-s":
            # Load slice dynamically without generating files.
            load_slice_files();
        
        elif arg.startswith("--config-file="):
            # User is specifying the config file's name.
            config_file = arg[len("--config-file="):];
            if not config_file:
                print "--config-file usage:";
                print "--config-file=[FILENAME]";
                return 1;
            
            if not os.path.exists(os.path.abspath(config_file)):
                print "Config file does not exist:", config_file;
                return 1;
            
            debug_reporter("Using config file " + config_file + ".");
            
        else:
            # Unknown.
            print "Unknown option:", arg, " -- ignoring it.";
            
    # Run unit testing here.
    if run_unit_tests:
        import Unit_Test;
        return Unit_Test.run_all_tests();
    
    import Log;
    import World;
    import Config;
    import Map_Manager;
    
    if debug_mode:
        reporter_func = debug_reporter;
    else:
        reporter_func = Log.log_reporter;
    
    # Start handling the world.
    try:
        World.initialize_world(config_file, reporter_func);
        world = World.get_world();
        Map_Manager.initialize(world.get_config(), world.get_database(), reporter_func);
        
        # Write the process ID of this server to file.
        file = open('echelon.pid', 'w');
        with file:
            file.write(str(os.getpid()));
            
        stackless.tasklet(VersionChecker.get_mysql_version)();
        stackless.run();
        
        # Unless some design changes, it will likely never reach this point.
        # Instead, it will be running through the stackless scheduler.
        reporter_func("Waiting for Ice shutdown.");
        World.get_world().get_communicator().waitForShutdown();
    except Force_Exit_Exception, e:
        Log.log_print("CRITICAL_ERROR.log", "", "Startup failure: " + str(e));
        reporter_func("Critical error occurred: " + str(e));
        from sys import exit;
        return e.exit_code;
示例#11
0
 def HashIsValid(self, mapFileName, hash, current=None):
     self.refresh_action();
     
     return Map_Manager.get_manager().check_hash(mapFileName, hash);
 def RemoveMap(self, mapName, current=None):
     if not Map_Manager.get_manager().delete(mapName):
         raise BadInformationException("Map does not exist.");
 def GetMapList(self, current=None):
     return Map_Manager.get_manager().get_map_list();
示例#14
0
 def GetMapList(self, current=None):
     return Map_Manager.get_manager().get_map_list()
示例#15
0
 def RemoveMap(self, mapName, current=None):
     if not Map_Manager.get_manager().delete(mapName):
         raise BadInformationException("Map does not exist.")
示例#16
0
 def GetMapList(self, current=None):
     self.refresh_action();
     
     return Map_Manager.get_manager().get_map_list();