Package com.smartfoxserver.v2.extensions
Class BaseSFSExtension
- java.lang.Object
-
- com.smartfoxserver.v2.extensions.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 Summary
Fields Modifier and Type Field Description protected int
lagOscillation
protected int
lagSimulationMillis
Experimental lag simulator.protected org.slf4j.Logger
logger
protected ISFSApi
sfsApi
A reference to the SFS2X API
-
Constructor Summary
Constructors Constructor Description BaseSFSExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEventListener(SFSEventType eventType, ISFSEventListener listener)
Allows to add a listener for a specific server event.ISFSApi
getApi()
Get a reference to the main SFS2X Server API, which exposes useful methods for interacting with the serverISFSBuddyApi
getBuddyApi()
Get a reference to the SFS2X Buddy API, exposing useful methods for working with BuddyListsjava.util.Properties
getConfigProperties()
Returns a reference the Properties object loaded from the specified properties file.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)java.lang.String
getExtensionFileName()
Get the extension file nameISFSGameApi
getGameApi()
Get a reference to the SFS2X Game API, exposing useful methods for working with SFSGame classes, invitations and match making.com.smartfoxserver.v2.extensions.ExtensionLevel
getLevel()
Return the level of the extension.org.slf4j.Logger
getLogger()
Obtain a direct reference to the Extension's loggerISFSMMOApi
getMMOApi()
Get a reference to the SFS2X MMO API, exposing useful methods for working with MMORoom(s) and MMOItem(s) objects.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()
java.lang.Object
handleInternalMessage(java.lang.String cmdName, java.lang.Object params)
This method can be invoked across different Extensions.void
handleServerEvent(ISFSEvent event)
Handle server eventboolean
isActive()
Checks if the Extension is active.void
removeEventListener(SFSEventType eventType, ISFSEventListener listener)
Remove an event listenerprotected void
removeEventsForListener(ISFSEventListener listener)
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 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)
java.lang.String
toString()
void
trace(ExtensionLogLevel level, java.lang.Object... args)
Trace a message to the console and log files using the specified logging levelvoid
trace(java.lang.Object... args)
Traces a message to the console and log files using the Logger INFO level-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.smartfoxserver.v2.extensions.ISFSExtension
destroy, handleClientRequest, init
-
-
-
-
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
-
-
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 interfaceISFSExtension
- Returns:
- the extension name
-
setName
public void setName(java.lang.String name)
- Specified by:
setName
in interfaceISFSExtension
-
getExtensionFileName
public java.lang.String getExtensionFileName()
Get the extension file name- Specified by:
getExtensionFileName
in interfaceISFSExtension
- 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 interfaceISFSExtension
- 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 interfaceISFSExtension
- Returns:
- the name of the configuration properties file
-
setPropertiesFileName
public void setPropertiesFileName(java.lang.String fileName) throws java.io.IOException
- Specified by:
setPropertiesFileName
in interfaceISFSExtension
- 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 interfaceISFSEventListener
- 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 interfaceISFSExtension
- Parameters:
cmdName
- a command nameparams
- custom parameters
-
setExtensionFileName
public void setExtensionFileName(java.lang.String fileName)
- Specified by:
setExtensionFileName
in interfaceISFSExtension
-
getParentRoom
public Room getParentRoom()
Return the parent Room of the Extension. (valid only for Room-level extensions)- Specified by:
getParentRoom
in interfaceISFSExtension
- Returns:
- the Room or null if this is not a Room-level extension
-
setParentRoom
public void setParentRoom(Room room)
- Specified by:
setParentRoom
in interfaceISFSExtension
-
getParentZone
public Zone getParentZone()
Return the parent Zone of the Extension.- Specified by:
getParentZone
in interfaceISFSExtension
- Returns:
- the Zone of the Extension
-
setParentZone
public void setParentZone(Zone zone)
- Specified by:
setParentZone
in interfaceISFSExtension
-
addEventListener
public void addEventListener(SFSEventType eventType, ISFSEventListener listener)
Allows to add a listener for a specific server event.- Specified by:
addEventListener
in interfaceISFSExtension
- Parameters:
eventType
- the type of event to listen forlistener
- the event handler- See Also:
SFSEventType
,ISFSEventListener
-
removeEventListener
public void removeEventListener(SFSEventType eventType, ISFSEventListener listener)
Remove an event listener- Specified by:
removeEventListener
in interfaceISFSExtension
- Parameters:
eventType
- the type of eventlistener
- the event handler- See Also:
SFSEventType
,ISFSEventListener
-
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 interfaceISFSExtension
- Returns:
- true if the Extension is active.
-
setActive
public void setActive(boolean flag)
- Specified by:
setActive
in interfaceISFSExtension
-
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 interfaceISFSExtension
- Returns:
- the extension Level
-
setLevel
public void setLevel(com.smartfoxserver.v2.extensions.ExtensionLevel level)
- Specified by:
setLevel
in interfaceISFSExtension
-
getType
public com.smartfoxserver.v2.extensions.ExtensionType getType()
- Specified by:
getType
in interfaceISFSExtension
-
setType
public void setType(com.smartfoxserver.v2.extensions.ExtensionType type)
- Specified by:
setType
in interfaceISFSExtension
-
getReloadMode
public ExtensionReloadMode getReloadMode()
- Specified by:
getReloadMode
in interfaceISFSExtension
-
setReloadMode
public void setReloadMode(ExtensionReloadMode mode)
- Specified by:
setReloadMode
in interfaceISFSExtension
-
send
public void send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients)
- Specified by:
send
in interfaceISFSExtension
-
send
public void send(java.lang.String cmdName, ISFSObject params, User recipient)
- Specified by:
send
in interfaceISFSExtension
-
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 interfaceISFSExtension
- Parameters:
cmdName
- the command nameparams
- custom parametersrecipients
- the list of recipientsuseUDP
- 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 interfaceISFSExtension
- Parameters:
cmdName
- the command nameparams
- custom parametersrecipient
- the recipient of the messageuseUDP
- send as UDP packet
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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 levelargs
- any number of object to trace
-
removeEventsForListener
protected void removeEventsForListener(ISFSEventListener listener)
-
-