Finally fix all registries
This commit is contained in:
1 parent
d444f68093
commit
2fd3585af7
12 files changed
+146
-252
No files matched your search
@@ -1,7 +1,6 @@
|
||||
|
||||
use pumpkin_protocol::{
|
||||
client::{
|
||||
config::{CFinishConfig, CKnownPacks, CRegistryData, Entry},
|
||||
config::{CFinishConfig, CKnownPacks, CRegistryData},
|
||||
login::{CEncryptionRequest, CLoginSuccess},
|
||||
status::{CPingResponse, CStatusResponse},
|
||||
},
|
||||
@@ -13,7 +12,7 @@ use pumpkin_protocol::{
|
||||
},
|
||||
ConnectionState, KnownPack,
|
||||
};
|
||||
use pumpkin_registry::{DimensionCodec, WolfCodec};
|
||||
use pumpkin_registry::Registry;
|
||||
|
||||
use crate::{
|
||||
entity::player::{ChatMode, Hand},
|
||||
@@ -175,35 +174,13 @@ impl ClientPacketProcessor for Client {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_known_packs(&mut self, server: &mut Server, config_acknowledged: SKnownPacks) {
|
||||
self.send_packet(CRegistryData::new(
|
||||
"dimension_type",
|
||||
&[
|
||||
Entry {
|
||||
entry_id: "minecraft:dimension_type",
|
||||
has_data: true,
|
||||
data: &DimensionCodec::parse(),
|
||||
},
|
||||
Entry {
|
||||
entry_id: "minecraft:wolf_variant",
|
||||
has_data: true,
|
||||
data: &WolfCodec::parse(),
|
||||
},
|
||||
/* Entry {
|
||||
entry_id: "minecraft:worldgen/biome".into(),
|
||||
has_data: true,
|
||||
},
|
||||
Entry {
|
||||
entry_id: "minecraft:chat_type".into(),
|
||||
has_data: true,
|
||||
},
|
||||
Entry {
|
||||
entry_id: "minecraft:damage_type".into(),
|
||||
has_data: true,
|
||||
}, */
|
||||
],
|
||||
))
|
||||
.unwrap_or_else(|e| self.kick(&e.to_string()));
|
||||
fn handle_known_packs(&mut self, _server: &mut Server, _config_acknowledged: SKnownPacks) {
|
||||
for registry in Registry::get_static() {
|
||||
self.send_packet(CRegistryData::new(
|
||||
®istry.registry_id,
|
||||
®istry.registry_entries,
|
||||
)).unwrap_or_else(|e| self.kick(&e.to_string()));
|
||||
}
|
||||
|
||||
// We are done with configuring
|
||||
dbg!("finish config");
|
||||
|
||||
@@ -190,8 +190,8 @@ impl Client {
|
||||
}
|
||||
|
||||
// Reads the connection until our buffer of len 4096 is full, then decode
|
||||
/// Returns `true` if the connection is closed.
|
||||
pub fn poll(&mut self, server: &mut Server, event: &Event) -> Result<bool, io::Error> {
|
||||
/// Close connection when an error occurs
|
||||
pub fn poll(&mut self, server: &mut Server, event: &Event) {
|
||||
if event.is_readable() {
|
||||
let mut received_data = vec![0; 4096];
|
||||
let mut bytes_read = 0;
|
||||
@@ -201,7 +201,7 @@ impl Client {
|
||||
Ok(0) => {
|
||||
// Reading 0 bytes means the other side has closed the
|
||||
// connection or is done writing, then so are we.
|
||||
self.closed = true;
|
||||
self.close();
|
||||
break;
|
||||
}
|
||||
Ok(n) => {
|
||||
@@ -215,7 +215,7 @@ impl Client {
|
||||
Err(ref err) if would_block(err) => break,
|
||||
Err(ref err) if interrupted(err) => continue,
|
||||
// Other errors we'll consider fatal.
|
||||
Err(err) => return Err(err),
|
||||
Err(_) => self.close(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +234,6 @@ impl Client {
|
||||
self.dec.clear();
|
||||
}
|
||||
}
|
||||
Ok(self.closed)
|
||||
}
|
||||
|
||||
/// Kicks the Client with a reason depending on the connection state
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ fn main() -> io::Result<()> {
|
||||
token => {
|
||||
// Maybe received an event for a TCP connection.
|
||||
let done = if let Some(client) = connections.get_mut(&token) {
|
||||
client.poll(&mut server, event).unwrap();
|
||||
client.poll(&mut server, event);
|
||||
client.closed
|
||||
} else {
|
||||
// Sporadic events happen, we can safely ignore them.
|
||||
|
||||
+7
-12
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
io::{self, Cursor},
|
||||
io::Cursor,
|
||||
sync::atomic::{AtomicI32, Ordering},
|
||||
};
|
||||
|
||||
@@ -85,12 +85,7 @@ impl Server {
|
||||
}
|
||||
|
||||
// Returns Tokens to remove
|
||||
pub fn poll(
|
||||
&mut self,
|
||||
client: &mut Client,
|
||||
_poll: &Poll,
|
||||
event: &Event,
|
||||
) -> Result<bool, io::Error> {
|
||||
pub fn poll(&mut self, client: &mut Client, _poll: &Poll, event: &Event) {
|
||||
// todo, Poll players in every world
|
||||
client.poll(self, event)
|
||||
}
|
||||
@@ -106,19 +101,19 @@ impl Server {
|
||||
.send_packet(CLogin::new(
|
||||
player.entity_id(),
|
||||
self.difficulty == Difficulty::Hard,
|
||||
1,
|
||||
vec!["minecraft:overworld".into()],
|
||||
0,
|
||||
"minecraft:overworld".into(),
|
||||
self.max_players as VarInt,
|
||||
8, // view distance todo
|
||||
8, // sim view dinstance todo
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
1,
|
||||
0,
|
||||
"minecraft:overworld".into(),
|
||||
0, // seed
|
||||
GameMode::Survival.to_byte() as u8,
|
||||
GameMode::Undefined.to_byte(),
|
||||
GameMode::Spectator.to_byte() as u8,
|
||||
GameMode::Spectator.to_byte(),
|
||||
false,
|
||||
false,
|
||||
false, // deth loc
|
||||
|
||||
Reference in new issue
Block a user