org.mega.gasp.client.midp
Class GASPClient

java.lang.Object
  extended byorg.mega.gasp.client.midp.GASPClient

public abstract class GASPClient
extends java.lang.Object

A game client logic running with the MGP must implement this class, MGPClient.

Author:
PELLERIN Romain (pellerin@cnam.fr) - MEGA Project

Field Summary
protected static javax.microedition.io.HttpConnection connection
           
protected  CustomTypes customTypes
           
private static java.io.DataInputStream dis
           
private static java.io.DataOutputStream dos
           
private static java.lang.String GPServletContainerUrl
           
 
Constructor Summary
GASPClient()
           
 
Method Summary
private static void closeAllConnection()
          Close all connection streams and the connection.
protected  int createAI(int sID, int minActors, int maxActors)
          Create an public ApplicationInstance.
protected  int createAIPriv(int sID, java.lang.String[] actors, int minActors, int maxActors)
          Create a private Application Instance with the choosed actors.
protected  void endAI(int aSID)
          (Try to) End the game if the user is the owner of the application instance.
private  void eventsOf(java.io.DataInputStream dis)
          Treats the events of the servlet response data input stream.
protected  int firstLogin(int applicationID, java.lang.String username, java.lang.String password)
          This method is called when the user use the application for the first time, e.g when the Actor ID is not present on the client.
private  java.util.Vector formLobbyDatas(java.io.DataInputStream dis)
          Form the datas contained on the DataInputStream of the lobby servlet response, returns a vector of ApplicationInstanceInfos objects.
protected  java.util.Vector getApplicationInstances(int sID)
          Returns a stream of game sessions currently available on the Gaming Platform.
protected  void getEvents(int aSID)
          Provide to get the events in user actorSession on the Platform.
abstract  void initCustomTypes()
           
protected  int joinAI(int sID, int aIID)
          Join the specific ApplicationInstance ID.
protected  int joinAIRnd(int sID)
          Join randomly an open ApplicationInstance.
protected  int login(int aID, java.lang.String username, java.lang.String password, java.lang.String version)
          Provide the login on the Gaming Platform, require the correct ActorID, the username and the password, the version of MGIF is optional.
protected  java.lang.String name(int aSID, java.lang.String name)
          In game session, this method provides to the user to change his pseudoname.
abstract  void onDataEvent(int actorSessionID, java.util.Hashtable datas)
          Method called when a DataEvent is received from the platform.
abstract  void onEndEvent(int actorSessionID)
          Method called when a EndEvent is received from the platform.
abstract  void onJoinEvent(int actorSessionID, java.lang.String username)
          Method called when a JoinEvent is received from the platform.
abstract  void onQuitEvent(int actorSessionID)
          Method called when a QuitEvent is received from the platform.
abstract  void onStartEvent(int actorSessionID)
          Method called when a StartEvent is received from the platform.
protected  void quit(int sID)
          Quit the platform.
protected  void quitAI(int aSID)
          Quit the ApplicationInstance joined.
protected  void sendData(int aSID, java.util.Hashtable h)
          Provide to send in game datas to the Platform.
private  java.io.DataInputStream servletRequest(java.lang.String servletName, java.lang.String formData)
          Send a request to the specified servlet with the http post parameters.
private  java.io.DataInputStream servletSendDataRequest(java.lang.String servletName, int aSID, java.util.Hashtable h)
          Send the data in the hashtable to the specified servlet.
protected  boolean startAI(int aSID)
          (Try to) Start the game if the user is the owner of the application instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GPServletContainerUrl

private static java.lang.String GPServletContainerUrl

customTypes

protected CustomTypes customTypes

connection

protected static javax.microedition.io.HttpConnection connection

dos

private static java.io.DataOutputStream dos

dis

private static java.io.DataInputStream dis
Constructor Detail

GASPClient

public GASPClient()
Method Detail

initCustomTypes

public abstract void initCustomTypes()

firstLogin

protected int firstLogin(int applicationID,
                         java.lang.String username,
                         java.lang.String password)
This method is called when the user use the application for the first time, e.g when the Actor ID is not present on the client. Returns the ActorID if authentification informations are valids.

Parameters:
applicationID - the ID of the application
username - the username wanted by the user
password - the password wanted by the user
Returns:
the Actor ID

login

protected int login(int aID,
                    java.lang.String username,
                    java.lang.String password,
                    java.lang.String version)
Provide the login on the Gaming Platform, require the correct ActorID, the username and the password, the version of MGIF is optional.

Parameters:
aID - the Actor ID of the user stored on the mobile
username - the username choosed at the first login
password - the password chooset at the first login
version - MGIF compliant version
Returns:
the Session ID of the user

getApplicationInstances

protected java.util.Vector getApplicationInstances(int sID)
Returns a stream of game sessions currently available on the Gaming Platform.

