Skip to content

Commit

Permalink
use an "enum"
Browse files Browse the repository at this point in the history
  • Loading branch information
EmosewaMC committed Dec 12, 2024
1 parent 47323a2 commit 039ab05
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ ACCOUNT_MANAGER_SECRET=
# Should be the externally facing IP of your server host
EXTERNAL_IP=localhost


# If using sqlite, set this to 1 and the others to 0. You can ignore the mariadb values if you are using sqlite.
USING_SQLITE=1
# The database type that will be used.
# Acceptable values are `sqlite`, `mysql`, `mariadb`, `maria`.
# Case insensitive.
database_type=sqlite
SQLITE_DATABASE_PATH=resServer/dlu.sqlite

# If using mysql, set this to 1 and the others to 0. You can ignore the sqlite values if you are using mysql.
USING_MYSQL=0
# Database values
# Be careful with special characters here. It is more safe to use normal characters and/or numbers.
MARIADB_USER=darkflame
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ foreach(resource_file ${RESOURCE_FILES})

if(NOT ${parsed_current_file_contents} MATCHES ${variable_name})
# For backwards compatibility with older setup versions, dont add this option.
if(NOT ${variable_name} MATCHES "using_sqlite")
if(NOT ${variable_name} MATCHES "database_type")
message(STATUS "Adding missing config option " ${variable_name} " to " ${resource_file})
set(line_to_add ${line_to_add} ${line})

Expand Down
9 changes: 7 additions & 2 deletions dDatabase/GameDatabase/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
#include "SQLiteDatabase.h"
#include "MySQLDatabase.h"

#include <ranges>

#pragma warning (disable:4251) //Disables SQL warnings

namespace {
GameDatabase* database = nullptr;
}

std::string Database::GetMigrationFolder() {
if (Game::config->GetValue("using_sqlite") == "1") return "sqlite";
else if (Game::config->GetValue("using_mysql") == "1") return "mysql";
const std::set<std::string> validMysqlTypes = { "mysql", "mariadb", "maria" };
auto databaseType = Game::config->GetValue("database_type");
std::ranges::transform(databaseType, databaseType.begin(), ::tolower);
if (databaseType == "sqlite") return "sqlite";
else if (validMysqlTypes.contains(databaseType)) return "mysql";
else {
LOG("No database specified, using MySQL");
return "mysql";
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ services:
- CLIENT_LOCATION=/app/luclient
- DLU_CONFIG_DIR=/app/configs
- DUMP_FOLDER=/app/dump
- USING_SQLITE=${USING_SQLITE:-1}
- DATABASE_TYPE=${DATABASE_TYPE:sqlite}
- SQLITE_DATABASE_PATH=${SQLITE_DATABASE_PATH:-resServer/dlu.sqlite}
- USING_MYSQL=${USING_MYSQL:-0}
- SKIP_ACCOUNT_CREATION=${SKIP_ACCOUNT_CREATION:-1}
- MYSQL_HOST=darkflamedb
- MYSQL_DATABASE=${MARIADB_DATABASE:-darkflame}
Expand Down
6 changes: 1 addition & 5 deletions resources/sharedconfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ chat_server_port=2005

sqlite_database_path=resServer/dlu.sqlite

# If using sqlite, set this to 1 and the others to 0
using_sqlite=1

# If using mysql, set this to 1 and the others to 0
using_mysql=0
database_type=sqlite

# Skips the account creation check in master. Used for non-interactive setups.
skip_account_creation=0

0 comments on commit 039ab05

Please sign in to comment.