Verified Commit 60782811 authored by insert's avatar insert 🎺

Progress on login, added PLAY packets. 0x05, 0x0B

parent 64a36dbd
......@@ -52,8 +52,8 @@ struct ServerListPing {
fn get_status() -> Result<String, serde_json::error::Error> {
let mut status = ServerListPing {
version: SLPVersion {
name: "1.8.9".to_owned(),
protocol: 47
name: "1.14.4".to_owned(),
protocol: 498
},
players: SLPPlayers {
max: 1337,
......@@ -133,7 +133,7 @@ fn handle_packet(client: &mut Client, cur: &mut Cursor<&mut [u8]>, length: u64)
match client.state {
State::HANDSHAKE => {
match id {
0 => {
0x00 => {
// Handshake
let protocol = cur.read_var_int().unwrap().value;
......@@ -158,14 +158,14 @@ fn handle_packet(client: &mut Client, cur: &mut Cursor<&mut [u8]>, length: u64)
}
State::STATUS => {
match id {
0 => {
0x00 => {
// Request
let mut buf = Vec::<u8>::new();
buf.write_string(get_status().unwrap()).unwrap();
client.send(0, &mut buf).unwrap();
client.send(0x00, &mut buf).unwrap();
}
1 => {
0x01 => {
// Ping
let payload = cur.read_ilong().unwrap();
......@@ -173,31 +173,61 @@ fn handle_packet(client: &mut Client, cur: &mut Cursor<&mut [u8]>, length: u64)
let mut buf = Vec::<u8>::new();
buf.write_ilong(payload).unwrap();
client.send(1, &mut buf).unwrap();
client.send(0x01, &mut buf).unwrap();
}
_ => client.unknown_packet(id)
}
}
State::LOGIN => {
match id {
0 => {
0x00 => {
// Login Start
let username = cur.read_string(Some(16)).unwrap();
client.println("login", &format!("{} is logging in.", username.yellow()));
//let mut buf = Vec::<u8>::new();
//buf.write_string("{\"text\":\"ur mom gay\"}".to_owned()).unwrap();
//client.send(0, &mut buf).unwrap();
let mut buf1 = Vec::<u8>::new();
buf1.write_string("4db72998-a62e-4be5-b6de-02ed1dd82847".to_owned()).unwrap();
buf1.write_string("Insertish".to_owned()).unwrap();
client.send(0x02, &mut buf1).unwrap();
client.state = State::PLAY;
let mut buf2 = Vec::<u8>::new();
buf2.write_iint(7).unwrap();
buf2.write_ubyte(1).unwrap();
buf2.write_iint(0).unwrap();
buf2.write_ubyte(0).unwrap();
buf2.write_string("default".to_owned()).unwrap();
buf2.write_var_int(8).unwrap();
buf2.write_bool(false).unwrap();
client.send(0x25, &mut buf2).unwrap();
}
_ => client.unknown_packet(id)
}
}
State::PLAY => {
match id {
0x05 => {
// Client Settings
let locale = cur.read_string(Some(16)).unwrap();
let view_distance = cur.read_ibyte().unwrap();
let chat_mode = cur.read_var_int().unwrap();
let _chat_colors = cur.read_bool().unwrap();
let _displayed_skin = cur.read_ubyte().unwrap();
let _main_hand = cur.read_var_int().unwrap();
println!("Locale: {}\nView Distance: {}\nChat mode: {}", locale, view_distance, chat_mode.value);
}
0x0B => {
// Plugin Message
let channel = cur.read_string(None).unwrap();
client.println("plugin", &format!("received message from channel {}", channel));
}
_ => client.unknown_packet(id)
}
}
......
......@@ -74,10 +74,30 @@ pub trait MinecraftRead: Read + VarIntRead {
Ok(String::from_utf8(buf).unwrap())
}
fn read_bool(&mut self) -> Result<bool, Error> {
if self.read_u8().unwrap() > 0 {
return Ok(true)
} else {
return Ok(false)
}
}
fn read_ubyte(&mut self) -> Result<u8, Error> {
self.read_u8()
}
fn read_ibyte(&mut self) -> Result<i8, Error> {
self.read_i8()
}
fn read_ushort(&mut self) -> Result<u16, Error> {
self.read_u16::<LittleEndian>()
}
fn read_iint(&mut self) -> Result<i32, Error> {
self.read_i32::<LittleEndian>()
}
fn read_ilong(&mut self) -> Result<i64, Error> {
self.read_i64::<LittleEndian>()
}
......
......@@ -35,6 +35,18 @@ pub trait MinecraftWrite: Write + VarIntWrite {
self.write(string.as_bytes())
}
fn write_bool(&mut self, boolean: bool) -> Result<()> {
self.write_u8(if boolean { 0x01 } else { 0x00 })
}
fn write_ubyte(&mut self, byte: u8) -> Result<()> {
self.write_u8(byte)
}
fn write_iint(&mut self, int: i32) -> Result<()> {
self.write_i32::<LittleEndian>(int)
}
fn write_ilong(&mut self, long: i64) -> Result<()> {
self.write_i64::<LittleEndian>(long)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment