2021-12-07 13:50:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function set_defaults() {
|
|
|
|
DATABASE_PORT=${DATABASE_PORT:-3306}
|
|
|
|
DATABASE=${DATABASE:-darkflame}
|
|
|
|
|
|
|
|
if [[ -z $DATABASE_PASSWORD ]]; then
|
|
|
|
USE_DATABASE_PASSWORD="No"
|
|
|
|
else
|
|
|
|
USE_DATABASE_PASSWORD="Yes"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CHAT_SERVER_PORT=${CHAT_SERVER_PORT:-2005}
|
|
|
|
MAX_CLIENTS=${MAX_CLIENTS:-999}
|
2021-12-08 06:33:34 +00:00
|
|
|
EXTERNAL_IP=${EXTERNAL_IP:-localhost}
|
2021-12-07 13:50:05 +00:00
|
|
|
|
|
|
|
echo "Start server with configuration:"
|
|
|
|
echo "===== Database Config ========="
|
|
|
|
echo "Database: $DATABASE"
|
|
|
|
echo "Database host: $DATABASE_HOST"
|
|
|
|
echo "Database port: $DATABASE_PORT"
|
|
|
|
echo "Database user: $DATABASE_USER"
|
|
|
|
echo "Database password set: $USE_DATABASE_PASSWORD"
|
|
|
|
echo "===== Other settings =========="
|
|
|
|
echo "Chat server port: $CHAT_SERVER_PORT"
|
|
|
|
echo "Max clients: $MAX_CLIENTS"
|
2021-12-08 06:33:34 +00:00
|
|
|
echo "External IP: $EXTERNAL_IP"
|
2021-12-07 13:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_sql_connection() {
|
|
|
|
until echo '\q' | mysql -h"$DATABASE_HOST" -P"$DATABASE_PORT" -u"$DATABASE_USER" -p"$DATABASE_PASSWORD" $DATABASE; do
|
|
|
|
>&2 echo "MySQL/MariaDB is unavailable - sleeping"
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_ini() {
|
|
|
|
INI_FILE=$1
|
|
|
|
KEY=$2
|
|
|
|
NEW_VALUE=$3
|
|
|
|
sed -i "/^$KEY=/s/=.*/=$NEW_VALUE/" $INI_FILE
|
|
|
|
}
|
|
|
|
|
2021-12-07 19:58:18 +00:00
|
|
|
function update_database_ini_values_for() {
|
|
|
|
INI_FILE=$1
|
|
|
|
update_ini $INI_FILE mysql_host $DATABASE_HOST
|
|
|
|
update_ini $INI_FILE mysql_database $DATABASE
|
|
|
|
update_ini $INI_FILE mysql_username $DATABASE_USER
|
2021-12-07 21:25:58 +00:00
|
|
|
update_ini $INI_FILE mysql_password $DATABASE_PASSWORD
|
2021-12-07 23:40:15 +00:00
|
|
|
if [[ "$INI_FILE" != "worldconfig.ini" ]]; then
|
2021-12-08 06:33:34 +00:00
|
|
|
update_ini $INI_FILE external_ip $EXTERNAL_IP
|
2021-12-07 23:40:15 +00:00
|
|
|
fi
|
2021-12-07 19:58:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 13:50:05 +00:00
|
|
|
function update_ini_values() {
|
|
|
|
update_ini worldconfig.ini chat_server_port $CHAT_SERVER_PORT
|
|
|
|
update_ini worldconfig.ini max_clients $MAX_CLIENTS
|
2021-12-07 19:58:18 +00:00
|
|
|
|
|
|
|
update_database_ini_values_for masterconfig.ini
|
|
|
|
update_database_ini_values_for authconfig.ini
|
|
|
|
update_database_ini_values_for chatconfig.ini
|
|
|
|
update_database_ini_values_for worldconfig.ini
|
2021-12-07 13:50:05 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 15:29:26 +00:00
|
|
|
function symlink_client_files() {
|
|
|
|
ln -s /client/client/res/macros/ /app/res/macros
|
|
|
|
ln -s /client/client/res/BrickModels/ /app/res/BrickModels
|
|
|
|
ln -s /client/client/res/chatplus_en_us.txt /app/res/chatplus_en_us.txt
|
2021-12-08 06:33:34 +00:00
|
|
|
ln -s /client/client/res/maps/ /app/res/maps
|
2021-12-07 15:29:26 +00:00
|
|
|
ln -s /client/client/res/names/ /app/res/names
|
|
|
|
ln -s /client/client/locale/locale.xml /app/locale/locale.xml
|
|
|
|
}
|
|
|
|
|
|
|
|
function fdb_to_sqlite() {
|
|
|
|
echo "Run fdb_to_sqlite"
|
2021-12-08 06:33:34 +00:00
|
|
|
python3 /app/utils/fdb_to_sqlite.py /client/client/res/cdclient.fdb --sqlite_path /client/client/res/CDServer.sqlite
|
2021-12-07 15:29:26 +00:00
|
|
|
|
|
|
|
(
|
|
|
|
cd /app/migrations/cdserver
|
|
|
|
readarray -d '' entries < <(printf '%s\0' *.sql | sort -zV)
|
|
|
|
for entry in "${entries[@]}"; do
|
|
|
|
echo "Execute $entry"
|
2021-12-08 06:33:34 +00:00
|
|
|
sqlite3 /client/client/res/CDServer.sqlite < $entry
|
2021-12-07 15:29:26 +00:00
|
|
|
done
|
|
|
|
)
|
2021-12-08 06:33:34 +00:00
|
|
|
|
|
|
|
ln -s /client/client/res/CDServer.sqlite /app/res/CDServer.sqlite
|
2021-12-07 15:29:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 13:50:05 +00:00
|
|
|
set_defaults
|
|
|
|
|
|
|
|
check_sql_connection
|
|
|
|
|
|
|
|
update_ini_values
|
|
|
|
|
|
|
|
if [[ ! -d "/client" ]]; then
|
|
|
|
echo "Client not found."
|
|
|
|
echo "Did you forgot to mount the client into the \"/client\" directory?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -f "/client/extracted" ]]; then
|
|
|
|
echo "Start client resource extraction"
|
|
|
|
|
|
|
|
python3 /app/utils/pkextractor.py /client/ /client/
|
2021-12-07 15:29:26 +00:00
|
|
|
|
2021-12-07 13:50:05 +00:00
|
|
|
touch /client/extracted
|
|
|
|
else
|
|
|
|
echo "Client already extracted. Skip this step"
|
|
|
|
echo "If you want to force re-extract, just delete the file called \"extracted\" in the client directory"
|
|
|
|
fi
|
|
|
|
|
2021-12-07 15:29:26 +00:00
|
|
|
symlink_client_files
|
|
|
|
|
|
|
|
fdb_to_sqlite
|
|
|
|
|
|
|
|
echo "Start MasterServer"
|
|
|
|
|
|
|
|
./MasterServer
|
|
|
|
|
|
|
|
tail -f /dev/null
|