removing bad webserver
This commit is contained in:
@@ -11,58 +11,5 @@ fn main() {
|
||||
|
||||
let game_state = Arc::new(Mutex::new(GameState::default()));
|
||||
|
||||
// Start the webserver in a separate thread
|
||||
std::thread::spawn(|| {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
start_webserver().await;
|
||||
// Keep the runtime alive indefinitely to prevent TLS cleanup issues
|
||||
std::future::pending::<()>().await;
|
||||
});
|
||||
});
|
||||
|
||||
rsbwapi::start(move |_game| ProtosBot::new(game_state.clone()));
|
||||
}
|
||||
|
||||
async fn start_webserver() {
|
||||
use axum::Router;
|
||||
use leptos::*;
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
use protoss_bot_web::App;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
let leptos_options = LeptosOptions {
|
||||
output_name: "protoss-bot-web".to_string(),
|
||||
site_root: "target/site".to_string(),
|
||||
site_pkg_dir: "pkg".to_string(),
|
||||
env: leptos_config::Env::DEV,
|
||||
site_addr: "127.0.0.1:3333".parse().unwrap(),
|
||||
reload_port: 3001,
|
||||
hash_file: "".to_string(),
|
||||
hash_files: false,
|
||||
..Default::default()
|
||||
};
|
||||
let addr = leptos_options.site_addr;
|
||||
let routes = generate_route_list(App);
|
||||
|
||||
let app = Router::new()
|
||||
.leptos_routes(&leptos_options, routes, App)
|
||||
.nest_service("/pkg", ServeDir::new("web/style"))
|
||||
.with_state(leptos_options);
|
||||
|
||||
match tokio::net::TcpListener::bind(&addr).await {
|
||||
Ok(listener) => {
|
||||
println!("Web server listening on http://{}", &addr);
|
||||
if let Err(e) = axum::serve(listener, app.into_make_service()).await {
|
||||
eprintln!("Web server error: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"Failed to bind to {}: {}. Is the port already in use?",
|
||||
&addr, e
|
||||
);
|
||||
eprintln!("Skipping web server startup.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
[package]
|
||||
name = "protoss-bot-web"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
leptos = { version = "0.6", default-features = false, features = ["ssr"] }
|
||||
leptos_axum = { version = "0.6", default-features = false }
|
||||
leptos_meta = { version = "0.6", default-features = false, features = ["ssr"] }
|
||||
leptos_router = { version = "0.6", default-features = false, features = ["ssr"] }
|
||||
axum = "0.7"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tower = "0.4"
|
||||
tower-http = { version = "0.5", features = ["fs"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
lazy_static = "1.4"
|
||||
|
||||
[features]
|
||||
default = ["ssr"]
|
||||
ssr = ["leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
@@ -1,20 +0,0 @@
|
||||
# Leptos configuration file
|
||||
[package]
|
||||
name = "protoss-bot-web"
|
||||
version = "0.1.0"
|
||||
|
||||
[leptos]
|
||||
output-name = "protoss-bot-web"
|
||||
site-root = "target/site"
|
||||
site-pkg-dir = "pkg"
|
||||
style-file = "style/main.css"
|
||||
assets-dir = "public"
|
||||
site-addr = "127.0.0.1:3001"
|
||||
reload-port = 3001
|
||||
browserquery = "defaults"
|
||||
watch = false
|
||||
env = "DEV"
|
||||
bin-features = ["ssr"]
|
||||
bin-default-features = false
|
||||
lib-features = ["hydrate"]
|
||||
lib-default-features = false
|
||||
@@ -1,32 +0,0 @@
|
||||
# Protoss Bot Web Control Panel
|
||||
|
||||
A Leptos web interface to control the Protoss bot in real-time.
|
||||
|
||||
## Setup
|
||||
|
||||
1. Install cargo-leptos:
|
||||
```bash
|
||||
cargo install cargo-leptos
|
||||
```
|
||||
|
||||
2. Run the development server:
|
||||
```bash
|
||||
cd web
|
||||
cargo leptos watch
|
||||
```
|
||||
|
||||
3. Open your browser to `http://localhost:3000`
|
||||
|
||||
## Features
|
||||
|
||||
- **Game Speed Control**: Set the desired game speed with convenient buttons
|
||||
- Real-time updates via server functions
|
||||
- Dark theme matching StarCraft aesthetics
|
||||
|
||||
## Integration with Bot
|
||||
|
||||
The web server exposes a global `GAME_SPEED` variable that can be read by the bot. To integrate:
|
||||
|
||||
1. Add the web crate as a dependency in your bot's `Cargo.toml`
|
||||
2. Read the speed value: `protoss_bot_web::GAME_SPEED.read().unwrap()`
|
||||
3. Apply it to the game using BWAPI's setLocalSpeed() or setFrameSkip()
|
||||
@@ -1,82 +0,0 @@
|
||||
use leptos::*;
|
||||
use leptos_meta::*;
|
||||
use leptos_router::*;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
// Global static for game speed (shared with the bot)
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref GAME_SPEED: Arc<RwLock<i32>> = Arc::new(RwLock::new(20));
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
provide_meta_context();
|
||||
|
||||
view! {
|
||||
<Stylesheet id="leptos" href="/pkg/main.css"/>
|
||||
<Title text="Protoss Bot Control"/>
|
||||
<Router>
|
||||
<main>
|
||||
<Routes>
|
||||
<Route path="" view=HomePage/>
|
||||
</Routes>
|
||||
</main>
|
||||
</Router>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn HomePage() -> impl IntoView {
|
||||
let (game_speed, set_game_speed) = create_signal(0);
|
||||
|
||||
let set_speed = create_action(move |speed: &i32| {
|
||||
let speed = *speed;
|
||||
async move {
|
||||
set_game_speed.set(speed);
|
||||
let _ = set_game_speed_server(speed).await;
|
||||
}
|
||||
});
|
||||
|
||||
view! {
|
||||
<div class="container">
|
||||
<h1>"Protoss Bot Control Panel"</h1>
|
||||
|
||||
<div class="speed-control">
|
||||
<h2>"Game Speed Control"</h2>
|
||||
<p>"Current Speed: " {game_speed}</p>
|
||||
|
||||
<div class="button-group">
|
||||
<button
|
||||
class:selected=move || game_speed.get() == -1
|
||||
on:click=move |_| set_speed.dispatch(-1)>
|
||||
"Fastest (-1)"
|
||||
</button>
|
||||
<button
|
||||
class:selected=move || game_speed.get() == 0
|
||||
on:click=move |_| set_speed.dispatch(0)>
|
||||
"Fast (0)"
|
||||
</button>
|
||||
<button
|
||||
class:selected=move || game_speed.get() == 1
|
||||
on:click=move |_| set_speed.dispatch(1)>
|
||||
"Normal (1)"
|
||||
</button>
|
||||
<button
|
||||
class:selected=move || game_speed.get() == 42
|
||||
on:click=move |_| set_speed.dispatch(42)>
|
||||
"Slowest (42)"
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[server(SetGameSpeed, "/api")]
|
||||
pub async fn set_game_speed_server(speed: i32) -> Result<(), ServerFnError> {
|
||||
if let Ok(mut game_speed) = GAME_SPEED.write() {
|
||||
*game_speed = speed;
|
||||
println!("Game speed set to: {}", speed);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
use axum::{
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
use leptos::*;
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
use protoss_bot_web::App;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let conf = get_configuration(None).await.unwrap();
|
||||
let leptos_options = conf.leptos_options;
|
||||
let addr = leptos_options.site_addr;
|
||||
let routes = generate_route_list(App);
|
||||
|
||||
let app = Router::new()
|
||||
.leptos_routes(&leptos_options, routes, App)
|
||||
.fallback(leptos_axum::file_and_error_handler(App))
|
||||
.with_state(leptos_options);
|
||||
|
||||
println!("Listening on http://{}", &addr);
|
||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||
axum::serve(listener, app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
body {
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
|
||||
Cantarell, sans-serif;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background-color: #1a1a1a;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #4a9eff;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #ffffff;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.speed-control {
|
||||
background-color: #2a2a2a;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #4a9eff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #357abd;
|
||||
}
|
||||
|
||||
button:active {
|
||||
background-color: #2a5f9a;
|
||||
}
|
||||
|
||||
button.selected {
|
||||
background-color: #28a745;
|
||||
box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
button.selected:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #cccccc;
|
||||
margin: 10px 0;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// Dummy module for SSR-only mode
|
||||
export default function () {
|
||||
console.log("SSR-only mode - no client-side hydration");
|
||||
return Promise.resolve({});
|
||||
}
|
||||
Reference in New Issue
Block a user