A House Divided A House DividedDocumentation
↵
Changelog
Game Design/Platform

Player Mail

Last updated 2026-10-29
Player wikiMail
Source files

In-game messaging between player characters. Players can send, receive, and report mail from character profile pages and the Notifications page. Game systems (forex notices, loan decisions, party whips) also deliver system mail into the same inbox.

Summary#

Mail is private one-to-one messaging with a subject and body. It is request driven, not part of the turn processor. Each message is one playerMail document with two independent soft-delete flags. A recipient can report a message, which writes a playerMailReports document holding a snapshot of the text for moderators.

Player guide: Mail

Rules#

Sending Mail#

Inbox and Sent Box#

The Mail tab on the Notifications page (/notifications) provides two views:

The client groups inbox and sent mail into threads keyed by counterpart and subject with any leading Re: prefixes stripped (groupMailIntoThreads and normalizeMailSubject in ).

Both views are paginated via the API: default 20 per page, maximum 50, minimum 1, offset floored at 0 (, ). Mail from a sender the recipient has blocked is hidden from the inbox while the block lasts (blockedByRecipient flag, set and cleared by blockPlayer and unblockPlayer in ; a player can block up to MAX_BLOCKED_USERS = 500 users).

System mail (sendSystemMail in ) has no sender character, defaults the sender name to "Forex Market", and cannot be replied to or deleted from a sent box because it has none.

Unread Count#

Unread mail count is returned by both /api/client-nav and /api/auth/me as unreadMailCount. The navbar badge combines unread notifications + unread mail into a single count. The count is toUserId = viewer, read: false, deletedByRecipient: false, blockedByRecipient not true.

Deletion#

Mail uses dual-sided soft-delete:

Mark-read and both delete routes are limited to 30 requests per minute per user (, ).

Reporting#

Any received message that the recipient has not deleted can be reported for abuse. Reports go to the staff mail reports queue.

Admin Mail Reports#

Mail Reports tab in the admin or moderator panel (routes use requireModerator, so moderators and admins both have access). Filterable by status: pending, dismissed, actioned; the list is newest first, default 20 per page, maximum 50 (). The detail view loads the full conversation thread ().

Each report shows the full message body, sender/recipient links, and four actions. The API action names are dismiss, delete_mail, warn, ban ():

Action API value Effect
Dismiss dismiss Sets status to "dismissed"; no player impact
Delete delete_mail Hard-deletes the mail document; sets status to "actioned"
Warn warn Sends a system notification to the sender; sets "actioned"
Ban ban Bans the sender's user account; sets "actioned"

All actions accept an optional admin note (max 500 chars). Ban stores the note as banReason (default "Banned via mail moderation"), records the CEO corporations for share release, withdraws the user's candidacies, and cleans up party elections, leadership and membership.

Shareholder Address#

CEOs can broadcast a message to all current shareholders of their corporation.

API Routes#

Method Path Description
GET /api/mail Inbox (paginated, excludes deleted and blocked)
POST /api/mail Send mail (rate-limited 1/min)
PATCH /api/mail/[id] Mark as read
DELETE /api/mail/[id] Soft-delete from inbox
GET /api/mail/sent Sent box (paginated, excludes deleted)
DELETE /api/mail/sent/[id] Soft-delete from sent box
POST /api/mail/[id]/report Report a message for abuse
GET /api/admin/mail-reports List reports (filterable by status)
GET /api/admin/mail-reports/[id] Report detail with conversation thread
PATCH /api/admin/mail-reports/[id] Admin action (dismiss/delete_mail/warn/ban)
POST /api/corporations/[id]/shareholder-address CEO broadcast (notifications, not mail)

Constants#

Constant Value Source
Subject length 1 to 80 sendMailSchema,
Body length 1 to 1000 sendMailSchema,
Send rate 1 per 60,000 ms per character
Page size default / max 20 / 50 ,
Report rate 10 per 60,000 ms per user
Read and delete rate 30 per 60,000 ms per user ,
MAX_BLOCKED_USERS 500
Admin note max 500 mailReportActionSchema,
Default system sender "Forex Market"
Welcome mail sender / subject "Game Guide" / "Your first moves"
Shareholder address cooldown 12 hours

