Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rewrite/v3' into rewrite/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
ReCore-sys committed Oct 22, 2024
2 parents 9500e7e + 3aa1f59 commit 470f87d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/target
.idea
.vscode
/crates/lib/dummy_lib/Cargo.lock

Cargo.lock
Expand Down
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ FROM rust:alpine3.20 AS build-stage

WORKDIR /app
COPY . /app
RUN cargo build --release
RUN apk add --no-cache musl-dev gcc
RUN cargo build --release -j 10
RUN strip target/release/ferrumc
# Stage 2: Runtime environment
FROM alpine:3.20 AS final-stage
WORKDIR /app

WORKDIR /app
RUN apk add --no-cache wget
COPY --from=build-stage /app/target/release/ferrumc /app/

# leaving this out for now since we dont have world loading
# Once we get the website working, we should put the file on our own server, instead of a contributors side project.
RUN wget --progress=dot:giga https://aboleth.ai/static/ferumc-121-exampleworld.tar.gz -P /app
RUN mkdir -p /app/import && \
tar -xzvf /app/ferumc-121-exampleworld.tar.gz -C /app/import
RUN ./ferrumc --import
RUN rm /app/ferumc-121-exampleworld.tar.gz && \
rm -rf /app/import
# RUN wget --progress=dot:giga https://aboleth.ai/static/ferumc-121-exampleworld.tar.gz -P /app
# RUN mkdir -p /app/import && \
# tar -xzvf /app/ferumc-121-exampleworld.tar.gz -C /app/import
# RUN ./ferrumc --import
# RUN rm /app/ferumc-121-exampleworld.tar.gz && \
# rm -rf /app/import

EXPOSE 25565
CMD ["./ferrumc"]
CMD ["./ferrumc"]
4 changes: 2 additions & 2 deletions src/bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Security or something like that
#![forbid(unsafe_code)]

use std::sync::Arc;
use std::sync::{atomic::AtomicBool, Arc};
use tracing::{error, info};
use ferrumc_ecs::Universe;
use ferrumc_net::ServerState;
Expand All @@ -28,7 +28,7 @@ async fn main() {
async fn entry() -> Result<()> {
let listener = ferrumc_net::server::create_server_listener().await?;

let state = ServerState::new(Universe::new());
let state = ServerState::new(Universe::new(),AtomicBool::new(false));

ferrumc_net::server::listen(Arc::new(state), listener).await?;

Expand Down
2 changes: 1 addition & 1 deletion src/bin/src/packet_handlers/login_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn handle_login_start(

let uuid = login_start_event.login_start_packet.uuid;
let username = login_start_event.login_start_packet.username.clone();
trace!("Received login start from user with username {}", username);
info!("Received login start from user with username {}", username);

//Send a Login Success Response to further the login sequence
let response = LoginSuccessPacket::new(uuid, username);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/net/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ pub async fn handle_connection(state: Arc<ServerState>, tcp_stream: TcpStream) -
break 'recv;
};

trace!("Received packet: {:?}", packet_skele);
if state.log_packets.load(std::sync::atomic::Ordering::Relaxed){
trace!("Received packet: {:?}", packet_skele);
}

let conn_state = state.universe.get::<ConnectionState>(entity)?.clone();
if let Err(e) = handle_packet(
Expand Down
16 changes: 8 additions & 8 deletions src/lib/net/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use std::sync::Arc;
use ferrumc_ecs::Universe;
use ferrumc_macros::bake_packet_registry;
use std::sync::{atomic::AtomicBool, Arc};

pub mod connection;
pub mod errors;
pub mod packets;
pub mod connection;
pub mod server;
pub mod utils;
pub type NetResult<T> = Result<T, errors::NetError>;


pub struct ServerState {
pub universe: Universe
pub universe: Universe,
pub log_packets: AtomicBool,
}

pub type GlobalState = Arc<ServerState>;

impl ServerState {
pub fn new(universe: Universe) -> Self {
pub fn new(universe: Universe, log_packets: AtomicBool) -> Self {
Self {
universe
universe,
log_packets,
}
}
}


bake_packet_registry!("\\src\\packets\\incoming");
bake_packet_registry!("\\src\\packets\\incoming");
24 changes: 6 additions & 18 deletions src/lib/utils/config/src/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::errors::ConfigError;
use crate::statics::{get_global_config, set_global_config};
use ferrumc_general_purpose::paths::get_root_path;
use serde_derive::{Deserialize, Serialize};
use tracing::{error, info};
use tracing::{error, info, warn};

/// The server configuration struct.
///
Expand Down Expand Up @@ -135,29 +135,17 @@ impl ServerConfig {
));
}
// Config could not be read. Prompt the user to create a new one from ServerConfig::Default.
error!(
warn!(
"Could not read configuration file \"{}\" : {}",
path.to_string_lossy().to_string(),
e
);
error!("Would you like to create a new config file? (y/N): ");

let user_input = {
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
input.trim().to_ascii_lowercase()
};
info!("creating new config file!");

if user_input == "y" {
// Create a new config file
std::fs::write(&path, DEFAULT_CONFIG)?;
// Create a new config file
std::fs::write(&path, DEFAULT_CONFIG)?;

DEFAULT_CONFIG
} else {
return Err(ConfigError::ConfigLoadError(
path.to_string_lossy().to_string(),
));
}
DEFAULT_CONFIG
}
};

Expand Down

0 comments on commit 470f87d

Please sign in to comment.