Restructure
This commit is contained in:
parent
737a1de7af
commit
253ab0802a
15
output.log
15
output.log
@ -1,3 +1,18 @@
|
||||
[2020-12-17 19:37:46][Composition][INFO] Starting server...
|
||||
[2020-12-17 19:37:46][Composition::net][INFO] Network server started!
|
||||
[2020-12-17 19:37:46][Composition][INFO] Done! Start took 1.175717ms
|
||||
[2021-03-01 19:29:47][composition][INFO] Starting server...
|
||||
[2021-03-01 19:29:47][composition::server::net][INFO] Network server started!
|
||||
[2021-03-01 19:29:47][composition][INFO] Done! Start took 899.375µs
|
||||
[2021-03-01 19:32:40][composition][INFO] Starting server...
|
||||
[2021-03-01 19:32:40][composition::server::net][INFO] Network server started!
|
||||
[2021-03-01 19:32:40][composition][INFO] Done! Start took 916.834µs
|
||||
[2021-03-01 19:32:52][composition][INFO] Starting server...
|
||||
[2021-03-01 19:32:52][composition::server::net][INFO] Network server started!
|
||||
[2021-03-01 19:32:52][composition][INFO] Done! Start took 943.171µs
|
||||
[2021-03-01 19:33:27][composition][INFO] Starting server...
|
||||
[2021-03-01 19:33:27][composition::server::net][INFO] Network server started!
|
||||
[2021-03-01 19:33:27][composition][INFO] Done! Start took 845.987µs
|
||||
[2021-03-01 19:33:44][composition][INFO] Starting server...
|
||||
[2021-03-01 19:33:44][composition::server::net][INFO] Network server started!
|
||||
[2021-03-01 19:33:44][composition][INFO] Done! Start took 715.677µs
|
||||
|
1
src/entity/mod.rs
Normal file
1
src/entity/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
|
32
src/lib.rs
Normal file
32
src/lib.rs
Normal file
@ -0,0 +1,32 @@
|
||||
pub mod entity;
|
||||
pub mod mctypes;
|
||||
pub mod server;
|
||||
pub mod world;
|
||||
|
||||
pub use mctypes::*;
|
||||
|
||||
pub fn init() {
|
||||
// Set up fern logging.
|
||||
fern::Dispatch::new()
|
||||
.format(move |out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"[{date}][{target}][{level}] {message}",
|
||||
date = chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
|
||||
target = record.target(),
|
||||
level = record.level(),
|
||||
message = message,
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Debug)
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file("output.log").unwrap())
|
||||
.apply()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn start_server() -> server::GameServer {
|
||||
// Start the network.
|
||||
let network = server::net::NetworkServer::new("0.0.0.0:25565");
|
||||
let server = server::GameServer { network: network };
|
||||
server
|
||||
}
|
34
src/main.rs
34
src/main.rs
@ -1,39 +1,11 @@
|
||||
#![allow(unused_imports)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
pub mod mctypes;
|
||||
pub mod net;
|
||||
pub mod server;
|
||||
|
||||
use log::{debug, error, info, warn};
|
||||
use net::NetworkServer;
|
||||
use server::GameServer;
|
||||
use log::info;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub fn main() {
|
||||
let start_time = Instant::now();
|
||||
|
||||
// Set up fern logging.
|
||||
fern::Dispatch::new()
|
||||
.format(move |out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"[{date}][{target}][{level}] {message}",
|
||||
date = chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
|
||||
target = record.target(),
|
||||
level = record.level(),
|
||||
message = message,
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Debug)
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file("output.log").unwrap())
|
||||
.apply()
|
||||
.unwrap();
|
||||
composition::init();
|
||||
info!("Starting server...");
|
||||
|
||||
// Start the network.
|
||||
let network = NetworkServer::new("0.0.0.0:25565");
|
||||
let mut server = GameServer { network: network };
|
||||
let mut server = composition::start_server();
|
||||
info!("Done! Start took {:?}", start_time.elapsed());
|
||||
|
||||
// The main server loop.
|
||||
|
@ -1012,7 +1012,7 @@ pub mod numbers {
|
||||
}
|
||||
impl MCType for MCVarInt {
|
||||
fn read(t: &mut TcpStream) -> std::io::Result<Self> {
|
||||
let mut numRead = 0;
|
||||
let mut num_read = 0;
|
||||
let mut result = 0i32;
|
||||
let mut read = 0u8;
|
||||
let mut run_once = false;
|
||||
@ -1020,9 +1020,9 @@ pub mod numbers {
|
||||
run_once = true;
|
||||
read = read_byte(t)?;
|
||||
let value = (read & 0b01111111) as i32;
|
||||
result |= value << (7 * numRead);
|
||||
numRead += 1;
|
||||
if numRead > 5 {
|
||||
result |= value << (7 * num_read);
|
||||
num_read += 1;
|
||||
if num_read > 5 {
|
||||
return Err(io_error("MCVarInt is too big"));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::net::{NetworkClient, NetworkClientState, NetworkServer};
|
||||
use log::{debug, error, info, warn};
|
||||
pub mod net;
|
||||
|
||||
pub struct GameServer {
|
||||
pub network: NetworkServer,
|
||||
pub network: net::NetworkServer,
|
||||
}
|
||||
impl GameServer {
|
||||
pub fn update(&mut self) {
|
||||
|
@ -1,11 +1,11 @@
|
||||
pub mod packets;
|
||||
|
||||
use crate::mctypes::*;
|
||||
use log::{debug, error, info, warn};
|
||||
use log::{debug, info};
|
||||
use packets::*;
|
||||
use std::net::{TcpListener, TcpStream, ToSocketAddrs};
|
||||
use std::sync::mpsc::{self, Receiver, Sender, TryRecvError};
|
||||
use serde_json::json;
|
||||
use std::net::{TcpListener, TcpStream, ToSocketAddrs};
|
||||
use std::sync::mpsc::{self, Receiver, TryRecvError};
|
||||
|
||||
pub struct NetworkServer {
|
||||
pub clients: Vec<NetworkClient>,
|
||||
@ -114,7 +114,7 @@ impl NetworkClient {
|
||||
"description": {
|
||||
"text": "Hello world!"
|
||||
},
|
||||
"favicon": format!("data:image/png;base64,{}", radix64::STD.encode(include_bytes!("../server-icon.png")))
|
||||
"favicon": format!("data:image/png;base64,{}", radix64::STD.encode(include_bytes!("../../server-icon.png")))
|
||||
}).to_string().into();
|
||||
statusresponse.write(&mut self.stream).unwrap();
|
||||
debug!("Sending status response: StatusResponse");
|
1
src/world/mod.rs
Normal file
1
src/world/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
|
Loading…
x
Reference in New Issue
Block a user