com.SecurePlay
Class SPGameClass

java.lang.Object
  extended bycom.SecurePlay.SPRootTransactionClass
      extended bycom.SecurePlay.SPGameClass
All Implemented Interfaces:
SPGameInterface

public class SPGameClass
extends SPRootTransactionClass
implements SPGameInterface

This is the general class that holds a game instance. It is also the transaction class for the basic game transaction.

Author:
IT GlobalSecure
See Also:
SecurePlay License Information
 

Field Summary
 
Fields inherited from class com.SecurePlay.SPRootTransactionClass
EventListenerList, gameID, master, playerIDList, transactionID
 
Constructor Summary
SPGameClass()
          Default Constructor Consructor
 
Method Summary
 boolean addComms(java.lang.String commsID)
          This method associates a comms service specified by the commsID string to a game instance.
 boolean addPlayer(java.lang.String pid)
          This method safely adds an existing Player, specified by the playerID to the game instance.
 boolean addTransaction(SPAbstractTransactionInterface transObj)
          This safely adds a transaction to a game instance and appropriately updates the game state.
 boolean attach(java.lang.String gid, SecurePlayClass lib, java.lang.String master, boolean signaturepolicy, boolean encryptionpolicy, SPLogInterface log, SPSecurityManagerInterface security)
          This method attaches an empty game object instance and configures it for use in the SecurePlay library as a game NOTE: This method does not set the classAPI because it is an attached game.
 boolean closeTransaction(java.lang.String transID)
          Safely removes a transaction from a game instance.
 boolean gameComplete()
          This method allows external entities to review the status of the game instance without directly accessing its internals.
 int getBasicGameTransactionCount()
          Getter function that returns the property: prBasicGameTransactionCount
 SPCommsManagerClass getCommsManager()
          Gets the comms manager object
 java.lang.String getCurrentGameSegment()
          Getter function that returns the property: prcurrentGameSegment
 SPGameAPIInterface getGameAPI()
          This method returns the handler for the Game API object.
 SPPlayerInterface getGamePlayer(java.lang.String playerID)
          This method returns the player object specified by the playerID.
 int getGameSegmentCount()
          Getter function that returns the property: prgamesegmentcount
 java.lang.String getGamestatus()
          Getter function that returns the property: gamestatus
 SPAbstractTransactionInterface getGameTransaction(java.lang.String tid)
          This method returns a specific transaction associated with a given game instance.
 byte[] getHashText(java.lang.String plainText, java.lang.String algorithm)
          This method gets the hashed string
 java.lang.String getNextGameSegment()
          Getter function that returns the property: prnextGameSegment
 java.lang.String[] getOpentransactionIDList()
          Getter function that returns the open transaction IDs
 SPPlayerInterface[] getPlayers()
          Getter function that returns the players from prplayerlist
 int getPreloadGameSegment()
          Getter function that returns the property: prpreloadGameSegment
 SecurePlayClass getSecurePlay()
          This method returns the unique SecurePlay library object associated with the game instance object.
 SPSecurityManagerInterface getSecurityManager()
          This method returns the security manager class associated with this game.
 SPAbstractTransactionInterface[] getTransactions()
          Getter function that returns the transactions from propentransactionlist
 boolean incrementBasicGameTransactionCount(int count)
          This method increments the game’s transaction counter to support certain licensing models
 boolean isPlayerInternal(java.lang.String pid)
          Checks to see if the player is internal
 void logError()
          This method is a placeholder for future internal logging
 boolean onbeginGame(SPMessageClass messObj)
          This method handles requests to begin the local game.
 boolean onendGame(SPMessageClass messObj)
          This method safely ends the local game instance.
 void onIncomingTransaction(SPMessageClass messObj)
          This method is the generic handler for incoming Game transaction methods.
 boolean onnextGameSegmentID(SPMessageClass messObj)
          This method supports the SecurePlay licensing system to maintain synchronization of game segment IDs within a game.
 void onrequestbeginGame(SPMessageClass messObj)
          This method handles incoming requests to begin a game It passes the requests on to the API rules parser.
 void onrequestendGame(SPMessageClass messObj)
          This method passes a request to end a game on to the game master's rule parser.
 java.lang.String prsetTransactionID(SPAbstractTransactionInterface transObj)
          This method generates a transactionID for a transaction object
 void prUpdateGameStatus()
          This method does a self-check on the game instance object and updates its status appropriately.
 boolean removeComms(java.lang.String commsID)
          This method removes the association of a communications service with a game instance.
 boolean removePlayer(java.lang.String pid)
          This method safely removes a Player instance from an existing Game Instance.
 boolean sendMessage(java.lang.String sender, java.lang.String[] receivers, boolean encryptflag, boolean privateflag, java.lang.String messagetype, java.lang.String[] messagebody, java.lang.String[] altmessage)
          This method actually constructs messages to be sent by the Game object to other game object instances via the Comms Manager
 boolean setPlayerComms(java.lang.String playerID, java.lang.String commsID, boolean relayflag)
          This method associates a specific player instance, specified by the playerID, with a specific communications service, specified by the commsID.
 byte[] SPcreateBHash(java.lang.String input, java.lang.String gameid)
          This is a wrapper function for creating a hash of a string.
 byte[] SPcreateBSignature(java.lang.String senderID, byte[] input, java.lang.String gameid)
          This is a wrapper function for creating a digital signature based on an existing hashed string and a Sender ID.
 java.lang.String SPcreateHash(java.lang.String input, java.lang.String gameid)
          This is a wrapper function for creating a hash of a string.
 java.lang.String SPcreateSignature(java.lang.String senderID, java.lang.String input, java.lang.String gameid)
          This is a wrapper function for creating a digital signature based on an existing hashed string and a Sender ID.
 java.lang.String[] SPdecrypt(java.lang.String[] input, java.lang.String senderID, java.lang.String[] recvrs, java.lang.String gameID, java.lang.String messageID)
          This is a placeholder for an decryption function.
 java.lang.String[] SPencrypt(java.lang.String[] input, java.lang.String senderID, java.lang.String[] recvrs, java.lang.String gameID, java.lang.String messageID)
          This is a placeholder for an encryption function.
 java.lang.String SPtransform(java.lang.String input, java.lang.String gameid)
          This function performs an irreversible transform on an input string to generate an output string.
 boolean SPverifySignature(byte[] sigToVerify, java.lang.String senderID, byte[] testhash, java.lang.String gameid)
          This is a wrapper for a digital signature verification function.
 boolean SPverifySignature(java.lang.String signature, java.lang.String senderID, java.lang.String testhash, java.lang.String gameid)
          This is a wrapper for a digital signature verification function.
 boolean transactionincluded(java.lang.String tid)
          This method checks the specified transaction ID against the currently included transaction IDs in the game instance.
 boolean updateGameSegment(java.lang.String currentseg, java.lang.String nextseg)
          This method supports the administration of game segment IDs and counters.
 
