it.gotoandplay.smartfoxserver.extensions
Class ExtensionHelper

java.lang.Object
  extended by it.gotoandplay.smartfoxserver.extensions.ExtensionHelper

public class ExtensionHelper
extends java.lang.Object

The ExtensionHelper class provides the main access to the server side API in Java. It is recommended 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();
 }
 

Author:
(c) 2004-2008 gotoAndPlay() -- www.gotoandplay.it

Field Summary
static int MOD_MESSAGE_TO_ROOM
           
static int MOD_MESSAGE_TO_USER
           
static int MOD_MESSAGE_TO_ZONE
           
 
Method Summary
 void addBuddy(java.lang.String buddyName, User user)
          Add a buddy to a user buddy list
Based on the BuddyList configuration this may immediately add the buddy to the user list or send a buddy request that the target user must respond to.
 void addModerator(java.lang.String zoneName, java.lang.String modName, java.lang.String modPass)
          Add a new moderator to a Zone
 void banOfflineUser(java.lang.String userName)
          Banishes an offline user by name
 void banUser(User user, int delay, java.lang.String farewellMessage, int banType)
          Disconnects and bans a user.
 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.
 User canLogin(java.lang.String nick, java.lang.String pass, java.nio.channels.SocketChannel ch, java.lang.String zone, boolean forceLogin)
          Checks if a connected client can log in the requested Zone.
 void clearBuddyList(User user)
          Deprecated.  
 User createNPC(java.lang.String userName, java.lang.String ipAddress, int port, java.lang.String zoneName)
           Creates an NPC (Non-Player Character) or BOT User that can be used for automated tasks, game AI etc...
 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)
          Destroys 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 long value
 java.lang.String getSecretKey(java.nio.channels.SocketChannel channel)
          Return the unique secret key for this socket channel
For further info about this method and its usage check the "Secure Login Tutorial"
found at chapter 8.9 of the documentation.
 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 kickUser(User user, int delay, java.lang.String farewellMessage)
          Kicks a user allowing to specify a delay before the task is executed and an admin message.
 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 rebootServer()
          Performs a soft reboot of the server, just like hitting the "Restart" button in the Admin interface.
 void removeBanishment(java.lang.String param, int mode)
          Removes a banned user from the ban-list, allowing him/her to be able to login again
 void removeBuddy(java.lang.String buddyName, User user)
          Removes a buddy from a user buddy list.
 void removeModerator(java.lang.String zoneName, java.lang.String modName)
          Removes a moderator user from a Zone
 void requestAddBuddyPermission(User sender, java.lang.String targetUserName, java.lang.String optionalMessage)
           Requests permission for adding the target user in the sender buddy list.
 void sendBuddyListUpdate(User user)
          Send an update about the specified User to all clients that have him/her in their buddy list.
 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 setBuddyBlockStatus(User user, java.lang.String buddyName, boolean isBlocked)
          Set the isBlocked flag of a buddy in the User's buddy list.
 void setBuddyVariables(User user, java.util.Map<java.lang.String,java.lang.String> variables)
          Set the buddy variables of the specified user.
 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 Map 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 switchPlayer(User u, int roomId, boolean brodcastEvent)
          Switch a player into a spectator, if possible (game rooms only)
Fires an onPlayerSwitched event on the client side.
 void switchSpectator(User u, int roomId, boolean brodcastEvent)
          Switch a spectator into a player, if possible (game rooms only)
For more details about switching spectators to players you should check the SmartFoxTris game example.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOD_MESSAGE_TO_USER

public static final int MOD_MESSAGE_TO_USER
See Also:
Constant Field Values

MOD_MESSAGE_TO_ROOM

public static final int MOD_MESSAGE_TO_ROOM
See Also:
Constant Field Values

MOD_MESSAGE_TO_ZONE

public static final int MOD_MESSAGE_TO_ZONE
See Also:
Constant Field Values
Method Detail

instance

public static ExtensionHelper instance()
Get an instance of the ExtensionHelper class

Returns:
the instance of the ExtensionHelper

destroy

public static void destroy()

