com.SecurePlay.SPTRandom
Class SPTRandomClass

java.lang.Object
  extended bycom.SecurePlay.SPRootTransactionClass
      extended bycom.SecurePlay.SPAbstractTransactionClass
          extended bycom.SecurePlay.SPTRandom.SPTRandomClass
All Implemented Interfaces:
SPAbstractTransactionInterface

public class SPTRandomClass
extends SPAbstractTransactionClass

This transaction class extends the SPAbstractTransaction class. It provides for the generation of fair random events over a network based on a Random. The APIconfigureTransaction method sets the 3 unique parameters - deckSize, repacement, and expirecount for the Random. The Random class can be used for a typical game with a shared Random and a dealer or for games without shared Randoms (in which case each Random is a separate instance of the class). Randoms can contain multiple "decks", but this is handled at the game rules level outside of the SecurePlay library

Author:
IT GlobalSecure
See Also:
SecurePlay License Information
 

Field Summary
 
Fields inherited from class com.SecurePlay.SPAbstractTransactionClass
classAPI, configuration, gameblock, gameinstance, transactionstatus, transtype
 
Fields inherited from class com.SecurePlay.SPRootTransactionClass
EventListenerList, gameID, master, playerIDList, transactionID
 
Constructor Summary
SPTRandomClass(SPGameInterface gameobj, java.lang.String master, java.lang.String[] playerIDList, boolean privateflag, java.lang.String transactionID)
          Overloaded Constructor
 
Method Summary
static boolean APIBcreateTransaction(SPGameAPIClass gapi, java.lang.String transmaster, java.lang.String[] playerIDList, boolean privateflag)
          This method allows the creation of a new Random type, internally controlled transaction.
 boolean APIbeginTransaction(java.lang.String pid)
          This action can only be initiated by the Transaction master.
 boolean APIcompleteTransaction(java.lang.String pid)
          This method overrides the SPAbstractTransactionClass method.
 boolean APIconfigureTransaction(java.lang.String sender, int decksize, boolean replacement, int expiration)
          This method handles the specific configuration required for a Random
 boolean APIconfigureTransaction(java.lang.String sender, java.lang.String[] args)
          This method overrides the APIconfigureTransaction included in the SPAbstractTransactionClass.
static SPTRandomClass APIcreateTransaction(SPGameAPIClass gapi, java.lang.String transmaster, java.lang.String[] playerIDList, boolean privateflag)
          This method allows the creation of a new Random type, internally controlled transaction.
 boolean APIgenerateRandomEvent(java.lang.String sender, java.lang.String[] receivers, boolean privacy, int count)
          This method handles either requests or local generation of random events by the Random master.
 java.lang.String[] APIgetlastRandomEvents()
          This method returns an array that includes the last set of random events provided by the Random master.
 int APIgetRandomEvent(int index)
          This method returns a random event from the dealtEventList property as specified by the index.
 boolean APIrequestbeginTransaction(java.lang.String pid)
          This method allows any transaction participant excluding the Transaction master to request that the transaction be begun.
 java.lang.String APISPawn(java.lang.String pid)
          This method creates a new transaction with the identical participants and configuration as the spawning transaction.
static SPTRandomAPIClass APITAOcreateTransaction(SPGameAPIClass gapi, java.lang.String transmaster, java.lang.String[] playerIDList, boolean privateflag)
          This method allows the creation of a new Random type, internally controlled transaction.
 SPUEctf APIverifyRandom()
          This method verifies a Random once the transaction has been completed.
protected  SPAbstractTransactionInterface buildSPawn()
          This method provides the unique transaction creation services for spawned Random transactions
 SPAbstractTransactionInterface createTransaction(SPGameAPIInterface gameapiobj, java.lang.String master, java.lang.String[] playerIDList, boolean privateflag, java.lang.String transactionID)
          This method creates a SPRandomClass transaction.
 java.lang.String[] getDealtEventList()
          Getter function that returns the property: dealtEventList
 int getLastcount()
          Getter function that returns the property: lastcount
 int getPrdeckSize()
          Getter function that returns the property: prdeckSize
 int getPrexpireeventcount()
          Getter function that returns the property: prexpireeventcount
 java.lang.Integer[] getPrkeyArray()
          Getter function that returns the property: prkeyArray
 int getPrkeySize()
          Getter function that returns the property: prkeySize
 SPMap getPrplayerKeyList()
          Getter function that returns the property: prplayerKeyList
 SPMap getPrplayerKeyTransformList()
          Getter function that returns the property: prplayerKeyTransformList
 java.lang.Integer[] getPrremainingValuesList()
          Getter function that returns the property: prremainingValuesList
