WIP: add master_ip option

This commit is contained in:
Nils Bergmann 2021-12-08 14:57:16 +01:00
parent 51a9f61e88
commit 7f1e392be2
No known key found for this signature in database
GPG Key ID: 5FAEC08EE1DC2DF9
4 changed files with 18 additions and 4 deletions

View File

@ -157,10 +157,16 @@ int main(int argc, char** argv) {
auto* masterLookupStatement = Database::CreatePreppedStmt("SELECT id FROM `servers` WHERE `name` = 'master'");
auto* result = masterLookupStatement->executeQuery();
auto master_server_ip = config.GetValue("master_ip");
if (master_server_ip == "") {
master_server_ip = Game::server->GetIP();
}
//If we found a server, update it's IP and port to the current one.
if (result->next()) {
auto* updateStatement = Database::CreatePreppedStmt("UPDATE `servers` SET `ip` = ?, `port` = ? WHERE `id` = ?");
updateStatement->setString(1, Game::server->GetIP());
updateStatement->setString(1, master_server_ip);
updateStatement->setInt(2, Game::server->GetPort());
updateStatement->setInt(3, result->getInt("id"));
updateStatement->execute();
@ -169,7 +175,7 @@ int main(int argc, char** argv) {
else {
//If we didn't find a server, create one.
auto* insertStatement = Database::CreatePreppedStmt("INSERT INTO `servers` (`name`, `ip`, `port`, `state`, `version`) VALUES ('master', ?, ?, 0, 171023)");
insertStatement->setString(1, Game::server->GetIP());
insertStatement->setString(1, master_server_ip);
insertStatement->setInt(2, Game::server->GetPort());
insertStatement->execute();
delete insertStatement;

View File

@ -30,8 +30,10 @@ services:
- database:/var/lib/mysql
networks:
- darkflame
ports:
- 3306:3306 # (optional) ports only exposed so that DB management tools can connect
# (optional) ports only exposed so that DB management tools can connect
# Remove the # of the next two lines to expose your database
# ports:
# - 3306:3306
darkflame:
container_name: DarkflameServer

View File

@ -31,6 +31,9 @@ function update_ini_values() {
update_ini worldconfig.ini chat_server_port $CHAT_SERVER_PORT
update_ini worldconfig.ini max_clients $MAX_CLIENTS
# always use the internal docker hostname
update_ini masterconfig.ini master_ip "darkflame"
update_database_ini_values_for masterconfig.ini
update_database_ini_values_for authconfig.ini
update_database_ini_values_for chatconfig.ini

View File

@ -7,6 +7,9 @@ mysql_password=
# The public facing IP address. Can be 'localhost' for locally hosted servers
external_ip=localhost
# The internal ip of the master server
master_ip=localhost
# Port number
port=2000