Privatization rework (#2)

* Add clang-format

* Multiple privatization changes

"Participation handshake" this refers to the moment that the user's client sends the `askchaa` packet.

* Server::m_clients is now private. Get a copy with Server::getClients()
* Server::m_player_count is now private. Get a copy with Server::getPlayerCount() (Additional logic was added to handle the player count.)
* AOClient::m_joined is now private. Get a copy with AOClient::hasJoined()
* Added signal AOClient::joined(); will be emitted when the client first complete the participation handshake.
* Renamed Server::updatePlayerCount to Server::playerCountUpdated

* Privatized Server

* Made Server members private: m_characters, m_areas, m_area_names
* Added Server methods: getCharacters(), getAreas(), getAreaById(f_area_id), getAreaByName(f_area_name), getAreaNames(), getAreaName(f_area_id), getMusicList
* Added Server helper methods: getCharacterCount(), getAreaCount()
- This reduce code repetition of the following example: server->getCharacters().length(), server->getAreas().size()

* Solved other merge conflicts

* Added Server methods, various fixes

* Added Server methods: getCharacterById(f_chr_id)
* Various optimizations

* More Server privatization changes

* Made Server members private: db_manager, next_message_timer, can_send_ic_messages
* Renamed Server members:
  * next_message_timer -> m_message_floodguard_timer
  * can_send_ic_message -> m_can_send_ic_message
Added Server methods: getDatabaseManager, isMessageAllowed, startMessageFloodguard(f_duration)
Made Server methods private: allowMessage

* Added new fields to load for AreaData

* Added fields: `area_message` (default: empty string) and `send_area_message_on_join` (default: false)

* Added Server::clearAreaMessage

* Cleaned up headers include (AOPacket excluded)

* Removed most project file includes, moved to source file (cpp)
  * AOPacket was excluded because some methods modify the copy

* Fix compile error when using MingW compiler

* Appease clang by using proper or and putting it in parentheses
* Remove extra semicolon
This commit is contained in:
Leifa♥ 2022-04-25 21:54:15 +02:00 committed by Rosemary Witchaven
parent 2e7ad02bc3
commit b0555207d6
44 changed files with 2045 additions and 1675 deletions

21
.clang-format Normal file
View File

@ -0,0 +1,21 @@
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterEnum: true
AfterFunction: true
AfterStruct: true
AfterExternBlock: true
BeforeElse: true
SplitEmptyFunction: false
ColumnLimit: 0
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: false
IndentWidth: 4
PackConstructorInitializers: CurrentLine

View File

@ -15,8 +15,8 @@
// 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/>. //
//////////////////////////////////////////////////////////////////////////////////////
#include <include/server.h>
#include <include/config_manager.h>
#include <include/server.h>
#include <cstdlib>
@ -25,7 +25,8 @@
Server *server;
void cleanup() {
void cleanup()
{
server->deleteLater();
}

View File

@ -58,6 +58,7 @@ HEADERS += include/aoclient.h \
include/db_manager.h \
include/discord.h \
include/server.h \
include/typedefs.h \
include/ws_client.h \
include/ws_proxy.h \
include/advertiser.h \

View File

@ -18,9 +18,8 @@
#ifndef ADVERTISER_H
#define ADVERTISER_H
#include <QtNetwork>
#include <QObject>
#include "include/config_manager.h"
#include <QtNetwork>
/**
* @brief Represents the advertiser of the server. Sends current server information to masterserver.
@ -28,13 +27,13 @@
class Advertiser : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor for the HTTP_Advertiser class.
*/
explicit Advertiser();
/**
* @brief Deconstructor for the HTTP_Advertiser class. Yes, that's it. Can't say more about it.
*/
@ -64,7 +63,6 @@ public slots:
void updateAdvertiserSettings();
private:
/**
* @brief Pointer to the network manager, necessary to execute POST requests to the masterserver.
*/

View File

@ -18,30 +18,32 @@
#ifndef AOCLIENT_H
#define AOCLIENT_H
#include "include/aopacket.h"
#include "include/server.h"
#include "include/area_data.h"
#include "include/db_manager.h"
#include "include/music_manager.h"
#include <algorithm>
#include <QHostAddress>
#include <QTcpSocket>
#include <QDateTime>
#include <QHostAddress>
#include <QRegularExpression>
#include <QTcpSocket>
#include <QtGlobal>
#include <QTimer>
#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0)
#include <QRandomGenerator>
#endif
#include "include/aopacket.h"
class AreaData;
class DBManager;
class MusicManager;
class Server;
/**
* @brief Represents a client connected to the server running Attorney Online 2 or one of its derivatives.
*/
class AOClient : public QObject {
class AOClient : public QObject
{
Q_OBJECT
public:
/**
* @brief Creates an instance of the AOClient class.
@ -51,7 +53,7 @@ class AOClient : public QObject {
* @param user_id The user ID of the client.
* @param parent Qt-based parent, passed along to inherited constructor from QObject.
*/
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0, MusicManager* p_manager = nullptr);;
AOClient(Server *p_server, QTcpSocket *p_socket, QObject *parent = nullptr, int user_id = 0, MusicManager *p_manager = nullptr);
/**
* @brief Destructor for the AOClient instance.
@ -78,6 +80,13 @@ class AOClient : public QObject {
*/
QString getHwid() const;
/**
* @brief Returns true if the client has completed the participation handshake. False otherwise.
*
* @return True if the client has completed the participation handshake. False otherwise.
*/
bool hasJoined() const;
/**
* @brief Calculates the client's IPID based on a hashed version of its IP.
*/
@ -197,7 +206,8 @@ class AOClient : public QObject {
* @note Though the version number and naming scheme looks vaguely semver-like,
* do not be misled into thinking it is that.
*/
struct ClientVersion {
struct ClientVersion
{
QString string; //!< The name of the client software, for example, `AO2`.
int release = -1; //!< The 'release' part of the version number. In Attorney Online's case, this is fixed at `2`.
int major = -1; //!< The 'major' part of the version number. In Attorney Online's case, this increases when a new feature is introduced (generally).
@ -236,9 +246,7 @@ class AOClient : public QObject {
{"IGNORE_BGLIST", 1ULL << 15},
{"SEND_NOTICE", 1ULL << 16},
{"JUKEBOX", 1ULL << 17},
{"SUPER", ~0ULL }
};
{"SUPER", ~0ULL}};
/**
* @brief A list of 5 casing preferences (def, pro, judge, jury, steno)
@ -344,6 +352,12 @@ class AOClient : public QObject {
*/
void onAfkTimeout();
signals:
/**
* @brief This signal is emitted when the client has completed the participation handshake.
*/
void joined();
private:
/**
* @brief The TCP socket used to communicate with the client.
@ -358,7 +372,8 @@ class AOClient : public QObject {
/**
* @brief The type of area update, used for area update (ARUP) packets.
*/
enum ARUPType {
enum ARUPType
{
PLAYER_COUNT, //!< The packet contains player count updates.
STATUS, //!< The packet contains area status updates.
CM, //!< The packet contains updates about who's the CM of what area.
@ -505,7 +520,6 @@ class AOClient : public QObject {
*/
void pktChangeMusic(AreaData *area, int argc, QStringList argv, AOPacket packet);
/**
* @brief Implements [the witness testimony / cross examination / judge decision popups]
* (https://github.com/AttorneyOnline/docs/blob/master/docs/development/network.md#witness-testimonycross-examination-wtce).
@ -644,7 +658,8 @@ class AOClient : public QObject {
///@}
/// Describes a packet's interpretation details.
struct PacketInfo {
struct PacketInfo
{
unsigned long long acl_mask; //!< The permissions necessary for the packet.
int minArgs; //!< The minimum arguments needed for the packet to be interpreted correctly / make sense.
void (AOClient::*action)(AreaData *, int, QStringList, AOPacket);
@ -1178,7 +1193,6 @@ class AOClient : public QObject {
*/
void cmdBans(int argc, QStringList argv);
/**
* @brief Toggle whether or not in-character messages purely consisting of spaces are allowed.
*
@ -1766,7 +1780,6 @@ class AOClient : public QObject {
*/
void cmdAddStatement(int argc, QStringList argv);
/**
* @brief Sends a list of the testimony to OOC of the requesting client
*
@ -2026,7 +2039,6 @@ class AOClient : public QObject {
*/
void sendNotice(QString f_notice, bool f_global = false);
/**
* @brief Checks if a testimony contains '<' or '>'.
*
@ -2048,7 +2060,8 @@ class AOClient : public QObject {
/**
* @brief Describes a command's details.
*/
struct CommandInfo {
struct CommandInfo
{
unsigned long long acl_mask; //!< The permissions necessary to be able to run the command. @see ACLFlags.
int minArgs; //!< The minimum mandatory arguments needed for the command to function.
void (AOClient::*action)(int, QStringList);
@ -2212,8 +2225,7 @@ class AOClient : public QObject {
{"addcategory", {ACLFlags.value("CM"), 1, &AOClient::cmdAddCategory}},
{"removeentry", {ACLFlags.value("CM"), 1, &AOClient::cmdRemoveCategorySong}},
{"toggleroot", {ACLFlags.value("CM"), 0, &AOClient::cmdToggleRootlist}},
{"clearcustom", {ACLFlags.value("CM"), 0, &AOClient::cmdClearCustom}}
};
{"clearcustom", {ACLFlags.value("CM"), 0, &AOClient::cmdClearCustom}}};
/**
* @brief Filled with part of a packet if said packet could not be read fully from the client's socket.

View File

@ -29,7 +29,8 @@
* @see https://github.com/AttorneyOnline/docs/blob/master/docs/development/network.md for a general explanation
* on Attorney Online 2's network protocol.
*/
class AOPacket {
class AOPacket
{
public:
/**
* @brief Creates an AOPacket with the given header and contents.

View File

@ -18,25 +18,27 @@
#ifndef AREA_DATA_H
#define AREA_DATA_H
#include "aopacket.h"
#include "config_manager.h"
#include "music_manager.h"
#include <QMap>
#include <QString>
#include <QSettings>
#include <QDebug>
#include <QTimer>
#include <QElapsedTimer>
#include <QMap>
#include <QRandomGenerator>
#include <QSettings>
#include <QString>
#include <QTimer>
#include "include/aopacket.h"
class ConfigManager;
class Logger;
class MusicManager;
/**
* @brief Represents an area on the server, a distinct "room" for people to chat in.
*/
class AreaData : public QObject {
class AreaData : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor for the AreaData class.
@ -50,7 +52,8 @@ class AreaData : public QObject {
/**
* @brief The data for evidence in the area.
*/
struct Evidence {
struct Evidence
{
QString name; //!< The name of the evidence, shown when hovered over clientside.
QString description; //!< The longer description of the evidence, when the user opens the evidence window.
QString image; //!< A path originating from `base/evidence/` that points to an image file.
@ -62,7 +65,8 @@ class AreaData : public QObject {
* @details This is purely aesthetic, and serves no functional purpose from a gameplay perspective.
* It's only benefit is giving the users a rough idea as to what is going on in an area.
*/
enum Status {
enum Status
{
IDLE, //!< The area is currently not busy with anything, or the area is empty.
RP, //!< There is some (non-Ace Attorney-related) roleplay going on in the area.
CASING, //!< An Ace Attorney or Danganronpa-styled case is currently being held in the area.
@ -77,7 +81,8 @@ class AreaData : public QObject {
/**
* @brief Determines who may traverse and communicate in the area.
*/
enum LockStatus {
enum LockStatus
{
FREE,
LOCKED,
SPECTATABLE
@ -110,7 +115,8 @@ class AreaData : public QObject {
/**
* @brief The level of "authorisation" needed to be able to modify, add, and remove evidence in the area.
*/
enum class EvidenceMod{
enum class EvidenceMod
{
FFA,
MOD,
CM,
@ -144,7 +150,8 @@ class AreaData : public QObject {
/**
* @brief The five "states" the testimony recording system can have in an area.
*/
enum TestimonyRecording{
enum TestimonyRecording
{
STOPPED,
RECORDING,
UPDATE,
@ -190,7 +197,8 @@ class AreaData : public QObject {
* @brief Determines how the testimony progressed after advancement was called in a direction
* (Either to next or previous statement).
*/
enum class TestimonyProgress {
enum class TestimonyProgress
{
OK, //!< The expected statement was selected.
LOOPED, //!< The "next" statement would have been beyond the testimony's limits, so the first one was selected.
STAYED_AT_FIRST, //!< The "previous" statement would have been before the first, so the selection stayed at the first.
@ -199,7 +207,8 @@ class AreaData : public QObject {
/**
* @brief Determines a side. Self-explanatory.
*/
enum class Side {
enum class Side
{
DEFENCE, //!< Self-explanatory.
PROSECUTOR, //!< Self-explanatory.
};
@ -571,6 +580,11 @@ class AreaData : public QObject {
*/
void changeAreaMessage(const QString &f_newMessage_r);
/**
* @brief Clear the area message in the area.
*/
void clearAreaMessage();
/**
* @brief Returns the value of the Confidence bar for the defence's side.
*
@ -1061,7 +1075,6 @@ private:
*/
TestimonyRecording m_testimonyRecording;
QVector<QStringList> m_testimony; //!< Vector of all statements saved. Index 0 is always the title of the testimony.
int m_statement; //!< Keeps track of the currently played statement.
@ -1077,7 +1090,6 @@ private:
*/
QStringList m_lastICMessage;
/**
* @brief Whether or not to force immediate text processing in this area.
*/

View File

@ -20,29 +20,29 @@
#define CONFIG_VERSION 1
#include "data_types.h"
#include <QDebug>
#include <QDir>
#include <QElapsedTimer>
#include <QFile>
#include <QFileInfo>
#include <QHostAddress>
#include <QMetaEnum>
#include <QSettings>
#include <QUrl>
#include <QMetaEnum>
#include <QElapsedTimer>
#include <QHostAddress>
// JSON loading requirements
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
typedef QMap<QString,QPair<QString,int>> MusicList;
#include "include/data_types.h"
#include "include/typedefs.h"
/**
* @brief The config file handler class.
*/
class ConfigManager {
class ConfigManager
{
public:
/**
@ -451,7 +451,8 @@ class ConfigManager {
* @brief A struct that contains the help information for a command.
* It's split in the syntax and the explanation text.
*/
struct help {
struct help
{
QString usage;
QString text;
};
@ -482,7 +483,6 @@ class ConfigManager {
*/
static void reloadSettings();
private:
/**
* @brief Checks if a file exists and is valid.
@ -505,7 +505,8 @@ private:
/**
* @brief A struct for storing QStringLists loaded from command configuration files.
*/
struct CommandSettings {
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
@ -566,6 +567,4 @@ private:
static QStringList loadConfigFile(const QString filename);
};
#endif // CONFIG_MANAGER_H

View File

@ -19,6 +19,7 @@
#define DATA_TYPES_H
#include <QDebug>
/**
* @brief A class for handling several custom data types.
*/
@ -30,7 +31,8 @@ public:
/**
* @brief Custom type for authorization types.
*/
enum class AuthType {
enum class AuthType
{
SIMPLE,
ADVANCED
};
@ -39,7 +41,8 @@ public:
/**
* @brief Custom type for logging types.
*/
enum class LogType {
enum class LogType
{
MODCALL,
FULL,
FULLAREA
@ -48,12 +51,14 @@ public:
};
template <typename T>
T toDataType(const QString& f_string){
T toDataType(const QString &f_string)
{
return QVariant(f_string).value<T>();
}
template <typename T>
QString fromDataType(const T& f_t){
QString fromDataType(const T &f_t)
{
return QVariant::fromValue(f_t).toString();
}

View File

@ -21,13 +21,13 @@
#define DB_VERSION 1
#include <QDateTime>
#include <QFileInfo>
#include <QHostAddress>
#include <QMessageAuthenticationCode>
#include <QSqlDatabase>
#include <QSqlDriver>
#include <QSqlError>
#include <QSqlQuery>
#include <QFileInfo>
/**
* @brief A class used to handle database interaction.
@ -39,8 +39,10 @@
* differently than the average user.
* This comes in two forms, when the user's client is banned, and when the user is a moderator.
*/
class DBManager : public QObject {
class DBManager : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor for the DBManager class.
@ -95,7 +97,8 @@ public:
/**
* @brief Details about a ban.
*/
struct BanInfo {
struct BanInfo
{
QString ipid; //!< The banned user's IPID.
QHostAddress ip; //!< The banned user's IP.
QString hdid; //!< The banned user's hardware ID.

View File

@ -18,14 +18,16 @@
#ifndef DISCORD_H
#define DISCORD_H
#include <QtNetwork>
#include <QCoreApplication>
#include "config_manager.h"
#include <QtNetwork>
class ConfigManager;
/**
* @brief A class for handling all Discord webhook requests.
*/
class Discord : public QObject {
class Discord : public QObject
{
Q_OBJECT
public:
@ -56,7 +58,6 @@ public:
*/
void stopUptimeTimer();
public slots:
/**
* @brief Handles a modcall webhook request.
@ -159,7 +160,6 @@ private slots:
* @return A JSON document for the alive notification.
*/
QJsonDocument constructUptimeJson(const QString &f_timeExpired);
};
#endif // DISCORD_H

View File

@ -18,13 +18,13 @@
#ifndef U_LOGGER_H
#define U_LOGGER_H
#include <QObject>
#include <QMap>
#include <QQueue>
#include <QDateTime>
#include "include/config_manager.h"
#include "include/logger/writer_full.h"
#include "include/logger/writer_modcall.h"
#include <QDateTime>
#include <QMap>
#include <QObject>
#include <QQueue>
/**
* @brief The Universal Logger class to provide a common place to handle, store and write logs to file.
@ -32,6 +32,7 @@
class ULogger : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor for the universal logger. Determines which writer is initially created.
@ -102,7 +103,6 @@ public slots:
void loadLogtext();
private:
/**
* @brief Updates the area buffer with a new entry, moving old ones if the buffer exceesed the maximum size.
* @param Name of the area which buffer is modified.
@ -144,8 +144,7 @@ private:
{"kick", "[%1][%2][KICK][%3]"},
{"ban", "[%1][%2][BAN][%3][%4]"},
{"modcall", "[%1][%2][MODCALL][%5][%3(%4)]"},
{"connect", "[%1][CONNECT][%2][%3][%4]"}
};
{"connect", "[%1][CONNECT][%2][%3][%4]"}};
};
#endif // U_LOGGER_H

View File

@ -17,10 +17,10 @@
//////////////////////////////////////////////////////////////////////////////////////
#ifndef WRITER_FULL_H
#define WRITER_FULL_H
#include <QObject>
#include <QFile>
#include <QDir>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QObject>
#include <QTextStream>
/**
@ -29,13 +29,15 @@
class WriterFull : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor for full logwriter
*
* @param QObject pointer to the parent object.
*/
WriterFull(QObject* parent = nullptr);;
WriterFull(QObject *parent = nullptr);
;
/**
* @brief Deconstructor for full logwriter.

View File

@ -17,13 +17,12 @@
//////////////////////////////////////////////////////////////////////////////////////
#ifndef WRITER_MODCALL_H
#define WRITER_MODCALL_H
#include <QObject>
#include <QFile>
#include <QDir>
#include <QDateTime>
#include <QTextStream>
#include <QDir>
#include <QFile>
#include <QObject>
#include <QQueue>
#include <QTextStream>
/**
* @brief A class to handle file interaction when writing the modcall buffer.
@ -31,13 +30,15 @@
class WriterModcall : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor for modcall logwriter
*
* @param QObject pointer to the parent object.
*/
WriterModcall(QObject* parent = nullptr);;
WriterModcall(QObject *parent = nullptr);
;
/**
* @brief Deconstructor for modcall logwriter.

View File

@ -18,26 +18,27 @@
#ifndef MUSIC_MANAGER_H
#define MUSIC_MANAGER_H
#include <QObject>
#include <QMap>
#include <QHash>
#include <QMap>
#include <QObject>
#include <QPair>
#include <include/config_manager.h>
#include <include/aopacket.h>
#include "include/aopacket.h"
#include "include/typedefs.h"
class ConfigManager;
class MusicManager : public QObject
{
Q_OBJECT
public:
public:
/**
* @brief Constructor for the server-wide musiclist manager.
*
* @param Copy of the server musiclist generated by ConfigManager::musiclist();
*/
MusicManager(QObject* parent = nullptr, QStringList f_root_ordered = {}, QStringList f_cdns = {"cdn.discord.com"},
QMap<QString, QPair<QString, int> > f_root_list = ConfigManager::musiclist());
MusicManager(QStringList f_root_ordered, QStringList f_cdns, QMap<QString, QPair<QString, int>> f_root_list, QObject *parent = nullptr);
/**
* @brief Destructor for the server-wide musiclist manager.
@ -179,7 +180,6 @@ signals:
void sendAreaFMPacket(AOPacket f_packet, int f_area_index);
private:
/**
* @brief Contains all custom lists of all areas in the server.
*/

View File

@ -18,35 +18,34 @@
#ifndef SERVER_H
#define SERVER_H
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/ws_proxy.h"
#include "include/db_manager.h"
#include "include/discord.h"
#include "include/config_manager.h"
#include "include/advertiser.h"
#include "include/logger/u_logger.h"
#include "include/music_manager.h"
#include <QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QMap>
#include <QSettings>
#include <QStack>
#include <QString>
#include <QTcpServer>
#include <QTcpSocket>
#include <QTimer>
#include "include/aopacket.h"
class Advertiser;
class AOClient;
class DBManager;
class AreaData;
class ConfigManager;
class DBManager;
class Discord;
class MusicManager;
class ULogger;
class WSProxy;
/**
* @brief The class that represents the actual server as it is.
*/
class Server : public QObject {
class Server : public QObject
{
Q_OBJECT
public:
@ -79,13 +78,21 @@ class Server : public QObject {
/**
* @brief Enum to specifc different targets to send altered packets to a specific usergroup.
*/
enum class TARGET_TYPE {
enum class TARGET_TYPE
{
AUTHENTICATED,
MODCHAT,
ADVERT
};
Q_ENUM(TARGET_TYPE)
/**
* @brief Returns a list of all clients currently in the server.
*
* @return A list of all clients currently in the server.
*/
QVector<AOClient *> getClients();
/**
* @brief Gets a pointer to a client by IPID.
*
@ -115,6 +122,36 @@ class Server : public QObject {
*/
AOClient *getClientByID(int id);
/**
* @brief Returns the overall player count in the server.
*
* @return The overall player count in the server.
*/
int getPlayerCount();
/**
* @brief Returns a list of the available characters on the server to use.
*
* @return A list of the available characters on the server to use.
*/
QStringList getCharacters();
/**
* @brief Returns the count of available characters on the server to use.
*
* @return The count of available characters on the server to use.
*/
int getCharacterCount();
/**
* @brief Get the available character by index.
*
* @param f_chr_id The index of the character.
*
* @return The character if it exist, otherwise an empty stirng.
*/
QString getCharacterById(int f_chr_id);
/**
* @brief Updates which characters are taken in the given area, and sends out an update packet to
* all clients present the area.
@ -185,11 +222,220 @@ class Server : public QObject {
**/
bool isIPBanned(QHostAddress f_remote_IP);
/**
* @brief Returns the list of areas in the server.
*
* @return A list of areas.
*/
QVector<AreaData *> getAreas();
/**
* @brief Returns the number of areas in the server.
*/
int getAreaCount();
/**
* @brief Returns a pointer to the area associated with the index.
*
* @param f_area_id The index of the area.
*
* @return A pointer to the area or null.
*/
AreaData *getAreaById(int f_area_id);
/**
* @brief Getter for an area specific buffer from the logger.
*/
QQueue<QString> getAreaBuffer(const QString &f_areaName);
/**
* @brief The names of the areas on the server.
*
* @return A list of names.
*/
QStringList getAreaNames();
/**
* @brief Returns the name of the area associated with the index.
*
* @param f_area_id The index of the area.
*
* @return The name of the area or empty.
*/
QString getAreaName(int f_area_id);
/**
* @brief Returns the available songs on the server.
*
* @return A list of songs.
*/
QStringList getMusicList();
/**
* @brief Returns the available backgrounds on the server.
*
* @return A list of backgrounds.
*/
QStringList getBackgrounds();
/**
* @brief Returns a pointer to a database manager.
*
* @return A pointer to database manager.
*/
DBManager *getDatabaseManager();
/**
* @brief The server-wide global timer.
*/
QTimer *timer;
QStringList getCursedCharsTaken(AOClient *client, QStringList chars_taken);
/**
* @brief Returns whatever a game message may be broadcasted or not.
*
* @return True if expired; false otherwise.
*/
bool isMessageAllowed();
/**
* @brief Starts a global timer that determines whatever a game message may be broadcasted or not.
*
* @param f_duration The duration of the message floodguard timer.
*/
void startMessageFloodguard(int f_duration);
/**
* @brief Attempts to parse a IPv6 mapped IPv4 to an IPv4.
*/
QHostAddress parseToIPv4(QHostAddress f_remote_ip);
public slots:
/**
* @brief Convenience class to call a reload of available configuraiton elements.
*/
void reloadSettings();
/**
* @brief Handles a new connection.
*
* @details The function creates an AOClient to represent the user, assigns a user ID to them, and
* checks if the client is banned.
*/
void clientConnected();
/**
* @brief Method to construct and reconstruct Discord Webhook Integration.
*
* @details Constructs or rebuilds Discord Object during server startup and configuration reload.
*/
void handleDiscordIntegration();
/**
* @brief Marks a userID as free and ads it back to the available client id queue.
*/
void markIDFree(const int &f_user_id);
signals:
/**
* @brief Sends the server name and description, emitted by /reload.
*
* @param p_name The server name.
* @param p_desc The server description.
*/
void reloadRequest(QString p_name, QString p_desc);
/**
* @brief This signal is emitted whenever the current player count has changed.
*
* @param f_current_player The player count at the time the signal was emitted.
*/
void playerCountUpdated(int f_current_players);
/**
* @brief Triggers a partial update of the modern advertiser as some information, such as ports
* can't be updated while the server is running.
*/
void updateHTTPConfiguration();
/**
* @brief Sends a modcall webhook request, emitted by AOClient::pktModcall.
*
* @param f_name The character or OOC name of the client who sent the modcall.
* @param f_area The name of the area the modcall was sent from.
* @param f_reason The reason the client specified for the modcall.
* @param f_buffer The area's log buffer.
*/
void modcallWebhookRequest(const QString &f_name, const QString &f_area, const QString &f_reason, const QQueue<QString> &f_buffer);
/**
* @brief Sends a ban webhook request, emitted by AOClient::cmdBan
* @param f_ipid The IPID of the banned client.
* @param f_moderator The moderator who issued the ban.
* @param f_duration The duration of the ban in a human readable format.
* @param f_reason The reason for the ban.
* @param f_banID The ID of the issued ban.
*/
void banWebhookRequest(const QString &f_ipid, const QString &f_moderator, const QString &f_duration, const QString &f_reason, const int &f_banID);
/**
* @brief Signal connected to universal logger. Logs a client connection attempt.
* @param f_ip_address The IP Address of the incoming connection.
* @param f_ipid The IPID of the incoming connection.
* @param f_hdid The HDID of the incoming connection.
*/
void logConnectionAttempt(const QString &f_ip_address, const QString &f_ipid, const QString &f_hwid);
private:
/**
* @brief The proxy used for WebSocket connections.
*
* @see WSProxy and WSClient for an explanation as to why this is a thing.
*/
WSProxy *proxy;
/**
* @brief Listens for incoming TCP connections.
*/
QTcpServer *server;
/**
* @brief Handles Discord webhooks.
*/
Discord *discord;
/**
* @brief Handles HTTP server advertising.
*/
Advertiser *ms3_Advertiser;
/**
* @brief Advertises the server in a regular intervall.
*/
QTimer *AdvertiserTimer;
/**
* @brief Handles the universal log framework.
*/
ULogger *logger;
/**
* @brief Handles all musiclists.
*/
MusicManager *music_manager;
/**
* @brief The port through which the server will accept TCP connections.
*/
int port;
/**
* @brief The port through which the server will accept WebSocket connections.
*/
int ws_port;
/**
* @brief The collection of all currently connected clients.
*/
@ -247,169 +493,43 @@ class Server : public QObject {
*/
QStringList m_ipban_list;
/**
* @brief Timer until the next IC message can be sent.
*/
QTimer *m_message_floodguard_timer;
/**
* @brief If false, IC messages will be rejected.
*/
bool m_can_send_ic_messages = true;
/**
* @brief The database manager on the server, used to store users' bans and authorisation details.
*/
DBManager *db_manager;
/**
* @brief The server-wide global timer.
*/
QTimer* timer;
QStringList getCursedCharsTaken(AOClient* client, QStringList chars_taken);
/**
* @brief Timer until the next IC message can be sent.
*/
QTimer next_message_timer;
/**
* @brief Attempts to parse a IPv6 mapped IPv4 to an IPv4.
*/
QHostAddress parseToIPv4(QHostAddress f_remote_ip);
/**
* @brief If false, IC messages will be rejected.
*/
bool can_send_ic_messages = true;
public slots:
/**
* @brief Convenience class to call a reload of available configuraiton elements.
*/
void reloadSettings();
/**
* @brief Handles a new connection.
*
* @details The function creates an AOClient to represent the user, assigns a user ID to them, and
* checks if the client is banned.
*/
void clientConnected();
/**
* @brief Sets #can_send_messages to true.
*
* @details Called whenever #next_message_timer reaches 0.
*/
void allowMessage();
/**
* @brief Method to construct and reconstruct Discord Webhook Integration.
*
* @details Constructs or rebuilds Discord Object during server startup and configuration reload.
*/
void handleDiscordIntegration();
/**
* @brief Marks a userID as free and ads it back to the available client id queue.
*/
void markIDFree(const int& f_user_id);
signals:
/**
* @brief Sends the server name and description, emitted by /reload.
*
* @param p_name The server name.
* @param p_desc The server description.
*/
void reloadRequest(QString p_name, QString p_desc);
/**
* @brief Updates the playercount in the modern advertiser.
*/
void updatePlayerCount(int f_current_players);
/**
* @brief Triggers a partial update of the modern advertiser as some information, such as ports
* can't be updated while the server is running.
*/
void updateHTTPConfiguration();
/**
* @brief Sends a modcall webhook request, emitted by AOClient::pktModcall.
*
* @param f_name The character or OOC name of the client who sent the modcall.
* @param f_area The name of the area the modcall was sent from.
* @param f_reason The reason the client specified for the modcall.
* @param f_buffer The area's log buffer.
*/
void modcallWebhookRequest(const QString& f_name, const QString& f_area, const QString& f_reason, const QQueue<QString>& f_buffer);
/**
* @brief Sends a ban webhook request, emitted by AOClient::cmdBan
* @param f_ipid The IPID of the banned client.
* @param f_moderator The moderator who issued the ban.
* @param f_duration The duration of the ban in a human readable format.
* @param f_reason The reason for the ban.
* @param f_banID The ID of the issued ban.
*/
void banWebhookRequest(const QString& f_ipid, const QString& f_moderator, const QString& f_duration, const QString& f_reason, const int& f_banID);
/**
* @brief Signal connected to universal logger. Logs a client connection attempt.
* @param f_ip_address The IP Address of the incoming connection.
* @param f_ipid The IPID of the incoming connection.
* @param f_hdid The HDID of the incoming connection.
*/
void logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid, const QString& f_hwid);
private:
/**
* @brief Connects new AOClient to logger and disconnect handling.
**/
void hookupAOClient(AOClient *client);
private slots:
/**
* @brief The proxy used for WebSocket connections.
* @brief Increase the current player count by one.
*/
void increasePlayerCount();
/**
* @brief Decrease the current player count based on the client id provided.
*
* @see WSProxy and WSClient for an explanation as to why this is a thing.
* @param f_client_id The client id of the client to check.
*/
WSProxy* proxy;
void decreasePlayerCount();
/**
* @brief Listens for incoming TCP connections.
* @brief Allow game messages to be broadcasted.
*/
QTcpServer* server;
/**
* @brief Handles Discord webhooks.
*/
Discord* discord;
/**
* @brief Handles HTTP server advertising.
*/
Advertiser* ms3_Advertiser;
/**
* @brief Advertises the server in a regular intervall.
*/
QTimer* AdvertiserTimer;
/**
* @brief Handles the universal log framework.
*/
ULogger* logger;
/**
* @brief Handles all musiclists.
*/
MusicManager* music_manager;
/**
* @brief The port through which the server will accept TCP connections.
*/
int port;
/**
* @brief The port through which the server will accept WebSocket connections.
*/
int ws_port;
void allowMessage();
};
#endif // SERVER_H

7
core/include/typedefs.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <QMap>
#include <QPair>
#include <QString>
typedef QMap<QString, QPair<QString, int>> MusicList;

View File

@ -19,9 +19,9 @@
#define WS_CLIENT_H
#include <QObject>
#include <QtWebSockets/QtWebSockets>
#include <QTcpSocket>
#include <QString>
#include <QTcpSocket>
#include <QtWebSockets/QtWebSockets>
/**
* @brief Represents a WebSocket client (generally WebAO) connected to the server.
@ -31,8 +31,10 @@
*
* This class is a very thin layer -- see WSProxy for the actual mechanics of this WebSocket-to-TCP proxy solution.
*/
class WSClient : public QObject {
class WSClient : public QObject
{
Q_OBJECT
public:
/**
* @brief Creates an instance of the WSClient class.
@ -92,7 +94,6 @@ public slots:
*/
void onTcpConnect();
private:
/**
* @brief The local TCP socket used as a proxy to connect with the server.

View File

@ -18,19 +18,21 @@
#ifndef WS_PROXY_H
#define WS_PROXY_H
#include "include/ws_client.h"
#include <QHostAddress>
#include <QMap>
#include <QTcpSocket>
#include <QtWebSockets/QtWebSockets>
#include <QHostAddress>
class WSClient;
/**
* @brief Handles WebSocket connections by redirecting data sent through them through a local TCP connection
* for common handling.
*/
class WSProxy : public QObject {
class WSProxy : public QObject
{
Q_OBJECT
public:
/**
* @brief Creates a WSProxy instance.

View File

@ -17,13 +17,14 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/advertiser.h"
#include "include/config_manager.h"
Advertiser::Advertiser()
{
m_manager = new QNetworkAccessManager();
connect(m_manager, &QNetworkAccessManager::finished,
this, &Advertiser::msRequestFinished);
m_name = ConfigManager::serverName();
m_hostname = ConfigManager::advertiserHostname();
m_description = ConfigManager::serverDescription();
@ -73,7 +74,6 @@ void Advertiser::msAdvertiseServer()
if (m_debug)
qWarning().noquote() << "Unable to advertise. Masterserver URL '" + m_masterserver.toString() + "' is not valid.";
return;
}
void Advertiser::msRequestFinished(QNetworkReply *f_reply)
@ -110,5 +110,3 @@ void Advertiser::updateAdvertiserSettings()
m_masterserver = ConfigManager::advertiserIP();
m_debug = ConfigManager::advertiserDebug();
}

View File

@ -17,6 +17,12 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/db_manager.h"
#include "include/server.h"
void AOClient::clientData()
{
if (last_read + m_socket->bytesAvailable() > 30720) { // Client can send a max of 30KB to the server over two sequential reads
@ -53,19 +59,18 @@ void AOClient::clientDisconnected()
qDebug() << remote_ip.toString() << "disconnected";
#endif
if (m_joined) {
server->m_player_count--;
emit server->updatePlayerCount(server->m_player_count);
server->m_areas[m_current_area]->clientLeftArea(server->getCharID(m_current_char), m_id);
server->getAreaById(m_current_area)->clientLeftArea(server->getCharID(m_current_char), m_id);
arup(ARUPType::PLAYER_COUNT, true);
}
if (m_current_char != "") {
server->updateCharsTaken(server->m_areas[m_current_area]);
server->updateCharsTaken(server->getAreaById(m_current_area));
}
bool l_updateLocks = false;
for (AreaData* l_area : qAsConst(server->m_areas)) {
const QVector<AreaData *> l_areas = server->getAreas();
for (AreaData *l_area : l_areas) {
l_updateLocks = l_updateLocks || l_area->removeOwner(m_id);
}
@ -81,7 +86,7 @@ void AOClient::handlePacket(AOPacket packet)
#ifdef NET_DEBUG
qDebug() << "Received packet:" << packet.header << ":" << packet.contents << "args length:" << packet.contents.length();
#endif
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
PacketInfo l_info = packets.value(packet.header, {false, 0, &AOClient::pktDefault});
if (packet.contents.join("").size() > 16384) {
@ -112,38 +117,38 @@ void AOClient::handlePacket(AOPacket packet)
void AOClient::changeArea(int new_area)
{
if (m_current_area == new_area) {
sendServerMessage("You are already in area " + server->m_area_names[m_current_area]);
sendServerMessage("You are already in area " + server->getAreaName(m_current_area));
return;
}
if (server->m_areas[new_area]->lockStatus() == AreaData::LockStatus::LOCKED && !server->m_areas[new_area]->invited().contains(m_id) && !checkAuth(ACLFlags.value("BYPASS_LOCKS"))) {
sendServerMessage("Area " + server->m_area_names[new_area] + " is locked.");
if (server->getAreaById(new_area)->lockStatus() == AreaData::LockStatus::LOCKED && !server->getAreaById(new_area)->invited().contains(m_id) && !checkAuth(ACLFlags.value("BYPASS_LOCKS"))) {
sendServerMessage("Area " + server->getAreaName(new_area) + " is locked.");
return;
}
if (m_current_char != "") {
server->m_areas[m_current_area]->changeCharacter(server->getCharID(m_current_char), -1);
server->updateCharsTaken(server->m_areas[m_current_area]);
server->getAreaById(m_current_area)->changeCharacter(server->getCharID(m_current_char), -1);
server->updateCharsTaken(server->getAreaById(m_current_area));
}
server->m_areas[m_current_area]->clientLeftArea(m_char_id, m_id);
server->getAreaById(m_current_area)->clientLeftArea(m_char_id, m_id);
bool l_character_taken = false;
if (server->m_areas[new_area]->charactersTaken().contains(server->getCharID(m_current_char))) {
if (server->getAreaById(new_area)->charactersTaken().contains(server->getCharID(m_current_char))) {
m_current_char = "";
m_char_id = -1;
l_character_taken = true;
}
server->m_areas[new_area]->clientJoinedArea(m_char_id, m_id);
server->getAreaById(new_area)->clientJoinedArea(m_char_id, m_id);
m_current_area = new_area;
arup(ARUPType::PLAYER_COUNT, true);
sendEvidenceList(server->m_areas[new_area]);
sendPacket("HP", {"1", QString::number(server->m_areas[new_area]->defHP())});
sendPacket("HP", {"2", QString::number(server->m_areas[new_area]->proHP())});
sendPacket("BN", {server->m_areas[new_area]->background()});
sendEvidenceList(server->getAreaById(new_area));
sendPacket("HP", {"1", QString::number(server->getAreaById(new_area)->defHP())});
sendPacket("HP", {"2", QString::number(server->getAreaById(new_area)->proHP())});
sendPacket("BN", {server->getAreaById(new_area)->background()});
if (l_character_taken) {
sendPacket("DONE");
}
const QList<QTimer*> l_timers = server->m_areas[m_current_area]->timers();
const QList<QTimer *> l_timers = server->getAreaById(m_current_area)->timers();
for (QTimer *l_timer : l_timers) {
int l_timer_id = server->m_areas[m_current_area]->timers().indexOf(l_timer) + 1;
int l_timer_id = server->getAreaById(m_current_area)->timers().indexOf(l_timer) + 1;
if (l_timer->isActive()) {
sendPacket("TI", {QString::number(l_timer_id), "2"});
sendPacket("TI", {QString::number(l_timer_id), "0", QString::number(QTime(0, 0).msecsTo(QTime(0, 0).addMSecs(l_timer->remainingTime())))});
@ -152,19 +157,19 @@ void AOClient::changeArea(int new_area)
sendPacket("TI", {QString::number(l_timer_id), "3"});
}
}
sendServerMessage("You moved to area " + server->m_area_names[m_current_area]);
if (server->m_areas[m_current_area]->sendAreaMessageOnJoin())
sendServerMessage(server->m_areas[m_current_area]->areaMessage());
sendServerMessage("You moved to area " + server->getAreaName(m_current_area));
if (server->getAreaById(m_current_area)->sendAreaMessageOnJoin())
sendServerMessage(server->getAreaById(m_current_area)->areaMessage());
if (server->m_areas[m_current_area]->lockStatus() == AreaData::LockStatus::SPECTATABLE)
sendServerMessage("Area " + server->m_area_names[m_current_area] + " is spectate-only; to chat IC you will need to be invited by the CM.");
if (server->getAreaById(m_current_area)->lockStatus() == AreaData::LockStatus::SPECTATABLE)
sendServerMessage("Area " + server->getAreaName(m_current_area) + " is spectate-only; to chat IC you will need to be invited by the CM.");
}
bool AOClient::changeCharacter(int char_id)
{
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if(char_id >= server->m_characters.length())
if (char_id >= server->getCharacterCount())
return false;
if (m_is_charcursed && !m_charcurse_list.contains(char_id)) {
@ -178,7 +183,7 @@ bool AOClient::changeCharacter(int char_id)
}
if (l_successfulChange == true) {
QString l_char_selected = server->m_characters[char_id];
QString l_char_selected = server->getCharacterById(char_id);
m_current_char = l_char_selected;
m_pos = "";
server->updateCharsTaken(l_area);
@ -217,18 +222,22 @@ void AOClient::arup(ARUPType type, bool broadcast)
{
QStringList l_arup_data;
l_arup_data.append(QString::number(type));
for (AreaData* l_area : qAsConst(server->m_areas)) {
const QVector<AreaData *> l_areas = server->getAreas();
for (AreaData *l_area : l_areas) {
switch (type) {
case ARUPType::PLAYER_COUNT: {
case ARUPType::PLAYER_COUNT:
{
l_arup_data.append(QString::number(l_area->playerCount()));
break;
}
case ARUPType::STATUS: {
case ARUPType::STATUS:
{
QString l_area_status = QVariant::fromValue(l_area->status()).toString().replace("_", "-"); // LOOKING_FOR_PLAYERS to LOOKING-FOR-PLAYERS
l_arup_data.append(l_area_status);
break;
}
case ARUPType::CM: {
case ARUPType::CM:
{
if (l_area->owners().isEmpty())
l_arup_data.append("FREE");
else {
@ -242,12 +251,14 @@ void AOClient::arup(ARUPType type, bool broadcast)
}
break;
}
case ARUPType::LOCKED: {
case ARUPType::LOCKED:
{
QString l_lock_status = QVariant::fromValue(l_area->lockStatus()).toString();
l_arup_data.append(l_lock_status);
break;
}
default: {
default:
{
return;
}
}
@ -258,7 +269,8 @@ void AOClient::arup(ARUPType type, bool broadcast)
sendPacket("ARUP", l_arup_data);
}
void AOClient::fullArup() {
void AOClient::fullArup()
{
arup(ARUPType::PLAYER_COUNT, false);
arup(ARUPType::STATUS, false);
arup(ARUPType::CM, false);
@ -326,7 +338,7 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
#endif
if (acl_mask != ACLFlags.value("NONE")) {
if (acl_mask == ACLFlags.value("CM")) {
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->owners().contains(m_id))
return true;
}
@ -338,7 +350,7 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
return m_authenticated;
break;
case DataTypes::AuthType::ADVANCED:
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
unsigned long long l_user_acl = server->getDatabaseManager()->getACL(m_moderator_name);
return (l_user_acl & acl_mask) != 0;
break;
}
@ -346,7 +358,6 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
return true;
}
QString AOClient::getIpid() const
{
return m_ipid;
@ -357,6 +368,11 @@ QString AOClient::getHwid() const
return m_hwid;
}
bool AOClient::hasJoined() const
{
return m_joined;
}
Server *AOClient::getServer() { return server; }
void AOClient::onAfkTimeout()
@ -366,8 +382,8 @@ void AOClient::onAfkTimeout()
m_is_afk = true;
}
AOClient::AOClient(Server *p_server, QTcpSocket *p_socket, QObject *parent, int user_id, MusicManager *p_manager)
: QObject(parent),
AOClient::AOClient(Server *p_server, QTcpSocket *p_socket, QObject *parent, int user_id, MusicManager *p_manager) :
QObject(parent),
m_id(user_id),
m_remote_ip(p_socket->peerAddress()),
m_password(""),
@ -382,10 +398,10 @@ AOClient::AOClient(Server *p_server, QTcpSocket *p_socket, QObject *parent, int
{
m_afk_timer = new QTimer;
m_afk_timer->setSingleShot(true);
connect(m_afk_timer, &QTimer::timeout,
this, &AOClient::onAfkTimeout);
connect(m_afk_timer, &QTimer::timeout, this, &AOClient::onAfkTimeout);
}
AOClient::~AOClient() {
AOClient::~AOClient()
{
m_socket->deleteLater();
}

View File

@ -18,7 +18,10 @@
#include <algorithm>
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/music_manager.h"
AreaData::AreaData(QString p_name, int p_index, MusicManager *p_music_manager = nullptr) :
m_index(p_index),
@ -47,6 +50,8 @@ AreaData::AreaData(QString p_name, int p_index, MusicManager* p_music_manager =
m_bgLocked = areas_ini->value("bg_locked", "false").toBool();
m_eviMod = QVariant(areas_ini->value("evidence_mod", "FFA").toString().toUpper()).value<EvidenceMod>();
m_blankpostingAllowed = areas_ini->value("blankposting_allowed", "true").toBool();
m_area_message = areas_ini->value("area_message").toString();
m_send_area_message = areas_ini->value("send_area_message_on_join", false).toBool();
m_forceImmediate = areas_ini->value("force_immediate", "false").toBool();
m_toggleMusic = areas_ini->value("toggle_music", "true").toBool();
m_shownameAllowed = areas_ini->value("shownames_allowed", "true").toBool();
@ -468,7 +473,8 @@ void AreaData::changeHP(AreaData::Side f_side, int f_newHP)
{
if (f_side == Side::DEFENCE) {
m_defHP = std::min(std::max(0, f_newHP), 10);
} else if(f_side == Side::PROSECUTOR) {
}
else if (f_side == Side::PROSECUTOR) {
m_proHP = std::min(std::max(0, f_newHP), 10);
}
}
@ -490,7 +496,7 @@ void AreaData::changeDoc(const QString &f_newDoc_r)
QString AreaData::areaMessage() const
{
return m_area_message;
return m_area_message.isEmpty() ? "No area message set." : m_area_message;
}
bool AreaData::sendAreaMessageOnJoin() const
@ -500,12 +506,14 @@ bool AreaData::sendAreaMessageOnJoin() const
void AreaData::changeAreaMessage(const QString &f_newMessage_r)
{
if(f_newMessage_r.isEmpty())
m_area_message = "No area message set.";
else
m_area_message = f_newMessage_r;
}
void AreaData::clearAreaMessage()
{
changeAreaMessage(QString{});
}
bool AreaData::bgLocked() const
{
return m_bgLocked;

View File

@ -17,14 +17,18 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/server.h"
// This file is for commands under the area category in aoclient.h
// Be sure to register the command in the header before adding it here!
void AOClient::cmdCM(int argc, QStringList argv)
{
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->isProtected()) {
sendServerMessage("This area is protected, you may not become CM.");
return;
@ -63,7 +67,7 @@ void AOClient::cmdCM(int argc, QStringList argv)
void AOClient::cmdUnCM(int argc, QStringList argv)
{
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
int l_uid;
if (l_area->owners().isEmpty()) {
@ -108,7 +112,7 @@ void AOClient::cmdInvite(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
bool ok;
int l_invited_id = argv[0].toInt(&ok);
if (!ok) {
@ -133,7 +137,7 @@ void AOClient::cmdUnInvite(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
bool ok;
int l_uninvited_id = argv[0].toInt(&ok);
if (!ok) {
@ -163,16 +167,17 @@ void AOClient::cmdLock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[m_current_area];
AreaData *area = server->getAreaById(m_current_area);
if (area->lockStatus() == AreaData::LockStatus::LOCKED) {
sendServerMessage("This area is already locked.");
return;
}
sendServerMessageArea("This area is now locked.");
area->lock();
for (AOClient* client : qAsConst(server->m_clients)) { // qAsConst here avoids detaching the container
if (client->m_current_area == m_current_area && client->m_joined) {
area->invite(client->m_id);
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_current_area == m_current_area && l_client->hasJoined()) {
area->invite(l_client->m_id);
}
}
arup(ARUPType::LOCKED, true);
@ -183,16 +188,17 @@ void AOClient::cmdSpectatable(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->lockStatus() == AreaData::LockStatus::SPECTATABLE) {
sendServerMessage("This area is already in spectate mode.");
return;
}
sendServerMessageArea("This area is now spectatable.");
l_area->spectatable();
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->m_current_area == m_current_area && client->m_joined) {
l_area->invite(client->m_id);
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_current_area == m_current_area && l_client->hasJoined()) {
l_area->invite(l_client->m_id);
}
}
arup(ARUPType::LOCKED, true);
@ -203,7 +209,7 @@ void AOClient::cmdUnLock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->lockStatus() == AreaData::LockStatus::FREE) {
sendServerMessage("This area is not locked.");
return;
@ -219,9 +225,9 @@ void AOClient::cmdGetAreas(int argc, QStringList argv)
Q_UNUSED(argv);
QStringList l_entries;
l_entries.append("\n== Currently Online: " + QString::number(server->m_player_count)+ " ==");
for (int i = 0; i < server->m_area_names.length(); i++) {
if (server->m_areas.value(i)->playerCount() > 0) {
l_entries.append("\n== Currently Online: " + QString::number(server->getPlayerCount()) + " ==");
for (int i = 0; i < server->getAreaCount(); i++) {
if (server->getAreaById(i)->playerCount() > 0) {
QStringList l_cur_area_lines = buildAreaList(i);
l_entries.append(l_cur_area_lines);
}
@ -244,7 +250,7 @@ void AOClient::cmdArea(int argc, QStringList argv)
bool ok;
int l_new_area = argv[0].toInt(&ok);
if (!ok || l_new_area >= server->m_areas.size() || l_new_area < 0) {
if (!ok || l_new_area >= server->getAreaCount() || l_new_area < 0) {
sendServerMessage("That does not look like a valid area ID.");
return;
}
@ -255,7 +261,7 @@ void AOClient::cmdAreaKick(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
bool ok;
int l_idx = argv[0].toInt(&ok);
@ -263,7 +269,7 @@ void AOClient::cmdAreaKick(int argc, QStringList argv)
sendServerMessage("That does not look like a valid ID.");
return;
}
if (server->m_areas[m_current_area]->owners().contains(l_idx)) {
if (server->getAreaById(m_current_area)->owners().contains(l_idx)) {
sendServerMessage("You cannot kick another CM!");
return;
}
@ -287,9 +293,9 @@ void AOClient::cmdSetBackground(int argc, QStringList argv)
Q_UNUSED(argc);
QString f_background = argv.join(" ");
AreaData* area = server->m_areas[m_current_area];
AreaData *area = server->getAreaById(m_current_area);
if (m_authenticated || !area->bgLocked()) {
if (server->m_backgrounds.contains(f_background, Qt::CaseInsensitive) || area->ignoreBgList() == true) {
if (server->getBackgrounds().contains(f_background, Qt::CaseInsensitive) || area->ignoreBgList() == true) {
area->setBackground(f_background);
server->broadcast(AOPacket("BN", {f_background}), m_current_area);
sendServerMessageArea(m_current_char + " changed the background to " + f_background);
@ -308,7 +314,7 @@ void AOClient::cmdBgLock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->bgLocked() == false) {
l_area->toggleBgLock();
@ -322,7 +328,7 @@ void AOClient::cmdBgUnlock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->bgLocked() == true) {
l_area->toggleBgLock();
@ -335,13 +341,14 @@ void AOClient::cmdStatus(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
QString l_arg = argv[0].toLower();
if (l_area->changeStatus(l_arg)) {
arup(ARUPType::STATUS, true);
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), m_current_char + " changed status to " + l_arg.toUpper(), "1"}), m_current_area);
} else {
}
else {
const QStringList keys = AreaData::map_statuses.keys();
sendServerMessage("That does not look like a valid status. Valid statuses are " + keys.join(", "));
}
@ -352,7 +359,7 @@ void AOClient::cmdJudgeLog(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->judgelog().isEmpty()) {
sendServerMessage("There have been no judge actions in this area.");
return;
@ -373,7 +380,7 @@ void AOClient::cmdIgnoreBgList(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->toggleIgnoreBgList();
QString l_state = l_area->ignoreBgList() ? "ignored." : "enforced.";
sendServerMessage("BG list in this area is now " + l_state);
@ -381,7 +388,7 @@ void AOClient::cmdIgnoreBgList(int argc, QStringList argv)
void AOClient::cmdAreaMessage(int argc, QStringList argv)
{
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (argc == 0) {
sendServerMessage(l_area->areaMessage());
return;
@ -398,7 +405,7 @@ void AOClient::cmdToggleAreaMessageOnJoin(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->toggleAreaMessageJoin();
QString l_state = l_area->sendAreaMessageOnJoin() ? "enabled." : "disabled.";
sendServerMessage("Sending message on area join is now " + l_state);
@ -409,8 +416,8 @@ void AOClient::cmdClearAreaMessage(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
l_area->changeAreaMessage(QString{});
AreaData *l_area = server->getAreaById(m_current_area);
l_area->clearAreaMessage();
if (l_area->sendAreaMessageOnJoin()) // Turn off the automatic sending.
cmdToggleAreaMessageOnJoin(0, QStringList{}); // Dummy values.
}

View File

@ -17,6 +17,10 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/config_manager.h"
#include "include/db_manager.h"
#include "include/server.h"
// This file is for commands under the authentication category in aoclient.h
// Be sure to register the command in the header before adding it here!
@ -86,7 +90,7 @@ void AOClient::cmdSetRootPass(int argc, QStringList argv)
#endif
QString l_salt = QStringLiteral("%1").arg(l_salt_number, 16, 16, QLatin1Char('0'));
server->db_manager->createUser("root", l_salt, argv[0], ACLFlags.value("SUPER"));
server->getDatabaseManager()->createUser("root", l_salt, argv[0], ACLFlags.value("SUPER"));
}
void AOClient::cmdAddUser(int argc, QStringList argv)
@ -107,7 +111,7 @@ void AOClient::cmdAddUser(int argc, QStringList argv)
#endif
QString l_salt = QStringLiteral("%1").arg(l_salt_number, 16, 16, QLatin1Char('0'));
if (server->db_manager->createUser(argv[0], l_salt, argv[1], ACLFlags.value("NONE")))
if (server->getDatabaseManager()->createUser(argv[0], l_salt, argv[1], ACLFlags.value("NONE")))
sendServerMessage("Created user " + argv[0] + ".\nUse /addperm to modify their permissions.");
else
sendServerMessage("Unable to create user " + argv[0] + ".\nDoes a user with that name already exist?");
@ -117,7 +121,7 @@ void AOClient::cmdRemoveUser(int argc, QStringList argv)
{
Q_UNUSED(argc);
if (server->db_manager->deleteUser(argv[0]))
if (server->getDatabaseManager()->deleteUser(argv[0]))
sendServerMessage("Successfully removed user " + argv[0] + ".");
else
sendServerMessage("Unable to remove user " + argv[0] + ".\nDoes it exist?");
@ -125,19 +129,21 @@ void AOClient::cmdRemoveUser(int argc, QStringList argv)
void AOClient::cmdListPerms(int argc, QStringList argv)
{
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
unsigned long long l_user_acl = server->getDatabaseManager()->getACL(m_moderator_name);
QStringList l_message;
const QStringList l_keys = ACLFlags.keys();
if (argc == 0) {
// Just print out all permissions available to the user.
l_message.append("You have been given the following permissions:");
for (const QString &l_perm : l_keys) {
if (l_perm == "NONE"); // don't need to list this one
if (l_perm == "NONE")
; // don't need to list this one
else if (l_perm == "SUPER") {
if (l_user_acl == ACLFlags.value("SUPER")) // This has to be checked separately, because SUPER & anything will always be truthy
l_message.append("SUPER (Be careful! This grants the user all permissions.)");
}
else if ((ACLFlags.value(l_perm) & l_user_acl) == 0); // user doesn't have this permission, don't print it
else if ((ACLFlags.value(l_perm) & l_user_acl) == 0)
; // user doesn't have this permission, don't print it
else
l_message.append(l_perm);
}
@ -149,7 +155,7 @@ void AOClient::cmdListPerms(int argc, QStringList argv)
}
l_message.append("User " + argv[0] + " has the following permissions:");
unsigned long long l_acl = server->db_manager->getACL(argv[0]);
unsigned long long l_acl = server->getDatabaseManager()->getACL(argv[0]);
if (l_acl == 0) {
sendServerMessage("This user either doesn't exist, or has no permissions set.");
return;
@ -168,7 +174,7 @@ void AOClient::cmdAddPerms(int argc, QStringList argv)
{
Q_UNUSED(argc);
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
unsigned long long l_user_acl = server->getDatabaseManager()->getACL(m_moderator_name);
argv[1] = argv[1].toUpper();
const QStringList l_keys = ACLFlags.keys();
@ -191,7 +197,7 @@ void AOClient::cmdAddPerms(int argc, QStringList argv)
unsigned long long l_newperm = ACLFlags.value(argv[1]);
if ((l_newperm & l_user_acl) != 0) {
if (server->db_manager->updateACL(argv[0], l_newperm, true))
if (server->getDatabaseManager()->updateACL(argv[0], l_newperm, true))
sendServerMessage("Successfully added permission " + argv[1] + " to user " + argv[0]);
else
sendServerMessage(argv[0] + " wasn't found!");
@ -205,7 +211,7 @@ void AOClient::cmdRemovePerms(int argc, QStringList argv)
{
Q_UNUSED(argc);
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
unsigned long long l_user_acl = server->getDatabaseManager()->getACL(m_moderator_name);
argv[1] = argv[1].toUpper();
const QStringList l_keys = ACLFlags.keys();
@ -234,7 +240,7 @@ void AOClient::cmdRemovePerms(int argc, QStringList argv)
unsigned long long l_newperm = ACLFlags.value(argv[1]);
if ((l_newperm & l_user_acl) != 0) {
if (server->db_manager->updateACL(argv[0], l_newperm, false))
if (server->getDatabaseManager()->updateACL(argv[0], l_newperm, false))
sendServerMessage("Successfully removed permission " + argv[1] + " from user " + argv[0]);
else
sendServerMessage(argv[0] + " wasn't found!");
@ -249,7 +255,7 @@ void AOClient::cmdListUsers(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QStringList l_users = server->db_manager->getUsers();
QStringList l_users = server->getDatabaseManager()->getUsers();
sendServerMessage("All users:\n" + l_users.join("\n"));
}
@ -291,7 +297,7 @@ void AOClient::cmdChangePassword(int argc, QStringList argv)
return;
}
if (server->db_manager->updatePassword(l_username, l_password)) {
if (server->getDatabaseManager()->updatePassword(l_username, l_password)) {
sendServerMessage("Successfully changed password.");
}
else {

View File

@ -17,13 +17,18 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/server.h"
// This file is for commands under the casing category in aoclient.h
// Be sure to register the command in the header before adding it here!
void AOClient::cmdDoc(int argc, QStringList argv)
{
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (argc == 0) {
sendServerMessage("Document: " + l_area->document());
}
@ -39,7 +44,7 @@ void AOClient::cmdClearDoc(int argc, QStringList argv)
Q_UNUSED(argv);
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->changeDoc("No document.");
sendServerMessageArea(l_sender_name + " cleared the document.");
}
@ -48,7 +53,7 @@ void AOClient::cmdEvidenceMod(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
argv[0] = argv[0].toLower();
if (argv[0] == "cm")
l_area->setEviMod(AreaData::EvidenceMod::CM);
@ -72,7 +77,7 @@ void AOClient::cmdEvidence_Swap(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
int l_ev_size = l_area->evidence().size() - 1;
if (l_ev_size < 0) {
@ -106,7 +111,7 @@ void AOClient::cmdTestify(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING) {
sendServerMessage("Testimony recording is already in progress. Please stop it before starting a new one.");
}
@ -122,9 +127,8 @@ void AOClient::cmdExamine(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->testimony().size() -1 > 0)
{
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->testimony().size() - 1 > 0) {
l_area->restartTestimony();
server->broadcast(AOPacket("RT", {"testimony2"}), m_current_area);
server->broadcast(AOPacket("MS", {l_area->testimony()[0]}), m_current_area);
@ -141,15 +145,14 @@ void AOClient::cmdTestimony(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->testimony().size() - 1 < 1) {
sendServerMessage("Unable to display empty testimony.");
return;
}
QString l_ooc_message;
for (int i = 1; i <= l_area->testimony().size() -1; i++)
{
for (int i = 1; i <= l_area->testimony().size() - 1; i++) {
QStringList l_packet = l_area->testimony().at(i);
QString l_ic_message = l_packet[4];
l_ooc_message.append("[" + QString::number(i) + "]" + l_ic_message + "\n");
@ -162,7 +165,7 @@ void AOClient::cmdDeleteStatement(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
int l_c_statement = l_area->statement();
if (l_area->testimony().size() - 1 == 0) {
sendServerMessage("Unable to delete statement. No statements saved in this area.");
@ -178,7 +181,7 @@ void AOClient::cmdUpdateStatement(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
server->m_areas[m_current_area]->setTestimonyRecording(AreaData::TestimonyRecording::UPDATE);
server->getAreaById(m_current_area)->setTestimonyRecording(AreaData::TestimonyRecording::UPDATE);
sendServerMessage("The next IC-Message will replace the last displayed replay message.");
}
@ -187,7 +190,7 @@ void AOClient::cmdPauseTestimony(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->setTestimonyRecording(AreaData::TestimonyRecording::STOPPED);
server->broadcast(AOPacket("RT", {"testimony1", "1"}), m_current_area);
sendServerMessage("Testimony has been stopped.");
@ -198,8 +201,8 @@ void AOClient::cmdAddStatement(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
if (server->m_areas[m_current_area]->statement() < ConfigManager::maxStatements()) {
server->m_areas[m_current_area]->setTestimonyRecording(AreaData::TestimonyRecording::ADD);
if (server->getAreaById(m_current_area)->statement() < ConfigManager::maxStatements()) {
server->getAreaById(m_current_area)->setTestimonyRecording(AreaData::TestimonyRecording::ADD);
sendServerMessage("The next IC-Message will be inserted into the testimony.");
}
else
@ -218,7 +221,7 @@ void AOClient::cmdSaveTestimony(int argc, QStringList argv)
l_permission_found = true;
if (l_permission_found) {
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (l_area->testimony().size() - 1 <= 0) {
sendServerMessage("Can't save an empty testimony.");
return;
@ -239,8 +242,7 @@ void AOClient::cmdSaveTestimony(int argc, QStringList argv)
QTextStream l_out(&l_file);
l_out.setCodec("UTF-8");
if (l_file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
for (int i = 0; i <= l_area->testimony().size() -1; i++)
{
for (int i = 0; i <= l_area->testimony().size() - 1; i++) {
l_out << l_area->testimony().at(i).join("#") << "\n";
}
sendServerMessage("Testimony saved. To load it use /loadtestimony " + l_testimony_name);
@ -257,7 +259,7 @@ void AOClient::cmdLoadTestimony(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
QDir l_dir_testimony("storage/testimony");
if (!l_dir_testimony.exists()) {
sendServerMessage("Unable to load testimonies. Testimony storage not found.");

View File

@ -17,6 +17,11 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/server.h"
// This file is for functions used by various commands, defined in the command helper function category in aoclient.h
// Be sure to register the command in the header before adding it here!
@ -32,8 +37,8 @@ void AOClient::cmdDefault(int argc, QStringList argv)
QStringList AOClient::buildAreaList(int area_idx)
{
QStringList entries;
QString area_name = server->m_area_names[area_idx];
AreaData* area = server->m_areas[area_idx];
QString area_name = server->getAreaName(area_idx);
AreaData *area = server->getAreaById(area_idx);
entries.append("=== " + area_name + " ===");
switch (area->lockStatus()) {
case AreaData::LockStatus::LOCKED:
@ -47,18 +52,19 @@ QStringList AOClient::buildAreaList(int area_idx)
break;
}
entries.append("[" + QString::number(area->playerCount()) + " users][" + QVariant::fromValue(area->status()).toString().replace("_", "-") + "]");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->m_current_area == area_idx && client->m_joined) {
QString char_entry = "[" + QString::number(client->m_id) + "] " + client->m_current_char;
if (client->m_current_char == "")
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_current_area == area_idx && l_client->hasJoined()) {
QString char_entry = "[" + QString::number(l_client->m_id) + "] " + l_client->m_current_char;
if (l_client->m_current_char == "")
char_entry += "Spectator";
if (client->m_showname != "")
char_entry += " (" + client->m_showname + ")";
if (area->owners().contains(client->m_id))
if (l_client->m_showname != "")
char_entry += " (" + l_client->m_showname + ")";
if (area->owners().contains(l_client->m_id))
char_entry.insert(0, "[CM] ");
if (m_authenticated)
char_entry += " (" + client->getIpid() + "): " + client->m_ooc_name;
if (client->m_is_afk)
char_entry += " (" + l_client->getIpid() + "): " + l_client->m_ooc_name;
if (l_client->m_is_afk)
char_entry += " [AFK]";
entries.append(char_entry);
}
@ -100,7 +106,7 @@ void AOClient::diceThrower(int argc, QStringList argv, bool p_roll)
QString AOClient::getAreaTimer(int area_idx, int timer_idx)
{
AreaData* l_area = server->m_areas[area_idx];
AreaData *l_area = server->getAreaById(area_idx);
QTimer *l_timer;
QString l_timer_name = (timer_idx == 0) ? "Global timer" : "Timer " + QString::number(timer_idx);

View File

@ -17,6 +17,10 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/server.h"
// This file is for commands under the messaging category in aoclient.h
// Be sure to register the command in the header before adding it here!
@ -25,7 +29,7 @@ void AOClient::cmdPos(int argc, QStringList argv)
Q_UNUSED(argc);
changePosition(argv[0]);
updateEvidenceList(server->m_areas[m_current_area]);
updateEvidenceList(server->getAreaById(m_current_area));
}
void AOClient::cmdForcePos(int argc, QStringList argv)
@ -51,9 +55,10 @@ void AOClient::cmdForcePos(int argc, QStringList argv)
}
else if (argv[1] == "*") { // force all clients in the area
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->m_current_area == m_current_area)
l_targets.append(client);
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_current_area == m_current_area)
l_targets.append(l_client);
}
}
for (AOClient *l_target : l_targets) {
@ -69,7 +74,7 @@ void AOClient::cmdG(int argc, QStringList argv)
Q_UNUSED(argc);
QString l_sender_name = m_ooc_name;
QString l_sender_area = server->m_area_names.value(m_current_area);
QString l_sender_area = server->getAreaName(m_current_area);
QString l_sender_message = argv.join(" ");
//Slightly better readability
AOPacket l_mod_packet = AOPacket("CT", {"[G][" + m_ipid + "][" + l_sender_area + "]" + l_sender_name, l_sender_message});
@ -82,7 +87,7 @@ void AOClient::cmdNeed(int argc, QStringList argv)
{
Q_UNUSED(argc);
QString l_sender_area = server->m_area_names.value(m_current_area);
QString l_sender_area = server->getAreaName(m_current_area);
QString l_sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"=== Advert ===\n[" + l_sender_area + "] needs " + l_sender_message + "."}), Server::TARGET_TYPE::ADVERT);
}
@ -109,11 +114,11 @@ void AOClient::cmdRandomChar(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
int l_selected_char_id;
bool l_taken = true;
while (l_taken) {
l_selected_char_id = genRand(0, server->m_characters.size() - 1);
l_selected_char_id = genRand(0, server->getCharacterCount() - 1);
if (!l_area->charactersTaken().contains(l_selected_char_id)) {
l_taken = false;
}
@ -178,7 +183,7 @@ void AOClient::cmdGM(int argc, QStringList argv)
Q_UNUSED(argc);
QString l_sender_name = m_ooc_name;
QString l_sender_area = server->m_area_names.value(m_current_area);
QString l_sender_area = server->getAreaName(m_current_area);
QString l_sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"[G][" + l_sender_area + "]" + "[" + l_sender_name + "][M]", l_sender_message}), Server::TARGET_TYPE::MODCHAT);
}
@ -427,11 +432,11 @@ void AOClient::cmdCharCurse(int argc, QStringList argv)
// Kick back to char select screen
if (!l_target->m_charcurse_list.contains(server->getCharID(l_target->m_current_char))) {
l_target->changeCharacter(-1);
server->updateCharsTaken(server->m_areas.value(m_current_area));
server->updateCharsTaken(server->getAreaById(m_current_area));
l_target->sendPacket("DONE");
}
else {
server->updateCharsTaken(server->m_areas.value(m_current_area));
server->updateCharsTaken(server->getAreaById(m_current_area));
}
l_target->sendServerMessage("You have been charcursed!");
@ -462,7 +467,7 @@ void AOClient::cmdUnCharCurse(int argc, QStringList argv)
}
l_target->m_is_charcursed = false;
l_target->m_charcurse_list.clear();
server->updateCharsTaken(server->m_areas.value(m_current_area));
server->updateCharsTaken(server->getAreaById(m_current_area));
sendServerMessage("Uncharcursed player.");
l_target->sendServerMessage("You were uncharcursed.");
}
@ -496,7 +501,6 @@ void AOClient::cmdCharSelect(int argc, QStringList argv)
l_target->changeCharacter(-1);
l_target->sendPacket("DONE");
sendServerMessage("Client has been forced into character select!");
}
}
@ -511,7 +515,7 @@ void AOClient::cmdA(int argc, QStringList argv)
return;
}
AreaData* l_area = server->m_areas[l_area_id];
AreaData *l_area = server->getAreaById(l_area_id);
if (!l_area->owners().contains(m_id)) {
sendServerMessage("You are not CM in that area.");
return;
@ -527,12 +531,12 @@ void AOClient::cmdS(int argc, QStringList argv)
{
Q_UNUSED(argc);
int l_all_areas = server->m_areas.size() - 1;
int l_all_areas = server->getAreaCount() - 1;
QString l_sender_name = m_ooc_name;
QString l_ooc_message = argv.join(" ");
for (int i = 0; i <= l_all_areas; i++) {
if (server->m_areas[i]->owners().contains(m_id))
if (server->getAreaById(i)->owners().contains(m_id))
server->broadcast(AOPacket("CT", {"[CM]" + l_sender_name, l_ooc_message}), i);
}
}

View File

@ -17,6 +17,11 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/db_manager.h"
#include "include/server.h"
// This file is for commands under the moderation category in aoclient.h
// Be sure to register the command in the header before adding it here!
@ -58,11 +63,11 @@ void AOClient::cmdBan(int argc, QStringList argv)
}
const QList<AOClient *> l_targets = server->getClientsByIpid(l_ban.ipid);
for (AOClient* client : l_targets) {
for (AOClient *l_client : l_targets) {
if (!l_ban_logged) {
l_ban.ip = client->m_remote_ip;
l_ban.hdid = client->m_hwid;
server->db_manager->addBan(l_ban);
l_ban.ip = l_client->m_remote_ip;
l_ban.hdid = l_client->m_hwid;
server->getDatabaseManager()->addBan(l_ban);
sendServerMessage("Banned user with ipid " + l_ban.ipid + " for reason: " + l_ban.reason);
l_ban_logged = true;
}
@ -73,9 +78,9 @@ void AOClient::cmdBan(int argc, QStringList argv)
else {
l_ban_duration = "The heat death of the universe.";
}
int l_ban_id = server->db_manager->getBanID(l_ban.ip);
client->sendPacket("KB", {l_ban.reason + "\nID: " + QString::number(l_ban_id) + "\nUntil: " + l_ban_duration});
client->m_socket->close();
int l_ban_id = server->getDatabaseManager()->getBanID(l_ban.ip);
l_client->sendPacket("KB", {l_ban.reason + "\nID: " + QString::number(l_ban_id) + "\nUntil: " + l_ban_duration});
l_client->m_socket->close();
l_kick_counter++;
emit logBan(l_ban.moderator, l_ban.ipid, l_ban_duration, l_ban.reason);
@ -88,7 +93,7 @@ void AOClient::cmdBan(int argc, QStringList argv)
// We're banning someone not connected.
if (!l_ban_logged) {
server->db_manager->addBan(l_ban);
server->getDatabaseManager()->addBan(l_ban);
sendServerMessage("Banned " + l_ban.ipid + " for reason: " + l_ban.reason);
}
}
@ -106,9 +111,9 @@ void AOClient::cmdKick(int argc, QStringList argv)
}
const QList<AOClient *> l_targets = server->getClientsByIpid(l_target_ipid);
for (AOClient* client : l_targets) {
client->sendPacket("KK", {l_reason});
client->m_socket->close();
for (AOClient *l_client : l_targets) {
l_client->sendPacket("KK", {l_reason});
l_client->m_socket->close();
l_kick_counter++;
}
@ -132,7 +137,8 @@ void AOClient::cmdMods(int argc, QStringList argv)
QStringList l_entries;
int l_online_count = 0;
for (AOClient* l_client : qAsConst(server->m_clients)) {
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_authenticated) {
l_entries << "---";
if (ConfigManager::authType() != DataTypes::AuthType::SIMPLE)
@ -206,7 +212,7 @@ void AOClient::cmdBans(int argc, QStringList argv)
QStringList l_recent_bans;
l_recent_bans << "Last 5 bans:";
l_recent_bans << "-----";
const QList<DBManager::BanInfo> l_bans_list = server->db_manager->getRecentBans();
const QList<DBManager::BanInfo> l_bans_list = server->getDatabaseManager()->getRecentBans();
for (const DBManager::BanInfo &l_ban : l_bans_list) {
QString l_banned_until;
if (l_ban.duration == -2)
@ -235,7 +241,7 @@ void AOClient::cmdUnBan(int argc, QStringList argv)
sendServerMessage("Invalid ban ID.");
return;
}
else if (server->db_manager->invalidateBan(l_target_ban))
else if (server->getDatabaseManager()->invalidateBan(l_target_ban))
sendServerMessage("Successfully invalidated ban " + argv[0] + ".");
else
sendServerMessage("Couldn't invalidate ban " + argv[0] + ", are you sure it exists?");
@ -417,7 +423,7 @@ void AOClient::cmdAllowBlankposting(int argc, QStringList argv)
Q_UNUSED(argv);
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->toggleBlankposting();
if (l_area->blankpostingAllowed() == false) {
sendServerMessageArea(l_sender_name + " has set blankposting in the area to forbidden.");
@ -449,7 +455,7 @@ void AOClient::cmdBanInfo(int argc, QStringList argv)
return;
}
QString l_id = argv[0];
const QList<DBManager::BanInfo> l_bans = server->db_manager->getBanInfo(l_lookup_type, l_id);
const QList<DBManager::BanInfo> l_bans = server->getDatabaseManager()->getBanInfo(l_lookup_type, l_id);
for (const DBManager::BanInfo &l_ban : l_bans) {
QString l_banned_until;
if (l_ban.duration == -2)
@ -483,7 +489,7 @@ void AOClient::cmdForceImmediate(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->toggleImmediate();
QString l_state = l_area->forceImmediate() ? "on." : "off.";
sendServerMessage("Forced immediate text processing in this area is now " + l_state);
@ -494,7 +500,7 @@ void AOClient::cmdAllowIniswap(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->toggleIniswap();
QString state = l_area->iniswapAllowed() ? "allowed." : "disallowed.";
sendServerMessage("Iniswapping in this area is now " + state);
@ -560,7 +566,6 @@ void AOClient::cmdUpdateBan(int argc, QStringList argv)
return;
}
l_updated_info = QVariant(l_duration_seconds);
}
else if (argv[1] == "reason") {
QString l_args_str = argv[2];
@ -574,7 +579,7 @@ void AOClient::cmdUpdateBan(int argc, QStringList argv)
sendServerMessage("Invalid update type.");
return;
}
if (!server->db_manager->updateBan(l_ban_id, argv[1], l_updated_info)) {
if (!server->getDatabaseManager()->updateBan(l_ban_id, argv[1], l_updated_info)) {
sendServerMessage("There was an error updating the ban. Please confirm the ban ID is valid.");
return;
}
@ -599,7 +604,7 @@ void AOClient::cmdClearCM(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas.value(m_current_area);
AreaData *l_area = server->getAreaById(m_current_area);
foreach (int l_client_id, l_area->owners()) {
l_area->removeOwner(l_client_id);
}

View File

@ -16,6 +16,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/music_manager.h"
#include "include/server.h"
// This file is for commands under the music category in aoclient.h
// Be sure to register the command in the header before adding it here!
@ -27,7 +33,7 @@ void AOClient::cmdPlay(int argc, QStringList argv)
sendServerMessage("You are blocked from changing the music.");
return;
}
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
QString l_song = argv.join(" ");
if (m_showname.isEmpty()) {
l_area->changeMusic(m_current_char, l_song);
@ -44,7 +50,7 @@ void AOClient::cmdCurrentMusic(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (!l_area->currentMusic().isEmpty() && !l_area->currentMusic().contains("~stop.mp3")) // dummy track for stopping music
sendServerMessage("The current song is " + l_area->currentMusic() + " played by " + l_area->musicPlayerBy());
else
@ -110,7 +116,7 @@ void AOClient::cmdToggleMusic(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
l_area->toggleMusic();
QString l_state = l_area->isMusicAllowed() ? "allowed." : "disallowed.";
sendServerMessage("Music in this area is now " + l_state);
@ -122,7 +128,7 @@ void AOClient::cmdToggleJukebox(int argc, QStringList argv)
Q_UNUSED(argv);
if (checkAuth(ACLFlags.value("CM")) | checkAuth(ACLFlags.value("Jukebox"))) {
AreaData* l_area = server->m_areas.value(m_current_area);
AreaData *l_area = server->getAreaById(m_current_area);
l_area->toggleJukebox();
QString l_state = l_area->isjukeboxEnabled() ? "enabled." : "disabled.";
sendServerMessageArea("The jukebox in this area has been " + l_state);

View File

@ -17,6 +17,11 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/server.h"
// This file is for commands under the roleplay category in aoclient.h
// Be sure to register the command in the header before adding it here!
@ -43,7 +48,7 @@ void AOClient::cmdRollP(int argc, QStringList argv)
void AOClient::cmdTimer(int argc, QStringList argv)
{
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
// Called without arguments
// Shows a brief of all timers
@ -134,7 +139,7 @@ void AOClient::cmdNoteCard(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
QString l_notecard = argv.join(" ");
l_area->addNotecard(m_current_char, l_notecard);
sendServerMessageArea(m_current_char + " wrote a note card.");
@ -145,7 +150,7 @@ void AOClient::cmdNoteCardClear(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
if (!l_area->addNotecard(m_current_char, QString())) {
sendServerMessageArea(m_current_char + " erased their note card.");
}
@ -156,7 +161,7 @@ void AOClient::cmdNoteCardReveal(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
AreaData *l_area = server->getAreaById(m_current_area);
const QStringList l_notecards = l_area->getNotecards();
if (l_notecards.isEmpty()) {
@ -192,7 +197,8 @@ void AOClient::cmdSubTheme(int argc, QStringList argv)
Q_UNUSED(argc);
QString l_subtheme = argv.join(" ");
for (AOClient* l_client : qAsConst(server->m_clients)) {
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_current_area == m_current_area)
l_client->sendPacket("ST", {l_subtheme, "1"});
}

View File

@ -94,6 +94,8 @@ bool ConfigManager::verifyServerConfig()
m_commands->reprimands = (loadConfigFile("reprimands"));
m_commands->gimps = (loadConfigFile("gimp"));
m_commands->cdns = (loadConfigFile("cdns"));
if (m_commands->cdns.isEmpty())
m_commands->cdns = QStringList{"cdn.discord.com"};
m_uptimeTimer->start();

View File

@ -59,9 +59,11 @@ QPair<bool, QString> DBManager::isIPBanned(QString ipid)
long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch();
if (ban_time + duration > current_time)
return {true, reason};
else return {false, nullptr};
else
return {false, nullptr};
}
else return {false, nullptr};
else
return {false, nullptr};
}
QPair<bool, QString> DBManager::isHDIDBanned(QString hdid)
@ -79,9 +81,11 @@ QPair<bool, QString> DBManager::isHDIDBanned(QString hdid)
long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch();
if (ban_time + duration > current_time)
return {true, reason};
else return {false, nullptr};
else
return {false, nullptr};
}
else return {false, nullptr};
else
return {false, nullptr};
}
int DBManager::getBanID(QString hdid)
@ -98,7 +102,6 @@ int DBManager::getBanID(QString hdid)
}
}
int DBManager::getBanID(QHostAddress ip)
{
QSqlQuery query;

View File

@ -17,6 +17,8 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/discord.h"
#include "include/config_manager.h"
Discord::Discord(QObject *parent) :
QObject(parent)
{
@ -68,15 +70,13 @@ QJsonDocument Discord::constructModcallJson(const QString &f_name, const QString
QJsonObject l_object{
{"color", ConfigManager::discordWebhookColor()},
{"title", f_name + " filed a modcall in " + f_area},
{"description", f_reason}
};
{"description", f_reason}};
l_array.append(l_object);
if (!ConfigManager::discordModcallWebhookContent().isEmpty())
l_json["content"] = ConfigManager::discordModcallWebhookContent();
l_json["embeds"] = l_array;
return QJsonDocument(l_json);
}
@ -87,8 +87,7 @@ QJsonDocument Discord::constructBanJson(const QString &f_ipid, const QString &f_
QJsonObject l_object{
{"color", ConfigManager::discordWebhookColor()},
{"title", "Ban issued by " + f_moderator},
{"description", "Client IPID : " + f_ipid + "\nBan ID: " + QString::number(f_banID) + "\nBan reason : " + f_reason +"\nBanned until : " +f_duration}
};
{"description", "Client IPID : " + f_ipid + "\nBan ID: " + QString::number(f_banID) + "\nBan reason : " + f_reason + "\nBanned until : " + f_duration}};
l_array.append(l_object);
l_json["embeds"] = l_array;
@ -102,8 +101,7 @@ QJsonDocument Discord::constructUptimeJson(const QString& f_timeExpired)
QJsonObject l_object{
{"color", ConfigManager::discordWebhookColor()},
{"title", "Your server is online!"},
{"description", "Your server has been online for " + f_timeExpired}
};
{"description", "Your server has been online for " + f_timeExpired}};
l_array.append(l_object);
l_json["embeds"] = l_array;

View File

@ -47,4 +47,3 @@ void WriterFull::flush(const QString f_entry, const QString f_area_name)
}
l_logfile.close();
};

View File

@ -43,5 +43,4 @@ void WriterModcall::flush(const QString f_area_name, QQueue<QString> f_buffer)
}
l_logfile.close();
};

View File

@ -1,6 +1,9 @@
#include "include/music_manager.h"
MusicManager::MusicManager(QObject *parent, QStringList f_root_ordered, QStringList f_cdns, QMap<QString, QPair<QString, int>> f_root_list) :
#include "include/aopacket.h"
#include "include/config_manager.h"
MusicManager::MusicManager(QStringList f_root_ordered, QStringList f_cdns, QMap<QString, QPair<QString, int>> f_root_list, QObject *parent) :
QObject(parent),
m_root_list(f_root_list),
m_root_ordered(f_root_ordered)
@ -13,7 +16,6 @@ MusicManager::MusicManager(QObject *parent, QStringList f_root_ordered, QStringL
MusicManager::~MusicManager()
{
}
QStringList MusicManager::musiclist(int f_area_id)
@ -53,8 +55,7 @@ bool MusicManager::validateSong(QString f_song_name, QStringList f_approved_cdns
if (f_song_name.startsWith("https://") || f_song_name.startsWith("http://")) {
for (const QString &l_cdn : qAsConst(f_approved_cdns)) {
// Iterate trough all available CDNs to find an approved match
if (f_song_name.startsWith("https://" + l_cdn + "/", Qt::CaseInsensitive)
|| f_song_name.startsWith("http://" + l_cdn + "/", Qt::CaseInsensitive)) {
if (f_song_name.startsWith("https://" + l_cdn + "/", Qt::CaseInsensitive) || f_song_name.startsWith("http://" + l_cdn + "/", Qt::CaseInsensitive)) {
l_cdn_approved = true;
break;
}
@ -68,7 +69,8 @@ bool MusicManager::validateSong(QString f_song_name, QStringList f_approved_cdns
}
}
bool l_suffix_found = false;;
bool l_suffix_found = false;
;
for (const QString &suffix : qAsConst(l_extensions)) {
if (f_song_name.endsWith(suffix)) {
l_suffix_found = true;
@ -185,8 +187,8 @@ void MusicManager::sanitiseCustomList(int f_area_id)
MusicList l_sanitised_list;
QStringList l_sanitised_ordered = m_customs_ordered.value(f_area_id);
for (auto iterator = m_custom_lists->value(f_area_id).keyBegin(),
end = m_custom_lists->value(f_area_id).keyEnd(); iterator != end; ++iterator)
{
end = m_custom_lists->value(f_area_id).keyEnd();
iterator != end; ++iterator) {
QString l_key = iterator.operator*();
if (!m_root_list.contains(l_key)) {
l_sanitised_list.insert(l_key, m_custom_lists->value(f_area_id).value(l_key));
@ -194,7 +196,6 @@ void MusicManager::sanitiseCustomList(int f_area_id)
else {
l_sanitised_ordered.removeAll(l_key);
}
}
m_custom_lists->insert(f_area_id, l_sanitised_list);
m_customs_ordered.insert(f_area_id, l_sanitised_ordered);

View File

@ -17,6 +17,15 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include <QQueue>
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/db_manager.h"
#include "include/music_manager.h"
#include "include/server.h"
void AOClient::pktDefault(AreaData *area, int argc, QStringList argv, AOPacket packet)
{
Q_UNUSED(area);
@ -37,9 +46,9 @@ void AOClient::pktHardwareId(AreaData* area, int argc, QStringList argv, AOPacke
m_hwid = argv[0];
emit server->logConnectionAttempt(m_remote_ip.toString(), m_ipid, m_hwid);
auto l_ban = server->db_manager->isHDIDBanned(m_hwid);
auto l_ban = server->getDatabaseManager()->isHDIDBanned(m_hwid);
if (l_ban.first) {
sendPacket("BD", {l_ban.second + "\nBan ID: " + QString::number(server->db_manager->getBanID(m_hwid))});
sendPacket("BD", {l_ban.second + "\nBan ID: " + QString::number(server->getDatabaseManager()->getBanID(m_hwid))});
m_socket->close();
return;
}
@ -61,9 +70,7 @@ void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacke
"deskmod", "evidence", "cccc_ic_support",
"arup", "casing_alerts", "modcall_reason",
"looping_sfx", "additive", "effects",
"y_offset", "expanded_desk_mods", "auth_packet"
};
"y_offset", "expanded_desk_mods", "auth_packet"};
m_version.string = argv[1];
QRegularExpression rx("\\b(\\d+)\\.(\\d+)\\.(\\d+)\\b"); // matches X.X.X (e.g. 2.9.0, 2.4.10, etc.)
@ -74,7 +81,7 @@ void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacke
m_version.minor = l_match.captured(3).toInt();
}
sendPacket("PN", {QString::number(server->m_player_count), QString::number(ConfigManager::maxPlayers()), ConfigManager::serverDescription()});
sendPacket("PN", {QString::number(server->getPlayerCount()), QString::number(ConfigManager::maxPlayers()), ConfigManager::serverDescription()});
sendPacket("FL", l_feature_list);
if (ConfigManager::assetUrl().isValid()) {
@ -93,7 +100,7 @@ void AOClient::pktBeginLoad(AreaData* area, int argc, QStringList argv, AOPacket
// Evidence isn't loaded during this part anymore
// As a result, we can always send "0" for evidence length
// Client only cares about what it gets from LE
sendPacket("SI", {QString::number(server->m_characters.length()), "0", QString::number(server->m_area_names.length() + server->m_music_list.length())});
sendPacket("SI", {QString::number(server->getCharacterCount()), "0", QString::number(server->getAreaCount() + server->getMusicList().length())});
}
void AOClient::pktRequestChars(AreaData *area, int argc, QStringList argv, AOPacket packet)
@ -103,7 +110,7 @@ void AOClient::pktRequestChars(AreaData* area, int argc, QStringList argv, AOPac
Q_UNUSED(argv);
Q_UNUSED(packet);
sendPacket("SC", server->m_characters);
sendPacket("SC", server->getCharacters());
}
void AOClient::pktRequestMusic(AreaData *area, int argc, QStringList argv, AOPacket packet)
@ -113,7 +120,7 @@ void AOClient::pktRequestMusic(AreaData* area, int argc, QStringList argv, AOPac
Q_UNUSED(argv);
Q_UNUSED(packet);
sendPacket("SM", server->m_area_names + server->m_music_list);
sendPacket("SM", server->getAreaNames() + server->getMusicList());
}
void AOClient::pktLoadingDone(AreaData *area, int argc, QStringList argv, AOPacket packet)
@ -132,13 +139,12 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack
return;
}
server->m_player_count++;
m_joined = true;
server->updateCharsTaken(area);
sendEvidenceList(area);
sendPacket("HP", {"1", QString::number(area->defHP())});
sendPacket("HP", {"2", QString::number(area->proHP())});
sendPacket("FA", server->m_area_names);
sendPacket("FA", server->getAreaNames());
// Here lies OPPASS, the genius of FanatSors who send the modpass to everyone in plain text.
sendPacket("DONE");
sendPacket("BN", {area->background()});
@ -164,7 +170,7 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack
sendPacket("TI", {QString::number(l_timer_id), "3"});
}
}
emit server->updatePlayerCount(server->m_player_count);
emit joined();
area->clientJoinedArea(-1, m_id);
arup(ARUPType::PLAYER_COUNT, true); // Tell everyone there is a new player
}
@ -204,7 +210,7 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
return;
}
if (!server->can_send_ic_messages) {
if (!server->isMessageAllowed()) {
return;
}
@ -216,11 +222,10 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
validated_packet.contents[5] = m_pos;
server->broadcast(validated_packet, m_current_area);
emit logIC((m_current_char + " " + m_showname), m_ooc_name, m_ipid,server->m_areas[m_current_area]->name(), m_last_message);
emit logIC((m_current_char + " " + m_showname), m_ooc_name, m_ipid, server->getAreaById(m_current_area)->name(), m_last_message);
area->updateLastICMessage(validated_packet.contents);
server->can_send_ic_messages = false;
server->next_message_timer.start(ConfigManager::messageFloodguard());
server->startMessageFloodguard(ConfigManager::messageFloodguard());
}
void AOClient::pktOocChat(AreaData *area, int argc, QStringList argv, AOPacket packet)
@ -263,7 +268,7 @@ void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket p
int l_cmd_argc = l_cmd_argv.length();
handleCommand(l_command, l_cmd_argc, l_cmd_argv);
emit logCMD((m_current_char + " " + m_showname), m_ipid, m_ooc_name, l_command, l_cmd_argv,server->m_areas[m_current_area]->name());
emit logCMD((m_current_char + " " + m_showname), m_ipid, m_ooc_name, l_command, l_cmd_argv, server->getAreaById(m_current_area)->name());
return;
}
else {
@ -297,7 +302,7 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack
// argument is a valid song
QString l_argument = argv[0];
if (server->m_music_list.contains(l_argument) || m_music_manager->isCustom(m_current_area, l_argument) || l_argument == "~stop.mp3") { // ~stop.mp3 is a dummy track used by 2.9+
if (server->getMusicList().contains(l_argument) || m_music_manager->isCustom(m_current_area, l_argument) || l_argument == "~stop.mp3") { // ~stop.mp3 is a dummy track used by 2.9+
// We have a song here
if (m_is_dj_blocked) {
sendServerMessage("You are blocked from changing the music.");
@ -345,8 +350,8 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack
return;
}
for (int i = 0; i < server->m_area_names.length(); i++) {
QString l_area = server->m_area_names[i];
for (int i = 0; i < server->getAreaCount(); i++) {
QString l_area = server->getAreaName(i);
if (l_area == l_argument) {
changeArea(i);
break;
@ -422,7 +427,7 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack
}
calculateIpid();
auto l_ban = server->db_manager->isIPBanned(m_ipid);
auto l_ban = server->getDatabaseManager()->isIPBanned(m_ipid);
if (l_ban.first) {
sendPacket("BD", {l_ban.second});
m_socket->close();
@ -430,7 +435,8 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack
}
int l_multiclient_count = 0;
for (AOClient* l_joined_client : qAsConst(server->m_clients)) {
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_joined_client : l_clients) {
if (m_remote_ip.isEqual(l_joined_client->m_remote_ip))
l_multiclient_count++;
}
@ -460,16 +466,22 @@ void AOClient::pktModCall(AreaData* area, int argc, QStringList argv, AOPacket p
else
l_modcallNotice.append("No reason given.");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->m_authenticated) {
client->sendPacket(AOPacket("ZZ", {l_modcallNotice}));
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_authenticated)
l_client->sendPacket(AOPacket("ZZ", {l_modcallNotice}));
}
}
emit logModcall((m_current_char + " " + m_showname), m_ipid, m_ooc_name, server->m_areas[m_current_area]->name());
emit logModcall((m_current_char + " " + m_showname), m_ipid, m_ooc_name, server->getAreaById(m_current_area)->name());
if (ConfigManager::discordModcallWebhookEnabled())
if (ConfigManager::discordModcallWebhookEnabled()) {
QString l_name = m_ooc_name;
if (m_ooc_name.isEmpty())
l_name = m_current_char;
QString l_areaName = area->name();
emit server->modcallWebhookRequest(l_name, l_areaName, packet.contents[0], server->getAreaBuffer(l_areaName));
}
}
void AOClient::pktAddEvidence(AreaData *area, int argc, QStringList argv, AOPacket packet)
{
@ -564,7 +576,8 @@ void AOClient::pktAnnounceCase(AreaData* area, int argc, QStringList argv, AOPac
#else
QSet<bool> l_needs_set = l_needs_list.toSet();
#endif
for (AOClient* l_client : qAsConst(server->m_clients)) {
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QSet<bool> l_matches(l_client->m_casing_preferences.begin(), l_client->m_casing_preferences.end());
l_matches.intersect(l_needs_set);
@ -586,7 +599,8 @@ void AOClient::pktAnnounceCase(AreaData* area, int argc, QStringList argv, AOPac
void AOClient::sendEvidenceList(AreaData *area)
{
for (AOClient* l_client : qAsConst(server->m_clients)) {
const QVector<AOClient *> l_clients = server->getClients();
for (AOClient *l_client : l_clients) {
if (l_client->m_current_area == m_current_area)
l_client->updateEvidenceList(area);
}
@ -633,7 +647,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
if (m_current_char == "" || !m_joined)
// Spectators cannot use IC
return l_invalid;
AreaData* area = server->m_areas[m_current_area];
AreaData *area = server->getAreaById(m_current_area);
if (area->lockStatus() == AreaData::LockStatus::SPECTATABLE && !area->invited().contains(m_id) && !checkAuth(ACLFlags.value("BYPASS_LOCKS")))
// Non-invited players cannot speak in spectatable areas
return l_invalid;
@ -645,7 +659,13 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
// desk modifier
QStringList allowed_desk_mods;
allowed_desk_mods << "chat" << "0" << "1" << "2" << "3" << "4" << "5";
allowed_desk_mods << "chat"
<< "0"
<< "1"
<< "2"
<< "3"
<< "4"
<< "5";
if (allowed_desk_mods.contains(l_incoming_args[0].toString())) {
l_args.append(l_incoming_args[0].toString());
}
@ -660,7 +680,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
// Selected char is different from supplied folder name
// This means the user is INI-swapped
if (!area->iniswapAllowed()) {
if (!server->m_characters.contains(l_incoming_args[2].toString(), Qt::CaseInsensitive))
if (!server->getCharacters().contains(l_incoming_args[2].toString(), Qt::CaseInsensitive))
return l_invalid;
}
qDebug() << "INI swap detected from " << getIpid();
@ -679,9 +699,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
return l_invalid;
QString l_incoming_msg = dezalgo(l_incoming_args[4].toString().trimmed());
if (!area->lastICMessage().isEmpty()
&& l_incoming_msg == area->lastICMessage()[4]
&& l_incoming_msg != "")
if (!area->lastICMessage().isEmpty() && l_incoming_msg == area->lastICMessage()[4] && l_incoming_msg != "")
return l_invalid;
if (l_incoming_msg == "" && area->blankpostingAllowed() == false) {
@ -713,7 +731,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
l_args.append(l_incoming_args[5].toString());
if (m_pos != l_incoming_args[5].toString()) {
m_pos = l_incoming_args[5].toString();
updateEvidenceList(server->m_areas[m_current_area]);
updateEvidenceList(server->getAreaById(m_current_area));
}
// sfx name
@ -815,10 +833,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
QString l_other_flip = "0";
for (int l_client_id : area->joinedIDs()) {
AOClient* l_client = server->getClientByID(l_client_id);
if (l_client->m_pairing_with == m_char_id
&& l_other_charid != m_char_id
&& l_client->m_char_id == m_pairing_with
&& l_client->m_pos == m_pos) {
if (l_client->m_pairing_with == m_char_id && l_other_charid != m_char_id && l_client->m_char_id == m_pairing_with && l_client->m_pos == m_pos) {
l_other_name = l_client->m_current_iniswap;
l_other_emote = l_client->m_emote;
l_other_offset = l_client->m_offset;
@ -956,7 +971,6 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
l_args = l_statement.first;
l_progress = l_statement.second;
switch (l_progress) {
case AreaData::TestimonyProgress::LOOPED:
{
@ -1035,7 +1049,7 @@ void AOClient::loginAttempt(QString message)
sendServerMessage("Incorrect password.");
}
emit logLogin((m_current_char + " " + m_showname), m_ooc_name, "Moderator",
m_ipid, server->m_areas.value(m_current_area)->name(), m_authenticated);
m_ipid, server->getAreaById(m_current_area)->name(), m_authenticated);
break;
case DataTypes::AuthType::ADVANCED:
QStringList l_login = message.split(" ");
@ -1047,7 +1061,7 @@ void AOClient::loginAttempt(QString message)
}
QString username = l_login[0];
QString password = l_login[1];
if (server->db_manager->authenticate(username, password)) {
if (server->getDatabaseManager()->authenticate(username, password)) {
m_moderator_name = username;
m_authenticated = true;
sendPacket("AUTH", {"1"}); // Client: "You were granted the Disable Modcalls button."
@ -1060,11 +1074,10 @@ void AOClient::loginAttempt(QString message)
sendServerMessage("Incorrect password.");
}
emit logLogin((m_current_char + " " + m_showname), m_ooc_name, username, m_ipid,
server->m_areas.value(m_current_area)->name(), m_authenticated);
server->getAreaById(m_current_area)->name(), m_authenticated);
break;
}
sendServerMessage("Exiting login prompt.");
m_is_logging_in = false;
return;
}

View File

@ -17,11 +17,22 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/server.h"
#include "include/advertiser.h"
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/db_manager.h"
#include "include/discord.h"
#include "include/logger/u_logger.h"
#include "include/music_manager.h"
#include "include/ws_proxy.h"
Server::Server(int p_port, int p_ws_port, QObject *parent) :
QObject(parent),
m_player_count(0),
port(p_port),
ws_port(p_ws_port)
ws_port(p_ws_port),
m_player_count(0)
{
server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(clientConnected()));
@ -29,7 +40,7 @@ Server::Server(int p_port, int p_ws_port, QObject* parent) :
proxy = new WSProxy(port, ws_port, this);
if (ws_port != -1)
proxy->start();
timer = new QTimer();
timer = new QTimer(this);
db_manager = new DBManager();
@ -37,8 +48,7 @@ Server::Server(int p_port, int p_ws_port, QObject* parent) :
discord = new Discord(this);
logger = new ULogger(this);
connect(this, &Server::logConnectionAttempt,
logger, &ULogger::logConnectionAttempt);
connect(this, &Server::logConnectionAttempt, logger, &ULogger::logConnectionAttempt);
}
void Server::start()
@ -67,13 +77,10 @@ void Server::start()
AdvertiserTimer = new QTimer(this);
ms3_Advertiser = new Advertiser();
connect(AdvertiserTimer, &QTimer::timeout,
ms3_Advertiser, &Advertiser::msAdvertiseServer);
connect(this, &Server::updatePlayerCount,
ms3_Advertiser, &Advertiser::updatePlayerCount);
connect(this, &Server::updateHTTPConfiguration,
ms3_Advertiser, &Advertiser::updateAdvertiserSettings);
emit updatePlayerCount(m_player_count);
connect(AdvertiserTimer, &QTimer::timeout, ms3_Advertiser, &Advertiser::msAdvertiseServer);
connect(this, &Server::playerCountUpdated, ms3_Advertiser, &Advertiser::updatePlayerCount);
connect(this, &Server::updateHTTPConfiguration, ms3_Advertiser, &Advertiser::updateAdvertiserSettings);
emit playerCountUpdated(m_player_count);
ms3_Advertiser->msAdvertiseServer();
AdvertiserTimer->start(300000);
}
@ -86,11 +93,9 @@ void Server::start()
// Build our music manager.
ConfigManager::musiclist();
music_manager = new MusicManager(this, ConfigManager::ordered_songs(), ConfigManager::cdnList());
connect(music_manager, &MusicManager::sendFMPacket,
this, &Server::unicast);
connect(music_manager, &MusicManager::sendAreaFMPacket,
this, QOverload<AOPacket,int>::of(&Server::broadcast));
music_manager = new MusicManager(ConfigManager::ordered_songs(), ConfigManager::cdnList(), ConfigManager::musiclist(), this);
connect(music_manager, &MusicManager::sendFMPacket, this, &Server::unicast);
connect(music_manager, &MusicManager::sendAreaFMPacket, this, QOverload<AOPacket, int>::of(&Server::broadcast));
// Get musiclist from config file
m_music_list = music_manager->rootMusiclist();
@ -102,12 +107,9 @@ void Server::start()
QString area_name = raw_area_names[i];
AreaData *l_area = new AreaData(area_name, i, music_manager);
m_areas.insert(i, l_area);
connect(l_area, &AreaData::sendAreaPacket,
this, QOverload<AOPacket,int>::of(&Server::broadcast));
connect(l_area, &AreaData::sendAreaPacketClient,
this, &Server::unicast);
connect(l_area, &AreaData::userJoinedArea,
music_manager, &MusicManager::userJoinedArea);
connect(l_area, &AreaData::sendAreaPacket, this, QOverload<AOPacket, int>::of(&Server::broadcast));
connect(l_area, &AreaData::sendAreaPacketClient, this, &Server::unicast);
connect(l_area, &AreaData::userJoinedArea, music_manager, &MusicManager::userJoinedArea);
music_manager->registerArea(i);
}
@ -118,7 +120,8 @@ void Server::start()
m_ipban_list = ConfigManager::iprangeBans();
// Rate-Limiter for IC-Chat
connect(&next_message_timer, &QTimer::timeout, this, &Server::allowMessage);
m_message_floodguard_timer = new QTimer(this);
connect(m_message_floodguard_timer, &QTimer::timeout, this, &Server::allowMessage);
// Prepare player IDs and reference hash.
for (int i = ConfigManager::maxPlayers() - 1; i >= 0; i--) {
@ -127,6 +130,11 @@ void Server::start()
}
}
QVector<AOClient *> Server::getClients()
{
return m_clients;
}
void Server::clientConnected()
{
QTcpSocket *socket = server->nextPendingConnection();
@ -188,9 +196,11 @@ void Server::clientConnected()
}
m_clients.append(client);
connect(socket, &QTcpSocket::disconnected, client,
&AOClient::clientDisconnected);
connect(socket, &QTcpSocket::disconnected, client, &AOClient::clientDisconnected);
connect(socket, &QTcpSocket::disconnected, this, [=] {
if (client->hasJoined()) {
decreasePlayerCount();
}
m_clients.removeAll(client);
client->deleteLater();
});
@ -217,14 +227,14 @@ void Server::updateCharsTaken(AreaData* area)
AOPacket response_cc("CharsCheck", chars_taken);
for (AOClient* client : qAsConst(m_clients)) {
if (client->m_current_area == area->index()){
if (!client->m_is_charcursed)
client->sendPacket(response_cc);
for (AOClient *l_client : qAsConst(m_clients)) {
if (l_client->m_current_area == area->index()) {
if (!l_client->m_is_charcursed)
l_client->sendPacket(response_cc);
else {
QStringList chars_taken_cursed = getCursedCharsTaken(client, chars_taken);
QStringList chars_taken_cursed = getCursedCharsTaken(l_client, chars_taken);
AOPacket response_cc_cursed("CharsCheck", chars_taken_cursed);
client->sendPacket(response_cc_cursed);
l_client->sendPacket(response_cc_cursed);
}
}
}
@ -242,6 +252,17 @@ QStringList Server::getCursedCharsTaken(AOClient* client, QStringList chars_take
return chars_taken_cursed;
}
bool Server::isMessageAllowed()
{
return m_can_send_ic_messages;
}
void Server::startMessageFloodguard(int f_duration)
{
m_can_send_ic_messages = false;
m_message_floodguard_timer->start(f_duration);
}
QHostAddress Server::parseToIPv4(QHostAddress f_remote_ip)
{
bool l_ok;
@ -273,8 +294,8 @@ void Server::broadcast(AOPacket packet, int area_index)
void Server::broadcast(AOPacket packet)
{
for (AOClient* client : qAsConst(m_clients)) {
client->sendPacket(packet);
for (AOClient *l_client : qAsConst(m_clients)) {
l_client->sendPacket(packet);
}
}
@ -302,12 +323,12 @@ void Server::broadcast(AOPacket packet, AOPacket other_packet, TARGET_TYPE targe
{
switch (target) {
case TARGET_TYPE::AUTHENTICATED:
for (AOClient* client : qAsConst(m_clients)){
if (client->m_authenticated) {
client->sendPacket(other_packet);
for (AOClient *l_client : qAsConst(m_clients)) {
if (l_client->m_authenticated) {
l_client->sendPacket(other_packet);
}
else {
client->sendPacket(packet);
l_client->sendPacket(packet);
}
}
default:
@ -328,9 +349,9 @@ void Server::unicast(AOPacket f_packet, int f_client_id)
QList<AOClient *> Server::getClientsByIpid(QString ipid)
{
QList<AOClient *> return_clients;
for (AOClient* client : qAsConst(m_clients)) {
if (client->getIpid() == ipid)
return_clients.append(client);
for (AOClient *l_client : qAsConst(m_clients)) {
if (l_client->getIpid() == ipid)
return_clients.append(l_client);
}
return return_clients;
}
@ -340,6 +361,32 @@ AOClient* Server::getClientByID(int id)
return m_clients_ids.value(id);
}
int Server::getPlayerCount()
{
return m_player_count;
}
QStringList Server::getCharacters()
{
return m_characters;
}
int Server::getCharacterCount()
{
return m_characters.length();
}
QString Server::getCharacterById(int f_chr_id)
{
QString l_chr;
if (f_chr_id >= 0 && f_chr_id < m_characters.length()) {
l_chr = m_characters.at(f_chr_id);
}
return l_chr;
}
int Server::getCharID(QString char_name)
{
for (const QString &character : qAsConst(m_characters)) {
@ -350,14 +397,66 @@ int Server::getCharID(QString char_name)
return -1; // character does not exist
}
QVector<AreaData *> Server::getAreas()
{
return m_areas;
}
int Server::getAreaCount()
{
return m_areas.length();
}
AreaData *Server::getAreaById(int f_area_id)
{
AreaData *l_area = nullptr;
if (f_area_id >= 0 && f_area_id < m_areas.length()) {
l_area = m_areas.at(f_area_id);
}
return l_area;
}
QQueue<QString> Server::getAreaBuffer(const QString &f_areaName)
{
return logger->buffer(f_areaName);
}
QStringList Server::getAreaNames()
{
return m_area_names;
}
QString Server::getAreaName(int f_area_id)
{
QString l_name;
if (f_area_id >= 0 && f_area_id < m_area_names.length()) {
l_name = m_area_names.at(f_area_id);
}
return l_name;
}
QStringList Server::getMusicList()
{
return m_music_list;
}
QStringList Server::getBackgrounds()
{
return m_backgrounds;
}
DBManager *Server::getDatabaseManager()
{
return db_manager;
}
void Server::allowMessage()
{
can_send_ic_messages = true;
m_can_send_ic_messages = true;
}
void Server::handleDiscordIntegration()
@ -367,12 +466,10 @@ void Server::handleDiscordIntegration()
if (ConfigManager::discordWebhookEnabled()) {
if (ConfigManager::discordModcallWebhookEnabled())
connect(this, &Server::modcallWebhookRequest,
discord, &Discord::onModcallWebhookRequested);
connect(this, &Server::modcallWebhookRequest, discord, &Discord::onModcallWebhookRequested);
if (ConfigManager::discordBanWebhookEnabled())
connect(this, &Server::banWebhookRequest,
discord, &Discord::onBanWebhookRequested);
connect(this, &Server::banWebhookRequest, discord, &Discord::onBanWebhookRequested);
if (ConfigManager::discordUptimeEnabled())
discord->startUptimeTimer();
@ -390,22 +487,26 @@ void Server::markIDFree(const int &f_user_id)
void Server::hookupAOClient(AOClient *client)
{
connect(client, &AOClient::logIC,
logger, &ULogger::logIC);
connect(client, &AOClient::logOOC,
logger, &ULogger::logOOC);
connect(client, &AOClient::logLogin,
logger, &ULogger::logLogin);
connect(client, &AOClient::logCMD,
logger, &ULogger::logCMD);
connect(client, &AOClient::logBan,
logger, &ULogger::logBan);
connect(client, &AOClient::logKick,
logger, &ULogger::logKick);
connect(client, &AOClient::logModcall,
logger, &ULogger::logModcall);
connect(client, &AOClient::clientSuccessfullyDisconnected,
this, &Server::markIDFree);
connect(client, &AOClient::joined, this, &Server::increasePlayerCount);
connect(client, &AOClient::logIC, logger, &ULogger::logIC);
connect(client, &AOClient::logOOC, logger, &ULogger::logOOC);
connect(client, &AOClient::logLogin, logger, &ULogger::logLogin);
connect(client, &AOClient::logCMD, logger, &ULogger::logCMD);
connect(client, &AOClient::logBan, logger, &ULogger::logBan);
connect(client, &AOClient::logKick, logger, &ULogger::logKick);
connect(client, &AOClient::logModcall, logger, &ULogger::logModcall);
}
void Server::increasePlayerCount()
{
m_player_count++;
emit playerCountUpdated(m_player_count);
}
void Server::decreasePlayerCount()
{
m_player_count--;
emit playerCountUpdated(m_player_count);
}
bool Server::isIPBanned(QHostAddress f_remote_IP)
@ -422,8 +523,8 @@ bool Server::isIPBanned(QHostAddress f_remote_IP)
Server::~Server()
{
for (AOClient* client : qAsConst(m_clients)) {
client->deleteLater();
for (AOClient *l_client : qAsConst(m_clients)) {
l_client->deleteLater();
}
server->deleteLater();
proxy->deleteLater();

View File

@ -17,12 +17,16 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
#include "include/area_data.h"
#include "include/config_manager.h"
#include "include/server.h"
void AOClient::addStatement(QStringList packet)
{
if (checkTestimonySymbols(packet[4])) {
return;
}
AreaData* area = server->m_areas[m_current_area];
AreaData *area = server->getAreaById(m_current_area);
int c_statement = area->statement();
if (c_statement >= -1) {
if (area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING) {
@ -55,7 +59,7 @@ QStringList AOClient::updateStatement(QStringList packet)
if (checkTestimonySymbols(packet[4])) {
return packet;
}
AreaData* area = server->m_areas[m_current_area];
AreaData *area = server->getAreaById(m_current_area);
int c_statement = area->statement();
area->setTestimonyRecording(AreaData::TestimonyRecording::PLAYBACK);
if (c_statement <= 0 || area->testimony()[c_statement].empty())
@ -71,7 +75,7 @@ QStringList AOClient::updateStatement(QStringList packet)
void AOClient::clearTestimony()
{
AreaData* area = server->m_areas[m_current_area];
AreaData *area = server->getAreaById(m_current_area);
area->clearTestimony();
}

View File

@ -65,13 +65,13 @@ void WSClient::onTcpConnect()
tcp_socket->flush();
}
WSClient::WSClient(QTcpSocket *p_tcp_socket, QWebSocket *p_web_socket, QObject *parent)
: QObject(parent),
WSClient::WSClient(QTcpSocket *p_tcp_socket, QWebSocket *p_web_socket, QObject *parent) :
QObject(parent),
tcp_socket(p_tcp_socket),
web_socket(p_web_socket)
{
bool l_is_local = web_socket->peerAddress() == QHostAddress::LocalHost |
web_socket->peerAddress() == QHostAddress::LocalHostIPv6;
bool l_is_local = (web_socket->peerAddress() == QHostAddress::LocalHost) ||
(web_socket->peerAddress() == QHostAddress::LocalHostIPv6);
// TLDR : We check if the header comes trough a proxy/tunnel running locally.
// This is to ensure nobody can send those headers from the web.
QNetworkRequest l_request = web_socket->request();

View File

@ -17,6 +17,8 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/ws_proxy.h"
#include "include/ws_client.h"
WSProxy::WSProxy(int p_local_port, int p_ws_port, QObject *parent) :
QObject(parent),
local_port(p_local_port),
@ -32,7 +34,8 @@ void WSProxy::start()
{
if (!server->listen(QHostAddress::Any, ws_port)) {
qDebug() << "WebSocket proxy failed to start: " << server->errorString();
} else {
}
else {
qDebug() << "WebSocket proxy listening";
}
}

View File

@ -143,7 +143,8 @@ void Area::changeHP()
if (AreaData::Side::DEFENCE == side) {
QCOMPARE(expectedHP, m_area->defHP());
} else {
}
else {
QCOMPARE(expectedHP, m_area->proHP());
}
}
@ -211,8 +212,7 @@ void Area::testimony()
{
// Add all statements, and check that they're added.
for (const auto& l_statement : l_testimony)
{
for (const auto &l_statement : l_testimony) {
m_area->recordStatement(l_statement);
QCOMPARE(l_statement, m_area->testimony().at(m_area->statement() - 1));

View File

@ -11,8 +11,8 @@ namespace unittests {
class MusicListManager : public QObject
{
Q_OBJECT
public :
public:
MusicManager *m_music_manager;
private slots:
@ -70,8 +70,6 @@ private slots:
* @brief Tests the retrieval of the full musiclist for an area.
*/
void musiclist();
};
void MusicListManager::init()
@ -82,9 +80,11 @@ void MusicListManager::init()
l_test_list.insert("Announce The Truth (JFA).opus", {"Announce The Truth (JFA).opus", 98});
QStringList l_list = {};
l_list << "==Music==" << "Announce The Truth (AJ).opus" << "Announce The Truth (JFA).opus";
l_list << "==Music=="
<< "Announce The Truth (AJ).opus"
<< "Announce The Truth (JFA).opus";
m_music_manager = new MusicManager(nullptr, l_list ,{"my.cdn.com","your.cdn.com"}, l_test_list);
m_music_manager = new MusicManager(l_list, {"my.cdn.com", "your.cdn.com"}, l_test_list, nullptr);
}
void MusicListManager::registerArea()
@ -215,7 +215,6 @@ void MusicListManager::addCustomCategory()
QCOMPARE(l_result, true);
QCOMPARE(m_music_manager->musiclist(0).size(), 5);
QCOMPARE(m_music_manager->musiclist(0).at(4), "===Music===");
}
}
@ -237,7 +236,6 @@ void MusicListManager::sanitiseCustomList()
QCOMPARE(m_music_manager->musiclist(0).size(), 5);
QCOMPARE(m_music_manager->musiclist(0).at(3), "==Music2==");
QCOMPARE(m_music_manager->musiclist(0).at(4), "mysong.opus");
}
void MusicListManager::removeCategorySong()