static java.lang.String gettranstype()
          This method gets the transaction type.
 boolean isBuilt()
          Getter function that returns the property: built
 boolean isPrreplacement()
          Getter function that returns the property: prreplacement
 boolean oncompleteTransaction(SPMessageClass incoming)
          This method handles incoming "completeTransaction" messages.
 boolean oncompleteTransaction(java.lang.String sourceid, java.lang.String[] body)
          This method handles incoming "completeTransaction" messages.
 boolean onprepareRandom(SPMessageClass incoming)
          This method/event handles the initial response to the APIconfigureTransaction call by the Transaction Master.
 boolean onRandomEvents(SPMessageClass incoming)
          This method handles incoming random events from the Random master.
protected  void onrequestconfigureTransaction(SPMessageClass incoming)
          This method handles the unique processing associated with incoming requests to configure a Random Class.
 boolean onrequestRandomEvents(SPMessageClass incoming)
          This method handles incoming requests to generate Random events.
 boolean onsendPlayerKey(SPMessageClass incoming)
          This method handles incoming "sendPlayerKey" messages.
 boolean onsendPlayerKeyTransform(SPMessageClass incoming)
          This method handles incoming "sendPlayerKeyTransform" messages.
protected  boolean onSpawn(SPMessageClass incoming)
          This method handles incoming spawn messages.
 boolean prbuildRandom()
          This method provides the core configuration common to all Randoms.
 void prcreateRandomKey()
          This method actually builds the game key from the various player keys.
 boolean prgetRandomValue(java.lang.String playverifyflag)
          This method actually generates the random values.
 boolean pronincomingTransaction(SPMessageClass incoming)
          This method provides the unique handlers for incoming Secret turn message types
 void pruniqueinit()
          Unique initialization method
static boolean registerTransaction()
          Registers this transaction.
 boolean spawnConfigureRandom(SPTRandomClass a)
          This method provides the unique transaction configuration services for spawned Random transactions
 SPTRandomAPIClass SPgetAPI()
          Gets this class's API
 
Methods inherited from class com.SecurePlay.SPAbstractTransactionClass
APIgetGameBlock, APIrequestCompleteTransaction, APIrequestconfigureTransaction, APIsetGameBlock, getClassAPI, getConfiguration, getGameinstance, getLasterror, getPrivacyFlag, getTransactionstatus, getTransactionType, isPlayerInternal, isPrivateflag, logError, onbeginTransaction, onconfigureTransaction, onconfigureTransaction, onincomingTransaction, onrequestbeginTransaction, onrequestcompleteTransaction, sendMessage, setGameBlock, setTransactionID, spawnConfigure, transComplete, transError
 
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.SPAbstractTransactionInterface
getGameID, getMaster, getPlayerIDList, getTransactionID
 

Constructor Detail

SPTRandomClass

public SPTRandomClass(SPGameInterface gameobj,
                      java.lang.String master,
                      java.lang.String[] playerIDList,
                      boolean privateflag,
                      java.lang.String transactionID)
Overloaded Constructor

Parameters:
gameobj - SPGameInterface - the game object with which the transaction will be associated
master - String - the master of the transaction
playerIDList - String[] - the player id list
privateflag - boolean - private flag
transactionID - String - the transaction id
Method Detail

pruniqueinit

public void pruniqueinit()
Unique initialization method

Overrides:
pruniqueinit in class SPAbstractTransactionClass

APIconfigureTransaction

public boolean APIconfigureTransaction(java.lang.String sender,
                                       java.lang.String[] args)
This method overrides the APIconfigureTransaction included in the SPAbstractTransactionClass. It supports the configuration of the decksize,replacement, and Randomexpire parameters. NOTE, this method also triggers a series of onXXX handlers to completely configure the Random. it does not use or override the onconfigureTransaction portion of the AbstractTransactionClass, also, the handlers for this method are triggered by the local princomingTransaction handler.

