Class BaseSFSExtension

java.lang.Object
com.smartfoxserver.extensions.BaseSFSExtension
All Implemented Interfaces:
ISFSEventListener, ISFSExtension
Direct Known Subclasses:
SFSExtension

public abstract class BaseSFSExtension extends Object implements ISFSExtension, ISFSEventListener
SFSExtension's base class.
Use SFSExtension instead
  • Field Details

    • log

      protected final org.slf4j.Logger log
    • sfsApi

      protected final ISFSApi sfsApi
      A reference to the SmartFoxServer API main object
      See Also:
  • Constructor Details

    • BaseSFSExtension

      public BaseSFSExtension()
  • Method Details

    • getCurrentFolder

      public 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 String getName()
      The extension name
      Specified by:
      getName in interface ISFSExtension
      Returns:
      the extension name
    • setName

      public void setName(String name)
      Specified by:
      setName in interface ISFSExtension
    • getExtensionFileName

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

      public 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 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(String fileName) throws IOException
      Specified by:
      setPropertiesFileName in interface ISFSExtension
      Throws:
      IOException
    • getSFS

      public SmartFoxServer getSFS()
      Get a reference to the Server's main object
      Returns:
      a reference to the main server's instance singleton
    • getApi

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

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

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

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

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

      public Object handleInternalMessage(String cmdName, 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
    • setExtensionFileName

      public void setExtensionFileName(String fileName)
      Specified by:
      setExtensionFileName in interface ISFSExtension
    • 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
    • setParentRoom

      public void setParentRoom(Room room)
      Specified by:
      setParentRoom in interface ISFSExtension
    • getParentZone

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

      public void setParentZone(Zone zone)
      Specified by:
      setParentZone in interface ISFSExtension
    • addEventListener

      public void addEventListener(SFSEventType eventType, ISFSEventListener listener)
      Allows to add a listener for a specific server event.
      Specified by:
      addEventListener in interface ISFSExtension
      Parameters:
      eventType - the type of event to listen for
      listener - the event handler
      See Also:
    • removeEventListener

      public void removeEventListener(SFSEventType eventType, ISFSEventListener listener)
      Remove an event listener
      Specified by:
      removeEventListener in interface ISFSExtension
      Parameters:
      eventType - the type of event
      listener - the event handler
      See Also:
    • 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.
    • setActive

      public void setActive(boolean flag)
      Specified by:
      setActive in interface ISFSExtension
    • getLevel

      public com.smartfoxserver.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.extensions.ExtensionLevel level)
      Specified by:
      setLevel in interface ISFSExtension
    • getType

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

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

      public ExtensionReloadMode getReloadMode()
      Specified by:
      getReloadMode in interface ISFSExtension
    • setReloadMode

      public void setReloadMode(ExtensionReloadMode mode)
      Specified by:
      setReloadMode in interface ISFSExtension
    • send

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

      public void send(String cmdName, ISFSObject params, User recipient)
      Specified by:
      send in interface ISFSExtension
    • send

      public void send(String cmdName, ISFSObject params, List<User> recipients, TransportType txType)
      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
      txType - network transport to use (default is TCP)
      See Also:
    • send

      public void send(String cmdName, ISFSObject params, User recipient, TransportType txType)
      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
      txType - network transport to use (default is TCP)
      See Also:
    • toString

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

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

      public void trace(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, 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)