false, 'error' => 'Room not found or expired.', ], 404); } roomsApiRespond([ 'success' => true, 'updated_at' => gmdate(DATE_ATOM), 'room' => $room, ]); } if ($method !== 'POST') { roomsApiRespond([ 'success' => false, 'error' => 'Method not allowed.', ], 405); } $action = strtolower(trim((string) ($_POST['action'] ?? ''))); if ($action === 'create') { $room = multiplayerCreateRoom((string) ($_POST['player_name'] ?? '')); roomsApiRespond([ 'success' => true, 'message' => 'Room created.', 'updated_at' => gmdate(DATE_ATOM), 'room' => $room, ], 201); } if ($action === 'join') { $room = multiplayerJoinRoom((string) ($_POST['room_code'] ?? ''), (string) ($_POST['player_name'] ?? '')); roomsApiRespond([ 'success' => true, 'message' => 'Joined room.', 'updated_at' => gmdate(DATE_ATOM), 'room' => $room, ]); } roomsApiRespond([ 'success' => false, 'error' => 'Unknown room action.', ], 422); } catch (InvalidArgumentException $e) { roomsApiRespond([ 'success' => false, 'error' => $e->getMessage(), ], 422); } catch (Throwable $e) { roomsApiRespond([ 'success' => false, 'error' => 'Unable to process the room request right now.', ], 500); }