Save up until dynamic info in ping

This commit is contained in:
ElementG9 2020-07-08 21:24:08 -06:00
parent 2d732fd2c4
commit 767ac2e981
10 changed files with 1152 additions and 254 deletions

382
Cargo.lock generated
View File

@ -6,14 +6,77 @@ version = "0.1.0"
dependencies = [
"chrono",
"colorful",
"lazy_static",
"ozelot",
"serde",
"toml",
]
[[package]]
name = "addr2line"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "602d785912f476e480434627e8732e6766b760c045bbf897d9dfaa9f4fbd399c"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccc9a9dd069569f212bc4330af9f17c4afb5e8ce185e83dbb14f1349dda18b10"
[[package]]
name = "adler32"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d"
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "backtrace"
version = "0.3.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05100821de9e028f12ae3d189176b41ee198341eb8f369956407fea2f5cc666c"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide 0.3.7",
"object",
"rustc-demangle",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cc"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "chrono"
version = "0.4.13"
@ -31,12 +94,142 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bca1619ff57dd7a56b58a8e25ef4199f123e78e503fe1653410350a1b98ae65"
[[package]]
name = "crc32fast"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
dependencies = [
"cfg-if",
]
[[package]]
name = "curl"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0447a642435be046540f042950d874a4907f9fee28c0513a0beb3ba89f91eb7"
dependencies = [
"curl-sys",
"libc",
"openssl-probe",
"openssl-sys",
"schannel",
"socket2",
"winapi",
]
[[package]]
name = "curl-sys"
version = "0.4.32+curl-7.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "834425a2f22fdd621434196965bf99fbfd9eaed96348488e27b7ac40736c560b"
dependencies = [
"cc",
"libc",
"libz-sys",
"openssl-sys",
"pkg-config",
"vcpkg",
"winapi",
]
[[package]]
name = "error-chain"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d371106cc88ffdfb1eabd7111e432da544f16f3e2d7bf1dfe8bf575f1df045cd"
dependencies = [
"backtrace",
"version_check",
]
[[package]]
name = "flate2"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e"
dependencies = [
"cfg-if",
"crc32fast",
"libc",
"miniz_oxide 0.4.0",
]
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "gimli"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c"
[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f"
[[package]]
name = "libz-sys"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "miniz_oxide"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
dependencies = [
"adler32",
]
[[package]]
name = "miniz_oxide"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f"
dependencies = [
"adler",
]
[[package]]
name = "netbuf"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f41e95a536af3c11c6dcf16f30b8319aad291049e67c8aa4701f69f11761a9db"
[[package]]
name = "num-integer"
version = "0.1.43"
@ -56,6 +249,168 @@ dependencies = [
"autocfg",
]
[[package]]
name = "object"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
[[package]]
name = "openssl"
version = "0.10.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4"
dependencies = [
"bitflags",
"cfg-if",
"foreign-types",
"lazy_static",
"libc",
"openssl-sys",
]
[[package]]
name = "openssl-probe"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
[[package]]
name = "openssl-sys"
version = "0.9.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de"
dependencies = [
"autocfg",
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "ozelot"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea00748638603838e4c5907d8d10449ee9a7e548667af7c20c684888006f6657"
dependencies = [
"byteorder",
"curl",
"error-chain",
"flate2",
"netbuf",
"openssl",
"serde",
"serde_derive",
"serde_json",
]
[[package]]
name = "pkg-config"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
[[package]]
name = "proc-macro2"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
[[package]]
name = "rustc-demangle"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "schannel"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
dependencies = [
"lazy_static",
"winapi",
]
[[package]]
name = "serde"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "socket2"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi",
]
[[package]]
name = "syn"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "time"
version = "0.1.43"
@ -66,6 +421,33 @@ dependencies = [
"winapi",
]
[[package]]
name = "toml"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
dependencies = [
"serde",
]
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "vcpkg"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "winapi"
version = "0.3.8"

View File

@ -9,3 +9,7 @@ edition = "2018"
[dependencies]
chrono = "0.4.13"
colorful = "0.2.1"
lazy_static = "1.4.0"
ozelot = "0.9.0" # Ozelot 0.9.0 supports protocol version 578 (1.15.2)
toml = "0.5.6"
serde = { version = "1.0.114", features = ["serde_derive"]}

4
composition.toml Normal file
View File

@ -0,0 +1,4 @@
port = 25565
protocol_version = 578
max_players = 420
motd = ligma balls lol

227
log.txt
View File

@ -1,5 +1,222 @@
2020-07-05 21:37:41 [IMPORTANT] - Cleared log file log.txt
2020-07-05 21:37:41 [IMPORTANT] - This is important information
2020-07-05 21:37:41 [INFO] - This is information
2020-07-05 21:37:41 [WARN] - This is a warning
2020-07-05 21:37:41 [ERROR] - This is an error
2020-07-06 10:40:25 [IMPORTANT] - Cleared log file log.txt
2020-07-06 10:40:25 [INFO] - gamer
2020-07-06 10:40:25 [INFO] - balls
2020-07-06 10:41:04 [INFO] - Network thread started
2020-07-06 10:41:04 [INFO] - balls
2020-07-06 10:42:10 [INFO] - Network thread started
2020-07-06 10:42:10 [INFO] - balls
2020-07-06 10:44:02 [INFO] - Network thread started
2020-07-06 10:44:02 [INFO] - balls
2020-07-06 10:44:15 [INFO] - Network thread started
2020-07-06 10:44:15 [INFO] - log from network thread
2020-07-06 10:49:45 [INFO] - Network thread started
2020-07-06 10:49:59 [INFO] - Got a client!
2020-07-06 11:00:42 [INFO] - Network thread started
2020-07-06 11:04:04 [INFO] - Network thread started
2020-07-06 11:04:04 [IMPORTANT] - Starting server on 127.0.0.1:25565
2020-07-06 11:04:24 [INFO] - Network thread started
2020-07-06 11:04:24 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-06 11:04:43 [INFO] - Got a client!
2020-07-06 11:22:16 [INFO] - Network thread started
2020-07-06 11:22:16 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-06 11:22:22 [INFO] - Got a client!
2020-07-06 11:25:16 [INFO] - Network thread started
2020-07-06 11:25:16 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-06 11:25:20 [INFO] - Got a client!
2020-07-06 11:26:01 [INFO] - Network thread started
2020-07-06 11:26:01 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-06 11:26:04 [INFO] - Got a client!
2020-07-06 11:27:38 [INFO] - Network thread started
2020-07-06 11:27:38 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-06 11:27:47 [INFO] - Got a client!
2020-07-06 11:29:02 [INFO] - Network thread started
2020-07-06 11:29:02 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-06 11:29:05 [INFO] - Got a client!
2020-07-06 13:06:10 [INFO] - Network thread started
2020-07-06 13:06:10 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-06 13:06:14 [INFO] - Got a client!
2020-07-07 12:51:20 [INFO] - Network thread started
2020-07-07 12:51:20 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-07 12:51:45 [INFO] - Network thread started
2020-07-07 12:51:45 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-07 12:57:26 [INFO] - Network thread started
2020-07-07 12:57:26 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:08:57 [INFO] - Got a client!
2020-07-08 19:08:57 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 19:17:12 [INFO] - Network thread started
2020-07-08 19:17:12 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:40:27 [INFO] - Network thread started
2020-07-08 19:40:27 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:40:38 [INFO] - Network thread started
2020-07-08 19:40:38 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:41:43 [INFO] - 12345
2020-07-08 19:41:43 [INFO] - Network thread started
2020-07-08 19:41:43 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:41:55 [INFO] - 25565
2020-07-08 19:41:55 [INFO] - Network thread started
2020-07-08 19:41:55 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:43:03 [INFO] - 12345
2020-07-08 19:43:03 [INFO] - Network thread started
2020-07-08 19:43:03 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:43:12 [WARN] - Could not load config from composition.toml, using default config.
2020-07-08 19:43:12 [INFO] - 25565
2020-07-08 19:43:12 [INFO] - Network thread started
2020-07-08 19:43:12 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:56:14 [INFO] - 25565
2020-07-08 19:56:14 [INFO] - Network thread started
2020-07-08 19:56:14 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:58:29 [INFO] - Network thread started
2020-07-08 19:58:29 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 19:58:43 [INFO] - Network thread started
2020-07-08 19:58:43 [IMPORTANT] - Started server on 127.0.0.1:12345
2020-07-08 19:58:52 [INFO] - Network thread started
2020-07-08 19:58:52 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:03:06 [INFO] - Network thread started
2020-07-08 20:03:06 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:03:12 [INFO] - Got a client!
2020-07-08 20:03:12 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 20:05:29 [INFO] - Network thread started
2020-07-08 20:05:29 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:08:08 [INFO] - Network thread started
2020-07-08 20:08:08 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:10:04 [INFO] - Network thread started
2020-07-08 20:10:04 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:10:08 [INFO] - Got a client!
2020-07-08 20:10:09 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 20:10:09 [INFO] - Client and server run same version of Minecraft.
2020-07-08 20:11:50 [INFO] - Got a client!
2020-07-08 20:11:50 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 20:11:50 [INFO] - Client and server don't run same version of Minecraft.
2020-07-08 20:38:15 [INFO] - Network thread started
2020-07-08 20:38:15 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:38:30 [INFO] - Got a client!
2020-07-08 20:38:30 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 20:38:32 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 20:40:27 [INFO] - Network thread started
2020-07-08 20:40:27 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:40:30 [INFO] - Got a client!
2020-07-08 20:40:30 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 20:40:30 [INFO] - Next state: Login
2020-07-08 20:40:33 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 20:48:19 [INFO] - Network thread started
2020-07-08 20:48:19 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:48:25 [INFO] - Got a client!
2020-07-08 20:48:25 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 20:48:25 [INFO] - Next state: Login
2020-07-08 20:48:25 [INFO] - LoginStart { username: MCString { value: "ElementG9" } }
2020-07-08 20:48:25 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 20:51:41 [INFO] - Network thread started
2020-07-08 20:51:41 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:52:00 [INFO] - Got a client!
2020-07-08 20:52:00 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 20:52:00 [INFO] - Next state: Status
2020-07-08 20:52:30 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 20:52:30 [INFO] - Got a client!
2020-07-08 20:52:30 [INFO] - Handshake { protocol_version: MCVarInt { value: 11 }, server_address: MCString { value: "" }, server_port: MCUnsignedShort { value: 19712 }, next_state: MCVarInt { value: 67 } }
2020-07-08 20:52:30 [INFO] - Next state: Closed
2020-07-08 20:52:30 [INFO] - Client at 127.0.0.1:52064 closed connection
2020-07-08 20:55:47 [INFO] - Network thread started
2020-07-08 20:55:47 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 20:55:53 [INFO] - Got a client!
2020-07-08 20:55:53 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "localhost" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } }
2020-07-08 20:55:53 [INFO] - Next state: Login
2020-07-08 20:55:53 [INFO] - LoginStart { username: MCString { value: "ElementG9" } }
2020-07-08 20:55:54 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 20:56:00 [INFO] - Got a client!
2020-07-08 20:56:00 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 20:56:00 [INFO] - Next state: Status
2020-07-08 20:56:30 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 20:56:30 [INFO] - Got a client!
2020-07-08 20:56:30 [INFO] - Handshake { protocol_version: MCVarInt { value: 11 }, server_address: MCString { value: "" }, server_port: MCUnsignedShort { value: 19712 }, next_state: MCVarInt { value: 67 } }
2020-07-08 20:56:30 [INFO] - Next state: Closed
2020-07-08 20:56:30 [INFO] - Client at 127.0.0.1:52096 closed connection
2020-07-08 21:04:04 [INFO] - Network thread started
2020-07-08 21:04:04 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:04:17 [INFO] - Network thread started
2020-07-08 21:04:17 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:04:22 [INFO] - Got a client!
2020-07-08 21:04:22 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:04:22 [INFO] - Next state: Status
2020-07-08 21:04:52 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 21:04:52 [INFO] - Got a client!
2020-07-08 21:04:52 [INFO] - Handshake { protocol_version: MCVarInt { value: 11 }, server_address: MCString { value: "" }, server_port: MCUnsignedShort { value: 19712 }, next_state: MCVarInt { value: 67 } }
2020-07-08 21:04:52 [INFO] - Next state: Closed
2020-07-08 21:04:52 [INFO] - Client at 127.0.0.1:52301 closed connection
2020-07-08 21:09:13 [INFO] - Network thread started
2020-07-08 21:09:13 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:09:26 [INFO] - Got a client!
2020-07-08 21:09:26 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:09:26 [INFO] - Next state: Status
2020-07-08 21:09:56 [ERROR] - Error when handling client: Connection reset by peer (os error 54)
2020-07-08 21:09:56 [INFO] - Got a client!
2020-07-08 21:09:56 [INFO] - Handshake { protocol_version: MCVarInt { value: 11 }, server_address: MCString { value: "" }, server_port: MCUnsignedShort { value: 19712 }, next_state: MCVarInt { value: 67 } }
2020-07-08 21:09:56 [INFO] - Next state: Closed
2020-07-08 21:09:56 [INFO] - Client at 127.0.0.1:52998 closed connection
2020-07-08 21:10:42 [INFO] - Network thread started
2020-07-08 21:10:42 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:10:44 [INFO] - Got a client!
2020-07-08 21:10:44 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:10:44 [INFO] - Next state: Status
2020-07-08 21:10:44 [INFO] - Ping number: MCLong { value: 6738900 }
2020-07-08 21:10:44 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 21:11:20 [INFO] - Network thread started
2020-07-08 21:11:20 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:11:25 [INFO] - Got a client!
2020-07-08 21:11:25 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:11:25 [INFO] - Next state: Status
2020-07-08 21:11:25 [INFO] - Ping number: MCLong { value: 6779912 }
2020-07-08 21:11:25 [INFO] - Client at 127.0.0.1:53056 closed connection
2020-07-08 21:16:51 [INFO] - Network thread started
2020-07-08 21:16:51 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:16:58 [INFO] - Got a client!
2020-07-08 21:16:58 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:16:58 [INFO] - Next state: Status
2020-07-08 21:16:58 [ERROR] - Error when handling client: failed to fill whole buffer
2020-07-08 21:16:58 [INFO] - Got a client!
2020-07-08 21:16:58 [INFO] - Handshake { protocol_version: MCVarInt { value: 11 }, server_address: MCString { value: "" }, server_port: MCUnsignedShort { value: 19712 }, next_state: MCVarInt { value: 67 } }
2020-07-08 21:16:58 [INFO] - Next state: Closed
2020-07-08 21:16:58 [INFO] - Client at 127.0.0.1:53607 closed connection
2020-07-08 21:17:32 [INFO] - Network thread started
2020-07-08 21:17:32 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:17:36 [INFO] - Got a client!
2020-07-08 21:17:36 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:17:36 [INFO] - Next state: Status
2020-07-08 21:17:36 [INFO] - Ping number: MCLong { value: 7150256 }
2020-07-08 21:17:36 [INFO] - Client at 127.0.0.1:53687 closed connection
2020-07-08 21:18:54 [INFO] - Network thread started
2020-07-08 21:18:54 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:18:58 [INFO] - Got a client!
2020-07-08 21:18:58 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:18:58 [INFO] - Next state: Status
2020-07-08 21:18:58 [INFO] - Ping number: MCLong { value: 7232924 }
2020-07-08 21:18:58 [INFO] - Client at 127.0.0.1:53774 closed connection
2020-07-08 21:19:42 [INFO] - Network thread started
2020-07-08 21:19:42 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:19:45 [INFO] - Got a client!
2020-07-08 21:19:45 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:19:45 [INFO] - Next state: Status
2020-07-08 21:19:45 [INFO] - Ping number: MCLong { value: 7279794 }
2020-07-08 21:19:45 [INFO] - Client at 127.0.0.1:53784 closed connection
2020-07-08 21:20:07 [INFO] - Network thread started
2020-07-08 21:20:07 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:20:12 [INFO] - Got a client!
2020-07-08 21:20:12 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:20:12 [INFO] - Next state: Status
2020-07-08 21:20:12 [INFO] - Ping number: MCLong { value: 7306496 }
2020-07-08 21:20:12 [INFO] - Client at 127.0.0.1:54216 closed connection
2020-07-08 21:22:22 [INFO] - Network thread started
2020-07-08 21:22:22 [WARN] - Could not load config from composition.toml, using default config.
2020-07-08 21:22:22 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:22:26 [INFO] - Got a client!
2020-07-08 21:22:26 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:22:26 [INFO] - Next state: Status
2020-07-08 21:22:26 [INFO] - Ping number: MCLong { value: 7440272 }
2020-07-08 21:22:26 [INFO] - Client at 127.0.0.1:55792 closed connection
2020-07-08 21:23:10 [INFO] - Network thread started
2020-07-08 21:23:10 [WARN] - Could not load config from composition.toml, using default config.
2020-07-08 21:23:10 [IMPORTANT] - Started server on 127.0.0.1:25565
2020-07-08 21:23:13 [INFO] - Got a client!
2020-07-08 21:23:13 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "127.0.0.1" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } }
2020-07-08 21:23:13 [INFO] - Next state: Status
2020-07-08 21:23:13 [INFO] - Ping number: MCLong { value: 7487517 }
2020-07-08 21:23:13 [INFO] - Client at 127.0.0.1:55872 closed connection

