broadfield-dev commited on
Commit
438862f
·
verified ·
1 Parent(s): 3059061

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -7,16 +7,14 @@ import os
7
  app = Flask(__name__)
8
  app.config['SECRET_KEY'] = 'your-secret-key' # Replace with a secure key
9
 
10
- # Configure SocketIO with eventlet for WebSocket support
11
  socketio = SocketIO(app,
12
  cors_allowed_origins="https://broadfield-dev-dungeon-game.hf.space", # Your Spaces URL
13
- async_mode='eventlet')
14
 
15
  # Store game instances per client session
16
  games = {}
17
 
18
- # ... (rest of your routes and SocketIO handlers remain the same)
19
-
20
  @app.route('/')
21
  def index():
22
  session['sid'] = str(uuid.uuid4()) # Unique session ID for each client
@@ -26,7 +24,9 @@ def index():
26
  def handle_connect(auth=None):
27
  sid = session.get('sid')
28
  games[sid] = Game()
29
- emit('update_game', games[sid].get_game_state())
 
 
30
  emit('message', 'Connected to the dungeon! Use arrow keys to move.')
31
 
32
  @socketio.on('move')
@@ -55,5 +55,6 @@ def handle_disconnect():
55
  del games[sid]
56
 
57
  if __name__ == '__main__':
 
58
  port = int(os.environ.get('PORT', 7860))
59
  socketio.run(app, debug=True, host='0.0.0.0', port=port)
 
7
  app = Flask(__name__)
8
  app.config['SECRET_KEY'] = 'your-secret-key' # Replace with a secure key
9
 
10
+ # Configure SocketIO with eventlet for WebSocket support and specific CORS origin
11
  socketio = SocketIO(app,
12
  cors_allowed_origins="https://broadfield-dev-dungeon-game.hf.space", # Your Spaces URL
13
+ async_mode='eventlet') # Use eventlet for WebSocket support
14
 
15
  # Store game instances per client session
16
  games = {}
17
 
 
 
18
  @app.route('/')
19
  def index():
20
  session['sid'] = str(uuid.uuid4()) # Unique session ID for each client
 
24
  def handle_connect(auth=None):
25
  sid = session.get('sid')
26
  games[sid] = Game()
27
+ game_state = games[sid].get_game_state()
28
+ print(f"Emitting update_game for SID {sid}:", game_state) # Debug log
29
+ emit('update_game', game_state)
30
  emit('message', 'Connected to the dungeon! Use arrow keys to move.')
31
 
32
  @socketio.on('move')
 
55
  del games[sid]
56
 
57
  if __name__ == '__main__':
58
+ print("Starting server on port", os.environ.get('PORT', 7860)) # Debug log
59
  port = int(os.environ.get('PORT', 7860))
60
  socketio.run(app, debug=True, host='0.0.0.0', port=port)