canLogin

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
Checks if a connected client can log in the requested Zone.
If the Zone is full, or a user with the same name already exist a LoginException will be thrown.
Before logging in a Zone a client has a very limited set of actions that can perform with the server.
Once the login phase is successfully passed, a User object is created and added to the Zone allowing the user to interact with the server.
You can learn more by checking the PixelGame example found at chapter 8.10 of the docs.
The Java extension source can be found under the {path-to-your-sfs-folder}/Server/javaExtensions/ folder under the it.gotoandplay.extensions.examples package

Parameters:
nick - the nickname you want to use to log in
pass - an optional password
ch - the SocketChannel of the connected client
zone - the zone name
Returns:
a User object
Throws:
it.gotoandplay.smartfoxserver.exceptions.LoginException - if there are problems with the login

canLogin

public User canLogin(java.lang.String nick,
                     java.lang.String pass,
                     java.nio.channels.SocketChannel ch,
                     java.lang.String zone,
                     boolean forceLogin)
              throws it.gotoandplay.smartfoxserver.exceptions.LoginException
Checks if a connected client can log in the requested Zone.
If the Zone is full, or a user with the same name already exist a LoginException will be thrown.
Before logging in a Zone a client has a very limited set of actions that can perform with the server.
Once the login phase is successfully passed, a User object is created and added to the Zone allowing the user to interact with the server.
You can learn more by checking the PixelGame example found at chapter 8.10 of the docs.
The Java extension source can be found under the {path-to-your-sfs-folder}/Server/javaExtensions/ folder under the it.gotoandplay.extensions.examples package

Parameters:
nick - the nickname you want to use to log in
pass - an optional password
ch - the SocketChannel of the connected client
zone - the zone name
forceLogin - attempts to drop a previous existing connection and logs in again
Returns:
a User object
Throws:
it.gotoandplay.smartfoxserver.exceptions.LoginException - if there are problems with the login

dispatchPublicMessage

public void dispatchPublicMessage(java.lang.String msg,
                                  Room r,
                                  User u)
Dispatch a public message.
This method is usually invoked when handling a pubMsg internal event.
The server fires the event when a client has requested to send a public message in his current room.
You can handle the message before it gets dispatched, log it, process it and finally dispatch it to the room.

Parameters:
msg - the message
r - the target room
u - the sender user
See Also:
InternalEventHandler

dispatchPrivateMessage

public void dispatchPrivateMessage(java.lang.String msg,
                                   Room r,
                                   User sender,
                                   User recipient)
Dispatch a private message.
This method is usually invoked when handling a privMsg internal event.
The server fires the event when a client has requested to send a private message to another user
You can handle the message before it gets dispatched, log it, process it and finally dispatch it to the user.

Parameters:
msg - the message
r - the room of the sender
sender - the sender user
recipient - the recipient user
See Also:
InternalEventHandler

getGuestName

public java.lang.String getGuestName()
Return a guest name in the format of "guest_nn" where nn is an autoincrement long value

Returns:
the guest name

getSecretKey

public java.lang.String getSecretKey(java.nio.channels.SocketChannel channel)
Return the unique secret key for this socket channel
For further info about this method and its usage check the "Secure Login Tutorial"
found at chapter 8.9 of the documentation.

Parameters:
channel - the user socket channel
Returns:
the secret key

getUserByChannel

public User getUserByChannel(java.nio.channels.SocketChannel sc)
Return a User object from its socket channel

Parameters:
sc - a valid socket channel
Returns:
the User object

getUserById

public User getUserById(int id)
Return a User object from its numeric id

Parameters:
id - a valid user id
Returns:
the User object

logoutUser

public void logoutUser(int id,
                       boolean fireClientEvt,
                       boolean fireInternalEvt)
Logout a user from the current Zone

Parameters:
id - the user id

logoutUser

public void logoutUser(User user,
                       boolean fireClientEvt,
                       boolean fireInternalEvt)
Logout a user from the current Zone

Parameters:
user - the User object

sendGenericMessage

public void sendGenericMessage(java.lang.String message,
                               java.nio.channels.SocketChannel sender,
                               java.util.LinkedList channelList)
Send a generic text or XML message.
This method is rarely used, but it can be usefull for sending modified versions of the server system messages.

Parameters:
message - string or xml message
sender - the sender channel (can be null)
channelList - a list of recipient channels

createRoom

public 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)

