don't try to generate config from scratch

This commit is contained in:
scatterflower 2020-09-02 08:10:42 -05:00
parent f72cb575fe
commit 857e36b835
7 changed files with 151 additions and 184 deletions

5
config/areas.ini Normal file
View File

@ -0,0 +1,5 @@
[Basement]
background=gs4
[Courtroom 1]
background=gs4

51
config/characters.txt Normal file
View File

@ -0,0 +1,51 @@
Adrian
Apollo
April
Armstrong
Atmey
Butz
Diego
Edgeworth
Edgeworthw
Ema
EmaSkye
Franny
Franziska
Gant
Gavin
Gavin K
Godot
Gregory
Grossberg
Gumshoe
Gumshoey
Hawk
Hobo_Phoenix
Ini
Judge
Judge's Bro
Klav
Klavier
Kristoph
Lana
Layton
Lotta
Luis
Maggey
Manfred
Marshall
Matt
Maya
Mia
Miles
Oldbag
Payne
Pearl
Phoenix
Valant
Vasquez
Wellington
Winston
WinstonPayne
Young Mia
Zak

18
config/config.ini Normal file
View File

@ -0,0 +1,18 @@
[Info]
version=1
[Options]
advertise=true
hostname=$H
language=en
max_message_size=256
max_players=100
modpass=password
ms_ip=master.aceattorneyonline.com
ms_port=27016
multiclient_limit=16
port=27016
server_description=This is my flashy new server
server_name=My First Server
webao_enable=true
webao_port=27017

49
config/music.txt Normal file
View File

@ -0,0 +1,49 @@
Announce The Truth (AA).opus
Announce The Truth (AJ).opus
Announce The Truth (JFA).opus
Announce The Truth (Miles).opus
Announce The Truth (T&T).opus
Confrontation ~ Presto 2009.opus
Crises of Fate.opus
Forgotten Legend.opus
Godot - The Fragrance of Dark Coffee.opus
Great Revival ~ Franziska von Karma.opus
Great Revival ~ Miles Edgeworth.opus
Hotline of Fate.opus
Interesting People.opus
Logic and Trick.opus
Luke Atmey ~ I Just Want Love.opus
Noisy People.opus
OBJECTION (AA).opus
Objection (AJ).opus
OBJECTION (JFA).opus
Objection (Miles).opus
OBJECTION (T&T).opus
Others ~ Guilty love.opus
Prelude (AA).opus
Prelude (AJ).opus
Prologue (AA).opus
Pursuit (AA) - variation.opus
Pursuit (AA).opus
Pursuit (AJ).opus
Pursuit (DS).opus
Pursuit (JFA) - variation.opus
Pursuit (JFA).opus
Pursuit (Miles).opus
Pursuit (T&T) - variation.opus
Pursuit (T&T).opus
Pursuit ~ I Want to Find the Truth (Orchestra).opus
Questioning AA (Allegro).opus
Questioning AA (Moderato).opus
Questioning AJ (Allegro).opus
Questioning AJ (Moderato).opus
Questioning JFA (Allegro).opus
Questioning JFA (Moderato).opus
Questioning T&T (Allegro).opus
Questioning T&T (Moderato).opus
Speak up Pup.opus
Suspense (AA).opus
The Great Truth Burglar.opus
Trial (AA).opus
Trial (AJ).opus
Trial (Miles).opus

View File