Parameters:
sID - the Session ID of the user
Returns:
the stream format (applicationInstanceID, (actorID,username)*)*

formLobbyDatas

private java.util.Vector formLobbyDatas(java.io.DataInputStream dis)
                                 throws java.io.IOException
Form the datas contained on the DataInputStream of the lobby servlet response, returns a vector of ApplicationInstanceInfos objects.

Returns:
the vector of ApplicationInstanceInfos objects
Throws:
java.io.IOException

joinAI

protected int joinAI(int sID,
                     int aIID)
Join the specific ApplicationInstance ID.

Parameters:
sID - the Session ID of the user
aIID - the ApplicationInstance ID choosed
Returns:
the ActorSession ID of the user

joinAIRnd

protected int joinAIRnd(int sID)
Join randomly an open ApplicationInstance.

Parameters:
sID - the Session ID of the user
Returns:
the ActorSession ID of the user

createAI

protected int createAI(int sID,
                       int minActors,
                       int maxActors)
Create an public ApplicationInstance.

Parameters:
sID - the Session ID of the user
minActors - the minimum number of actors required to start
maxActors - the maximum number of actors
Returns:
the ActorSession ID of the user

createAIPriv

protected int createAIPriv(int sID,
                           java.lang.String[] actors,
                           int minActors,
                           int maxActors)
Create a private Application Instance with the choosed actors.

Parameters:
sID - the Session ID of the user
actors - the table of ActorID representing the actors accepted in the game session
minActors - the minimum number of actors required to start
maxActors - the maximum number of actors
Returns:
the ActorSession ID of the user

getEvents

protected void getEvents(int aSID)
Provide to get the events in user actorSession on the Platform.

Parameters:
aSID - the ActorSession ID
Returns:
a vector of events send by the platform

name

protected java.lang.String name(int aSID,
                                java.lang.String name)
In game session, this method provides to the user to change his pseudoname. Returns a boolean representing the success of the operation.

Parameters:
aSID -
Returns:
boolean

startAI

protected boolean startAI(int aSID)
(Try to) Start the game if the user is the owner of the application instance. Return 1 if the game has started, else 0. For manual mode only.

Parameters:
aSID -
Returns:
int

endAI

protected void endAI(int aSID)
(Try to) End the game if the user is the owner of the application instance. Return 1 if the game has ended, else 0. For manual mode only.

Parameters:
aSID -

quitAI

protected void quitAI(int aSID)
Quit the ApplicationInstance joined.

Parameters:
aSID - the ActorSession ID

sendData

protected void sendData(int aSID,
                        java.util.Hashtable h)
Provide to send in game datas to the Platform.

Parameters:
aSID - the ActorSession ID
h - the hashtable of datas
Returns:
a vector of events send by the platform

eventsOf

private void eventsOf(java.io.DataInputStream dis)
               throws java.io.IOException
Treats the events of the servlet response data input stream.

Parameters:
dis - the data input strem
Returns:
Throws:
java.io.IOException

quit

protected void quit(int sID)
Quit the platform.

Parameters:
sID - the Session ID of the user

servletRequest

private java.io.DataInputStream servletRequest(java.lang.String servletName,
                                               java.lang.String formData)
                                        throws java.io.IOException
Send a request to the specified servlet with the http post parameters. Return the servlet response DataInputStream.

Parameters:
servletName - the name of the servlet
formData - the HTTP post parameters
Returns:
the DataInputStream
Throws:
java.io.IOException

servletSendDataRequest

private java.io.DataInputStream servletSendDataRequest(java.lang.String servletName,
                                                       int aSID,
                                                       java.util.Hashtable h)
                                                throws java.io.IOException
Send the data in the hashtable to the specified servlet.

Parameters:
servletName - the name of the servlet
Returns:
the DataInputStream of the servlet response
Throws:
java.io.IOException

closeAllConnection

private static void closeAllConnection()
Close all connection streams and the connection.


onJoinEvent

public abstract void onJoinEvent(int actorSessionID,
                                 java.lang.String username)
Method called when a JoinEvent is received from the platform.

Parameters:
actorSessionID -
username -

onStartEvent

public abstract void onStartEvent(int actorSessionID)
Method called when a StartEvent is received from the platform.

Parameters:
actorSessionID -

onEndEvent

public abstract void onEndEvent(int actorSessionID)
Method called when a EndEvent is received from the platform.

Parameters:
actorSessionID -

onQuitEvent

public abstract void onQuitEvent(int actorSessionID)
Method called when a QuitEvent is received from the platform.

Parameters:
actorSessionID -

onDataEvent

public abstract void onDataEvent(int actorSessionID,
                                 java.util.Hashtable datas)
Method called when a DataEvent is received from the platform.

Parameters:
actorSessionID -
datas - the hashtable of datas