idle/web/server.php
2025-12-11 18:03:25 +08:00

55 lines
1.6 KiB
PHP

<?php
/**
* Web 游戏服务器入口
* 使用方法: php -S 0.0.0.0:8080 web/server.php
*/
// 自动加载
require_once __DIR__ . '/../vendor/autoload.php';
// 设置响应头
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
// 处理 OPTIONS 预检请求
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
// 获取请求路径
$requestUri = $_SERVER['REQUEST_URI'];
$path = parse_url($requestUri, PHP_URL_PATH);
// 静态文件处理
if ($path === '/' || $path === '/process.html') {
header('Content-Type: text/html; charset=utf-8');
echo '<!DOCTYPE html>
<html>
<head>
<title>凡人修仙传 - Web Terminal Edition</title>
<style>
body { font-family: monospace; background: #000; color: #0f0; margin: 0; padding: 20px; }
#game { height: 600px; overflow-y: auto; border: 1px solid #0f0; padding: 10px; margin-bottom: 10px; }
input { background: #000; color: #0f0; border: 1px solid #0f0; padding: 5px; width: 100%; box-sizing: border-box; }
</style>
</head>
<body>
<div id="game">游戏初始化中...</div>
<input type="text" id="input" placeholder="输入命令..." autofocus>
<script>
console.log("Web game interface loaded");
</script>
</body>
</html>';
exit;
}
// API 路由
$response = ['success' => true, 'message' => 'Web server is running. This is a CLI-based game.'];
http_response_code(200);
echo json_encode($response, JSON_UNESCAPED_UNICODE);