error display + remove unused imports
This commit is contained in:
parent
abb717f4cf
commit
a3fd9dc40b
@ -1,6 +1,5 @@
|
||||
use std::{net::TcpListener, sync::{Arc, Mutex}, thread};
|
||||
|
||||
use rust_mc_proto::{DataBufferReader, DataBufferWriter, MCConn, MCConnTcp, MinecraftConnection, Packet, ProtocolError};
|
||||
use rust_mc_proto::{DataBufferReader, DataBufferWriter, MCConnTcp, MinecraftConnection, Packet, ProtocolError};
|
||||
|
||||
/*
|
||||
|
||||
@ -44,7 +43,15 @@ fn accept_client(mut conn: MCConnTcp, server: Arc<Mutex<MinecraftServer>>) -> Re
|
||||
if handshake {
|
||||
if packet.id == 0x00 {
|
||||
let mut status = Packet::empty(0x00);
|
||||
status.write_string(&server.lock().unwrap().motd)?;
|
||||
|
||||
let serv = server.lock().unwrap();
|
||||
|
||||
let motd = serv.motd.clone();
|
||||
let motd = motd.replace(
|
||||
"PROTOCOL_VERSION",
|
||||
&serv.protocol_version.to_string());
|
||||
|
||||
status.write_string(&motd)?;
|
||||
conn.write_packet(&status)?;
|
||||
} else if packet.id == 0x01 {
|
||||
let mut status = Packet::empty(0x01);
|
||||
@ -83,7 +90,7 @@ fn main() {
|
||||
765,
|
||||
"{
|
||||
\"version\":{
|
||||
\"protocol\":765,
|
||||
\"protocol\":PROTOCOL_VERSION,
|
||||
\"name\":\"Version name\"
|
||||
},
|
||||
\"players\":{
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::{net::TcpListener, sync::{atomic::AtomicBool, atomic::Ordering}, thread};
|
||||
use std::sync::mpsc::channel;
|
||||
use rust_mc_proto::{DataBufferReader, DataBufferWriter, MCConn, MCConnTcp, MinecraftConnection, Packet, ProtocolError};
|
||||
use std::{net::TcpListener, thread, sync::mpsc::channel};
|
||||
use rust_mc_proto::{DataBufferReader, DataBufferWriter, MCConnTcp, Packet};
|
||||
|
||||
const LONG_TEXT: &str = "some_long_text_wow_123123123123123123123123";
|
||||
|
||||
|
18
src/lib.rs
18
src/lib.rs
@ -1,9 +1,5 @@
|
||||
use std::io::{Write, Read};
|
||||
use std::net::{TcpStream, ToSocketAddrs};
|
||||
|
||||
use flate2::read::ZlibDecoder;
|
||||
use flate2::write::ZlibEncoder;
|
||||
use flate2::{Compress, Compression, Decompress, FlushCompress, Status, FlushDecompress};
|
||||
use std::{error::Error, fmt, io::{Read, Write}, net::{TcpStream, ToSocketAddrs}};
|
||||
use flate2::{read::ZlibDecoder, write::ZlibEncoder, Compression};
|
||||
use bytebuffer::ByteBuffer;
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -34,6 +30,14 @@ pub enum ProtocolError {
|
||||
UnsignedShortError
|
||||
}
|
||||
|
||||
impl fmt::Display for ProtocolError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "An protocol error occured")
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ProtocolError {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Packet {
|
||||
pub id: u8,
|
||||
@ -358,7 +362,7 @@ impl DataBufferReader for Packet {
|
||||
fn read_bytes(&mut self, size: usize) -> Result<Vec<u8>, ProtocolError> {
|
||||
let mut buf = vec![0; size];
|
||||
match self.buffer.read_exact(&mut buf) {
|
||||
Ok(i) => Ok(buf),
|
||||
Ok(_) => Ok(buf),
|
||||
Err(_) => Err(ProtocolError::ReadError),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user