Interface ISFSExtension
-
- All Known Implementing Classes:
BaseSFSExtension
,SFSExtension
public interface ISFSExtension
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addEventListener(SFSEventType eventType, ISFSEventListener listener)
Allows to add a listener for a specific server event.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)java.util.Properties
getConfigProperties()
Returns a reference the Properties object loaded from the specified properties file.java.lang.String
getExtensionFileName()
Get the extension file namecom.smartfoxserver.v2.extensions.ExtensionLevel
getLevel()
Return the level of the extension.java.lang.String
getName()
The extension nameRoom
getParentRoom()
Return the parent Room of the Extension.Zone
getParentZone()
Return the parent Zone of the Extension.java.lang.String
getPropertiesFileName()
Get the name of the properties file that was loaded at init time.ExtensionReloadMode
getReloadMode()
com.smartfoxserver.v2.extensions.ExtensionType
getType()
void
handleClientRequest(java.lang.String cmdName, User sender, ISFSObject params)
This method is called whenever a client sends a request to this Extensionjava.lang.Object
handleInternalMessage(java.lang.String cmdName, java.lang.Object params)
This method can be invoked across different Extensions.void
init()
This method is called once by the Server after the Extension is instantiated.boolean
isActive()
Checks if the Extension is active.void
removeEventListener(SFSEventType eventType, ISFSEventListener listener)
Remove an event listenervoid
send(java.lang.String cmdName, ISFSObject params, User recipient)
void
send(java.lang.String cmdName, ISFSObject params, User recipient, boolean useUDP)
Send an extension message/response to a single Uservoid
send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients)
void
send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients, boolean useUDP)
Send an extension message/response to a list of recipientsvoid
setActive(boolean flag)
void
setExtensionFileName(java.lang.String fileName)
void
setLevel(com.smartfoxserver.v2.extensions.ExtensionLevel level)
void
setName(java.lang.String name)
void
setParentRoom(Room room)
void
setParentZone(Zone zone)
void
setPropertiesFileName(java.lang.String fileName)
void
setReloadMode(ExtensionReloadMode mode)
void
setType(com.smartfoxserver.v2.extensions.ExtensionType type)
-
-
-
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)
-
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 forlistener
- the event handler- See Also:
SFSEventType
,ISFSEventListener
-
removeEventListener
void removeEventListener(SFSEventType eventType, ISFSEventListener listener)
Remove an event listener- Parameters:
eventType
- the type of eventlistener
- the event handler- See Also:
SFSEventType
,ISFSEventListener
-
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)
-
getReloadMode
ExtensionReloadMode getReloadMode()
-
setReloadMode
void setReloadMode(ExtensionReloadMode mode)
-
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 namesender
- the sender of the requestparams
- 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 nameparams
- 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 nameparams
- custom parametersrecipient
- the recipient of the messageuseUDP
- 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 nameparams
- custom parametersrecipients
- the list of recipientsuseUDP
- send as UDP packet
-
send
void send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients)
-
-