Cypherpoker Tutorial: Creating a Front End Development Start-Up Configuration

This article explains how to program Cypherpoker to automatically open two instances, setup a poker game, and have both players join the game. This configuration significantly speeds up the development process for front end developer. This tutorial was created by myself with the help of Patrick Bay.

This article expands on the first Cypherpoker tutorial about configuration settings.

First Step

First we will set the fast messaging protocol to auto start when the Cypherpoker clients starts up. From there we need to automate the opening of a second instance of Cypherpoker which will give us two players for our testing. From there we auto-populate the game settings and create the table. Lastly we set both players to automatically join the game. A small caution, wwe have to remember for some settings such as opening a new instance of Cypherpoker we only want the parent (our first instance) to open a window otherwise we will be stuck a loop as our new window would open a new window which would open a new window and so on.

When we are finished Cypherpoker will open upon execution and it will automatically start and join a for-fun game between two players allowing developers to debug changes significant faster than before.

Auto Enable Fast Messaging Protocol

Our first task is to setup an auto-enable configuration for the fast messaging protocol. We can find the initialization for the connectivity toggle switch in the class.

In settings.xml the node that refers to the switch is as follows:

<widget class=”” vpadding=”20">

<toggleswitch instance=”connectToggle”>

In the default settings of the settings.xml file we add our default setting node:


<! --Auto Enables Fast Messaging if true --> 

Then we attempt to call the default settings in the initialization function after adding an import for Global settings:

override public function initialize():void {

/// initial defualt setting isenabled to set fast msging to
/// auto run
try {
DebugView.addText(“Looking for Fast Messaging Auto-Start”);
var fastMessagingEnabled:Boolean = GlobalSettings.toBoolean(GlobalSettings.getSetting(“defaults”, “fastmessagingautostart”).enabled);
} catch (err:*) {
fastMessagingEnabled = false;
if (fastMessagingEnabled == true) {
DebugView.addText(“Fast Messaging Auto-Start is Enabled.”);
this.connectToggle.isSelected = true;

We simply check for a default setting for fastmessagingautostart and if there is we call the function that corresponds to a toggle switch click event.

We should be able to compile and test this change. Since we are using the default connectivity picker setting there is no need to change or reference it.

Auto Open 2nd Cypherpoker Instance

Our second change is to call on our client to open another Cypherpoker instance. Normally this requires 2 clicks worth of navigation to the window pane above the opening pane and then to the left where the players can normally change their screen-name and choose their player icon.

First we add our startup configuration setting to the settings.xml file:

<!-- Starts another window, will add support for multiple windows eventually -->

Next we add our code to the initialization function of the NewWindowWidget class (after adding the import global settings line):

override public function initialize():void {

/// look for user requested additional windown
/// instances
try {
DebugView.addText(“Check for user requested new window instances.”);
var openNewWindowIsEnabled:XML = GlobalSettings.getSetting(“defaults”, “opennewwindow”);
var openNewWindowIsEnabledBool:Boolean = Boolean(openNewWindowIsEnabled);
} catch (err:*) {
DebugView.addText(“No user requests detected for new windows.”);
if (openNewWindowIsEnabledBool == true) {
if (lounge.isChildInstance) {
//this is a new window
else {
DebugView.addText(“New window requested in default settings. Opening new window.”);

The code is nearly the same as the fastmessaginprotocol configuration expect for one important addition, namely we have to make sure the second instance doesn’t also created a new instance upon start-up otherwise we will create an infinite loop. So the client will check if it is a childInstance if (lounge.isChildInstance), do nothing if it is, and create a second instant if its not (i.e. its the parent or first instance we created).

We should be able to compile now and check this configuration setting (and we can comment out our if/else and check out an infinite loop of tables if we want for fun!).

Auto Create and New Table

Creating and Joining a new table takes two steps and the first step also involves populating the table settings.

Populating the Table Settings Fields

In the TableManagerWidget class under the initialize function heading and at the end of the body we will initialize the textinput box’s text fields with the following:

this.create_buyInAmount.text = “100”;
this.create_bigBlindAmount.text = “2”;
this.create_smallBlindAmount.text = “1”;

The (play money) buyin for each player will be 100 chips and the big blind and small blind will be set to 2 and 1 respectively.

Also in the same initialization function we will initialize the fun game option of the radio group by adding the last line the code below (somewhere after the first two lines):

this.create_contractGameRadio.toggleGroup = this._gameTypeRadioGroup;
this.create_funGameRadio.toggleGroup = this._gameTypeRadioGroup;
this.create_funGameRadio.toggleGroup = this._gameTypeRadioGroup;

this._gameTypeRadioGroup.selectedItem = this.create_funGameRadio;

Now if a game is auto-created it will automatically be a a for fun game for 100 chips with a 2 chip big blind and 1 chip small blind.

1 Player Creates a Game (Parent) and Both players Join

In order to make sure that there is a connection established before we try to create a game we will setup a listener for a Cliqueconnect event. In the same function as above we will add:

this.lounge.addEventListener(LoungeEvent.NEW_CLIQUE, this.onCliqueConnect);

When a NEW_CLIQUE event fires the ‘onCliqueConnect’ function starts a listener for a peer and once found goes into goes into the process checking if auto-create a new table is enabled.

First we have to add the setting to our defaults in settings.xml.

<! — auto creates a table when enabled →

Again we check if we are the parent as there is only need for one player to start a game:

if (lounge.isChildInstance) {
//this is a new window
else {
try {
DebugView.addText(“Checking for Auto Create Table”);
var createTableIsEnabled:XML = GlobalSettings.getSetting(“defaults”, “createtable”);
var createTableIsEnabledBool:Boolean = Boolean(createTableIsEnabled);
//var enabledchild:XML = openNewWindowIsEnabled.child(“enabled”)[0];
} catch (err:*) {
DebugView.addText(“No Auto Create Table Enabled”);
DebugView.addText(“create table is enabled: “ + createTableIsEnabledBool);
if (createTableIsEnabledBool == true) {
setTimeout(onCreateTableClick, 2000, null);

At the end of the onNewTableCreated function we can add the following which causes the player creating the table to join their own game and announce to the other player instance:

private function onNewTableCreated(eventObj:TableManagerEvent):void {

this._currentSelectedGameListItemData = tableInfoObj;

In the onNewTableRecieved function we add the following for the other player instance to automatically join once the table is created and announced:

this._currentSelectedGameListItemData = tableInfoObj;

Lastly we add the imports:

import flash.utils.setTimeout;

That’s It!

Now if we compile successfully we should see Cypherpoker execute, connect to the fast messaging protocol, open a new window (which also connects to the fast messaging protocol), have the parent instance create a new game with our given settings, and have both players join the game.

With one click (compile) we are now ready to player poker heads up versus ourselves or to test and debug any development changes!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.