Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropped Qt5, drop backward compatibility/feature list #362

Merged
merged 7 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ INCLUDEPATH += src

SOURCES += \
src/acl_roles_handler.cpp \
src/akashidefs.cpp \
src/aoclient.cpp \
src/network/aopacket.cpp \
src/network/network_socket.cpp \
Expand Down
2 changes: 0 additions & 2 deletions src/acl_roles_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ void ACLRolesHandler::clearRoles()
bool ACLRolesHandler::loadFile(QString f_file_name)
{
QSettings l_settings(f_file_name, QSettings::IniFormat);
l_settings.setIniCodec("UTF-8");
if (!checkPermissionsIni(&l_settings)) {
return false;
}
Expand Down Expand Up @@ -218,7 +217,6 @@ bool ACLRolesHandler::loadFile(QString f_file_name)
bool ACLRolesHandler::saveFile(QString f_file_name)
{
QSettings l_settings(f_file_name, QSettings::IniFormat);
l_settings.setIniCodec("UTF-8");
if (!checkPermissionsIni(&l_settings)) {
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions src/akashidefs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "akashidefs.h"

namespace akashi {
QString get_protocol_version_string()
{
return QString::number(PROTOCOL_MAJOR_VERSION) + "." + QString::number(PROTOCOL_MINOR_VERSION) + "." + QString::number(PROTOCOL_PATCH_VERSION);
}
}
8 changes: 6 additions & 2 deletions src/akashidefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define AKASHIDEFS_H

#include <QString>
#include <qnamespace.h>

namespace akashi {
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Expand All @@ -12,6 +11,11 @@ using SplitBehavior = Qt::SplitBehaviorFlags;
#endif
const SplitBehavior KeepEmptyParts = SplitBehavior::KeepEmptyParts;
const SplitBehavior SkipEmptyParts = SplitBehavior::SkipEmptyParts;
}

QString get_protocol_version_string();

const int PROTOCOL_MAJOR_VERSION = 1;
const int PROTOCOL_MINOR_VERSION = 0;
const int PROTOCOL_PATCH_VERSION = 0;
}
#endif // AKASHIDEFS_H
7 changes: 3 additions & 4 deletions src/aoclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,9 @@ class AOClient : public QObject
*/
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).
int minor = -1; //!< The 'minor' part of the version number. In Attorney Online's case, this increases for bugfix releases (generally).
int major = -1;
int minor = -1;
int patch = -1;
};

/**
Expand Down
6 changes: 0 additions & 6 deletions src/area_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ AreaData::AreaData(QString p_name, int p_index, MusicManager *p_music_manager =
name_split.removeFirst();
m_name = name_split.join(":");
QSettings *areas_ini = ConfigManager::areaData();
areas_ini->setIniCodec("UTF-8");
areas_ini->beginGroup(p_name);
m_background = areas_ini->value("background", "gs4").toString();
m_isProtected = areas_ini->value("protected_area", "false").toBool();
Expand Down Expand Up @@ -262,12 +261,7 @@ QList<AreaData::Evidence> AreaData::evidence() const

void AreaData::swapEvidence(int f_eviId1, int f_eviId2)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
// swapItemsAt does not exist in Qt older than 5.13
m_evidence.swap(f_eviId1, f_eviId2);
#else
m_evidence.swapItemsAt(f_eviId1, f_eviId2);
#endif
}

void AreaData::appendEvidence(const AreaData::Evidence &f_evi_r)
Expand Down
1 change: 0 additions & 1 deletion src/command_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ CommandExtension CommandExtensionCollection::getExtension(QString f_command_name
bool CommandExtensionCollection::loadFile(QString f_filename)
{
QSettings l_settings(f_filename, QSettings::IniFormat);
l_settings.setIniCodec("UTF-8");
if (l_settings.status() != QSettings::NoError) {
qWarning() << "[Command Extension Collection]"
<< "error: failed to load file" << f_filename << "; aborting";
Expand Down
2 changes: 0 additions & 2 deletions src/commands/casing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ 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++) {
l_out << l_area->testimony().at(i).join("#") << "\n";
Expand Down Expand Up @@ -280,7 +279,6 @@ void AOClient::cmdLoadTestimony(int argc, QStringList argv)
clearTestimony();
int l_testimony_lines = 0;
QTextStream l_in(&l_file);
l_in.setCodec("UTF-8");
while (!l_in.atEnd()) {
if (l_testimony_lines <= ConfigManager::maxStatements()) {
QString line = l_in.readLine();
Expand Down
7 changes: 0 additions & 7 deletions src/commands/command_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ QStringList AOClient::buildAreaList(int area_idx)

int AOClient::genRand(int min, int max)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
qsrand(QDateTime::currentMSecsSinceEpoch());
quint32 random_number = (qrand() % (max - min + 1)) + min;
return random_number;

#else
return QRandomGenerator::system()->bounded(min, max + 1);
#endif
}

void AOClient::diceThrower(int sides, int dice, bool p_roll, int roll_modifier)
Expand Down
1 change: 0 additions & 1 deletion src/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ bool ConfigManager::verifyServerConfig()

// Verify areas
QSettings l_areas_ini("config/areas.ini", QSettings::IniFormat);
l_areas_ini.setIniCodec("UTF-8");
if (l_areas_ini.childGroups().length() < 1) {
qCritical() << "areas.ini is invalid!";
return false;
Expand Down
1 change: 1 addition & 0 deletions src/data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define DATA_TYPES_H

#include <QDebug>
#include <QVariant>

/**
* @brief A class for handling several custom data types.
Expand Down
11 changes: 2 additions & 9 deletions src/packet/packet_casea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,13 @@ void PacketCasea::handlePacket(AreaData *area, AOClient &client) const
QString l_message = "=== Case Announcement ===\r\n" + (client.name() == "" ? client.character() : client.name()) + " needs " + l_needed_roles.join(", ") + " for " + (l_case_title == "" ? "a case" : l_case_title) + "!";

QList<AOClient *> l_clients_to_alert;
// here lies morton, RIP
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QSet<bool> l_needs_set(l_needs_list.begin(), l_needs_list.end());
#else
QSet<bool> l_needs_set = l_needs_list.toSet();
#endif

const QVector<AOClient *> l_clients = client.getServer()->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);
#else
QSet<bool> l_matches = l_client->m_casing_preferences.toSet().intersect(l_needs_set);
#endif

if (!l_matches.isEmpty() && !l_clients_to_alert.contains(l_client))
l_clients_to_alert.append(l_client);
}
Expand Down
6 changes: 4 additions & 2 deletions src/packet/packet_ct.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "packet/packet_ct.h"

#include "akashidefs.h"
#include "config_manager.h"
#include "packet/packet_factory.h"
#include "server.h"

#include <QDebug>
#include <QRegularExpression>

PacketCT::PacketCT(QStringList &contents) :
AOPacket(contents)
Expand All @@ -27,8 +29,8 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const
return;
}

client.setName(client.dezalgo(m_content[0]).replace(QRegExp("\\[|\\]|\\{|\\}|\\#|\\$|\\%|\\&"), "")); // no fucky wucky shit here
if (client.name().isEmpty() || client.name() == ConfigManager::serverName()) // impersonation & empty name protection
client.setName(client.dezalgo(m_content[0]).replace(QRegularExpression("\\[|\\]|\\{|\\}|\\#|\\$|\\%|\\&"), "")); // no fucky wucky shit here
if (client.name().isEmpty() || client.name() == ConfigManager::serverName()) // impersonation & empty name protection
return;

if (client.name().length() > 30) {
Expand Down
10 changes: 8 additions & 2 deletions src/packet/packet_hi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "packet/packet_hi.h"
#include "akashiutils.h"

#include "config_manager.h"
#include "db_manager.h"
#include "server.h"

Expand Down Expand Up @@ -47,5 +48,10 @@ void PacketHI::handlePacket(AreaData *area, AOClient &client) const
return;
}

client.sendPacket("ID", {QString::number(client.clientId()), "akashi", QCoreApplication::applicationVersion()});
client.sendPacket("PN", {QString::number(client.getServer()->getPlayerCount()), QString::number(ConfigManager::maxPlayers()), ConfigManager::serverDescription()});

if (ConfigManager::assetUrl().isValid()) {
QByteArray l_asset_url = ConfigManager::assetUrl().toEncoded(QUrl::EncodeSpaces);
client.sendPacket("ASS", {l_asset_url});
}
}
56 changes: 16 additions & 40 deletions src/packet/packet_id.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "packet/packet_id.h"

#include "akashidefs.h"
#include "config_manager.h"
#include "server.h"

Expand All @@ -13,7 +15,7 @@ PacketInfo PacketID::getPacketInfo() const
{
PacketInfo info{
.acl_permission = ACLRole::Permission::NONE,
.min_args = 2,
.min_args = 3,
.header = "ID"};
return info;
}
Expand All @@ -22,56 +24,30 @@ void PacketID::handlePacket(AreaData *area, AOClient &client) const
{
Q_UNUSED(area)

if (client.m_version.major == 2) {
if (client.m_version.major == akashi::PROTOCOL_MAJOR_VERSION) {
// No double sending of the ID packet!
client.sendPacket("BD", {"A protocol error has been encountered. Packet : ID"});
client.m_socket->close();
return;
}

// Full feature list as of AO 2.8.5
// The only ones that are critical to ensuring the server works are
// "noencryption" and "fastloading"
QStringList l_feature_list = {
"noencryption", "yellowtext", "prezoom",
"flipping", "customobjections", "fastloading",
"deskmod", "evidence", "cccc_ic_support",
"arup", "casing_alerts", "modcall_reason",
"looping_sfx", "additive", "effects",
"y_offset", "expanded_desk_mods", "auth_packet", "custom_blips"};

client.m_version.string = m_content[1];
QRegularExpression rx("\\b(\\d+)\\.(\\d+)\\.(\\d+)\\b"); // matches X.X.X (e.g. 2.9.0, 2.4.10, etc.)
QRegularExpressionMatch l_match = rx.match(client.m_version.string);
if (l_match.hasMatch()) {
client.m_version.release = l_match.captured(1).toInt();
client.m_version.major = l_match.captured(2).toInt();
client.m_version.minor = l_match.captured(3).toInt();
if (!ConfigManager::webaoEnabled() && m_content[0] == "webAO") {
client.sendPacket("BD", {"WebAO is disabled on this server."});
client.m_socket->close();
return;
}
if (m_content[0] == "webAO") {
client.m_version.release = 2;
client.m_version.major = 10;
client.m_version.minor = 0;

if (!ConfigManager::webaoEnabled()) {
client.sendPacket("BD", {"WebAO is disabled on this server."});
client.m_socket->close();
return;
}
AOClient::ClientVersion version;
if (m_content[2] == akashi::get_protocol_version_string()) {
version.major = akashi::PROTOCOL_MAJOR_VERSION;
version.minor = akashi::PROTOCOL_MINOR_VERSION;
version.patch = akashi::PROTOCOL_PATCH_VERSION;
}

if (client.m_version.release != 2) {
// No valid ID packet resolution.
client.sendPacket("BD", {"A protocol error has been encountered. Packet : ID\nMajor version not recognised."});
else {
client.sendPacket("BD", {"A protocol error has been encountered. Packet : ID\nProtocol version not supported."});
client.m_socket->close();
return;
}

client.sendPacket("PN", {QString::number(client.getServer()->getPlayerCount()), QString::number(ConfigManager::maxPlayers()), ConfigManager::serverDescription()});
client.sendPacket("FL", l_feature_list);

if (ConfigManager::assetUrl().isValid()) {
QByteArray l_asset_url = ConfigManager::assetUrl().toEncoded(QUrl::EncodeSpaces);
client.sendPacket("ASS", {l_asset_url});
}
client.sendPacket("ID", {QString::number(client.clientId()), "akashi", QCoreApplication::applicationVersion()});
}
Loading
Loading