@ -30,8 +30,7 @@ class ConfigManager {
public:
ConfigManager();
bool initConfig();
void generateDefaultConfig(bool backup_old);
void updateConfig(int current_version);
bool updateConfig(int current_version);
struct server_settings {
QString ms_ip;

View File

@ -19,166 +19,43 @@
ConfigManager::ConfigManager()
{
config = new QSettings("config.ini", QSettings::IniFormat);
config = new QSettings("config/config.ini", QSettings::IniFormat);
}
// Validate and set up the config
bool ConfigManager::initConfig()
{
QFileInfo char_list_info("characters.txt");
if (!(char_list_info.exists() && char_list_info.isFile())) {
// TODO: signals go here
QFile char_list("characters.txt");
if (!char_list.open(QIODevice::WriteOnly | QIODevice::Text))
qDebug() << "Couldn't create character list";
QTextStream file_stream(&char_list);
qDebug() << "Creating vanilla character list";
file_stream << "Adrian\n";
file_stream << "Apollo\n";
file_stream << "April\n";
file_stream << "Armstrong\n";
file_stream << "Atmey\n";
file_stream << "Butz\n";
file_stream << "Diego\n";
file_stream << "Edgeworth\n";
file_stream << "Edgeworthw\n";
file_stream << "Ema\n";
file_stream << "EmaSkye\n";
file_stream << "Franny\n";
file_stream << "Franziska\n";
file_stream << "Gant\n";
file_stream << "Gavin\n";
file_stream << "Gavin K\n";
file_stream << "Godot\n";
file_stream << "Gregory\n";
file_stream << "Grossberg\n";
file_stream << "Gumshoe\n";
file_stream << "Gumshoey\n";
file_stream << "Hawk\n";
file_stream << "Hobo_Phoenix\n";
file_stream << "Ini\n";
file_stream << "Judge\n";
file_stream << "Judge's Bro\n";
file_stream << "Klav\n";
file_stream << "Klavier\n";
file_stream << "Kristoph\n";
file_stream << "Lana\n";
file_stream << "Layton\n";
file_stream << "Lotta\n";
file_stream << "Luis\n";
file_stream << "Maggey\n";
file_stream << "Manfred\n";
file_stream << "Marshall\n";
file_stream << "Matt\n";
file_stream << "Maya\n";
file_stream << "Mia\n";
file_stream << "Miles\n";
file_stream << "Oldbag\n";
file_stream << "Payne\n";
file_stream << "Pearl\n";
file_stream << "Phoenix\n";
file_stream << "Valant\n";
file_stream << "Vasquez\n";
file_stream << "Wellington\n";
file_stream << "Winston\n";
file_stream << "WinstonPayne\n";
file_stream << "Young Mia\n";
file_stream << "Zak\n";
char_list.flush();
char_list.close();
}
QFileInfo music_list_info("music.txt");
if (!(music_list_info.exists() && music_list_info.isFile())) {
QFile music_list("music.txt");
if (!music_list.open(QIODevice::WriteOnly | QIODevice::Text))
qDebug() << "Couldn't create music list";
QTextStream file_stream(&music_list);
qDebug() << "Creating vanilla music list";
file_stream << "Announce The Truth (AA).opus\n";
file_stream << "Announce The Truth (AJ).opus\n";
file_stream << "Announce The Truth (JFA).opus\n";
file_stream << "Announce The Truth (Miles).opus\n";
file_stream << "Announce The Truth (T&T).opus\n";
file_stream << "Confrontation ~ Presto 2009.opus\n";
file_stream << "Crises of Fate.opus\n";
file_stream << "Forgotten Legend.opus\n";
file_stream << "Godot - The Fragrance of Dark Coffee.opus\n";
file_stream << "Great Revival ~ Franziska von Karma.opus\n";
file_stream << "Great Revival ~ Miles Edgeworth.opus\n";
file_stream << "Hotline of Fate.opus\n";
file_stream << "Interesting People.opus\n";
file_stream << "Logic and Trick.opus\n";
file_stream << "Luke Atmey ~ I Just Want Love.opus\n";
file_stream << "Noisy People.opus\n";
file_stream << "OBJECTION (AA).opus\n";
file_stream << "Objection (AJ).opus\n";
file_stream << "OBJECTION (JFA).opus\n";
file_stream << "Objection (Miles).opus\n";
file_stream << "OBJECTION (T&T).opus\n";
file_stream << "Others ~ Guilty love.opus\n";
file_stream << "Prelude (AA).opus\n";
file_stream << "Prelude (AJ).opus\n";
file_stream << "Prologue (AA).opus\n";
file_stream << "Pursuit (AA) - variation.opus\n";
file_stream << "Pursuit (AA).opus\n";
file_stream << "Pursuit (AJ).opus\n";
file_stream << "Pursuit (DS).opus\n";
file_stream << "Pursuit (JFA) - variation.opus\n";
file_stream << "Pursuit (JFA).opus\n";
file_stream << "Pursuit (Miles).opus\n";
file_stream << "Pursuit (T&T) - variation.opus\n";
file_stream << "Pursuit (T&T).opus\n";
file_stream << "Pursuit ~ I Want to Find the Truth (Orchestra).opus\n";
file_stream << "Questioning AA (Allegro).opus\n";
file_stream << "Questioning AA (Moderato).opus\n";
file_stream << "Questioning AJ (Allegro).opus\n";
file_stream << "Questioning AJ (Moderato).opus\n";
file_stream << "Questioning JFA (Allegro).opus\n";
file_stream << "Questioning JFA (Moderato).opus\n";
file_stream << "Questioning T&T (Allegro).opus\n";
file_stream << "Questioning T&T (Moderato).opus\n";
file_stream << "Speak up Pup.opus\n";
file_stream << "Suspense (AA).opus\n";
file_stream << "The Great Truth Burglar.opus\n";
file_stream << "Trial (AA).opus\n";
file_stream << "Trial (AJ).opus\n";
file_stream << "Trial (Miles).opus\n";
music_list.flush();
music_list.close();
QFileInfo config_dir_info("config/");
if (!config_dir_info.exists() || !config_dir_info.isDir()) {
qCritical() << "Config directory doesn't exist!";
return false;
}
config->beginGroup("Info");
QString config_version = config->value("version", "none").toString();
config->endGroup();
if (config_version == "none") {
QFileInfo check_file("config.ini");
// TODO: put proper translatable warnings here
QFileInfo check_file("config/config.ini");
if (!(check_file.exists() && check_file.isFile())) {
// TODO: send signal config doesn't exist
generateDefaultConfig(false);
qCritical() << "config.ini doesn't exist!";
}
else {
// TODO: send signal config is invalid
generateDefaultConfig(true);
qCritical() << "config.ini is invalid!";
}
return false;
}
else if (config_version != QString::number(CONFIG_VERSION)) {
bool version_number_is_valid;
int current_version = config_version.toInt(&version_number_is_valid);
if (version_number_is_valid)
updateConfig(current_version);
if (version_number_is_valid) {
if (updateConfig(current_version))
qWarning() << "config.ini was out of date, and has been updated. Please review the changes, and restart the server.";
else
qCritical() << "config.ini is invalid!";
}
else
generateDefaultConfig(true); // Version number isn't a number at all
// This means the config is invalid
// TODO: send invalid config signal
qCritical() << "config.ini is invalid!"; // Version number isn't a number at all
// This means the config is invalid
return false;
}
else {
@ -187,56 +64,19 @@ bool ConfigManager::initConfig()
}
}
// Setting backup_old to true will move the existing config.ini to
// config_old.ini
void ConfigManager::generateDefaultConfig(bool backup_old)
{
qDebug() << "Config is invalid or missing, making a new one...";
QDir dir = QDir::current();
if (backup_old) {
// TODO: failsafe if config_old.ini already exists
dir.rename("config.ini", "config_old.ini");
}
// Group: Info
// This contains basic metadata about the config
config->beginGroup("Info");
config->setValue("version", CONFIG_VERSION);
config->endGroup();
// Group: Options
// This contains general configuration
config->beginGroup("Options");
config->setValue("hostname", "$H");
config->setValue("max_players", "100");
config->setValue("port", "27016");
config->setValue("webao_enable", "true");
config->setValue("webao_port", "27017");
config->setValue("modpass", "password");
config->setValue("advertise", "true");
config->setValue("ms_ip", "master.aceattorneyonline.com");
config->setValue("ms_port", "27016");
config->setValue("server_name", "My First Server");
config->setValue("server_description", "This is my flashy new server");
config->setValue("multiclient_limit", "16");
config->setValue("max_message_size", "256");
config->endGroup();
}
// Ensure version continuity with config versions
void ConfigManager::updateConfig(int current_version)
bool ConfigManager::updateConfig(int current_version)
{
if (current_version > CONFIG_VERSION) {
// Config version is newer than the latest version, and the config is
// invalid This could also mean the server is out of date, and the user
// should be shown a relevant message Regardless, regen the config
// anyways
// TODO: send signal config is invalid
generateDefaultConfig(true);
return false;
}
else if (current_version < 0) {
// Negative version number? Invalid!
generateDefaultConfig(true);
return false;
}
else {
// TODO: send signal config is out of date, and is being updated
@ -252,6 +92,7 @@ void ConfigManager::updateConfig(int current_version)
break; // This is the newest version, and nothing more needs to be
// done
}
return true;
}
}

View File

@ -39,11 +39,12 @@ int main(int argc, char* argv[])
// Validate some of the config before passing it on
ConfigManager::server_settings settings;
bool config_valid = config_manager.loadServerSettings(&settings);
if (!config_valid) {
// TODO: send signal config invalid
config_manager.generateDefaultConfig(true);
qCritical() << "config.ini is invalid!";
qCritical() << "Exiting server due to configuration issue.";
return EXIT_FAILURE;
}
else {
if (settings.advertise_server) {
// TODO: send signal advertiser started
@ -59,6 +60,9 @@ int main(int argc, char* argv[])
server = new Server(settings.port, settings.ws_port);
server->start();
}
} else {
qCritical() << "Exiting server due to configuration issue.";
return EXIT_FAILURE;
}
return app.exec();