maybe scrapped Server/ServerList

This commit is contained in:
2026-05-28 15:31:07 +02:00
parent 8a397d2b6e
commit 0cab69da71
7 changed files with 140 additions and 5 deletions

6
src/lib.rs Normal file
View File

@ -0,0 +1,6 @@
use bollard::Docker;
use std::sync::LazyLock;
pub static mut DOCKER: LazyLock<Docker> = LazyLock::new(|| Docker::connect_with_local_defaults().expect("Failed to connect to the docker socket") );
pub static mut DB_CONN: LazyLock<

View File

@ -1,14 +1,62 @@
use tokio::net::TcpListener;
//use tokio::net::TcpListener;
use std::io;
mod minecraft;
use minecraft::process_mc_socket;
//mod minecraft;
//use minecraft::process_mc_socket;
//mod rpc;
//use rpc::process_rpc_socket;
//
pub mod server;
use async_std::sync::{Mutex, Arc};
use server::Server;
use server::ServerStatus;
mod serverList;
mod rpc;
use rpc::process_rpc_socket;
#[tokio::main(flavor = "current_thread")]
async fn main() -> io::Result<()> {
Ok(())
/*
println!("{:?}", docker);
let options = ListImagesOptionsBuilder::default()
.all(true)
.build();
let images = &docker.list_images(Some(options)).await.unwrap();
println!("\n\nimages : {:?}", images);
let options = ListContainersOptionsBuilder::default()
.all(true)
.build();
let containers = docker.list_containers(Some(options)).await.unwrap();
println!("\n\ncontainers : {:?}", containers);
let options = CreateContainerOptionsBuilder::default()
.name("rust-created-container")
.build();
let config = ContainerCreateBody {
image: Some("hello-world".to_string()),
// cmd: Some(vc pec!["/hello".to_string()]),
..Default::default()
};
let container = docker.create_container(Some(options), config).await.unwrap();
let start_res = docker.start_container("rust-created-container", None).await;
*/
// let docker_conn = bollard::Docker::connect_with_local_defaults().expect("Failed to connect to the docker socket");
// *crate::server::DOCKER.lock().unwrap() = Some(docker_conn);
// let srv = Server { container_name: "something".to_string(), server_name: "potato".to_string(), server_id: 1, status: ServerStatus::Running };
// srv.start();
//
// Ok(())
/*
let mc_listener = TcpListener::bind("0.0.0.0:25565").await?;
let rpc_listener = TcpListener::bind("0.0.0.0:8080").await?;
@ -31,4 +79,5 @@ async fn main() -> io::Result<()> {
}
}
}
*/
}

6
src/server/mod.rs Normal file
View File

@ -0,0 +1,6 @@
mod server;
pub use server::Server;
mod status;
pub use status::ServerStatus;

48
src/server/server.rs Normal file
View File

@ -0,0 +1,48 @@
use bollard::{
query_parameters::{
ListImagesOptionsBuilder,
ListContainersOptionsBuilder,
CreateContainerOptionsBuilder
},
models::{
ContainerCreateBody
},
Docker
};
use crate::server::ServerStatus;
#[derive(Debug, Clone)]
pub struct Server {
pub container_name: String,
pub server_name: String,
pub server_id: u64,
pub status: ServerStatus,
pub docker: Docker
}
impl Server {
pub async fn new(name: String, id: u64) -> Self {
let docker = Docker::connect_with_local_defaults().expect("Failed to connect to the docker socket");
Self {
container_name: "idk".to_string(),
server_name: name,
server_id: id,
status: ServerStatus::Stopped,
docker
}
}
pub async fn start(&self) -> Result<(), String> {
let options = ListImagesOptionsBuilder::default()
.all(true)
.build();
let images = self.docker.list_images(Some(options)).await.unwrap();
println!("\n\nimages : {:?}", images);
Ok(())
}
}

7
src/server/status.rs Normal file
View File

@ -0,0 +1,7 @@
#[derive(Debug, Clone)]
pub enum ServerStatus {
Running,
Starting,
Stopped,
Archived
}

2
src/serverList/mod.rs Normal file
View File

@ -0,0 +1,2 @@
mod serverList;
pub use serverList::*;

View File

@ -0,0 +1,17 @@
use crate::server::Server;
use async_std::sync::{Mutex, Arc};
use std::sync::LazyLock;
use std::collections::HashMap;
pub static SERVER_LIST: LazyLock<Mutex<HashMap<u64, Arc<Mutex<Server>>>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
pub async fn get(id: u64) -> Option<Arc<Mutex<Server>>> {
let server_list = SERVER_LIST.lock().await;
match server_list.get(&id) {
Some(found) => { Some(found.clone()) },
None => { None }
}
}
// (*SERVER_LIST.lock().await).push(Arc::new(Mutex::new(Server::new("test".to_string(), 1u64).await)));