Skip to content

Commit

Permalink
Added background side locking (#366)
Browse files Browse the repository at this point in the history
* Added background side locking

* Fix clang format

---------

Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com>
  • Loading branch information
TrickyLeifa and Salanto authored Jul 20, 2024
1 parent d8ec4cc commit c24c3ea
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ bin/libcore.a
doxygen/html

.vscode/
*.TMP
3 changes: 2 additions & 1 deletion src/aoclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down Expand Up @@ -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");
}
Expand Down
9 changes: 9 additions & 0 deletions src/aoclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions src/area_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/area_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand Down
23 changes: 22 additions & 1 deletion src/commands/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/packet/packet_ms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("..\\", "");
Expand Down
2 changes: 1 addition & 1 deletion src/packet/packet_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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=============");

Expand Down

0 comments on commit c24c3ea

Please sign in to comment.