-
Notifications
You must be signed in to change notification settings - Fork 173
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
base: main
Are you sure you want to change the base?
Changes from all commits
5e3c869
8f00f16
5ba37ff
3cfbc9d
42cf2b6
0e6cb8a
66cf96a
f6f3cdc
bf58cf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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__ |
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__ |
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; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, that would make too much sense /s There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tell that to itemComponentTable