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

feat: deletion restrictions #1611

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
55 changes: 55 additions & 0 deletions dCommon/dEnums/eCSRCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef __ECSRCOMMAND__H__
#define __ECSRCOMMAND__H__

#include <cstdint>

enum class eCSRCommand : uint32_t {
QUERY_SERVER_STATUS = 0,
QUERY_CHARACTER_LOCATION,
QUERY_CHARACTER_ONLINE_STATUS,
INVENTORY_ADD_ITEM,
INVENTORY_DELETE_ITEM,
MODERATE_MUTE_ACCOUNT,
MODERATE_BAN_ACCOUNT,
MODERATE_EDUCATE_CHARACTER,
MODERATE_KICK_CHARACTER,
MODERATE_WARN_CHARACTER,
MODERATE_RENAME_CHARACTER,
MODERATE_DELETE_CHARACTER_FRIEND,
MODERATE_KILL_CHARACTER,
UPDATE_CHARACTER_HEALTH,
UPDATE_CHARACTER_ARMOR,
UPDATE_CHARACTER_IMAGINATION,
UPDATE_CHARACTER_MAX_HEALTH,
UPDATE_CHARACTER_MAX_ARMOR,
UPDATE_CHARACTER_MAX_IMAGINATION,
UPDATE_CHARACTER_CURRENCY,
UPDATE_CHARACTER_REPUTATION,
UPDATE_CHARACTER_LEGO_SCORE,
UPDATE_CHARACTER_EMOTES,
UPDATE_CHARACTER_ADD_ACHIEVEMENT,
UPDATE_CHARACTER_COMPLETE_ACHIEVEMENT,
UPDATE_CHARACTER_REMOVE_ACHIEVEMENT,
UPDATE_CHARACTER_POSITION_OFFLINE,
UPDATE_CHARACTER_INV_SLOT_AMOUNT,
UTILITY_SAVE_CHARACTER,
UTILITY_SEND_MAIL,
UTILITY_GIVE_ITEM_TO_ALL_PLAYERS_ONLINE,
METRICS_CONFIGURE,
DISABLE_ZONE,
INIT_DONATION_AMOUNT,
KILL_SERVERS_COUNTDOWN,
DISABLE_FAQ,
THROTTLEQUEUE,
GATEGM_ACCESS,
RECONNECT_CRISP,
MODERATE_KICK_ACCOUNT,
TOGGLE_CRISP_SERVER,
QUICK_DRAIN_SERVER,
QUICK_DRAIN_SERVER_RENEW,
REPLICATE_CHARACTER,
GET_SERVER_STATUS,
RELOAD_SERVER_INIS
};

#endif //!__ECSRCOMMAND__H__
16 changes: 16 additions & 0 deletions dCommon/dEnums/eDeletionRestrictionsCheckType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __EDELETIONRESTRICTIONSCHECKTYPE__H__
#define __EDELETIONRESTRICTIONSCHECKTYPE__H__

#include <cstdint>

enum class eDeletionRestrictionsCheckType : uint32_t {
INCLUDE_LOTS,
EXCLUDE_LOTS,
ANY_OF_THESE,
ALL_OF_THESE,
WHILE_IN_ZONE,
ALWAYS_RESTRICTED,
MAX
};

#endif //!__EDELETIONRESTRICTIONSCHECKTYPE__H__
3 changes: 3 additions & 0 deletions dDatabase/CDClientDatabase/CDClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "CDRailActivatorComponent.h"
#include "CDRewardCodesTable.h"
#include "CDPetComponentTable.h"
#include "CDDeletionRestrictionsTable.h"

#ifndef CDCLIENT_CACHE_ALL
// Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory.
Expand Down Expand Up @@ -103,6 +104,7 @@ DEFINE_TABLE_STORAGE(CDSkillBehaviorTable);
DEFINE_TABLE_STORAGE(CDTamingBuildPuzzleTable);
DEFINE_TABLE_STORAGE(CDVendorComponentTable);
DEFINE_TABLE_STORAGE(CDZoneTableTable);
DEFINE_TABLE_STORAGE(CDDeletionRestrictionsTable)

void CDClientManager::LoadValuesFromDatabase() {
if (!CDClientDatabase::isConnected) {
Expand Down Expand Up @@ -150,6 +152,7 @@ void CDClientManager::LoadValuesFromDatabase() {
CDTamingBuildPuzzleTable::Instance().LoadValuesFromDatabase();
CDVendorComponentTable::Instance().LoadValuesFromDatabase();
CDZoneTableTable::Instance().LoadValuesFromDatabase();
CDDeletionRestrictionsTable::Instance().LoadValuesFromDatabase();
}

void CDClientManager::LoadValuesFromDefaults() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "CDDeletionRestrictionsTable.h"
#include "GeneralUtils.h"
#include "eDeletionRestrictionsCheckType.h"

CDDeletionRestriction CDDeletionRestrictionsTable::Default = {
.id = 0,
.restricted = false,
.ids = {},
.checkType = eDeletionRestrictionsCheckType::MAX
};

void CDDeletionRestrictionsTable::LoadValuesFromDatabase() {
auto& entries = GetEntriesMutable();

auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM DeletionRestrictions");
while (!tableData.eof()) {
CDDeletionRestriction entry;
entry.id = tableData.getIntField("id", -1);
if (entry.id == -1) continue;
entry.restricted = tableData.getIntField("restricted", -1);
const std::string raw_ids = tableData.getStringField("ids", "");
if (!raw_ids.empty()) {
for (const auto& idstr : GeneralUtils::SplitString(raw_ids, ',')) {
if (!idstr.empty()) {
const auto id = GeneralUtils::TryParse<int32_t>(idstr);
if (id) entry.ids.push_back(id.value());
}
}
}
entry.checkType = static_cast<eDeletionRestrictionsCheckType>(tableData.getIntField("checkType", static_cast<int>(eDeletionRestrictionsCheckType::MAX)));

entries.insert(std::make_pair(entry.id, entry));
tableData.nextRow();
}

}

const CDDeletionRestriction& CDDeletionRestrictionsTable::GetByID(uint32_t id) {
auto& entries = GetEntries();
const auto& it = entries.find(id);
if (it != entries.end()) {
return it->second;
}
return Default;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "CDTable.h"

enum class eDeletionRestrictionsCheckType : uint32_t;

struct CDDeletionRestriction {
uint32_t id;
bool restricted;
std::vector<uint32_t> ids;
eDeletionRestrictionsCheckType checkType;
};

class CDDeletionRestrictionsTable : public CDTable<CDDeletionRestrictionsTable, std::map<uint32_t, CDDeletionRestriction>> {
public:
void LoadValuesFromDatabase();
const CDDeletionRestriction& GetByID(uint32_t id);

static CDDeletionRestriction Default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if this could be not public, and instead use a getter which returns a const reference to a default struct so this cannot be modified accidentally, alongside removing a static variable in place for a static function and an unnamed namespace member.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell that to itemComponentTable

};
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CDItemComponent {
uint32_t itemRating; //!< ???
bool isTwoHanded; //!< Whether or not the item is double handed
uint32_t minNumRequired; //!< Maybe the minimum number required for a mission, or to own this object?
uint32_t delResIndex; //!< ???
uint32_t delResIndex; //!< Relates to DeletionRestrictions Table
uint32_t currencyLOT; //!< ???
uint32_t altCurrencyCost; //!< ???
std::string subItems; //!< A comma seperate string of sub items (maybe for multi-itemed things like faction test gear set)
Expand Down
4 changes: 3 additions & 1 deletion dDatabase/CDClientDatabase/CDClientTables/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
"CDSkillBehaviorTable.cpp"
"CDTamingBuildPuzzleTable.cpp"
"CDVendorComponentTable.cpp"
"CDZoneTableTable.cpp" PARENT_SCOPE)
"CDZoneTableTable.cpp"
"CDDeletionRestrictionsTable.cpp"
PARENT_SCOPE)
42 changes: 42 additions & 0 deletions dGame/dInventory/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#include "eUseItemResponse.h"
#include "dZoneManager.h"
#include "ChatPackets.h"
#include "eDeletionRestrictionsCheckType.h"

#include "CDBrickIDTableTable.h"
#include "CDObjectSkillsTable.h"
#include "CDComponentsRegistryTable.h"
#include "CDPackageComponentTable.h"
#include "CDDeletionRestrictionsTable.h"

namespace {
const std::map<std::string, std::string> ExtraSettingAbbreviations = {
Expand Down Expand Up @@ -568,3 +570,43 @@ void Item::LoadConfigXml(const tinyxml2::XMLElement& i) {
config.push_back(LDFBaseData::DataFromString(value));
}
}

bool Item::CanDeleteItem(Item* item) {
if (!item) return false;
// TODO:
// Check if item is being possessed
// Check if the owner is mounting item? (how is this different than the above)
// Allow GM 9 to freely delete
// Finally, check Deletion Restriction
const auto& itemComponent = item->inventory->FindItemComponent(item->lot);
if (itemComponent.delResIndex == -1) return true;
return CheckDeletionRestriction(itemComponent.delResIndex, item->lot);
}

bool Item::CheckDeletionRestriction(uint32_t delResIndex, LOT item) {
auto* delresTable = CDClientManager::GetTable<CDDeletionRestrictionsTable>();
const auto restriction = delresTable->GetByID(delResIndex);

switch(restriction.checkType) {
case eDeletionRestrictionsCheckType::INCLUDE_LOTS:
if (std::ranges::find(restriction.ids, item) != restriction.ids.end()) return false;
else return true;
case eDeletionRestrictionsCheckType::EXCLUDE_LOTS:
if (std::ranges::find(restriction.ids, item) != restriction.ids.end()) return true;
else return false;
case eDeletionRestrictionsCheckType::ANY_OF_THESE:
// TODO: Implement
return true;
case eDeletionRestrictionsCheckType::ALL_OF_THESE:
// TODO: Implement
return true;
case eDeletionRestrictionsCheckType::WHILE_IN_ZONE:
if (std::ranges::find(restriction.ids, Game::zoneManager->GetZoneID().GetMapID()) != restriction.ids.end()) return false;
else return true;
case eDeletionRestrictionsCheckType::ALWAYS_RESTRICTED:
return false;
case eDeletionRestrictionsCheckType::MAX:
default:
return true;
}
Comment on lines +590 to +611
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider instead a bool toReturn before the switch and a single return at the bottom of the function instead. This would also allow you to greatly simplify the logic in the loop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, that would make too much sense /s

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of reasons for the verbose-ness of this currently is that I wanted to make sure I got the logic correct. now that I have, I will simplify it

}
7 changes: 7 additions & 0 deletions dGame/dInventory/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ class Item final

void LoadConfigXml(const tinyxml2::XMLElement& i);

bool CanDeleteItem(Item* item);

bool CheckDeletionRestriction(uint32_t delResIndex, LOT item);

bool CheckDeletionRestrictionRecursion(std::set<uint32_t>& delResIndexs, uint32_t delResIndex);


private:
/**
* The object ID of this item
Expand Down
Loading