get uuid and stuff working

This commit is contained in:
Danton 2020-07-09 14:03:42 -07:00
parent e9e0dc6b91
commit 4b8717c8b4
4 changed files with 910 additions and 5 deletions

859
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,3 +15,4 @@ toml = "0.5.6"
serde = { version = "1.0.114", features = ["serde_derive"]} serde = { version = "1.0.114", features = ["serde_derive"]}
base64 = "0.12.3" base64 = "0.12.3"
radix64 = "0.3.0" radix64 = "0.3.0"
mojang-api = "0.6.1"

View File

@ -4,11 +4,17 @@
// The module with everything to do with networkng. // The module with everything to do with networkng.
extern crate radix64; extern crate radix64;
extern crate ozelot;
extern crate mojang_api;
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 std::net::{TcpListener, TcpStream}; use std::net::{TcpListener, TcpStream};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::thread::sleep;
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);
@ -119,6 +125,34 @@ fn handle_client(t: TcpStream) -> std::io::Result<()> {
let (_packet_len, _packet_id) = read_packet_header(&mut gc.stream)?; let (_packet_len, _packet_id) = read_packet_header(&mut gc.stream)?;
let login = LoginStart::read(&mut gc.stream)?; let login = LoginStart::read(&mut gc.stream)?;
log.info(&format!("{:?}", login)); log.info(&format!("{:?}", login));
let packet_id = MCVarInt::from(0x02);
let packet_len = MCVarInt::from(packet_id.to_bytes().len() as i32 + 52i32);
let user = ozelot::mojang::NameToUUID::new(login.username.value, None);
let nameUUIDbundle = user.perform().unwrap();
log.info(&format!("{:?}", nameUUIDbundle));
let mut uuidLong = nameUUIDbundle.id;
uuidLong.insert(8, '-');
uuidLong.insert(13, '-');
uuidLong.insert(18, '-');
uuidLong.insert(23, '-');
log.info(&format!("Long UUID: {:?}", uuidLong));
for b in packet_len.to_bytes() {
write_byte(&mut gc.stream, b)?;
}
for b in packet_id.to_bytes() {
write_byte(&mut gc.stream, b)?;
}
for b in uuidLong.as_bytes() {
write_byte(&mut gc.stream, *b)?;
}
for b in nameUUIDbundle.name.as_bytes() {
write_byte(&mut gc.stream, *b)?;
}
gc.state = GameState::Play;
} }
GameState::Play => {} GameState::Play => {}
GameState::Closed => { GameState::Closed => {

View File

@ -79,3 +79,24 @@ impl LoginStart {
self.username.to_bytes() self.username.to_bytes()
} }
} }
#[derive(Debug)]
pub struct LoginSuccess {
pub uuid: MCString,
pub username: MCString,
}
impl LoginSuccess {
pub fn new(uuid: MCString, username: MCString) -> LoginSuccess {
LoginSuccess {uuid, username}
}
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
for b in self.uuid.to_bytes() {
bytes.push(b);
}
for b in self.username.to_bytes() {
bytes.push(b);
}
bytes
}
}