multiverse.server.worldmgr
Class LoginPlugin

java.lang.Object
  extended by multiverse.server.engine.EnginePlugin
      extended by multiverse.server.worldmgr.LoginPlugin
All Implemented Interfaces:
MessageCallback, StatusMapCallback, TcpAcceptCallback
Direct Known Subclasses:
MarsLoginPlugin

public class LoginPlugin
extends EnginePlugin
implements TcpAcceptCallback

Supports the character selection and creation protocols. The plugin returns a list characters available to the user. Includes character properties and the proxy server host/port for each character.

The user can create a character by supplying a set of character properties. The plugin returns the new character properties or an error if the character could not be created.

LoginPlugin must be sub-classed to implement character selection and creation. A sub-class must implement #handleCharacterRequestMessage(CharacterRequestMessage, SocketChannel) and may implement #handleCharacterCreateMessage(CharacterCreateMessage , SocketChannel , MVByteBuffer) if character creation is supported and #handleCharacterDeleteMessage(CharacterDeleteMessage , SocketChannel , MVByteBuffer) if character deletion is supported. Sub-classes should not need to call any LoginPlugin methods except getCharacterGenerator().

For a sample implementation see multiverse.mars.plugins


Nested Class Summary
 class LoginPlugin.CharacterCreateMessage
          Message to create a character using the given properties.
 class LoginPlugin.CharacterCreateResponseMessage
          Message to return new character properties.
 class LoginPlugin.CharacterDeleteMessage
          Message to delete a character using the given properties.
 class LoginPlugin.CharacterDeleteResponseMessage
          Message to return new character properties.
 class LoginPlugin.CharacterRequestMessage
          Message to authorize user and get their character list.
 class LoginPlugin.CharacterResponseMessage
          Message to return world token and character list.
 class LoginPlugin.CharacterSelectRequestMessage
          Message to log in as the selected character.
 class LoginPlugin.CharacterSelectResponseMessage
          Message to return access token and hostname/port for selected character.
protected  class LoginPlugin.SocketHandler
           
 
Nested classes/interfaces inherited from class multiverse.server.engine.EnginePlugin
EnginePlugin.DeleteHook, EnginePlugin.DeleteSubObjHook, EnginePlugin.GenerateSubObjectHook, EnginePlugin.GetPropertyMessage, EnginePlugin.LoadHook, EnginePlugin.LoadSubObjHook, EnginePlugin.PluginActivateHook, EnginePlugin.PluginStateMessage, EnginePlugin.SaveHook, EnginePlugin.SaveSubObjHook, EnginePlugin.SetPropertyMessage, EnginePlugin.SubObjData, EnginePlugin.TransferFilter, EnginePlugin.TransferObjectMessage, EnginePlugin.UnloadHook, EnginePlugin.UnloadSubObjHook
 
Field Summary
private  Object characterCreateLock
           
private static CharacterGenerator characterGenerator
           
static int LOGIN_IDLE_TIMEOUT
           
private  TcpServer loginListener
           
static int MSGCODE_CHARACTER_CREATE
           
static int MSGCODE_CHARACTER_CREATE_RESPONSE
           
static int MSGCODE_CHARACTER_DELETE
           
static int MSGCODE_CHARACTER_DELETE_RESPONSE
           
static int MSGCODE_CHARACTER_REQUEST
           
static int MSGCODE_CHARACTER_RESPONSE
           
static int MSGCODE_CHARACTER_SELECT_REQUEST
           
static int MSGCODE_CHARACTER_SELECT_RESPONSE
           
static int MSGCODE_SECURE_CHARACTER_REQUEST
           
static boolean SecureToken
          The master server sends us the account id in a secure manner by default.
private  Integer tcpPort
           
private static ExecutorService threadPool
           
static long TokenValidTime
           
static Integer WorldId
          If WorldId is set, the LoginPlugin only accepts master tokens that specify the correct world id.
 
Fields inherited from class multiverse.server.engine.EnginePlugin
deleteSubObjectSubscription, dumpAllThreadSubscription, dumpAllThreadSubscriptionLock, loadSubObjectSubscription, lock, MSG_TYPE_DUMP_ALL_THREAD_STACKS, MSG_TYPE_GET_PROPERTY, MSG_TYPE_PLUGIN_STATE, MSG_TYPE_SET_PROPERTY, MSG_TYPE_SET_PROPERTY_NONBLOCK, MSG_TYPE_TRANSFER_OBJECT, pluginStateSubscription, propertySubscription, saveSubObjectSubscription, selectionFilter, selectionSubscription, setSubObjectPersistenceSubscription, subObjectSubscription, unloadSubObjectSubscription
 
