Class BaseSFSExtension

  • All Implemented Interfaces:
    ISFSEventListener, ISFSExtension
    Direct Known Subclasses:
    SFSExtension

    public abstract class BaseSFSExtension
    extends java.lang.Object
    implements ISFSExtension, ISFSEventListener

    Overview

    The BaseSFSExtension provides the basic four methods already known in SmartFoxServer 1.x: init(), destroy(), handleClientRequest(), handleServerEvent(). We have included this class mainly for compatibility with the previous Extension model but we have also introduced a more powerful and high level class called SFSExtension
    See Also:
    SFSExtension
    • Field Detail

      • lagSimulationMillis

        protected volatile int lagSimulationMillis
        Experimental lag simulator.

        Set this value to any int > 0 and it will cause the current thread to delay any response by the amount of milliseconds specified.

        Default setting is == 0, no lag!

      • lagOscillation

        protected volatile int lagOscillation
      • logger

        protected final org.slf4j.Logger logger
      • sfsApi

        protected final ISFSApi sfsApi
        A reference to the SFS2X API
        See Also:
        SFSApi
    • Constructor Detail

      • BaseSFSExtension

        public BaseSFSExtension()
    • Method Detail

      • getCurrentFolder

        public java.lang.String getCurrentFolder()
        Return the relative path to the current extension folder
        Typically this will return: extensions/{name-of-extension}/
        The path is relative to the Server root folder and it can be used to load external data files that are stored together with the extension jar file(s)
        Returns:
        the relative path to the current extension folder
      • getName

        public java.lang.String getName()
        The extension name
        Specified by:
        getName in interface ISFSExtension
        Returns:
        the extension name
      • setName

        public void setName​(java.lang.String name)
        Specified by:
        setName in interface ISFSExtension
      • getExtensionFileName

        public java.lang.String getExtensionFileName()
        Get the extension file name
        Specified by:
        getExtensionFileName in interface ISFSExtension
        Returns:
        the Extension file name
      • getConfigProperties

        public 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

        Specified by:
        getConfigProperties in interface ISFSExtension
        Returns:
        the custom properties
      • getPropertiesFileName

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

        public void setPropertiesFileName​(java.lang.String fileName)
                                   throws java.io.IOException
        Specified by:
        setPropertiesFileName in interface ISFSExtension
        Throws:
        java.io.IOException
      • getApi

        public ISFSApi getApi()
        Get a reference to the main SFS2X Server API, which exposes useful methods for interacting with the server
        Returns:
        the API object
        See Also:
        ISFSApi
      • getBuddyApi

        public ISFSBuddyApi getBuddyApi()
        Get a reference to the SFS2X Buddy API, exposing useful methods for working with BuddyLists
        Returns:
        the API object
        See Also:
        ISFSBuddyApi
      • getGameApi

        public ISFSGameApi getGameApi()
        Get a reference to the SFS2X Game API, exposing useful methods for working with SFSGame classes, invitations and match making.
        Returns:
        the API object
        See Also:
        ISFSGameApi
      • getMMOApi

        public ISFSMMOApi getMMOApi()
        Get a reference to the SFS2X MMO API, exposing useful methods for working with MMORoom(s) and MMOItem(s) objects.
        Returns:
        the API object
        See Also:
        ISFSMMOApi
      • handleServerEvent

        public void handleServerEvent​(ISFSEvent event)
                               throws java.lang.Exception
        Handle server event
        Specified by:
        handleServerEvent in interface ISFSEventListener
        Parameters:
        event - the Event
        Throws:
        java.lang.Exception
        See Also:
        SFSEvent
      • handleInternalMessage

        public 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
        Specified by:
        handleInternalMessage in interface ISFSExtension
        Parameters:
        cmdName - a command name
        params - custom parameters
      • getParentRoom

        public Room getParentRoom()
        Return the parent Room of the Extension. (valid only for Room-level extensions)
        Specified by:
        getParentRoom in interface ISFSExtension
        Returns:
        the Room or null if this is not a Room-level extension
      • getParentZone

        public Zone getParentZone()
        Return the parent Zone of the Extension.
        Specified by:
        getParentZone in interface ISFSExtension
        Returns:
        the Zone of the Extension
      • isActive

        public boolean isActive()
        Checks if the Extension is active. If not the Extension is not going to respond to any events and/or requests.
        Specified by:
        isActive in interface ISFSExtension
        Returns:
        true if the Extension is active.
      • getLevel

        public 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
        Specified by:
        getLevel in interface ISFSExtension
        Returns:
        the extension Level
      • setLevel

        public void setLevel​(com.smartfoxserver.v2.extensions.ExtensionLevel level)
        Specified by:
        setLevel in interface ISFSExtension
      • getType

        public com.smartfoxserver.v2.extensions.ExtensionType getType()
        Specified by:
        getType in interface ISFSExtension
      • setType

        public void setType​(com.smartfoxserver.v2.extensions.ExtensionType type)
        Specified by:
        setType in interface ISFSExtension
      • send

        public void send​(java.lang.String cmdName,
                         ISFSObject params,
                         java.util.List<User> recipients)
        Specified by:
        send in interface ISFSExtension
      • send

        public 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
        Specified by:
        send in interface ISFSExtension
        Parameters:
        cmdName - the command name
        params - custom parameters
        recipients - the list of recipients
        useUDP - send as UDP packet
      • send

        public void send​(java.lang.String cmdName,
                         ISFSObject params,
                         User recipient,
                         boolean useUDP)
        Description copied from interface: ISFSExtension
        Send an extension message/response to a single User
        Specified by:
        send in interface ISFSExtension
        Parameters:
        cmdName - the command name
        params - custom parameters
        recipient - the recipient of the message
        useUDP - send as UDP packet
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getLogger

        public org.slf4j.Logger getLogger()
        Obtain a direct reference to the Extension's logger
        Returns:
        the logger object
      • trace

        public void trace​(java.lang.Object... args)
        Traces a message to the console and log files using the Logger INFO level
        Parameters:
        args - any number of strings/object to trace
      • trace

        public void trace​(ExtensionLogLevel level,
                          java.lang.Object... args)
        Trace a message to the console and log files using the specified logging level
        Parameters:
        level - the logging level
        args - any number of object to trace
      • removeEventsForListener

        protected void removeEventsForListener​(ISFSEventListener listener)