# Quick Start Guide - Team-Based Dangerous Falls Challenge

## First Time Setup

1. **Install Dependencies** (if not already done):
```bash
cd /Users/vaughanbd/sandbox/DangerousFalls/server
npm install
```

2. **Configure Environment** (optional):
```bash
# Create .env file if you want custom settings
echo "JWT_SECRET=your-secret-key-here" > .env
echo "PORT=3010" >> .env
echo "ADMIN_PASSWORD=your-admin-password" >> .env
```

3. **Start the Server**:
```bash
npm run dev
```

The database will be automatically created with the 4 teams on first run.

## Daily Game Session Workflow

### Before Participants Arrive

1. **Reset Previous Session** (if needed):
```bash
curl -X POST http://localhost:3010/api/admin/reset \
  -H "Content-Type: application/json" \
  -d '{"password":"reset123"}'
```

2. **Verify Server is Running**:
```bash
curl http://localhost:3010/api/health
```

### During the Activity

1. **Participants Log In**:
   - Each person goes to: `http://localhost:3010`
   - Selects their assigned station (e.g., Crocks1, Hipps2, etc.)
   - Clicks "Start Challenge"

2. **Monitor Progress** (optional):
```bash
curl http://localhost:3010/api/admin/stats | jq
```

### After Completion

1. **View Final Stats**:
```bash
curl http://localhost:3010/api/admin/stats | jq
```

2. **Reset for Next Session**:
```bash
curl -X POST http://localhost:3010/api/admin/reset \
  -H "Content-Type: application/json" \
  -d '{"password":"reset123"}'
```

## Station Assignments

### Team Crocks
- Computer 1: Crocks1
- Computer 2: Crocks2
- Computer 3: Crocks3
- Computer 4: Crocks4

### Team Hipps
- Computer 5: Hipps1
- Computer 6: Hipps2
- Computer 7: Hipps3
- Computer 8: Hipps4

### Team Buffs
- Computer 9: Buffs1
- Computer 10: Buffs2
- Computer 11: Buffs3
- Computer 12: Buffs4

### Team Tusks
- Computer 13: Tusks1
- Computer 14: Tusks2
- Computer 15: Tusks3
- Computer 16: Tusks4

## How Win Requirements Work

**Simple Rule**: Team must win as many times as they have active players.

Examples:
- If 3 people from Team Crocks log in → Need 3 wins per challenge
- If all 4 people from Team Hipps log in → Need 4 wins per challenge
- If only 1 person from Team Buffs logs in → Need 1 win per challenge

**Important**:
- If someone logs in with the same station twice, it doesn't count as a new player
- Win requirement is set when first player logs in and increases as more players join

## Game Flow

1. **Password Challenge** (first game, always unlocked)
2. **Get to the Temple** (unlocked after Password)
3. **Mastermind** (unlocked after Temple)
4. **Anaconda/Snake** (unlocked after Mastermind)
5. **Hangman** (unlocked after Snake, final game)

Each game reveals a secret code when completed:
- Password → unlocks Temple
- Temple → CASE code
- Mastermind → FLOATIES code
- Snake → STUNGUN code
- Hangman → ROPE code

## Troubleshooting

### Server Won't Start
```bash
# Check if port 3010 is already in use
lsof -i :3010

# Kill existing process if needed
kill -9 <PID>
```

### Database Issues
```bash
# Backup and recreate database
mv game.db game-backup.db
# Restart server - it will create fresh database
npm run dev
```

### Reset Not Working
```bash
# Check admin password in .env file
cat .env | grep ADMIN_PASSWORD

# Use correct password (default: reset123)
curl -X POST http://localhost:3010/api/admin/reset \
  -H "Content-Type: application/json" \
  -d '{"password":"your-password-here"}'
```

### Player Can't Log In
- Verify station name is spelled exactly: "Crocks1" not "crocks1" or "Crocks 1"
- Check browser console for errors (F12)
- Verify server is running and accessible

## Advanced: Custom Team Names

If you want different team names:

1. Stop the server
2. Delete `game.db`
3. Edit `database.js`, function `seedTeams()`:
```javascript
const teams = ['YourTeam1', 'YourTeam2', 'YourTeam3', 'YourTeam4'];
```
4. Edit `routes/auth.js`, update `VALID_STATIONS` array
5. Edit `public/index.html`, update dropdown options
6. Restart server

## Network Access

### Local Network Access (for multiple computers)
1. Find server's IP address:
```bash
ifconfig | grep "inet " | grep -v 127.0.0.1
```

2. Update server to listen on all interfaces (in `server.js`):
```javascript
app.listen(PORT, '0.0.0.0', () => {
  console.log(`Server running on port ${PORT}`);
});
```

3. Participants access via: `http://<server-ip>:3010`

### Firewall
Ensure port 3010 is open:
```bash
# macOS
sudo pfctl -d  # Disable firewall temporarily
# or allow specific port in System Preferences → Security
```

## Port Already in Use

The server is configured to run on port `3010`. If you see errors about port `3000`, check your `.env` file.

Current configuration:
- Server runs on port **3010** (not 3000)
- Database: `game.db` in server directory
- Admin password: `reset123` (default)