Overrides:
APIconfigureTransaction in class SPAbstractTransactionClass
Parameters:
sender - String - the sender
args - String[] - the configuration array
Returns:
Boolean TRUE, if successful, FALSE, if not

APIconfigureTransaction

public boolean APIconfigureTransaction(java.lang.String sender,
                                       int decksize,
                                       boolean replacement,
                                       int expiration)
This method handles the specific configuration required for a Random

Parameters:
sender - String - player id of the sender
decksize - int - deck size of the Random transaction
replacement - boolean - flag for replacability of the deck of this Random transaction
expiration - int - number of transactions before stop.
Returns:
status - Boolean: TRUE, if successful, FALSE, if not

onprepareRandom

public boolean onprepareRandom(SPMessageClass incoming)
This method/event handles the initial response to the APIconfigureTransaction call by the Transaction Master. It verifies that the message was from the transaction master, loads the master player key transform, and triggers the configuration of the Random (prbuildRandom) method. It also initiates sending of all internal player key transforms to the other remote players.

Parameters:
incoming - SPMessageClass - incoming message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

onsendPlayerKeyTransform

public boolean onsendPlayerKeyTransform(SPMessageClass incoming)
This method handles incoming "sendPlayerKeyTransform" messages. This is the second stage of the Random configuration process. Once all of the player key transforms are received, all of the player keys are sent to the remote players, excluding the Random master/transaction master key.

Parameters:
incoming - SPMessageClass - incoming message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

onsendPlayerKey

public boolean onsendPlayerKey(SPMessageClass incoming)
This method handles incoming "sendPlayerKey" messages. It is the third stage in the configuration of the Random. Once all player keys are recieved, excluding the Random master's, the Random master will create the game key (prKeyArray) and the Random status will move to "ready";

Parameters:
incoming - SPMessageClass - incoming message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

prbuildRandom

public boolean prbuildRandom()
This method provides the core configuration common to all Randoms. It sets the deckSize, replacement, and expireevent counter.

Returns:
result - Boolean: TRUE, if successful, FALSE, if not

prcreateRandomKey

public void prcreateRandomKey()
This method actually builds the game key from the various player keys. It combines them by essentially doing "character by character" addition.


APIgenerateRandomEvent

public boolean APIgenerateRandomEvent(java.lang.String sender,
                                      java.lang.String[] receivers,
                                      boolean privacy,
                                      int count)
This method handles either requests or local generation of random events by the Random master. Either a request message will be sent to the Random master or the Random master will generate the number of random events specified by (count) and send them to the specified receivers. This value is protected based on the privacy flag.

Parameters:
sender - String - sender
receivers - String - player id list of the recievers
privacy - boolean - privacy policy
count - int - the number of random events to be generated
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

prgetRandomValue

public boolean prgetRandomValue(java.lang.String playverifyflag)
This method actually generates the random values. It generates a single random value based on the settings in the Random and stores and updates the Random properties appropriately.

Parameters:
playverifyflag - String
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

onrequestRandomEvents

public boolean onrequestRandomEvents(SPMessageClass incoming)
This method handles incoming requests to generate Random events. This message must be sent by a party not the Random master with a recipient of the Random master. It also includes the proposed parameters for the Random master to use. api.rulesgenerateRandomEvent is used to determine if this request is accepted.

Parameters:
incoming - SPMessageClass - incoming message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

onRandomEvents

public boolean onRandomEvents(SPMessageClass incoming)
This method handles incoming random events from the Random master. The new random events are appended to the dealtEventlist array.

Parameters:
incoming - SPMessageClass - incoming message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

APIgetRandomEvent

public int APIgetRandomEvent(int index)
This method returns a random event from the dealtEventList property as specified by the index.

Parameters:
index - int - the specifier of the random event
Returns:
rmevent - int - the corresponding dealtEventList entry to the index

APIgetlastRandomEvents

public java.lang.String[] APIgetlastRandomEvents()
This method returns an array that includes the last set of random events provided by the Random master.

Returns:
rmevents - String[] - the last batch of random events

APIcompleteTransaction

public boolean APIcompleteTransaction(java.lang.String pid)
This method overrides the SPAbstractTransactionClass method. It supports the distribution of the Random master player key to allow the Random to be subsequently verified.

Overrides:
APIcompleteTransaction in class SPAbstractTransactionClass
Parameters:
pid - String - ID of requesting Player
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

