public abstract class BaseSFSExtension extends java.lang.Object implements ISFSExtension, ISFSEventListener
SFSExtension
Modifier and Type | Field and 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 and Description |
---|
BaseSFSExtension() |
Modifier and Type | Method and 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 server
|
ISFSBuddyApi |
getBuddyApi()
Get a reference to the SFS2X Buddy API, exposing useful methods for working with BuddyLists
|
java.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 name
|
ISFSGameApi |
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 logger
|
ISFSMMOApi |
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 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() |
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 event
|
boolean |
isActive()
Checks if the Extension is active.
|
void |
removeEventListener(SFSEventType eventType,
ISFSEventListener listener)
Remove an event listener
|
protected void |
removeEventsForListener(ISFSEventListener 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) |
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 level
|
void |
trace(java.lang.Object... args)
Traces a message to the console and log files using the Logger INFO level
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
destroy, handleClientRequest, init
protected volatile int lagSimulationMillis
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!
protected volatile int lagOscillation
protected final org.slf4j.Logger logger
public java.lang.String getCurrentFolder()
public java.lang.String getName()
getName
in interface ISFSExtension
public void setName(java.lang.String name)
setName
in interface ISFSExtension
public java.lang.String getExtensionFileName()
getExtensionFileName
in interface ISFSExtension
public 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
getConfigProperties
in interface ISFSExtension
public java.lang.String getPropertiesFileName()
getPropertiesFileName
in interface ISFSExtension
public void setPropertiesFileName(java.lang.String fileName) throws java.io.IOException
setPropertiesFileName
in interface ISFSExtension
java.io.IOException
public ISFSApi getApi()
ISFSApi
public ISFSBuddyApi getBuddyApi()
ISFSBuddyApi
public ISFSGameApi getGameApi()
ISFSGameApi
public ISFSMMOApi getMMOApi()
ISFSMMOApi
public void handleServerEvent(ISFSEvent event) throws java.lang.Exception
handleServerEvent
in interface ISFSEventListener
event
- the Eventjava.lang.Exception
SFSEvent
public java.lang.Object handleInternalMessage(java.lang.String cmdName, java.lang.Object params)
handleInternalMessage
in interface ISFSExtension
cmdName
- a command nameparams
- custom parameterspublic void setExtensionFileName(java.lang.String fileName)
setExtensionFileName
in interface ISFSExtension
public Room getParentRoom()
getParentRoom
in interface ISFSExtension
public void setParentRoom(Room room)
setParentRoom
in interface ISFSExtension
public Zone getParentZone()
getParentZone
in interface ISFSExtension
public void setParentZone(Zone zone)
setParentZone
in interface ISFSExtension
public void addEventListener(SFSEventType eventType, ISFSEventListener listener)
addEventListener
in interface ISFSExtension
eventType
- the type of event to listen forlistener
- the event handlerSFSEventType
,
ISFSEventListener
public void removeEventListener(SFSEventType eventType, ISFSEventListener listener)
removeEventListener
in interface ISFSExtension
eventType
- the type of eventlistener
- the event handlerSFSEventType
,
ISFSEventListener
public boolean isActive()
isActive
in interface ISFSExtension
public void setActive(boolean flag)
setActive
in interface ISFSExtension
public com.smartfoxserver.v2.extensions.ExtensionLevel getLevel()
getLevel
in interface ISFSExtension
public void setLevel(com.smartfoxserver.v2.extensions.ExtensionLevel level)
setLevel
in interface ISFSExtension
public com.smartfoxserver.v2.extensions.ExtensionType getType()
getType
in interface ISFSExtension
public void setType(com.smartfoxserver.v2.extensions.ExtensionType type)
setType
in interface ISFSExtension
public ExtensionReloadMode getReloadMode()
getReloadMode
in interface ISFSExtension
public void setReloadMode(ExtensionReloadMode mode)
setReloadMode
in interface ISFSExtension
public void send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients)
send
in interface ISFSExtension
public void send(java.lang.String cmdName, ISFSObject params, User recipient)
send
in interface ISFSExtension
public void send(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients, boolean useUDP)
send
in interface ISFSExtension
cmdName
- the command nameparams
- custom parametersrecipients
- the list of recipientsuseUDP
- send as UDP packetpublic void send(java.lang.String cmdName, ISFSObject params, User recipient, boolean useUDP)
ISFSExtension
send
in interface ISFSExtension
cmdName
- the command nameparams
- custom parametersrecipient
- the recipient of the messageuseUDP
- send as UDP packetpublic java.lang.String toString()
toString
in class java.lang.Object
public org.slf4j.Logger getLogger()
public void trace(java.lang.Object... args)
args
- any number of strings/object to tracepublic void trace(ExtensionLogLevel level, java.lang.Object... args)
level
- the logging levelargs
- any number of object to traceprotected void removeEventsForListener(ISFSEventListener listener)