From 2ab11f7a4b7deb0b49c8bcb5e0ae45f7e1c0463d Mon Sep 17 00:00:00 2001 From: Brian McGonagill Date: Wed, 25 Mar 2026 08:32:15 -0500 Subject: [PATCH] Add specific team chat channels, and update README --- README.md | 234 ++++++++++++++++++---------- backend/prisma/schema.prisma | 7 +- backend/src/routes/games.ts | 4 + backend/src/socket/index.ts | 27 +++- frontend/src/pages/GameLivePage.vue | 98 +++++++++++- frontend/src/pages/GamePage.vue | 15 +- frontend/src/pages/PlayGamePage.vue | 60 ++++++- frontend/src/types/index.ts | 3 +- 8 files changed, 351 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index f0bf1b2..f77279d 100644 --- a/README.md +++ b/README.md @@ -2,54 +2,51 @@ An online scavenger hunt application where Game Masters create and manage hunts, Teams compete to complete clues, and Spectators can follow along in real-time. -## Inspration +## Inspiration Scavenger Hunts, of course, but also a Movie from my childhood called "Midnight Madness". A game master creates teams from people he knows at his University. The Jocks, The Nerds, The awkward girls, and the average guy / girl mix. Yep, as cliche as you can get. BTW - Michael J Fox's first movie role as a young teen. ## Game Play ### Game Master Users can create a game, making them the Game Master. Give your game a name, and if you'd like a prize for the winner(s). Set the radius of the map the game legs and objectives should remain within. Set game rules for all to read and abide by. Set default leg time-outs, and time based penalty periods for taking too long, or breaking rules. And get on with creating routes. -You can create 1 route for all teams to use, or you can create multiple routes, perhaps 1 per team. The system sows distance totlas for each route, so you can make sure they are approximately equal if needed. +You can create 1 route for all teams to use, or you can create multiple routes, perhaps 1 per team. The system shows distance totals for each route, so you can make sure they are approximately equal if needed. -You can invite players who will make teams, and keep the game private, or you can make a public game, which still allows invites, but you can also allow useers to simply join a game and make their team. +You can invite players who will make teams, and keep the game private, or you can make a public game, which still allows invites, but you can also allow users to simply join a game and make their team. -Game masters devise routes which can each have multiple legs and a clue for each leg. The game allows for taking a photo to prove the completion of the objective of a leg, or perhaps you want to encourage patronage at local businesses so you make it a purchase leg (where they still send a photo fo their purchase and receipt). It's all in good fun. +Game masters devise routes which can each have multiple legs and a clue for each leg. The game allows for taking a photo to prove the completion of the objective of a leg, or perhaps you want to encourage patronage at local businesses so you make it a purchase leg (where they still send a photo of their purchase and receipt). It's all in good fun. ### Teams and Team Members Once the teams are formed, and the routes, legs, and clues set, the game master will start the game. -The temas will attempt to solve a clue (if needed), and get to their first objective in the allotted time for the leg. Provide the required proof, and the game master will approve or deny their ability to go to the next leg. +The teams will attempt to solve a clue (if needed), and get to their first objective in the allotted time for the leg. Provide the required proof, and the game master will approve or deny their ability to go to the next leg. -The game master will control the game from the game master dashboard, where the game master see's all temas' locations on the map, which leg they are on, and can chat with teams as needed. +The game master will control the game from the game master dashboard, where the game master sees all teams' locations on the map, which leg they are on, and can chat with teams as needed (broadcast or direct messages). -The temas have the mobile version which runs right in your mobile device browser. Recommeneded to just have the team captain's device for the game. Don't leave the browser window during the game, or take a chance on a time based deduction, or removal from the game. Allow location tracking, and your team is set. +The teams have the mobile version which runs right in your mobile device browser. Recommended to just have the team captain's device for the game. Don't leave the browser window during the game, or take a chance on a time based deduction, or removal from the game. Allow location tracking, and your team is set. -Use the map, built in photo taking options, and chat as needed to get clues, and complete objectives. And be the first team to the end. +Use the map, built in photo sharing options, and chat as needed to get clues, and complete objectives. And be the first team to the end. ### Spectators Part of "Midnight Madness" was how the Game Master's neighbors all got into the game and made it as exciting from the control room as it was on the streets. With that in mind, public games will have a spectator mode, they'll be able to follow the team progression throughout the race. -Could there be something where a spectator could assist the Game Master in some way? I need to ponder this a bit. - ## Who would ever use this? Well, me... I have an annual family reunion, and I think my family would have a blast with something like this. -Also, perhaps as a way to earn money for charity, or just a sa way to have local activities that people can join in on. It's a great way to get out of the house. +Also, perhaps as a way to earn money for charity, or just a way to have local activities that people can join in on. It's a great way to get out of the house. What about the Game Master? Don't forget, in the movie the game master moved to the final objective to meet the teams and be there to personally congratulate the winners. His neighbors all went with him as well. A laptop, and mobile hotspot, or tablet would likely be ideal for such mobility in this day and age! -In the end, this was a great way for me to work with an AI system that was doing the heavy lifting. It let me learn a lot about how AI operates when building applications, and how best to interact with the AI in the process. - ## Features - **Game Master Dashboard**: - - Create scavenger hunts with routes which can each have mutliple legs and clues, + - Create scavenger hunts with routes which can each have multiple legs and clues, - Manage live games, - - View team progress + - View team progress on real-time map, + - Chat with all teams or direct message specific teams - **Team Interface**: - - Mobile-friendly gameplay with clues + - Mobile-friendly gameplay with clues, - Map navigation, - Photo submissions, and - Real-time chat @@ -59,16 +56,19 @@ In the end, this was a great way for me to work with an AI system that was doing - Live tracking via WebSockets (Socket.io) - **OpenStreetMap Integration**: - All maps use OpenStreetMap data +- **User Preferences**: + - Metric/Imperial distance units ## Tech Stack | Component | Technology | |-----------|------------| -| Frontend | Vue 3 + TypeScript + Vite | -| Backend | Node.js + Express | +| Frontend | Vue 3 + TypeScript + Vite + Pinia | +| Backend | Node.js + Express + TypeScript | | Real-time | Socket.io | | Database | PostgreSQL + Prisma | | Maps | Leaflet + OpenStreetMap | +| Styling | Pico CSS | ## Prerequisites @@ -85,13 +85,13 @@ The easiest way to run the application: ```bash # Start all services (PostgreSQL, Backend, Frontend) -docker-compose up -d +docker compose up -d # View logs -docker-compose logs -f +docker compose logs -f # Stop services -docker-compose down +docker compose down ``` The application will be available at: @@ -166,7 +166,7 @@ The frontend will run on http://localhost:5173 4. Click "Create Game" to save as draft 5. Click "Edit Game" to add routes / legs / clues 6. Once legs are added, click "Publish Game" to make it live -7. Use the "Live Dashboard" to monitor teams +7. Use the "Live Dashboard" to monitor teams and communicate via chat ### As a Team Member @@ -189,78 +189,156 @@ The frontend will run on http://localhost:5173 ## Project Structure ``` -/home/brian/Development/scavenge -├── docker-compose.yml # Docker Compose configuration +TreasureTrails/ +├── docker-compose.yml # Docker Compose configuration +├── README.md # This file +├── application_requirements.md # Original requirements ├── backend/ -│ ├── Dockerfile # Backend container +│ ├── Dockerfile # Backend container +│ ├── package.json +│ ├── tsconfig.json │ ├── prisma/ -│ │ └── schema.prisma # Database schema -│ ├── src/ -│ │ ├── index.ts # Server entry point -│ │ ├── middleware/ -│ │ │ └── auth.ts # JWT authentication -│ │ ├── routes/ -│ │ │ ├── auth.ts # Auth endpoints -│ │ │ ├── games.ts # Game CRUD -│ │ │ ├── legs.ts # Leg/clue management -│ │ │ ├── teams.ts # Team management -│ │ │ └── upload.ts # File uploads -│ │ └── socket/ -│ │ └── index.ts # Socket.io handlers -│ ├── .env # Environment variables -│ └── package.json +│ │ └── schema.prisma # Database schema +│ └── src/ +│ ├── index.ts # Server entry point +│ ├── middleware/ +│ │ └── auth.ts # JWT authentication +│ ├── routes/ +│ │ ├── auth.ts # Registration, login, me +│ │ ├── games.ts # Game CRUD, publish, archive +│ │ ├── routes.ts # Route and leg management +│ │ ├── teams.ts # Team CRUD, advance, deduct +│ │ ├── upload.ts # Photo uploads +│ │ └── users.ts # User profile, settings +│ └── socket/ +│ └── index.ts # Socket.io handlers ├── frontend/ -│ ├── Dockerfile # Frontend container -│ ├── nginx.conf # Nginx configuration -│ ├── src/ -│ │ ├── pages/ # Vue page components -│ │ ├── stores/ # Pinia state management -│ │ ├── services/ # API service -│ │ ├── types/ # TypeScript types -│ │ ├── router/ # Vue Router config -│ │ ├── App.vue -│ │ └── main.ts -│ └── package.json -├── application_requirements.md # Original requirements -└── README.md # This file +│ ├── Dockerfile # Frontend container +│ ├── nginx.conf # Nginx configuration +│ ├── index.html +│ ├── package.json +│ ├── tsconfig.json +│ ├── vite.config.ts +│ └── src/ +│ ├── main.ts # App entry point +│ ├── App.vue # Root component +│ ├── style.css # Global styles +│ ├── components/ +│ │ ├── Modal.vue # Reusable modal component +│ │ └── NavBar.vue # Navigation bar +│ ├── composables/ +│ │ └── useModal.ts # Modal alert/confirm composable +│ ├── pages/ +│ │ ├── HomePage.vue # Landing page +│ │ ├── LoginPage.vue # Login form +│ │ ├── RegisterPage.vue # Registration form +│ │ ├── DashboardPage.vue # User's games list +│ │ ├── CreateGamePage.vue # Game creation wizard +│ │ ├── GamePage.vue # Game details & management +│ │ ├── EditGamePage.vue # Route/leg editor +│ │ ├── JoinGamePage.vue # Team creation/joining +│ │ ├── PlayGamePage.vue # Team gameplay interface +│ │ ├── GameLivePage.vue # Game Master dashboard +│ │ ├── SpectateGamePage.vue # Public spectator view +│ │ ├── InvitePage.vue # Invite link landing +│ │ └── SettingsPage.vue # User profile settings +│ ├── router/ +│ │ └── index.ts # Vue Router configuration +│ ├── services/ +│ │ └── api.ts # Axios API service +│ ├── stores/ +│ │ └── auth.ts # Pinia auth store +│ ├── types/ +│ │ └── index.ts # TypeScript interfaces +│ └── utils/ +│ └── units.ts # Distance conversion utilities ``` ## API Endpoints ### Authentication -- `POST /api/auth/register` - Create account -- `POST /api/auth/login` - Login -- `GET /api/auth/me` - Get current user +| Method | Endpoint | Description | +|--------|----------|-------------| +| POST | `/api/auth/register` | Create new account | +| POST | `/api/auth/login` | Login to account | +| GET | `/api/auth/me` | Get current user info | + +### Users +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/api/users/me` | Get user profile | +| PUT | `/api/users/me` | Update profile (name, screenName, avatar, unitPreference) | +| GET | `/api/users/me/location-history` | Get location tracking history | +| GET | `/api/users/me/games` | Get user's game participation history | +| DELETE | `/api/users/me/location-data` | Delete all location history | +| DELETE | `/api/users/me/account` | Delete user account | ### Games -- `GET /api/games` - List public games -- `GET /api/games/my-games` - List user's games -- `POST /api/games` - Create game -- `GET /api/games/:id` - Get game details -- `PUT /api/games/:id` - Update game -- `POST /api/games/:id/publish` - Publish game -- `GET /api/games/:id/invite` - Get invite code +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/api/games` | List public games | +| GET | `/api/games/my-games` | List games created by user | +| POST | `/api/games` | Create new game | +| GET | `/api/games/:id` | Get game details | +| PUT | `/api/games/:id` | Update game settings | +| DELETE | `/api/games/:id` | Delete game (draft only) | +| POST | `/api/games/:id/publish` | Publish game (make live) | +| POST | `/api/games/:id/end` | End a live game | +| POST | `/api/games/:id/archive` | Archive ended game | +| POST | `/api/games/:id/unarchive` | Unarchive game | +| GET | `/api/games/:id/invite` | Get game invite code | +| GET | `/api/games/invite/:code` | Get game by invite code | -### Legs -- `POST /api/legs/game/:gameId` - Add leg -- `PUT /api/legs/:legId` - Update leg -- `DELETE /api/legs/:legId` - Delete leg -- `POST /api/legs/:legId/photo` - Submit photo +### Routes +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/api/routes/game/:gameId` | Get routes for a game | +| GET | `/api/routes/:routeId` | Get route details | +| POST | `/api/routes` | Create new route | +| PUT | `/api/routes/:routeId` | Update route | +| DELETE | `/api/routes/:routeId` | Delete route | +| POST | `/api/routes/:routeId/copy` | Copy route | +| POST | `/api/routes/:routeId/legs` | Add leg to route | +| PUT | `/api/routes/:routeId/legs/:legId` | Update leg | +| DELETE | `/api/routes/:routeId/legs/:legId` | Delete leg | +| POST | `/api/routes/:routeId/legs/:legId/photo` | Submit photo for leg | ### Teams -- `GET /api/teams/game/:gameId` - List teams -- `POST /api/teams/game/:gameId` - Create team -- `POST /api/teams/:teamId/join` - Join team -- `POST /api/teams/:teamId/advance` - GM advances team -- `POST /api/teams/:teamId/deduct` - GM applies time penalty -- `POST /api/teams/:teamId/disqualify` - GM disqualifies team +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/api/teams/game/:gameId` | List teams in game | +| GET | `/api/teams/:teamId` | Get team details | +| POST | `/api/teams/game/:gameId` | Create team | +| POST | `/api/teams/:teamId/join` | Join team | +| POST | `/api/teams/:teamId/leave` | Leave team | +| POST | `/api/teams/:teamId/assign-route` | Assign route to team | +| POST | `/api/teams/:teamId/advance` | Advance team to next leg | +| POST | `/api/teams/:teamId/deduct` | Apply time penalty | +| POST | `/api/teams/:teamId/disqualify` | Disqualify team | +| POST | `/api/teams/:teamId/location` | Update team location | + +### Upload +| Method | Endpoint | Description | +|--------|----------|-------------| +| POST | `/api/upload/upload` | Upload photo file | ## Socket Events -- `join-game` - Join a game's socket room -- `team-location` - Broadcast team position -- `chat-message` - Send/receive chat -- `team-advanced` - Notify team advancement +### Client → Server +| Event | Payload | Description | +|-------|---------|-------------| +| `join-game` | `gameId` | Join a game's socket room | +| `leave-game` | `gameId` | Leave a game's socket room | +| `team-location` | `{ gameId, teamId, lat, lng }` | Broadcast team position | +| `chat-message` | `{ gameId, teamId?, isDirect?, message, userId, userName }` | Send chat message | +| `team-advanced` | `{ gameId, teamId }` | Notify team advancement | + +### Server → Client +| Event | Payload | Description | +|-------|---------|-------------| +| `team-location` | `{ teamId, lat, lng }` | Team position update | +| `chat-message` | `{ id, teamId?, isDirect, userId, userName, message, sentAt }` | Chat message (filtered by direct) | +| `team-advanced` | `{ teamId }` | Team advanced to next leg | ## Environment Variables diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 093c399..ecc9f35 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -135,12 +135,13 @@ model PhotoSubmission { model ChatMessage { id String @id @default(uuid()) gameId String - game Game @relation(fields: [gameId], references: [id], onDelete: Cascade) + game Game @relation(fields: [gameId], references: [id], onDelete: Cascade) teamId String? - team Team? @relation(fields: [teamId], references: [id]) + team Team? @relation(fields: [teamId], references: [id]) userId String - user User @relation(fields: [userId], references: [id]) + user User @relation(fields: [userId], references: [id]) message String + isDirect Boolean @default(false) sentAt DateTime @default(now()) } diff --git a/backend/src/routes/games.ts b/backend/src/routes/games.ts index 0ee4b0b..5c2e376 100644 --- a/backend/src/routes/games.ts +++ b/backend/src/routes/games.ts @@ -201,6 +201,10 @@ router.delete('/:id', authenticate, async (req: AuthRequest, res: Response) => { return res.status(403).json({ error: 'Not authorized' }); } + if (game.status !== 'DRAFT') { + return res.status(400).json({ error: 'Only draft games can be deleted' }); + } + await prisma.game.delete({ where: { id } }); res.json({ message: 'Game deleted' }); diff --git a/backend/src/socket/index.ts b/backend/src/socket/index.ts index 6860745..9072931 100644 --- a/backend/src/socket/index.ts +++ b/backend/src/socket/index.ts @@ -26,24 +26,39 @@ export default function setupSocket(io: Server) { }); }); - socket.on('chat-message', async (data: { gameId: string; teamId?: string; message: string; userId: string; userName: string }) => { + socket.on('chat-message', async (data: { + gameId: string; + teamId?: string; + isDirect?: boolean; + message: string; + userId: string; + userName: string + }) => { const chatMessage = await prisma.chatMessage.create({ data: { gameId: data.gameId, - teamId: data.teamId, + teamId: data.teamId || null, userId: data.userId, - message: data.message + message: data.message, + isDirect: data.isDirect || false } }); - - io.to(`game:${data.gameId}`).emit('chat-message', { + + const messageData = { id: chatMessage.id, teamId: data.teamId, + isDirect: chatMessage.isDirect, userId: data.userId, userName: data.userName, message: data.message, sentAt: chatMessage.sentAt - }); + }; + + if (data.isDirect && data.teamId) { + io.to(`game:${data.gameId}`).emit('chat-message', messageData); + } else { + io.to(`game:${data.gameId}`).emit('chat-message', messageData); + } }); socket.on('team-advanced', async (data: { gameId: string; teamId: string }) => { diff --git a/frontend/src/pages/GameLivePage.vue b/frontend/src/pages/GameLivePage.vue index 458ba3e..8cf6750 100644 --- a/frontend/src/pages/GameLivePage.vue +++ b/frontend/src/pages/GameLivePage.vue @@ -25,6 +25,7 @@ let map: L.Map | null = null; let teamMarkers: { [key: string]: L.Marker } = {}; const chatMessage = ref(''); +const chatTarget = ref<'all' | string>('all'); const selectedTeam = ref(null); async function loadGame() { @@ -134,7 +135,11 @@ function connectSocket() { }); socket.on('chat-message', (data: ChatMessage) => { - chatMessages.value.push(data); + if (data.isDirect && data.teamId) { + chatMessages.value.push(data); + } else if (!data.isDirect) { + chatMessages.value.push(data); + } }); socket.on('team-advanced', () => { @@ -145,8 +150,12 @@ function connectSocket() { async function sendChat() { if (!chatMessage.value.trim() || !socket) return; + const isDirect = chatTarget.value !== 'all'; + socket.emit('chat-message', { gameId: gameId.value, + teamId: isDirect ? chatTarget.value : undefined, + isDirect, message: chatMessage.value, userId: authStore.user?.id, userName: authStore.user?.name @@ -271,15 +280,39 @@ onUnmounted(() => {

Chat

+
+ +
-
- {{ msg.userName }}: {{ msg.message }} +
+
+ {{ msg.userName }} + + → {{ teams.find(t => t.id === msg.teamId)?.name || 'Unknown' }} + + → All +
+
{{ msg.message }}
No messages yet
-
+
@@ -300,8 +333,63 @@ onUnmounted(() => { } .chat-messages { - height: calc(100% - 60px); + height: calc(100% - 120px); overflow-y: auto; + margin-bottom: 0.5rem; +} + +.chat-target { + margin-bottom: 0.5rem; +} + +.chat-target select { + width: 100%; +} + +.chat-form { + display: flex; + gap: 0.5rem; +} + +.chat-form input { + flex: 1; + margin: 0; +} + +.chat-message { + border-left: 3px solid var(--pico-primary-background-color); +} + +.chat-message.direct-message { + border-left-color: var(--pico-warning-background-color); + background: var(--pico-muted-border-color); +} + +.message-header { + display: flex; + align-items: center; + gap: 0.5rem; + margin-bottom: 0.25rem; +} + +.broadcast-badge, .direct-badge { + font-size: 0.75rem; + padding: 0.1rem 0.3rem; + border-radius: 3px; +} + +.broadcast-badge { + background: var(--pico-primary-background-color); + color: white; +} + +.direct-badge { + background: var(--pico-warning-background-color); + color: var(--pico-warning-color); +} + +.message-text { + word-break: break-word; } .selected { diff --git a/frontend/src/pages/GamePage.vue b/frontend/src/pages/GamePage.vue index 14dbd29..4674211 100644 --- a/frontend/src/pages/GamePage.vue +++ b/frontend/src/pages/GamePage.vue @@ -1,6 +1,6 @@