oncompleteTransaction

public boolean oncompleteTransaction(java.lang.String sourceid,
                                     java.lang.String[] body)
This method handles incoming "completeTransaction" messages. It overrides the default SPAbstractTransactionClass method. It also stores the incoming Random master player key.

Parameters:
sourceid - String - id of the sender.
body - String[] - the mody of the message.
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

APIverifyRandom

public SPUEctf APIverifyRandom()
This method verifies a Random once the transaction has been completed. There is a third state that is possible - where a Random was used for private events that did not include specific players. If those events are not exchanged elsewhere, a partial verification is all that is possible - that the Random is "consistent" with known data.

Returns:
result - Boolean: TRUE, if successful, FALSE, if not, "consistent" if consistent, but not completely verified

pronincomingTransaction

public boolean pronincomingTransaction(SPMessageClass incoming)
This method provides the unique handlers for incoming Secret turn message types

Overrides:
pronincomingTransaction in class SPAbstractTransactionClass
Parameters:
incoming - SPMessageClass - incoming message
Returns:
Boolean - TRUE, if handled internally, FALSE, if not

onrequestconfigureTransaction

protected void onrequestconfigureTransaction(SPMessageClass incoming)
This method handles the unique processing associated with incoming requests to configure a Random Class.

Overrides:
onrequestconfigureTransaction in class SPAbstractTransactionClass
Parameters:
incoming - SPMessageClass - incoming message

APISPawn

public java.lang.String APISPawn(java.lang.String pid)
This method creates a new transaction with the identical participants and configuration as the spawning transaction.

Overrides:
APISPawn in class SPAbstractTransactionClass
Parameters:
pid - String - player id must be master of the transaction
Returns:
tid - String - transaction id of the new spawned transaction.

buildSPawn

protected SPAbstractTransactionInterface buildSPawn()
This method provides the unique transaction creation services for spawned Random transactions

Overrides:
buildSPawn in class SPAbstractTransactionClass
Returns:
tran - SPAbstractTransactionInterface - spawned transaction

spawnConfigureRandom

public boolean spawnConfigureRandom(SPTRandomClass a)
This method provides the unique transaction configuration services for spawned Random transactions


onSpawn

protected boolean onSpawn(SPMessageClass incoming)
This method handles incoming spawn messages.

Overrides:
onSpawn in class SPAbstractTransactionClass
Parameters:
incoming - SPMessageClass - message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

APIbeginTransaction

public boolean APIbeginTransaction(java.lang.String pid)
This action can only be initiated by the Transaction master. It sends a "beginTransaction" message to all of the transaction participants. A Transaction can only be begun if it has been successfully configured.

Overrides:
APIbeginTransaction in class SPAbstractTransactionClass
Parameters:
pid - String - id of the transaction beginner, must be the master and internal.
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

APIrequestbeginTransaction

public boolean APIrequestbeginTransaction(java.lang.String pid)
This method allows any transaction participant excluding the Transaction master to request that the transaction be begun. This can only be done after the transaction has been configured.

Overrides:
APIrequestbeginTransaction in class SPAbstractTransactionClass
Parameters:
pid - String - the id of the requestor, can not be master, must be internal
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

SPgetAPI

public SPTRandomAPIClass SPgetAPI()
Gets this class's API

Returns:
classAPI - SPRandomAPIClass

oncompleteTransaction

public boolean oncompleteTransaction(SPMessageClass incoming)
This method handles incoming "completeTransaction" messages. It overrides the default SPAbstractTransactionClass method. It also stores the incoming Random master player key.

Parameters:
incoming - SPMessageClass - incoming message
Returns:
result - Boolean: TRUE, if successful, FALSE, if not

isBuilt

public boolean isBuilt()
Getter function that returns the property: built

Returns:
built - bolean

getDealtEventList

public java.lang.String[] getDealtEventList()
Getter function that returns the property: dealtEventList

Returns:
dealtEventList - String[]

getLastcount

public int getLastcount()
Getter function that returns the property: lastcount

Returns:
lastcount - int

getPrdeckSize

public int getPrdeckSize()
Getter function that returns the property: prdeckSize

Returns:
prdeckSize - int

getPrexpireeventcount

public int getPrexpireeventcount()
Getter function that returns the property: prexpireeventcount

