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 intlagOscillationprotected intlagSimulationMillisExperimental lag simulator.protected org.slf4j.Loggerloggerprotected ISFSApisfsApiA reference to the SFS2X API
-
Constructor Summary
Constructors Constructor Description BaseSFSExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEventListener(SFSEventType eventType, ISFSEventListener listener)Allows to add a listener for a specific server event.ISFSApigetApi()Get a reference to the main SFS2X Server API, which exposes useful methods for interacting with the serverISFSBuddyApigetBuddyApi()Get a reference to the SFS2X Buddy API, exposing useful methods for working with BuddyListsjava.util.PropertiesgetConfigProperties()Returns a reference the Properties object loaded from the specified properties file.java.lang.StringgetCurrentFolder()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.StringgetExtensionFileName()Get the extension file nameISFSGameApigetGameApi()Get a reference to the SFS2X Game API, exposing useful methods for working with SFSGame classes, invitations and match making.com.smartfoxserver.v2.extensions.ExtensionLevelgetLevel()Return the level of the extension.org.slf4j.LoggergetLogger()Obtain a direct reference to the Extension's loggerISFSMMOApigetMMOApi()Get a reference to the SFS2X MMO API, exposing useful methods for working with MMORoom(s) and MMOItem(s) objects.java.lang.StringgetName()The extension nameRoomgetParentRoom()Return the parent Room of the Extension.ZonegetParentZone()Return the parent Zone of the Extension.java.lang.StringgetPropertiesFileName()Get the name of the properties file that was loaded at init time.ExtensionReloadModegetReloadMode()com.smartfoxserver.v2.extensions.ExtensionTypegetType()java.lang.ObjecthandleInternalMessage(java.lang.String cmdName, java.lang.Object params)This method can be invoked across different Extensions.voidhandleServerEvent(ISFSEvent event)Handle server eventbooleanisActive()Checks if the Extension is active.voidremoveEventListener(SFSEventType eventType, ISFSEventListener listener)Remove an event listenerprotected voidremoveEventsForListener(ISFSEventListener listener)voidsend(java.lang.String cmdName, ISFSObject params, User recipient)voidsend(java.lang.String cmdName, ISFSObject params, User recipient, boolean useUDP)Send an extension message/response to a single Uservoidsend(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients)voidsend(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients, boolean useUDP)Send an extension message/response to a list of recipientsvoidsetActive(boolean flag)voidsetExtensionFileName(java.lang.String fileName)voidsetLevel(com.smartfoxserver.v2.extensions.ExtensionLevel level)voidsetName(java.lang.String name)voidsetParentRoom(Room room)voidsetParentZone(Zone zone)voidsetPropertiesFileName(java.lang.String fileName)voidsetReloadMode(ExtensionReloadMode mode)voidsetType(com.smartfoxserver.v2.extensions.ExtensionType type)java.lang.StringtoString()voidtrace(ExtensionLogLevel level, java.lang.Object... args)Trace a message to the console and log files using the specified logging levelvoidtrace(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:
getNamein interfaceISFSExtension- Returns:
- the extension name
-
setName
public void setName(java.lang.String name)
- Specified by:
setNamein interfaceISFSExtension
-
getExtensionFileName
public java.lang.String getExtensionFileName()
Get the extension file name- Specified by:
getExtensionFileNamein 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:
getConfigPropertiesin 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:
getPropertiesFileNamein interfaceISFSExtension- Returns:
- the name of the configuration properties file
-
setPropertiesFileName
public void setPropertiesFileName(java.lang.String fileName) throws java.io.IOException- Specified by:
setPropertiesFileNamein 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:
handleServerEventin 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:
handleInternalMessagein interfaceISFSExtension- Parameters:
cmdName- a command nameparams- custom parameters
-
setExtensionFileName
public void setExtensionFileName(java.lang.String fileName)
- Specified by:
setExtensionFileNamein interfaceISFSExtension
-
getParentRoom
public Room getParentRoom()
Return the parent Room of the Extension. (valid only for Room-level extensions)- Specified by:
getParentRoomin interfaceISFSExtension- Returns:
- the Room or null if this is not a Room-level extension
-
setParentRoom
public void setParentRoom(Room room)
- Specified by:
setParentRoomin interfaceISFSExtension
-
getParentZone
public Zone getParentZone()
Return the parent Zone of the Extension.- Specified by:
getParentZonein interfaceISFSExtension- Returns:
- the Zone of the Extension
-
setParentZone
public void setParentZone(Zone zone)
- Specified by:
setParentZonein interfaceISFSExtension
-
addEventListener
public void addEventListener(SFSEventType eventType, ISFSEventListener listener)
Allows to add a listener for a specific server event.- Specified by:
addEventListenerin 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:
removeEventListenerin 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:
isActivein interfaceISFSExtension- Returns:
- true if the Extension is active.
-
setActive
public void setActive(boolean flag)
- Specified by:
setActivein 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:
getLevelin interfaceISFSExtension- Returns:
- the extension Level
-
setLevel
public void setLevel(com.smartfoxserver.v2.extensions.ExtensionLevel level)
- Specified by:
setLevelin interfaceISFSExtension
-
getType
public com.smartfoxserver.v2.extensions.ExtensionType getType()
- Specified by:
getTypein interfaceISFSExtension
-
setType
public void setType(com.smartfoxserver.v2.extensions.ExtensionType type)
- Specified by:
setTypein interfaceISFSExtension
-
getReloadMode
public ExtensionReloadMode getReloadMode()
- Specified by:
getReloadModein interfaceISFSExtension
-
setReloadMode
public void setReloadMode(ExtensionReloadMode mode)
- Specified by:
setReloadModein interfaceISFSExtension
-
send
public void send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients)- Specified by:
sendin interfaceISFSExtension
-
send
public void send(java.lang.String cmdName, ISFSObject params, User recipient)- Specified by:
sendin 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:
sendin 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:ISFSExtensionSend an extension message/response to a single User- Specified by:
sendin interfaceISFSExtension- Parameters:
cmdName- the command nameparams- custom parametersrecipient- the recipient of the messageuseUDP- send as UDP packet
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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)
-
-