Notify client of email send failure

This commit is contained in:
Gent S 2020-12-13 19:51:00 -05:00
parent a1274756ce
commit ec23e72215
3 changed files with 25 additions and 6 deletions

View File

@ -742,7 +742,7 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
// handle items
std::vector<sItemBase> attachments;
std::vector<int> attSlots;
for (int i = 0; i < 4; i++) {
sEmailItemInfoFromCL attachment = pkt->aItem[i];
resp.aItem[i] = attachment;
@ -750,6 +750,7 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
|| attachment.ItemInven.iID <= 0 || attachment.ItemInven.iType < 0)
continue; // sanity check
attachments.push_back(attachment.ItemInven);
attSlots.push_back(attachment.iSlotNum);
// delete item
plr->Inven[attachment.iSlotNum] = { 0, 0, 0, 0 };
}
@ -771,7 +772,24 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
0 // DeleteTime (unimplemented)
};
Database::sendEmail(&email, attachments);
if (!Database::sendEmail(&email, attachments)) {
plr->money += cost; // give money back
// give items back
while (!attachments.empty()) {
sItemBase attachment = attachments.back();
plr->Inven[attSlots.back()] = attachment;
attachments.pop_back();
attSlots.pop_back();
}
// send error message
INITSTRUCT(sP_FE2CL_REP_PC_SEND_EMAIL_FAIL, errResp);
errResp.iErrorCode = 1;
errResp.iTo_PCUID = pkt->iTo_PCUID;
sock->sendPacket((void*)&errResp, P_FE2CL_REP_PC_SEND_EMAIL_FAIL, sizeof(sP_FE2CL_REP_PC_SEND_EMAIL_FAIL));
return;
}
// HACK: use set value packet to force GUI taros update
INITSTRUCT(sP_FE2CL_GM_REP_PC_SET_VALUE, tarosResp);

View File

@ -1739,7 +1739,7 @@ int Database::getNextEmailIndex(int playerID) {
return (index > 0 ? index + 1 : 1);
}
void Database::sendEmail(EmailData* data, std::vector<sItemBase> attachments) {
bool Database::sendEmail(EmailData* data, std::vector<sItemBase> attachments) {
std::lock_guard<std::mutex> lock(dbCrit);
sqlite3_exec(db, "BEGIN TRANSACTION;", NULL, NULL, NULL);
@ -1770,7 +1770,7 @@ void Database::sendEmail(EmailData* data, std::vector<sItemBase> attachments) {
std::cout << "[WARN] Database: Failed to send email" << std::endl;
sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
sqlite3_finalize(stmt);
return;
return false;
}
// send attachments
@ -1796,11 +1796,12 @@ void Database::sendEmail(EmailData* data, std::vector<sItemBase> attachments) {
std::cout << "[WARN] Database: Failed to send email" << std::endl;
sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
sqlite3_finalize(stmt);
return;
return false;
}
sqlite3_reset(stmt);
}
sqlite3_finalize(stmt);
sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL);
return true;
}

View File

@ -86,5 +86,5 @@ namespace Database {
void deleteEmailAttachments(int playerID, int index, int slot);
void deleteEmails(int playerID, int64_t* indices);
int getNextEmailIndex(int playerID);
void sendEmail(EmailData* data, std::vector<sItemBase> attachments);
bool sendEmail(EmailData* data, std::vector<sItemBase> attachments);
}