View File

@ -18,75 +18,55 @@ pub fn new(logfile: &str) -> Logger {
Logger::new(logfile)
}
#[derive(Clone)]
pub struct Logger {
pub logfile: String,
pub info_written: u32,
pub warn_written: u32,
pub error_written: u32,
pub important_written: u32,
pub write_enabled: bool,
}
impl Logger {
pub fn new(logfile: &str) -> Logger {
Logger {
logfile: logfile.to_owned(),
info_written: 0,
warn_written: 0,
error_written: 0,
important_written: 0,
write_enabled: true,
}
}
pub fn important(&mut self, s: &str) {
pub fn important(&self, s: &str) {
let l = log("IMPORTANT", s);
println!("{}", l.clone().color(Color::Cyan));
println!("{}", l.clone().color(Color::Green));
self.append(&l);
self.important_written += 1;
}
pub fn info(&mut self, s: &str) {
pub fn info(&self, s: &str) {
let l = log("INFO", s);
println!("{}", l.clone().color(Color::White));
// println!("{}", l.clone().color(Color::White));
println!("{}", l.clone());
self.append(&l);
self.info_written += 1;
}
pub fn warn(&mut self, s: &str) {
pub fn warn(&self, s: &str) {
let l = log("WARN", s);
println!("{}", l.clone().color(Color::Yellow));
println!("{}", l.clone().color(Color::LightYellow));
self.append(&l);
self.warn_written += 1;
}
pub fn error(&mut self, s: &str) {
pub fn error(&self, s: &str) {
let l = log("ERROR", s);
println!("{}", l.clone().color(Color::Red));
println!("{}", l.clone().color(Color::LightRed));
self.append(&l);
self.error_written += 1;
}
pub fn append(&mut self, s: &str) {
if self.write_enabled {
let a = || -> std::io::Result<()> {
let mut file = OpenOptions::new()
.create(true)
.write(true)
.append(true)
.open(&self.logfile)?;
writeln!(file, "{}", s)?;
Ok(())
};
if a().is_err() {
self.logger_error(&format!("Could not write to log file {}", self.logfile));
}
pub fn append(&self, s: &str) {
let a = || -> std::io::Result<()> {
let mut file = OpenOptions::new()
.create(true)
.write(true)
.append(true)
.open(&self.logfile)?;
writeln!(file, "{}", s)?;
Ok(())
};
if a().is_err() {
self.logger_error(&format!("Could not write to log file {}", self.logfile));
}
}
pub fn clear(&mut self) {
if self.write_enabled {
if std::fs::remove_file(&self.logfile).is_err() {
self.logger_error(&format!("Could not write to log file {}", self.logfile));
}
pub fn clear(&self) {
if std::fs::remove_file(&self.logfile).is_err() {
self.logger_error(&format!("Could not write to log file {}", self.logfile));
}
self.info_written = 0;
self.warn_written = 0;
self.error_written = 0;
self.important_written = 0;
self.important(&format!("Cleared log file {}", self.logfile));
}
pub fn read(&self) -> std::io::Result<String> {
@ -95,8 +75,8 @@ impl Logger {
f.read_to_string(&mut buffer)?;
Ok(buffer)
}
pub fn logger_error(&mut self, error_message: &str) {
self.write_enabled = false;
self.error(error_message);
pub fn logger_error(&self, error_message: &str) {
let l = log("ERROR", error_message);
println!("{}", l.clone().color(Color::LightRed));
}
}

View File

@ -1,12 +1,63 @@
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
extern crate lazy_static;
extern crate ozelot;
extern crate serde;
extern crate toml;
pub mod logger;
pub mod mctypes;
pub mod net;
pub mod protocol;
use serde::{Deserialize, Serialize};
lazy_static! {
static ref log: logger::Logger = logger::new("log.txt");
static ref config: Config = { Config::from_file("composition.toml") };
}
fn main() {
let mut log = logger::new("log.txt");
log.clear();
log.important("This is important information");
log.info("This is information");
log.warn("This is a warning");
log.error("This is an error");
// Start the network thread.
std::thread::spawn(|| {
log.info("Network thread started");
net::start_listening();
});
// Loop the main thread for now.
loop {}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub port: u16,
pub protocol_version: u16,
}
impl Config {
pub fn default() -> Config {
Config {
port: 25565,
protocol_version: 578,
}
}
pub fn from_file(filename: &str) -> Config {
use std::fs::File;
use std::io::prelude::*;
let a = || -> std::io::Result<Config> {
let mut file = File::open(filename)?;
let mut configStr = String::new();
file.read_to_string(&mut configStr)?;
Ok(toml::from_str(&configStr)?)
};
if let Ok(c) = a() {
c
} else {
log.warn(&format!(
"Could not load config from {}, using default config.",
filename
));
Config::default()
}
}
}

View File

@ -6,6 +6,10 @@ pub fn read_byte(t: &mut TcpStream) -> std::io::Result<u8> {
t.read_exact(&mut buffer)?;
Ok(buffer[0])
}
pub fn write_byte(t: &mut TcpStream, value: u8) -> std::io::Result<()> {
t.write(&[value])?;
Ok(())
}
pub fn get_bytes(v: Vec<u8>, l: usize) -> Box<[u8]> {
use std::collections::VecDeque;
let mut v = VecDeque::from(v);

File diff suppressed because one or more lines are too long

214
src/old_net.rs Normal file
View File

@ -0,0 +1,214 @@
pub static SERVER_LISTENER_ADDRESS: &str = "127.0.0.1:25565";
pub static SOCKET_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(5);
extern crate serde;
extern crate serde_json;
use crate::mctypes::*;
use serde::Serialize;
use serde_json::json;
use std::io::prelude::*;
use std::net::{TcpListener, TcpStream};
use std::thread;
pub struct MCPacket {
pub id: MCVarInt,
pub data: Vec<u8>,
}
#[allow(dead_code)]
impl MCPacket {
pub fn read_header(t: &mut TcpStream) -> std::io::Result<(MCVarInt, MCVarInt)> {
let length = MCVarInt::from_stream(t)?;
let id = MCVarInt::from_stream(t)?;
Ok((length, id))
}
pub fn new(id: u8) -> MCPacket {
MCPacket {
id: MCVarInt::new(id as i32),
data: Vec::new(),
}
}
pub fn write(&mut self, v: Vec<u8>) {
for b in v {
self.data.push(b);
}
}
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
for b in MCVarInt::new((self.id.to_bytes().len() + self.data.len()) as i32).to_bytes() {
bytes.push(b);
}
for b in self.id.to_bytes() {
bytes.push(b);
}
for b in &self.data {
bytes.push(*b);
}
bytes
}
}
#[allow(dead_code)]
#[derive(PartialEq, Debug)]
pub enum GameState {
Handshake,
Status,
Login,
Play,
Closed,
}
#[allow(dead_code)]
pub struct GameConnection {
pub stream: TcpStream,
pub state: GameState,
}
pub fn start_listener() -> std::io::Result<()> {
if crate::DEBUG_LOGGING {
println!("Started listener at {}", SERVER_LISTENER_ADDRESS);
}
let listener = TcpListener::bind(SERVER_LISTENER_ADDRESS)?;
// Spawn a new thread for each connection.
for stream in listener.incoming() {
let stream = stream?;
thread::Builder::new()
.name(format!("GameConnection {}", stream.peer_addr().unwrap()))
.spawn(move || -> std::io::Result<()> {
if crate::DEBUG_LOGGING {
println!("Client connected at {}", stream.peer_addr().unwrap());
}
stream
.set_read_timeout(Some(SOCKET_TIMEOUT))
.expect("set_read_timeout call failed");
stream
.set_write_timeout(Some(SOCKET_TIMEOUT))
.expect("set_write_timeout call failed");
handle_client(GameConnection {
stream: stream,
state: GameState::Handshake,
})?;
Ok(())
})?;
}
Ok(())
}
pub fn handle_client(mut gc: GameConnection) -> std::io::Result<()> {
loop {
let (packet_length, packet_id) = MCPacket::read_header(&mut gc.stream)?;
if crate::DEBUG_LOGGING {
println!(
"Packet Length: {}, Packet ID: {}",
packet_length.value, packet_id.value
);
}
match gc.state {
GameState::Handshake => match packet_id.value {
0x00 => {
handshake(&mut gc)?;
}
_ => {
if crate::DEBUG_LOGGING {
println!("Unknown packet id {} in Handshake", packet_id);
}
}
},
GameState::Login => match packet_id.value {
0x00 => {
login(&mut gc)?;
}
_ => {
if crate::DEBUG_LOGGING {
println!("Unknown packet id {} in Login", packet_id);
}
}
},
GameState::Status => {
match packet_id.value {
0x00 => {
// Send a response packet.
let mut packet = MCPacket::new(0x00);
let json_response = json!({
"version": {
"name": crate::SERVER_VERSION,
"protocol": crate::SERVER_PROTOCOL_VERSION
},
"players": {
"max": 100,
"online": 5,
"sample": [
{
"name": "thinkofdeath",
"id": "4566e69f-c907-48ee-8d71-d7ba5aa00d20"
}
]
},
"description": {
"text": crate::SERVER_MOTD
}
// No favicon for now.
// "favicon": "data:image/png;base64,<data>"
})
.to_string();
packet.write(MCVarInt::new(json_response.len() as i32).to_bytes());
packet.write(MCString::from(json_response.clone()).to_bytes());
gc.stream.write(&packet.to_bytes())?;
println!("=== SENT SERVER RESPONSE ===\n{}", json_response);
}
_ => {
if crate::DEBUG_LOGGING {
println!("Unknown packet id {} in Status", packet_id);
}
}
}
}
_ => {
if crate::DEBUG_LOGGING {
println!("Unknown gamestate {:?}", gc.state);
}
}
}
}
}
pub fn handshake(gc: &mut GameConnection) -> std::io::Result<()> {
// C->S Handshake
let protocol_version = MCVarInt::from_stream(&mut gc.stream)?;
let server_address = MCString::from_stream(&mut gc.stream)?;
let server_port = MCUnsignedShort::from_stream(&mut gc.stream)?;
let next_state = match MCVarInt::from_stream(&mut gc.stream)?.value {
1 => GameState::Status,
2 => GameState::Login,
_ => {
if crate::DEBUG_LOGGING {
println!("Unknown next_state in handshake");
}
GameState::Handshake
}
};
if crate::DEBUG_LOGGING {
println!(
"Handshake: Protocol Version: {}, Server Address: {}:{}, Next State: {:?}",
protocol_version.value, server_address.value, server_port.value, next_state
);
}
gc.state = next_state;
Ok(())
}
pub fn login(gc: &mut GameConnection) -> std::io::Result<()> {
// C->S Login Start
let player_username = MCString::from_stream(&mut gc.stream)?;
if crate::DEBUG_LOGGING {
println!("Login: Player Username: {}", player_username);
}
// S->C Encryption Request
// C->S Encryption Response
// S->C Set Compression
// S->C Login Success
let mut login_success = MCPacket::new(0x02);
login_success.write(MCString::from("00000000-0000-0000-0000-000000000000").to_bytes()); // UUID
login_success.write(player_username.to_bytes());
gc.stream.write(&login_success.to_bytes())?;
// Move to Play state
gc.state = GameState::Play;
play(gc)?;
Ok(())
}
pub fn play(gc: &mut GameConnection) -> std::io::Result<()> {
Ok(())
}

75
src/protocol.rs Normal file
View File

@ -0,0 +1,75 @@
use crate::mctypes::*;
use std::net::TcpStream;
pub fn read_packet_header(t: &mut TcpStream) -> std::io::Result<(MCVarInt, MCVarInt)> {
let length = MCVarInt::from_stream(t)?;
let id = MCVarInt::from_stream(t)?;
Ok((length, id))
}
#[derive(Debug)]
pub struct Handshake {
pub protocol_version: MCVarInt,
pub server_address: MCString,
pub server_port: MCUnsignedShort,
pub next_state: MCVarInt,
}
impl Handshake {
pub fn new(
protocol_version: MCVarInt,
server_address: MCString,
server_port: MCUnsignedShort,
next_state: MCVarInt,
) -> Handshake {
Handshake {
protocol_version,
server_address,
server_port,
next_state,
}
}
pub fn read(t: &mut TcpStream) -> std::io::Result<Handshake> {
let protocol_version = MCVarInt::from_stream(t)?;
let server_address = MCString::from_stream(t)?;
let server_port = MCUnsignedShort::from_stream(t)?;
let next_state = MCVarInt::from_stream(t)?;
Ok(Handshake::new(
protocol_version,
server_address,
server_port,
next_state,
))
}
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
for b in self.protocol_version.to_bytes() {
bytes.push(b);
}
for b in self.server_address.to_bytes() {
bytes.push(b);
}
for b in self.server_port.to_bytes() {
bytes.push(b);
}
for b in self.next_state.to_bytes() {
bytes.push(b);
}
bytes
}
}
#[derive(Debug)]
pub struct LoginStart {
pub username: MCString,
}
impl LoginStart {
pub fn new(username: MCString) -> LoginStart {
LoginStart { username }
}
pub fn read(t: &mut TcpStream) -> std::io::Result<LoginStart> {
Ok(LoginStart::new(MCString::from_stream(t)?))
}
pub fn to_bytes(&self) -> Vec<u8> {
self.username.to_bytes()
}
}