akashi-esquizolandia/core/include/config_manager.h
in1tiate 83c41c05f7 Squashed commit of the following:
commit e946bf124602f224ce0e371ba1374f0355b537eb
Merge: d6a4e64 4505909
Author: Rosemary Witchaven <32779090+in1tiate@users.noreply.github.com>
Date:   Fri Jan 28 19:43:36 2022 -0600

    Merge pull request #225 from Salanto/Dynamic-Area-Musiclist-Take2

    Allow users to add custom songs to the music list on a per-area basis

commit 45059092d2888b60912f721e43a380910d10ccd8
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Mon Jan 24 22:05:27 2022 +0100

    TIL what a typedef is

commit 02584db9640fff0a1969a7f516c4bccfae9b5388
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Mon Jan 24 21:39:17 2022 +0100

    Not all OR are equal. Explain weird command splitting

    Remove hardcoded URLs

commit d00ebd5692296cd0c29dd377113b53fe0e7b99c0
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Mon Jan 24 21:28:08 2022 +0100

    Salanto PR Language Update by in1tiate

    As usual, my English is absolutely unreadable.

    Co-authored-by: Rosemary Witchaven <32779090+in1tiate@users.noreply.github.com>

commit d3842106e06350dc02d8864bb28232fdc5643f00
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Mon Jan 24 20:35:32 2022 +0100

    Add missing config file + document commands for help

commit ac64360e1c1741023b01052977de77a7d5ea4f8c
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Mon Jan 24 19:52:13 2022 +0100

    Minor improvements to command usage and addition of clear command

commit c614578e78ce9afa0c8e22aa36bdf46a70a97169
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sun Jan 23 22:19:54 2022 +0100

    Purge last traces of old songInformation system

commit 07618761f044a13d75587b28a9c994342a5980e2
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sun Jan 23 22:10:54 2022 +0100

    Working version, needs some refinement and debugging in AOClient

commit 33c0358c98c0fd2de805356a9aa3ac7bbed204e1
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sun Jan 23 21:48:05 2022 +0100

    Almost functional implementation

    Now only need to determine why I can't play the customs yet

commit b0acbace78b3f16f2fe4f3c6f65a422e3343f992
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sun Jan 23 15:26:42 2022 +0100

    Fix build error, expand validation test slightly

commit a48c4f503998ce8e42f0bb409c5a3c7dc5e40329
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sun Jan 23 01:03:27 2022 +0100

    Add commands

commit 88ab0b473953873166e291e5009b97df31547b3f
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sat Jan 22 15:10:26 2022 +0100

    Float sucks, int has to be good enough

    + add retrival of song information

commit e924e1340be1a0909eba84072f1646fe9770bd02
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Thu Jan 20 22:28:35 2022 +0100

    Fix removing moving

    Add necessary tests

commit 3df088f8d07ce7e0d8fe08b6a97608a623e6ef97
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Wed Jan 19 19:34:16 2022 +0100

    Start work on adding this shit into commands

commit c293ecfa99d1b2bd1e0b34cb8752d69b2eca057c
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Tue Jan 18 19:07:11 2022 +0100

    Fix typo and add singal for incremental upgrades

commit 10a42322e1e23af5795278a40b2ac59f3ab952ef
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Tue Jan 18 06:17:51 2022 +0100

    Hookup packet sending to music manager

    This might sound like a bad idea on first glance, but otherwise it breaks the AreaData tests and I am NOT gonna try to fix those without even understanding why they break.

commit 319836296374162b0b847432e8a626778317b869
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Tue Jan 18 06:17:51 2022 +0100

    Enraged comments, make area send FM packet

    Revert "Enraged comments, make area send FM packet"

    This reverts commit ec7a1a25646b2c2acc8a3a748b853851cc47d205.

commit 224a0d7efe989a5f336167c3f716061813f93ee3
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Tue Jan 18 05:10:18 2022 +0100

    Change packet communication from area to client

    First steps to hookup the custom musiclist.

