C# database server: refuse a put that names nothing, one unreadable text

IsUnreadableDocument follows the spec's Required fields rule (blank storedAt, empty payload, blank source ids and tags join blank schemaId/recordKey); ForUnreadableMessage is the single owner of the fixed text. Tests replay the blankFields vectors on receipt and legacy connections.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Libby 2026-11-08 21:26:49 +00:00
commit bc9a1842f5
4 changed files with 104 additions and 9 deletions

View file

@ -390,15 +390,24 @@ namespace GameCult.Networking
}
}
// A refusal: error.v1 carrying the write's id for a receipt-capable connection, the v0 error for any other.
// An empty or blank schemaId or recordKey names no record: refused as a frame that does not read, exactly as the Rust
// server's decoder refuses it (write-receipt.md, "Required fields"), never handed to the store.
// A write that names nothing is refused as a frame that does not read, exactly as the Rust server's decoder refuses it
// (write-receipt.md, "Required fields"), never handed to the store: a blank schemaId, recordKey or storedAt, an empty
// payload, and a source id or tag that is present but blank.
private static bool IsUnreadableWriteTarget(string? schemaId, string? recordKey) =>
string.IsNullOrWhiteSpace(schemaId) || string.IsNullOrWhiteSpace(recordKey);
private static CultNetErrorMessage UnreadableWriteTarget() =>
CultNetErrorMessage.ForMessageInvalid("message", "the message could not be read");
private static bool IsUnreadableDocument(CultNetRawDocumentRecord document) =>
IsUnreadableWriteTarget(document.SchemaId, document.RecordKey)
|| string.IsNullOrWhiteSpace(document.StoredAt)
|| document.Payload == null || document.Payload.Length == 0
|| IsPresentButBlank(document.SourceRuntimeId)
|| IsPresentButBlank(document.SourceAgentId)
|| IsPresentButBlank(document.SourceRole)
|| document.Tags != null && document.Tags.Any(tag => string.IsNullOrWhiteSpace(tag));
private static bool IsPresentButBlank(string? value) => value != null && string.IsNullOrWhiteSpace(value);
// A refusal: error.v1 carrying the write's id for a receipt-capable connection, the v0 error for any other.
private static void Refuse(CultNetServerPeer peer, CultNetReceiptedWrite? write, CultNetErrorMessage error)
{
if (write != null) write.Refused(error);
@ -439,9 +448,9 @@ namespace GameCult.Networking
return;
}
if (IsUnreadableWriteTarget(message.Document!.SchemaId, message.Document.RecordKey))
if (IsUnreadableDocument(message.Document!))
{
Refuse(peer, write, UnreadableWriteTarget());
Refuse(peer, write, CultNetErrorMessage.ForUnreadableMessage());
return;
}
@ -522,7 +531,7 @@ namespace GameCult.Networking
if (IsUnreadableWriteTarget(message.SchemaId, message.RecordKey))
{
Refuse(peer, write, UnreadableWriteTarget());
Refuse(peer, write, CultNetErrorMessage.ForUnreadableMessage());
return;
}