start switch to sqlite
This commit is contained in:
86
Cargo.lock
generated
86
Cargo.lock
generated
@ -302,12 +302,6 @@ version = "3.20.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
|
checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "byteorder"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.11.1"
|
version = "1.11.1"
|
||||||
@ -534,13 +528,13 @@ version = "2.3.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9940fb8467a0a06312218ed384185cb8536aa10d8ec017d0ce7fad2c1bd882d5"
|
checksum = "9940fb8467a0a06312218ed384185cb8536aa10d8ec017d0ce7fad2c1bd882d5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"chrono",
|
||||||
"byteorder",
|
|
||||||
"diesel_derives",
|
"diesel_derives",
|
||||||
"downcast-rs",
|
"downcast-rs",
|
||||||
"itoa",
|
"libsqlite3-sys",
|
||||||
"pq-sys",
|
|
||||||
"r2d2",
|
"r2d2",
|
||||||
|
"sqlite-wasm-rs",
|
||||||
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -721,6 +715,12 @@ version = "0.1.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foldhash"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "form_urlencoded"
|
name = "form_urlencoded"
|
||||||
version = "1.2.2"
|
version = "1.2.2"
|
||||||
@ -845,7 +845,16 @@ version = "0.15.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"foldhash",
|
"foldhash 0.1.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.16.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
||||||
|
dependencies = [
|
||||||
|
"foldhash 0.2.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1233,6 +1242,16 @@ version = "0.2.186"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libsqlite3-sys"
|
||||||
|
version = "0.37.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1f111c8c41e7c61a49cd34e44c7619462967221a6443b0ec299e0ac30cfb9b1"
|
||||||
|
dependencies = [
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@ -1435,17 +1454,6 @@ version = "1.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24"
|
checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pq-sys"
|
|
||||||
version = "0.7.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "574ddd6a267294433f140b02a726b0640c43cf7c6f717084684aaa3b285aba61"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"pkg-config",
|
|
||||||
"vcpkg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prettyplease"
|
name = "prettyplease"
|
||||||
version = "0.2.37"
|
version = "0.2.37"
|
||||||
@ -1535,6 +1543,16 @@ version = "0.8.10"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rsqlite-vfs"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c51c9ae4df8a7fba42103df5c621fa3c37eccf3a3c650879e90fc48b11cc192c"
|
||||||
|
dependencies = [
|
||||||
|
"hashbrown 0.16.1",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "1.1.4"
|
version = "1.1.4"
|
||||||
@ -1713,6 +1731,18 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sqlite-wasm-rs"
|
||||||
|
version = "0.5.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc3efc0da82635d7e1ced0053bbbfa8c7ab9645d0bf36ceb4f7127bb85315d75"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"js-sys",
|
||||||
|
"rsqlite-vfs",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stable_deref_trait"
|
name = "stable_deref_trait"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@ -1785,11 +1815,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"
|
checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deranged",
|
"deranged",
|
||||||
|
"itoa",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"num-conv",
|
"num-conv",
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
"serde_core",
|
"serde_core",
|
||||||
"time-core",
|
"time-core",
|
||||||
|
"time-macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1798,6 +1830,16 @@ version = "0.1.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca"
|
checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-macros"
|
||||||
|
version = "0.2.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215"
|
||||||
|
dependencies = [
|
||||||
|
"num-conv",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinystr"
|
name = "tinystr"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
|
|||||||
@ -8,7 +8,7 @@ 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"
|
clap = "4.6.1"
|
||||||
diesel = { version = "2.3.9", features = ["postgres", "r2d2"] }
|
diesel = { version = "2.3.9", features = ["sqlite", "r2d2", "chrono"] }
|
||||||
diesel-enum = "0.2.1"
|
diesel-enum = "0.2.1"
|
||||||
json = "0.12.4"
|
json = "0.12.4"
|
||||||
regex = "1.12.3"
|
regex = "1.12.3"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use clap::{ Arg, ArgAction, ArgMatches, parser::ValueSource};
|
use clap::{ Arg, ArgMatches, parser::ValueSource};
|
||||||
|
|
||||||
pub fn get_args() -> [Arg; 21] {
|
pub fn get_args() -> [Arg; 21] {
|
||||||
[
|
[
|
||||||
|
|||||||
2
src/docker/mod.rs
Normal file
2
src/docker/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
mod start;
|
||||||
|
pub use start::start_server;
|
||||||
3
src/docker/start.rs
Normal file
3
src/docker/start.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub async fn start_server() -> Result<String, String> {
|
||||||
|
Ok("".to_string())
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* 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/06/06 15:37:52 by tomoron ### ########.fr */
|
/* Updated: 2026/06/06 18:18:03 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,18 +22,20 @@ pub mod models;
|
|||||||
|
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
|
||||||
|
pub mod docker;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
use cli::*;
|
use cli::*;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
pub use config::Config;
|
pub use config::Config;
|
||||||
|
|
||||||
pub type DbPool = Pool<ConnectionManager<PgConnection>>;
|
pub type DbPool = Pool<ConnectionManager<SqliteConnection>>;
|
||||||
|
|
||||||
fn get_connection_pool() -> DbPool {
|
fn get_connection_pool() -> DbPool {
|
||||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||||
|
|
||||||
let manager = ConnectionManager::<PgConnection>::new(&database_url);
|
let manager = ConnectionManager::<SqliteConnection>::new(&database_url);
|
||||||
Pool::builder()
|
Pool::builder()
|
||||||
.build(manager)
|
.build(manager)
|
||||||
.unwrap_or_else(|_| panic!("Error creating pool for {}", database_url))
|
.unwrap_or_else(|_| panic!("Error creating pool for {}", database_url))
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use json::object;
|
|||||||
use crate::minecraft::varint::varint_write;
|
use crate::minecraft::varint::varint_write;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
pub async fn status_intent_handle(&self, packet: &mut VecDeque<u8>, packet_id: i32) -> Result<(),String> {
|
pub async fn status_intent_handle(&self, packet: &mut VecDeque<u8>, packet_id: i32) -> Result<(),String> {
|
||||||
@ -53,7 +53,7 @@ impl Client {
|
|||||||
Ok(server) => {
|
Ok(server) => {
|
||||||
let login = match server.last_login {
|
let login = match server.last_login {
|
||||||
Some(date) => {
|
Some(date) => {
|
||||||
let datetime: DateTime<Utc> = date.into();
|
let datetime: DateTime<Utc> = Utc.from_utc_datetime(&date);
|
||||||
|
|
||||||
format!("{}", datetime.format("%d-%m-%Y at %H:%M").to_string())
|
format!("{}", datetime.format("%d-%m-%Y at %H:%M").to_string())
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@ -12,11 +12,11 @@ use crate::schema;
|
|||||||
|
|
||||||
#[derive(Queryable, Selectable, Debug)]
|
#[derive(Queryable, Selectable, Debug)]
|
||||||
#[diesel(table_name = schema::servers)]
|
#[diesel(table_name = schema::servers)]
|
||||||
#[diesel(check_for_backend(diesel::pg::Pg))]
|
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||||
pub struct Servers {
|
pub struct Servers {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub last_login: Option<SystemTime>,
|
pub last_login: Option<NaiveDateTime>,
|
||||||
pub container_id: Option<String>,
|
pub container_id: Option<String>,
|
||||||
pub status: ServerStatus,
|
pub status: ServerStatus,
|
||||||
pub redirect_ip: Option<String>
|
pub redirect_ip: Option<String>
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
use diesel::deserialize::{self, FromSql, FromSqlRow};
|
use diesel::deserialize::{self, FromSql, FromSqlRow};
|
||||||
use diesel::pg::PgValue;
|
use diesel::sqlite::Sqlite;
|
||||||
use diesel::expression::AsExpression;
|
|
||||||
use diesel::pg::Pg;
|
|
||||||
use diesel::serialize::{self, ToSql, Output};
|
use diesel::serialize::{self, ToSql, Output};
|
||||||
use diesel::sql_types::SmallInt;
|
use diesel::sql_types::SmallInt;
|
||||||
|
use diesel::expression::AsExpression;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, AsExpression, FromSqlRow, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, AsExpression, FromSqlRow, serde::Serialize, serde::Deserialize)]
|
||||||
#[diesel(sql_type = SmallInt)]
|
#[diesel(sql_type = SmallInt)]
|
||||||
pub enum ServerStatus {
|
pub enum ServerStatus {
|
||||||
@ -17,24 +13,19 @@ pub enum ServerStatus {
|
|||||||
Stopping = 2,
|
Stopping = 2,
|
||||||
Starting = 3,
|
Starting = 3,
|
||||||
Running = 4,
|
Running = 4,
|
||||||
Unknown = 5
|
Unknown = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToSql<SmallInt, Pg> for ServerStatus {
|
impl ToSql<SmallInt, Sqlite> for ServerStatus {
|
||||||
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
|
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Sqlite>) -> serialize::Result {
|
||||||
let val = *self as i16;
|
let val = *self as i16;
|
||||||
out.write_all(&val.to_be_bytes())?;
|
<i16 as ToSql<SmallInt, Sqlite>>::to_sql(&val, out)
|
||||||
Ok(serialize::IsNull::No)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromSql<SmallInt, Pg> for ServerStatus {
|
impl FromSql<SmallInt, Sqlite> for ServerStatus {
|
||||||
fn from_sql(value: PgValue<'_>) -> deserialize::Result<Self> {
|
fn from_sql(value: diesel::sqlite::SqliteValue<'_, '_, '_>) -> deserialize::Result<Self> {
|
||||||
let bytes = value.as_bytes();
|
let val = value.as_i64() as i16;
|
||||||
if bytes.len() != 2 {
|
|
||||||
return Err("Invalid length for i16".into());
|
|
||||||
}
|
|
||||||
let val = i16::from_be_bytes([bytes[0], bytes[1]]);
|
|
||||||
match val {
|
match val {
|
||||||
0 => Ok(ServerStatus::Archived),
|
0 => Ok(ServerStatus::Archived),
|
||||||
1 => Ok(ServerStatus::Stopped),
|
1 => Ok(ServerStatus::Stopped),
|
||||||
@ -49,13 +40,12 @@ impl FromSql<SmallInt, Pg> for ServerStatus {
|
|||||||
impl fmt::Display for ServerStatus {
|
impl fmt::Display for ServerStatus {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let str_status = match self {
|
let str_status = match self {
|
||||||
ServerStatus::Archived => "archieved",
|
ServerStatus::Archived => "archived",
|
||||||
ServerStatus::Stopped => "stopped",
|
ServerStatus::Stopped => "stopped",
|
||||||
ServerStatus::Stopping => "stopping",
|
ServerStatus::Stopping => "stopping",
|
||||||
ServerStatus::Starting => "starting",
|
ServerStatus::Starting => "starting",
|
||||||
ServerStatus::Running => "running",
|
ServerStatus::Running => "running",
|
||||||
ServerStatus::Unknown => "(error : unknown status)"
|
ServerStatus::Unknown => "(error : unknown status)",
|
||||||
|
|
||||||
};
|
};
|
||||||
write!(f, "{}", str_status)
|
write!(f, "{}", str_status)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user