From 4fb61b7afd9f234492451ed34ee22c9a5ece0b7e Mon Sep 17 00:00:00 2001 From: Cerapter <43446478+Cerapter@users.noreply.github.com> Date: Wed, 15 May 2024 17:19:03 +0200 Subject: Lift out most server-related data into its own class (#955) * Lift out most server-related data into its own class * Fix missing negation in the auth packet support check * Update `get_feature(BASE_FEATURE_SET)`'s documentation * Make the version numbers public * Add support for custom blips --------- Co-authored-by: in1tiate <32779090+in1tiate@users.noreply.github.com> --- include/aoapplication.h | 65 +++++--------------- include/serverdata.h | 153 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 49 deletions(-) create mode 100644 include/serverdata.h (limited to 'include') diff --git a/include/aoapplication.h b/include/aoapplication.h index 43ed559e..2b79f6ef 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -1,11 +1,12 @@ #ifndef AOAPPLICATION_H #define AOAPPLICATION_H -#include "widgets/aooptionsdialog.h" #include "aopacket.h" #include "datatypes.h" #include "demoserver.h" #include "discord_rich_presence.h" +#include "serverdata.h" +#include "widgets/aooptionsdialog.h" #include "bass.h" @@ -87,51 +88,31 @@ public: qint64 latency = 0; QString window_title; - /////////////////server metadata////////////////// - - bool yellow_text_supported = false; - bool prezoom_supported = false; - bool flipping_supported = false; - bool custom_objection_supported = false; - bool desk_mod_supported = false; - bool evidence_supported = false; - bool cccc_ic_supported = false; - bool arup_supported = false; - bool casing_alerts_supported = false; - bool modcall_reason_supported = false; - bool looping_sfx_supported = false; - bool additive_supported = false; - bool effects_supported = false; - bool y_offset_supported = false; - bool expanded_desk_mods_supported = false; - bool auth_packet_supported = false; - bool custom_blips_supported = false; + /// Stores everything related to the server the client is connected to, if + /// any. + server::ServerData m_serverdata; ///////////////loading info/////////////////// // client ID. Not useful, to be removed eventually int client_id = 0; - QString server_software = ""; - - int char_list_size = 0; - int loaded_chars = 0; + /// Used for a fancy loading bar upon joining a server. int generated_chars = 0; - int evidence_list_size = 0; - int loaded_evidence = 0; - int music_list_size = 0; - int loaded_music = 0; bool courtroom_loaded = false; - //////////////////versioning/////////////// - - int get_release() const { return RELEASE; } - int get_major_version() const { return MAJOR_VERSION; } - int get_minor_version() const { return MINOR_VERSION; } - QString get_version_string(); + /** + * @brief Returns the version string of the software. + * + * @return The string "X.Y.Z", where X is the release of the software (usually + * '2'), Y is the major version, and Z is the minor version. + */ + static QString get_version_string(); - /////////////////////////////////////////// + static const int RELEASE = 2; + static const int MAJOR_VERSION = 10; + static const int MINOR_VERSION = 1; // Adds the server to favorite_servers.ini void add_favorite_server(int p_server); @@ -365,16 +346,6 @@ public: // The file name of the log file in base/logs. QString log_filename; - /** - * @brief A QString of an URL that defines the content repository - * send by the server. - * - * @details Introduced in Version 2.9.2. - * Addresses the issue of contenturl devlivery for WebAO - * without relying on someone adding the link manually. - */ - QString asset_url; - void initBASS(); static void load_bass_plugins(); static void CALLBACK BASSreset(HSTREAM handle, DWORD channel, DWORD data, @@ -385,10 +356,6 @@ public: DemoServer* demo_server = nullptr; private: - const int RELEASE = 2; - const int MAJOR_VERSION = 10; - const int MINOR_VERSION = 1; - QVector server_list; QHash asset_lookup_cache; QHash dir_listing_cache; diff --git a/include/serverdata.h b/include/serverdata.h new file mode 100644 index 00000000..0c342660 --- /dev/null +++ b/include/serverdata.h @@ -0,0 +1,153 @@ +#ifndef SERVERDATA_H +#define SERVERDATA_H + +#include +#include +#include + +namespace server { + Q_NAMESPACE + + /// The base feature set that almost all servers are supposed to support. + enum class BASE_FEATURE_SET { + YELLOWTEXT, ///< Yellow text in in-character messages. + ///< @since 2.1.0 + FLIPPING, ///< The ability to mirror a character in-game. + ///< @since 2.1.0 + CUSTOMOBJECTIONS, ///< Enables the use of a single custom objection named + ///< `custom`. + ///< @since 2.1.0 + FASTLOADING, ///< Enables the use of "fast loading" instead of the legacy + ///< loading protocol. + ///< @since 2.1.0 + NOENCRYPTION, ///< Disables "FantaCrypt" for the remainder of the session. + ///< @since 2.1.0 + DESKMOD, ///< Allows forcing the appearance or disappearance of the desk. + ///< @since 2.3 to 2.5 + EVIDENCE, ///< Allows creating and presenting evidence. + ///< @since 2.3 to 2.5 + CCCC_IC_SUPPORT, ///< The ability to pair up with another user's character, + ///< the ability to change one's displayed name + ///< in-character ("showname"), and the ability to perform + ///< "immediate" preanimations (ones that happen alongside + ///< text display). + ///< @since 2.6.0 + ARUP, ///< Areas have more data about them than just their name (including + ///< their status, their "lockedness", and who is the Case Master in + ///< the area), and sets the client up to receive and send ARUP + ///< packets. + ///< @since 2.6.0 + CASING_ALERTS, ///< The client gains a new window to announce cases with, + ///< and the settings to set itself up to receive case alerts + ///< based on casing preferences. No longer used. + ///< @since 2.6.0 + MODCALL_REASON, ///< Enables entering a custom reason for calling + ///< moderators. + ///< @since 2.6.0 + LOOPING_SFX, ///< Enables looping SFX extensions for the in-character + ///< command. + ///< @since 2.8.0 + ADDITIVE, ///< Enables "additive" text that allows in-character messages to + ///< concatenate to the previous one sent by the same character. + ///< @since 2.8.0 + EFFECTS, ///< Enables effect overlays. + ///< @since 2.8.0 + Y_OFFSET, ///< Enables support for vertical offsets. + ///< @since 2.9.0 + EXPANDED_DESK_MODS, ///< Enables desk modifiers 2 through 5. + ///< @since 2.9.0 + AUTH_PACKET, ///< Enables the use of the AUTH packet. + ///< @since 2.9.1 + PREZOOM, ///< Preanim zoom. + CUSTOM_BLIPS ///< Allows the in-character messages to contain data about + ///< what blips to use for the character's current message. + }; + Q_ENUM_NS(BASE_FEATURE_SET) + + /** + * @brief Arranges data about the server the client is connected to. + */ + class ServerData { + public: + /** + * @brief Returns true if one of the standard features exists on the server. + * + * @details Internally, this calls get_feature(const QString &f_feature) + * with the enum's value converted to string. + * + * @param f_feature The feature to check for. + * + * @return True if the feature exists on the server. + */ + bool get_feature(const BASE_FEATURE_SET &f_feature) const; + + /** + * @brief Returns true if the feature exists on the server. + * + * @param f_feature The feature to check for. Case insensitive. + * + * @return True if the feature exists on the server. + */ + bool get_feature(const QString &f_feature) const; + + /** + * @brief Sets the feature list, overwriting the existing one. + * + * @param f_feature_list The new feature list of the server. + */ + void set_features(const QStringList &f_feature_list); + + /** + * @brief Self-explanatory: gets the software the server is running on. + * + * @return As brief description. + */ + QString get_server_software() const; + + /** + * @brief Self-explanatory: setter for server software. + * + * @param f_software The new server software. + */ + void set_server_software(const QString &f_software); + + /** + * @brief Getter for the server's asset URL. + * + * @return As brief description. + * + * @see m_asset_url + */ + QString get_asset_url() const; + + /** + * @brief Attempts to set the new asset URL for the server. + * + * @details The function converts the sole parameter into UTF-8, then + * attempts to percent decode it. The URL is only set if all these steps + * successfully happen. + * + * @param f_asset_url A QString that contains the URL. + */ + void set_asset_url(const QString &f_asset_url); + + private: + /// The features available on the server. Determines what + QStringList m_features; + + /// The software the server is running. + QString m_server_software; + + /** + * @brief A QString of an URL that defines the content repository + * send by the server. + * + * @details Introduced in Version 2.9.2. + * Addresses the issue of contenturl devlivery for WebAO + * without relying on someone adding the link manually. + */ + QString m_asset_url; + }; +} // namespace server + +#endif // SERVERDATA_H -- cgit