mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
Notify client of email send failure
This commit is contained in:
parent
a1274756ce
commit
ec23e72215
@ -742,7 +742,7 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
// handle items
|
// handle items
|
||||||
std::vector<sItemBase> attachments;
|
std::vector<sItemBase> attachments;
|
||||||
|
std::vector<int> attSlots;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
sEmailItemInfoFromCL attachment = pkt->aItem[i];
|
sEmailItemInfoFromCL attachment = pkt->aItem[i];
|
||||||
resp.aItem[i] = attachment;
|
resp.aItem[i] = attachment;
|
||||||
@ -750,6 +750,7 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
|
|||||||
|| attachment.ItemInven.iID <= 0 || attachment.ItemInven.iType < 0)
|
|| attachment.ItemInven.iID <= 0 || attachment.ItemInven.iType < 0)
|
||||||
continue; // sanity check
|
continue; // sanity check
|
||||||
attachments.push_back(attachment.ItemInven);
|
attachments.push_back(attachment.ItemInven);
|
||||||
|
attSlots.push_back(attachment.iSlotNum);
|
||||||
// delete item
|
// delete item
|
||||||
plr->Inven[attachment.iSlotNum] = { 0, 0, 0, 0 };
|
plr->Inven[attachment.iSlotNum] = { 0, 0, 0, 0 };
|
||||||
}
|
}
|
||||||
@ -771,7 +772,24 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
|
|||||||
0 // DeleteTime (unimplemented)
|
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
|
// HACK: use set value packet to force GUI taros update
|
||||||
INITSTRUCT(sP_FE2CL_GM_REP_PC_SET_VALUE, tarosResp);
|
INITSTRUCT(sP_FE2CL_GM_REP_PC_SET_VALUE, tarosResp);
|
||||||
|
@ -1739,7 +1739,7 @@ int Database::getNextEmailIndex(int playerID) {
|
|||||||
return (index > 0 ? index + 1 : 1);
|
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);
|
std::lock_guard<std::mutex> lock(dbCrit);
|
||||||
|
|
||||||
sqlite3_exec(db, "BEGIN TRANSACTION;", NULL, NULL, NULL);
|
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;
|
std::cout << "[WARN] Database: Failed to send email" << std::endl;
|
||||||
sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
|
sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send attachments
|
// 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;
|
std::cout << "[WARN] Database: Failed to send email" << std::endl;
|
||||||
sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
|
sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
sqlite3_reset(stmt);
|
sqlite3_reset(stmt);
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL);
|
sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,5 +86,5 @@ namespace Database {
|
|||||||
void deleteEmailAttachments(int playerID, int index, int slot);
|
void deleteEmailAttachments(int playerID, int index, int slot);
|
||||||
void deleteEmails(int playerID, int64_t* indices);
|
void deleteEmails(int playerID, int64_t* indices);
|
||||||
int getNextEmailIndex(int playerID);
|
int getNextEmailIndex(int playerID);
|
||||||
void sendEmail(EmailData* data, std::vector<sItemBase> attachments);
|
bool sendEmail(EmailData* data, std::vector<sItemBase> attachments);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user