npc0 commited on
Commit
fb3f82e
·
verified ·
1 Parent(s): 889eee2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -912,10 +912,12 @@ def create_ui():
912
  import uuid
913
  room_id = str(uuid.uuid4())[:8].upper()
914
  player_id = str(uuid.uuid4())[:8]
915
-
916
- db.create_room(room_id)
 
 
917
  success, slot, msg = db.join_room(room_id, player_id, your_name, character_id)
918
-
919
  if success:
920
  return {
921
  'room_id': room_id,
@@ -923,7 +925,13 @@ def create_ui():
923
  'player_slot': slot,
924
  'is_spectator': slot is None
925
  }, f"✅ Room created: **{room_id}**\n\n{msg}\n\nShare this Room ID with your partner!"
926
- return {}, f"❌ Failed to create room: {msg}"
 
 
 
 
 
 
927
 
928
  def join_room_handler(room_id, your_name, character_id):
929
  import uuid
 
912
  import uuid
913
  room_id = str(uuid.uuid4())[:8].upper()
914
  player_id = str(uuid.uuid4())[:8]
915
+
916
+ if not db.create_room(room_id):
917
+ return {}, "❌ Failed to create room. Please try again."
918
+
919
  success, slot, msg = db.join_room(room_id, player_id, your_name, character_id)
920
+
921
  if success:
922
  return {
923
  'room_id': room_id,
 
925
  'player_slot': slot,
926
  'is_spectator': slot is None
927
  }, f"✅ Room created: **{room_id}**\n\n{msg}\n\nShare this Room ID with your partner!"
928
+
929
+ # If join fails, we should probably clean up the created room
930
+ with db.get_connection() as conn:
931
+ conn.execute("DELETE FROM rooms WHERE room_id = ?", (room_id,))
932
+ conn.commit()
933
+
934
+ return {}, f"❌ Failed to join room after creation: {msg}"
935
 
936
  def join_room_handler(room_id, your_name, character_id):
937
  import uuid