Interface ISFSExtension

    • Method Detail

      • init

        void init()
        This method is called once by the Server after the Extension is instantiated.

        Here you can put all your Extension initialization code (e.g. add event listeners)
        Any exception that is uncaught in this method will result in a failure starting the Extension.

        Please note that when the Extension is initialized the server is still running the boot sequence and it's not yet ready to communicate with any clients. At this stage any API call that involves communication with clients will fail and should be avoided. You should instead add a listener for the SERVER_READY event and move your API calls there.

        An example of this is creating an NPC which requires that the server engine has completed the boot sequence. If you are creating dynamic rooms you should make sure to specify that you don't want to send a client side update (remember at this time no user is connected so there's no use for this)

      • destroy

        void destroy()
        This method is called once by the Server when the Extension must be shut down (e.g. before a server restart or before the Extension code is reloaded)

        Here you can put all the necessary code to release any resources that was acquired/started in the init() method. (e.g. event listeners, threads, scheduled tasks, files etc...)

      • getName

        java.lang.String getName()
        The extension name
        Returns:
        the extension name
      • setName

        void setName​(java.lang.String name)
      • getExtensionFileName

        java.lang.String getExtensionFileName()
        Get the extension file name
        Returns:
        the Extension file name
      • setExtensionFileName

        void setExtensionFileName​(java.lang.String fileName)
      • getPropertiesFileName

        java.lang.String getPropertiesFileName()
        Get the name of the properties file that was loaded at init time.
        Returns:
        the name of the configuration properties file
      • setPropertiesFileName

        void setPropertiesFileName​(java.lang.String fileName)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • getConfigProperties

        java.util.Properties getConfigProperties()
        Returns a reference the Properties object loaded from the specified properties file.

        By default SmartFox will attempt to load a file called config.properties located in the Extension folder. Example: if your extension name is ChessGame the system will try to load extensions/ChessGame/config.properties

        No errors will be logged if the file is not found unless you have specified a custom properties file. In this case a warning will be logged if the file cannot be loaded.

        If the file is not found the method will return null

        Returns:
        the custom properties
      • isActive

        boolean isActive()
        Checks if the Extension is active. If not the Extension is not going to respond to any events and/or requests.
        Returns:
        true if the Extension is active.
      • setActive

        void setActive​(boolean flag)
      • setLevel

        void setLevel​(com.smartfoxserver.v2.extensions.ExtensionLevel level)
      • getLevel

        com.smartfoxserver.v2.extensions.ExtensionLevel getLevel()
        Return the level of the extension. There are only 2 levels:
        • Room: the extension is attached to a Room
        • Zone: the extension is attached to a Zone
        Returns:
        the extension Level
      • getType

        com.smartfoxserver.v2.extensions.ExtensionType getType()
      • setType

        void setType​(com.smartfoxserver.v2.extensions.ExtensionType type)
      • getParentZone

        Zone getParentZone()
        Return the parent Zone of the Extension.
        Returns:
        the Zone of the Extension
      • setParentZone

        void setParentZone​(Zone zone)
      • getParentRoom

        Room getParentRoom()
        Return the parent Room of the Extension. (valid only for Room-level extensions)
        Returns:
        the Room or null if this is not a Room-level extension
      • setParentRoom

        void setParentRoom​(Room room)
      • handleClientRequest

        void handleClientRequest​(java.lang.String cmdName,
                                 User sender,
                                 ISFSObject params)
                          throws SFSException
        This method is called whenever a client sends a request to this Extension
        Parameters:
        cmdName - the request command name
        sender - the sender of the request
        params - the custom parameters of the request
        Throws:
        SFSException
      • handleInternalMessage

        java.lang.Object handleInternalMessage​(java.lang.String cmdName,
                                               java.lang.Object params)
        This method can be invoked across different Extensions. It can be used as a mean of inter-operability between multiple Extensions
        Parameters:
        cmdName - a command name
        params - custom parameters
      • send

        void send​(java.lang.String cmdName,
                  ISFSObject params,
                  User recipient,
                  boolean useUDP)
        Send an extension message/response to a single User
        Parameters:
        cmdName - the command name
        params - custom parameters
        recipient - the recipient of the message
        useUDP - send as UDP packet
      • send

        void send​(java.lang.String cmdName,
                  ISFSObject params,
                  User recipient)
      • send

        void send​(java.lang.String cmdName,
                  ISFSObject params,
                  java.util.List<User> recipients,
                  boolean useUDP)
        Send an extension message/response to a list of recipients
        Parameters:
        cmdName - the command name
        params - custom parameters
        recipients - the list of recipients
        useUDP - send as UDP packet
      • send

        void send​(java.lang.String cmdName,
                  ISFSObject params,
                  java.util.List<User> recipients)