Compare commits

..

No commits in common. "main" and "v1.1.1" have entirely different histories.
main ... v1.1.1

15 changed files with 5374 additions and 2322 deletions

View file

@ -1,13 +1,11 @@
# McCarthyism
A subversive card game.
# BSX
The card game BS, but better!
## Getting started
Clone this repository, then run `npm install` in `front` and `back`.
`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.
## Developing
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.
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.
## Production deployment
Edit and run the script `./run`.
Edit the environmental variables in `./env` and use 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": "mccarthyism-back",
"name": "bsx-back",
"version": "1.0.0",
"description": "",
"main": "index.js",
@ -13,7 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"mccarthyism-core": "file:../core",
"bsx-core": "file:../core",
"dotenv": "^8.2.0",
"socket.io": "^3.1.1"
},

View file

@ -1,4 +1,4 @@
import {Card, Suit} from 'mccarthyism-core';
import {Card, Suit} from 'bsx-core';
import Client from './Client';
import logSocket from './logSocket';
@ -195,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.Spades ||
this.players[selectedPlayer].stack[0].suit === Suit.Clubs) this.phase = 3; // Red card
if (this.players[selectedPlayer].stack[0].suit === Suit.Diamonds ||
this.players[selectedPlayer].stack[0].suit === Suit.Hearts) 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,4 +3,15 @@ import http from 'http';
import https from 'https';
import {Server} from 'socket.io';
export default new Server(Number(process.env.PORT!), {cors: {origin: '*', methods: ['GET', 'POST']}});
// 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']}});

6
build Executable file
View file

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

View file

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

6
env Normal file
View file

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

6314
front/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
{
"name": "mccarthyism-front",
"name": "bsx-front",
"version": "0.1.0",
"private": true,
"scripts": {
@ -10,8 +10,8 @@
"preinstall": "cd ../core && npm i && npm run build"
},
"dependencies": {
"mccarthyism-core": "file:../core",
"next": "^12.0.8",
"bsx-core": "file:../core",
"next": "10.0.6",
"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 'mccarthyism-core';
import {Card, Suit} from 'bsx-core';
import {useEffect, useState} from 'react';
import io from 'socket.io-client';
@ -24,9 +24,9 @@ const rules = `There are only 5 simple rules!
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 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.
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 black (clubs or spades) cards from the tops of everyone's stacks.
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.
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.
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 McCarthyism!
Welcome to BSX!
</h2>
<div>
{rules}
@ -100,7 +100,6 @@ 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>
</>
);
}
@ -264,7 +263,7 @@ export default function Game() {
</li>
))}
</ul>
{`${gameState.playerTurn} has called BS! ${gameState.lastPlayedPlayer} must flip over ${gameState.lastPlayed} red cards!`}
{`${gameState.playerTurn} has called BS! ${gameState.lastPlayedPlayer} must flip over ${gameState.lastPlayed} black cards!`}
<div>
<p>Stacks:</p>
{gameState.players.map((player, i) => (

View file

@ -1,30 +1,19 @@
{
"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"
]
"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"]
}

20
run
View file

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