commit
25cb7d75fc
859
Cargo.lock
generated
859
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -15,3 +15,4 @@ toml = "0.5.6"
|
||||
serde = { version = "1.0.114", features = ["serde_derive"]}
|
||||
base64 = "0.12.3"
|
||||
radix64 = "0.3.0"
|
||||
mojang-api = "0.6.1"
|
||||
|
16
log.txt
16
log.txt
@ -400,3 +400,19 @@
|
||||
2020-07-08 22:25:40 [INFO] - Next state: Status
|
||||
2020-07-08 22:25:40 [INFO] - Ping number: MCLong { value: 4539076 }
|
||||
2020-07-08 22:25:40 [INFO] - Client at 192.168.0.88:55943 closed connection
|
||||
2020-07-09 14:07:50 [INFO] - Network thread started
|
||||
2020-07-09 14:07:50 [IMPORTANT] - Started server on 0.0.0.0:25565
|
||||
2020-07-09 14:07:59 [INFO] - Got a client!
|
||||
2020-07-09 14:07:59 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
|
||||
2020-07-09 14:07:59 [INFO] - Next state: Login
|
||||
2020-07-09 14:07:59 [INFO] - LoginStart { username: MCString { value: "NomCafeRage" } }
|
||||
2020-07-09 14:08:02 [INFO] - NameUUID { id: "3dc562e61c9047e4b5b02cd10cd895f2", name: "NomCafeRage", legacy: false, demo: false }
|
||||
2020-07-09 14:08:02 [INFO] - Long UUID: "3dc562e6-1c90-47e4-b5b0-2cd10cd895f2"
|
||||
2020-07-09 14:14:11 [INFO] - Network thread started
|
||||
2020-07-09 14:14:11 [IMPORTANT] - Started server on 0.0.0.0:25565
|
||||
2020-07-09 14:15:04 [INFO] - Got a client!
|
||||
2020-07-09 14:15:04 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
|
||||
2020-07-09 14:15:04 [INFO] - Next state: Login
|
||||
2020-07-09 14:15:04 [INFO] - LoginStart { username: MCString { value: "NomCafeRage" } }
|
||||
2020-07-09 14:15:07 [INFO] - NameUUID { id: "3dc562e61c9047e4b5b02cd10cd895f2", name: "NomCafeRage", legacy: false, demo: false }
|
||||
2020-07-09 14:15:07 [INFO] - Long UUID: "3dc562e6-1c90-47e4-b5b0-2cd10cd895f2"
|
||||
|
37
src/net.rs
37
src/net.rs
@ -3,12 +3,18 @@
|
||||
// description:
|
||||
// The module with everything to do with networkng.
|
||||
|
||||
extern crate mojang_api;
|
||||
extern crate ozelot;
|
||||
extern crate radix64;
|
||||
|
||||
use crate::mctypes::*;
|
||||
use crate::protocol::*;
|
||||
use crate::{config, log};
|
||||
use mojang_api::*;
|
||||
use ozelot::mojang::*;
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::thread::sleep;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub fn start_listening() {
|
||||
let server_address: &str = &format!("0.0.0.0:{}", config.port);
|
||||
@ -119,6 +125,37 @@ fn handle_client(t: TcpStream) -> std::io::Result<()> {
|
||||
let (_packet_len, _packet_id) = read_packet_header(&mut gc.stream)?;
|
||||
let login = LoginStart::read(&mut gc.stream)?;
|
||||
log.info(&format!("{:?}", login));
|
||||
|
||||
let packet_id = MCVarInt::from(0x02);
|
||||
let packet_len = MCVarInt::from(packet_id.to_bytes().len() as i32 + 54i32);
|
||||
|
||||
let nameUUIDbundle =
|
||||
ozelot::mojang::NameToUUID::new(login.clone().username.value, None)
|
||||
.perform()
|
||||
.unwrap();
|
||||
let username = nameUUIDbundle.name;
|
||||
let mut hyphenatedUUID = nameUUIDbundle.id;
|
||||
hyphenatedUUID.insert(8, '-');
|
||||
hyphenatedUUID.insert(13, '-');
|
||||
hyphenatedUUID.insert(18, '-');
|
||||
hyphenatedUUID.insert(23, '-');
|
||||
let login_success_packet =
|
||||
LoginSuccess::new(MCString::from(hyphenatedUUID), MCString::from(username));
|
||||
let mut bytes = Vec::new();
|
||||
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)?;
|
||||
}
|
||||
for b in bytes {
|
||||
write_byte(&mut gc.stream, b)?;
|
||||
}
|
||||
log.info(&format!("{:?}", login_success_packet));
|
||||
gc.state = GameState::Play;
|
||||
}
|
||||
GameState::Play => {}
|
||||
GameState::Closed => {
|
||||
|
@ -13,7 +13,7 @@ pub fn read_packet_header(t: &mut TcpStream) -> std::io::Result<(MCVarInt, MCVar
|
||||
Ok((length, id))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Handshake {
|
||||
pub protocol_version: MCVarInt,
|
||||
pub server_address: MCString,
|
||||
@ -64,7 +64,7 @@ impl Handshake {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LoginStart {
|
||||
pub username: MCString,
|
||||
}
|
||||
@ -79,3 +79,24 @@ impl LoginStart {
|
||||
self.username.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user