Methods inherited from class com.SecurePlay.SPRootTransactionClass
APIAddListener, APIClearListeners, APIGetListenerCount, APIGetListeners, APIRemoveListener, getGameID, getMaster, getPlayerIDList, getTransactionID, isPlayerIncluded, SPnotify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.SecurePlay.SPGameInterface
getGameID, getMaster, getPlayerIDList, getTransactionID, SPnotify
 

Constructor Detail

SPGameClass

public SPGameClass()
Default Constructor Consructor

Method Detail

attach

public boolean attach(java.lang.String gid,
                      SecurePlayClass lib,
                      java.lang.String master,
                      boolean signaturepolicy,
                      boolean encryptionpolicy,
                      SPLogInterface log,
                      SPSecurityManagerInterface security)
Description copied from interface: SPGameInterface
This method attaches an empty game object instance and configures it for use in the SecurePlay library as a game NOTE: This method does not set the classAPI because it is an attached game. The attached game does not have to behave like AbstractGame.

Specified by:
attach in interface SPGameInterface
Parameters:
gid - String - game id
lib - SecurePlayClass - the secure play library
master - String - the master of the game
signaturepolicy - boolean - signature policy
encryptionpolicy - boolean - encryption policy
log -
security -

getGameAPI

public SPGameAPIInterface getGameAPI()
Description copied from interface: SPGameInterface
This method returns the handler for the Game API object.

