remove rpc, cli start
This commit is contained in:
102
Cargo.lock
generated
102
Cargo.lock
generated
@ -20,6 +20,56 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"once_cell_polyfill",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-channel"
|
name = "async-channel"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
@ -260,6 +310,39 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@ -382,6 +465,7 @@ dependencies = [
|
|||||||
"async-std",
|
"async-std",
|
||||||
"bollard",
|
"bollard",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"clap",
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-enum",
|
"diesel-enum",
|
||||||
"json",
|
"json",
|
||||||
@ -830,6 +914,12 @@ dependencies = [
|
|||||||
"icu_properties",
|
"icu_properties",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
@ -931,6 +1021,12 @@ version = "1.21.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking"
|
name = "parking"
|
||||||
version = "2.2.1"
|
version = "2.2.1"
|
||||||
@ -1410,6 +1506,12 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "value-bag"
|
name = "value-bag"
|
||||||
version = "1.12.0"
|
version = "1.12.0"
|
||||||
|
|||||||
@ -7,6 +7,7 @@ edition = "2024"
|
|||||||
async-std = "1.13.2"
|
async-std = "1.13.2"
|
||||||
bollard = "0.21.0"
|
bollard = "0.21.0"
|
||||||
chrono = "0.4.44"
|
chrono = "0.4.44"
|
||||||
|
clap = "4.6.1"
|
||||||
diesel = { version = "2.3.9", features = ["postgres", "r2d2"] }
|
diesel = { version = "2.3.9", features = ["postgres", "r2d2"] }
|
||||||
diesel-enum = "0.2.1"
|
diesel-enum = "0.2.1"
|
||||||
json = "0.12.4"
|
json = "0.12.4"
|
||||||
|
|||||||
12
src/cli/add.rs
Normal file
12
src/cli/add.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use clap::{ArgMatches, Command, arg};
|
||||||
|
|
||||||
|
pub fn create_subcommand() -> Command {
|
||||||
|
Command::new("add")
|
||||||
|
.about("add a server")
|
||||||
|
.arg(arg!(<NAME> "Name of the server"))
|
||||||
|
.arg(arg!(-v --version <VERSION> "minecraft version of the server"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn subcommand(arg: &ArgMatches) {
|
||||||
|
println!("got add, sub : {:?}", arg);
|
||||||
|
}
|
||||||
6
src/cli/edit.rs
Normal file
6
src/cli/edit.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
use clap::{Command, arg};
|
||||||
|
|
||||||
|
pub fn create_subcommand() -> Command {
|
||||||
|
Command::new("edit")
|
||||||
|
.about("edit a server")
|
||||||
|
}
|
||||||
6
src/cli/ls.rs
Normal file
6
src/cli/ls.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
use clap::{Command, arg};
|
||||||
|
|
||||||
|
pub fn create_subcommand() -> Command {
|
||||||
|
Command::new("ls")
|
||||||
|
.about("list the servers")
|
||||||
|
}
|
||||||
4
src/cli/mod.rs
Normal file
4
src/cli/mod.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
pub mod add;
|
||||||
|
pub mod edit;
|
||||||
|
pub mod remove;
|
||||||
|
pub mod ls;
|
||||||
6
src/cli/remove.rs
Normal file
6
src/cli/remove.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
use clap::{Command, arg};
|
||||||
|
|
||||||
|
pub fn create_subcommand() -> Command {
|
||||||
|
Command::new("remove")
|
||||||
|
.about("remove a server")
|
||||||
|
}
|
||||||
131
src/main.rs
131
src/main.rs
@ -6,11 +6,10 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/05/29 21:22:17 by tomoron #+# #+# */
|
/* 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 tokio::io;
|
||||||
//use bollard::{
|
//use bollard::{
|
||||||
// query_parameters::{
|
// query_parameters::{
|
||||||
@ -24,21 +23,13 @@ use tokio::io;
|
|||||||
// Docker
|
// Docker
|
||||||
//};
|
//};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mod minecraft;
|
mod minecraft;
|
||||||
use minecraft::process_mc_socket;
|
use minecraft::mc_socket_listen;
|
||||||
|
|
||||||
mod rpc;
|
|
||||||
use rpc::process_rpc_socket;
|
|
||||||
|
|
||||||
|
|
||||||
use diesel::{prelude::*, r2d2::{ConnectionManager, Pool}};
|
use diesel::{prelude::*, r2d2::{ConnectionManager, Pool}};
|
||||||
|
|
||||||
//mod models;
|
|
||||||
|
|
||||||
//use dockermcmgr::schema;
|
|
||||||
|
|
||||||
//use crate::models::{ Servers, CreateServer };
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
@ -46,8 +37,9 @@ pub mod models;
|
|||||||
|
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
|
||||||
use status::ServerStatus;
|
mod cli;
|
||||||
use crate::models::Servers;
|
|
||||||
|
use cli::*;
|
||||||
|
|
||||||
|
|
||||||
pub type DbPool = Pool<ConnectionManager<PgConnection>>;
|
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))
|
.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")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
|
let arg = cli().get_matches();
|
||||||
let pool = get_connection_pool();
|
let pool = get_connection_pool();
|
||||||
|
|
||||||
let mc_listener = TcpListener::bind("0.0.0.0:25565").await?;
|
match arg.subcommand() {
|
||||||
let rpc_listener = TcpListener::bind("0.0.0.0:8080").await?;
|
Some(("serverMode", _)) => { mc_socket_listen(pool).await?; },
|
||||||
|
Some(("add", sub_matches)) => { add::subcommand(sub_matches); },
|
||||||
// let servers = schema::servers::table.select(Servers::as_select()).load(conn).unwrap();
|
_ => {panic!("subcommand not implemented")}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
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(())
|
Ok(())
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
println!("{:?}", docker);
|
println!("{:?}", docker);
|
||||||
let options = ListImagesOptionsBuilder::default()
|
let options = ListImagesOptionsBuilder::default()
|
||||||
@ -155,4 +148,4 @@ async fn main() -> io::Result<()> {
|
|||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -4,4 +4,4 @@ mod client;
|
|||||||
|
|
||||||
mod socket;
|
mod socket;
|
||||||
|
|
||||||
pub use socket::process_mc_socket;
|
pub use socket::mc_socket_listen;
|
||||||
|
|||||||
@ -3,7 +3,25 @@ use tokio::net::TcpStream;
|
|||||||
|
|
||||||
use crate::DbPool;
|
use crate::DbPool;
|
||||||
|
|
||||||
pub async fn process_mc_socket(stream: TcpStream, pool: DbPool) -> Result<(), String> {
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
pub async fn mc_socket_listen(pool: DbPool) -> io::Result<()> {
|
||||||
|
let mc_listener = TcpListener::bind("0.0.0.0:25565").await?;
|
||||||
|
loop {
|
||||||
|
if let Ok((socket, _)) = mc_listener.accept().await {
|
||||||
|
let cloned = pool.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = process_mc_socket(socket, cloned).await {
|
||||||
|
eprintln!("mc error: {:?}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn process_mc_socket(stream: TcpStream, pool: DbPool) -> Result<(), String> {
|
||||||
println!("new client {:?}", stream);
|
println!("new client {:?}", stream);
|
||||||
|
|
||||||
let mut client = Client::create(stream, pool);
|
let mut client = Client::create(stream, pool);
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
mod ping;
|
|
||||||
//pub use ping::ping;
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
//pub fn ping(data: json::object) -> json::object {
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
mod socket;
|
|
||||||
|
|
||||||
pub use socket::process_rpc_socket;
|
|
||||||
|
|
||||||
pub mod actions;
|
|
||||||
pub mod rpc_client;
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
pub struct RpcClient{
|
|
||||||
pub read_buffer: Vec<u8>,
|
|
||||||
pub buffer: Vec<u8>,
|
|
||||||
|
|
||||||
pub close: bool
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RpcClient {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
read_buffer: vec![0; 1024],
|
|
||||||
buffer: vec![0; 10240],
|
|
||||||
|
|
||||||
close: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
use std::io;
|
|
||||||
use tokio::net::TcpStream;
|
|
||||||
|
|
||||||
use crate::DbPool;
|
|
||||||
|
|
||||||
use crate::rpc::rpc_client::RpcClient;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* request_format :
|
|
||||||
* - "action" : 1 byte
|
|
||||||
* - length : 4 bytes (no more than 1MB)
|
|
||||||
* - json object : `length` bytes
|
|
||||||
* containing the parameters for this specific action (will vary
|
|
||||||
* depending on the action)
|
|
||||||
*
|
|
||||||
* response format :
|
|
||||||
* - response packet : may be more than one depending on the action
|
|
||||||
* - length: 4 bytes (no more than 1MB)
|
|
||||||
* - data: json object containing the response data
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub async fn process_rpc_socket(_stream: TcpStream, _pool: DbPool) -> io::Result<()> {
|
|
||||||
let client = RpcClient::new();
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user