Interface ISFSExtension

All Known Implementing Classes:
BaseSFSExtension, SFSExtension

public interface ISFSExtension
  • Method Details

    • 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 uncaught exception in this method will result in the failure of 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

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

      void setName(String name)
      Internal
    • getExtensionFileName

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

      void setExtensionFileName(String fileName)
      Internal
    • getPropertiesFileName

      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(String fileName) throws IOException
      Throws:
      IOException
      Internal
    • getConfigProperties

      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)
      Internal
    • addEventListener

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

      void removeEventListener(SFSEventType eventType, ISFSEventListener listener)
      Remove an event listener
      Parameters:
      eventType - the type of event
      listener - the event handler
      See Also:
    • setLevel

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

      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
      Returns:
      the extension Level
    • getType

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

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

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

      void setParentZone(Zone zone)
      Internal
    • 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)
      Internal
    • getReloadMode

      ExtensionReloadMode getReloadMode()
      Internal
    • setReloadMode

      void setReloadMode(ExtensionReloadMode mode)
      Internal
    • handleClientRequest

      void handleClientRequest(String cmdName, User sender, ISFSObject params, TransportType txType) 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

      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
      Parameters:
      cmdName - a command name
      params - custom parameters
    • send

      void send(String cmdName, ISFSObject params, User recipient, TransportType txType)
      Send an extension message/response to a single User
      Parameters:
      cmdName - the command name
      params - custom parameters
      recipient - the recipient of the message
      txType - network transport to use (default is TCP)
      See Also:
    • send

      void send(String cmdName, ISFSObject params, User recipient)
    • send

      void send(String cmdName, ISFSObject params, List<User> recipients, TransportType txType)
      Send an extension message/response to a list of recipients
      Parameters:
      cmdName - the command name
      params - custom parameters
      recipients - the list of recipients
      txType - network transport to use (default is TCP)
      See Also:
    • send

      void send(String cmdName, ISFSObject params, List<User> recipients)