feat(mail): notify online recipients of new mail on any world

Mail sent to someone who is not in the sender's world (system mail with
no address, and all player-to-player mail) now reaches them: the world
sends a MailNotify (Chat::MAIL, unused until now) to the chat server,
which passes it to the world the receiver is in, and that world sends
the client its unread count with a NewMail NotificationResponse.
Receivers in the same world are told directly. Player-to-player mail
did not notify the receiver at all before.

Replaces the TODO in Mail::SendMail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-27 08:38:39 -05:00
parent c96a771655
commit d43cdef104
7 changed files with 78 additions and 1 deletions

View File

@@ -22,6 +22,8 @@
#include "Item.h"
#include "MissionComponent.h"
#include "ChatPackets.h"
#include "ChatServerLink.h"
#include "eObjectBits.h"
#include "Character.h"
#include "dZoneManager.h"
#include "WorldConfig.h"
@@ -149,6 +151,7 @@ namespace Mail {
Database::Get()->InsertNewMail(mailInfo);
DashboardNotify::Changed("mail", mailInfo.receiverId);
NotifyNewMail(mailInfo.receiverId);
if (hasAttachment) {
EconomyLedger::RecordTransfer({ .method = IEconomyLedger::eTransferMethod::MAIL_SENT, .itemId = sentItemId,
.newItemId = mailInfo.itemID, .lot = mailInfo.itemLOT, .count = static_cast<uint32_t>(mailInfo.itemCount),
@@ -431,8 +434,35 @@ void Mail::SendMail(const LWOOBJID sender, const std::string& senderName, LWOOBJ
Database::Get()->InsertNewMail(mailInsert);
DashboardNotify::Changed("mail", mailInsert.receiverId);
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) return; // TODO: Echo to chat server
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
NotifyNewMail(recipient);
return;
}
NotificationResponse response;
response.status = eNotificationResponse::NewMail;
response.Send(sysAddr);
}
bool Mail::NotifyNewMailHere(LWOOBJID receiver) {
// Mail stores the character ID; the player's object ID also carries the character bit
GeneralUtils::SetBit(receiver, eObjectBits::CHARACTER);
auto* const player = Game::entityManager->GetEntity(receiver);
if (!player || !player->IsPlayer()) return false;
auto* const character = player->GetCharacter();
if (!character) return false;
NotificationResponse response;
response.status = eNotificationResponse::NewMail;
response.mailCount = Database::Get()->GetUnreadMailCount(character->GetID());
response.Send(player->GetSystemAddress());
return true;
}
void Mail::NotifyNewMail(const LWOOBJID receiver) {
if (NotifyNewMailHere(receiver)) return;
ChatPackets::MailNotify notify;
notify.receiverID = receiver;
GeneralUtils::SetBit(notify.receiverID, eObjectBits::CHARACTER);
ChatServerLink::Send(notify, MEDIUM_PRIORITY);
}

View File

@@ -210,6 +210,13 @@ namespace Mail {
void HandleMail(RakNet::BitStream& inStream, const SystemAddress& sysAddr, Entity* player);
// Tells the receiver about their unread mail if they are a player in this world. Returns false if they are not.
bool NotifyNewMailHere(LWOOBJID receiver);
// Tells the receiver about their new mail wherever they are online: in this world directly, otherwise through the
// chat server to the world they are in.
void NotifyNewMail(LWOOBJID receiver);
void SendMail(
const Entity* recipient,
const std::string& subject,