Specified by:
getGameAPI in interface SPGameInterface
Returns:
classAPI - SPAbstractGameAPI - Game API object handler

addPlayer

public boolean addPlayer(java.lang.String pid)
Description copied from interface: SPGameInterface
This method safely adds an existing Player, specified by the playerID to the game instance.

Specified by:
addPlayer in interface SPGameInterface
Parameters:
pid - String - the id of the player to be added
Returns:
result - Boolean: TRUE, if successful, FALSE, if no

removePlayer

public boolean removePlayer(java.lang.String pid)
Description copied from interface: SPGameInterface
This method safely removes a Player instance from an existing Game Instance.

Specified by:
removePlayer in interface SPGameInterface
Parameters:
pid - String - id of the player to be removed
Returns:
result - Boolean: TRUE, if successful, FALSE, if not.

setPlayerComms

public boolean setPlayerComms(java.lang.String playerID,
                              java.lang.String commsID,
                              boolean relayflag)
Description copied from interface: SPGameInterface
This method associates a specific player instance, specified by the playerID, with a specific communications service, specified by the commsID. For certain remote players, a relay service is supported to allow messages to be forwarded. NOTE: there is a reserved comms service "internal" for player instances that are included in the local application session.

Specified by:
setPlayerComms in interface SPGameInterface
Parameters:
playerID - String - id of the player to be added
commsID - String - id of the comms object to be added
relayflag - Boolean - relay flag
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

getGamePlayer

public SPPlayerInterface getGamePlayer(java.lang.String playerID)
Description copied from interface: SPGameInterface
This method returns the player object specified by the playerID.

Specified by:
getGamePlayer in interface SPGameInterface
Parameters:
playerID - String - the id of the player to get
Returns:
player - SPPlayerInterface(but actually is SPPlayerClass) - the game player object handler or an empty instance of the class, if the player is not present

prUpdateGameStatus

public void prUpdateGameStatus()
This method does a self-check on the game instance object and updates its status appropriately. Mainly, it is used to lock the game when changes are occuring or if an error has occured.


gameComplete

public boolean gameComplete()
Description copied from interface: SPGameInterface
This method allows external entities to review the status of the game instance without directly accessing its internals.

Specified by:
gameComplete in interface SPGameInterface
Returns:
result - Boolean: TRUE, if gamestatus is "complete", FALSE, if not

addComms

public boolean addComms(java.lang.String commsID)
Description copied from interface: SPGameInterface
This method associates a comms service specified by the commsID string to a game instance.

Specified by:
addComms in interface SPGameInterface
Parameters:
commsID - String - id of the comms to be added
Returns:
result - Boolean: TRUE, if gamestatus is "complete", FALSE, if not

removeComms

public boolean removeComms(java.lang.String commsID)
Description copied from interface: SPGameInterface
This method removes the association of a communications service with a game instance.

Specified by:
removeComms in interface SPGameInterface
Parameters:
commsID - String - id of the comms to be removed
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

addTransaction

public boolean addTransaction(SPAbstractTransactionInterface transObj)
Description copied from interface: SPGameInterface
This safely adds a transaction to a game instance and appropriately updates the game state.

Specified by:
addTransaction in interface SPGameInterface
Parameters:
transObj - SPAbstractTransactionInterface - the transaction Object handler
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

closeTransaction

public boolean closeTransaction(java.lang.String transID)
Description copied from interface: SPGameInterface
Safely removes a transaction from a game instance.

Specified by:
closeTransaction in interface SPGameInterface
Parameters:
transID - String - the id of the transaction to be closed
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

getGameTransaction

public SPAbstractTransactionInterface getGameTransaction(java.lang.String tid)
Description copied from interface: SPGameInterface
This method returns a specific transaction associated with a given game instance.

Specified by:
getGameTransaction in interface SPGameInterface
Parameters:
tid - String - identifier for transaction object
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

prsetTransactionID

public java.lang.String prsetTransactionID(SPAbstractTransactionInterface transObj)
This method generates a transactionID for a transaction object

Parameters:
transObj - SPAbstractTransactionInterface - the transaction object from which the id is retrieved
Returns:
transactionID - String - the transaction id

transactionincluded

public boolean transactionincluded(java.lang.String tid)
Description copied from interface: SPGameInterface
This method checks the specified transaction ID against the currently included transaction IDs in the game instance.

Specified by:
transactionincluded in interface SPGameInterface
Parameters:
tid - String - the id of the transaction in question
Returns:
result Boolean: TRUE, if included, FALSE, if not

onbeginGame

public boolean onbeginGame(SPMessageClass messObj)
This method handles requests to begin the local game. It ensures that the game is ready to be played, and, if so, updates the local game state appropriately.

Parameters:
messObj - SPMessageClass - incoming Message Object
Returns:
result - Boolean: TRUE, if successful, FALSE, if not.

onendGame

public boolean onendGame(SPMessageClass messObj)
Description copied from interface: SPGameInterface
This method safely ends the local game instance.

Specified by:
onendGame in interface SPGameInterface
Parameters:
messObj - SPMessageClass - incoming Message Object * @return result - Boolean: TRUE, if successful, FALSE, if not

onrequestbeginGame

public void onrequestbeginGame(SPMessageClass messObj)
This method handles incoming requests to begin a game It passes the requests on to the API rules parser.

Parameters:
messObj - SPMessageClass - incoming Message Object

onrequestendGame

public void onrequestendGame(SPMessageClass messObj)
This method passes a request to end a game on to the game master's rule parser.

Parameters:
messObj - SPMessageClass - incoming Message Object

updateGameSegment

public boolean updateGameSegment(java.lang.String currentseg,
                                 java.lang.String nextseg)
This method supports the administration of game segment IDs and counters. It is part of the SecurePlay licensing system. No deletion, modification, or circumvention is allowed without explicit permission as detailed in the SecurePlay license.

Parameters:
currentseg - String - current segment
nextseg - String - next segment
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

incrementBasicGameTransactionCount

public boolean incrementBasicGameTransactionCount(int count)
Description copied from interface: SPGameInterface
This method increments the game’s transaction counter to support certain licensing models

Specified by:
incrementBasicGameTransactionCount in interface SPGameInterface
Parameters:
count - int - number of increments
Returns:
Boolean TRUE, if successful, FALSE, if not

onnextGameSegmentID

public boolean onnextGameSegmentID(SPMessageClass messObj)
This method supports the SecurePlay licensing system to maintain synchronization of game segment IDs within a game. Deletion, modification, or circumvention of this software functionality is in violation of the SecurePlay license.

Parameters:
messObj - SPMessageClass - incoming Message Object
Returns:
result Boolean: TRUE, if successful, FALSE, if not

onIncomingTransaction

public void onIncomingTransaction(SPMessageClass messObj)
Description copied from interface: SPGameInterface
This method is the generic handler for incoming Game transaction methods.

Specified by:
onIncomingTransaction in interface SPGameInterface
Parameters:
messObj - SPMessageClass - incoming Message Object

isPlayerInternal

public boolean isPlayerInternal(java.lang.String pid)
Description copied from interface: SPGameInterface
Checks to see if the player is internal

Specified by:
isPlayerInternal in interface SPGameInterface
Parameters:
pid - String - id of the player to be checked
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

logError

public void logError()
This method is a placeholder for future internal logging


sendMessage

