Skip to content

Commit

Permalink
Merge branch 'master' into feat/commands
Browse files Browse the repository at this point in the history
  • Loading branch information
radstevee authored Jan 3, 2025
2 parents ebb5c52 + 1df4866 commit 2552af3
Show file tree
Hide file tree
Showing 55 changed files with 2,113 additions and 458 deletions.
2 changes: 2 additions & 0 deletions .etc/example-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ map_size = 1_000
cache_ttl = 60
# How big the cache can be in kb.
cache_capacity = 20_000

whitelist = false
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ferrumc-core = { path = "src/lib/core" }
ferrumc-default-commands = { path = "src/lib/default_commands" }
ferrumc-commands = { path = "src/lib/commands" }
ferrumc-ecs = { path = "src/lib/ecs" }
ferrumc-events = { path = "src/lib/events" }
ferrumc-events = { path = "src/lib/events"}
ferrumc-general-purpose = { path = "src/lib/utils/general_purpose" }
ferrumc-logging = { path = "src/lib/utils/logging" }
ferrumc-macros = { path = "src/lib/derive_macros" }
Expand All @@ -120,6 +120,7 @@ async-trait = "0.1.82"
# Logging
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-appender = "0.2.3"
log = "0.4.22"
console-subscriber = "0.4.1"