commit 65aa8f7855a36f2c668b1399a5ed22fefeaf186d
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Mon Jan 17 00:48:38 2022 +0100

    Add test for custom list sanitisation.

    + Fix intentionally broken tests

commit 7c00ab437a6ff12033742d029ce49037f5bb1ebe
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Mon Jan 17 00:29:51 2022 +0100

    Sanitise the custom list opposed to deleting it

    This will fail tests intentionally to test the CI.

commit 80ad401267068e75707b2517a0bf836763141f8b
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sun Jan 16 17:17:12 2022 +0100

    Add custom category capabilities

commit 08d8f5f8f683816ceba532f9c47cd0d5ab34389a
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sun Jan 16 03:58:18 2022 +0100

    Fix music addition and move relevant tests

commit 6ebf0d03b5da61a9c287115009d28038710ba7af
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sat Jan 15 08:08:20 2022 +0100

    Hookup music_manager into server, change default musiclist source for new clients

    + More tests 🆒

commit bd50c62376f131e2508ecdd3e272209894ecaec1
Author: Salanto <62221668+Salanto@users.noreply.github.com>
Date:   Sat Jan 15 03:13:42 2022 +0100

    Add central song validator for other classes

    Also added applicable test cases to ensure proper operation.
2022-01-28 19:51:30 -06:00

572 lines
14 KiB
C++

