Add super cool logger
This commit is contained in:
parent
79b0474739
commit
91d321e012
214
Cargo.lock
generated
214
Cargo.lock
generated
@ -3,10 +3,10 @@
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
name = "adler2"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
@ -14,6 +14,12 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
@ -28,12 +34,12 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "2.1.0"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
|
||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -56,10 +62,19 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.30"
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae"
|
||||
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
@ -77,16 +92,28 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
name = "itoa"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.155"
|
||||
version = "0.2.170"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||
checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
|
||||
|
||||
[[package]]
|
||||
name = "mcrizzledizzle"
|
||||
@ -96,16 +123,18 @@ dependencies = [
|
||||
"ctrlc",
|
||||
"flate2",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"rand",
|
||||
"simple_logger",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.7.3"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae"
|
||||
checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5"
|
||||
dependencies = [
|
||||
"adler",
|
||||
"adler2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -121,10 +150,52 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
@ -156,6 +227,88 @@ dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.218"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.218"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simple_logger"
|
||||
version = "5.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8c5dfa5e08767553704aa0ffd9d9794d527103c736aba9854773851fd7497eb"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"log",
|
||||
"time",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"libc",
|
||||
"num-conv",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
@ -300,3 +453,24 @@ name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.7.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
@ -8,4 +8,9 @@ colored = "2.1.0"
|
||||
ctrlc = "3.4.5"
|
||||
flate2 = "1.0.30"
|
||||
lazy_static = "1.4.0"
|
||||
log = "0.4.26"
|
||||
rand = "0.8.5"
|
||||
|
||||
[dependencies.simple_logger]
|
||||
version = "5.0.0"
|
||||
features = ["threads", "nightly"]
|
||||
|
@ -2,4 +2,7 @@ McRizzleDrizzle
|
||||
|
||||
mæk ˈrrɪzᵊl ˈdrɪzᵊl
|
||||
|
||||
TODO: Update player struct to support a backlog of instructions. (Will allow block manipulation)
|
||||
TODO:
|
||||
- Fix error on disconnect
|
||||
- Command support
|
||||
- classicube extensions
|
||||
|
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
42
src/main.rs
42
src/main.rs
@ -1,3 +1,4 @@
|
||||
use simple_logger::SimpleLogger;
|
||||
use flate2::write::GzEncoder;
|
||||
use flate2::Compression;
|
||||
use std::fs::{self, File};
|
||||
@ -6,8 +7,8 @@ use std::net::{SocketAddr, TcpListener, TcpStream};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::thread::sleep;
|
||||
use std::time::SystemTime;
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
use std::time::Duration;
|
||||
use log::{info, warn, error};
|
||||
|
||||
impl Default for Player {
|
||||
fn default() -> Self {
|
||||
@ -91,6 +92,8 @@ fn handle_client(
|
||||
world_arc_clone: Arc<Mutex<World>>,
|
||||
) {
|
||||
thread::spawn(move || {
|
||||
info!("Thread initialized with player ID: {}", client_number);
|
||||
|
||||
let mut player_statuses = [PlayerStatus::Disconnected; 255];
|
||||
let mut immediate_join = [false; 255];
|
||||
{
|
||||
@ -124,7 +127,7 @@ fn handle_client(
|
||||
let _ = &mut stream.write(&client_disconnect(
|
||||
"Something went wrong (CODE: PACKET_SKIPPED)",
|
||||
));
|
||||
println!("this client is wiggidy wack yo!");
|
||||
warn!("Something went wrong, packet 0x00 received but second byte was not 7");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -288,9 +291,9 @@ fn handle_client(
|
||||
SpecialPlayers::SelfPlayer as u8,
|
||||
String::from_iter(message),
|
||||
));
|
||||
println!("{}", String::from_iter(message));
|
||||
info!("{}", String::from_iter(message));
|
||||
}
|
||||
_ => println!("Packet {} not implemented!", buffer[0]),
|
||||
_ => warn!("Packet {} not implemented!", buffer[0]),
|
||||
}
|
||||
let is_kill = &mut stream.write(&ping()); // Ping that MF
|
||||
|
||||
@ -352,7 +355,7 @@ fn handle_client(
|
||||
|
||||
current_player.id = SpecialPlayers::SelfPlayer as u8;
|
||||
}
|
||||
println!("Thread {} is kill!", client_number);
|
||||
info!("Client {} disconnected, thread shutting down!", client_number);
|
||||
});
|
||||
}
|
||||
|
||||
@ -385,16 +388,7 @@ fn client_disconnect(text: &str) -> Vec<u8> {
|
||||
fn server_identification(is_op: bool) -> Vec<u8> {
|
||||
let mut ret_val: Vec<u8> = vec![];
|
||||
ret_val.push(0x00);
|
||||
let start = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
ret_val.push(0x07);
|
||||
let end = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
println!("Single stream write: {}ns", end - start);
|
||||
|
||||
let server_name = "Erm... what the sigma?";
|
||||
ret_val.append(&mut to_mc_string(server_name).to_vec());
|
||||
@ -554,7 +548,7 @@ fn send_level_data(world_arc_clone: &Arc<Mutex<World>>) -> Vec<u8> {
|
||||
ret_val.push(100);
|
||||
}
|
||||
|
||||
println!(
|
||||
info!(
|
||||
"World transmission size: {}KiB",
|
||||
ret_val.len() as f32 / 1024.0
|
||||
);
|
||||
@ -588,7 +582,7 @@ fn load_world() -> World {
|
||||
};
|
||||
let world_data_raw = fs::read("world.wrld").unwrap();
|
||||
if world_data_raw.len() < 6 {
|
||||
println!("INVALID WORLD!");
|
||||
error!("INVALID WORLD!");
|
||||
std::process::exit(1);
|
||||
}
|
||||
world.size_x = ((world_data_raw[0] as i16) << 8) + (world_data_raw[1] as i16);
|
||||
@ -598,7 +592,7 @@ fn load_world() -> World {
|
||||
if world_data_raw.len()
|
||||
!= (world.size_x as i32 * world.size_y as i32 * world.size_z as i32 + 6 as i32) as usize
|
||||
{
|
||||
println!(
|
||||
error!(
|
||||
"Expected more bytes in world contents: {} (expected) != {} (actual)",
|
||||
world.size_x * world.size_y * world.size_z + 6,
|
||||
world_data_raw.len()
|
||||
@ -625,19 +619,19 @@ fn bomb_server_details(
|
||||
world_arc_clone: &Arc<Mutex<World>>,
|
||||
) {
|
||||
let mut compound_data: Vec<u8> = vec![];
|
||||
println!("Server IDENT");
|
||||
info!("Server IDENT");
|
||||
compound_data.append(&mut server_identification(current_player.operator));
|
||||
|
||||
println!("Intialize level");
|
||||
info!("Intialize level");
|
||||
compound_data.append(&mut init_level());
|
||||
|
||||
println!("Send level data");
|
||||
info!("Send level data");
|
||||
compound_data.append(&mut send_level_data(&world_arc_clone)); // Approaching Nirvana - Maw of the beast
|
||||
|
||||
println!("Finalize level");
|
||||
info!("Finalize level");
|
||||
compound_data.append(&mut finalize_level(&world_arc_clone));
|
||||
|
||||
println!("Spawning player");
|
||||
info!("Spawning player");
|
||||
compound_data.append(&mut spawn_player(
|
||||
SpecialPlayers::SelfPlayer as u8,
|
||||
¤t_player.username,
|
||||
@ -652,6 +646,8 @@ fn bomb_server_details(
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
SimpleLogger::new().with_threads(true).init().unwrap();
|
||||
|
||||
let players: [Player; 255] = core::array::from_fn(|_| Player::default());
|
||||
let players_arc = Arc::new(Mutex::new(players));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user