Skip to content

Commit

Permalink
Merge branch 'rewrite/v3' into feature/chunk_sending
Browse files Browse the repository at this point in the history
  • Loading branch information
ReCore-sys committed Nov 27, 2024
2 parents eb0b2b1 + ca7ce8c commit 9da8487
Show file tree
Hide file tree
Showing 34 changed files with 1,470 additions and 160 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ who have you discussed this with, etc. If these questions were answered in a con
you talked with and what consensus was reached. Unexplained PRs will rarely be accepted.
4. Check again that tests pass.
5. Check a 3rd time.
6. Submit PR.
6. Check that Clippy passes with no issues. `cargo clippy --all-targets -- -Dwarnings` is used on CI.
7. Submit PR.

## Project specific guidelines
Just some rules to try to keep the repo nice and organised
Expand All @@ -27,7 +28,7 @@ made to the dev branch. This branch should be branched off of the dev branch.
#### `fix/fixed-thing`
This branch is for fixing a bug. Once the bug is fixed, a PR should be made to the dev
branch. This branch should be branched off of the dev branch.
#### `refactor/refactored-thing`
#### `rework/refactored-thing`
This branch is for refactoring code. Once the code is refactored, a PR should be made to the dev branch.
#### `housekeeping`
This branch is for stuff relating to the repo itself. This could be updating the README, adding
Expand Down
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ members = [
"src/lib/world",
"src/lib/derive_macros",
"src/lib/adapters/nbt", "src/lib/adapters/mca",
"src/tests", "src/lib/adapters/anvil"
"src/tests", "src/lib/adapters/anvil",
"src/lib/text",
]

#================== Lints ==================#
Expand Down Expand Up @@ -69,6 +70,7 @@ ferrumc-core = { path = "src/lib/core" }
ferrumc-ecs = { path = "src/lib/ecs" }
ferrumc-events = { path = "src/lib/events" }
ferrumc-net = { path = "src/lib/net" }
ferrumc-text = { path = "src/lib/text" }
ferrumc-net-encryption = { path = "src/lib/net/crates/encryption" }
ferrumc-net-codec = { path = "src/lib/net/crates/codec" }
ferrumc-plugins = { path = "src/lib/plugins" }
Expand Down Expand Up @@ -112,25 +114,27 @@ rand = "0.9.0-alpha.2"
fnv = "1.0.7"

# Encoding/Serialization
serde = "1.0.210"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
serde_derive = "1.0.210"
base64 = "0.22.1"
bitcode = "0.6.3"
bitcode_derive = "0.6.3"


# Data types
hashbrown = "0.15.0"
tinyvec = "1.8.0"
dashmap = "6.1.0"
uuid = "1.1"
uuid = { version = "1.1", features = ["v4", "v3", "serde"] }

# Macros
lazy_static = "1.5.0"
quote = "1.0.37"
syn = "2.0.77"
proc-macro2 = "1.0.86"
proc-macro-crate = "3.2.0"
paste = "1.0.15"
maplit = "1.0.2"
macro_rules_attribute = "0.2.0"

Expand All @@ -155,6 +159,7 @@ colored = "2.1.0"
deepsize = "0.2.0"
bitreader = "0.3.11"


# I/O
tempfile = "3.12.0"
memmap2 = "0.9.5"
Expand All @@ -170,4 +175,4 @@ debug = false
debug-assertions = false
overflow-checks = false
panic = "abort"
codegen-units = 1
codegen-units = 1
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ etc. live) by setting an environment variable `FERRUMC_ROOT` to the path of the
`set FERRUMC_ROOT=C:\Users\ReCor\Documents\Code\Rust\ferrumc` before running the server. This is useful if you
can't move the place the binary is executed from (`cargo run` for example).*

---

## Nightly Dev Server

There is a nightly deployed version of rewrite/v3 running at `ferrumc.nimq.xyz`.

## Docs

Documentation for rewrite/v3 can be found at:

- Unsecure https://docs.ferrumc.com/
- HTTPS https://docs.nimq.xyz/

## Funding / Donations

If you would like to donate to the development of FerrumC, you can do so via the following methods:

- OpenCollective: https://opencollective.com/ferrumc


2 changes: 1 addition & 1 deletion assets/plans/plans.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@