Fields inherited from interface multiverse.msgsys.MessageCallback
NO_FLAGS, RESPONSE_EXPECTED
 
Constructor Summary
LoginPlugin()
           
 
Method Summary
 void dbConnect()
          This method connects to the database.
static CharacterGenerator getCharacterGenerator()
          Get the global character generator.
 int getTCPPort()
          This method returns the port the login plugin will listen to for incoming tcp connection.
protected  LoginPlugin.CharacterCreateResponseMessage handleCharacterCreateMessage(LoginPlugin.CharacterCreateMessage message, LoginPlugin.SocketHandler clientSocket)
          Respond to a character creation request from the client.
protected  LoginPlugin.CharacterDeleteResponseMessage handleCharacterDeleteMessage(LoginPlugin.CharacterDeleteMessage message, LoginPlugin.SocketHandler clientSocket)
           
protected  LoginPlugin.CharacterResponseMessage handleCharacterRequestMessage(LoginPlugin.CharacterRequestMessage message, LoginPlugin.SocketHandler clientSocket)
          Respond to a character list request message from the client.
protected  LoginPlugin.CharacterSelectResponseMessage handleCharacterSelectRequestMessage(LoginPlugin.CharacterSelectRequestMessage message, LoginPlugin.SocketHandler clientSocket)
           
 void onActivate()
          for developers extending the EnginePlugin object, it may be easier to use the onActivate() method which gets called when the plugin is being activated by the Engine.
 void onTcpAccept(SocketChannel clientSocket)
           
protected  PluginStatus selectBestProxy(List<PluginStatus> plugins, Map<String,Serializable> characterProperties)
           
protected  PluginStatus selectProxyPlugin(Map<String,Serializable> characterProperties)
           
protected  boolean setProxyProperties(Map<String,Serializable> props, PluginStatus proxy)
           
 void setTCPPort(int port)
          Set the port the login plugin will listen to for incoming tcp connection.
private static String socketToString(SocketChannel channel)
           
 
Methods inherited from class multiverse.server.engine.EnginePlugin
activate, createMBeanInstance, createSubscription, getHookManager, getMessageHandler, getName, getObjectLockManager, getObjectProperties, getObjectProperties, getObjectProperty, getPercentCPULoad, getPluginAvailable, getPluginInfo, getPluginNamespaces, getPluginState, getPluginStatus, getPluginType, getPropertyImpl, getStatusMap, handleMessage, handleMessageImpl, logDepsOutstanding, processKeysAndValues, registerActivateHook, registerDeleteHook, registerLoadHook, registerPluginNamespace, registerPluginNamespaces, registerPluginNamespaces, registerPluginNamespaces, registerSaveHook, registerTransferHook, registerUnloadHook, sendSubObjectResponse, sendSubObjectResponse, sendSubObjectResponse, setMessageHandler, setName, setObjectProperties, setObjectProperties, setObjectPropertiesNoResponse, setObjectPropertiesNoResponse, setObjectProperty, setObjectPropertyNoResponse, setPercentCPULoad, setPluginAvailable, setPluginInfo, setPluginType, setPropertyImpl, transferObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MSGCODE_CHARACTER_RESPONSE

public static final int MSGCODE_CHARACTER_RESPONSE
See Also:
Constant Field Values

MSGCODE_CHARACTER_DELETE

public static final int MSGCODE_CHARACTER_DELETE
See Also:
Constant Field Values

MSGCODE_CHARACTER_DELETE_RESPONSE

public static final int MSGCODE_CHARACTER_DELETE_RESPONSE
See Also:
Constant Field Values

MSGCODE_CHARACTER_CREATE

public static final int MSGCODE_CHARACTER_CREATE
See Also:
Constant Field Values

MSGCODE_CHARACTER_CREATE_RESPONSE

public static final int MSGCODE_CHARACTER_CREATE_RESPONSE
See Also:
Constant Field Values

MSGCODE_CHARACTER_REQUEST

public static final int MSGCODE_CHARACTER_REQUEST
See Also:
Constant Field Values

MSGCODE_CHARACTER_SELECT_REQUEST

public static final int MSGCODE_CHARACTER_SELECT_REQUEST
See Also:
Constant Field Values

MSGCODE_CHARACTER_SELECT_RESPONSE

public static final int MSGCODE_CHARACTER_SELECT_RESPONSE
See Also:
Constant Field Values

MSGCODE_SECURE_CHARACTER_REQUEST

public static final int MSGCODE_SECURE_CHARACTER_REQUEST
See Also:
Constant Field Values

LOGIN_IDLE_TIMEOUT

public static final int LOGIN_IDLE_TIMEOUT
See Also:
Constant Field Values

threadPool

private static ExecutorService threadPool

loginListener

private TcpServer loginListener

tcpPort

private Integer tcpPort

characterCreateLock

private Object characterCreateLock

SecureToken

public static boolean SecureToken
The master server sends us the account id in a secure manner by default. If clients bypass the master server, set this to false. This allows people to masquerade as others and should only be used for development purposes.


TokenValidTime

public static long TokenValidTime

WorldId

public static Integer WorldId
If WorldId is set, the LoginPlugin only accepts master tokens that specify the correct world id.


characterGenerator

private static CharacterGenerator characterGenerator
Constructor Detail

LoginPlugin

public LoginPlugin()
Method Detail

dbConnect

public void dbConnect()
This method connects to the database. It assumes the host, user, and port have already been set.


setTCPPort

public void setTCPPort(int port)
Set the port the login plugin will listen to for incoming tcp connection.

Parameters:
port - the port number used for incoming tcp connections

getTCPPort

public int getTCPPort()
This method returns the port the login plugin will listen to for incoming tcp connection.

Returns:
the tcp port number
See Also:
setTCPPort(int)

onActivate

public void onActivate()
Description copied from class: EnginePlugin
for developers extending the EnginePlugin object, it may be easier to use the onActivate() method which gets called when the plugin is being activated by the Engine. this is an alternative to calling registerActivateHook()

Overrides:
onActivate in class EnginePlugin

socketToString

private static String socketToString(SocketChannel channel)

onTcpAccept

public void onTcpAccept(SocketChannel clientSocket)
Specified by:
onTcpAccept in interface TcpAcceptCallback

handleCharacterRequestMessage

protected LoginPlugin.CharacterResponseMessage handleCharacterRequestMessage(LoginPlugin.CharacterRequestMessage message,
                                                                             LoginPlugin.SocketHandler clientSocket)
Respond to a character list request message from the client. The message contains the client's auth token and client version. Implementations should verify the authenticity of the token and return an empty world token if the token is invalid. If the auth token is valid, then LoginPlugin.CharacterResponseMessage.setWorldToken(String) should be set to a non-empty string. This will indicate to the LoginPlugin base class that the user is authorized. The auth token to be passed to subsequent handleCharacterCreateMessage() calls only if the user is authorized.

The auth token should contain (or otherwise supply) the user's identity. The user's characters are returned in a LoginPlugin.CharacterResponseMessage.

Implementations must not read or write data to the clientSocket.

Parameters:
message - request for character list and authorization.
clientSocket - the client's socket connection. Useful for determining the client's source IP and port number. Implementations must not read or write data to the socket.

handleCharacterCreateMessage

protected LoginPlugin.CharacterCreateResponseMessage handleCharacterCreateMessage(LoginPlugin.CharacterCreateMessage message,
                                                                                  LoginPlugin.SocketHandler clientSocket)
Respond to a character creation request from the client. The message contains the desired character properties.

If character creation is successful, the returned CharacterCreateResponseMessage should contain the new character properties. In addition, the response should also contain a Boolean "status" property that is TRUE for success and FALSE for failure. In case of failure, the response should contain a String "errorMessage" property.

Implementations must not read or write data to the clientSocket.


handleCharacterDeleteMessage

protected LoginPlugin.CharacterDeleteResponseMessage handleCharacterDeleteMessage(LoginPlugin.CharacterDeleteMessage message,
                                                                                  LoginPlugin.SocketHandler clientSocket)

handleCharacterSelectRequestMessage

protected LoginPlugin.CharacterSelectResponseMessage handleCharacterSelectRequestMessage(LoginPlugin.CharacterSelectRequestMessage message,
                                                                                         LoginPlugin.SocketHandler clientSocket)

setProxyProperties

protected boolean setProxyProperties(Map<String,Serializable> props,
                                     PluginStatus proxy)

getCharacterGenerator

public static CharacterGenerator getCharacterGenerator()
Get the global character generator.


selectProxyPlugin

protected final PluginStatus selectProxyPlugin(Map<String,Serializable> characterProperties)

selectBestProxy

protected PluginStatus selectBestProxy(List<PluginStatus> plugins,
                                       Map<String,Serializable> characterProperties)