Compare commits

...

29 commits
v1.0.1 ... main

Author SHA1 Message Date
a13b6f46a0
Flip over red cards inatead of black 2022-05-03 10:57:27 -05:00
abd3e2edc1
Use correct backend URL 2022-04-11 22:22:46 -05:00
a207d8e08b
Use ports 4206 and 4207 2022-04-10 10:58:44 -05:00
6c749a2216
Host game on ports 1950 and 1951 2022-01-16 16:53:23 -06:00
4664d47aa9
Front page: add license info and link to source code 2022-01-14 11:17:50 -06:00
1b0984f6d2
Complete bash path in run script 2022-01-13 18:56:32 -06:00
d6d9f30562
Make frontend port and env var in run script too 2022-01-13 18:55:31 -06:00
a39796fc55
Clean up run script 2022-01-13 18:51:45 -06:00
e6325cf482
Reformat README 2022-01-13 18:11:36 -06:00
f7e60d17d1
Remove env variable file 2022-01-13 12:25:59 -06:00
de461a3da4
Clean up README instructions 2022-01-13 12:21:27 -06:00
aad9977d79
Merge scripts into a single run script 2022-01-13 12:21:20 -06:00
547a46697a
Simplify socket.io server configuration 2022-01-13 12:21:07 -06:00
26203d9f54
Simplify env file 2022-01-12 14:48:58 -06:00
ab5dd5c12a
Set socket.io port correctly 2022-01-12 14:48:47 -06:00
35726b7052
Rebuild node src 2022-01-12 14:48:34 -06:00
f4d4d16b87
Move SSL to proxy so we don't need sudo for backend 2022-01-12 14:36:59 -06:00
63b522b6d2
Update npm packages 2022-01-12 14:34:28 -06:00
e1378944ff
Update description in README 2022-01-12 14:33:52 -06:00
e8e34b9c62
Rename project to McCarthyism 2022-01-12 14:32:57 -06:00
acb7a8d34a
Update port 2021-07-15 20:59:58 -05:00
8e8dfc3cd6
Fix typo 2021-06-05 20:22:44 -05:00
46eb51e2b5
Update index.tsx 2021-05-22 19:50:38 +00:00
ae28d7be9c
Update index.tsx 2021-05-22 19:48:58 +00:00
6f274a5e8a
Fix big typo!! 2021-05-09 17:43:11 -05:00
bf5f9d86b9
Fix bug in dealt hands 2021-05-09 17:27:29 -05:00
bc42a5bfa4
Fix typo 2021-05-09 17:27:19 -05:00
10a0dc348e
Update rules 2021-05-09 17:24:11 -05:00
9580139a78
Make sure everyone has a black and red card 2021-05-09 17:23:37 -05:00
16 changed files with 2303 additions and 5339 deletions

View file

@ -1,11 +1,13 @@
# BSX
The card game BS, but better!
# McCarthyism
A subversive card game.
## Getting started
`git clone` this repository, then run `npm install` in `front` and `back`. You may have to run it multiple times for it to pull in all dependencies.
Clone this repository, then run `npm install` in `front` and `back`.
## Developing
You can use `NEXT_PUBLIC_BACK_HOST=localhost:4000 npm run dev` to run the frontend and `PORT=4000 node dist/index.js` to run the backend after building it with `npm run build`. You could also just run `NEXT_PUBLIC_BACK_HOST='https://server.exozy.me' npm run dev` if you are only developing the frontend and connect to the public backend server.
You can use `npm run build` to build the frontend and backend. Use `NEXT_PUBLIC_BACK_HOST=localhost:4000 npm run dev` to run the frontend and `PORT=4000 node dist/index.js` to run the backend.
You could also run `NEXT_PUBLIC_BACK_HOST='https://server.exozy.me' npm run dev` if you are only developing the frontend and connecting to the public backend server.
## Production deployment
Edit the environmental variables in `./env` and use the script `./run`.
Edit and run the script `./run`.

1230
back/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
{
"name": "bsx-back",
"name": "mccarthyism-back",
"version": "1.0.0",
"description": "",
"main": "index.js",
@ -13,7 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"bsx-core": "file:../core",
"mccarthyism-core": "file:../core",
"dotenv": "^8.2.0",
"socket.io": "^3.1.1"
},

View file

