diff --git a/composition.toml b/composition.toml index f7f123c..ef69dbb 100644 --- a/composition.toml +++ b/composition.toml @@ -1,5 +1,4 @@ port = 25565 -protocol_version = 578 max_players = 20 motd = "Composition MOTD" favicon = "server-icon.png" diff --git a/composition_icon.png b/composition_icon.png deleted file mode 100644 index 01f0727..0000000 Binary files a/composition_icon.png and /dev/null differ diff --git a/log.txt b/log.txt deleted file mode 100644 index 8877ba7..0000000 --- a/log.txt +++ /dev/null @@ -1,418 +0,0 @@ -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 -2020-07-08 21:08:05 [INFO] - Network thread started -2020-07-08 21:08:05 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:08:19 [INFO] - Got a client! -2020-07-08 21:08:19 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:08:19 [INFO] - Next state: Closed -2020-07-08 21:08:19 [INFO] - Client at 192.168.0.88:55408 closed connection -2020-07-08 21:08:19 [INFO] - Got a client! -2020-07-08 21:08:19 [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:08:19 [INFO] - Next state: Closed -2020-07-08 21:08:19 [INFO] - Client at 192.168.0.88:55409 closed connection -2020-07-08 21:08:59 [INFO] - Got a client! -2020-07-08 21:08:59 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:08:59 [INFO] - Next state: Closed -2020-07-08 21:08:59 [INFO] - Client at 192.168.0.88:55414 closed connection -2020-07-08 21:08:59 [INFO] - Got a client! -2020-07-08 21:08:59 [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:08:59 [INFO] - Next state: Closed -2020-07-08 21:08:59 [INFO] - Client at 192.168.0.88:55415 closed connection -2020-07-08 21:09:06 [INFO] - Got a client! -2020-07-08 21:09:06 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } } -2020-07-08 21:09:06 [INFO] - Next state: Closed -2020-07-08 21:09:06 [INFO] - Client at 192.168.0.88:55416 closed connection -2020-07-08 21:10:30 [INFO] - Got a client! -2020-07-08 21:10:30 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:10:30 [INFO] - Next state: Status -2020-07-08 21:10:30 [INFO] - Ping number: MCLong { value: 28962 } -2020-07-08 21:10:30 [INFO] - Client at 192.168.0.88:55679 closed connection -2020-07-08 21:12:50 [INFO] - Network thread started -2020-07-08 21:12:50 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:12:58 [INFO] - Got a client! -2020-07-08 21:12:58 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:12:58 [INFO] - Next state: Status -2020-07-08 21:12:58 [INFO] - Ping number: MCLong { value: 177626 } -2020-07-08 21:12:58 [INFO] - Client at 192.168.0.88:55688 closed connection -2020-07-08 21:13:23 [INFO] - Got a client! -2020-07-08 21:13:23 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } } -2020-07-08 21:13:23 [INFO] - Next state: Status -2020-07-08 21:13:23 [INFO] - Ping number: MCLong { value: 8029147796280267361 } -2020-07-08 21:13:23 [INFO] - Client at 192.168.0.88:55689 closed connection -2020-07-08 21:16:48 [INFO] - Network thread started -2020-07-08 21:16:48 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:17:03 [INFO] - Got a client! -2020-07-08 21:17:03 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:17:03 [INFO] - Next state: Status -2020-07-08 21:17:03 [INFO] - Ping number: MCLong { value: 422535 } -2020-07-08 21:17:03 [INFO] - Client at 192.168.0.88:55700 closed connection -2020-07-08 21:17:50 [INFO] - Got a client! -2020-07-08 21:17:50 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:17:50 [INFO] - Next state: Status -2020-07-08 21:17:50 [INFO] - Ping number: MCLong { value: 469501 } -2020-07-08 21:17:50 [INFO] - Client at 192.168.0.88:55706 closed connection -2020-07-08 21:18:17 [INFO] - Network thread started -2020-07-08 21:18:17 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:18:24 [INFO] - Got a client! -2020-07-08 21:18:24 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:18:24 [INFO] - Next state: Status -2020-07-08 21:18:24 [INFO] - Ping number: MCLong { value: 503077 } -2020-07-08 21:18:24 [INFO] - Client at 192.168.0.88:55712 closed connection -2020-07-08 21:18:31 [INFO] - Got a client! -2020-07-08 21:18:31 [INFO] - Handshake { protocol_version: MCVarInt { value: 47 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:18:31 [INFO] - Next state: Status -2020-07-08 21:18:32 [INFO] - Ping number: MCLong { value: 510863 } -2020-07-08 21:18:32 [INFO] - Client at 192.168.0.88:55718 closed connection -2020-07-08 21:18:40 [INFO] - Got a client! -2020-07-08 21:18:40 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:18:40 [INFO] - Next state: Status -2020-07-08 21:18:40 [INFO] - Ping number: MCLong { value: 519010 } -2020-07-08 21:18:40 [INFO] - Client at 192.168.0.88:55724 closed connection -2020-07-08 21:19:16 [INFO] - Got a client! -2020-07-08 21:19:16 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } } -2020-07-08 21:19:16 [INFO] - Next state: Status -2020-07-08 21:19:16 [INFO] - Ping number: MCLong { value: 8029147796280267361 } -2020-07-08 21:19:16 [INFO] - Client at 192.168.0.88:55726 closed connection -2020-07-08 21:21:09 [INFO] - Got a client! -2020-07-08 21:21:09 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } } -2020-07-08 21:21:09 [INFO] - Next state: Status -2020-07-08 21:21:09 [INFO] - Ping number: MCLong { value: 8029147796280267361 } -2020-07-08 21:21:09 [INFO] - Client at 192.168.0.88:55732 closed connection -2020-07-08 21:22:38 [INFO] - Network thread started -2020-07-08 21:22:38 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:22:48 [INFO] - Got a client! -2020-07-08 21:22:48 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:22:48 [INFO] - Next state: Status -2020-07-08 21:22:48 [INFO] - Ping number: MCLong { value: 767030 } -2020-07-08 21:22:48 [INFO] - Client at 192.168.0.88:55738 closed connection -2020-07-08 21:23:06 [INFO] - Got a client! -2020-07-08 21:23:06 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:23:06 [INFO] - Next state: Status -2020-07-08 21:23:06 [INFO] - Ping number: MCLong { value: 785172 } -2020-07-08 21:23:06 [INFO] - Client at 192.168.0.88:55744 closed connection -2020-07-08 21:23:12 [INFO] - Got a client! -2020-07-08 21:23:12 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 2 } } -2020-07-08 21:23:12 [INFO] - Next state: Closed -2020-07-08 21:23:12 [INFO] - Client at 192.168.0.88:55745 closed connection -2020-07-08 21:38:26 [INFO] - Network thread started -2020-07-08 21:38:26 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:38:38 [INFO] - Got a client! -2020-07-08 21:38:38 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:38:38 [INFO] - Next state: Status -2020-07-08 21:38:38 [ERROR] - Error when handling client: failed to fill whole buffer -2020-07-08 21:38:38 [INFO] - Got a client! -2020-07-08 21:38:38 [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:38:38 [INFO] - Next state: Closed -2020-07-08 21:38:38 [INFO] - Client at 192.168.0.88:55778 closed connection -2020-07-08 21:39:45 [INFO] - Network thread started -2020-07-08 21:39:45 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:39:52 [INFO] - Got a client! -2020-07-08 21:39:52 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:39:52 [INFO] - Next state: Status -2020-07-08 21:40:01 [ERROR] - Error when handling client: Connection reset by peer (os error 54) -2020-07-08 21:40:04 [INFO] - Got a client! -2020-07-08 21:40: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: 1 } } -2020-07-08 21:40:04 [INFO] - Next state: Status -2020-07-08 21:40:04 [INFO] - Ping number: MCLong { value: 1803114 } -2020-07-08 21:40:04 [INFO] - Client at 192.168.0.88:55790 closed connection -2020-07-08 21:40:16 [INFO] - Got a client! -2020-07-08 21:40:16 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:40:16 [INFO] - Next state: Status -2020-07-08 21:40:16 [INFO] - Ping number: MCLong { value: 1815195 } -2020-07-08 21:40:16 [INFO] - Client at 192.168.0.88:55796 closed connection -2020-07-08 21:40:47 [INFO] - Network thread started -2020-07-08 21:40:47 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:40:59 [INFO] - Got a client! -2020-07-08 21:40:59 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:40:59 [INFO] - Next state: Status -2020-07-08 21:41:00 [INFO] - Ping number: MCLong { value: 1858861 } -2020-07-08 21:41:00 [INFO] - Client at 192.168.0.88:55802 closed connection -2020-07-08 21:54:37 [INFO] - Network thread started -2020-07-08 21:54:37 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 21:54:45 [INFO] - Got a client! -2020-07-08 21:54:45 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:54:45 [INFO] - Next state: Status -2020-07-08 21:54:45 [INFO] - Ping number: MCLong { value: 2684003 } -2020-07-08 21:54:45 [INFO] - Client at 192.168.0.88:55845 closed connection -2020-07-08 21:54:54 [INFO] - Got a client! -2020-07-08 21:54:54 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 21:54:54 [INFO] - Next state: Status -2020-07-08 21:54:54 [INFO] - Ping number: MCLong { value: 2693231 } -2020-07-08 21:54:54 [INFO] - Client at 192.168.0.88:55851 closed connection -2020-07-08 22:08:35 [INFO] - Network thread started -2020-07-08 22:08:35 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 22:08:42 [INFO] - Got a client! -2020-07-08 22:08:42 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 22:08:42 [INFO] - Next state: Status -2020-07-08 22:08:42 [INFO] - Ping number: MCLong { value: 3521389 } -2020-07-08 22:08:42 [INFO] - Client at 192.168.0.88:55885 closed connection -2020-07-08 22:08:49 [INFO] - Got a client! -2020-07-08 22:08:49 [INFO] - Handshake { protocol_version: MCVarInt { value: 736 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 22:08:49 [INFO] - Next state: Status -2020-07-08 22:08:49 [INFO] - Ping number: MCLong { value: 3528562 } -2020-07-08 22:08:49 [INFO] - Client at 192.168.0.88:55891 closed connection -2020-07-08 22:15:19 [INFO] - Network thread started -2020-07-08 22:15:19 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 22:15:39 [INFO] - Got a client! -2020-07-08 22:15:39 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 22:15:39 [INFO] - Next state: Status -2020-07-08 22:15:39 [INFO] - Ping number: MCLong { value: 3938584 } -2020-07-08 22:15:39 [INFO] - Client at 192.168.0.88:55909 closed connection -2020-07-08 22:23:14 [INFO] - Network thread started -2020-07-08 22:23:14 [IMPORTANT] - Started server on 0.0.0.0:25565 -2020-07-08 22:23:20 [INFO] - Got a client! -2020-07-08 22:23:20 [INFO] - Handshake { protocol_version: MCVarInt { value: 498 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 22:23:20 [INFO] - Next state: Status -2020-07-08 22:23:20 [INFO] - Ping number: MCLong { value: 4398964 } -2020-07-08 22:23:20 [INFO] - Client at 192.168.0.88:55921 closed connection -2020-07-08 22:23:22 [INFO] - Got a client! -2020-07-08 22:23:22 [INFO] - Handshake { protocol_version: MCVarInt { value: 498 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 22:23:22 [INFO] - Next state: Status -2020-07-08 22:23:22 [INFO] - Ping number: MCLong { value: 4401109 } -2020-07-08 22:23:22 [INFO] - Client at 192.168.0.88:55927 closed connection -2020-07-08 22:23:41 [INFO] - Got a client! -2020-07-08 22:23:42 [INFO] - Handshake { protocol_version: MCVarInt { value: 578 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -2020-07-08 22:23:42 [INFO] - Next state: Status -2020-07-08 22:23:42 [INFO] - Ping number: MCLong { value: 4420928 } -2020-07-08 22:23:42 [INFO] - Client at 192.168.0.88:55934 closed connection -2020-07-08 22:25:40 [INFO] - Got a client! -2020-07-08 22:25:40 [INFO] - Handshake { protocol_version: MCVarInt { value: 316 }, server_address: MCString { value: "192.168.0.98" }, server_port: MCUnsignedShort { value: 25565 }, next_state: MCVarInt { value: 1 } } -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" diff --git a/output.log b/output.log index 97c90f9..cc46ad0 100644 --- a/output.log +++ b/output.log @@ -1,175 +1,40 @@ - -2020-07-27 11:25:17 [ERROR] - panicked at 'Normal panic', src/main.rs:55:5 -2020-07-27 11:25:18 [ERROR] - panicked at 'Normal panic', src/main.rs:55:5 - 0: backtrace::backtrace::libunwind::trace - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/backtrace/libunwind.rs:95 - backtrace::backtrace::trace_unsynchronized - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/backtrace/mod.rs:66 - 1: backtrace::backtrace::trace - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/backtrace/mod.rs:53 - 2: backtrace::capture::Backtrace::create - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/capture.rs:164 - 3: backtrace::capture::Backtrace::new - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/capture.rs:128 - 4: Composition::main::{{closure}} - at src/main.rs:52 - 5: std::panicking::rust_panic_with_hook - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:475 - 6: std::panicking::begin_panic - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:404 - 7: Composition::main - at src/main.rs:55 - 8: std::rt::lang_start::{{closure}} - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:67 - 9: std::rt::lang_start_internal::{{closure}} - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:52 - std::panicking::try::do_call - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:292 - 10: __rust_maybe_catch_panic - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libpanic_unwind/lib.rs:78 - 11: std::panicking::try - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:270 - std::panic::catch_unwind - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panic.rs:394 - std::rt::lang_start_internal - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:51 - 12: std::rt::lang_start - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:67 - 13: _main - -2020-07-27 11:26:38 [ERROR] - panicked at 'Normal panic', src/main.rs:54:5 - 0: backtrace::backtrace::libunwind::trace - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/backtrace/libunwind.rs:95 - backtrace::backtrace::trace_unsynchronized - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/backtrace/mod.rs:66 - 1: backtrace::backtrace::trace - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/backtrace/mod.rs:53 - 2: backtrace::capture::Backtrace::create - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/capture.rs:164 - 3: backtrace::capture::Backtrace::new - at /Users/gt/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.50/src/capture.rs:128 - 4: Composition::main::{{closure}} - at src/main.rs:51 - 5: std::panicking::rust_panic_with_hook - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:475 - 6: std::panicking::begin_panic - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:404 - 7: Composition::main - at src/main.rs:54 - 8: std::rt::lang_start::{{closure}} - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:67 - 9: std::rt::lang_start_internal::{{closure}} - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:52 - std::panicking::try::do_call - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:292 - 10: __rust_maybe_catch_panic - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libpanic_unwind/lib.rs:78 - 11: std::panicking::try - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:270 - std::panic::catch_unwind - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panic.rs:394 - std::rt::lang_start_internal - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:51 - 12: std::rt::lang_start - at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/rt.rs:67 - 13: _main - -2020-07-27 11:30:23 [INFO] - Starting server... -2020-07-27 11:30:46 [INFO] - Starting server... -2020-07-27 11:31:01 [INFO] - Starting server -2020-07-27 11:40:10 [INFO] - Starting server... -2020-07-27 11:40:10 [INFO] - Done! Start took 763.52µs -2020-07-27 11:40:51 [INFO] - Starting server... -2020-07-27 11:40:51 [INFO] - Done! Start took 820.196µs -2020-07-27 11:47:37 [INFO] - Starting server... -2020-07-27 11:47:37 [INFO] - Done! Start took 441.888µs -2020-07-27 12:51:18 [INFO] - Starting server... -2020-07-27 12:51:18 [INFO] - Done! Start took 929.466µs -2020-07-27 13:14:52 [INFO] - Starting server... -2020-07-27 13:14:52 [INFO] - Starting network server... -2020-07-27 13:14:52 [INFO] - Done! Start took 829.689µs -2020-07-27 17:14:52 [INFO] - Starting server... -2020-07-27 17:14:52 [INFO] - Done! Start took 920.073µs -2020-07-27 17:14:52 [INFO] - Starting network... -2020-07-27 17:14:52 [INFO] - [] -2020-07-27 17:14:52 [INFO] - [] -2020-07-27 17:14:52 [INFO] - [] -2020-07-27 17:14:52 [INFO] - [] -2020-07-27 17:14:52 [INFO] - [] -2020-07-27 17:14:52 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:53 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:54 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:55 [INFO] - [] -2020-07-27 17:14:56 [INFO] - [] -2020-07-27 17:14:56 [INFO] - [] -2020-07-27 17:14:56 [INFO] - [] -2020-07-27 17:28:01 [INFO] - Starting server... -2020-07-27 17:28:01 [INFO] - Done! Start took 1.079011ms -2020-07-27 17:28:01 [INFO] - Starting network... -2020-07-27 17:28:32 [INFO] - Starting server... -2020-07-27 17:28:32 [INFO] - Done! Start took 891.237µs -2020-07-27 17:30:03 [INFO] - Starting server... -2020-07-27 17:30:03 [INFO] - Done! Start took 889.43µs -2020-07-27 17:30:39 [INFO] - Starting server... -2020-07-27 17:30:39 [INFO] - Done! Start took 668.524µs -2020-07-27 17:32:13 [DEBUG] - Network received client: NetworkClient { id: 0, state: Handshake, alive: true, stream: BufReader { reader: TcpStream { addr: V4(127.0.0.1:25565), peer: V4(127.0.0.1:58986), fd: 5 }, buffer: 0/8192 }, username: None, packets: [] } -2020-07-27 17:32:13 [DEBUG] - Network received client: NetworkClient { id: 1, state: Handshake, alive: true, stream: BufReader { reader: TcpStream { addr: V4(127.0.0.1:25565), peer: V4(127.0.0.1:58988), fd: 5 }, buffer: 0/8192 }, username: None, packets: [] } -2020-07-27 17:37:57 [INFO] - Starting server... -2020-07-27 17:37:57 [INFO] - Done! Start took 1.007552ms -2020-07-27 18:15:45 [INFO] - Starting server... -2020-07-27 18:15:45 [INFO] - Done! Start took 812.588µs +[2020-08-17 16:41:40][Composition][INFO] Starting server... +[2020-08-17 16:41:40][Composition::net][INFO] Network server started! +[2020-08-17 16:41:40][Composition][INFO] Done! Start took 1.023788ms +[2020-08-17 16:41:50][Composition][INFO] Starting server... +[2020-08-17 16:41:50][Composition::net][INFO] Network server started! +[2020-08-17 16:41:50][Composition][INFO] Done! Start took 1.005714ms +[2020-08-17 16:42:32][Composition::net][INFO] Got client at 127.0.0.1:51769 +[2020-08-17 17:11:43][Composition][INFO] Starting server... +[2020-08-17 17:11:43][Composition::net][INFO] Network server started! +[2020-08-17 17:11:43][Composition][INFO] Done! Start took 1.245737ms +[2020-08-17 17:14:54][Composition][INFO] Starting server... +[2020-08-17 17:14:54][Composition::net][INFO] Network server started! +[2020-08-17 17:14:54][Composition][INFO] Done! Start took 1.252385ms +[2020-08-17 17:15:41][Composition::net][INFO] Got client at 127.0.0.1:56994 +[2020-08-17 21:14:58][Composition][INFO] Starting server... +[2020-08-17 21:14:58][Composition::net][INFO] Network server started! +[2020-08-17 21:14:58][Composition][INFO] Done! Start took 1.787424ms +[2020-08-17 21:15:32][Composition::net][INFO] Got client at 127.0.0.1:52811 +[2020-08-17 21:17:01][Composition][INFO] Starting server... +[2020-08-17 21:17:01][Composition::net][INFO] Network server started! +[2020-08-17 21:17:01][Composition][INFO] Done! Start took 1.242146ms +[2020-08-17 21:17:04][Composition::net][INFO] Got client at 127.0.0.1:52841 +[2020-08-17 21:18:13][Composition][INFO] Starting server... +[2020-08-17 21:18:13][Composition::net][INFO] Network server started! +[2020-08-17 21:18:13][Composition][INFO] Done! Start took 1.033613ms +[2020-08-17 21:18:15][Composition::net][INFO] Got client at 127.0.0.1:52847 +[2020-08-17 21:18:25][Composition::net][INFO] Got client at 127.0.0.1:52850 +[2020-08-17 21:18:52][Composition::net][INFO] Got client at 127.0.0.1:52855 +[2020-08-17 21:23:47][Composition][INFO] Starting server... +[2020-08-17 21:23:47][Composition::net][INFO] Network server started! +[2020-08-17 21:23:47][Composition][INFO] Done! Start took 966.985µs +[2020-08-17 21:23:49][Composition::net][INFO] Got client at 127.0.0.1:52879 +[2020-08-17 21:37:35][Composition][INFO] Starting server... +[2020-08-17 21:37:35][Composition::net][INFO] Network server started! +[2020-08-17 21:37:35][Composition][INFO] Done! Start took 1.448375ms +[2020-08-17 21:37:44][Composition::net][INFO] Got client at 127.0.0.1:53276 +[2020-08-18 08:15:48][Composition][INFO] Starting server... +[2020-08-18 08:15:48][Composition::net][INFO] Network server started! +[2020-08-18 08:15:48][Composition][INFO] Done! Start took 1.853066ms +[2020-08-18 08:15:55][Composition::net][INFO] Got client at 127.0.0.1:56532 diff --git a/src/main.rs b/src/main.rs index f0860f2..917c6cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,37 +1,27 @@ -// main.rs -// authors: Garen Tyler, Danton Hou -// description: -// Initializes the server, main server loop. - -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] #![allow(unused_imports)] +#![allow(non_snake_case)] -extern crate backtrace; -extern crate fern; -extern crate log; -extern crate serde; - -pub mod network; +pub mod mctypes; +pub mod net; pub mod server; +extern crate chrono; +extern crate fern; -use backtrace::Backtrace; -use fern::colors::{Color, ColoredLevelConfig}; use log::{debug, error, info, warn}; -use network::NetworkServer; -use serde::{Deserialize, Serialize}; -use server::{Server, ServerConfig}; -use std::sync::mpsc::{self, Receiver, Sender}; +use net::NetworkServer; +use server::GameServer; use std::time::{Duration, Instant}; -fn main() { - // Setup logging. +pub fn main() { + let start_time = Instant::now(); + + // Set up fern logging. fern::Dispatch::new() .format(move |out, message, record| { out.finish(format_args!( - "{date} [{level}] - {message}", + "[{date}][{target}][{level}] {message}", date = chrono::Local::now().format("%Y-%m-%d %H:%M:%S"), - // target = record.target(), + target = record.target(), level = record.level(), message = message, )) @@ -41,33 +31,16 @@ fn main() { .chain(fern::log_file("output.log").unwrap()) .apply() .unwrap(); - - std::panic::set_hook(Box::new(|panic_info| { - let backtrace = Backtrace::new(); - error!("{}\n{:?}", panic_info.to_string(), backtrace); - })); - info!("Starting server..."); - let start_time = Instant::now(); - - let config = ServerConfig::from_file("composition.toml"); - let port = config.port; - - // Create the message channels. - let (tx, rx) = mpsc::channel(); - - // Create the server. - let mut server = Server { - config, - receiver: rx, - network: NetworkServer::new(port), - }; + // Start the network. + let network = NetworkServer::new("0.0.0.0:25565"); + let mut server = GameServer { network: network }; info!("Done! Start took {:?}", start_time.elapsed()); // The main server loop. loop { - server.update(); // Do the tick. - std::thread::sleep(Duration::from_millis(50)); + server.update(); + std::thread::sleep(Duration::from_millis(2)); } } diff --git a/src/mctypes.rs b/src/mctypes.rs index 6dc4e77..b02671e 100644 --- a/src/mctypes.rs +++ b/src/mctypes.rs @@ -1,420 +1,1032 @@ -// mctypes.rs -// author: Garen Tyler -// description: -// A recreation of all the types necessary in the protocol. -// Directly taken from https://wiki.vg/Protocol#Data_types. +#![allow(dead_code)] +pub use functions::*; +pub use numbers::*; +pub use other::*; +use std::convert::{Into, TryFrom}; +use std::fmt::Display; use std::io::prelude::*; use std::net::TcpStream; -// Helper functions. -pub fn read_byte(t: &mut TcpStream) -> std::io::Result { - let mut buffer = [0u8; 1]; - 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, l: usize) -> Box<[u8]> { - use std::collections::VecDeque; - let mut v = VecDeque::from(v); - while v.len() > l { - v.pop_front(); - } - while v.len() < l { - v.push_front(0u8); - } - let mut a = Vec::new(); - for b in v { - a.push(b); - } - a.into_boxed_slice() -} -// Makes returning errors shorter. -pub fn io_error(s: &str) -> std::io::Error { - use std::io::{Error, ErrorKind}; - Error::new(ErrorKind::Other, s) +pub trait MCType: Into> + TryFrom> + Display { + fn read(_stream: &mut TcpStream) -> std::io::Result; } -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub enum MCBoolean { - True, - False, -} -impl From for MCBoolean { - fn from(v: bool) -> MCBoolean { - if v { - MCBoolean::True - } else { - MCBoolean::False +// Helper functions. +pub mod functions { + use super::*; + + pub fn read_byte(t: &mut TcpStream) -> std::io::Result { + let mut buffer = [0u8; 1]; + t.read_exact(&mut buffer)?; + Ok(buffer[0]) + } + pub fn write_byte(t: &mut TcpStream, value: u8) -> std::io::Result { + t.write(&[value])?; + Ok(value) + } + pub fn get_bytes(v: Vec, l: usize) -> Box<[u8]> { + use std::collections::VecDeque; + let mut v = VecDeque::from(v); + while v.len() > l { + v.pop_front(); } - } -} -#[allow(dead_code)] -impl MCBoolean { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let b = read_byte(t)?; - Ok(MCBoolean::from_bytes(vec![b])) - } - pub fn from_bytes(v: Vec) -> MCBoolean { - if get_bytes(v, 1)[0] == 0x01 { - MCBoolean::True - } else { - MCBoolean::False + while v.len() < l { + v.push_front(0u8); } - } - pub fn to_bytes(&self) -> Vec { - match self { - MCBoolean::True => vec![0x01], - MCBoolean::False => vec![0x00], + let mut a = Vec::new(); + for b in v { + a.push(b); } + a.into_boxed_slice() + } + // Makes returning errors shorter. + pub fn io_error(s: &str) -> std::io::Error { + use std::io::{Error, ErrorKind}; + Error::new(ErrorKind::Other, s) } } -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCByte { - pub value: i8, // -128 to 127 -} -impl From for MCByte { - fn from(v: i8) -> MCByte { - MCByte { value: v } + +// The other types, (booleans and strings). +pub mod other { + use super::*; + use std::convert::{From, Into, TryFrom}; + use std::fmt::Display; + + #[derive(Debug, Copy, Clone, PartialEq)] + pub enum MCBoolean { + True, + False, } -} -#[allow(dead_code)] -impl MCByte { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - Ok(MCByte::from_bytes(vec![read_byte(t)?])) - } - pub fn from_bytes(v: Vec) -> MCByte { - MCByte { - value: get_bytes(v, 1)[0] as i8, - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCUnsignedByte { - pub value: u8, // 0 to 255 -} -impl From for MCUnsignedByte { - fn from(v: u8) -> MCUnsignedByte { - MCUnsignedByte { value: v } - } -} -#[allow(dead_code)] -impl MCUnsignedByte { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - Ok(MCUnsignedByte::from_bytes(vec![read_byte(t)?])) - } - pub fn from_bytes(v: Vec) -> MCUnsignedByte { - MCUnsignedByte { - value: get_bytes(v, 1)[0], - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCShort { - pub value: i16, // -32768 to 32767 -} -impl From for MCShort { - fn from(v: i16) -> MCShort { - MCShort { value: v } - } -} -#[allow(dead_code)] -impl MCShort { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let mut bytes = Vec::new(); - bytes.push(read_byte(t)?); // MSD - bytes.push(read_byte(t)?); // LSD - Ok(MCShort::from_bytes(bytes)) - } - pub fn from_bytes(v: Vec) -> MCShort { - let mut a = [0u8; 2]; - a.copy_from_slice(&get_bytes(v, 2)); - MCShort { - value: i16::from_be_bytes(a), - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCUnsignedShort { - pub value: u16, // 0 to 65535 -} -impl From for MCUnsignedShort { - fn from(v: u16) -> MCUnsignedShort { - MCUnsignedShort { value: v } - } -} -#[allow(dead_code)] -impl MCUnsignedShort { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let mut bytes = Vec::new(); - bytes.push(read_byte(t)?); // MSD - bytes.push(read_byte(t)?); // LSD - Ok(MCUnsignedShort::from_bytes(bytes)) - } - pub fn from_bytes(v: Vec) -> MCUnsignedShort { - let mut a = [0u8; 2]; - a.copy_from_slice(&get_bytes(v, 2)); - MCUnsignedShort { - value: u16::from_be_bytes(a), - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCInt { - pub value: i32, // -2147483648 to 2147483647 -} -impl From for MCInt { - fn from(v: i32) -> MCInt { - MCInt { value: v } - } -} -#[allow(dead_code)] -impl MCInt { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let mut bytes = Vec::new(); - for _ in 0..4 { - bytes.push(read_byte(t)?); - } - Ok(MCInt::from_bytes(bytes)) - } - pub fn from_bytes(v: Vec) -> MCInt { - let mut a = [0u8; 4]; - a.copy_from_slice(&get_bytes(v, 4)); - MCInt { - value: i32::from_be_bytes(a), - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCLong { - pub value: i64, // -9223372036854775808 to 9223372036854775807 -} -impl From for MCLong { - fn from(v: i64) -> MCLong { - MCLong { value: v } - } -} -#[allow(dead_code)] -impl MCLong { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let mut bytes = Vec::new(); - for _ in 0..8 { - bytes.push(read_byte(t)?); - } - Ok(MCLong::from_bytes(bytes)) - } - pub fn from_bytes(v: Vec) -> MCLong { - let mut a = [0u8; 8]; - a.copy_from_slice(&get_bytes(v, 8)); - MCLong { - value: i64::from_be_bytes(a), - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCFloat { - pub value: f32, // 32-bit floating point number -} -impl From for MCFloat { - fn from(v: f32) -> MCFloat { - MCFloat { value: v } - } -} -#[allow(dead_code)] -impl MCFloat { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let mut bytes = Vec::new(); - for _ in 0..4 { - bytes.push(read_byte(t)?); - } - Ok(MCFloat::from_bytes(bytes)) - } - pub fn from_bytes(v: Vec) -> MCFloat { - let mut a = [0u8; 4]; - a.copy_from_slice(&get_bytes(v, 4)); - MCFloat { - value: f32::from_be_bytes(a), - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCDouble { - pub value: f64, // 64-bit floating point number -} -impl From for MCDouble { - fn from(v: f64) -> MCDouble { - MCDouble { value: v } - } -} -#[allow(dead_code)] -impl MCDouble { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let mut bytes = Vec::new(); - for _ in 0..8 { - bytes.push(read_byte(t)?); - } - Ok(MCDouble::from_bytes(bytes)) - } - pub fn from_bytes(v: Vec) -> MCDouble { - let mut a = [0u8; 8]; - a.copy_from_slice(&get_bytes(v, 8)); - MCDouble { - value: f64::from_be_bytes(a), - } - } - pub fn to_bytes(&self) -> Vec { - self.value.to_be_bytes().to_vec() - } -} -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct MCVarInt { - pub value: i32, // Variable length 32-bit integer -} -impl From for MCVarInt { - fn from(v: i32) -> MCVarInt { - MCVarInt { value: v } - } -} -#[allow(dead_code)] -impl MCVarInt { - pub fn new(i: i32) -> MCVarInt { - MCVarInt { value: i } - } - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let mut numRead = 0; - let mut result = 0i32; - let mut read = 0u8; - let mut run_once = false; - while (read & 0b10000000) != 0 || !run_once { - run_once = true; - read = read_byte(t)?; - let value = (read & 0b01111111) as i32; - result |= value << (7 * numRead); - numRead += 1; - if numRead > 5 { - return Err(io_error("MCVarInt is too big")); + impl From for MCBoolean { + fn from(v: bool) -> MCBoolean { + if v { + MCBoolean::True + } else { + MCBoolean::False } } - Ok(MCVarInt { value: result }) } - pub fn from_bytes(_: Vec) -> MCVarInt { - panic!("Cannot construct MCVarInt from raw bytes"); - } - pub fn to_bytes(&self) -> Vec { - let mut value = self.value.clone(); - let mut run_once = false; - let mut out: Vec = Vec::new(); - while value != 0 || !run_once { - run_once = true; - let mut temp: u8 = (value & 0b01111111) as u8; - value >>= 7; - if value != 0 { - temp |= 0b10000000; + impl Into for MCBoolean { + fn into(self) -> bool { + match self { + MCBoolean::True => true, + MCBoolean::False => false, } - out.push(temp); } - return out; } -} -impl std::fmt::Display for MCVarInt { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.value) - } -} -#[allow(dead_code)] -#[derive(Debug)] -pub struct MCString { - pub value: String, -} -#[allow(dead_code)] -impl MCString { - pub fn from_stream(t: &mut TcpStream) -> std::io::Result { - let length = MCVarInt::from_stream(t)?.value as u32; - let mut bytes = Vec::new(); - for _ in 0..length { - bytes.push(read_byte(t)?); + impl Display for MCBoolean { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + MCBoolean::True => "true", + MCBoolean::False => "false", + } + ) } - let value = String::from_utf8(bytes); - if value.is_ok() { + } + impl TryFrom> for MCBoolean { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 1 { + Err("Not enough bytes") + } else { + if bytes[0] == 1u8 { + Ok(MCBoolean::True) + } else { + Ok(MCBoolean::False) + } + } + } + } + impl Into> for MCBoolean { + fn into(self) -> Vec { + match self { + MCBoolean::True => vec![0x01], + MCBoolean::False => vec![0x00], + } + } + } + impl MCType for MCBoolean { + fn read(t: &mut TcpStream) -> std::io::Result { + let b = read_byte(t)?; + Ok(MCBoolean::try_from(vec![b]).unwrap()) + } + } + + #[derive(Debug, PartialEq)] + pub struct MCString { + pub value: String, + } + impl From<&str> for MCString { + fn from(s: &str) -> MCString { + MCString { + value: s.to_owned(), + } + } + } + impl From for MCString { + fn from(s: String) -> MCString { + MCString { value: s.clone() } + } + } + impl Into for MCString { + fn into(self) -> String { + self.value + } + } + impl PartialEq<&str> for MCString { + fn eq(&self, other: &&str) -> bool { + self.value == **other + } + } + impl PartialEq for MCString { + fn eq(&self, other: &String) -> bool { + self.value == *other + } + } + impl PartialEq<&String> for MCString { + fn eq(&self, other: &&String) -> bool { + self.value == **other + } + } + impl Clone for MCString { + fn clone(&self) -> Self { + MCString { + value: self.value.clone(), + } + } + } + impl Display for MCString { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "\"{}\" ({} chars)", self.value, self.value.len()) + } + } + impl TryFrom> for MCString { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("Cannot read MCString from bytes") + } + } + impl Into> for MCString { + fn into(self) -> Vec { + let mut out = vec![]; + let str_len: Vec = MCVarInt::from(self.value.len() as i32).into(); + for b in str_len { + out.push(b); + } + for b in self.value.into_bytes() { + out.push(b); + } + out + } + } + impl MCType for MCString { + fn read(t: &mut TcpStream) -> std::io::Result { + let str_len = MCVarInt::read(t)?; + let mut str_bytes = vec![]; + for _ in 0..str_len.into() { + str_bytes.push(read_byte(t)?); + } Ok(MCString { - value: value.unwrap(), + value: String::from_utf8_lossy(&str_bytes).to_string(), }) - } else { - return Err(io_error("MCString contains invalid utf-8")); } } - pub fn from_bytes(_: Vec) -> MCString { - panic!("Cannot construct MCVarInt from raw bytes"); + + #[derive(Debug, PartialEq)] + pub struct MCChat { + pub text: MCString, } - pub fn to_bytes(&self) -> Vec { - let mut out = Vec::new(); - let length = MCVarInt { - value: self.value.len() as i32, - }; - for b in length.to_bytes() { - out.push(b); + impl Clone for MCChat { + fn clone(&self) -> Self { + MCChat { + text: self.text.clone(), + } } - for b in self.value.clone().into_bytes() { - out.push(b); - } - out } -} -impl From<&str> for MCString { - fn from(s: &str) -> MCString { - MCString { - value: s.to_owned(), + impl Display for MCChat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "\"{}\" ({} chars)", + self.text.value, + self.text.value.len() + ) + } + } + impl TryFrom> for MCChat { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("Cannot read MCChat from bytes") + } + } + impl Into> for MCChat { + fn into(self) -> Vec { + // Just output + // {"text": ""} + let mut out = vec![]; + let mut temp = vec![]; + temp.extend_from_slice(&"{\"text\": \"".to_owned().into_bytes()); + temp.extend_from_slice(&self.text.value.into_bytes()); + temp.extend_from_slice(&"\"}".to_owned().into_bytes()); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } + } + impl MCType for MCChat { + fn read(_t: &mut TcpStream) -> std::io::Result { + Err(io_error("Cannot read MCChat from stream")) } } } -impl From for MCString { - fn from(s: String) -> MCString { - MCString { value: s.clone() } + +// All the numbers, from i8 and u8 to i64 and u64, plus VarInts. +pub mod numbers { + use super::*; + use std::convert::{From, Into, TryFrom}; + use std::fmt::Display; + + // Byte: i8 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCByte { + pub value: i8, // -128 to 127 } -} -impl Clone for MCString { - fn clone(&self) -> Self { - MCString { - value: self.value.clone(), + impl MCByte { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + Ok(MCByte::from_bytes(vec![read_byte(t)?])) + } + pub fn from_bytes(v: Vec) -> MCByte { + MCByte { + value: get_bytes(v, 1)[0] as i8, + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCByte { + fn from(v: i8) -> MCByte { + MCByte { value: v } + } + } + impl Into for MCByte { + fn into(self) -> i8 { + self.value + } + } + impl PartialEq for MCByte { + fn eq(&self, other: &i8) -> bool { + self.value == *other + } + } + impl Display for MCByte { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCByte { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 1 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 1]; + a.copy_from_slice(&get_bytes(bytes, 1)); + Ok(MCByte { + value: i8::from_be_bytes(a), + }) + } + } + } + impl Into> for MCByte { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCByte { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..1 { + bytes.push(read_byte(t)?); + } + Ok(MCByte::try_from(bytes).unwrap()) + } + } + + // Unsigned Byte: u8 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCUnsignedByte { + pub value: u8, // 0 to 255 + } + impl MCUnsignedByte { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + Ok(MCUnsignedByte::from_bytes(vec![read_byte(t)?])) + } + pub fn from_bytes(v: Vec) -> MCUnsignedByte { + MCUnsignedByte { + value: get_bytes(v, 1)[0], + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCUnsignedByte { + fn from(v: u8) -> MCUnsignedByte { + MCUnsignedByte { value: v } + } + } + impl Into for MCUnsignedByte { + fn into(self) -> u8 { + self.value + } + } + impl PartialEq for MCUnsignedByte { + fn eq(&self, other: &u8) -> bool { + self.value == *other + } + } + impl Display for MCUnsignedByte { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCUnsignedByte { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 1 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 1]; + a.copy_from_slice(&get_bytes(bytes, 1)); + Ok(MCUnsignedByte { + value: u8::from_be_bytes(a), + }) + } + } + } + impl Into> for MCUnsignedByte { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCUnsignedByte { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..1 { + bytes.push(read_byte(t)?); + } + Ok(MCUnsignedByte::try_from(bytes).unwrap()) + } + } + + // Short: i16 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCShort { + pub value: i16, // -32768 to 32767 + } + impl MCShort { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + bytes.push(read_byte(t)?); // MSD + bytes.push(read_byte(t)?); // LSD + Ok(MCShort::from_bytes(bytes)) + } + pub fn from_bytes(v: Vec) -> MCShort { + let mut a = [0u8; 2]; + a.copy_from_slice(&get_bytes(v, 2)); + MCShort { + value: i16::from_be_bytes(a), + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCShort { + fn from(v: i16) -> MCShort { + MCShort { value: v } + } + } + impl Into for MCShort { + fn into(self) -> i16 { + self.value + } + } + impl PartialEq for MCShort { + fn eq(&self, other: &i16) -> bool { + self.value == *other + } + } + impl Display for MCShort { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCShort { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 2 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 2]; + a.copy_from_slice(&get_bytes(bytes, 2)); + Ok(MCShort { + value: i16::from_be_bytes(a), + }) + } + } + } + impl Into> for MCShort { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCShort { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..2 { + bytes.push(read_byte(t)?); + } + Ok(MCShort::try_from(bytes).unwrap()) + } + } + + // Unsigned Short: u16 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCUnsignedShort { + pub value: u16, // 0 to 65535 + } + impl MCUnsignedShort { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + bytes.push(read_byte(t)?); // MSD + bytes.push(read_byte(t)?); // LSD + Ok(MCUnsignedShort::from_bytes(bytes)) + } + pub fn from_bytes(v: Vec) -> MCUnsignedShort { + let mut a = [0u8; 2]; + a.copy_from_slice(&get_bytes(v, 2)); + MCUnsignedShort { + value: u16::from_be_bytes(a), + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCUnsignedShort { + fn from(v: u16) -> MCUnsignedShort { + MCUnsignedShort { value: v } + } + } + impl Into for MCUnsignedShort { + fn into(self) -> u16 { + self.value + } + } + impl PartialEq for MCUnsignedShort { + fn eq(&self, other: &u16) -> bool { + self.value == *other + } + } + impl Display for MCUnsignedShort { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCUnsignedShort { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 2 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 2]; + a.copy_from_slice(&get_bytes(bytes, 2)); + Ok(MCUnsignedShort { + value: u16::from_be_bytes(a), + }) + } + } + } + impl Into> for MCUnsignedShort { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCUnsignedShort { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..2 { + bytes.push(read_byte(t)?); + } + Ok(MCUnsignedShort::try_from(bytes).unwrap()) + } + } + + // Int: i32 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCInt { + pub value: i32, // -2147483648 to 2147483647 + } + impl MCInt { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..4 { + bytes.push(read_byte(t)?); + } + Ok(MCInt::from_bytes(bytes)) + } + pub fn from_bytes(v: Vec) -> MCInt { + let mut a = [0u8; 4]; + a.copy_from_slice(&get_bytes(v, 4)); + MCInt { + value: i32::from_be_bytes(a), + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCInt { + fn from(v: i32) -> MCInt { + MCInt { value: v } + } + } + impl Into for MCInt { + fn into(self) -> i32 { + self.value + } + } + impl PartialEq for MCInt { + fn eq(&self, other: &i32) -> bool { + self.value == *other + } + } + impl Display for MCInt { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCInt { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 4 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 4]; + a.copy_from_slice(&get_bytes(bytes, 4)); + Ok(MCInt { + value: i32::from_be_bytes(a), + }) + } + } + } + impl Into> for MCInt { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCInt { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..4 { + bytes.push(read_byte(t)?); + } + Ok(MCInt::try_from(bytes).unwrap()) + } + } + + // Unsigned Int: u32 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCUnsignedInt { + pub value: u32, // 0 to 4294967295 + } + impl MCUnsignedInt { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..4 { + bytes.push(read_byte(t)?); + } + Ok(MCUnsignedInt::from_bytes(bytes)) + } + pub fn from_bytes(v: Vec) -> MCUnsignedInt { + let mut a = [0u8; 4]; + a.copy_from_slice(&get_bytes(v, 4)); + MCUnsignedInt { + value: u32::from_be_bytes(a), + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCUnsignedInt { + fn from(v: u32) -> MCUnsignedInt { + MCUnsignedInt { value: v } + } + } + impl Into for MCUnsignedInt { + fn into(self) -> u32 { + self.value + } + } + impl PartialEq for MCUnsignedInt { + fn eq(&self, other: &u32) -> bool { + self.value == *other + } + } + impl Display for MCUnsignedInt { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCUnsignedInt { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 4 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 4]; + a.copy_from_slice(&get_bytes(bytes, 4)); + Ok(MCUnsignedInt { + value: u32::from_be_bytes(a), + }) + } + } + } + impl Into> for MCUnsignedInt { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCUnsignedInt { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..4 { + bytes.push(read_byte(t)?); + } + Ok(MCUnsignedInt::try_from(bytes).unwrap()) + } + } + + // Long: i64 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCLong { + pub value: i64, // -9223372036854775808 to 9223372036854775807 + } + impl MCLong { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..8 { + bytes.push(read_byte(t)?); + } + Ok(MCLong::from_bytes(bytes)) + } + pub fn from_bytes(v: Vec) -> MCLong { + let mut a = [0u8; 8]; + a.copy_from_slice(&get_bytes(v, 8)); + MCLong { + value: i64::from_be_bytes(a), + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCLong { + fn from(v: i64) -> MCLong { + MCLong { value: v } + } + } + impl Into for MCLong { + fn into(self) -> i64 { + self.value + } + } + impl PartialEq for MCLong { + fn eq(&self, other: &i64) -> bool { + self.value == *other + } + } + impl Display for MCLong { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCLong { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 8 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 8]; + a.copy_from_slice(&get_bytes(bytes, 8)); + Ok(MCLong { + value: i64::from_be_bytes(a), + }) + } + } + } + impl Into> for MCLong { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCLong { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..8 { + bytes.push(read_byte(t)?); + } + Ok(MCLong::try_from(bytes).unwrap()) + } + } + + // Unsigned Long: u64 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCUnsignedLong { + pub value: u64, // 0 to 18446744073709551615 + } + impl MCUnsignedLong { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..8 { + bytes.push(read_byte(t)?); + } + Ok(MCUnsignedLong::from_bytes(bytes)) + } + pub fn from_bytes(v: Vec) -> MCUnsignedLong { + let mut a = [0u8; 8]; + a.copy_from_slice(&get_bytes(v, 8)); + MCUnsignedLong { + value: u64::from_be_bytes(a), + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCUnsignedLong { + fn from(v: u64) -> MCUnsignedLong { + MCUnsignedLong { value: v } + } + } + impl Into for MCUnsignedLong { + fn into(self) -> u64 { + self.value + } + } + impl PartialEq for MCUnsignedLong { + fn eq(&self, other: &u64) -> bool { + self.value == *other + } + } + impl Display for MCUnsignedLong { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCUnsignedLong { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 8 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 8]; + a.copy_from_slice(&get_bytes(bytes, 8)); + Ok(MCUnsignedLong { + value: u64::from_be_bytes(a), + }) + } + } + } + impl Into> for MCUnsignedLong { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCUnsignedLong { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..8 { + bytes.push(read_byte(t)?); + } + Ok(MCUnsignedLong::try_from(bytes).unwrap()) + } + } + + // Float: f32 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCFloat { + pub value: f32, // 32-bit floating point number + } + impl MCFloat { + pub fn from_stream(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..4 { + bytes.push(read_byte(t)?); + } + Ok(MCFloat::from_bytes(bytes)) + } + pub fn from_bytes(v: Vec) -> MCFloat { + let mut a = [0u8; 4]; + a.copy_from_slice(&get_bytes(v, 4)); + MCFloat { + value: f32::from_be_bytes(a), + } + } + pub fn to_bytes(&self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl From for MCFloat { + fn from(v: f32) -> MCFloat { + MCFloat { value: v } + } + } + impl Into for MCFloat { + fn into(self) -> f32 { + self.value + } + } + impl PartialEq for MCFloat { + fn eq(&self, other: &f32) -> bool { + self.value == *other + } + } + impl Display for MCFloat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCFloat { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 4 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 4]; + a.copy_from_slice(&get_bytes(bytes, 4)); + Ok(MCFloat { + value: f32::from_be_bytes(a), + }) + } + } + } + impl Into> for MCFloat { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCFloat { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..4 { + bytes.push(read_byte(t)?); + } + Ok(MCFloat::try_from(bytes).unwrap()) + } + } + + // Double: f64 + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCDouble { + pub value: f64, // 64-bit floating point number + } + impl From for MCDouble { + fn from(v: f64) -> MCDouble { + MCDouble { value: v } + } + } + impl Into for MCDouble { + fn into(self) -> f64 { + self.value + } + } + impl PartialEq for MCDouble { + fn eq(&self, other: &f64) -> bool { + self.value == *other + } + } + impl Display for MCDouble { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCDouble { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + if bytes.len() < 8 { + Err("Not enough bytes") + } else { + let mut a = [0u8; 8]; + a.copy_from_slice(&get_bytes(bytes, 8)); + Ok(MCDouble { + value: f64::from_be_bytes(a), + }) + } + } + } + impl Into> for MCDouble { + fn into(self) -> Vec { + self.value.to_be_bytes().to_vec() + } + } + impl MCType for MCDouble { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut bytes = Vec::new(); + for _ in 0..8 { + bytes.push(read_byte(t)?); + } + Ok(MCDouble::try_from(bytes).unwrap()) + } + } + + #[derive(Debug, Copy, Clone, PartialEq)] + pub struct MCVarInt { + pub value: i32, // Variable length 32-bit integer + } + impl From for MCVarInt { + fn from(v: i32) -> MCVarInt { + MCVarInt { value: v } + } + } + impl Into for MCVarInt { + fn into(self) -> i32 { + self.value + } + } + impl PartialEq for MCVarInt { + fn eq(&self, other: &i32) -> bool { + self.value == *other + } + } + impl Display for MCVarInt { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.value) + } + } + impl TryFrom> for MCVarInt { + type Error = &'static str; + fn try_from(bytes: Vec) -> Result { + let mut num_read = 0; + let mut result: i32 = 0; + loop { + let value = bytes[num_read] & 0b01111111; + result |= (value << (7 * num_read)) as i32; + if bytes[num_read] & 0b10000000 == 0x00 { + break; + } + num_read += 1; + if num_read == bytes.len() { + return Err("Not enough bytes"); + } + if num_read > 5 { + return Err("VarInt is too big"); + } + } + Ok(MCVarInt { value: result }) + } + } + impl Into> for MCVarInt { + fn into(self) -> Vec { + let mut value = self.value; + let mut run_once = false; + let mut out: Vec = Vec::new(); + while value != 0 || !run_once { + run_once = true; + let mut temp: u8 = (value & 0b01111111) as u8; + value >>= 7; + if value != 0 { + temp |= 0b10000000; + } + out.push(temp); + } + return out; + } + } + impl MCType for MCVarInt { + fn read(t: &mut TcpStream) -> std::io::Result { + let mut numRead = 0; + let mut result = 0i32; + let mut read = 0u8; + let mut run_once = false; + while (read & 0b10000000) != 0 || !run_once { + run_once = true; + read = read_byte(t)?; + let value = (read & 0b01111111) as i32; + result |= value << (7 * numRead); + numRead += 1; + if numRead > 5 { + return Err(io_error("MCVarInt is too big")); + } + } + Ok(MCVarInt { value: result }) } } } -impl std::fmt::Display for MCString { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "\"{}\" ({} chars)", self.value, self.value.len()) - } -} diff --git a/src/net.rs b/src/net.rs deleted file mode 100644 index c1d5114..0000000 --- a/src/net.rs +++ /dev/null @@ -1,188 +0,0 @@ -// net.rs -// authors: Garen Tyler, Danton Hou -// 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); - let listener = TcpListener::bind(server_address); - if listener.is_err() { - log.error("Could not start listener"); - } else { - log.important(&format!("Started server on {}", server_address)); - for stream in listener.unwrap().incoming() { - if stream.is_err() { - log.error("Could not connect to client"); - } else { - std::thread::spawn(move || { - if let Err(e) = handle_client(stream.unwrap()) { - log.error(&format!("Error when handling client: {}", e)); - } - }); - } - } - } -} -fn handle_client(t: TcpStream) -> std::io::Result<()> { - log.info("Got a client!"); - let mut gc = GameConnection { - stream: t, - state: GameState::Handshake, - protocol_version: 0, - }; - - 'main: loop { - match gc.state { - GameState::Handshake => { - // Read the handshake packet. - let (_packet_len, _packet_id) = read_packet_header(&mut gc.stream)?; - let handshake = Handshake::read(&mut gc.stream)?; - log.info(&format!("{:?}", handshake)); - gc.state = if handshake.protocol_version.value != config.protocol_version as i32 - && handshake.next_state.value == 2 - { - GameState::Closed - } else { - match handshake.next_state.value { - 1 => GameState::Status, - 2 => GameState::Login, - _ => GameState::Closed, - } - }; - log.info(&format!("Next state: {:?}", gc.state)); - gc.protocol_version = handshake.protocol_version.value as u16; - } - GameState::Status => { - // Read the request packet. - let (_request_packet_len, _request_packet_id) = read_packet_header(&mut gc.stream)?; - // Send the response packet. - log.warn("Server favicon not working correctly. Fix this in issue #4"); - let mut base64_encoded_favicon = "".to_owned(); - let a = || -> std::io::Result> { - // Only call this if config.favicon is not None, or it'll panic. - use std::fs::File; - use std::io::prelude::*; - let mut file = File::open(config.favicon.as_ref().unwrap())?; - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer)?; - Ok(buffer) - }; - if config.favicon.is_some() { - let temp = a(); - if let Ok(s) = temp { - base64_encoded_favicon = radix64::STD.encode(&s); - } else { - println!("{:?}", temp); - } - } - let response = MCString::from(format!("{{\n\t\"version\": {{\n\t\t\"name\": \"Composition 1.15.2\",\n\t\t\"protocol\": {}\n\t}},\n\t\"players\": {{\n\t\t\"max\": {},\n\t\t\"online\": 2147483648,\n\t\t\"sample\": [\n\t\t\t{{\n\t\t\t\t\"name\": \"fumolover12\",\n\t\t\t\t\"id\": \"4566e69f-c907-48ee-8d71-d7ba5aa00d20\"\n\t\t\t}}\n\t\t]\n\t}},\n\t\"description\": {{\n\t\t\"text\": \"{}\"\n\t}},\n\t\"favicon\": \"data:image/png;base64,{}\"\n}}", config.protocol_version, config.max_players, config.motd, base64_encoded_favicon)); - let packet_id = MCVarInt::from(0x00); - let packet_len = MCVarInt::from( - packet_id.to_bytes().len() as i32 + response.to_bytes().len() as i32, - ); - 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 response.to_bytes() { - write_byte(&mut gc.stream, b)?; - } - // Read the ping packet. - let (_ping_packet_len, _ping_packet_id) = read_packet_header(&mut gc.stream)?; - let num = MCLong::from_stream(&mut gc.stream)?; - log.info(&format!("Ping number: {:?}", num)); - // Send the pong packet. - let packet_id = MCVarInt::from(0x01); - let packet_len = MCVarInt::from(packet_id.to_bytes().len() as i32 + 8i32); - 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 num.to_bytes() { - write_byte(&mut gc.stream, b)?; - } - gc.state = GameState::Closed; - } - GameState::Login => { - // Read the login start packet. - 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 => { - log.info(&format!( - "Client at {} closed connection", - gc.stream.peer_addr().unwrap() - )); - break 'main; - } - } - } - - Ok(()) -} - -#[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 protocol_version: u16, -} diff --git a/src/net/mod.rs b/src/net/mod.rs new file mode 100644 index 0000000..8fb3a4a --- /dev/null +++ b/src/net/mod.rs @@ -0,0 +1,148 @@ +pub mod packets; + +use crate::mctypes::*; +use log::{debug, error, info, warn}; +use packets::*; +use std::net::{TcpListener, TcpStream, ToSocketAddrs}; +use std::sync::mpsc::{self, Receiver, Sender, TryRecvError}; + +pub struct NetworkServer { + pub clients: Vec, + receiver: Receiver, +} +impl NetworkServer { + pub fn new(addr: A) -> NetworkServer { + let (tx, rx) = mpsc::channel(); + std::thread::spawn(move || { + let listener = TcpListener::bind(addr).expect("Could not bind to TCP socket"); + for (id, stream) in listener.incoming().enumerate() { + if let Ok(s) = stream { + tx.send(NetworkClient { + id: id as u128, + connected: true, + stream: s, + state: NetworkClientState::Handshake, + }) + .expect("Network receiver disconnected"); + } + } + }); + info!("Network server started!"); + NetworkServer { + clients: vec![], + receiver: rx, + } + } + pub fn update(&mut self) { + loop { + match self.receiver.try_recv() { + Ok(client) => { + info!( + "Got client at {}", + client.stream.peer_addr().expect("Could not get peer addr") + ); + self.clients.push(client) + } + Err(TryRecvError::Empty) => break, + Err(TryRecvError::Disconnected) => panic!("Network sender disconnected"), + } + } + for client in self.clients.iter_mut() { + client.update(); + } + } +} +pub enum NetworkClientState { + Handshake, + Status, + Login, + Play, + Disconnected, +} +pub struct NetworkClient { + pub id: u128, + pub connected: bool, + pub stream: TcpStream, + pub state: NetworkClientState, +} +impl NetworkClient { + pub fn update(&mut self) { + match self.state { + NetworkClientState::Handshake => { + let (_packet_length, _packet_id) = read_packet_header(&mut self.stream).unwrap(); + let handshake = Handshake::read(&mut self.stream).unwrap(); + // Minecraft versions 1.8 - 1.8.9 use protocol version 47. + let compatible_versions = handshake.protocol_version == 47; + let next_state = match handshake.next_state.into() { + 1 => NetworkClientState::Status, + 2 => NetworkClientState::Login, + _ => NetworkClientState::Disconnected, + }; + self.state = next_state; + // If incompatible versions or wrong next state + if !compatible_versions { + let mut logindisconnect = LoginDisconnect::new(); + logindisconnect.reason = MCChat { + text: MCString::from("Incompatible client! Server is on 1.8.9"), + }; + logindisconnect.write(&mut self.stream).unwrap(); + self.state = NetworkClientState::Disconnected; + } + println!("{:?}", handshake); + } + NetworkClientState::Status => { + let (_packet_length, _packet_id) = read_packet_header(&mut self.stream).unwrap(); + let statusrequest = StatusRequest::read(&mut self.stream).unwrap(); + println!("{:?}", statusrequest); + let mut statusresponse = StatusResponse::new(); + statusresponse.json_response = r#"{ + "version": { + "name": "1.8.7", + "protocol": 47 + }, + "players": { + "max": 100, + "online": 5, + "sample": [ + { + "name": "thinkofdeath", + "id": "4566e69f-c907-48ee-8d71-d7ba5aa00d20" + } + ] + }, + "description": { + "text": "Hello world" + }, + "sample": "" +}"# + .into(); + statusresponse.write(&mut self.stream).unwrap(); + println!("{:?}", statusresponse); + let (_packet_length, _packet_id) = read_packet_header(&mut self.stream).unwrap(); + let statusping = StatusPing::read(&mut self.stream).unwrap(); + println!("{:?}", statusping); + let mut statuspong = StatusPong::new(); + statuspong.payload = statusping.payload; + statuspong.write(&mut self.stream).unwrap(); + self.state = NetworkClientState::Disconnected; + } + NetworkClientState::Login => { + let (_packet_length, _packet_id) = read_packet_header(&mut self.stream).unwrap(); + let loginstart = LoginStart::read(&mut self.stream).unwrap(); + println!("{:?}", loginstart); + // Offline mode skips encryption and compression. + let mut loginsuccess = LoginSuccess::new(); + // We're in offline mode, so this is a temporary uuid. + loginsuccess.uuid = "00000000-0000-3000-0000-000000000000".into(); + loginsuccess.username = loginstart.player_name; + loginsuccess.write(&mut self.stream).unwrap(); + println!("{:?}", loginsuccess); + self.state = NetworkClientState::Play; + } + NetworkClientState::Play => {} + NetworkClientState::Disconnected => { + self.connected = false; + } + } + } +} diff --git a/src/net/packets/clientbound.rs b/src/net/packets/clientbound.rs new file mode 100644 index 0000000..6c0754e --- /dev/null +++ b/src/net/packets/clientbound.rs @@ -0,0 +1,166 @@ +use super::Packet; +use crate::mctypes::*; +use std::convert::{Into, TryFrom}; +use std::net::TcpStream; + +#[derive(Debug, Clone)] +pub struct StatusResponse { + pub json_response: MCString, +} +impl Into> for StatusResponse { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x00).into(); // 0x00 Status Response. + temp.extend_from_slice(&Into::>::into(self.json_response)); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for StatusResponse { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for StatusResponse { + fn new() -> Self { + StatusResponse { + json_response: MCString::from(""), + } + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut statusresponse = StatusResponse::new(); + statusresponse.json_response = MCString::read(t)?; + Ok(statusresponse) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct StatusPong { + pub payload: MCLong, +} +impl Into> for StatusPong { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x01).into(); // 0x01 Status Pong. + temp.extend_from_slice(&Into::>::into(self.payload)); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for StatusPong { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for StatusPong { + fn new() -> Self { + StatusPong { payload: 0.into() } + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut statuspong = StatusPong::new(); + statuspong.payload = MCLong::read(t)?; + Ok(statuspong) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct LoginSuccess { + pub uuid: MCString, + pub username: MCString, +} +impl Into> for LoginSuccess { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x02).into(); // 0x02 Login Success. + temp.extend_from_slice(&Into::>::into(self.uuid)); + temp.extend_from_slice(&Into::>::into(self.username)); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for LoginSuccess { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for LoginSuccess { + fn new() -> Self { + LoginSuccess { + uuid: MCString::from(""), + username: MCString::from(""), + } + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut loginsuccess = LoginSuccess::new(); + loginsuccess.uuid = MCString::read(t)?; + loginsuccess.username = MCString::read(t)?; + Ok(loginsuccess) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct LoginDisconnect { + pub reason: MCChat, +} +impl Into> for LoginDisconnect { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x00).into(); // 0x00 Login Disconnect. + temp.extend_from_slice(&Into::>::into(self.reason)); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for LoginDisconnect { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for LoginDisconnect { + fn new() -> Self { + LoginDisconnect { + reason: MCChat { + text: MCString::from(""), + }, + } + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut logindisconnect = LoginDisconnect::new(); + logindisconnect.reason = MCChat { + text: MCString::read(t)?, + }; + Ok(logindisconnect) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} diff --git a/src/net/packets/mod.rs b/src/net/packets/mod.rs new file mode 100644 index 0000000..0914bb6 --- /dev/null +++ b/src/net/packets/mod.rs @@ -0,0 +1,20 @@ +pub mod clientbound; +pub mod serverbound; + +use crate::mctypes::{MCType, MCVarInt}; +pub use clientbound::*; +pub use serverbound::*; +use std::convert::{Into, TryFrom}; +use std::net::TcpStream; + +pub trait Packet: Into> + TryFrom> { + fn new() -> Self; + fn read(_stream: &mut TcpStream) -> std::io::Result; + fn write(&self, _stream: &mut TcpStream) -> std::io::Result<()>; +} + +pub fn read_packet_header(t: &mut TcpStream) -> std::io::Result<(MCVarInt, MCVarInt)> { + let length = MCVarInt::read(t)?; + let id = MCVarInt::read(t)?; + Ok((length, id)) +} diff --git a/src/net/packets/serverbound.rs b/src/net/packets/serverbound.rs new file mode 100644 index 0000000..da08428 --- /dev/null +++ b/src/net/packets/serverbound.rs @@ -0,0 +1,164 @@ +use super::Packet; +use crate::mctypes::*; +use std::convert::{Into, TryFrom}; +use std::net::TcpStream; + +#[derive(Debug, Clone)] +pub struct Handshake { + pub protocol_version: MCVarInt, + pub server_address: MCString, + pub server_port: MCUnsignedShort, + pub next_state: MCVarInt, +} +impl Into> for Handshake { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x00).into(); // 0x00 Handshake. + temp.extend_from_slice(&Into::>::into(self.protocol_version)); + temp.extend_from_slice(&Into::>::into(self.server_address)); + temp.extend_from_slice(&Into::>::into(self.server_port)); + temp.extend_from_slice(&Into::>::into(self.next_state)); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for Handshake { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for Handshake { + fn new() -> Self { + Handshake { + protocol_version: 0.into(), + server_address: "".into(), + server_port: 0.into(), + next_state: 0.into(), + } + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut handshake = Handshake::new(); + handshake.protocol_version = MCVarInt::read(t)?; + handshake.server_address = MCString::read(t)?; + handshake.server_port = MCUnsignedShort::read(t)?; + handshake.next_state = MCVarInt::read(t)?; + Ok(handshake) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct StatusRequest {} +impl Into> for StatusRequest { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x00).into(); // 0x00 Status Request. + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for StatusRequest { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for StatusRequest { + fn new() -> Self { + StatusRequest {} + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut statusrequest = StatusRequest::new(); + Ok(statusrequest) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct StatusPing { + pub payload: MCLong, +} +impl Into> for StatusPing { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x01).into(); // 0x01 Status Pong. + temp.extend_from_slice(&Into::>::into(self.payload)); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for StatusPing { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for StatusPing { + fn new() -> Self { + StatusPing { payload: 0.into() } + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut statusping = StatusPing::new(); + statusping.payload = MCLong::read(t)?; + Ok(statusping) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct LoginStart { + pub player_name: MCString, +} +impl Into> for LoginStart { + fn into(self) -> Vec { + let mut out = vec![]; + let mut temp: Vec = MCVarInt::from(0x00).into(); // 0x00 Login Start. + temp.extend_from_slice(&Into::>::into(self.player_name)); + out.extend_from_slice(&Into::>::into(MCVarInt::from(temp.len() as i32))); + out.extend_from_slice(&temp); + out + } +} +impl TryFrom> for LoginStart { + type Error = &'static str; + fn try_from(_bytes: Vec) -> Result { + Err("unimplemented") + } +} +impl Packet for LoginStart { + fn new() -> Self { + LoginStart { + player_name: "".into(), + } + } + fn read(t: &mut TcpStream) -> std::io::Result { + let mut loginstart = LoginStart::new(); + loginstart.player_name = MCString::read(t)?; + Ok(loginstart) + } + fn write(&self, t: &mut TcpStream) -> std::io::Result<()> { + for b in Into::>::into(self.clone()) { + write_byte(t, b)?; + } + Ok(()) + } +} diff --git a/src/network/mod.rs b/src/network/mod.rs deleted file mode 100644 index 1f6756b..0000000 --- a/src/network/mod.rs +++ /dev/null @@ -1,84 +0,0 @@ -// network/mod.rs -// authors: Garen Tyler -// description: -// This module contains the network logic. - -pub mod packet; - -use crate::server::ServerMessage; -use log::{debug, error, info, warn}; -use packet::Packet; -use std::io::BufReader; -use std::net::{TcpListener, TcpStream}; -use std::sync::mpsc::{self, Receiver, Sender}; - -pub struct NetworkServer { - receiver: Receiver, - clients: Vec, -} -impl NetworkServer { - pub fn new(port: u16) -> NetworkServer { - let (tx, rx) = mpsc::channel(); - std::thread::spawn(move || NetworkServer::listen(port, tx)); - NetworkServer { - receiver: rx, - clients: Vec::new(), - } - } - fn listen(port: u16, sender: Sender) { - let listener = TcpListener::bind(&format!("0.0.0.0:{}", port)).unwrap(); - - for (index, stream) in listener.incoming().enumerate() { - let stream = stream.unwrap(); - stream.set_nonblocking(true).unwrap(); - sender - .send(NetworkClient { - // The index will increment after each client making it unique. We'll just use this as the id. - id: index as u32, - stream: BufReader::new(stream), - state: NetworkClientState::Handshake, - packets: Vec::new(), - username: None, - alive: true, - }) - .unwrap(); - } - } - pub fn update(&mut self) { - loop { - match self.receiver.try_recv() { - Ok(client) => self.clients.push(client), - Err(mpsc::TryRecvError::Empty) => break, - Err(mpsc::TryRecvError::Disconnected) => { - panic!("Client receiver channel disconnected!") - } - } - } - // Todo: Update each client - for client in self.clients.iter_mut() { - client.update(); - } - } -} - -#[derive(Debug)] -pub struct NetworkClient { - id: u32, - state: NetworkClientState, - alive: bool, - stream: BufReader, - username: Option, - packets: Vec, -} - -impl NetworkClient { - pub fn update(&mut self) {} -} - -#[derive(PartialEq, Debug)] -pub enum NetworkClientState { - Handshake, - Status, - Login, - Play, -} diff --git a/src/network/packet/mod.rs b/src/network/packet/mod.rs deleted file mode 100644 index c70fc5a..0000000 --- a/src/network/packet/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -// network/packet/mod.rs -// authors: Garen Tyler -// description: -// This module contains the packet structs. - -#[derive(Debug)] -pub struct Packet { - kind: PacketType, -} -#[derive(PartialEq, Debug)] -pub enum PacketType { - Handshake, -} diff --git a/src/protocol.rs b/src/protocol.rs deleted file mode 100644 index 8f13bc3..0000000 --- a/src/protocol.rs +++ /dev/null @@ -1,102 +0,0 @@ -// protocol.rs -// author: Garen Tyler -// description: -// This module contains all the packet structs. -// Not all of them are implemented, and new ones will be added as necessary. - -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, Clone)] -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 { - 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 { - 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, Clone)] -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 { - Ok(LoginStart::new(MCString::from_stream(t)?)) - } - pub fn to_bytes(&self) -> Vec { - 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 { - 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 - } -} diff --git a/src/server.rs b/src/server.rs deleted file mode 100644 index c696535..0000000 --- a/src/server.rs +++ /dev/null @@ -1,75 +0,0 @@ -// server.rs -// author: Garen Tyler -// description: -// Contains the server logic. - -use crate::network::NetworkServer; -use log::{debug, error, info, warn}; -use serde::{Deserialize, Serialize}; -use std::sync::mpsc::{self, Receiver, Sender, TryRecvError}; - -pub struct Server { - pub config: ServerConfig, - pub receiver: Receiver, - pub network: NetworkServer, -} -impl Server { - pub fn update(&mut self) { - // Do a tick. - while let Ok(message) = self.receiver.try_recv() { - debug!("Server received message: {:?}", message); - self.handle_message(message); - } - self.network.update(); - } - fn handle_message(&self, message: ServerMessage) {} - pub fn shutdown(&self) { - unimplemented!(); - } -} - -#[derive(Serialize, Deserialize, Clone)] -pub struct ServerConfig { - pub port: u16, - pub protocol_version: u16, - pub max_players: u32, - pub motd: String, - pub favicon: Option, -} -impl ServerConfig { - pub fn default() -> ServerConfig { - ServerConfig { - port: 25565, - protocol_version: 578, - max_players: 250, - motd: "Hello world!".to_owned(), - favicon: None, - } - } - pub fn from_file(filename: &str) -> ServerConfig { - use std::fs::File; - use std::io::prelude::*; - let a = || -> std::io::Result { - 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 { - warn!( - "Could not load config from {}, using default config.", - filename - ); - ServerConfig::default() - } - } -} - -#[derive(Debug)] -pub enum BroadcastMessage { - Shutdown, -} -#[derive(Debug)] -pub enum ServerMessage {} diff --git a/src/server/mod.rs b/src/server/mod.rs new file mode 100644 index 0000000..a9a4333 --- /dev/null +++ b/src/server/mod.rs @@ -0,0 +1,11 @@ +use crate::net::{NetworkClient, NetworkClientState, NetworkServer}; +use log::{debug, error, info, warn}; + +pub struct GameServer { + pub network: NetworkServer, +} +impl GameServer { + pub fn update(&mut self) { + self.network.update(); + } +}