Data#

playerMail collection#

Written by sendPlayerMail and sendSystemMail/sendSystemMails (src/lib/mail/), plus two direct inserts for currency trade offers in and . Type: . All fields are visible to the two parties through serializePlayerMail (), which turns ids into strings and createdAt into an ISO string; staff see the same fields in the report detail view.

Field Type Description
_id ObjectId Document ID
fromCharacterId ObjectId? Sender character; absent on system mail
fromCharacterName string Sender display name
fromCharacterSequentialId number? Sender sequential ID; absent on system mail
toUserId ObjectId Recipient user
toCharacterId ObjectId Recipient character
toCharacterName string Recipient display name
toCharacterSequentialId number Recipient sequential ID
subject string Subject line (max 80 chars)
body string Message body (max 1000 chars)
read boolean Has recipient read it
deletedByRecipient boolean Recipient soft-delete flag
deletedBySender boolean Sender soft-delete flag
blockedByRecipient boolean? Set while the recipient has the sender blocked; hides it from the inbox and unread counts
createdAt Date Send timestamp

The index playerMail_toUserId_read_deleted on { toUserId, read, deletedByRecipient } serves the unread count that runs on every /api/auth/me call ().

playerMailReports collection#

Written by reportReceivedMail and the admin PATCH route. Not shown to players; read by moderators.

Field Type Description
_id ObjectId Document ID
mailId ObjectId Reference to reported mail
mailSnapshot object? Copy of the message at report time (absent on reports filed before snapshots existed)
reportedByUserId ObjectId User who filed the report
status string "pending", "dismissed" or "actioned"
adminNote string? Admin notes (max 500 chars)
reviewedAt Date? When admin reviewed
reviewedByAdminId ObjectId? Admin who reviewed
createdAt Date Report timestamp

Other documents touched#

Collection Field Access
users blockedUserIds, isBanned Read on send (sendPlayerMail); blockedUserIds written by blockPlayer and unblockPlayer; ban fields written by the admin ban action
characters userId, name, sequentialId Read to resolve the recipient and the report sender
corporations lastShareholderAddressAt, shareholders Shareholder address cooldown and recipients
notifications system rows Staff "New Mail Report", sender "Warning from Admin", shareholder address

Configuration#

Mail has no gameConfig field, era preset or country preset. Every limit above is a code constant. The settings that change behaviour:

Setting Default Where Effect
onboardingChecklistEnabled on the gameState singleton true in fresh worlds, fail-closed (only an explicit true enables it) src/lib/onboarding/featureFlag.ts, seeded by , flipped from the admin Feature Gates panel Controls whether a welcome system mail ("Game Guide") is sent at character creation ()
Player block list empty users.blockedUserIds, cap MAX_BLOCKED_USERS Hides and refuses mail from blocked users
User ban false users.isBanned Banned recipients refuse mail

The in-memory rate limiter is per server process, so its counters reset on restart and are not shared between instances.

Timing#

Mail is not part of the turn processor. Everything is request driven: sending, reading, deleting and reporting run when the player acts. The turn-time and event writers of system mail are listed below; each inserts through sendSystemMail or sendSystemMails during its own phase or request.

Sender name Trigger Source
Forex Market "FX Intervention Failure" to a central bank chair when reserves cannot defend a currency commitment, during the forex turn phase
Forex Market "Limit Order Filled" when a limit order fills
The bank's name Loan approval decisions
Game Guide Character creation, if the onboarding checklist flag is on
Party Whip Hard whip issued to a party's members
<caucus name> Caucus Hard whip issued by a caucus
IMF Restructuring Bondholder haircut in an IMF bailout

Currency trade offers () are inserted directly as player-style mail from the proposing character, not through sendSystemMail.

Unread counts are computed on each /api/client-nav and /api/auth/me call, not cached.

flowchart TD
  P[Player acts] --> POST[POST /api/mail] --> RL[Rate limit 1 per 60 s] --> SPM[sendPlayerMail] --> M[(playerMail)]
  TURN[Turn phase or game event] --> SSM[sendSystemMail] --> M
  M --> CNT[Unread count in /api/client-nav and /api/auth/me]
  M --> REP[POST /api/mail/id/report] --> R[(playerMailReports + staff notifications)]

Worked trace#

Character A (user UA) mails character B (user UB). B has 45 inbox rows, 12 of them unread, and has not blocked A.

  1. A submits subject "Joint fundraiser, Saturday" (26 chars) and a 200 char body. Both fall inside 1 to 80 and 1 to 1000, so sendMailSchema passes.
  2. The limiter key api/mail:<A> is new: count 1, 1 > 1 is false, so the send proceeds and the window resets at now + 60,000 ms.
  3. sendPlayerMail: recipient differs from sender, containsSlur is false, B's character exists, B is not banned and A is not in blockedUserIds. One playerMail row is inserted with read: false, deletedByRecipient: false, deletedBySender: false, createdAt now.
  4. At t = 20 s A tries again: count becomes 2, 2 > 1, so the route returns 429 with retryAfter = ceil((60,000 - 20,000) / 1000) = 40 seconds. The slot is consumed before sendPlayerMail runs, so a send refused later (for instance by the slur filter) still uses up the minute.
  5. B now has 46 inbox rows and 13 unread. GET /api/mail?offset=0&limit=20 returns 20 rows, total 46, unreadCount 13, and hasMore is true because 0 + 20 < 46. A request with limit=200 is clamped to 50; limit=0 becomes 1; limit=abc falls back to 20.
  6. B deletes the message: deletedByRecipient becomes true, deletedBySender is false, so the row stays and A's sent box still shows it.
  7. A deletes the sent copy: deleteSentMail reads the row (deletedByRecipient true), sets deletedBySender true, and because the other side had already deleted it, calls deleteOne. The document is gone.

Block variant: if B had blocked A before step 1, step 3 throws 400 "Cannot send mail to this player", the same text a banned recipient produces. If B blocks A after step 3, setMailHiddenFrom sets blockedByRecipient: true on every row from A's characters to B, so B's inbox total falls and the unread count drops by the unread rows from A. Unblocking unsets the flag and the rows return.

Edge cases and limits#

Invariants#

Invariant Enforcement
A message is hard-deleted exactly when both deletedByRecipient and deletedBySender are true, or an admin deletes it Code in deleteReceivedMail and deleteSentMail; no dedicated test
A message has at most one report reportReceivedMail checks for an existing report by mailId (409). There is no unique index, so two simultaneous reports could both pass; not enforced at the database
A report keeps a copy of the message text it was filed on reportReceivedMail writes mailSnapshot; covered by
Messages containing slurs are never stored from the player send path Filter runs before any database write; covered by
A blocked sender's mail is absent from the inbox and unread count, and the block cannot be detected by the sender ("hides existing mail, refuses new mail, and restores on unblock")
The block list never exceeds 500 Atomic filtered update in blockPlayer;
System mail has no sender id sendSystemMail omits fromCharacterId;
Pending reports survive a world reset playerMailReports is in the preserved seed manifest (, )

Failure and recovery#

Connections#

Tests#

File Covers
Inbox and send routes, including the 429 path
Mark read and delete
Report route
Sent box
Sent-box delete
Report snapshot, slur refusal
Bulk system mail, empty batch
Snapshot fallback in the report detail view
Report list
Block hides and restores mail, block cap
Unread mail count in navbar data

Gaps: no test for the admin action route (PATCH /api/admin/mail-reports/[id]), no test for the shareholder address route, and none for the duplicate-report race.

Known issues and history#

Last checked: 2026-10-29, version 1.18.0

Ask