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

Change from chrono implementation to impl based on time crate #506

Closed
416 changes: 222 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions feather/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ahash = "0.7"
anyhow = "1"
base = { path = "../base", package = "feather-base" }
base64 = "0.13"
chrono = "0.4"
time = { version = "0.3.4", features = ["local-offset", "formatting", "macros"] }
colored = "2"
common = { path = "../common", package = "feather-common" }
crossbeam-utils = "0.8"
Expand All @@ -36,10 +36,14 @@ parking_lot = "0.11"
plugin-host = { path = "../plugin-host", package = "feather-plugin-host" }
protocol = { path = "../protocol", package = "feather-protocol" }
quill-common = { path = "../../quill/common" }
rand = "0.7"

rand = "0.8.0"
ring = "0.16"
rsa = "0.3"
rsa-der = "0.2"

rsa = "0.5"
rsa-der = "0.3"
base64ct = "=1.1.1"

serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
sha-1 = "0.9"
Expand Down
6 changes: 3 additions & 3 deletions feather/server/src/initial_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use protocol::{
ServerLoginPacket, ServerPlayPacket, ServerStatusPacket,
};
use rand::rngs::OsRng;
use rsa::{PaddingScheme, PublicKeyParts, RSAPrivateKey};
use rsa::{PaddingScheme, PublicKeyParts, RsaPrivateKey};
use serde::{Deserialize, Serialize};
use sha1::Sha1;
use std::convert::TryInto;
Expand Down Expand Up @@ -205,8 +205,8 @@ fn offline_mode_uuid(username: &str) -> Uuid {
const RSA_BITS: usize = 1024;

/// Cached RSA key used by this server instance.
static RSA_KEY: Lazy<RSAPrivateKey> =
Lazy::new(|| RSAPrivateKey::new(&mut OsRng, RSA_BITS).expect("failed to create RSA key"));
static RSA_KEY: Lazy<RsaPrivateKey> =
Lazy::new(|| RsaPrivateKey::new(&mut OsRng, RSA_BITS).expect("failed to create RSA key"));
static RSA_KEY_ENCODED: Lazy<Vec<u8>> = Lazy::new(|| {
rsa_der::public_key_to_der(&RSA_KEY.n().to_bytes_be(), &RSA_KEY.e().to_bytes_be())
});
Expand Down
13 changes: 12 additions & 1 deletion feather/server/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use colored::Colorize;
use log::{Level, LevelFilter};
use time::macros::format_description;
use time::OffsetDateTime;

pub fn init(level: LevelFilter) {
fern::Dispatch::new()
Expand All @@ -16,9 +18,18 @@ pub fn init(level: LevelFilter) {
} else {
record.module_path().unwrap_or_default()
};

let datetime: OffsetDateTime = match OffsetDateTime::now_local() {
Ok(x) => x,
Err(_) => OffsetDateTime::now_utc(),
};
out.finish(format_args!(
"{} {:<5} [{}] {}",
chrono::Local::now().format("%Y-%m-%d %H:%M:%S,%3f"),
datetime
.format(format_description!(
"[year]-[month]-[day] [hour]:[minute]:[second],[subsecond digits:3]"
))
.unwrap(),
level_string,
target,
message,
Expand Down
1 change: 0 additions & 1 deletion feather/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ edition = "2018"
[dependencies]

[dev-dependencies]
simple_logger = "1"
5 changes: 4 additions & 1 deletion tools/proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ futures-lite = "1"
argh = "0.1"
anyhow = "1"
log = "0.4"
simple_logger = "1"
either = "1"
colored = "2"
fern = "0.6"
time = { version = "0.3.4", features = ["local-offset", "formatting", "macros"] }

42 changes: 42 additions & 0 deletions tools/proxy/src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use colored::Colorize;
use log::{Level, LevelFilter};
use time::macros::format_description;
use time::OffsetDateTime;

pub fn init(level: LevelFilter) {
fern::Dispatch::new()
.format(|out, message, record| {
let level_string = match record.level() {
Level::Error => record.level().to_string().red(),
Level::Warn => record.level().to_string().yellow(),
Level::Info => record.level().to_string().cyan(),
Level::Debug => record.level().to_string().purple(),
Level::Trace => record.level().to_string().normal(),
};
let target = if !record.target().is_empty() {
record.target()
} else {
record.module_path().unwrap_or_default()
};

let datetime: OffsetDateTime = match OffsetDateTime::now_local() {
Ok(x) => x,
Err(_) => OffsetDateTime::now_utc(),
};
out.finish(format_args!(
"{} {:<5} [{}] {}",
datetime
.format(format_description!(
"[year]-[month]-[day] [hour]:[minute]:[second],[subsecond digits:3]"
))
.unwrap(),
level_string,
target,
message,
));
})
.level(level)
.chain(std::io::stdout())
.apply()
.unwrap();
}
8 changes: 3 additions & 5 deletions tools/proxy/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::net::{SocketAddr, TcpListener, TcpStream};

mod logging;

use anyhow::{bail, Context};
use argh::FromArgs;
use async_executor::Executor;
Expand All @@ -11,7 +13,6 @@ use feather_protocol::{
};
use futures_lite::FutureExt;
use futures_lite::{AsyncReadExt, AsyncWriteExt};
use simple_logger::SimpleLogger;

/// A proxy for debugging and inspecting the Minecraft protocol.
#[derive(Debug, FromArgs)]
Expand All @@ -26,10 +27,7 @@ struct Args {
}

fn main() -> anyhow::Result<()> {
SimpleLogger::new()
.with_level(log::LevelFilter::Debug)
.init()
.unwrap();
logging::init(log::LevelFilter::Debug);
let args: Args = argh::from_env();

let addr = format!("127.0.0.1:{}", args.port);
Expand Down