Esempio n. 1
0
 def __init__(self, config_file = "config.cfg", reporter = None):
     """
     Construct a world handler instance.  Also reads the configuration file and
     creates new handler objects that belong under main tasklet observation.
     @param config_file Configuration file to read.  The default file name is "config.cfg".
     """
     self.reporter = reporter;
     
     # Read the configuration file.
     self.config = Config.VTank_Config();
     if not self.config.read(config_file):
         raise Force_Exit_Exception, "Reading configuration file failed!";
     
     # Create a database object.
     self.database = Database(self.config.database_host, self.config.database_user, 
         self.config.database_passwd, self.config.database_name);
     
     if not self.database.connect():
         # Connection to DB failed! This is considered a fatal error.
         raise Force_Exit_Exception, "Unable to connect to database: " \
             + str(self.database.get_last_error());
             
     Equipment_Manager.set_manager(Equipment_Manager._Manager(self.database));
     
     self.initialize_ice();
     
     self.client_tracker = Client_Tracker(self.config, self.database, reporter);
     
     # Prevent constructor from being called again.
     World_Handler.__init__ = World_Handler.__nomore__;
Esempio n. 2
0
    def __init__(self, config_file="config.cfg", reporter=None):
        """
        Construct a world handler instance.  Also reads the configuration file and
        creates new handler objects that belong under main tasklet observation.
        @param config_file Configuration file to read.  The default file name is "config.cfg".
        """
        self.reporter = reporter

        # Read the configuration file.
        self.config = Config.VTank_Config()
        if not self.config.read(config_file):
            raise Force_Exit_Exception, "Reading configuration file failed!"

        # Create a database object.
        self.database = Database(self.config.database_host,
                                 self.config.database_user,
                                 self.config.database_passwd,
                                 self.config.database_name)

        if not self.database.connect():
            # Connection to DB failed! This is considered a fatal error.
            raise Force_Exit_Exception, "Unable to connect to database: " \
                + str(self.database.get_last_error())

        Equipment_Manager.set_manager(Equipment_Manager._Manager(
            self.database))

        self.initialize_ice()

        self.client_tracker = Client_Tracker(self.config, self.database,
                                             reporter)

        # Prevent constructor from being called again.
        World_Handler.__init__ = World_Handler.__nomore__
Esempio n. 3
0
 def validate_tank_attributes(self, tank):
     """
     Validate the given set of tank attributes.
     """
     # Extract attributes.
     weapon_id   = tank.weaponID;
     speed_factor= tank.speedFactor;
     armor_factor= tank.armorFactor;
     color       = tank.color;
     model       = tank.model;
     skin        = tank.skin;
     
     manager = Equipment_Manager.get_manager();
     weapon = manager.get_weapon(weapon_id);
     if weapon == None:
         # Weapon doesn't exist.
         Log.quick_log("User %s was able to send through an invalid weapon ID (%i)." % (
             self, weapon_id));
         raise BadInformationException("Bad weapon ID.");
     
    
     if speed_factor < 0.5 or speed_factor > 1.5 or armor_factor < 0.5 or armor_factor > 1.5:
         # Invalid factor values.
         Log.quick_log("User %s was able to send through an invalid speed_factor/armor_factor." % self);
         raise BadInformationException("Minimum/Maximum allowed speed/armor breached.");
     
     difference_speed = math.fabs(1.0 - round(speed_factor, 2));
     difference_armor = math.fabs(1.0 - round(armor_factor, 2));
     if difference_speed - difference_armor > 0.001:
         Log.quick_log("User %s was able to send through an invalid speed_factor/armor_factor." % self);
         raise BadInformationException("Speed-to-armor ratio must have exactly the same distance from 100%.");
     
     if model == "":
         raise BadInformationException("Invalid model (%s)." % model);
Esempio n. 4
0
 def update_game_server_utilities(self):
     """
     Get the list of game servers and notify them of the current utility 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().UpdateUtilities(Equipment_Manager.get_manager().get_utilities_list());
Esempio n. 5
0
 def update_game_server_utilities(self):
     """
     Get the list of game servers and notify them of the current utility 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().UpdateUtilities(
                 Equipment_Manager.get_manager().get_utilities_list())
Esempio n. 6
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);
Esempio n. 7
0
    def validate_tank_attributes(self, tank):
        """
        Validate the given set of tank attributes.
        """
        # Extract attributes.
        weapon_id = tank.weaponID
        speed_factor = tank.speedFactor
        armor_factor = tank.armorFactor
        color = tank.color
        model = tank.model
        skin = tank.skin

        manager = Equipment_Manager.get_manager()
        weapon = manager.get_weapon(weapon_id)
        if weapon == None:
            # Weapon doesn't exist.
            Log.quick_log(
                "User %s was able to send through an invalid weapon ID (%i)." %
                (self, weapon_id))
            raise BadInformationException("Bad weapon ID.")

        if speed_factor < 0.5 or speed_factor > 1.5 or armor_factor < 0.5 or armor_factor > 1.5:
            # Invalid factor values.
            Log.quick_log(
                "User %s was able to send through an invalid speed_factor/armor_factor."
                % self)
            raise BadInformationException(
                "Minimum/Maximum allowed speed/armor breached.")

        difference_speed = math.fabs(1.0 - round(speed_factor, 2))
        difference_armor = math.fabs(1.0 - round(armor_factor, 2))
        if difference_speed - difference_armor > 0.001:
            Log.quick_log(
                "User %s was able to send through an invalid speed_factor/armor_factor."
                % self)
            raise BadInformationException(
                "Speed-to-armor ratio must have exactly the same distance from 100%."
            )

        if model == "":
            raise BadInformationException("Invalid model (%s)." % model)
Esempio n. 8
0
    def GetUtilitiesList(self, current=None):
        self.refresh_action()

        manager = Equipment_Manager.get_manager()
        return manager.get_utilities_list().values()
Esempio n. 9
0
 def GetUtilitiesList(self, current=None):
     self.refresh_action();
     
     manager = Equipment_Manager.get_manager();
     return manager.get_utilities_list().values();