Skip to content

Commit 685e2f6

Browse files
committed
Revert "Move plugin message handling to plugin_messages::PluginMessageHandler"
This reverts commit f91f592.
1 parent f91f592 commit 685e2f6

File tree

2 files changed

+37
-47
lines changed

2 files changed

+37
-47
lines changed

src/server/mod.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ pub struct Server {
5656
resources: Arc<RwLock<resources::Manager>>,
5757
version: usize,
5858

59-
plugin_message_handler: plugin_messages::PluginMessageHandler,
60-
6159
// Entity accessors
6260
game_info: ecs::Key<entity::GameInfo>,
6361
player_movement: ecs::Key<entity::player::PlayerMovement>,
@@ -294,8 +292,6 @@ impl Server {
294292
version,
295293
resources,
296294

297-
plugin_message_handler: plugin_messages::PluginMessageHandler {},
298-
299295
// Entity accessors
300296
game_info,
301297
player_movement: entities.get_key(),
@@ -674,11 +670,46 @@ impl Server {
674670
}
675671

676672
fn on_plugin_message_clientbound_i16(&mut self, msg: packet::play::clientbound::PluginMessageClientbound_i16) {
677-
self.plugin_message_handler.on_plugin_message_clientbound(&msg.channel, msg.data.data.as_slice())
673+
self.on_plugin_message_clientbound(&msg.channel, msg.data.data.as_slice())
678674
}
679675

680676
fn on_plugin_message_clientbound_1(&mut self, msg: packet::play::clientbound::PluginMessageClientbound) {
681-
self.plugin_message_handler.on_plugin_message_clientbound(&msg.channel, &msg.data)
677+
self.on_plugin_message_clientbound(&msg.channel, &msg.data)
678+
}
679+
680+
fn on_plugin_message_clientbound(&mut self, channel: &str, data: &[u8]) {
681+
println!("Received plugin message: channel={}, data={:?}", channel, data);
682+
683+
match channel {
684+
// TODO: "REGISTER" =>
685+
// TODO: "UNREGISTER" =>
686+
"FML|HS" => {
687+
// https://wiki.vg/Minecraft_Forge_Handshake
688+
let discriminator = data[0];
689+
690+
match discriminator {
691+
0 => {
692+
// ServerHello
693+
let fml_protocol_version = data[1];
694+
let dimension = if fml_protocol_version > 1 {
695+
use byteorder::{BigEndian, ReadBytesExt};
696+
let dimension = (&data[2..2 + 4]).read_u32::<BigEndian>().unwrap();
697+
Some(dimension)
698+
} else {
699+
None
700+
};
701+
702+
println!("FML|HS ServerHello: fml_protocol_version={}, dimension={:?}", fml_protocol_version, dimension);
703+
704+
// TODO: send reply
705+
},
706+
_ => {
707+
println!("Unhandled FML|HS packet: discriminator={}", discriminator);
708+
}
709+
}
710+
}
711+
_ => ()
712+
}
682713
}
683714

684715
fn on_game_join_i32_viewdistance(&mut self, join: packet::play::clientbound::JoinGame_i32_ViewDistance) {

src/server/plugin_messages.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,6 @@ use crate::protocol::Serializable;
33
use crate::protocol::packet::play::serverbound::PluginMessageServerbound;
44
use crate::protocol::packet::play::serverbound::PluginMessageServerbound_i16;
55

6-
pub struct PluginMessageHandler {
7-
}
8-
9-
impl PluginMessageHandler {
10-
pub fn on_plugin_message_clientbound(&mut self, channel: &str, data: &[u8]) {
11-
println!("Received plugin message: channel={}, data={:?}", channel, data);
12-
13-
match channel {
14-
// TODO: "REGISTER" =>
15-
// TODO: "UNREGISTER" =>
16-
"FML|HS" => {
17-
// https://wiki.vg/Minecraft_Forge_Handshake
18-
let discriminator = data[0];
19-
20-
match discriminator {
21-
0 => {
22-
// ServerHello
23-
let fml_protocol_version = data[1];
24-
let dimension = if fml_protocol_version > 1 {
25-
use byteorder::{BigEndian, ReadBytesExt};
26-
let dimension = (&data[2..2 + 4]).read_u32::<BigEndian>().unwrap();
27-
Some(dimension)
28-
} else {
29-
None
30-
};
31-
32-
println!("FML|HS ServerHello: fml_protocol_version={}, dimension={:?}", fml_protocol_version, dimension);
33-
34-
// TODO: send reply
35-
},
36-
_ => {
37-
println!("Unhandled FML|HS packet: discriminator={}", discriminator);
38-
}
39-
}
40-
}
41-
_ => ()
42-
}
43-
}
44-
}
45-
46-
476
pub struct Brand {
487
pub brand: String,
498
}

0 commit comments

Comments
 (0)