Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev merge to main #3

Closed
wants to merge 15 commits into from
17 changes: 0 additions & 17 deletions .editorconfig

This file was deleted.

24 changes: 15 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ release/
rls/
*.o
.vscode/

perf.data
# Generated by Cargo
# will have compiled files and executables
debug/
Expand Down Expand Up @@ -108,25 +108,31 @@ fabric.properties
.idea/caches/build_file_checksums.ser

.idea/


# different file generated by the server


# World folder
world/*
world/DIM1/
world/DIM-1/
world/region/
# logs folder
# World directories
world/

# Logs directory
logs/


#conf files
# Configuration files
ops.json
whitelist.json
banned-ips.json
banned-players.json
usercache.json
session.lock
version.json
server.properties
*.properties
eula.txt

# macOS files
.DS_Store

# Other
.editorconfig
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tempfile = "3.12.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.127"
reqwest = { version = "0.12.7", features = ["json", "rustls-tls"] }
clap = { version = "4.5.17", features = ["derive"] }
[profile.release]
opt-level = 3 # optimiosation level 3 is the best
debug = false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ Copper is licensed under the Mozilla Public License Version 2.0. See the `LICENS

---

For any questions or comments, feel free to open an issue or contact me directly at the email: [[email protected]](mailto:minecraft.copper@proton.me)
For any questions or comments, feel free to open an issue or contact me directly at the email: [[email protected]](mailto:minecraft.cactus@proton.me)
83 changes: 83 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,86 @@

- [ ] Somehow get a player to connect

# Issues
- [ ] resolve this memory leak
spectre@fedora:~/RustProject/CopperMC$ valgrind --tool=memcheck --leak-check=full ./target/release/copper_server
==20441== Memcheck, a memory error detector
==20441== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==20441== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==20441== Command: ./target/release/copper_server
==20441==
[2024-09-25T07:26:15Z INFO copper_server] Starting minecraft server version 1.21.1
[2024-09-25T07:26:15Z INFO copper_server] Hello, world from Copper!
[2024-09-25T07:26:15Z ERROR copper_server::fs_manager] Cannot start the server, please agree to the 'eula.txt'
[2024-09-25T07:26:15Z WARN copper_server] [ SERVER SHUTDOWN WITH CODE: -1]
==20441==
==20441== HEAP SUMMARY:
==20441== in use at exit: 103,256 bytes in 172 blocks
==20441== total heap usage: 289 allocs, 117 frees, 118,951 bytes allocated
==20441==
==20441== 280 bytes in 1 blocks are possibly lost in loss record 42 of 60
==20441== at 0x4843866: malloc (vg_replace_malloc.c:446)
==20441== by 0x1455A3: hashbrown::raw::RawTable<T,A>::reserve_rehash (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x36DF4B: tokio::runtime::blocking::pool::Spawner::spawn_task (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x363AA8: tokio::runtime::builder::Builder::build (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x16EFF4: copper_server::main (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x17A502: std::sys::backtrace::__rust_begin_short_backtrace (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x16ECAC: main (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441==
==20441== 304 bytes in 1 blocks are possibly lost in loss record 43 of 60
==20441== at 0x484B133: calloc (vg_replace_malloc.c:1675)
==20441== by 0x4011FE3: UnknownInlinedFun (rtld-malloc.h:44)
==20441== by 0x4011FE3: allocate_dtv (dl-tls.c:370)
==20441== by 0x4012A71: _dl_allocate_tls (dl-tls.c:629)
==20441== by 0x4FA2233: allocate_stack (allocatestack.c:429)
==20441== by 0x4FA2233: pthread_create@@GLIBC_2.34 (pthread_create.c:655)
==20441== by 0x3526A9: std::sys::pal::unix::thread::Thread::new (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x16E031: copper_server::init_ctrlc_handler (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x16F674: copper_server::main (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x17A502: std::sys::backtrace::__rust_begin_short_backtrace (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x16ECAC: main (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441==
==20441== 304 bytes in 1 blocks are possibly lost in loss record 44 of 60
==20441== at 0x484B133: calloc (vg_replace_malloc.c:1675)
==20441== by 0x4011FE3: UnknownInlinedFun (rtld-malloc.h:44)
==20441== by 0x4011FE3: allocate_dtv (dl-tls.c:370)
==20441== by 0x4012A71: _dl_allocate_tls (dl-tls.c:629)
==20441== by 0x4FA2233: allocate_stack (allocatestack.c:429)
==20441== by 0x4FA2233: pthread_create@@GLIBC_2.34 (pthread_create.c:655)
==20441== by 0x3526A9: std::sys::pal::unix::thread::Thread::new (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x36DEB0: tokio::runtime::blocking::pool::Spawner::spawn_task (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x181CC8: copper_server::commands::command_line::handle_input::{{closure}} (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x1814C7: tokio::runtime::task::core::Core<T,S>::poll (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x149521: tokio::runtime::task::raw::poll (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x355454: tokio::runtime::scheduler::multi_thread::worker::Context::run_task (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x3594C3: tokio::runtime::task::raw::poll (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x35BBB6: std::sys::backtrace::__rust_begin_short_backtrace (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441==
==20441== 1,216 bytes in 4 blocks are possibly lost in loss record 51 of 60
==20441== at 0x484B133: calloc (vg_replace_malloc.c:1675)
==20441== by 0x4011FE3: UnknownInlinedFun (rtld-malloc.h:44)
==20441== by 0x4011FE3: allocate_dtv (dl-tls.c:370)
==20441== by 0x4012A71: _dl_allocate_tls (dl-tls.c:629)
==20441== by 0x4FA2233: allocate_stack (allocatestack.c:429)
==20441== by 0x4FA2233: pthread_create@@GLIBC_2.34 (pthread_create.c:655)
==20441== by 0x3526A9: std::sys::pal::unix::thread::Thread::new (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x36DEB0: tokio::runtime::blocking::pool::Spawner::spawn_task (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x363AA8: tokio::runtime::builder::Builder::build (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x16EFF4: copper_server::main (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x17A502: std::sys::backtrace::__rust_begin_short_backtrace (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441== by 0x16ECAC: main (in /home/spectre/RustProject/CopperMC/target/release/copper_server)
==20441==
==20441== LEAK SUMMARY:
==20441== definitely lost: 0 bytes in 0 blocks
==20441== indirectly lost: 0 bytes in 0 blocks
==20441== possibly lost: 2,104 bytes in 7 blocks
==20441== still reachable: 101,152 bytes in 165 blocks
==20441== suppressed: 0 bytes in 0 blocks
==20441== Reachable blocks (those to which a pointer was found) are not shown.
==20441== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==20441==
==20441== For lists of detected and suppressed errors, rerun with: -s
==20441== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
spectre@fedora:~/RustProject/CopperMC$


Binary file added perf.data
Binary file not shown.
28 changes: 28 additions & 0 deletions src/args/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::fs_manager;
use clap::Parser;
use log::error;

#[derive(Parser)]
#[command(name = "CopperMC")]
#[command(about = "This is the about, please change", long_about = None)]
struct Cli {
/// Removes all files related to the server, excluding the server.
#[arg(short, long)]
remove_files: Option<bool>,
}

/// Retrieves args and initializes the argument parsing logic.
pub fn init() {
let args = Cli::parse();

parse_args(args);
}

/// Parses args and calls the appropriate functions.
fn parse_args(args: Cli) {
if let Some(_) = args.remove_files {
if let Err(e) = fs_manager::clean_files() {
error!("Error(s) when cleaning files: {e}");
}
}
}
4 changes: 2 additions & 2 deletions src/commands/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub async fn handle_input() -> ! {
};
let content = match fs_manager::write_ops_json(
&consts::filepaths::OPERATORS,
uuid.as_str(),
element,
&uuid.as_str(),
&element,
4,
true,
) {
Expand Down
9 changes: 7 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct Settings {
max_tick_time: i64,
require_resource_pack: bool,
use_native_transport: bool,
max_players: u32,
pub max_players: u32,
online_mode: bool,
enable_status: bool,
allow_flight: bool,
Expand Down Expand Up @@ -134,7 +134,12 @@ impl Settings {
"" => None,
s => Some(s.parse::<i64>().unwrap()),
},
gamemode: match config_file.get_property("gamemode").unwrap().to_lowercase().as_str() {
gamemode: match config_file
.get_property("gamemode")
.unwrap()
.to_lowercase()
.as_str()
{
"creative" => Gamemode::CREATIVE,
"survival" => Gamemode::SURVIVAL,
"spectator" => Gamemode::SPECTATOR,
Expand Down
13 changes: 13 additions & 0 deletions src/consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,16 @@ white-list=false"#;
)
}
}
pub mod ping_slp {
use crate::config;

use super::minecraft::{PROTOCOL_VERSION, VERSION};
///return the json which will be send as a response of the ping to the CLI.
pub fn JSON_response() -> () {
// For the version like 1.21.1,767.
let version_name = VERSION;
let version_protocol = PROTOCOL_VERSION;
// For the players.
//let player_max = config::Settings::new().max_players();
}
}
11 changes: 11 additions & 0 deletions src/file_folder_parser/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::fs::File;
use std::io::{self, Write}; // Importer std::io pour utiliser io::Result et io::Error

pub fn create_server_properties(content:&str) -> io::Result<()> {
// create the file
let mut file = File::create("server_test.properties")?;
//write into the file
file.write_all(content.as_bytes())?; // chatgpt says me rust want have bytes for write anything ...

Ok(())
}
Loading
Loading