public interface ISFSExtension
Modifier and Type | Method and 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)
Here you can put all the necessary code to release any resources that was acquired/started in the init() method.
|
java.util.Properties |
getConfigProperties()
Returns a reference the Properties object loaded from the specified properties file.
|
java.lang.String |
getExtensionFileName()
Get the extension file name
|
com.smartfoxserver.v2.extensions.ExtensionLevel |
getLevel()
Return the level of the extension.
|
java.lang.String |
getName()
The extension name
|
Room |
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 Extension
|
java.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 listener
|
void |
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 recipients
|
void |
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 User
|
void |
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) |
void init()
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)
void destroy()
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...)
java.lang.String getName()
void setName(java.lang.String name)
java.lang.String getExtensionFileName()
void setExtensionFileName(java.lang.String fileName)
java.lang.String getPropertiesFileName()
void setPropertiesFileName(java.lang.String fileName) throws java.io.IOException
java.io.IOException
java.util.Properties getConfigProperties()
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
boolean isActive()
void setActive(boolean flag)
void addEventListener(SFSEventType eventType, ISFSEventListener listener)
eventType
- the type of event to listen forlistener
- the event handlerSFSEventType
,
ISFSEventListener
void removeEventListener(SFSEventType eventType, ISFSEventListener listener)
eventType
- the type of eventlistener
- the event handlerSFSEventType
,
ISFSEventListener
void setLevel(com.smartfoxserver.v2.extensions.ExtensionLevel level)
com.smartfoxserver.v2.extensions.ExtensionLevel getLevel()
com.smartfoxserver.v2.extensions.ExtensionType getType()
void setType(com.smartfoxserver.v2.extensions.ExtensionType type)
Zone getParentZone()
void setParentZone(Zone zone)
Room getParentRoom()
void setParentRoom(Room room)
ExtensionReloadMode getReloadMode()
void setReloadMode(ExtensionReloadMode mode)
void handleClientRequest(java.lang.String cmdName, User sender, ISFSObject params) throws SFSException
cmdName
- the request command namesender
- the sender of the requestparams
- the custom parameters of the requestSFSException
java.lang.Object handleInternalMessage(java.lang.String cmdName, java.lang.Object params)
cmdName
- a command nameparams
- custom parametersvoid send(java.lang.String cmdName, ISFSObject params, User recipient, boolean useUDP)
cmdName
- the command nameparams
- custom parametersrecipient
- the recipient of the messageuseUDP
- send as UDP packetvoid send(java.lang.String cmdName, ISFSObject params, User recipient)
void send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients, boolean useUDP)
cmdName
- the command nameparams
- custom parametersrecipients
- the list of recipientsuseUDP
- send as UDP packetvoid send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients)