From 4748bd00b1957b680061962dd203f46b2d854c59 Mon Sep 17 00:00:00 2001 From: Bryan Mainardi Date: Thu, 13 Mar 2025 21:11:01 +0100 Subject: [PATCH 1/7] Added mario-kart-8 server repository as submodule --- .gitmodules | 3 +++ repos/mario-kart-8 | 1 + 2 files changed, 4 insertions(+) create mode 160000 repos/mario-kart-8 diff --git a/.gitmodules b/.gitmodules index 75fd25c..c6a5664 100644 --- a/.gitmodules +++ b/.gitmodules @@ -91,3 +91,6 @@ path = repos/pikmin-3 url = https://github.com/PretendoNetwork/pikmin-3 branch = master ignore = dirty +[submodule "repos/mario-kart-8"] + path = repos/mario-kart-8 + url = https://github.com/Newtendo-Network/nex_mario_kart_8.git diff --git a/repos/mario-kart-8 b/repos/mario-kart-8 new file mode 160000 index 0000000..b5f9f94 --- /dev/null +++ b/repos/mario-kart-8 @@ -0,0 +1 @@ +Subproject commit b5f9f942a35fb67f0906da85461c6878f55a7f0d From 74588b19542178dc47e96ef90c3fbf6f44577e4c Mon Sep 17 00:00:00 2001 From: Bryan Mainardi Date: Wed, 19 Mar 2025 23:41:54 +0100 Subject: [PATCH 2/7] Created mario-kart-8 environment files --- environment/mario-kart-8.env | 14 ++++++++++++++ scripts/setup-environment.sh | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 environment/mario-kart-8.env diff --git a/environment/mario-kart-8.env b/environment/mario-kart-8.env new file mode 100644 index 0000000..6723e89 --- /dev/null +++ b/environment/mario-kart-8.env @@ -0,0 +1,14 @@ +PN_MK8_AUTHENTICATION_SERVER_PORT=5781 +PN_MK8_SECURE_SERVER_PORT=5782 +PN_MK8_FRIENDS_GRPC_HOST=friends +PN_MK8_FRIENDS_GRPC_PORT=5001 +PN_MK8_ACCOUNT_GRPC_HOST=account +PN_MK8_ACCOUNT_GRPC_PORT=5000 +PN_MK8_GRPC_PORT=5780 +PN_MK8_ACCOUNT_DATABASE=pretendo_account +PN_MK8_MONGO_HOST=mongodb +PN_MK8_MONGO_PORT=27017 +PN_MK8_CONFIG_S3_ENDPOINT=minio.pretendo.cc +PN_MK8_CONFIG_S3_ACCESS_KEY=minio_pretendo +PN_MK8_CONFIG_S3_BUCKET=amkj +PN_MK8_REDIS_URI=redis:6379 \ No newline at end of file diff --git a/scripts/setup-environment.sh b/scripts/setup-environment.sh index 3f2bff4..7c101ad 100755 --- a/scripts/setup-environment.sh +++ b/scripts/setup-environment.sh @@ -87,6 +87,7 @@ echo "PN_SMM_ACCOUNT_GRPC_API_KEY=$account_grpc_api_key" >>./super-mario-maker.l echo "PN_SPLATOON_ACCOUNT_GRPC_API_KEY=$account_grpc_api_key" >>./splatoon.local.env echo "PN_MINECRAFT_ACCOUNT_GRPC_API_KEY=$account_grpc_api_key" >>./minecraft-wiiu.local.env echo "PN_PIKMIN3_ACCOUNT_GRPC_API_KEY=$account_grpc_api_key" >>./pikmin-3.local.env +echo "PN_MK8_ACCOUNT_GRPC_API_KEY=$account_grpc_api_key" >>./mario-kart-8.local.env # Generate a secret key for MinIO minio_secret_key=$(generate_password 32) @@ -96,6 +97,7 @@ echo "PN_MIIVERSE_API_CONFIG_S3_ACCESS_SECRET=$minio_secret_key" >>./miiverse-ap echo "JUXT_CONFIG_AWS_SPACES_SECRET=$minio_secret_key" >>./juxtaposition-ui.local.env echo "PN_BOSS_CONFIG_S3_ACCESS_SECRET=$minio_secret_key" >>./boss.local.env echo "PN_SMM_CONFIG_S3_ACCESS_SECRET=$minio_secret_key" >>./super-mario-maker.local.env +echo "PN_MK8_CONFIG_S3_ACCESS_SECRET=$minio_secret_key" >>./mario-kart-8.local.env # Generate a password for Postgres postgres_password=$(generate_password 32) @@ -113,12 +115,17 @@ echo "PN_FRIENDS_CONFIG_SECURE_PASSWORD=$friends_secure_password" >>./friends.lo friends_api_key=$(generate_password 32) echo "PN_FRIENDS_CONFIG_GRPC_API_KEY=$friends_api_key" >>./friends.local.env echo "PN_WIIU_CHAT_FRIENDS_GRPC_API_KEY=$friends_api_key" >>./wiiu-chat.local.env +echo "PN_MK8_FRIENDS_GRPC_API_KEY=$friends_api_key" >>./wiiu-chat.local.env echo "PN_MIIVERSE_API_CONFIG_GRPC_FRIENDS_API_KEY=$friends_api_key" >>./miiverse-api.local.env echo "JUXT_CONFIG_GRPC_FRIENDS_API_KEY=$friends_api_key" >>./juxtaposition-ui.local.env echo "PN_BOSS_CONFIG_GRPC_FRIENDS_SERVER_API_KEY=$friends_api_key" >>./boss.local.env friends_aes_key=$(generate_hex 64) echo "PN_FRIENDS_CONFIG_AES_KEY=$friends_aes_key" >>./friends.local.env +# Generate a gRPC API Key for Mario Kart 8 server +mk8_api_key=$(generate_password 32) +echo "PN_MK8_GRPC_API_KEY=$mk8_api_key" >>./mario-kart-8.local.env + # Generate a Kerberos password for the Wii U Chat server chat_kerberos_password=$(generate_password 32) echo "PN_WIIU_CHAT_KERBEROS_PASSWORD=$chat_kerberos_password" >>./wiiu-chat.local.env @@ -138,6 +145,14 @@ echo "PN_MINECRAFT_KERBEROS_PASSWORD=$minecraft_kerberos_password" >>./minecraft pikmin3_kerberos_password=$(generate_password 32) echo "PN_PIKMIN3_KERBEROS_PASSWORD=$pikmin3_kerberos_password" >>./pikmin-3.local.env +# Generate a Kerberos password for the Mario Kart 8 server +mk8_kerberos_password=$(generate_password 32) +echo "PN_MK8_KERBEROS_PASSWORD=$mk8_kerberos_password" >>./mario-kart-8.local.env + +# Generate a secure password for the Mario Kart 8 server +mk8_secure_password=$(generate_password 32) +echo "PN_MK8_SECURE_PASSWORD=$mk8_secure_password" >>./mario-kart-8.local.env + # Generate an AES key for the Miiverse servers miiverse_aes_key=$(generate_hex 64) echo "PN_MIIVERSE_API_CONFIG_AES_KEY=$miiverse_aes_key" >>./miiverse-api.local.env @@ -156,6 +171,7 @@ echo "PN_SMM_SECURE_SERVER_HOST=$server_ip" >>./super-mario-maker.local.env echo "PN_SPLATOON_SECURE_SERVER_HOST=$server_ip" >>./splatoon.local.env echo "PN_MINECRAFT_SECURE_SERVER_HOST=$server_ip" >>./minecraft-wiiu.local.env echo "PN_PIKMIN3_SECURE_SERVER_HOST=$server_ip" >>./pikmin-3.local.env +echo "PN_MK8_SECURE_SERVER_HOST=$server_ip" >>./mario-kart-8.local.env # Get the Wii U IP address if [[ -n "$wiiu_ip" ]]; then From 88674c31cddfd2118ed5217d0936e6378db9edf8 Mon Sep 17 00:00:00 2001 From: Bryan Mainardi Date: Wed, 19 Mar 2025 23:42:27 +0100 Subject: [PATCH 3/7] Patches for mario-kart-8 server + fix submodule loading --- .../create_python_requirements.patch | 14 +++ .../mario-kart-8/create_server_config.patch | 104 ++++++++++++++++++ .../mario-kart-8/dockerfile-creation.patch | 34 ++++++ scripts/setup-submodule-patches.sh | 14 +-- 4 files changed, 159 insertions(+), 7 deletions(-) create mode 100644 patches/mario-kart-8/create_python_requirements.patch create mode 100644 patches/mario-kart-8/create_server_config.patch create mode 100644 patches/mario-kart-8/dockerfile-creation.patch diff --git a/patches/mario-kart-8/create_python_requirements.patch b/patches/mario-kart-8/create_python_requirements.patch new file mode 100644 index 0000000..9429a5a --- /dev/null +++ b/patches/mario-kart-8/create_python_requirements.patch @@ -0,0 +1,14 @@ +diff --git a/requirements.txt b/requirements.txt +new file mode 100644 +index 0000000..d873a47 +--- /dev/null ++++ b/requirements.txt +@@ -0,0 +1,7 @@ ++aioconsole ++requests ++pymongo ++redis ++grpcio-tools ++minio ++nintendoclients +\ No newline at end of file diff --git a/patches/mario-kart-8/create_server_config.patch b/patches/mario-kart-8/create_server_config.patch new file mode 100644 index 0000000..3c34aa2 --- /dev/null +++ b/patches/mario-kart-8/create_server_config.patch @@ -0,0 +1,104 @@ +diff --git a/server_config.py b/server_config.py +new file mode 100644 +index 0000000..dcb8279 +--- /dev/null ++++ b/server_config.py +@@ -0,0 +1,98 @@ ++from nintendo.nex import settings ++import pymongo ++import pymongo ++import urllib.parse ++import os ++ ++GAME_SERVER_ID = 0x1010EB00 ++ACCESS_KEY = "25dbf96a" ++NEX_VERSION = 30504 ++ ++# NEX_SETTINGS = settings.load("friends") ++NEX_SETTINGS = settings.default() ++NEX_SETTINGS.configure(ACCESS_KEY, NEX_VERSION) ++NEX_SETTINGS["prudp.resend_timeout"] = 1.5 ++NEX_SETTINGS["prudp.resend_limit"] = 3 ++NEX_SETTINGS["prudp.version"] = 1 ++NEX_SETTINGS["prudp.max_substream_id"] = 1 ++ ++ ++class MongoCredentials: ++ def __init__(self, host: str, port: int, use_auth: bool = False, username: str = "", password: str = ""): ++ self.host = host ++ self.port = port ++ self.use_auth = use_auth ++ self.username = username ++ self.password = password ++ ++ def connect(self): ++ # Username and password must be percent-escaped ++ db_use_auth = self.use_auth ++ db_user = urllib.parse.quote_plus(self.username) ++ db_pass = urllib.parse.quote_plus(self.password) ++ db_host = self.host ++ db_port = self.port ++ ++ if db_use_auth: ++ db_uri = 'mongodb://%s:%s@%s:%d' % (db_user, db_pass, db_host, db_port) ++ else: ++ db_uri = 'mongodb://%s:%d' % (db_host, db_port) ++ ++ return pymongo.MongoClient(db_uri, serverSelectionTimeoutMS=3000) ++ ++ ++class NEXConfig: ++ def __init__(self): ++ self.nex_host = "0.0.0.0" ++ self.nex_auth_port = int(os.getenv('PN_MK8_AUTHENTICATION_SERVER_PORT', 1000)) ++ self.nex_secure_port = int(os.getenv('PN_MK8_SECURE_SERVER_PORT', 1001)) ++ self.nex_secure_user_password = os.getenv('PN_MK8_SECURE_PASSWORD', 'abcdef123456') # PLEASE, make this a real private password. ++ self.nex_external_address = os.getenv('PN_MK8_SECURE_SERVER_HOST', '0.0.0.0') # Your external IP, for external clients to connect. ++ ++ self.friends_grpc_host = os.getenv('PN_MK8_FRIENDS_GRPC_HOST', '123.123.123.123') ++ self.friends_grpc_port = int(os.getenv('PN_MK8_FRIENDS_GRPC_PORT', 1002)) ++ self.friends_grpc_api_key = os.getenv('PN_MK8_FRIENDS_GRPC_API_KEY', 'abcdefghijklmnopqrstuvwxyz123456789') ++ ++ self.account_grpc_host = os.getenv('PN_MK8_ACCOUNT_GRPC_HOST', '124.124.124.124') ++ self.account_grpc_port = int(os.getenv('PN_MK8_ACCOUNT_GRPC_PORT', 1003)) ++ self.account_grpc_api_key = os.getenv('PN_MK8_ACCOUNT_GRPC_API_KEY', 'abcdefghijklmnopqrstuvwxyz123456789') ++ ++ # These gRPC credentials are for the server we're implementing ++ self.mario_kart_8_grpc_host = "localhost" ++ self.mario_kart_8_grpc_port = int(os.getenv('PN_MK8_GRPC_PORT', 50051)) ++ self.mario_kart_8_grpc_api_key = os.getenv('PN_MK8_GRPC_API_KEY', 'abcdefghijklmnopqrstuvwxyz123456789') ++ ++ self.account_database = os.getenv('PN_MK8_ACCOUNT_DATABASE', 'pretendo_account') ++ ++ self.pnid_collection = "pnids" ++ self.nex_account_collection = "nexaccounts" ++ ++ self.game_db_server = MongoCredentials( ++ host=os.getenv('PN_MK8_MONGO_HOST', '222.222.222.222'), ++ port=int(os.getenv('PN_MK8_MONGO_PORT', 1004)) ++ ) ++ ++ self.game_database = "mk8" ++ ++ self.sequence_collection = "counters" ++ self.gatherings_collection = "gatherings" ++ self.sessions_collection = "sessions" ++ self.tournaments_collection = "tournaments" ++ self.tournaments_score_collection = "tournaments_scores" ++ self.ranking_common_data_collection = "commondata" ++ self.rankings_score_collection = "rankings" ++ self.secure_reports_collection = "secure_reports" ++ self.datastore_collection = "datastore" ++ self.restriction_collection = "restrictions" ++ ++ self.s3_endpoint_domain = os.getenv('PN_MK8_CONFIG_S3_ENDPOINT', 'minio.pretendo.cc') ++ self.s3_endpoint = "http://" + self.s3_endpoint_domain ++ self.s3_access_key = os.getenv('PN_MK8_CONFIG_S3_ACCESS_KEY', 'minio_pretendo') ++ self.s3_secret = os.getenv('PN_MK8_CONFIG_S3_SECRET', '...') ++ self.s3_region = "it" ++ self.bucket_name = os.getenv('PN_MK8_CONFIG_S3_BUCKET', 'amkj') ++ ++ self.redis_uri = "redis://" + os.getenv('PN_MK8_REDIS_URI', '53.53.53.53:1005') # redis://HOST[:PORT][?db=DATABASE[&password=PASSWORD]] ++ ++ ++NEX_CONFIG = NEXConfig() diff --git a/patches/mario-kart-8/dockerfile-creation.patch b/patches/mario-kart-8/dockerfile-creation.patch new file mode 100644 index 0000000..18daf32 --- /dev/null +++ b/patches/mario-kart-8/dockerfile-creation.patch @@ -0,0 +1,34 @@ +diff --git a/Dockerfile b/Dockerfile +new file mode 100644 +index 0000000..9fb5b2d +--- /dev/null ++++ b/Dockerfile +@@ -0,0 +1,20 @@ ++# Use the official Python image as the base ++FROM python:3.9-slim ++ ++# Set the working directory inside the container ++WORKDIR /app ++ ++# Copy the requirements file to the working directory ++COPY requirements.txt . ++ ++ENV PYTHONPATH="/usr/local/lib/python3.9/site-packages" ++ ++# Install dependencies specified in requirements.txt ++RUN python -m pip install --no-cache-dir -r requirements.txt ++ ++# Copy all project files into the container ++COPY . . ++ ++# Install Git (required for submodules) ++#RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* ++ ++# Ensure all submodules (including nested ones) are initialized and updated ++#RUN git submodule update --init --recursive ++ ++# Generate gRPC Python files before running the application ++RUN python -m grpc_tools.protoc --proto_path=grpc --python_out=. --grpc_python_out=. grpc/amkj_service.proto ++ ++# Set the command to run the application ++CMD ["python", "main.py"] diff --git a/scripts/setup-submodule-patches.sh b/scripts/setup-submodule-patches.sh index 1e603b6..711ea72 100755 --- a/scripts/setup-submodule-patches.sh +++ b/scripts/setup-submodule-patches.sh @@ -8,14 +8,14 @@ use this if you're trying to update the submodules to a newer version than is su fails to apply, a 3-way merge will be attempted." parse_arguments "$@" -print_info "Resetting all submodules..." -run_verbose git submodule sync -run_verbose git submodule foreach "git reset --hard" -run_verbose git submodule foreach "git clean -fd" -run_verbose git submodule update --init --checkout +print_info "Resetting all submodules (including nested submodules)..." +run_verbose git submodule sync --recursive +run_verbose git submodule foreach --recursive "git reset --hard" +run_verbose git submodule foreach --recursive "git clean -xfd" +run_verbose git submodule update --init --checkout --recursive if [[ -n "$update_remote" ]]; then - print_info "Updating submodules from their remotes..." - git submodule update --remote + print_info "Updating submodules from their remotes (including nested submodules)..." + run_verbose git submodule update --remote --recursive fi print_info "Applying patches to submodules..." From 2588cca0b47447269e033f8fe7b73c88265ee0a8 Mon Sep 17 00:00:00 2001 From: Bryan Mainardi Date: Wed, 19 Mar 2025 23:43:02 +0100 Subject: [PATCH 4/7] Implemented mario-kart-8 in the compose.yml --- compose.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/compose.yml b/compose.yml index bb2b307..a145071 100644 --- a/compose.yml +++ b/compose.yml @@ -484,6 +484,27 @@ services: - ./environment/pikmin-3.env - ./environment/pikmin-3.local.env + mario-kart-8: + build: ./repos/mario-kart-8 + depends_on: + - account + - friends + - mongodb + - redis + - minio + restart: unless-stopped + ports: + # Authentication server + - 5781:5781/udp + # Secure server + - 5782:5782/udp + networks: + internal: + dns: 172.20.0.200 + env_file: + - ./environment/mario-kart-8.env + - ./environment/mario-kart-8.local.env + volumes: mitmproxy-pretendo-data: mongodb-database: From ee9624863b13b5e162f8e62085000ae74118d578 Mon Sep 17 00:00:00 2001 From: Bryan Mainardi Date: Fri, 25 Apr 2025 03:34:58 +0200 Subject: [PATCH 5/7] Fixed mario-kart-8 Dockerfile patch --- patches/mario-kart-8/dockerfile-creation.patch | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/patches/mario-kart-8/dockerfile-creation.patch b/patches/mario-kart-8/dockerfile-creation.patch index 18daf32..2d75620 100644 --- a/patches/mario-kart-8/dockerfile-creation.patch +++ b/patches/mario-kart-8/dockerfile-creation.patch @@ -3,7 +3,7 @@ new file mode 100644 index 0000000..9fb5b2d --- /dev/null +++ b/Dockerfile -@@ -0,0 +1,20 @@ +@@ -0,0 +1,22 @@ +# Use the official Python image as the base +FROM python:3.9-slim + @@ -21,12 +21,6 @@ index 0000000..9fb5b2d +# Copy all project files into the container +COPY . . + -+# Install Git (required for submodules) -+#RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* -+ -+# Ensure all submodules (including nested ones) are initialized and updated -+#RUN git submodule update --init --recursive -+ +# Generate gRPC Python files before running the application +RUN python -m grpc_tools.protoc --proto_path=grpc --python_out=. --grpc_python_out=. grpc/amkj_service.proto + From b197c2634c721a37a2653b9ee102df7b52126e08 Mon Sep 17 00:00:00 2001 From: Bryan Mainardi Date: Fri, 25 Apr 2025 15:06:00 +0200 Subject: [PATCH 6/7] Created patch for disabling mario-kart-8 interactive input in the container --- .../disable-interactive-input.patch | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 patches/mario-kart-8/disable-interactive-input.patch diff --git a/patches/mario-kart-8/disable-interactive-input.patch b/patches/mario-kart-8/disable-interactive-input.patch new file mode 100644 index 0000000..35df4c1 --- /dev/null +++ b/patches/mario-kart-8/disable-interactive-input.patch @@ -0,0 +1,31 @@ +diff --git a/main.py b/main-diff.py +index 9fb8233..b9fa3a7 100644 +--- a/main.py ++++ b/main.py +@@ -8,6 +8,7 @@ import aioconsole + import contextlib + import datetime + import requests ++import signal + + from datetime import datetime, timezone + +@@ -246,7 +247,17 @@ async def main(): + logging.info("Starting gRPC amkj server on %s", listen_addr) + + await server.start() +- await aioconsole.ainput("Press enter to exit...\n") ++ ++ # Set signal handlers for graceful shutdown ++ loop = asyncio.get_running_loop() ++ for sig in (signal.SIGINT, signal.SIGTERM): ++ loop.add_signal_handler(sig, lambda: asyncio.create_task(shutdown(server))) ++ ++ # Keep server running ++ try: ++ await server.wait_for_termination() ++ except asyncio.CancelledError: ++ pass + + + async def sync_amkj_status_to_database(task: asyncio.Task): From 061e7739f3bf21e3e2c21a54692f0bf84b171715 Mon Sep 17 00:00:00 2001 From: Bryan Mainardi Date: Fri, 25 Apr 2025 15:06:41 +0200 Subject: [PATCH 7/7] Implemented mario-kart-8 server in the game servers database --- scripts/internal/update-account-servers-database.sh | 3 ++- .../run-in-container/update-account-servers-database.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/internal/update-account-servers-database.sh b/scripts/internal/update-account-servers-database.sh index 31cda00..5addbce 100755 --- a/scripts/internal/update-account-servers-database.sh +++ b/scripts/internal/update-account-servers-database.sh @@ -7,7 +7,7 @@ parse_arguments "$@" print_info "Setting up Pretendo account servers database..." load_dotenv .env -dotenv_files=("friends" "miiverse-api" "wiiu-chat" "super-mario-maker" "splatoon" "minecraft-wiiu" "pikmin-3") +dotenv_files=("friends" "miiverse-api" "wiiu-chat" "super-mario-maker" "splatoon" "minecraft-wiiu" "pikmin-3" "mario-kart-8") for file in "${dotenv_files[@]}"; do load_dotenv "$file.env" "$file.local.env" done @@ -24,6 +24,7 @@ run_verbose docker compose exec -e SERVER_IP="$SERVER_IP" \ -e SPLATOON_PORT="$PN_SPLATOON_AUTHENTICATION_SERVER_PORT" \ -e MINECRAFT_PORT="$PN_MINECRAFT_AUTHENTICATION_SERVER_PORT" \ -e PIKMIN3_PORT="$PN_PIKMIN3_AUTHENTICATION_SERVER_PORT" \ + -e MK8_PORT="$PN_MK8_AUTHENTICATION_SERVER_PORT" \ account node -e "$create_server_script" print_success "Account servers database is set up." diff --git a/scripts/run-in-container/update-account-servers-database.js b/scripts/run-in-container/update-account-servers-database.js index 959bac8..b7b74d0 100644 --- a/scripts/run-in-container/update-account-servers-database.js +++ b/scripts/run-in-container/update-account-servers-database.js @@ -109,6 +109,15 @@ async function runAsync() { 1, "0".repeat(64) ); + await createNexServer( + "Mario Kart 8", + "1010EB00", + ["000500001010EB00", "000500001010EC00", "000500001010ED00"], + process.env.SERVER_IP, + process.env.MK8_PORT, + 1, + "0".repeat(64) + ); } runAsync().then(() => {