Inital commit

This commit is contained in:
Paul Black 2023-10-15 21:03:34 -06:00
commit 0d746d2973
7 changed files with 254 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

75
Cargo.lock generated Normal file
View file

@ -0,0 +1,75 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "arrow-rs"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

9
Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "arrow-rs"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8"

21
LICENSE.md Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Paul Black
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

1
README.md Normal file
View file

@ -0,0 +1 @@
Not very functional (yet).

3
src/data_dumps.rs Normal file

File diff suppressed because one or more lines are too long

144
src/main.rs Normal file
View file

@ -0,0 +1,144 @@
use std::net::{TcpListener, TcpStream};
use std::io::{Read, Write};
use std::thread;
mod data_dumps;
fn handle_client(mut stream: TcpStream) {
let mut buffer = vec![0; 1024];
while let Ok(size) = stream.read(&mut buffer) {
if size == 0 {
println!("Client disconnected.");
break;
}
let packet_id = buffer[0];
println!("Received Packet ID: 0x{:02X}", packet_id);
// Print the hexadecimal representation of the entire packet
let packet_hex: Vec<String> = buffer.iter().map(|byte| format!("{:02X}", byte)).collect();
//println!("Received content (hex): {:?}", packet_hex.join(" "));
match packet_id {
0x00 => {
println!("Received Keep Alive packet (0x00)");
let response = vec![0x00]; // Not sure what to send. This might be good enough
println!("Sending a Keep Alive packet (0x00)");
stream.write(&response).unwrap();
}
0x01 => {
if size >= 18 {
// Extract protocol version (int16) and username (string16)
let protocol_version = i16::from_le_bytes([buffer[4], buffer[3]]);
let protocol_version_str = protocol_version.to_string();
let username_bytes = &buffer[8..40];
let username_str = String::from_utf8_lossy(username_bytes).to_string();
println!("Received Login packet - Protocol Version: {}, Username: {}", protocol_version_str, username_str);
if protocol_version_str == "14" {
println!("Supported protcol version {} detected!", protocol_version_str)
}
else {
println!("The detected protcol version {} isn't supported at this time. The server may not work correctly.", protocol_version_str)
}
// You can handle other fields such as Unused long and byte here if needed
// Respond as needed for the Login packet
// For example, you can check the protocol version and username and respond accordingly
// Create a response packet, for example:
//let response_packet: Vec<u8> = vec![0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
//stream.write(&response_packet).unwrap();
let response = data_dumps::DUMP0X01;
println!("Responding with a dump from java b1.7.3. (0x01)");
stream.write(&response).unwrap();
let response2 = data_dumps::DUMP0X32;
println!("Sending pre-chunk data... (0x32)");
stream.write(&response2).unwrap();
let response3 = data_dumps::DUMP0X33;
println!("Sending chunk data... (0x33)");
stream.write(&response3).unwrap();
} else {
println!("Incomplete Login packet received.");
}
}
0x02 => {
if size >= 3 {
let username_bytes = &buffer[3..];
let username_str = String::from_utf8_lossy(username_bytes).to_string();
println!("Received username: {}", username_str);
} else {
println!("Incomplete username packet received.");
}
let response = vec![0x02, 0x00, 0x01, 0x00, 0x2d];
println!("Responding with hash: {:?}", response);
stream.write(&response).unwrap();
}
0x12 => {
println!("Player most likely punched, as is only supported animation by vanilla client. (0x12)")
}
0x13 => {
println!("Player either crouched, uncrouched, or left a bed. (0x13)")
}
0x0A => {
if size >= 2 && buffer[1] == 0x01 {
println!("Player is flying. (0x0A)");
} else {
println!("Player is grounded. (0x0A)");
}
}
0x0B => {
println!("Position data sent to server. No response needed. (0x0B)");
}
0x0C => {
println!("Update where the player is looking. No response needed. (0x0C)");
}
0x0D => {
println!("Position data and look data, response needed. (0x0D)");
//Sending this causes the client to disconnect when the player looks with back packet id 64
//
//
//let response = vec![0x0d, 0x40, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x50, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x50, 0xa7, 0xae, 0x14, 0x80, 0x00, 0x00, 0x40, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
//
//println!("Sending fake position + look data. (0x0D)");
//
//stream.write(&response).unwrap();
}
_ => {
println!("Received unknown packet with ID: 0x{:02X}", packet_id);
}
}
}
}
fn main() {
let listener = TcpListener::bind("127.0.0.1:25565").expect("Failed to bind to address");
println!("Server listening on port 25565...");
for stream in listener.incoming() {
match stream {
Ok(stream) => {
thread::spawn(|| {
handle_client(stream);
});
}
Err(e) => {
eprintln!("Error accepting connection: {}", e);
}
}
}
}