remove rpc, cli start
This commit is contained in:
131
src/main.rs
131
src/main.rs
@ -6,11 +6,10 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/29 21:22:17 by tomoron #+# #+# */
|
||||
/* Updated: 2026/05/31 15:02:01 by tomoron ### ########.fr */
|
||||
/* Updated: 2026/06/04 12:37:14 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::io;
|
||||
//use bollard::{
|
||||
// query_parameters::{
|
||||
@ -24,21 +23,13 @@ use tokio::io;
|
||||
// Docker
|
||||
//};
|
||||
|
||||
|
||||
|
||||
mod minecraft;
|
||||
use minecraft::process_mc_socket;
|
||||
|
||||
mod rpc;
|
||||
use rpc::process_rpc_socket;
|
||||
|
||||
use minecraft::mc_socket_listen;
|
||||
|
||||
use diesel::{prelude::*, r2d2::{ConnectionManager, Pool}};
|
||||
|
||||
//mod models;
|
||||
|
||||
//use dockermcmgr::schema;
|
||||
|
||||
//use crate::models::{ Servers, CreateServer };
|
||||
|
||||
use std::env;
|
||||
|
||||
pub mod schema;
|
||||
@ -46,8 +37,9 @@ pub mod models;
|
||||
|
||||
pub mod status;
|
||||
|
||||
use status::ServerStatus;
|
||||
use crate::models::Servers;
|
||||
mod cli;
|
||||
|
||||
use cli::*;
|
||||
|
||||
|
||||
pub type DbPool = Pool<ConnectionManager<PgConnection>>;
|
||||
@ -61,69 +53,70 @@ fn get_connection_pool() -> DbPool {
|
||||
.unwrap_or_else(|_| panic!("Error creating pool for {}", database_url))
|
||||
}
|
||||
|
||||
|
||||
use clap::{Command, arg};
|
||||
|
||||
|
||||
fn cli() -> Command {
|
||||
Command::new("dmm")
|
||||
.about("Docker Minecraft server Manager cli")
|
||||
.subcommand_required(true)
|
||||
.arg_required_else_help(true)
|
||||
.subcommand(
|
||||
Command::new("serverMode")
|
||||
.about("start the server manager")
|
||||
|
||||
)
|
||||
.subcommand(add::create_subcommand())
|
||||
.subcommand(remove::create_subcommand())
|
||||
.subcommand(edit::create_subcommand())
|
||||
.subcommand(ls::create_subcommand())
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> io::Result<()> {
|
||||
|
||||
let arg = cli().get_matches();
|
||||
let pool = get_connection_pool();
|
||||
|
||||
let mc_listener = TcpListener::bind("0.0.0.0:25565").await?;
|
||||
let rpc_listener = TcpListener::bind("0.0.0.0:8080").await?;
|
||||
|
||||
// let servers = schema::servers::table.select(Servers::as_select()).load(conn).unwrap();
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
Ok((socket, _)) = mc_listener.accept() => {
|
||||
let cloned = pool.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = process_mc_socket(socket, cloned).await {
|
||||
eprintln!("mc error: {:?}", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok((socket, _)) = rpc_listener.accept() => {
|
||||
let cloned = pool.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = process_rpc_socket(socket, cloned).await {
|
||||
eprintln!("rpc error: {:?}", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
match arg.subcommand() {
|
||||
Some(("serverMode", _)) => { mc_socket_listen(pool).await?; },
|
||||
Some(("add", sub_matches)) => { add::subcommand(sub_matches); },
|
||||
_ => {panic!("subcommand not implemented")}
|
||||
}
|
||||
/*
|
||||
|
||||
let conn = &mut pool.get().unwrap();
|
||||
//
|
||||
|
||||
|
||||
let new_server = CreateServer {
|
||||
name: "potato",
|
||||
volume_path: "potato2",
|
||||
last_login: None,
|
||||
container_id: None,
|
||||
status: ServerStatus::Stopped,
|
||||
redirect_ip: None
|
||||
};
|
||||
|
||||
match diesel::insert_into(schema::servers::table)
|
||||
.values(&new_server)
|
||||
.execute(conn) {
|
||||
Ok(a) => { println!("{:?}", a); },
|
||||
Err(reason) => {println!("got an error : {:?}", reason) }
|
||||
}
|
||||
|
||||
let start = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
let servers = schema::servers::table.select(Servers::as_select()).load(conn).unwrap();
|
||||
let end = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
println!("servers : {:?}", servers);
|
||||
println!("retreived in {:?}", end - start);
|
||||
|
||||
|
||||
println!("server id : {}",servers[0].id);
|
||||
|
||||
Ok(())
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
println!("{:?}", docker);
|
||||
let options = ListImagesOptionsBuilder::default()
|
||||
@ -155,4 +148,4 @@ async fn main() -> io::Result<()> {
|
||||
*/
|
||||
/*
|
||||
*/
|
||||
}
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user