@ -1,4 +1,4 @@
import {Card, Suit} from 'bsx-core';
import {Card, Suit} from 'mccarthyism-core';
import Client from './Client';
import logSocket from './logSocket';
@ -55,16 +55,32 @@ export default class Game {
for (let i = 1; i <= 13; ++i)
for (let j = 0; j < 4; ++j)
cards.push({rank: i, suit: j});
// Shuffle cards
for (let i = 0; i < 52; ++i) {
const handSize = 5 - Math.floor(this.room.clients.length/7);
// Shuffle red cards
for (let i = 0; i < 26; ++i) {
const j = Math.floor(Math.random() * (i+1));
[cards[i], cards[j]] = [cards[j], cards[i]];
}
const handSize = 5 - Math.floor(this.room.clients.length/7);
// Shuffle black cards
for (let i = 0; i < 26; ++i) {
const j = Math.floor(Math.random() * (i+1));
[cards[i+26], cards[j+26]] = [cards[j+26], cards[i+26]];
}
for (let i = 0; i < this.room.clients.length; ++i) {
this.players.push(new Player(this, this.room.clients[i]));
this.players[i].cards = cards.slice(i * handSize, (i + 1) * handSize);
this.players[i].cards.push(cards[i], cards[i+26]); // Make sure everyone has a red and black card
}
const remainingCards = [];
for (let i = this.room.clients.length; i < 26; ++i)
remainingCards.push(cards[i], cards[i+26]);
// Shuffle remaining cards
for (let i = 0; i < remainingCards.length; ++i) {
const j = Math.floor(Math.random() * (i+1));
[remainingCards[i], remainingCards[j]] = [remainingCards[j], remainingCards[i]];
}
for (let i = 0; i < this.room.clients.length; ++i)
for (let j = 0; j < handSize-2; ++j)
this.players[i].cards.push(remainingCards[i*(handSize-2)+j]);
const startingPlayer = this.players[0]; // Pick a random starting player instead??
this.playerTurn = this.players.indexOf(startingPlayer);
this.playersFinished = this.room.clients.length;
@ -179,8 +195,8 @@ export default class Game {
delete p.disconnectListener;
(() => {
if (this.players[selectedPlayer].stack.length > 0) {
if (this.players[selectedPlayer].stack[0].suit === Suit.Diamonds ||
this.players[selectedPlayer].stack[0].suit === Suit.Hearts) this.phase = 3; // Red card
if (this.players[selectedPlayer].stack[0].suit === Suit.Spades ||
this.players[selectedPlayer].stack[0].suit === Suit.Clubs) this.phase = 3; // Red card
this.players[selectedPlayer].flipped.push(this.players[selectedPlayer].stack[0]);
this.players[selectedPlayer].stack.splice(0, 1);
return;

View file

@ -3,15 +3,4 @@ import http from 'http';
import https from 'https';
import {Server} from 'socket.io';
// export default new Server({cors: {origin: process.env.ORIGIN, methods: ['GET', 'POST']}});
const base = process.env.SSL_KEY && process.env.SSL_CERT && process.env.SSL_CA ? https.createServer({
"key": fs.readFileSync(process.env.SSL_KEY),
"cert": fs.readFileSync(process.env.SSL_CERT),
"ca": fs.readFileSync(process.env.SSL_CA)
}) : http.createServer();
base.listen(+process.env.PORT!, '0.0.0.0', () => {
console.log(`Listening on port ${process.env.PORT}`);
});
export default new Server(base, {cors: {origin: process.env.ORIGIN, methods: ['GET', 'POST']}});
export default new Server(Number(process.env.PORT!), {cors: {origin: '*', methods: ['GET', 'POST']}});

6
build
View file

@ -1,6 +0,0 @@
#!/bin/bash
source ./env
cd front
npm run build
cd ../back
npm run build

16
core/package-lock.json generated
View file

@ -1,11 +1,11 @@
{
"name": "bsx-core",
"name": "mccarthyism-core",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "bsx-core",
"name": "mccarthyism-core",
"version": "1.0.0",
"license": "ISC",
"devDependencies": {
@ -13,9 +13,9 @@
}
},
"node_modules/typescript": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.5.tgz",
"integrity": "sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==",
"version": "4.5.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz",
"integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
@ -28,9 +28,9 @@
},
"dependencies": {
"typescript": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.5.tgz",
"integrity": "sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==",
"version": "4.5.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz",
"integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==",
"dev": true
}
}

View file

@ -1,5 +1,5 @@
{
"name": "bsx-core",
"name": "mccarthyism-core",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",

View file

@ -1,7 +1,7 @@
enum Suit {
Clubs,
Diamonds,
Hearts,
Clubs,
Spades
}

6
env
View file

@ -1,6 +0,0 @@
export NEXT_PUBLIC_BACK_HOST='https://server.exozy.me'
export ORIGIN="*"
export PORT=4000
export SSL_KEY=/etc/letsencrypt/live/exozy.me/privkey.pem
export SSL_CERT=/etc/letsencrypt/live/exozy.me/cert.pem
export SSL_CA=/etc/letsencrypt/live/exozy.me/chain.pem

5
front/next-env.d.ts vendored
View file

@ -1,2 +1,5 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

6230
front/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
{
"name": "bsx-front",
"name": "mccarthyism-front",
"version": "0.1.0",
"private": true,
"scripts": {
@ -10,8 +10,8 @@
"preinstall": "cd ../core && npm i && npm run build"
},
"dependencies": {
"bsx-core": "file:../core",
"next": "10.0.6",
"mccarthyism-core": "file:../core",
"next": "^12.0.8",
"react": "17.0.1",
"react-dom": "17.0.1",
"socket.io-client": "^3.1.1"

View file

@ -1,4 +1,4 @@
import {Card, Suit} from 'bsx-core';
import {Card, Suit} from 'mccarthyism-core';
import {useEffect, useState} from 'react';
import io from 'socket.io-client';
@ -16,17 +16,17 @@ interface GameState {
}
const rankStrs = ['', 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
const suitChars = ['♣', '♦', '♥', '♠'];
const suitChars = ['♦', '♥', '♣', '♠'];
const rules = `There are only 5 simple rules!
1. You will first be dealt 5 cards.
1. Each player will first be dealt the same number of cards.
2. At the beginning of each round, you must rearrange the order of your cards and place them face down in a stack.
3. During the round, players go around in a circle, claiming increasingly greater numbers. If it is you turn to claim a number, you must either claim a larger number than the previously claimed number or call BS. If you call BS, the previous player must flip over their claimed number of black (clubs or spades) cards from the tops of everyone's stacks.
3. During the round, players go around in a circle, claiming increasingly greater numbers. If it is your turn to claim a number, you must either claim a larger number than the previously claimed number or call BS. If you call BS, the previous player must flip over their claimed number of red (heart or diamond) cards from the tops of everyone's stacks.
4. If the previous player manages to flip over their claimed number of black cards, you must choose a card from your stack to give up. Otherwise, the previous player must choose one of their cards to give up.
4. When you click flip, it flips over the top card from that person's stack. If the previous player flips over a black card or cannot flip over their claimed number of red cards, they must choose a card from their stack to give up. Otherwise, the person who called BS must choose one of their cards to give up.
5. If you give up all your cards, you lose! Last player remaining wins!
@ -87,7 +87,7 @@ export default function Game() {
return (
<>
<h2>
Welcome to BSX!
Welcome to McCarthyism!
</h2>
<div>
{rules}
@ -100,6 +100,7 @@ export default function Game() {
}}
username={username}
/>
This game is licensed under the AGPL. <a href="https://git.exozy.me/Ta180m/McCarthyism">Source code here!</a>
</>
);
}
@ -263,7 +264,7 @@ export default function Game() {
</li>
))}
</ul>
{`${gameState.playerTurn} has called BS! ${gameState.lastPlayedPlayer} must flip over ${gameState.lastPlayed} black cards!`}
{`${gameState.playerTurn} has called BS! ${gameState.lastPlayedPlayer} must flip over ${gameState.lastPlayed} red cards!`}
<div>
<p>Stacks:</p>
{gameState.players.map((player, i) => (

View file

@ -1,19 +1,30 @@
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"compilerOptions": {
"target": "esnext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}

20
run
View file

@ -1,5 +1,17 @@
#!/bin/bash
source ./env
./build
#!/usr/bin/bash
# Environment variable
export NEXT_PUBLIC_BACK_HOST='https://7.exozy.me'
export FRONT_PORT=4206
export PORT=4207
# Build
cd front
npm run start -- -p 5000 | sudo -E node ../back/dist/index.js # sudo hack to read SSL files
npm run build
cd ../back
npm run build
echo 'Build complete'
# Run
cd ../front
npm run start -- -p $FRONT_PORT | node ../back/dist/index.js