Added Server Icon

This commit is contained in:
Kyler 2023-12-19 15:25:17 -07:00
parent 88c02f6b2a
commit c46031c737
3 changed files with 23 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target
Cargo.lock
test_server/*
main_icon.png

View File

@ -9,3 +9,4 @@ edition = "2021"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
base64 = "0.21.5"

View File

@ -1,8 +1,12 @@
// Yeahbut December 2023
use std::fs::File;
use std::io::Read;
use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::io::AsyncWriteExt;
use serde::{Serialize, Deserialize};
use base64::{Engine as _, engine::general_purpose};
use crate::mc_types;
use crate::handshake;
@ -52,7 +56,22 @@ fn motd() -> String {
}
fn favicon() -> Option<String> {
None
let file_path = "./main_icon.png";
let mut file = match File::open(file_path) {
Ok(file) => file,
Err(_) => return None,
};
let mut buffer = Vec::new();
if let Err(_) = file.read_to_end(&mut buffer) {
return None
}
let base64_string = general_purpose::STANDARD_NO_PAD.encode(buffer);
let full_string = "data:image/png;base64,".to_string() + &base64_string;
Some(full_string)
}
pub async fn respond_status(