public boolean sendMessage(java.lang.String sender,
                           java.lang.String[] receivers,
                           boolean encryptflag,
                           boolean privateflag,
                           java.lang.String messagetype,
                           java.lang.String[] messagebody,
                           java.lang.String[] altmessage)
This method actually constructs messages to be sent by the Game object to other game object instances via the Comms Manager

Parameters:
sender - - id of the sender
receivers - - ids of the recievers of the message
encryptflag - - encryption flag
privateflag - - private flag
messagetype - - the type of message
messagebody - - the message body
altmessage - - alternative message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

getCommsManager

public SPCommsManagerClass getCommsManager()
Description copied from interface: SPGameInterface
Gets the comms manager object

Specified by:
getCommsManager in interface SPGameInterface
Returns:
comms - SPCommsManagerClass - the comms manager object

getSecurePlay

public SecurePlayClass getSecurePlay()
Description copied from interface: SPGameInterface
This method returns the unique SecurePlay library object associated with the game instance object.

Specified by:
getSecurePlay in interface SPGameInterface
Returns:
spc - SecurePlayLibrary - the secure play library

getGamestatus

public java.lang.String getGamestatus()
Getter function that returns the property: gamestatus

Returns:
gamestatus - String

getOpentransactionIDList

public java.lang.String[] getOpentransactionIDList()
Getter function that returns the open transaction IDs

Returns:
opentransactionIDList - String

getTransactions

public SPAbstractTransactionInterface[] getTransactions()
Getter function that returns the transactions from propentransactionlist

Returns:
prplayerList - SPHashtable

getBasicGameTransactionCount

public int getBasicGameTransactionCount()
Getter function that returns the property: prBasicGameTransactionCount

Returns:
prBasicGameTransactionCount - int

getCurrentGameSegment

public java.lang.String getCurrentGameSegment()
Getter function that returns the property: prcurrentGameSegment

Returns:
prcurrentGameSegment - String

getGameSegmentCount

public int getGameSegmentCount()
Getter function that returns the property: prgamesegmentcount

Returns:
prgamesegmentcount - int

getNextGameSegment

public java.lang.String getNextGameSegment()
Getter function that returns the property: prnextGameSegment

Returns:
prnextGameSegment - String

getPlayers

public SPPlayerInterface[] getPlayers()
Getter function that returns the players from prplayerlist

Returns:
prplayerList - SPHashtable

getPreloadGameSegment

public int getPreloadGameSegment()
Getter function that returns the property: prpreloadGameSegment

Returns:
prpreloadGameSegment - int

getSecurityManager

public SPSecurityManagerInterface getSecurityManager()
Description copied from interface: SPGameInterface
This method returns the security manager class associated with this game.

Specified by:
getSecurityManager in interface SPGameInterface
Returns:
SPSecurityManagerInterface

getHashText

public byte[] getHashText(java.lang.String plainText,
                          java.lang.String algorithm)
This method gets the hashed string

Parameters:
plainText - String - string to be hashed
algorithm - String - The algorithm to use like MD2, MD5, SHA-1, etc.
Returns:
hash - String - the hashed string

SPcreateBHash

public byte[] SPcreateBHash(java.lang.String input,
                            java.lang.String gameid)
This is a wrapper function for creating a hash of a string. This reference implementation includes a MD5 hash.

Specified by:
SPcreateBHash in interface SPGameInterface
Parameters:
input - String
Returns:
str - String - Hash of input

SPcreateBSignature

public byte[] SPcreateBSignature(java.lang.String senderID,
                                 byte[] input,
                                 java.lang.String gameid)
This is a wrapper function for creating a digital signature based on an existing hashed string and a Sender ID. The reference implementation currently uses an MD5 function to approximate performance of a real signature. The included signature function is a sample function - REPLACE with a function that meets your specific security requirements.

Specified by:
SPcreateBSignature in interface SPGameInterface
Parameters:
senderID - String
input - String
gameid - String
Returns:
realSig - byte[] - digital signature of hashstring signed by senderID.

SPcreateHash

