mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
[Protocol] Fix Minecraft Java query not being able to specify a hostname (#91)
* Make initial fix * Fix imports * Rename query_address to hostname and add this to the mc example * Fix master_querant example not compiling * Add extra safety on converting strings to Minecraft Varint strings * Add docs to RequestSettings * Fix formatting
This commit is contained in:
parent
211cd5fd5f
commit
a56ca45de6
8 changed files with 118 additions and 28 deletions
|
|
@ -20,16 +20,20 @@ pub trait Socket {
|
|||
|
||||
fn send(&mut self, data: &[u8]) -> GDResult<()>;
|
||||
fn receive(&mut self, size: Option<usize>) -> GDResult<Vec<u8>>;
|
||||
|
||||
fn port(&self) -> u16;
|
||||
}
|
||||
|
||||
pub struct TcpSocket {
|
||||
socket: net::TcpStream,
|
||||
address: SocketAddr,
|
||||
}
|
||||
|
||||
impl Socket for TcpSocket {
|
||||
fn new(address: &SocketAddr) -> GDResult<Self> {
|
||||
Ok(Self {
|
||||
socket: net::TcpStream::connect(address).map_err(|e| SocketConnect.context(e))?,
|
||||
address: *address,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +58,8 @@ impl Socket for TcpSocket {
|
|||
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn port(&self) -> u16 { self.address.port() }
|
||||
}
|
||||
|
||||
pub struct UdpSocket {
|
||||
|
|
@ -96,6 +102,8 @@ impl Socket for UdpSocket {
|
|||
|
||||
Ok(buf[.. number_of_bytes_received].to_vec())
|
||||
}
|
||||
|
||||
fn port(&self) -> u16 { self.address.port() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue