more helper functions
This commit is contained in:
parent
50262ff1d7
commit
4d04729809
@ -25,4 +25,3 @@ impl ReadWritePosition for Packet {
|
|||||||
Ok(self.write_long(((x & 0x3FFFFFF) << 38) | ((z & 0x3FFFFFF) << 12) | (y & 0xFFF))?)
|
Ok(self.write_long(((x & 0x3FFFFFF) << 38) | ((z & 0x3FFFFFF) << 12) | (y & 0xFFF))?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,32 @@ impl ProtocolHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset_chat(&self) -> Result<(), ServerError> {
|
||||||
|
match self.state {
|
||||||
|
ConnectionState::Configuration => {
|
||||||
|
self.client
|
||||||
|
.write_packet(&Packet::empty(clientbound::configuration::RESET_CHAT))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(ServerError::UnexpectedState),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn store_cookie(&self, id: &str, data: &[u8]) -> Result<(), ServerError> {
|
||||||
|
self.client.write_packet(&Packet::build(
|
||||||
|
match self.state {
|
||||||
|
ConnectionState::Configuration => clientbound::configuration::STORE_COOKIE,
|
||||||
|
ConnectionState::Play => clientbound::play::STORE_COOKIE,
|
||||||
|
_ => { return Err(ServerError::UnexpectedState) },
|
||||||
|
},
|
||||||
|
|p| {
|
||||||
|
p.write_string(id)?;
|
||||||
|
p.write_bytes(data)
|
||||||
|
},
|
||||||
|
)?)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Leave from Configuration to Play state
|
/// Leave from Configuration to Play state
|
||||||
pub fn leave_configuration(&self) -> Result<(), ServerError> {
|
pub fn leave_configuration(&self) -> Result<(), ServerError> {
|
||||||
match self.state {
|
match self.state {
|
||||||
@ -132,6 +158,24 @@ impl ProtocolHelper {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Ok(data)
|
||||||
|
},
|
||||||
|
ConnectionState::Play => {
|
||||||
|
let mut packet = Packet::empty(clientbound::play::COOKIE_REQUEST);
|
||||||
|
packet.write_string(id)?;
|
||||||
|
self.client.write_packet(&packet)?;
|
||||||
|
|
||||||
|
let mut packet = self
|
||||||
|
.client
|
||||||
|
.read_packet(serverbound::play::COOKIE_RESPONSE)?;
|
||||||
|
packet.read_string()?;
|
||||||
|
let data = if packet.read_boolean()? {
|
||||||
|
let n = packet.read_usize_varint()?;
|
||||||
|
Some(packet.read_bytes(n)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
_ => Err(ServerError::UnexpectedState),
|
_ => Err(ServerError::UnexpectedState),
|
||||||
|
Loading…
Reference in New Issue
Block a user