mirror of
https://github.com/zyllian/classics.git
synced 2025-01-18 03:32:41 -08:00
support LongerMessages, resolves #33
This commit is contained in:
parent
3f5a869f78
commit
b93e35c36b
3 changed files with 42 additions and 3 deletions
|
@ -200,6 +200,9 @@ impl ExtBitmask {
|
||||||
// this isn't actually used by the server at all, but it technically sort of implements it
|
// this isn't actually used by the server at all, but it technically sort of implements it
|
||||||
Self::HeldBlock => ExtInfo::new("HeldBlock".to_string(), 1, Self::HeldBlock),
|
Self::HeldBlock => ExtInfo::new("HeldBlock".to_string(), 1, Self::HeldBlock),
|
||||||
Self::EmoteFix => ExtInfo::new("EmoteFix".to_string(), 1, Self::EmoteFix),
|
Self::EmoteFix => ExtInfo::new("EmoteFix".to_string(), 1, Self::EmoteFix),
|
||||||
|
Self::LongerMessages => {
|
||||||
|
ExtInfo::new("LongerMessages".to_string(), 1, Self::LongerMessages)
|
||||||
|
}
|
||||||
// TODO: render CP437 properly in server output
|
// TODO: render CP437 properly in server output
|
||||||
Self::FullCP437 => ExtInfo::new("FullCP437".to_string(), 1, Self::FullCP437),
|
Self::FullCP437 => ExtInfo::new("FullCP437".to_string(), 1, Self::FullCP437),
|
||||||
Self::EnvWeatherType => {
|
Self::EnvWeatherType => {
|
||||||
|
|
|
@ -58,6 +58,15 @@ impl ServerData {
|
||||||
player.packets_to_send.push(packet.clone());
|
player.packets_to_send.push(packet.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// spreads multiple packets to all players
|
||||||
|
pub fn spread_packets(&mut self, packets: &[ServerPacket]) {
|
||||||
|
for player in &mut self.players {
|
||||||
|
for packet in packets {
|
||||||
|
player.packets_to_send.push(packet.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
level::{block::BLOCK_INFO, BlockUpdate, Level},
|
level::{block::BLOCK_INFO, BlockUpdate, Level},
|
||||||
packet::{
|
packet::{
|
||||||
client::ClientPacket, server::ServerPacket, ExtBitmask, PacketWriter, ARRAY_LENGTH,
|
client::ClientPacket, server::ServerPacket, ExtBitmask, PacketWriter, ARRAY_LENGTH,
|
||||||
EXTENSION_MAGIC_NUMBER,
|
EXTENSION_MAGIC_NUMBER, STRING_LENGTH,
|
||||||
},
|
},
|
||||||
player::{Player, PlayerType},
|
player::{Player, PlayerType},
|
||||||
server::config::ServerProtectionMode,
|
server::config::ServerProtectionMode,
|
||||||
|
@ -132,6 +132,7 @@ async fn handle_stream_inner(
|
||||||
own_id: &mut i8,
|
own_id: &mut i8,
|
||||||
) -> Result<(), GeneralError> {
|
) -> Result<(), GeneralError> {
|
||||||
let mut reply_queue: Vec<ServerPacket> = Vec::new();
|
let mut reply_queue: Vec<ServerPacket> = Vec::new();
|
||||||
|
let mut incoming_message: Vec<String> = Vec::new();
|
||||||
|
|
||||||
macro_rules! msg {
|
macro_rules! msg {
|
||||||
($message:expr) => {
|
($message:expr) => {
|
||||||
|
@ -411,6 +412,22 @@ async fn handle_stream_inner(
|
||||||
ClientPacket::Message { player_id, message } => {
|
ClientPacket::Message { player_id, message } => {
|
||||||
let mut data = data.write().await;
|
let mut data = data.write().await;
|
||||||
|
|
||||||
|
let player = data
|
||||||
|
.players
|
||||||
|
.iter()
|
||||||
|
.find(|p| p.id == *own_id)
|
||||||
|
.expect("missing player");
|
||||||
|
let message = if player.extensions.contains(ExtBitmask::LongerMessages) {
|
||||||
|
incoming_message.push(message);
|
||||||
|
if player_id == 0 {
|
||||||
|
incoming_message.drain(..).collect()
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(message) = message.strip_prefix(Command::PREFIX) {
|
if let Some(message) = message.strip_prefix(Command::PREFIX) {
|
||||||
match Command::parse(message) {
|
match Command::parse(message) {
|
||||||
Ok(cmd) => {
|
Ok(cmd) => {
|
||||||
|
@ -424,7 +441,8 @@ async fn handle_stream_inner(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("{message}");
|
println!("{message}");
|
||||||
let message = format!(
|
let mut messages = Vec::new();
|
||||||
|
let mut message = format!(
|
||||||
"&f<{}> {message}",
|
"&f<{}> {message}",
|
||||||
data.players
|
data.players
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -432,7 +450,16 @@ async fn handle_stream_inner(
|
||||||
.expect("should never fail")
|
.expect("should never fail")
|
||||||
.username
|
.username
|
||||||
);
|
);
|
||||||
data.spread_packet(ServerPacket::Message { player_id, message });
|
while message.len() > STRING_LENGTH {
|
||||||
|
// TODO: split on whitespace if possible
|
||||||
|
let new_message = message.split_off(STRING_LENGTH);
|
||||||
|
// TODO: this will overwrite color codes and it shouldn't
|
||||||
|
messages.push(ServerPacket::Message { player_id, message });
|
||||||
|
message = format!("&f{new_message}");
|
||||||
|
}
|
||||||
|
messages.push(ServerPacket::Message { player_id, message });
|
||||||
|
println!("{messages:#?}");
|
||||||
|
data.spread_packets(&messages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue