Added background side locking (#366)

* Added background side locking

* Fix clang format

---------

Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com>
This commit is contained in:
Leifa 2024-07-20 16:25:46 +02:00 committed by GitHub
parent d8ec4ccdf5
commit c24c3ea387
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 68 additions and 4 deletions

1
.gitignore vendored
View File

@ -80,3 +80,4 @@ bin/libcore.a
doxygen/html
.vscode/
*.TMP

View File

@ -32,6 +32,7 @@ const QMap<QString, AOClient::CommandInfo> AOClient::COMMANDS{
{"changeauth", {{ACLRole::SUPER}, 0, &AOClient::cmdChangeAuth}},
{"rootpass", {{ACLRole::SUPER}, 1, &AOClient::cmdSetRootPass}},
{"background", {{ACLRole::NONE}, 1, &AOClient::cmdSetBackground}},
{"side", {{ACLRole::NONE}, 0, &AOClient::cmdSetSide}},
{"lock_background", {{ACLRole::BGLOCK}, 0, &AOClient::cmdBgLock}},
{"unlock_background", {{ACLRole::BGLOCK}, 0, &AOClient::cmdBgUnlock}},
{"adduser", {{ACLRole::MODIFY_USERS}, 2, &AOClient::cmdAddUser}},
@ -239,7 +240,7 @@ void AOClient::changeArea(int new_area)
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()});
sendPacket("BN", {server->getAreaById(new_area)->background(), server->getAreaById(new_area)->side()});
if (l_character_taken) {
sendPacket("DONE");
}

View File

@ -939,6 +939,15 @@ class AOClient : public QObject
*/
void cmdSetBackground(int argc, QStringList argv);
/**
* @brief Fixes the background side of the current area.
*
* @details Takes the **background side** as the only argument.
*
* @iscommand
*/
void cmdSetSide(int argc, QStringList argv);
/**
* @brief Locks the background, preventing it from being changed.
*

View File

@ -603,6 +603,16 @@ void AreaData::setBackground(const QString f_background)
}
}
QString AreaData::side() const
{
return m_side;
}
void AreaData::setSide(const QString f_side)
{
m_side = f_side;
}
bool AreaData::ignoreBgList()
{
return m_ignoreBgList;

View File

@ -515,6 +515,22 @@ class AreaData : public QObject
*/
void setBackground(const QString f_background);
/**
* @brief Returns the side of the area.
*
* @return See short description.
*
* @see #m_side
*/
QString side() const;
/**
* @brief Sets the side of the area.
*
* @see #AOClient::cmdSetSide and #m_side
*/
void setSide(const QString f_side);
/**
* @brief Returns if custom shownames are allowed in the area.
*
@ -1048,6 +1064,7 @@ class AreaData : public QObject
* @details Represents a directory's name in `base/background/` clientside.
*/
QString m_background;
QString m_side;
/**
* @brief If true, nobody may become the CM of this area.

View File

@ -298,7 +298,7 @@ void AOClient::cmdSetBackground(int argc, QStringList argv)
if (m_authenticated || !area->bgLocked()) {
if (server->getBackgrounds().contains(f_background, Qt::CaseInsensitive) || area->ignoreBgList() == true) {
area->setBackground(f_background);
server->broadcast(PacketFactory::createPacket("BN", {f_background}), areaId());
server->broadcast(PacketFactory::createPacket("BN", {f_background, area->side()}), areaId());
QString ambience_name = ConfigManager::ambience()->value(f_background + "/ambience").toString();
if (ambience_name != "") {
server->broadcast(PacketFactory::createPacket("MC", {ambience_name, "-1", characterName(), "1", "1"}), areaId());
@ -317,6 +317,27 @@ void AOClient::cmdSetBackground(int argc, QStringList argv)
}
}
void AOClient::cmdSetSide(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData *area = server->getAreaById(areaId());
if (area->bgLocked()) {
sendServerMessage("This area's background is locked.");
return;
}
QString side = argv.join(" ");
area->setSide(side);
server->broadcast(PacketFactory::createPacket("BN", {area->background(), side}), areaId());
if (side.isEmpty()) {
sendServerMessageArea(character() + " unlocked the background side");
}
else {
sendServerMessageArea(character() + " locked the background side to " + side);
}
}
void AOClient::cmdBgLock(int argc, QStringList argv)
{
Q_UNUSED(argc);

View File

@ -163,7 +163,12 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const
// side
// this is validated clientside so w/e
l_args.append(l_incoming_args[5].toString());
QString side = area->side();
if (side.isEmpty()) {
side = l_incoming_args[5].toString();
}
l_args.append(side);
if (client.m_pos != l_incoming_args[5].toString()) {
client.m_pos = l_incoming_args[5].toString();
client.m_pos.replace("../", "").replace("..\\", "");

View File

@ -38,7 +38,7 @@ void PacketRD::handlePacket(AreaData *area, AOClient &client) const
client.sendPacket("FA", client.getServer()->getAreaNames());
// Here lies OPPASS, the genius of FanatSors who send the modpass to everyone in plain text.
client.sendPacket("DONE");
client.sendPacket("BN", {area->background()});
client.sendPacket("BN", {area->background(), area->side()});
client.sendServerMessage("=== MOTD ===\r\n" + ConfigManager::motd() + "\r\n=============");