Skip to content

Commit

Permalink
Fixes for outstanding v0.3.0 issues (#8 and #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
monicanagent committed Dec 2, 2018
1 parent 134eba5 commit 86d03b0
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 134 deletions.
63 changes: 27 additions & 36 deletions src/server/api/CP_SmartContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ async function CP_SmartContract (sessionObj) {
sendError(JSONRPC_ERRORS.ACTION_DISALLOWED, "Could not update account balance.", sessionObj);
return(false);
}
console.log ("New contract created: \""+newContract.contractID+"\"");
console.log (" Owner PID: \""+privateID+"\"");
console.log (" Owner Account: \""+playerAccount[0].address+"\"");
//console.log ("New contract created: \""+newContract.contractID+"\"");
//console.log (" Owner PID: \""+privateID+"\"");
//console.log (" Owner Account: \""+playerAccount[0].address+"\"");
break;
case "agree":
var contractOwnerPID = requestParams.ownerPID;
Expand Down Expand Up @@ -197,6 +197,7 @@ async function CP_SmartContract (sessionObj) {
sendError(JSONRPC_ERRORS.ACTION_DISALLOWED, "Could not update account balance.", sessionObj);
return(false);
}
//console.log ("Player has agreed to contract: "+privateID);
break;
case "store":
if (typeof(requestParams.type) != "string") {
Expand Down Expand Up @@ -362,7 +363,7 @@ async function CP_SmartContract (sessionObj) {
keychainsFound++;
}
if (keychainsFound == gameContract.players.length) {
console.log ("Contract "+contractID+" played to end. Analyzing...");
//console.log ("Contract "+contractID+" played to end. Analyzing...");
try {
var nonFoldedPlayers = new Array();
for (count = 0; count < gameContract.players.length; count++) {
Expand Down Expand Up @@ -390,16 +391,16 @@ async function CP_SmartContract (sessionObj) {
sendError(JSONRPC_ERRORS.PLAYER_ACTION_ERROR, "Contract validation failed.", sessionObj);
return (false);
}
console.log ("Contract "+contractID+" being scored...");
//console.log ("Contract "+contractID+" being scored...");
var scoreResult = await scoreHands(gameContract);
//Additional information can be gathered from:
// scoreResult.winningPlayers
// scoreResult.winningHands
console.log ("Contract "+contractID+" completed.");
//console.log ("Contract "+contractID+" completed.");
} else {
//all but player nonFoldedPlayers[0].privateID have folded
console.log ("Contract "+contractID+" played to end.");
console.log ("All but one player have folded: "+nonFoldedPlayers[0].privateID);
//console.log ("Contract "+contractID+" played to end.");
//console.log ("All but one player have folded: "+nonFoldedPlayers[0].privateID);
scoreResult = new Object();
scoreResult.winningPlayers = new Array();
scoreResult.winningPlayers.push(nonFoldedPlayers[0]);
Expand Down Expand Up @@ -918,16 +919,30 @@ async function scoreHands(contract) {
newWinningPlayers.push(player);
newWinningHands.push(winningHand);
} else if (currentScore == highestScore) {
//both private card values are the same -- split pot
newWinningPlayers.push(player);
newWinningHands.push(winningHand);
//both private card values are the same -- possible split pot
var playerExists = false;
for (count2 = 0; count2 < newWinningPlayers.length; count2++) {
if (newWinningPlayers[count2].privateID == player.privateID) {
playerExists = true;
break;
}
}
//only add player once (since some hands generate multiple similar results)
if (playerExists == false) {
newWinningPlayers.push(player);
newWinningHands.push(winningHand);
}
}
}
winningPlayers = newWinningPlayers;
winningHands = newWinningHands;
}
cardsObj.winningPlayers = winningPlayers;
cardsObj.winningHands = winningHands;
//console.log ("Winning players:");
//console.dir (winningPlayers);
//console.log ("Winning Hands:");
//console.dir (winningHands);
return (cardsObj);
}

Expand Down Expand Up @@ -1262,7 +1277,7 @@ async function applyPenalty (contract, playerPIDs, penaltyType) {
penalizedPIDs.push(player.privateID);
}
}
console.log ("Player \""+penalizedPIDs+"\" has timed out contract: "+contract.contractID);
//console.log ("Player \""+penalizedPIDs+"\" has timed out contract: "+contract.contractID);
var distributionPIDs = new Array();
for (count = 0; count < contract.players.length; count++) {
var currentPlayer = contract.players[count];
Expand Down Expand Up @@ -1902,30 +1917,6 @@ function updatePlayersTimeout(privateID, sourcePID, contract, action, storeActio
//nextBettingPlayer is betting next
}
}
/*
//check for missing encryption actions
if (storeAction == "encrypt") {
//deck creation (multi-party encryption)
var numActions = 1;
for (count = 0; count < storeArray.length; count++) {
var currentStoreItem = storeArray[count];
if (currentStoreItem.type == "select") {
//restart action count
numActions = 1;
} else {
numActions++;
}
}
if (numActions == (contract.players.length + 2)) {
//action includes extra storage for plaintext and fully-encrypted decks (hence +2)
for (count = 0; count < contract.players.length; count++) {
var player = contract.players[count];
//deck is now created, everyone is reset to same timeout for selection
player.updated = now;
}
}
}
*/
} else if (action == "keychain") {
getPlayer(contract, privateID).updated = now;
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
"CP": {
"API": {
"database":{
"enabled":true,
"url":"https://127.0.0.1/rdb.php",
"enabled":false,
"url":"http://localhost/rdb.php",
"host":"localhost",
"accessKey":"PRIVATE DATABASE ACCESS KEY"
"accessKey":"DATABASE_ACCESS_KEY"
},
"wallets":{
"bitcoin":{
"xprv":"xprv...",
"startChain":0,
"startIndex":2
"startIndex":1
},
"test3":{
"tprv":"tprv...",
"startChain":0,
"startIndex":2
"startIndex":1
}
},
"tokens": {
"blockcypher":"PRIVATE BLOCKCYPHER TOKEN"
"blockcypher":"BLOCKCYPHER_TOKEN"
},
"bitcoin":{
"networks":{
Expand All @@ -32,11 +32,11 @@
"updateLimitSeconds": 120,
"baseDenom": "satoshi",
"main":{
"cashOutAddrPath":"m/0/1",
"cashOutAddrPath":"m/0/0",
"minerFee": "50000"
},
"test3":{
"cashOutAddrPath":"m/0/1",
"cashOutAddrPath":"m/0/0",
"minerFee": "50000"
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CP_server",
"version": "0.2.0",
"version": "0.2.3",
"description": "A CypherPoker.JS JSON-RPC 2.0 WebSocket Sessions server.",
"engines": {
"node": ">=8.0.0"
Expand Down
8 changes: 4 additions & 4 deletions src/server/utils/rdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

//External API access key:
$_accessKey = "PRIVATE ACCESS KEY";
$_accessKey = "DATABASE_ACCESS_KEY";

//Database settings:
$_dbhost = "localhost"; //the MySQL database host URL
$_dbname = "db_name"; //the MySQL database name
$_dbuser = "db_user"; //the authorized database user account
$_dbpw = "db_password"; //password for $_dbuser
$_dbname = "database_name"; //the MySQL database name
$_dbuser = "database_user"; //the authorized database user account
$_dbpw = "database_password"; //password for $_dbuser
$db = NULL; //active database connection

/**
Expand Down
2 changes: 1 addition & 1 deletion src/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Main / default dialog element controlled by the CypherPokerUI instance.
-->
<dialog id="mainDialog" class="dialog" open="true">
<p>Connecting to peer-to-peer network...</p>
<p>Loading game components...</p>
</dialog>

<!--
Expand Down
40 changes: 20 additions & 20 deletions src/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CypherPoker.JS_client",
"version": "0.2.0",
"version": "0.2.3",
"description": "CypherPoker.JS client API interface.",
"engines": {
"node": ">=8.0.0"
Expand All @@ -20,28 +20,28 @@
"start": "node_modules/.bin/http-server -c-1"
},
"keywords": [
"CypherPoker",
"poker",
"client",
"crypto",
"cryptosystem",
"SRA",
"game",
"p2p",
"peer-to-peer",
"websocket",
"session",
"sessions",
"wss",
"json-rpc",
"jsonrpc",
"2.0",
"http",
"ws"
"CypherPoker",
"poker",
"client",
"crypto",
"cryptosystem",
"SRA",
"game",
"p2p",
"peer-to-peer",
"websocket",
"session",
"sessions",
"wss",
"json-rpc",
"jsonrpc",
"2.0",
"http",
"ws"
],
"author": {
"name": "Patrick Bay (Monican Agent)",
"url" : "https://github.com/monicanagent"
"url": "https://github.com/monicanagent"
},
"license": "MIT",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/web/scripts/CypherPoker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* manages accounts and tables, launches games, and provides accesss to other shared
* functionality.
*
* @version 0.2.2
* @version 0.2.3
* @author Patrick Bay
* @copyright MIT License
*/
Expand Down Expand Up @@ -222,7 +222,7 @@ class CypherPoker extends EventDispatcher {
* @property {Object} p2p Reference to a peer-to-peer networking interface
* supporting the property <code>privateID</code> and functions <code>connect(serverURL)</code>,
* <code>broadcast(message)</code>, and <code>direct(message, [recipient,recipient...])</code>.
* For example, {@link WSS.js}
* For example, {@link WSS}
* @readonly
*/
get p2p() {
Expand Down
9 changes: 1 addition & 8 deletions src/web/scripts/CypherPokerAccount.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file Contains information and functionality associated with a single managed account.
*
* @version 0.2.0
* @version 0.2.3
* @author Patrick Bay
* @copyright MIT License
*/
Expand Down Expand Up @@ -91,13 +91,6 @@ class CypherPokerAccount extends EventDispatcher {
return (this._network);
}

get network() {
if (this._network == undefined) {
this._network = null;
}
return (this._network);
}

/**
* @property {BigInteger} balance="0" The current total account balance. Note that
* this is different than the {@link CypherPokerPlayer#balance} property
Expand Down

0 comments on commit 86d03b0

Please sign in to comment.