Get Login Response working
This commit is contained in:
parent
fd95cab64c
commit
ecbe983205
49
src/net.rs
49
src/net.rs
@ -3,18 +3,18 @@
|
|||||||
// description:
|
// description:
|
||||||
// The module with everything to do with networkng.
|
// The module with everything to do with networkng.
|
||||||
|
|
||||||
extern crate radix64;
|
|
||||||
extern crate ozelot;
|
|
||||||
extern crate mojang_api;
|
extern crate mojang_api;
|
||||||
|
extern crate ozelot;
|
||||||
|
extern crate radix64;
|
||||||
|
|
||||||
use mojang_api::*;
|
|
||||||
use ozelot::mojang::*;
|
|
||||||
use crate::mctypes::*;
|
use crate::mctypes::*;
|
||||||
use crate::protocol::*;
|
use crate::protocol::*;
|
||||||
use crate::{config, log};
|
use crate::{config, log};
|
||||||
|
use mojang_api::*;
|
||||||
|
use ozelot::mojang::*;
|
||||||
use std::net::{TcpListener, TcpStream};
|
use std::net::{TcpListener, TcpStream};
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
pub fn start_listening() {
|
pub fn start_listening() {
|
||||||
let server_address: &str = &format!("0.0.0.0:{}", config.port);
|
let server_address: &str = &format!("0.0.0.0:{}", config.port);
|
||||||
@ -129,29 +129,32 @@ fn handle_client(t: TcpStream) -> std::io::Result<()> {
|
|||||||
let packet_id = MCVarInt::from(0x02);
|
let packet_id = MCVarInt::from(0x02);
|
||||||
let packet_len = MCVarInt::from(packet_id.to_bytes().len() as i32 + 54i32);
|
let packet_len = MCVarInt::from(packet_id.to_bytes().len() as i32 + 54i32);
|
||||||
|
|
||||||
let user = ozelot::mojang::NameToUUID::new(login.username.value, None);
|
let nameUUIDbundle =
|
||||||
let nameUUIDbundle = user.perform().unwrap();
|
ozelot::mojang::NameToUUID::new(login.clone().username.value, None)
|
||||||
log.info(&format!("{:?}", nameUUIDbundle));
|
.perform()
|
||||||
let mut uuidLong = nameUUIDbundle.id;
|
.unwrap();
|
||||||
uuidLong.insert(8, '-');
|
let username = nameUUIDbundle.name;
|
||||||
uuidLong.insert(13, '-');
|
let mut hyphenatedUUID = nameUUIDbundle.id;
|
||||||
uuidLong.insert(18, '-');
|
hyphenatedUUID.insert(8, '-');
|
||||||
uuidLong.insert(23, '-');
|
hyphenatedUUID.insert(13, '-');
|
||||||
log.info(&format!("Long UUID: {:?}", uuidLong));
|
hyphenatedUUID.insert(18, '-');
|
||||||
|
hyphenatedUUID.insert(23, '-');
|
||||||
for b in packet_len.to_bytes() {
|
let login_success_packet =
|
||||||
write_byte(&mut gc.stream, b)?;
|
LoginSuccess::new(MCString::from(hyphenatedUUID), MCString::from(username));
|
||||||
}
|
let mut bytes = Vec::new();
|
||||||
for b in packet_id.to_bytes() {
|
for b in packet_id.to_bytes() {
|
||||||
|
bytes.push(b);
|
||||||
|
}
|
||||||
|
for b in login_success_packet.to_bytes() {
|
||||||
|
bytes.push(b);
|
||||||
|
}
|
||||||
|
for b in MCVarInt::from(bytes.len() as i32).to_bytes() {
|
||||||
write_byte(&mut gc.stream, b)?;
|
write_byte(&mut gc.stream, b)?;
|
||||||
}
|
}
|
||||||
for b in MCString::from(uuidLong).to_bytes() {
|
for b in bytes {
|
||||||
write_byte(&mut gc.stream, b)?;
|
write_byte(&mut gc.stream, b)?;
|
||||||
}
|
}
|
||||||
for b in MCString::from(nameUUIDbundle.name).to_bytes() {
|
log.info(&format!("{:?}", login_success_packet));
|
||||||
write_byte(&mut gc.stream, b)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
gc.state = GameState::Play;
|
gc.state = GameState::Play;
|
||||||
}
|
}
|
||||||
GameState::Play => {}
|
GameState::Play => {}
|
||||||
|
@ -13,7 +13,7 @@ pub fn read_packet_header(t: &mut TcpStream) -> std::io::Result<(MCVarInt, MCVar
|
|||||||
Ok((length, id))
|
Ok((length, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Handshake {
|
pub struct Handshake {
|
||||||
pub protocol_version: MCVarInt,
|
pub protocol_version: MCVarInt,
|
||||||
pub server_address: MCString,
|
pub server_address: MCString,
|
||||||
@ -64,7 +64,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LoginStart {
|
pub struct LoginStart {
|
||||||
pub username: MCString,
|
pub username: MCString,
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ impl LoginStart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LoginSuccess {
|
pub struct LoginSuccess {
|
||||||
pub uuid: MCString,
|
pub uuid: MCString,
|
||||||
pub username: MCString,
|
pub username: MCString,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user