For all the details about Rooms please refer also to the Application Architecture article found in Section A (white-papers) of the documentation

Parameters:
z - the Zone where the room will be created
params - a Map of params: name, pwd, isGame etc...
creator - the "owner" of the room. null = Server owned. A Server owned Room will be ignored by the default room management system and will be never removed, unless you it manually from your code.
sendUpdate - Update the clients about the new room created (true is recommended, otherwise clients will be out of synch with their Room Lists)
broadcastEvent - Broadcast the event internally.
Returns:
The new room
Throws:
it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException

createRoom

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.

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)

For all the details about Rooms please refer also to the Application Architecture article found in Section A (white-papers) of the documentation

Parameters:
z - the Zone where the room will be created
params - a Map of params: name,pwd,maxU,maxS,isGame
creator - the "owner" of the room. null = Server owned
roomVars - an HashMap of variables to set on the newly created room (null if not needed)
varsOwner - the owner of the variables
setOwnership - true = all modified/created variables will be owned by the creator User, false = ownership is not changed
sendUpdate - Update the clients about the new room created (true is recommended, otherwise clients will be out of synch with their Room Lists)
broadcastEvent - Broadcast the event internally.
Returns:
The new room
Throws:
it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException

joinRoom

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
Join a room from a server side extension

Parameters:
usr - the User object
currRoom - the id of the current room where the user is in
newRoom - the id of the room that the user wants to join
leaveRoom - if true the user will leave the current room once he successfully joined the new one
pword - an optional password for the room
isSpectator - if true the user is joined as spectator (for game rooms only)
broadcast - if true the onJoinRoom event is fired back to all clients (recommended)
Returns:
true if the room was successfully joined
Throws:
it.gotoandplay.smartfoxserver.exceptions.ExtensionHelperException

sendModeratorMessage

public 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.
This will fire an onModeratorMessage event on the client side.

Parameters:
message - the text message
sender - the sender user
type - 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.

sendRoomList

public void sendRoomList(java.nio.channels.SocketChannel sc)
Send a room list in default format (XML)
This will fire a onRoomListUpdate event on the client.

There is a specific "sequence" to keep in mind when the user is logging in:

  1. Connect
  2. Login
  3. Handle room list
  4. Join a room

You can see this in action by checking the PixelGame example found at chapter 8.10 of the docs.
The Java extension source can be found under the {path-to-your-sfs-folder}/Server/javaExtensions/ folder under the it.gotoandplay.extensions.examples package

Parameters:
sc - The SocketChannel that will receive the list

setRoomVariable

public 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. 

Set a room variable

Parameters:
r - the Room
u - the User
vn - the var name
vt - the var type
vv - the var value
pr - private flag
ps - persistent flag
setOwnership - setOwnership flag (will set the variable owner to the User who sent the request)
broadcastAll - if true the onRoomVariablesUpdate() event will be fired (reccomended)

setRoomVariables

public 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 Map of RoomVariables where the key is the variable name and the value is the RoomVariable object.

For all the details about Rooms and RoomVariables please refer also to the Application Architecture article found in Section A (white-papers) of the documentation

Also check Chapter 5.11 of the docs for a complete example of usage of Room Variables

Parameters:
r - the target room, where variables should be set
u - the user, owner of the variables
vars - a java.util.HashMap of RoomVariables
setOwnership - setOwnership flag (will set the variable owner to the User who sent the request)
broadcastAll - if true the onRoomVariablesUpdate() event will be fired (recommended)
See Also:
RoomVariable

setUserVariables

public void setUserVariables(User u,
                             java.util.HashMap vars,
                             boolean broadcastAll)
Set one or more User Variables.
The vars parameter requires a Map of UserVariables where the key is the variable name and the value is the UserVariable.

Also check Chapter 5.6 of the docs for a complete example of the usage of User Variables

Parameters:
vars - a map of UserVariables
u - the User object
broadcastAll - if true the onUserVariablesUpdate() event will be fired (reccomended)
See Also:
UserVariable

getZone

public Zone getZone(java.lang.String zoneName)
Return a Zone object from its name

Parameters:
zoneName - the name of the zone
Returns:
the Zone object

leaveRoom

public void leaveRoom(User u,
                      int roomId,
                      boolean broadcastEvent)
Force a user to leave a room.
Works only when the user is logged in more than one room at a time (multi-room mode)
Fires an onRoomLeft event on the client side.

For more details about the multi-room usage refer to Chapter 5.10 of the docs.

Parameters:
u - the user
roomId - the id of the room to leave
broadcastEvent - if true, the response event is fired (reccomended)

switchSpectator

public void switchSpectator(User u,
                            int roomId,
                            boolean brodcastEvent)
Switch a spectator into a player, if possible (game rooms only)
For more details about switching spectators to players you should check the SmartFoxTris game example.
In particular Chapter 8.8 of the docs is walk through in building a complete turn-based game with support for spectators. You will find the Java version of the game extension in {path-to-your-sfs-folder}/Server/javaExtensions/ folder under the it.gotoandplay.extensions.examples package
The game class is called SFSTris2.java

Parameters:
u - the user
roomId - the target room id
brodcastEvent - if true, the response event is fired (reccomended)

switchPlayer

public void switchPlayer(User u,
                         int roomId,
                         boolean brodcastEvent)
Switch a player into a spectator, if possible (game rooms only)
Fires an onPlayerSwitched event on the client side.

Parameters:
u - the user
roomId - the target room id
brodcastEvent - if true, the response event is fired (reccomended)

disconnectUser

public void disconnectUser(User u)
Disconnects a client from the server.

Parameters:
u - the user to kick

destroyRoom

public boolean destroyRoom(Zone zone,
                           int roomId)
Destroys a server room.
Rooms can be destroyed only if they don't contain any user.
Additionally rooms are auto-removed by the default room manager. The only rooms that are never removed are static rooms defined in the external server configuration file or dynamic rooms whose owner field is set to null

Parameters:
zone - the zone
roomId - the roomId
Returns:
true if room was destroyed

addBuddy

public void addBuddy(java.lang.String buddyName,
                     User user)
Add a buddy to a user buddy list
Based on the BuddyList configuration this may immediately add the buddy to the user list or send a buddy request that the target user must respond to.

If mutualAddBuddy is activated both users will be added to their respective buddy lists.

You can learn more about the Buddy List system by checking chapters 5.12, 6.10, and 8.16 of the docs.

Parameters:
buddyName - the name of the buddy to add
user - the user whose buddy list should be updated
Since:
1.6.0

removeBuddy

public void removeBuddy(java.lang.String buddyName,
                        User user)
Removes a buddy from a user buddy list.
If mutualRemoveBuddy is activated both users will be removed to their respective buddy lists.

You can learn more about the Buddy List system by checking chapters 5.12, 6.10, and 8.16 of the docs.

Parameters:
buddyName - the name of the buddy to remove
user - the user whose buddy list should be updated
Since:
1.6.0

requestAddBuddyPermission

public void requestAddBuddyPermission(User sender,
                                      java.lang.String targetUserName,
                                      java.lang.String optionalMessage)

Requests permission for adding the target user in the sender buddy list. This is already done by default if the mode of the buddy list is set to ADVANCED. In most of the cases you wouldn't need to call this method in your extension.

It could be used to implement an off-line permission request system, where the system stores the requests for off-line users in a database and sends the requests as soon as the target user logs in.

You can learn more about the Buddy List 2.0 system by checking chapters 6.10, 8.16 of the docs.

Parameters:
sender - the requester
targetUserName - the name of the target user
optionalMessage - an optional text message for the request. Use null if you don't need it.
Since:
1.6.0

clearBuddyList

public void clearBuddyList(User user)
Deprecated. 

Clear a user buddy list. All the entries in the buddylist will be cleared.

Parameters:
user - the user whose buddy list should be cleared.

setBuddyVariables

public void setBuddyVariables(User user,
                              java.util.Map<java.lang.String,java.lang.String> variables)

Set the buddy variables of the specified user.

The variables Map contains all the variables to set, where the key is the name of the variable and the value represents the variable value.

Since version 1.6.0 you can set off-line buddy variables by using a '$' sign as the first character of the variable name.
Example:

 Map variables = new HashMap();
 variables.put("$country", "Italy"); // an off-line buddy variable
 variables.put("invisible", "false"); // a regular buddy variable
 
 helper.setBuddyVariables( theUser, variables );
 

