-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/commands
- Loading branch information
Showing
55 changed files
with
2,113 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)};") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.