-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from ferrumc-rs/rewrite/db
Database importing
- Loading branch information
Showing
44 changed files
with
1,291 additions
and
343 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# IP or hostname where the server will bind. Leave as 0.0.0.0 if you want it to be accessible from any IP. | ||
host = "0.0.0.0" | ||
# Server port (0-65535). Minecraft's default port is 25565, so you probably want to leave it as is. | ||
port = 25565 | ||
# Message of the day. A random one will be selected. | ||
motd = ["Welcome to the best server ever!", "Rust", "Good luck, have fun!"] | ||
# Maximum number of players | ||
max_players = 100 | ||
# How many network updates per second per user | ||
network_tick_rate = 30 | ||
# World name to load | ||
world = "world" | ||
# Network compression threshold (can be negative). This decides how long a packet has to be before it is compressed. | ||
# Very small packets may actually increase in size when compressed, so setting it to 0 won't be perfect in all situations. | ||
# Set to -1 to disable compression. | ||
network_compression_threshold = 64 | ||
|
||
# Database configuration | ||
[database] | ||
# Cache size in KB | ||
cache_size = 1024 | ||
# Compression algorithm (brotli, deflate, gzip, zlib, zstd) | ||
compression = "gzip" | ||
# Database backend (redb, rocksdb, sled, surrealkv) | ||
backend = "redb" | ||
# Path to the world database | ||
db_path = "/path/to/world/database" | ||
# Path to world import folder (e.g., %APPDATA%/.minecraft/saves/world) | ||
import_path = "/path/to/import/folder" | ||
# Compression level (0-22) for the database. Higher values mean less disk space but will take longer to read/write. | ||
compression_level = 5 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,9 @@ | |
Cargo.lock | ||
config.toml | ||
.temp | ||
|
||
.etc/blockstates.json | ||
|
||
.etc/blocks.json | ||
|
||
flame.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import bz2 | ||
import json | ||
|
||
|
||
def dict_reorder(item): | ||
return {k: dict_reorder(v) if isinstance(v, dict) else v for k, v in sorted(item.items())} | ||
|
||
out = {} | ||
|
||
with open("../.etc/blocks.json") as f: | ||
blocks = json.load(f) | ||
for block in blocks: | ||
data = blocks[block] | ||
for state in data["states"]: | ||
if "properties" in state: | ||
props = state["properties"] | ||
if "id" in state: | ||
block_id = state["id"] | ||
out[block_id] = {"name": block, "properties": props} | ||
else: | ||
block_id = state["id"] | ||
out[block_id] = {"name": block, "default": True} | ||
|
||
out = dict_reorder(out) | ||
|
||
with open("../.etc/blockstates.json", "w") as bs: | ||
json.dump(out, bs, indent=4) | ||
with open("../.etc/blockmappings.bz2", "wb") as f: | ||
as_string = json.dumps(out, separators=(',', ':')) | ||
print("Compressing and writing to file...") | ||
print("This may take a while.") | ||
f.write(bz2.compress(as_string.encode("utf-8"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import bz2 | ||
import gzip | ||
import lzma | ||
import time | ||
import zlib | ||
|
||
results = {} | ||
|
||
def compress_zlib_max(data): | ||
return zlib.compress(data, 9) | ||
|
||
def compress_zlib_min(data): | ||
return zlib.compress(data, 1) | ||
|
||
def compress_gzip_max(data): | ||
return gzip.compress(data, 5) | ||
|
||
def compress_gzip_min(data): | ||
return gzip.compress(data, 1) | ||
|
||
def compress_lzma(data): | ||
return lzma.compress(data) | ||
|
||
def compress_bzip2_max(data): | ||
return bz2.compress(data, 9) | ||
|
||
def compress_bzip2_min(data): | ||
return bz2.compress(data, 1) | ||
|
||
def compress_none(data): | ||
return data | ||
|
||
|
||
with open("../.etc/codec.nbt", "rb") as f: | ||
data = f.read() | ||
original_size = len(data) | ||
for algo in [compress_zlib_max, compress_zlib_min, compress_gzip_max, compress_gzip_min, compress_lzma, compress_bzip2_max, compress_bzip2_min, compress_none]: | ||
print(f"Testing {algo.__name__}...") | ||
times = [] | ||
sizediff = 0 | ||
for iteration in range(1, 3000): | ||
start = time.time_ns() | ||
compressed = algo(data) | ||
end = time.time_ns() | ||
times.append(end - start) | ||
sizediff = len(compressed) / original_size | ||
average_time = (sum(times) / len(times) / 1000) / 1000 | ||
results[algo.__name__] = { | ||
"average_time": average_time, | ||
"size_decrease_percentage": sizediff | ||
} | ||
for result in results: | ||
name = result | ||
average_time = results[result]["average_time"] | ||
sizediff = results[result]["size_decrease_percentage"] | ||
print(f"Algorithm: {name}") | ||
print(f"Average Time: {average_time:.3f} ms") | ||
print(f"Compressed Size: {sizediff*100:.2f}% of original size") | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import json | ||
|
||
path = input("Enter the path to the file: ") | ||
jsondata = "" | ||
with open(path, "r") as f: | ||
jsondata = json.load(f) | ||
with open(path, "w") as f: | ||
json.dump(jsondata, f, separators=(',', ':')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "anvil" | ||
name = "ferrumc-anvil" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.