Record claimed code items, and other misc DB fixes

* Create new table to store redeemed codes
* Check if a player already used a code when using /redeem
* Change Coordinate columns to non-plural form
* Fixed EmailItems unique constraint not being specific enough
* Bumped DB version to 3
This commit is contained in:
CakeLancelot
2021-01-18 20:44:02 -06:00
parent 74af1ad173
commit 04a17ed862
5 changed files with 104 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
#include "CNShardServer.hpp"
#include "CNStructs.hpp"
#include "ChatManager.hpp"
#include "Database.hpp"
#include "PlayerManager.hpp"
#include "TransportManager.hpp"
#include "TableData.hpp"
@@ -754,6 +755,12 @@ void redeemCommand(std::string full, std::vector<std::string>& args, CNSocket* s
}
Player* plr = PlayerManager::getPlayer(sock);
if (Database::isCodeRedeemed(plr->iID, code)) {
ChatManager::sendServerMessage(sock, "/redeem: You have already redeemed this code item");
return;
}
int itemCount = ItemManager::CodeItems[code].size();
int slots[4];
@@ -772,6 +779,8 @@ void redeemCommand(std::string full, std::vector<std::string>& args, CNSocket* s
plr->Inven[slots[i]] = { 999, 999, 999, 0 }; // temp item; overwritten later
}
Database::recordCodeRedemption(plr->iID, code);
for (int i = 0; i < itemCount; i++) {
std::pair<int32_t, int32_t> item = ItemManager::CodeItems[code][i];
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);