|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.gotoandplay.smartfoxserver.extensions.ExtensionHelper
public class ExtensionHelper
The ExtensionHelper class provides utility methods for server side extensions written in Java. It is reccomended to always keep a reference to the class in your Extension.
A good practice is to create such reference in the init() method of your extension:
private ExtensionHelper helper; public void init() { helper = ExtensionHelper.instance(); }
Field Summary | |
---|---|
static int |
MOD_MESSAGE_TO_ROOM
|
static int |
MOD_MESSAGE_TO_USER
|
static int |
MOD_MESSAGE_TO_ZONE
|
Method Summary | |
---|---|
User |
canLogin(java.lang.String nick,
java.lang.String pass,
java.nio.channels.SocketChannel ch,
java.lang.String zone)
Checks if a connected client can log in the requested Zone. |
Room |
createRoom(Zone z,
java.util.Map params,
User creator,
boolean sendUpdate,
boolean broadcastEvent)
Create a new dynamic room. |
Room |
createRoom(Zone z,
java.util.Map params,
User creator,
java.util.HashMap roomVars,
User varsOwner,
boolean setOwnership,
boolean sendUpdate,
boolean broadcastEvent)
Create a new dynamic room. |
static void |
destroy()
|
boolean |
destroyRoom(Zone zone,
int roomId)
Destroy a server room |
void |
disconnectUser(User u)
Disconnects a client from the server |
void |
dispatchPrivateMessage(java.lang.String msg,
Room r,
User sender,
User recipient)
Dispatch a private message. |
void |
dispatchPublicMessage(java.lang.String msg,
Room r,
User u)
Dispatch a public message. |
java.lang.String |
getGuestName()
Return a guest name in the format of "guest_nn" where nn is an autoincrement integer |
User |
getUserByChannel(java.nio.channels.SocketChannel sc)
Return a User object from its socket channel |
User |
getUserById(int id)
Return a User object from its numeric id |
Zone |
getZone(java.lang.String zoneName)
Return a Zone object from its name |
static ExtensionHelper |
instance()
Get an instance of the ExtensionHelper class |
boolean |
joinRoom(User usr,
int currRoom,
int newRoom,
boolean leaveRoom,
java.lang.String pword,
boolean isSpectator,
boolean broadcast)
Join a room from a server side extension |
void |
leaveRoom(User u,
int roomId,
boolean broadcastEvent)
Force a user to leave a room. |
void |
logoutUser(int id,
boolean fireClientEvt,
boolean fireInternalEvt)
Logout a user from the current Zone |
void |
logoutUser(User user,
boolean fireClientEvt,
boolean fireInternalEvt)
Logout a user from the current Zone |
void |
sendGenericMessage(java.lang.String message,
java.nio.channels.SocketChannel sender,
java.util.LinkedList channelList)
Send a generic text or XML message. |
void |
sendModeratorMessage(java.lang.String message,
User sender,
int type,
int id)
Send a moderator message to a single user, a room or an entire Zone |
void |
sendRoomList(java.nio.channels.SocketChannel sc)
Send a room list in default format (XML) This will fire a onRoomListUpdate() event on the client. |
void |
setRoomVariable(Room r,
User u,
java.lang.String vn,
java.lang.String vt,
java.lang.String vv,
boolean pr,
boolean ps,
boolean setOwnership,
boolean broadcastAll)
Deprecated. |
void |
setRoomVariables(Room r,
User u,
java.util.HashMap vars,
boolean setOwnership,
boolean broadcastAll)
Set one or more Room Variable The vars parameter requires a HashMap of RoomVariables where the key is the variable name and the value is the RoomVariable object |
void |
setUserVariables(User u,
java.util.HashMap vars,
boolean broadcastAll)
Set one or more User Variables. |
void |
switchSpectator(User u,
int roomId,
boolean brodcastEvent)
Switch a spectator into a player, if possible (game rooms only) |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MOD_MESSAGE_TO_USER
public static final int MOD_MESSAGE_TO_ROOM
public static final int MOD_MESSAGE_TO_ZONE
Method Detail |
---|
public static ExtensionHelper instance()
public static void destroy()
public User canLogin(java.lang.String nick, java.lang.String pass, java.nio.channels.SocketChannel ch, java.lang.String zone) throws it.gotoandplay.smartfoxserver.exceptions.LoginException
nick
- the nickname you want to use to log inpass
- an optional passwordch
- the SocketChannel of the connected clientzone
- the zone name
it.gotoandplay.smartfoxserver.exceptions.LoginException
- if there are problems with the loginpublic void dispatchPublicMessage(java.lang.String msg, Room r, User u)
msg
- the messager
- the target roomu
- the sender userpublic void dispatchPrivateMessage(java.lang.String msg, Room r, User sender, User recipient)
msg
- the messager
- the room of the sendersender
- the sender userrecipient
- the recipient userpublic java.lang.String getGuestName()
public User getUserByChannel(java.nio.channels.SocketChannel sc)
sc
- a valid socket channel
public User getUserById(int id)
id
- a valid user id
public void logoutUser(int id, boolean fireClientEvt, boolean fireInternalEvt)
id
- the user idpublic void logoutUser(User user, boolean fireClientEvt, boolean fireInternalEvt)
user
- the User objectpublic void sendGenericMessage(java.lang.String message, java.nio.channels.SocketChannel sender, java.util.LinkedList channelList)
message
- string or xml messagesender
- the sender channel (can be null)channelList
- a list of recipient channelspublic Room createRoom(Zone z, java.util.Map params, User creator, boolean sendUpdate, boolean broadcastEvent) throws it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException
Create a new dynamic room.
The params parameter can contain the following keys:
name | the room name | |
pwd | the room password (optional) | |
maxU | max number of users | |
maxS | max number of spectators (optional for game rooms) | |
isGame | a boolean flag. If true the room is a game room | |
isLimbo | a boolean flag. If true the room is in "Limbo mode" | |
uCount | a boolean flag. If true the room will receive the uCount update messages. | |
xtName | The name of the extension that will be attached to the room | |
xtClass | The name of the class (Java) or script (Actionscript)
to load as extension. The file extension should only be specified for Actionscript files (.as) |
z
- the Zone where the room will be createdparams
- a Map of params: name,pwd,maxU,maxS,isGamecreator
- the "owner" of the room. null = Server ownedsendUpdate
- send a default xml update to clients?broadcastEvent
- TRUE = broadcast event to all, FALSE = only Server scope (for admin)
it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException
public Room createRoom(Zone z, java.util.Map params, User creator, java.util.HashMap roomVars, User varsOwner, boolean setOwnership, boolean sendUpdate, boolean broadcastEvent) throws it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException
Create a new dynamic room.
Additionally create any number of room variables in the new room
The params parameter can contain the following keys:
name | the room name | |
pwd | the room password (optional) | |
maxU | max number of users | |
maxS | max number of spectators (optional for game rooms) | |
isGame | a boolean flag. If true the room is a game room | |
isLimbo | a boolean flag. If true the room is in "Limbo mode" | |
uCount | a boolean flag. If true the room will receive the uCount update messages. | |
xtName | The name of the extension that will be attached to the room | |
xtClass | The name of the class (Java) or script (Actionscript)
to load as extension. The file extension should only be specified for Actionscript files (.as) |
z
- the Zone where the room will be createdparams
- a Map of params: name,pwd,maxU,maxS,isGamecreator
- the "owner" of the room. null = Server ownedroomVars
- an HashMap of variables to set on the newly created room (null if not needed)varsOwner
- the owner of the variablessetOwnership
- the setOwnership flag for the roomVarssendUpdate
- send a default xml update?broadcastEvent
- TRUE = broadcast event to all, FALSE = only Server scope (for admin)
it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException
public boolean joinRoom(User usr, int currRoom, int newRoom, boolean leaveRoom, java.lang.String pword, boolean isSpectator, boolean broadcast) throws it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException
usr
- the User objectcurrRoom
- the id of the current room where the user is innewRoom
- the id of the room that the user wants to joinleaveRoom
- if true the user will leave the current room once he successfully joined the new onepword
- an optional password for the roomisSpectator
- if true the user is joined as spectator (for game rooms only)broadcast
- if true the onJoinRoom event is fired back to all clients (reccomended)
it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException
public void sendModeratorMessage(java.lang.String message, User sender, int type, int id)
message
- the text messagesender
- the sender usertype
- the type of message (ExtensionHelper.MOD_MESSAGE_TO_ constants)id
- the id of the recipient user or room.
In case of a Zone message it will be ignored and the message will be sent to the current Zone.public void sendRoomList(java.nio.channels.SocketChannel sc)
sc
- The SocketChannel that will receive the listpublic void setRoomVariable(Room r, User u, java.lang.String vn, java.lang.String vt, java.lang.String vv, boolean pr, boolean ps, boolean setOwnership, boolean broadcastAll)
r
- the Roomu
- the Uservn
- the var namevt
- the var typevv
- the var valuepr
- private flagps
- persistent flagsetOwnership
- setOwnership flag (will set the variable owner to the User who sent the request)broadcastAll
- if true the onRoomVariablesUpdate() event will be fired (reccomended)public void setRoomVariables(Room r, User u, java.util.HashMap vars, boolean setOwnership, boolean broadcastAll)
r
- the target room, where variables should be setu
- the user, owner of the variablesvars
- a java.util.HashMap of RoomVariablessetOwnership
- setOwnership flag (will set the variable owner to the User who sent the request)broadcastAll
- if true the onRoomVariablesUpdate() event will be fired (recommended)public void setUserVariables(User u, java.util.HashMap vars, boolean broadcastAll)
vars
- a map of UserVariablesu
- the User objectbroadcastAll
- if true the onUserVariablesUpdate() event will be fired (reccomended)public Zone getZone(java.lang.String zoneName)
zoneName
- the name of the zone
public void leaveRoom(User u, int roomId, boolean broadcastEvent)
u
- the userroomId
- the id of the room to leavebroadcastEvent
- if true, the response event is fired (reccomended)public void switchSpectator(User u, int roomId, boolean brodcastEvent)
u
- the userroomId
- the target room idbrodcastEvent
- if true, the response event is fired (reccomended)public void disconnectUser(User u)
u
- the user to kickpublic boolean destroyRoom(Zone zone, int roomId)
zone
- the zoneroomId
- the roomId
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |