Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -408,17 +408,14 @@ async def join_game(request: Request):
|
|
| 408 |
if not game:
|
| 409 |
raise HTTPException(status_code=404, detail="Game not found.")
|
| 410 |
|
| 411 |
-
|
| 412 |
-
formatted_name = player_name.title()
|
| 413 |
-
logging.info(f"Original name: {player_name}, Formatted name: {formatted_name}")
|
| 414 |
|
| 415 |
-
# Prevent duplicate player names (case-insensitive).
|
| 416 |
existing_names = [name.lower() for name in game["permissions"].keys()]
|
| 417 |
if formatted_name.lower() in existing_names:
|
| 418 |
raise HTTPException(status_code=400, detail="Player name already taken.")
|
| 419 |
|
| 420 |
game["players"].append(formatted_name)
|
| 421 |
-
|
| 422 |
game["permissions"][formatted_name] = {"steal": True, "gain": True}
|
| 423 |
|
| 424 |
return {"success": True, "message": "Player joined successfully!"}
|
|
@@ -482,4 +479,19 @@ def check_game_status(game):
|
|
| 482 |
else:
|
| 483 |
if name in game.get("permissions", {}):
|
| 484 |
game["permissions"][name].pop("mustCoup", None)
|
| 485 |
-
return game
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
if not game:
|
| 409 |
raise HTTPException(status_code=404, detail="Game not found.")
|
| 410 |
|
| 411 |
+
formatted_name = capitalize_name(player_name)
|
|
|
|
|
|
|
| 412 |
|
|
|
|
| 413 |
existing_names = [name.lower() for name in game["permissions"].keys()]
|
| 414 |
if formatted_name.lower() in existing_names:
|
| 415 |
raise HTTPException(status_code=400, detail="Player name already taken.")
|
| 416 |
|
| 417 |
game["players"].append(formatted_name)
|
| 418 |
+
|
| 419 |
game["permissions"][formatted_name] = {"steal": True, "gain": True}
|
| 420 |
|
| 421 |
return {"success": True, "message": "Player joined successfully!"}
|
|
|
|
| 479 |
else:
|
| 480 |
if name in game.get("permissions", {}):
|
| 481 |
game["permissions"][name].pop("mustCoup", None)
|
| 482 |
+
return game
|
| 483 |
+
|
| 484 |
+
def capitalize_name(name):
|
| 485 |
+
result = ""
|
| 486 |
+
capitalize_next = True # Capitalize first letter
|
| 487 |
+
|
| 488 |
+
for char in name:
|
| 489 |
+
if capitalize_next and char.isalpha():
|
| 490 |
+
result += char.upper()
|
| 491 |
+
capitalize_next = False
|
| 492 |
+
else:
|
| 493 |
+
result += char
|
| 494 |
+
if char == " ":
|
| 495 |
+
capitalize_next = True
|
| 496 |
+
|
| 497 |
+
return result
|