- [ ] Database
- [x] [redb](https://www.redb.org/)
- [ ] [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) (K/V Store)
- [ ] Hash(key) => Value

Expand All @@ -58,7 +59,6 @@
- [x] Auto init with reflections
- [ ] support multiple versions (map versions packet id etc)


- [ ] Redstone
- [ ] Compile redstone, lightweight impl (fast & accurate)

Expand Down
94 changes: 65 additions & 29 deletions src/bin/src/packet_handlers/login_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use ferrumc_macros::event_handler;
use ferrumc_net::connection::{ConnectionState, StreamWriter};
use ferrumc_net::errors::NetError;
use ferrumc_net::packets::incoming::ack_finish_configuration::AckFinishConfigurationEvent;
use ferrumc_net::packets::incoming::keep_alive::IncomingKeepAlivePacket;
use ferrumc_net::packets::incoming::login_acknowledged::LoginAcknowledgedEvent;
use ferrumc_net::packets::incoming::login_start::LoginStartEvent;
use ferrumc_net::packets::incoming::server_bound_known_packs::ServerBoundKnownPacksEvent;
use ferrumc_net::packets::outgoing::client_bound_known_packs::ClientBoundKnownPacksPacket;
use ferrumc_net::packets::outgoing::finish_configuration::FinishConfigurationPacket;
use ferrumc_net::packets::outgoing::game_event::GameEventPacket;
use ferrumc_net::packets::outgoing::keep_alive::{KeepAlive, KeepAlivePacket};
use ferrumc_net::packets::outgoing::keep_alive::OutgoingKeepAlivePacket;
use ferrumc_net::packets::outgoing::login_play::LoginPlayPacket;
use ferrumc_net::packets::outgoing::login_success::LoginSuccessPacket;
use ferrumc_net::packets::outgoing::registry_data::get_registry_packets;
Expand All @@ -34,19 +36,23 @@ async fn handle_login_start(
let username = login_start_event.login_start_packet.username.as_str();
debug!("Received login start from user with username {}", username);


// Add the player identity component to the ECS for the entity.
state.universe.add_component::<PlayerIdentity>(
login_start_event.conn_id,
PlayerIdentity::new(username.to_string(), uuid),
)?;

//Send a Login Success Response to further the login sequence
let mut writer = state
.universe
.get_mut::<StreamWriter>(login_start_event.conn_id)?;

writer.send_packet(&LoginSuccessPacket::new(uuid, username), &NetEncodeOpts::WithLength).await?;
writer
.send_packet(
&LoginSuccessPacket::new(uuid, username),
&NetEncodeOpts::WithLength,
)
.await?;

Ok(login_start_event)
}
Expand All @@ -65,15 +71,16 @@ async fn handle_login_acknowledged(

*connection_state = ConnectionState::Configuration;


// Send packets packet
let client_bound_known_packs = ClientBoundKnownPacksPacket::new();

let mut writer = state
.universe
.get_mut::<StreamWriter>(login_acknowledged_event.conn_id)?;

writer.send_packet(&client_bound_known_packs, &NetEncodeOpts::WithLength).await?;
writer
.send_packet(&client_bound_known_packs, &NetEncodeOpts::WithLength)
.await?;

Ok(login_acknowledged_event)
}
Expand All @@ -90,10 +97,17 @@ async fn handle_server_bound_known_packs(
.get_mut::<StreamWriter>(server_bound_known_packs_event.conn_id)?;

let registry_packets = get_registry_packets();
writer.send_packet(&registry_packets, &NetEncodeOpts::None).await?;

writer.send_packet(&FinishConfigurationPacket::new(), &NetEncodeOpts::WithLength).await?;

writer
.send_packet(&registry_packets, &NetEncodeOpts::None)
.await?;

writer
.send_packet(
&FinishConfigurationPacket::new(),
&NetEncodeOpts::WithLength,
)
.await?;

Ok(server_bound_known_packs_event)
}

Expand All @@ -106,9 +120,7 @@ async fn handle_ack_finish_configuration(

let conn_id = ack_finish_configuration_event.conn_id;

let mut conn_state = state
.universe
.get_mut::<ConnectionState>(conn_id)?;
let mut conn_state = state.universe.get_mut::<ConnectionState>(conn_id)?;

*conn_state = ConnectionState::Play;

Expand All @@ -120,28 +132,52 @@ async fn handle_ack_finish_configuration(
.add_component::<OnGround>(conn_id, OnGround::default())?;


let mut writer = state
.universe
.get_mut::<StreamWriter>(conn_id)?;

writer.send_packet(&LoginPlayPacket::new(conn_id), &NetEncodeOpts::WithLength).await?;
writer.send_packet(&SetDefaultSpawnPositionPacket::default(), &NetEncodeOpts::WithLength).await?;
writer.send_packet(&SynchronizePlayerPositionPacket::default(), &NetEncodeOpts::WithLength).await?;
writer.send_packet(&GameEventPacket::start_waiting_for_level_chunks(), &NetEncodeOpts::WithLength).await?;
let mut writer = state.universe.get_mut::<StreamWriter>(conn_id)?;

writer
.send_packet(&LoginPlayPacket::new(conn_id), &NetEncodeOpts::WithLength)
.await?;
writer
.send_packet(
&SetDefaultSpawnPositionPacket::default(),
&NetEncodeOpts::WithLength,
)
.await?;
writer
.send_packet(
&SynchronizePlayerPositionPacket::default(),
&NetEncodeOpts::WithLength,
)
.await?;
writer
.send_packet(
&GameEventPacket::start_waiting_for_level_chunks(),
&NetEncodeOpts::WithLength,
)
.await?;

send_keep_alive(conn_id, state, &mut writer).await?;


Ok(ack_finish_configuration_event)
}
async fn send_keep_alive(conn_id: usize, state: GlobalState, writer: &mut ComponentRefMut<'_, StreamWriter>) -> Result<(), NetError> {
let keep_alive_packet = KeepAlivePacket::default();
writer.send_packet(&keep_alive_packet, &NetEncodeOpts::WithLength).await?;

let id = keep_alive_packet.id;
async fn send_keep_alive(
conn_id: usize,
state: GlobalState,
writer: &mut ComponentRefMut<'_, StreamWriter>,
) -> Result<(), NetError> {
let keep_alive_packet = OutgoingKeepAlivePacket::default();
writer
.send_packet(&keep_alive_packet, &NetEncodeOpts::WithLength)
.await?;

state.universe.add_component::<KeepAlive>(conn_id, id)?;
let timestamp = keep_alive_packet.timestamp;

state
.universe
.add_component::<OutgoingKeepAlivePacket>(conn_id, keep_alive_packet)?;
state
.universe
.add_component::<IncomingKeepAlivePacket>(conn_id, IncomingKeepAlivePacket { timestamp })?;

Ok(())
}
}
Loading

0 comments on commit 9da8487

Please sign in to comment.