//////////////////////////////////////////////////////////////////////////////////////
// akashi - a server for Attorney Online 2 //
// Copyright (C) 2020 scatterflower //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//////////////////////////////////////////////////////////////////////////////////////
#ifndef CONFIG_MANAGER_H
#define CONFIG_MANAGER_H
#define CONFIG_VERSION 1
#include "data_types.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QSettings>
#include <QUrl>
#include <QMetaEnum>
#include <QElapsedTimer>
#include <QHostAddress>
//JSON loading requirements
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
typedef QMap<QString,QPair<QString,int>> MusicList;
/**
* @brief The config file handler class.
*/
class ConfigManager {
public:
/**
* @brief Verifies the server configuration, confirming all required files/directories exist and are valid.
*
* @return True if the server configuration was verified, false otherwise.
*/
static bool verifyServerConfig();
/**
* @brief Returns the IP the TCP Server binds to.
*
* @return See short description
*/
static QString bindIP();
/**
* @brief Returns the character list of the server.
*
* @return See short description.
*/
static QStringList charlist();
/**
* @brief Returns the a QStringList of the available backgrounds.
*
* @return See short description.
*/
static QStringList backgrounds();
/**
* @brief Returns a QStringlist of the available songs.
*
* @return See short description.
*/
static MusicList musiclist();
/**
* @brief Returns an ordered QList of all basesongs of this server.
*
* @return See short description.
*/
static QStringList ordered_songs();
/**
* @brief Loads help information into m_help_information.
*
* @return See short description.
*/
static void loadCommandHelp();
/**
* @brief Returns the content of
*
* @return See short description.
*/
static QSettings* areaData();
/**
* @brief Returns a sanitized QStringList of the areas.
*
* @return See short description.
*/
static QStringList sanitizedAreaNames();
/**
* @brief Returns the raw arealist
*
* @return See short description.
*/
static QStringList rawAreaNames();
/**
* @brief Returns a list of the IPrange bans.
*
* @return See short description.
*/
static QStringList iprangeBans();
/**
* @brief Returns the maximum number of players the server will allow.
*
* @return See short description.
*/
static int maxPlayers();
/**
* @brief Returns the port to listen for connections on.
*
* @return See short description.
*/
static int serverPort();
/**
* @brief Returns the server description.
*
* @return See short description.
*/
static QString serverDescription();
/**
* @brief Returns the server name.
*
* @return See short description.
*/
static QString serverName();
/**
* @brief Returns the server's Message of the Day.
*
* @return See short description.
*/
static QString motd();
/**
* @brief Returns true if the server should accept webAO connections.
*
* @return See short description.
*/
static bool webaoEnabled();
/**
* @brief Returns the port to listen for webAO connections on.
*
* @return See short description.
*/
static int webaoPort();
/**
* @brief Returns the server's authorization type.
*
* @return See short description.
*/
static DataTypes::AuthType authType();
/**
* @brief Returns the server's moderator password.
*
* @return See short description.
*/
static QString modpass();
/**
* @brief Returns the server's log buffer length.
*
* @return See short description.
*/
static int logBuffer();
/**
* @brief Returns the server's logging type.
*
* @return See short description.
*/
static DataTypes::LogType loggingType();
/**
* @brief Returns true if the server should advertise to the master server.
*
* @return See short description.
*/
static int maxStatements();
/**
* @brief Returns the maximum number of permitted connections from the same IP.
*
* @return See short description.
*/
static int multiClientLimit();
/**
* @brief Returns the maximum number of characters a message can contain.
*
* @return See short description.
*/
static int maxCharacters();
/**
* @brief Returns the duration of the message floodguard.
*
* @return See short description.
*/
static int messageFloodguard();
/**
* @brief Returns the URL where the server should retrieve remote assets from.
*
* @return See short description.
*/
static QUrl assetUrl();
/**
* @brief Returns the maximum number of sides dice can have.
*
* @return See short description.
*/
static int diceMaxValue();
/**
* @brief Returns the maximum number of dice that can be rolled at once.
*
* @return See short description.
*/
static int diceMaxDice();
/**
* @brief Returns true if the discord webhook integration is enabled.
*
* @return See short description.
*/
static bool discordWebhookEnabled();
/**
* @brief Returns true if the discord modcall webhook is enabled.
*
* @return See short description.
*/
static bool discordModcallWebhookEnabled();
/**
* @brief Returns the discord webhook URL.
*
* @return See short description.
*/
static QString discordModcallWebhookUrl();
/**
* @brief Returns the discord webhook content.
*
* @return See short description.
*/
static QString discordModcallWebhookContent();
/**
* @brief Returns true if the discord webhook should send log files.
*
* @return See short description.
*/
static bool discordModcallWebhookSendFile();
/**
* @brief Returns true if the discord ban webhook is enabled.
*
* @return See short description.
*/
static bool discordBanWebhookEnabled();
/**
* @brief Returns the Discord Ban Webhook URL.
*
* @return See short description.
*/
static QString discordBanWebhookUrl();
/**
* @brief Returns if the Webhook sends an alive message.
*/
static bool discordUptimeEnabled();
/**
* @brief Returns the time between posting.
*/
static int discordUptimeTime();
/**
* @brief Returns the Discord Uptime Webhook URL.
*
* @return See short description.
*/
static QString discordUptimeWebhookUrl();
/**
* @brief Returns a user configurable color code for the embeed object.s
*
* @return See short description.
*/
static QString discordWebhookColor();
/**
* @brief Returns true if password requirements should be enforced.
*
* @return See short description.
*/
static bool passwordRequirements();
/**
* @brief Returns the minimum length passwords must be.
*
* @return See short description.
*/
static int passwordMinLength();
/**
* @brief Returns the maximum length passwords can be, or `0` for unlimited length.
*
* @return See short description.
*/
static int passwordMaxLength();
/**
* @brief Returns true if passwords must be mixed case.
*
* @return See short description.
*/
static bool passwordRequireMixCase();
/**
* @brief Returns true is passwords must contain one or more numbers.
*
* @return See short description.
*/
static bool passwordRequireNumbers();
/**
* @brief Returns true if passwords must contain one or more special characters..
*
* @return See short description.
*/
static bool passwordRequireSpecialCharacters();
/**
* @brief Returns true if passwords can contain the username.
*
* @return See short description.
*/
static bool passwordCanContainUsername();
/**
* @brief Returns the logstring for the specified logtype.
*
* @param Name of the logstring we want.
*
* @return See short description.
*/
static QString LogText(QString f_logtype);
/**
* @brief Returns the duration before a client is considered AFK.
*
* @return See short description.
*/
static int afkTimeout();
/**
* @brief Returns a list of magic 8 ball answers.
*
* @return See short description.
*/
static QStringList magic8BallAnswers();
/**
* @brief Returns a list of praises.
*
* @return See short description.
*/
static QStringList praiseList();
/**
* @brief Returns a list of reprimands.
*
* @return See short description.
*/
static QStringList reprimandsList();
/**
* @brief Returns the server gimp list.
*
* @return See short description.
*/
static QStringList gimpList();
/**
* @brief Returns the server approved domain list.
*
* @return See short description.
*/
static QStringList cdnList();
/**
* @brief Returns if the advertiser is enabled to advertise on ms3.
*/
static bool advertiseServer();
/**
* @brief Returns if the advertiser prints debug info to console.
*/
static bool advertiserDebug();
/**
* @brief Returns the IP or URL of the masterserver.
*/
static QUrl advertiserIP();
/**
* @brief Returns an optional hostname paramemter for the advertiser.
* If used allows user to set a custom IP or domain name.
*/
static QString advertiserHostname();
/**
* @brief Returns the uptime of the server in miliseconds.
*/
static qint64 uptime();
/**
* @brief A struct that contains the help information for a command.
* It's split in the syntax and the explanation text.
*/
struct help {
QString usage;
QString text;
};
/**
* @brief Returns a struct with the help information of the command.
*
* @return See short description.
*/
static help commandHelp(QString f_command_name);
/**
* @brief Sets the server's authorization type.
*
* @param f_auth The auth type to set.
*/
static void setAuthType(const DataTypes::AuthType f_auth);
/**
* @brief Sets the server's Message of the Day.
*
* @param f_motd The MOTD to set.
*/
static void setMotd(const QString f_motd);
/**
* @brief Reload the server configuration.
*/
static void reloadSettings();
private:
/**
* @brief Checks if a file exists and is valid.
*
* @param file The file to check.
*
* @return True if the file exists and is valid, false otherwise.
*/
static bool fileExists(const QFileInfo& file);
/**
* @brief Checks if a directory exists and is valid.
*
* @param file The directory to check.
*
* @return True if the directory exists and is valid, false otherwise.
*/
static bool dirExists(const QFileInfo& dir);
/**
* @brief A struct for storing QStringLists loaded from command configuration files.
*/
struct CommandSettings {
QStringList magic_8ball; //!< Contains answers for /8ball, found in config/text/8ball.txt
QStringList praises; //!< Contains command praises, found in config/text/praises.txt
QStringList reprimands; //!< Contains command reprimands, found in config/text/reprimands.txt
QStringList gimps; //!< Contains phrases for /gimp, found in config/text/gimp.txt
QStringList cdns; // !< Contains domains for custom song validation, found in config/text/cdns.txt
};
/**
* @brief Contains the settings required for various commands.
*/
static CommandSettings* m_commands;
/**
* @brief Stores all server configuration values.
*/
static QSettings* m_settings;
/**
* @brief Stores all discord webhook configuration values.
*/
static QSettings* m_discord;
/**
* @brief Stores all of the area valus.
*/
static QSettings* m_areas;
/**
* @brief Stores all adjustable logstrings.
*/
static QSettings* m_logtext;
/**
* @brief Pointer to QElapsedTimer to track the uptime of the server.
*/
static QElapsedTimer* m_uptimeTimer;
/**
* @brief Contains the musiclist with time durations.
*/
static MusicList* m_musicList;
/**
* @brief Contains an ordered list for the musiclist.
*/
static QStringList* m_ordered_list;
/**
* @brief QHash containing the help information for all commands registered to the server.
*/
static QHash<QString,help>* m_commands_help;
/**
* @brief Returns a stringlist with the contents of a .txt file from config/text/.
*
* @param Name of the file to load.
*/
static QStringList loadConfigFile(const QString filename);
};
#endif // CONFIG_MANAGER_H