Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes #1

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
JWT_TOKEN=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
ADMIN_PASSWORD=
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**node_modules**
**package-lock.json**
node_modules/
.env

postgres_data
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
# boelter
A mini pop quiz game for CS 118

A mini pop quiz game for CS 33, originally created by https://github.com/eado for CS 118, updated and modified by https://github.com/burturt

## Requirements
Docker >=v24
Ports open:
- 80 (Public progress dashboard)
- 22[0-n] (where n is the number of players)

- Docker
- Intended use ports open

## Setup
Run `start.bash`.
To change the number of players (default 10, max 99),

Make a copy of `.env.example` into `.env.`. Set a value for each:

- `JWT_TOKEN` should be some very long random secret string.
- `POSTGRES_*` self explanatory, just pick something
- `ADMIN_PASSWORD` password needed to login to the host instance. User password is just `desk`

### One game

Run `docker compose up`. Players connect to ports 2222 via ssh, and the game host connects to port 2223 and can see the website at port 8080.

### Multiple games

Run `start.bash`.
To change the number of game instances to spawn (default 2, max 99),
add the option `-n <num>` where `<num>` is the number of players you want to
instantiate.
instantiate.

This will:
- Create n + 1 Docker containers with the name `player<i>`.
- This includes `player0` for demonstration.
- Each will have ssh open on port `22<i:2>` (for example, `player1` has port
`2201` open).
- These are helpdesk servers that players use as a starting point.
- Create a progress server to track players' progression.
- Each player connects to the progress server via WebSockets

- Create n docker compose projects, named 01, 02, ... up to n
- Each project consists of a psql database, a player container that players can ssh into, and a host container that the host must ssh into to start the game
- If XX is the project name, port 2XX0 is the port players ssh into, port 2XX1 is the HTTP web server port, and port 2XX2 is the host ssh port.
- Inside of the player container, each player gets an instance of player.js automatically upon connection
- Each player connects to the host server via WebSockets, and directly to the database
- The progress server pings the players whenever there's a new round
- Based on the elapsed time, the progress server awards points when a player
submits an answer

# Questions

All the questions are available at `player/questions.json`. The `file`
attribute points to a file in the `player/texts` directory for the actual
question text.
question text.
21 changes: 21 additions & 0 deletions db/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE teams (
team_name text PRIMARY KEY,
member1_name text NOT NULL,
member2_name text NOT NULL,
member3_name text,
member1_id text NOT NULL,
member2_id text NOT NULL,
member3_id text,
member1_dis text NOT NULL,
member2_dis text NOT NULL,
member3_dis text
);

CREATE TABLE submissions (
team_name text NOT NULL REFERENCES teams(team_name),
question integer NOT NULL,
points integer NOT NULL,
solved boolean NOT NULL,
solved_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (team_name, question)
);
43 changes: 43 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
db:
image: postgres:latest
restart: always
env_file:
- .env
environment:
- INSTANCE_NUM=${INSTANCE_NUM:-1}
volumes:
- dbdata:/var/lib/postgresql/data
- ./db/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
player:
build:
context: .
dockerfile: player/Dockerfile
restart: always
env_file:
- .env
environment:
- INSTANCE_NUM=${INSTANCE_NUM:-1}
ports:
- "${PLAYER_PORT:-2222}:22"
depends_on:
- db
server:
restart: always
build:
context: .
dockerfile: progress/Dockerfile
args:
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
env_file:
- .env
environment:
- INSTANCE_NUM=${INSTANCE_NUM:-1}
ports:
- "${SERVER_PORT:-2223}:22"
- "${SERVER_HTTP_PORT:-8080}:8080"
depends_on:
- db

volumes:
dbdata:
12 changes: 9 additions & 3 deletions player/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ENV USER=help
ENV PASSWORD=desk
ENV ENV=/$USER/.rc

WORKDIR /$USER

RUN mkdir -p /$USER \
&& echo -e "$PASSWORD\n$PASSWORD\n" | adduser --gecos "" --home "/$USER" --no-create-home $USER \
&& mkdir -p /$USER/.ssh \
Expand All @@ -17,7 +19,11 @@ RUN mkdir -p /$USER \
&& apk add --update nodejs npm \
&& echo -e "trap 'exit' 0 SIGINT EXIT SIGSTOP \n/$USER/run \nexit" >> /etc/profile

COPY . /$USER
RUN cd /$USER && npm i
COPY player/ .
RUN npm i
COPY .env .
COPY questions/questions.json .
COPY wait-stop-ssh.sh .
RUN chmod +x wait-stop-ssh.sh

CMD ["sh", "-c", "rc-status; rc-service sshd start; cat"]
CMD ["sh", "-c", "echo ' ' >> .env; echo INSTANCE_NUM=$INSTANCE_NUM >> .env; rc-status; rc-service sshd start; ./wait-stop-ssh.sh"]
8 changes: 8 additions & 0 deletions player/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import globals from "globals";
import pluginJs from "@eslint/js";

export default [
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
];
Loading