Skip to content

Instantly share code, notes, and snippets.

@singiamtel
Last active June 2, 2024 14:46
Show Gist options
  • Save singiamtel/dfe5bb6964d32ce30e98a35145f50753 to your computer and use it in GitHub Desktop.
Save singiamtel/dfe5bb6964d32ce30e98a35145f50753 to your computer and use it in GitHub Desktop.
Running your own Showdown server/loginserver/client

Client

Write config/config.js and config/routes.json

  • docker network create main
  • node build full
  • docker compose up

Loginserver

  • Create rsa key (gen_key.py)
  • Edit config/config.js
  • Setup a mysql (run_mysql opens a docker container with a mysql server)
  • Setup the schemas (setup_db.sh) -Launch loginserver with npm run run config/config.js

Server

In config/config.js:

  • Set exports.loginserver to your loginserver ip/domain
  • Set exports.loginserverpublickey to the public key you created previously
http://:3000/* {
log
bind 0.0.0.0
@showdown {
path /~~showdown*
}
handle @showdown {
reverse_proxy host.docker.internal:8080
}
root * /app/public/play.pokemonshowdown.com/
file_server browse
php_fastcgi php-fpm:9000
}
networks:
default:
external: true
name: main
services:
caddy:
container_name: caddy
image: caddy
networks:
- default
restart: unless-stopped
ports:
- "3000:3000"
# - "443:443"
volumes:
- $PWD/Caddyfile:/etc/caddy/Caddyfile
- $PWD:/app/public
- caddy_data:/data
- caddy_config:/config
depends_on:
- php-fpm
extra_hosts:
- "host.docker.internal:host-gateway"
php-fpm:
container_name: php-fpm
build: .
restart: unless-stopped
volumes:
- $PWD:/app/public
volumes:
caddy_data:
caddy_config:
FROM php:7.0-fpm
# RUN apt-get update -y
RUN docker-php-ext-install pdo_mysql
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
)
public_key = private_key.public_key()
pem_private_key = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption(),
)
pem_public_key = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo,
)
with open("private_key.pem", "wb") as private_file:
private_file.write(pem_private_key)
with open("public_key.pem", "wb") as public_file:
public_file.write(pem_public_key)
print("Keys generated successfully")
#!/usr/bin/env bash
source ./.env
if [ -z "$MYSQL_USER" ]
then
echo "MYSQL_USER is not set"
exit 1
fi
if [ -z "$MYSQL_PASSWORD" ]
then
echo "MYSQL_PASSWORD is not set"
exit 1
fi
if [ -z "$MYSQL_DATABASE" ]
then
echo "MYSQL_DATABASE is not set"
exit 1
fi
if [ -z "$MYSQL_ROOT_PASSWORD" ]
then
echo "MYSQL_ROOT_PASSWORD is not set"
exit 1
fi
docker run --rm --name loginserver_mysql -e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD -e MYSQL_USER=$MYSQL_USER -e MYSQL_PASSWORD=$MYSQL_PASSWORD -e MYSQL_DATABASE=$MYSQL_DATABASE -p 3306:3306 -v mysqldata:/var/lib/mysql mysql:latest
#!/usr/bin/env bash
# Set the database credentials
# Path to the directory containing your SQL files
SQL_DIR=$(pwd)/src/schemas
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
fi
# Loop through each .sql file in the directory
# The replays schema fails (it's for postgres...)
for sql_file in "$SQL_DIR"/*.sql
do
echo "Applying $sql_file to database $MYSQL_DATABASE..."
mysql -h 127.0.0.1 -P 3306 -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -h "$MYSQL_HOST" "$MYSQL_DATABASE" < "$sql_file"
if [ $? -ne 0 ]; then
echo "Error applying $sql_file"
# exit 1
fi
done
echo "All SQL files have been applied successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment