Skip to content

Repository files navigation

dfg-server

Real-time WebSocket server for Super Debunkers, a multiplayer card game about identifying misinformation tactics. Built with PartyKit and TypeScript.

Deployed:dfg-server.mlenda000.partykit.dev

Related Repository

This is the server application. It powers the companion client:

RepoDescription
super-debunkersReact front-end — UI, game interactions, drag-and-drop
dfg-server (this repo)PartyKit WebSocket server — rooms, scoring, game state

Both must be running for local development.

What the Server Does

  • Manages game room lifecycle (create, join, leave, auto-delete empty rooms after 30s)
  • Handles player connections, disconnections, and reconnections with full state restoration
  • Shuffles and distributes the influencer card deck
  • Calculates scores when all players submit answers (correct/wrong/streak bonuses)
  • Broadcasts real-time state updates to all connected clients
  • Enforces room capacity (max 5 players per room)
  • Manages a lobby system with available room discovery

Architecture

src/
├── server.ts # Main PartyKit server — WebSocket & HTTP handlers
├── components/
│ ├── Deck/ # Deck shuffling and card management
│ ├── Player/ # Player creation and state management
│ ├── Room/ # GameRoom class — per-room state
│ ├── RoomManager.ts # Room lifecycle (create, delete, timers)
│ └── Scoring/ # Score calculation, streaks, bonuses
├── data/ # Static card data (influencer cards)
├── types/ # TypeScript type definitions
└── utils/ # Parsing and utility functions

Message Types

The server handles these WebSocket message types:

MessageDirectionDescription
getPlayerIdClient → ServerRequest a unique player ID
enteredLobbyClient → ServerPlayer entered the lobby
createRoomClient → ServerCreate a new game room
playerEntersClient → ServerPlayer joins a game room
playerLeavesClient → ServerPlayer leaves a game room
influencerClient → ServerBroadcast current news card + villain
playerReadyClient → ServerPlayer submitted their tactic choices
playerNotReadyClient → ServerPlayer retracted their choices
endOfRoundClient → ServerAll players ready — trigger scoring
roomUpdateServer → ClientFull room state sync
scoreUpdateServer → ClientScoring results for the round
reconnectStateServer → ClientFull state restore for reconnecting player
lobbyUpdateServer → ClientAvailable rooms and player counts

Getting Started

Prerequisites

  • Node.js 25+
  • npm

Installation

# Clone the repo
git clone https://github.com/mlenda000/dfg-server.git
cd dfg-server
# Install dependencies
npm install
# Start the dev server on port 1999
npm run dev

The server runs on http://127.0.0.1:1999 in development mode. The Super Debunkers client connects here automatically when running locally.

Deploying

npm run deploy

Deploys to the PartyKit cloud at dfg-server.mlenda000.partykit.dev.

Testing

The project includes comprehensive tests covering scoring logic, room lifecycle, WebSocket flows, and server integration:

# Run all tests
npm test# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage

Test Suite

Test FileCoverage
scoring.test.tsMulti-player scoring, streak logic, bonus calculations, edge cases
room-lifecycle.test.tsRoom creation, deletion, auto-cleanup timers
websocket-flow.test.tsMessage handling, player state transitions
server-integration.test.tsEnd-to-end server behavior

Scripts

CommandDescription
npm run devStart PartyKit dev server on port 1999
npm run deployDeploy to PartyKit cloud
npm testRun test suite
npm run test:watchRun tests in watch mode
npm run test:coverageGenerate test coverage report
  • ✅ Score validation and state management

See TESTING.md for detailed testing documentation.

Refer to our docs for more information: https://github.com/partykit/partykit/blob/main/README.md. For more help, reach out to us on Discord, GitHub, or Twitter.

About

websocket server for dfg game

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages