Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
First start the server:
./bin/server.sh
Then, start a client:
./bin/client.sh
Stretch goals
I was able to complete this amount of work by leveraging existing modules. Mocha, async, prompt and request all saved an immense amount of time.
Additionally, many of the modules were written previously by myself:
I'm happy with how it came out. The try/catch on the end-points enabled liberal use of "assert" and "have" worry-free since everything happens as a result of a REST call and there is no asynchronous code outside of the networking, due to no persistence (so domains were not needed).
There are things I would change, though:
All responses have:
If the request is a POST, then the request body is JSON.
The REST API commands follow.
Allows players to login to the game, where they can view tables and join a game.
Request Format
POST
/login
JSON Request Body
{ "playername": "Edmond" }
JSON Response
{
"success": true,
"cmd": "login",
"playerId": 1,
"tables": {
"1": {
"id": 1,
"players": { },
"numPlayers": 0,
"state": "waiting for players"
}
}
}
Allows players to see the tables and who is at each table.
Request Format
GET
/viewTables
JSON Response
{
"success": true,
"cmd": "viewTables",
"tables": {
"1": {
"id": 1,
"players": { },
"numPlayers": 0,
"state": "waiting for players"
}
}
}
Allows players to join a table and play the next hand dealt. Because a hand may be progress at the time, clients have to check back on an interval to get their hand. This means a keep-alive connection should be used, however at scale, this would not be ideal, as you'd want to keep the connections to a minimum to scale.
Request Format
POST
/joinTable
JSON Request Body
{ "playerid": 3 }
JSON Response
{
"success": true,
"cmd": "joinTable",
"table": {
"id": 1,
"players": {
"1": {
"name": "Edmond",
"bet": -1,
"hand": [ ],
"done": false,
"busted": false
}
},
"numPlayers": 1,
"state": "betting"
}
}
Allows the player to leave the table. If a hand is in play, the player will lose the bet to the house. The player returns to the lobby and then receices information describing all the tables.
Request Format
POST
/leaveTable
JSON Request Body
{ "playerid": 3 }
JSON Response
{
"success": true,
"cmd": "leaveTable",
"tables": {
"1": {
"id": 1,
"players": { },
"numPlayers": 0,
"state": "waiting for players"
}
}
}
Allows players to drop out of the game.
Request Format
POST
/logout
JSON Request Body
{ "playerId": 3 }
JSON Response
{ "success": true, "cmd": "logout", "credits": 1023 }
Indicates players are in on the next hand and the amount they are betting.
Request Format
POST
/bet
JSON Request Body
{ "playerId": 3, "bet": 10 }
JSON Response
{
"success": true,
"cmd": "bet",
"bet": 10,
"hand": [
{ "suit": "spades", "rank": "Queen", "value": 10 },
{ "suit": "spades", "rank": "2", "value": 2 }
],
"table": {
"id": 1,
"players": {
"1": {
"name": "Edmond",
"bet": 10,
"hand": [
{ "suit": "spades", "rank": "Queen", "value": 10 },
{ "suit": "spades", "rank": "2", "value": 2 }
],
"done": false,
"busted": false
}
},
"dealer": {
"name": "Dealer",
"hand": [
{ "suit": "hearts", "rank": "4", "value": 4 },
"face down card"
]
},
"numPlayers": 1,
"state": "dealing"
}
}
Informs the dealer to add another card to the player's hand. If the player exceeds 21, the player loses the hand.
Request Format
POST
/hit
JSON Request Body
{ "playerId": 3, hand: 3 }
JSON Reponse
{
"success": true,
"cmd": "hit",
"hand": [
{ "suit": "spades", "rank": "Queen", "value": 10 },
{ "suit": "spades", "rank": "2", "value": 2 },
{ "suit": "clubs", "rank": "2", "value": 2 }
],
"table": {
"id": 1,
"players": {
"1": {
"name": "Edmond",
"bet": 10,
"hand": [
{ "suit": "spades", "rank": "Queen", "value": 10 },
{ "suit": "spades", "rank": "2", "value": 2 },
{ "suit": "clubs", "rank": "2", "value": 2 }
],
"done": false,
"busted": false
}
},
"dealer": {
"name": "Dealer",
"hand": [
{ "suit": "hearts", "rank": "4", "value": 4 },
"face down card"
]
},
"numPlayers": 1,
"state": "dealing"
}
}
Informs the dealer, you want to stand on your hand, no more cards are to be dealt. Once all players are concluded, the dealer will handle their hand and the results are known.
Request Format
POST
/stand
JSON Request Body
{ "playerId": 3, "hand": 1 }
JSON Reponse:
{
"success": true,
"cmd": "stand",
"hand": [
],
"table": {
"id": 1,
"players": {
"1": {
"name": "Edmond",
"bet": -1,
"hand": [
],
"done": true,
"busted": false
}
},
"dealer": {
"name": "Dealer",
"hand": [ { "suit": "hearts", "rank": "4", "value": 4 },
{ "suit": "clubs", "rank": "4", "value": 4 },
{ "suit": "clubs", "rank": "Jack", "value": 10 }
]
},
"numPlayers": 1,
"state": "betting"
}
}
The player may increase the initial bet by up to 100% in exchange for committing to stand after receiving exactly one more card. The additional bet is placed in the betting box next to the original bet. Some games do not permit the player to increase the bet by amounts other than 100%. Non-controlling players may double their wager or decline to do so, but they are bound by the controlling player's decision to take only one card.
Signal: Place additional chips beside the original bet outside the betting box, and point with one finger.
Request Format
POST
/doubledown
JSON Request Body
{ "playerId": 3 }
JSON Reponse
Only available as first decision of a hand: Some games offer the option to "surrender", usually in hole-card games and directly after the dealer has checked for blackjack When the player surrenders, the house takes half the player's bet and returns the other half to the player; this terminates the player's interest in the hand. The request to surrender is made verbally, there being no standard hand signal.
Request Format
POST
/surrender
JSON Request Body
{ "playerId": 3 }
JSON Reponse
Only available as the first decision of a hand: If the first two cards have the same value, the player can split them into two hands, by moving a second bet equal to the first into an area outside the betting box. The dealer separates the two cards and draws an additional card on each, placing one bet with each hand. The player then plays out the two separate hands in turn, with some restrictions. Occasionally, in the case of ten-valued cards, some casinos allow splitting only when the cards have the identical ranks; for instance, a hand of 10-10 may be split, but not one of 10-king. However, usually all 10-value cards are treated the same. Doubling and further splitting of post-split hands may be restricted, and blackjacks after a split are counted as non-blackjack 21 when comparing against the dealer's hand. Hitting split aces is usually not allowed. Non-controlling players may follow the controlling player by putting down an additional bet or decline to do so, instead associating their existing wager with one of the two post-split hands. In that case they must choose which hand to play behind before the second cards are drawn. Some casinos do not give non-controlling players this option, and require that the wager of a player not electing to split remains with the first of the two post-split hands.
Signal: Place additional chips next to the original bet outside the betting box; point with two fingers spread into a V formation.
Request Format
POST
/split
Request Body
{ "playerId": 3 }
JSON Reponse
Allows developers to set the amount of credits a player has to any value.
Request Format
/debugCredits
Request Body
{ "playerId": 3, "credits": 999 }
Allows developers to get the player information. It uses a POST because I was too pressed for time to expand json-rest-api to handle query strings.
Request Format
/debugGetPlayer
Request Body
{ "playerId": 3 }
FAQs
A simple blackjack server with client.
The npm package blackjack receives a total of 2 weekly downloads. As such, blackjack popularity was classified as not popular.
We found that blackjack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.