public java.lang.String SPcreateHash(java.lang.String input,
                                     java.lang.String gameid)
This is a wrapper function for creating a hash of a string. This reference implementation includes a MD5 hash.

Specified by:
SPcreateHash in interface SPGameInterface
Parameters:
input - String
Returns:
str - String - Hash of input

SPcreateSignature

public java.lang.String SPcreateSignature(java.lang.String senderID,
                                          java.lang.String input,
                                          java.lang.String gameid)
This is a wrapper function for creating a digital signature based on an existing hashed string and a Sender ID. The reference implementation currently uses an MD5 function to approximate performance of a real signature. The included signature function is a sample function - REPLACE with a function that meets your specific security requirements.

Specified by:
SPcreateSignature in interface SPGameInterface
Parameters:
senderID - String
input - String
gameid - String
Returns:
str - String - digital signature of hashstring signed by senderID.

SPdecrypt

public java.lang.String[] SPdecrypt(java.lang.String[] input,
                                    java.lang.String senderID,
                                    java.lang.String[] recvrs,
                                    java.lang.String gameID,
                                    java.lang.String messageID)
This is a placeholder for an decryption function. An actual encryption function is the responsibility of the game implementer.

Specified by:
SPdecrypt in interface SPGameInterface
Parameters:
input - String[] - input message body to be decrypted
senderID - String - sender id
recvrs - String[] - receiver id list
gameID - String - game id
messageID - String - message id
Returns:
mess - String[] - String array of decrypted messagebody.

SPencrypt

public java.lang.String[] SPencrypt(java.lang.String[] input,
                                    java.lang.String senderID,
                                    java.lang.String[] recvrs,
                                    java.lang.String gameID,
                                    java.lang.String messageID)
This is a placeholder for an encryption function. An actual encryption function is the responsibility of the game implementer.

Specified by:
SPencrypt in interface SPGameInterface
Parameters:
input - String[] - message body to be encrypted
senderID - String - sender id
recvrs - String[] - receiver id list
gameID - String - game id
messageID - String - message id
Returns:
mess - String[] - Encrypted message body

SPtransform

public java.lang.String SPtransform(java.lang.String input,
                                    java.lang.String gameid)
This function performs an irreversible transform on an input string to generate an output string. The sample implementation uses MD5. This method can be overridden and should be reviewed for security purposes prior to use in a production implementation.

Parameters:
input - String
Returns:
str - String

SPverifySignature

public boolean SPverifySignature(byte[] sigToVerify,
                                 java.lang.String senderID,
                                 byte[] testhash,
                                 java.lang.String gameid)
This is a wrapper for a digital signature verification function. CAREFUL CHOICE OF ACTUAL DIGITAL SIGNATURES AND VERIFICATION IS CRITICAL. SELECTION OF APPROPRIATE FUNCTIONS AND IMPLEMENTATION MAY HAVE A SUBSTANTIAL IMPACT ON THE SECURITY AND PERFORMANCE OF A GAME IMPLEMENTATION.

Specified by:
SPverifySignature in interface SPGameInterface
Parameters:
sigToVerify - byte[]
senderID - String
testhash - String
Returns:
true - Boolean - TRUE, if verification Successful, FALSE, if not.

SPverifySignature

public boolean SPverifySignature(java.lang.String signature,
                                 java.lang.String senderID,
                                 java.lang.String testhash,
                                 java.lang.String gameid)
This is a wrapper for a digital signature verification function. CAREFUL CHOICE OF ACTUAL DIGITAL SIGNATURES AND VERIFICATION IS CRITICAL. SELECTION OF APPROPRIATE FUNCTIONS AND IMPLEMENTATION MAY HAVE A SUBSTANTIAL IMPACT ON THE SECURITY AND PERFORMANCE OF A GAME IMPLEMENTATION.

Specified by:
SPverifySignature in interface SPGameInterface
Parameters:
signature - String
senderID - String
testhash - String
Returns:
true - Boolean - TRUE, if verification Successful, FALSE, if not.