Expand Down
46 changes: 33 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ our [Discord server](https://discord.gg/qT5J8EMjwk) for help or to discuss the p
<img src="https://github.com/ferrumc-rs/ferrumc/blob/master/assets/README/server%20list.png?raw=true" alt="Server list">
</li>
<li>
<h4>🚄 Extremely fast and adaptable update speeds</h4>
<h4>🚄 Extremely fast </h4>
<img src="https://github.com/ferrumc-rs/ferrumc/blob/master/assets/README/mind%20boggling.gif?raw=true" alt="Mind boggling">
</li>
<li>
<h4>🖥️ Highly efficient memory usage</h4>
<img src="https://github.com/ferrumc-rs/ferrumc/blob/master/assets/README/mem_use.png?raw=true" alt="Low memory usage">
</li>
<li>
<h4>🗂️ Customizable configuration</h4>
<h4>🗂️ Straightforward Configuration</h4>
<img src="https://github.com/ferrumc-rs/ferrumc/blob/master/assets/README/config.toml.png?raw=true" alt="Configuration">
</li>
<li>
<h4>🔄 Can import existing worlds from vanilla minecraft</h4>
<img src="https://github.com/ferrumc-rs/ferrumc/blob/master/assets/README/chunk_importing.gif?raw=true" alt="Configuration">
</li>
<li>
<h4>🌐 Compatible with vanilla Minecraft clients (Currently only 1.21.1)</h4>
<h4>🌐 Compatible with vanilla Minecraft clients (Version 1.21.1)</h4>
</li>
<li>
<h4>💪 Powerful Entity Component System to handle high entity loads</h4>
Expand All @@ -72,7 +72,7 @@ our [Discord server](https://discord.gg/qT5J8EMjwk) for help or to discuss the p
<h4>📝 Custom made network, NBT and Anvil encoding systems to allow for minimal I/O lag</h4>
</li>
<li>
<h4>💾 Multiple database options to finetune the server to your needs</h4>
<h4>💾 Crazy fast K/V database </h4>
<i>32 render distance*</i>
<img src="https://github.com/ferrumc-rs/ferrumc/blob/master/assets/README/chunk_loading.gif?raw=true" alt="Chunk Loading DEMO">
</li>
Expand All @@ -82,19 +82,19 @@ our [Discord server](https://discord.gg/qT5J8EMjwk) for help or to discuss the p

<ul>
<li>
<h4>Ability to view other players</h4>
<h4>PvE mechanics, and entities.</h4>
</li>
<li>
<h4>World modification (place / break blocks etc)</h4>
</li>
<li>
<h4>Chat & Command system</h4>
<h4>Web based server dashboard</h4>
</li>
<li>
<h4>Optimizations</h4>
</li>
<li>
<h4>Plugin support (JVM currently, other languages will be considered later)</h4>
<h4>Plugin support (FFI currently, other languages will be considered later)</h4>
</li>
</ul>

Expand Down Expand Up @@ -148,9 +148,23 @@ cargo build --release

## 🖥️ Usage

```plaintext
Usage: ferrumc.exe [OPTIONS] [COMMAND]
Commands:
setup Sets up the config
import Import the world data
run Start the server (default, if no command is given)
help Print this message or the help of the given subcommand(s)
Options:
--log <LOG> [default: debug] [possible values: trace, debug, info, warn, error]
-h, --help Print help
```

1. Move the FerrumC binary (`ferrumc.exe` or `ferrumc` depending on the OS) to your desired server directory
2. Open a terminal in that directory
3. (Optional) Generate a config file: `./ferrumc --setup`
3. (Optional) Generate a config file: `./ferrumc setup`
- Edit the generated `config.toml` file to customize your server settings
4. Import an existing world: Either copy your world files to the server directory or specify the path to the world files
in the `config.toml` file. This should be the root directory of your world files, containing the `region` directory
Expand Down Expand Up @@ -218,10 +232,9 @@ with the vanilla server, but we do plan on implementing some sort of terrain gen
### Will there be plugins? And how?
We do very much plan to have a plugin system and as of right now, our plan is to leverage the
JVM to allow for plugins to be written in Kotlin, Java, or any other JVM language. We are also considering other
languages
such as Rust, JavaScript and possibly other native languages, but that is a fair way off for now.
We do very much plan to have a plugin system and as of right now we are planning to use
some kind of ffi (foreign function interface) to allow for plugins to be written in other languages.
Not confirmed yet.
### What does 'FerrumC' mean?
Expand All @@ -240,4 +253,11 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) f
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=ferrumc-rs/ferrumc&type=Date" />
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=ferrumc-rs/ferrumc&type=Date" />
</picture>
</a>
</a>
## 📊 Stats
[![Timeline graph](https://images.repography.com/59032276/ferrumc-rs/ferrumc/recent-activity/J6CgGhzs6y3LXRuADz1QpSUriBC3ix9DXnPUbbljruA/O-qGFiSVQmksFEaX7mVQ4jY3lppUTK2xUw4CpqZ3oUk_timeline.svg)](https://github.com/ferrumc-rs/ferrumc/commits)
[![Issue status graph](https://images.repography.com/59032276/ferrumc-rs/ferrumc/recent-activity/J6CgGhzs6y3LXRuADz1QpSUriBC3ix9DXnPUbbljruA/O-qGFiSVQmksFEaX7mVQ4jY3lppUTK2xUw4CpqZ3oUk_issues.svg)](https://github.com/ferrumc-rs/ferrumc/issues)
[![Pull request status graph](https://images.repography.com/59032276/ferrumc-rs/ferrumc/recent-activity/J6CgGhzs6y3LXRuADz1QpSUriBC3ix9DXnPUbbljruA/O-qGFiSVQmksFEaX7mVQ4jY3lppUTK2xUw4CpqZ3oUk_prs.svg)](https://github.com/ferrumc-rs/ferrumc/pulls)
[![Top contributors](https://images.repography.com/59032276/ferrumc-rs/ferrumc/recent-activity/J6CgGhzs6y3LXRuADz1QpSUriBC3ix9DXnPUbbljruA/O-qGFiSVQmksFEaX7mVQ4jY3lppUTK2xUw4CpqZ3oUk_users.svg)](https://github.com/ferrumc-rs/ferrumc/graphs/contributors)
64 changes: 64 additions & 0 deletions scripts/new_packet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os.path

incoming_template = """
use crate::packets::IncomingPacket;
use crate::NetResult;
use ferrumc_macros::{packet, NetDecode};
use ferrumc_state::ServerState;
use std::sync::Arc;
#[derive(NetDecode)]
#[packet(packet_id = ++id++, state = "play")]
pub struct ++name++ {
}
impl IncomingPacket for ++name++ {
async fn handle(self, conn_id: usize, state: Arc<ServerState>) -> NetResult<()> {
todo!()
}
}
"""

outgoing_template = """
use ferrumc_macros::{packet, NetEncode};\
use std::io::Write;
#[derive(NetEncode)]
#[packet(packet_id = ++id++)]
pub struct ++name++ {}
"""


def to_snake_case(string) -> str:
return string.lower().replace(" ", "_")


def to_camel_case(string) -> str:
return string.title().replace(" ", "")


packet_type_input = input("Incoming or outgoing packet? (i/o): ")
packet_type = ""
if packet_type_input == "i":
packet_type = "incoming"
elif packet_type_input == "o":
packet_type = "outgoing"
else:
print("Invalid input")
exit()

packet_name = input("Packet name: ")
packets_dir = os.path.join(os.path.join(os.path.dirname(__file__), ".."), "src/lib/net/src/packets")

packet_id = input("Packet ID (formatted like 0x01): ")
packet_id = packet_id[:-2] + packet_id[-2:].upper()

with open(f"{packets_dir}/{packet_type}/{to_snake_case(packet_name)}.rs", "x") as f:
if packet_type == "incoming":
f.write(incoming_template.replace("++name++", to_camel_case(packet_name)).replace("++id++", packet_id))
with open(f"{packets_dir}/incoming/mod.rs", "a") as modfile:
modfile.write(f"\npub mod {to_snake_case(packet_name)};")
else:
f.write(outgoing_template.replace("++name++", to_camel_case(packet_name)).replace("++id++", packet_id))
with open(f"{packets_dir}/outgoing/mod.rs", "a") as modfile:
modfile.write(f"\npub mod {to_snake_case(packet_name)};")
5 changes: 2 additions & 3 deletions src/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ ferrumc-commands = { workspace = true }
ferrumc-default-commands = { workspace = true }
ferrumc-text = { workspace = true }

ctor = { workspace = true }
parking_lot = { workspace = true, features = ["deadlock_detection"] }
tracing = { workspace = true }
tokio = { workspace = true }
rayon = { workspace = true }
futures = { workspace = true }
serde_json = { workspace = true }
async-trait = { workspace = true }
clap = { workspace = true, features = ["derive"] }
flate2 = { workspace = true }
ctor = { workspace = true }


[[bin]]
Expand Down
6 changes: 3 additions & 3 deletions src/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ferrumc_world::World;
use std::hash::{Hash, Hasher};
use std::sync::Arc;
use systems::definition;
use tracing::{error, info};
use tracing::{error, info, trace};

pub(crate) mod errors;
use crate::cli::{CLIArgs, Command, ImportArgs};
Expand All @@ -37,11 +37,11 @@ async fn main() {
let mut hasher = std::collections::hash_map::DefaultHasher::new();
std::any::TypeId::of::<ChunkReceiver>().hash(&mut hasher);
let digest = hasher.finish();
println!("ChunkReceiver: {:X}", digest);
trace!("ChunkReceiver: {:X}", digest);
let mut hasher = std::collections::hash_map::DefaultHasher::new();
std::any::TypeId::of::<StreamWriter>().hash(&mut hasher);
let digest = hasher.finish();
println!("StreamWriter: {:X}", digest);
trace!("StreamWriter: {:X}", digest);
}

match cli_args.command {
Expand Down
21 changes: 21 additions & 0 deletions src/bin/src/packet_handlers/animations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use ferrumc_macros::event_handler;
use ferrumc_net::errors::NetError;
use ferrumc_net::packets::outgoing::entity_animation::EntityAnimationEvent;
use ferrumc_net::utils::broadcast::{broadcast, BroadcastOptions};
use ferrumc_state::GlobalState;

#[event_handler]
async fn entity_animation(
event: EntityAnimationEvent,
state: GlobalState,
) -> Result<EntityAnimationEvent, NetError> {
//TODO change this global broadcast to a broadcast that affects only players in the view distance
// of the player doing it, but as long as we still cant see other players, this will be fine.
broadcast(
&event.packet,
&state,
BroadcastOptions::default().except([event.entity]),
)
.await?;
Ok(event)
}
Loading

0 comments on commit 2552af3

Please sign in to comment.