Returns:
prexpireeventcount - int

getPrkeyArray

public java.lang.Integer[] getPrkeyArray()
Getter function that returns the property: prkeyArray

Returns:
prkeyArray - Integer[]

getPrkeySize

public int getPrkeySize()
Getter function that returns the property: prkeySize

Returns:
prkeySize - int

getPrplayerKeyList

public SPMap getPrplayerKeyList()
Getter function that returns the property: prplayerKeyList

Returns:
prplayerKeyList - SPHashtable

getPrplayerKeyTransformList

public SPMap getPrplayerKeyTransformList()
Getter function that returns the property: prplayerKeyTransformList

Returns:
prplayerKeyTransformList - SPHashtable

getPrremainingValuesList

public java.lang.Integer[] getPrremainingValuesList()
Getter function that returns the property: prremainingValuesList

Returns:
prremainingValuesList - Integer[]

isPrreplacement

public boolean isPrreplacement()
Getter function that returns the property: prreplacement

Returns:
prreplacement - boolean

APIcreateTransaction

public static SPTRandomClass APIcreateTransaction(SPGameAPIClass gapi,
                                                  java.lang.String transmaster,
                                                  java.lang.String[] playerIDList,
                                                  boolean privateflag)
This method allows the creation of a new Random type, internally controlled transaction. It also sends a message to the other transaction and game participants about this new transaction.

Parameters:
gapi - SPGameAPIInterface - the game that will be associated with this transaction.
transmaster - String - player id of the master of the transaction
playerIDList - String[] - This is an array that holds the Player IDs of the players within the game that are participating in this transaction.
privateflag - boolean - This is a flag to describe whether the specific transaction is a private transaction to the non-participating Players.
Returns:
tran - SPTRandomClass(but returns the actual object) - if successful, null if not

APIBcreateTransaction

public static boolean APIBcreateTransaction(SPGameAPIClass gapi,
                                            java.lang.String transmaster,
                                            java.lang.String[] playerIDList,
                                            boolean privateflag)
This method allows the creation of a new Random type, internally controlled transaction. It also sends a message to the other transaction and game participants about this new transaction.

Parameters:
gapi - SPGameAPIInterface - the game that will be associated with this transaction.
transmaster - String - player id of the master of the transaction
playerIDList - String[] - This is an array that holds the Player IDs of the players within the game that are participating in this transaction.
privateflag - boolean - This is a flag to describe whether the specific transaction is a private transaction to the non-participating Players.
Returns:
result - Boolean: TRUE, if successful, FALSE, if not.

APITAOcreateTransaction

public static SPTRandomAPIClass APITAOcreateTransaction(SPGameAPIClass gapi,
                                                        java.lang.String transmaster,
                                                        java.lang.String[] playerIDList,
                                                        boolean privateflag)
This method allows the creation of a new Random type, internally controlled transaction. It also sends a message to the other transaction and game participants about this new transaction.

Parameters:
gapi - SPGameAPIInterface - the game that will be associated with this transaction.
transmaster - String - player id of the master of the transaction
playerIDList - String[] - This is an array that holds the Player IDs of the players within the game that are participating in this transaction.
privateflag - boolean - This is a flag to describe whether the specific transaction is a private transaction to the non-participating Players.
Returns:
tran - SPRandomAPIClass - if successful, null if not

gettranstype

public static java.lang.String gettranstype()
This method gets the transaction type.

Returns:
String

registerTransaction

public static boolean registerTransaction()
Registers this transaction.

Returns:

createTransaction

public SPAbstractTransactionInterface createTransaction(SPGameAPIInterface gameapiobj,
                                                        java.lang.String master,
                                                        java.lang.String[] playerIDList,
                                                        boolean privateflag,
                                                        java.lang.String transactionID)
This method creates a SPRandomClass transaction.

Specified by:
createTransaction in interface SPAbstractTransactionInterface
Overrides:
createTransaction in class SPAbstractTransactionClass
Parameters:
gameapiobj - SPGameAPIInterface - the game that will be associated with this transaction.
master - String - player id of the master of the transaction
playerIDList - String[] - This is an array that holds the Player IDs of the players within the game that are participating in this transaction.
privateflag - boolean - This is a flag to describe whether the specific transaction is a private transaction to the non-participating Players.
transactionID - String - transaction id.