You can learn more about the Buddy List 2.0 system by checking chapters 6.10, 8.16 of the docs.

Parameters:
user - the User
variables - a map containing the variables to set
Since:
1.6.0

sendBuddyListUpdate

public void sendBuddyListUpdate(User user)
Send an update about the specified User to all clients that have him/her in their buddy list.
Normally you don't need to call this method. Updates are sent automatically when needed.
You may need to force an update if you're manipulating the buddy lists without using the regular commands (add, remove, etc...)

You can learn more about the Buddy List 2.0 system by checking chapters 6.10, 8.16 of the docs.

Parameters:
user - A User
Since:
1.6.0

setBuddyBlockStatus

public void setBuddyBlockStatus(User user,
                                java.lang.String buddyName,
                                boolean isBlocked)
Set the isBlocked flag of a buddy in the User's buddy list.
When the isBlocked flag is set to true the buddy won't be able to send any messages to the user.

You can learn more about the Buddy List 2.0 system by checking chapters 6.10, 8.16 of the docs.

Parameters:
user - the owner of the buddy list
buddyName - the name of the buddy to block / unblock
isBlocked - the status (true == blocked)
Since:
1.6.0

kickUser

public void kickUser(User user,
                     int delay,
                     java.lang.String farewellMessage)
Kicks a user allowing to specify a delay before the task is executed and an admin message.
The admin message should be handled on the client side via the onAdminMessage callback.

Parameters:
user - the user
delay - an amount of seconds before the actual task is executed
farewellMessage - an admin message that is sent immediately to the user
Since:
1.6.3

banUser

public void banUser(User user,
                    int delay,
                    java.lang.String farewellMessage,
                    int banType)
Disconnects and bans a user.
The banishment will be cleared after a certain amount of time as specified in the config.xml, in the <BanDuration> The admin message should be handled on the client side via the onAdminMessage callback.

Parameters:
user - the user
delay - an amount of seconds to wait before disconnecting the user
farewellMessage - an admin message that is sent immediately
banType - you can ban by Ip address or Name.
Since:
1.6.3
See Also:
BanTypes

banOfflineUser

public void banOfflineUser(java.lang.String userName)
Banishes an offline user by name

Parameters:
userName - the user name
Since:
1.6.3

removeBanishment

public void removeBanishment(java.lang.String param,
                             int mode)
Removes a banned user from the ban-list, allowing him/her to be able to login again

Parameters:
param - can be a user name or an ip address based on the 2nd argument
mode - the ban mode (by ip or by name)
Since:
1.6.3
See Also:
BanTypes

createNPC

public User createNPC(java.lang.String userName,
                      java.lang.String ipAddress,
                      int port,
                      java.lang.String zoneName)

Creates an NPC (Non-Player Character) or BOT User that can be used for automated tasks, game AI etc... It will be able to send and receive messages and it will be seen from client side as a real user.

NPCs need to be connected to a physical socket end in order to "trick" the server into thinking that it is a real connected client. This is done behind the scenes by running a connection to the localhost, so if you take a look at the Admin Tool you will notice that NPC connections all come from 127.0.0.1

NPCs are subject to the MaxIdleUserTime policy as any other connected users, so you will need to start a thread or add a Scheduled task (recommended) that invokes the updateMessageTime() method on each non-player character to avoid disconnections.

Parameters:
userName - name of the NPC
ipAddress - ip address of the socket end
port - TCP port number
zoneName - the zone in which the NPC should be logged in
Returns:
the User object
Since:
1.6.3

addModerator

public void addModerator(java.lang.String zoneName,
                         java.lang.String modName,
                         java.lang.String modPass)
Add a new moderator to a Zone

Parameters:
zoneName - name of the zone
modName - name of the user that will act as Moderator
modPass - password for the moderator
Since:
1.6.3

removeModerator

public void removeModerator(java.lang.String zoneName,
                            java.lang.String modName)
Removes a moderator user from a Zone

Parameters:
zoneName - name of the Zone
modName - name of the moderator user
Since:
1.6.3

rebootServer

public void rebootServer()
Performs a soft reboot of the server, just like hitting the "Restart" button in the Admin interface.
All connections will be closed and all extensions shut down and restarted.