Skip to content

Commit af31e6e

Browse files
committed
fmt & enhancements & changelog
1 parent acf9d3d commit af31e6e

File tree

9 files changed

+197
-227
lines changed

9 files changed

+197
-227
lines changed

Cargo.lock

Lines changed: 0 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ edition = "2021"
77
async-std = "1.12.0"
88
lettre = "0.11"
99
maud = "0.26.0"
10-
tracing-subscriber = "0.3.18"

changelog/1.0.0.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 1.0.0 Release
2+
This is the first `ServerAPI` **stable** release you can enjoy!
3+
4+
Added features:
5+
- installation wizard
6+
- launching rust modules in parallel
7+
- config support (you can change everything manually)
8+
- implemented fancy html header (use of `maud` crate)
9+
- implemented a text raw alternative to html in case client does not support it
10+
11+
12+
Waited soon:
13+
- crate organization, such as in my [`LimitPush`](https://github.com/heydocode/limitpush) project
14+
- launching of processes via the CLI environment
15+
- responsible CLI with commands
16+
- inter-operability with [`LimitPush`](https://github.com/heydocode/limitpush) template, and any other bevy game
17+
- feature organization
18+
- custom multiplayer protocol that'll work with `LimitPush` if "mp-protocol" feature enabled

src/file_reader.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs::{create_dir_all, File, metadata};
1+
use std::fs::{create_dir_all, metadata, File};
22
use std::io::{BufReader, Read};
33
use std::path::Path;
44

@@ -41,7 +41,12 @@ pub fn mc_status_reader() -> String {
4141
}
4242

4343
let contents = read_from_file(file_path.to_str().unwrap_or("config/logs.txt"));
44-
if contents.clone().expect("Could not convert contents to Ok()").len() <= 5 {
44+
if contents
45+
.clone()
46+
.expect("Could not convert contents to Ok()")
47+
.len()
48+
<= 5
49+
{
4550
String::from("The server's logs are empty! Is there a problem?")
4651
} else {
4752
contents.expect("Could not convert contents to Ok()")
@@ -63,11 +68,14 @@ fn read_from_file(file_path: &str) -> Result<String, String> {
6368
}
6469

6570
// Attempt to open the file
66-
let file = File::open(file_path).map_err(|e| format!("Error opening file '{}': {}", file_path, e))?;
71+
let file =
72+
File::open(file_path).map_err(|e| format!("Error opening file '{}': {}", file_path, e))?;
6773
let mut buf_reader = BufReader::new(file);
6874
let mut contents = String::new();
69-
70-
buf_reader.read_to_string(&mut contents).map_err(|e| format!("Error reading file '{}': {}", file_path, e))?;
75+
76+
buf_reader
77+
.read_to_string(&mut contents)
78+
.map_err(|e| format!("Error reading file '{}': {}", file_path, e))?;
7179

7280
Ok(contents)
7381
}

src/file_writer.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use async_std::fs::File;
12
use async_std::fs::OpenOptions;
23
use async_std::path::Path;
3-
use async_std::fs::File;
44
use async_std::prelude::*;
55

66
pub async fn write_to_file(text: String, file_path: &str) -> Result<(), String> {
@@ -11,27 +11,37 @@ pub async fn write_to_file(text: String, file_path: &str) -> Result<(), String>
1111
.await
1212
.map_err(|e| e.to_string())?;
1313

14-
file.write_all(text.as_bytes()).await.map_err(|e| e.to_string())
14+
file.write_all(text.as_bytes())
15+
.await
16+
.map_err(|e| e.to_string())
1517
}
1618

17-
pub async fn update_credentials(username: String, password: String, receiver: String) -> Result<(), String> {
19+
pub async fn update_credentials(
20+
username: String,
21+
password: String,
22+
receiver: String,
23+
) -> Result<(), String> {
1824
let file_path = "config/smtp_account.txt";
1925
let path = Path::new(file_path);
2026

2127
let mut content = String::new();
2228
{
23-
let mut file = File::open(path)
24-
.await
25-
.map_err(|e| e.to_string())?;
29+
let mut file = File::open(path).await.map_err(|e| e.to_string())?;
2630
file.read_to_string(&mut content)
2731
.await
2832
.map_err(|e| e.to_string())?;
2933
}
3034

3135
let updated_content = content
32-
.replace("username:[email protected]", &format!("username:{}", username))
36+
.replace(
37+
"username:[email protected]",
38+
&format!("username:{}", username),
39+
)
3340
.replace("password:password123123", &format!("password:{}", password))
34-
.replace("receiver:[email protected]", &format!("receiver:{}", receiver));
41+
.replace(
42+
"receiver:[email protected]",
43+
&format!("receiver:{}", receiver),
44+
);
3545

3646
{
3747
let mut file = OpenOptions::new()

src/mail.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use crate::file_reader::smtp_account_reader;
22
use crate::file_writer::write_to_file;
33
use lettre::{
4-
message::{header::{self, ContentType}, MultiPart, SinglePart}, transport::smtp::authentication::Credentials, Message,
5-
SmtpTransport, Transport,
4+
message::{
5+
header::{self}, MaybeString, MultiPart, SinglePart
6+
},
7+
transport::smtp::authentication::Credentials,
8+
Message, SmtpTransport, Transport,
69
};
710
use maud::PreEscaped;
811

@@ -28,8 +31,7 @@ pub async fn mail_sender(title: &str, html: PreEscaped<String>) {
2831
.singlepart(
2932
SinglePart::builder()
3033
.header(header::ContentType::TEXT_PLAIN)
31-
.body(format!(
32-
"Hello there!\nYour server is working fine! The next status email will be sent in 5 minutes.\n\nServer's Logs:\nYour client does not support html...")),
34+
.body(MaybeString::String(String::from("Hello there!\nYour server is working fine! The next status email will be sent in 5 minutes.\n\nServer's Logs:\nYour client does not support html..."))),
3335
)
3436
.singlepart(
3537
SinglePart::builder()
@@ -50,7 +52,7 @@ pub async fn mail_sender(title: &str, html: PreEscaped<String>) {
5052
match mailer.send(&email) {
5153
Ok(_) => {
5254
match write_to_file(
53-
format!("Email has been sent successfully!"),
55+
"Email has been sent successfully!".to_string(),
5456
"config/mail_logs.txt",
5557
)
5658
.await

src/main.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ use scheduler::status_upload;
1212
use file_writer::write_to_file;
1313
use setup::check_config_components;
1414
use std::thread;
15-
use tracing_subscriber;
1615

1716
fn main() {
18-
tracing_subscriber::fmt::init();
19-
2017
let setup_handle = thread::Builder::new().name("setup".to_string()).spawn(|| {
2118
println!("Setup Process has been launched");
2219
match check_config_components() {
@@ -26,7 +23,7 @@ fn main() {
2623

2724
async_std::task::block_on(async {
2825
match write_to_file(
29-
format!("All config components are OK, loading the server.."),
26+
"All config components are OK, loading the server..".to_string(),
3027
"config/logs.txt",
3128
)
3229
.await
@@ -37,23 +34,30 @@ fn main() {
3734
});
3835
});
3936

40-
if let Err(_) = setup_handle.expect("Unable to join setup handle").join() {
37+
let mail_handle = thread::Builder::new()
38+
.name("mail_server".to_string())
39+
.spawn(|| {
40+
println!("Mail Server has been enabled");
41+
status_upload();
42+
println!("Mail Server has been disabled");
43+
});
44+
45+
if setup_handle
46+
.expect("Unable to join setup handle")
47+
.join()
48+
.is_err()
49+
{
4150
eprintln!("An error occured when tried to join setup handle");
42-
} else {
43-
let mail_handle = thread::Builder::new()
44-
.name("mail_server".to_string())
45-
.spawn(|| {
46-
println!("Mail Server has been enabled");
47-
status_upload();
48-
println!("Mail Server has been disabled");
49-
});
50-
if let Err(_) = mail_handle.expect("Unable to join mail handle").join() {
51-
eprintln!("An error occured when tried to join mail handle");
52-
}
53-
// Please consider adding `else if` blocks until all handles won't be joined
54-
else {
55-
println!("All config components are OK, loading the server..");
56-
}
51+
} else if mail_handle
52+
.expect("Unable to join mail handle")
53+
.join()
54+
.is_err()
55+
{
56+
eprintln!("An error occured when tried to join mail handle");
57+
}
58+
// Please consider adding `else if` blocks until all handles won't be joined
59+
else {
60+
println!("All config components are OK, loading the server..");
5761
}
5862
/*
5963
MINECRAFT SERVER SUPPORT USING VALENCE

0 commit comments

Comments
 (0)