Skip to content

Commit 18af48a

Browse files
committed
configured proxy so game-server connections needs to be pointed to path game-server/socket.io instead of default path to make sure it overlap with other possible socket connections, updated readme
1 parent f3c82dc commit 18af48a

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

Frontend/nginx.conf

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ http {
106106
}
107107

108108
# Proxy WebSocket and HTTP requests to the game server
109-
location /socket.io/ {
109+
location /game-server/socket.io/ {
110+
rewrite ^/game-server/socket.io/(.*) /socket.io/$1 break;
110111
proxy_pass http://game-server;
111112
proxy_set_header Host $host;
112113
proxy_set_header X-Real-IP $remote_addr;

Frontend/nginx.conf.dev

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ http {
2828
}
2929

3030
# WebSocket requests
31-
location /socket.io/ {
32-
proxy_pass http://game-server:8010;
31+
location /game-server/socket.io/ {
32+
proxy_pass http://game-server:8010/socket.io;
3333
proxy_set_header Host $host;
3434
proxy_set_header X-Real-IP $remote_addr;
3535
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Frontend/src/js/pong/socket.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { io } from 'socket.io-client';
22

33
// Use the proxy path for local development
4-
// const socket = io( {path: '/game-server/socket.io'});
5-
const socket = io();
6-
console.log("derp")
4+
const socket = io('/', {path: '/game-server/socket.io',});
5+
// const socket = io();
76

87
socket.on('connect', () => {
98
console.log('Connected to server');

Frontend/vite.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export default defineConfig(({ mode }) => ({
2121
target: 'http://game-history:8002', // Proxy to game history service
2222
changeOrigin: true,
2323
},
24-
'/socket.io': {
25-
target: 'http://game-server:8010', // Proxy to game server
24+
'/game-server/socket.io': {
25+
target: 'http://game-server:8010/socket.io', // Proxy to game server
2626
changeOrigin: true,
2727
ws: true, // Enable WebSocket support
2828
},

Game_server/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This is the game server for the Mighty Pong Contest. Developed with Python and S
1414
To start a game session, follow these instructions:
1515

1616
1. **Connect to the Server**
17-
- Connect your client to the server using Socket.IO at `http://game-server:8010/socket.io`.
17+
- Connect your client to the server using Socket.IO at `http://game-server:8010/game-server/socket.io`.
1818

1919
2. **Prepare Game Initialization Data**
2020
- Create an object with the following details:
@@ -79,6 +79,11 @@ To start a game session, follow these instructions:
7979
uvicorn main:app --host 0.0.0.0 --port 8010 --log-level info
8080
```
8181

82+
4. **Build and run the app**
83+
```bash
84+
make
85+
```
86+
8287
### TODO: Remote Play Integration
8388

8489
The backend is working on matchmaking feature which is coming soon, in the meantime remote play needs to be fully integrated, and handling the ending of the game as well.

Game_server/server.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async def game_loop(self) -> None:
122122
while self.game_state.in_progress:
123123
self.game_state.current_rally = 0
124124
self.game_state.reset_ball()
125-
logging.info("Rally started")
125+
logging.info(f"Rally started, game ID: {self.game_state.game_id}, sids: {self.sids}")
126126
await self.send_game_state_to_client()
127127
await asyncio.sleep(0.5) # Little break before start of the rally
128128
self.game_state.paused = False
@@ -298,7 +298,7 @@ async def connect(sid, environ):
298298
# This function is called when a client disconnects from the server
299299
# The 'sid' parameter is the session ID of the client
300300
# Removes sid from sid_to_game and active_games
301-
# If no players are left in the game, the game instance is removed
301+
# If no players are left in the game, the game instance is or should be removed
302302
@sio.event
303303
async def disconnect(sid):
304304
logging.info(f'Disconnect: {sid}')
@@ -309,7 +309,8 @@ async def disconnect(sid):
309309
if sid in game_instance.sids:
310310
game_instance.sids.remove(sid)
311311
if not game_instance.sids:
312-
del active_games[game_id] # Optionally handle cleanup if no players are left
312+
logging.info(f"No players left in game {game_id}")
313+
del active_games[game_id] # this cleanup actually does not work
313314

314315
# Event handler for messages
315316
# This function is called when a client sends a message to the server

0 commit comments

Comments
 (0)