Document CultCache and CultNet public surface

This commit is contained in:
Meta Vens 2026-05-08 13:11:01 +01:00
commit 322cda12a6
11 changed files with 995 additions and 5 deletions

View file

@ -8,15 +8,36 @@ using GameCult.Caching.MessagePack;
namespace GameCult.Networking
{
/// <summary>
/// Optional metadata applied when creating CultNet document messages.
/// </summary>
public sealed class CultNetDocumentMessageOptions
{
/// <summary>
/// Gets or sets an explicit storage timestamp.
/// </summary>
public string? StoredAt { get; set; }
/// <summary>
/// Gets or sets the runtime that produced the document.
/// </summary>
public string? SourceRuntimeId { get; set; }
/// <summary>
/// Gets or sets the agent that produced the document.
/// </summary>
public string? SourceAgentId { get; set; }
/// <summary>
/// Gets or sets the role that produced the document.
/// </summary>
public string? SourceRole { get; set; }
/// <summary>
/// Gets or sets optional document tags.
/// </summary>
public string[]? Tags { get; set; }
}
/// <summary>
/// Binds a CultCache document type to CultNet payload serialization.
/// </summary>
public sealed class CultNetDocumentBinding
{
internal CultNetDocumentBinding(
@ -31,11 +52,26 @@ namespace GameCult.Networking
PayloadDeserializer = payloadDeserializer;
}
/// <summary>
/// Gets the bound document type.
/// </summary>
public Type DocumentType { get; }
/// <summary>
/// Gets the bound schema identifier.
/// </summary>
public string SchemaId { get; }
/// <summary>
/// Gets the payload serializer.
/// </summary>
public Func<object, byte[]> PayloadSerializer { get; }
/// <summary>
/// Gets the payload deserializer.
/// </summary>
public Func<byte[], object> PayloadDeserializer { get; }
/// <summary>
/// Creates a document binding for a typed CultCache document.
/// </summary>
public static CultNetDocumentBinding ForDocument<T>(
CultDocumentRegistry? registry = null,
Func<T, byte[]>? payloadSerializer = null,
@ -59,6 +95,9 @@ namespace GameCult.Networking
}
}
/// <summary>
/// Creates and applies CultNet messages that replicate CultCache documents.
/// </summary>
public sealed class CultNetDocumentRegistry
{
private readonly CultDocumentRegistry _documents;
@ -66,6 +105,9 @@ namespace GameCult.Networking
new(StringComparer.Ordinal);
private readonly Dictionary<Type, CultNetDocumentBinding> _bindingsByType = new();
/// <summary>
/// Creates a document registry with optional bindings.
/// </summary>
public CultNetDocumentRegistry(
CultDocumentRegistry? documents = null,
IEnumerable<CultNetDocumentBinding>? bindings = null)
@ -82,6 +124,9 @@ namespace GameCult.Networking
}
}
/// <summary>
/// Registers a document binding.
/// </summary>
public CultNetDocumentRegistry Register(CultNetDocumentBinding binding)
{
_bindingsBySchemaId[binding.SchemaId] = binding;
@ -89,16 +134,25 @@ namespace GameCult.Networking
return this;
}
/// <summary>
/// Gets a binding by schema identifier.
/// </summary>
public CultNetDocumentBinding? GetBySchemaId(string schemaId)
{
return _bindingsBySchemaId.TryGetValue(schemaId, out var binding) ? binding : null;
}
/// <summary>
/// Gets a binding by CLR document type.
/// </summary>
public CultNetDocumentBinding? GetByDocumentType(Type documentType)
{
return _bindingsByType.TryGetValue(documentType, out var binding) ? binding : null;
}
/// <summary>
/// Creates a document delete message.
/// </summary>
public CultNetDocumentDeleteMessage CreateDocumentDeleteMessage(
string messageId,
string schemaId,
@ -112,6 +166,9 @@ namespace GameCult.Networking
};
}
/// <summary>
/// Creates a raw document put message for a typed document.
/// </summary>
public CultNetDocumentPutRawMessage CreateRawDocumentPutMessage<T>(
string messageId,
CultRecordHandle<T> handle,
@ -141,6 +198,9 @@ namespace GameCult.Networking
};
}
/// <summary>
/// Creates a snapshot request message.
/// </summary>
public CultNetSnapshotRequestMessage CreateSnapshotRequest(
string messageId,
IEnumerable<string>? schemaIds = null,
@ -154,6 +214,9 @@ namespace GameCult.Networking
};
}
/// <summary>
/// Creates a raw snapshot response from the cache.
/// </summary>
public CultNetSnapshotResponseRawMessage CreateRawSnapshotResponse(
CultCache cache,
string messageId,
@ -225,6 +288,9 @@ namespace GameCult.Networking
};
}
/// <summary>
/// Applies a raw document put message to a cache.
/// </summary>
public async Task<object> ApplyRawDocumentPutMessageAsync(
CultCache cache,
CultNetDocumentPutRawMessage message)
@ -253,6 +319,9 @@ namespace GameCult.Networking
return document;
}
/// <summary>
/// Applies a raw document put message and returns the typed document.
/// </summary>
public async Task<T> ApplyRawDocumentPutMessageAsync<T>(
CultCache cache,
CultNetDocumentPutRawMessage message)
@ -261,6 +330,9 @@ namespace GameCult.Networking
return (T)await ApplyRawDocumentPutMessageAsync(cache, message).ConfigureAwait(false);
}
/// <summary>
/// Applies all documents from a raw snapshot response.
/// </summary>
public async Task<IReadOnlyList<object>> ApplyRawSnapshotResponseAsync(
CultCache cache,
CultNetSnapshotResponseRawMessage response)
@ -280,6 +352,9 @@ namespace GameCult.Networking
return applied;
}
/// <summary>
/// Applies all typed documents from a raw snapshot response.
/// </summary>
public async Task<IReadOnlyList<T>> ApplyRawSnapshotResponseAsync<T>(
CultCache cache,
CultNetSnapshotResponseRawMessage response)

View file

@ -8,21 +8,33 @@ namespace GameCult.Networking
/// </summary>
public static class CultNetSchemaMessageSerialization
{
/// <summary>
/// Gets the serializer options used for CultNet schema-v0 messages.
/// </summary>
public static readonly MessagePackSerializerOptions Options =
MessagePackSerializerOptions.Standard.WithSecurity(MessagePackSecurity.UntrustedData);
/// <summary>
/// Serializes a typed CultNet schema message.
/// </summary>
public static byte[] Serialize<T>(T message) where T : ICultNetSchemaMessage
{
if (message == null) throw new ArgumentNullException(nameof(message));
return MessagePackSerializer.Serialize(message, Options);
}
/// <summary>
/// Deserializes a typed CultNet schema message.
/// </summary>
public static T Deserialize<T>(byte[] payload) where T : ICultNetSchemaMessage
{
if (payload == null) throw new ArgumentNullException(nameof(payload));
return MessagePackSerializer.Deserialize<T>(payload, Options);
}
/// <summary>
/// Deserializes a CultNet schema message by inspecting its schema version.
/// </summary>
public static ICultNetSchemaMessage Deserialize(byte[] payload)
{
if (payload == null) throw new ArgumentNullException(nameof(payload));
@ -54,7 +66,7 @@ namespace GameCult.Networking
};
}
[MessagePackObject]
[MessagePackObject(AllowPrivate = true)]
internal sealed class CultNetSchemaHeader
{
[Key("schemaVersion")] public string SchemaVersion { get; set; } = string.Empty;

View file

@ -8,7 +8,13 @@ namespace GameCult.Networking
/// </summary>
public static class CultNetWireContracts
{
/// <summary>
/// schema v0 contract identifier.
/// </summary>
public const string SchemaV0 = "cultnet.schema.v0";
/// <summary>
/// game cult networking v0 contract identifier.
/// </summary>
public const string GameCultNetworkingV0 = "gamecult.networking.v0";
}
@ -17,19 +23,61 @@ namespace GameCult.Networking
/// </summary>
public static class CultNetSchemaVersions
{
/// <summary>
/// hello contract identifier.
/// </summary>
public const string Hello = "cultnet.hello.v0";
/// <summary>
/// login contract identifier.
/// </summary>
public const string Login = "cultnet.login.v0";
/// <summary>
/// register contract identifier.
/// </summary>
public const string Register = "cultnet.register.v0";
/// <summary>
/// verify contract identifier.
/// </summary>
public const string Verify = "cultnet.verify.v0";
/// <summary>
/// login success contract identifier.
/// </summary>
public const string LoginSuccess = "cultnet.login_success.v0";
/// <summary>
/// error contract identifier.
/// </summary>
public const string Error = "cultnet.error.v0";
/// <summary>
/// sample change name contract identifier.
/// </summary>
public const string SampleChangeName = "cultnet.sample.change_name.v0";
/// <summary>
/// sample chat contract identifier.
/// </summary>
public const string SampleChat = "cultnet.sample.chat.v0";
/// <summary>
/// document delete contract identifier.
/// </summary>
public const string DocumentDelete = "cultnet.document_delete.v0";
/// <summary>
/// document put raw contract identifier.
/// </summary>
public const string DocumentPutRaw = "cultnet.document_put_raw.v0";
/// <summary>
/// snapshot request contract identifier.
/// </summary>
public const string SnapshotRequest = "cultnet.snapshot_request.v0";
/// <summary>
/// snapshot response raw contract identifier.
/// </summary>
public const string SnapshotResponseRaw = "cultnet.snapshot_response_raw.v0";
/// <summary>
/// schema catalog request contract identifier.
/// </summary>
public const string SchemaCatalogRequest = "cultnet.schema_catalog_request.v0";
/// <summary>
/// schema catalog response contract identifier.
/// </summary>
public const string SchemaCatalogResponse = "cultnet.schema_catalog_response.v0";
}
@ -38,155 +86,413 @@ namespace GameCult.Networking
/// </summary>
public interface ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version carried by this message.
/// </summary>
string SchemaVersion { get; set; }
}
/// <summary>
/// CultNet hello message used to announce a runtime and its supported contracts.
/// </summary>
[MessagePackObject]
public class CultNetHelloMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.Hello;
/// <summary>
/// Gets or sets the runtime id.
/// </summary>
[Key("runtimeId")] public string RuntimeId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the runtime kind.
/// </summary>
[Key("runtimeKind")] public string RuntimeKind { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the agent id.
/// </summary>
[Key("agentId")] public string? AgentId { get; set; }
/// <summary>
/// Gets or sets the role.
/// </summary>
[Key("role")] public string? Role { get; set; }
/// <summary>
/// Gets or sets the display name.
/// </summary>
[Key("displayName")] public string? DisplayName { get; set; }
/// <summary>
/// Gets or sets the supported document types.
/// </summary>
[Key("supportedDocumentTypes")] public string[]? SupportedDocumentTypes { get; set; }
/// <summary>
/// Gets or sets the supported message versions.
/// </summary>
[Key("supportedMessageVersions")] public string[]? SupportedMessageVersions { get; set; }
/// <summary>
/// Gets or sets the supports schema catalog.
/// </summary>
[Key("supportsSchemaCatalog")] public bool SupportsSchemaCatalog { get; set; }
}
/// <summary>
/// CultNet login request message.
/// </summary>
[MessagePackObject]
public class CultNetLoginMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.Login;
/// <summary>
/// Gets or sets the nonce.
/// </summary>
[Key("nonce")] public string Nonce { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the auth.
/// </summary>
[Key("auth")] public string Auth { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the password.
/// </summary>
[Key("password")] public string Password { get; set; } = string.Empty;
}
/// <summary>
/// CultNet registration request message.
/// </summary>
[MessagePackObject]
public class CultNetRegisterMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.Register;
/// <summary>
/// Gets or sets the nonce.
/// </summary>
[Key("nonce")] public string Nonce { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the email.
/// </summary>
[Key("email")] public string Email { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the password.
/// </summary>
[Key("password")] public string Password { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the name.
/// </summary>
[Key("name")] public string Name { get; set; } = string.Empty;
}
/// <summary>
/// CultNet session verification request message.
/// </summary>
[MessagePackObject]
public class CultNetVerifyMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.Verify;
/// <summary>
/// Gets or sets the nonce.
/// </summary>
[Key("nonce")] public string Nonce { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the session.
/// </summary>
[Key("session")] public string Session { get; set; } = string.Empty;
}
/// <summary>
/// CultNet message returned after successful session verification.
/// </summary>
[MessagePackObject]
public class CultNetLoginSuccessMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.LoginSuccess;
/// <summary>
/// Gets or sets the nonce.
/// </summary>
[Key("nonce")] public string Nonce { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the session.
/// </summary>
[Key("session")] public string Session { get; set; } = string.Empty;
}
/// <summary>
/// CultNet error response message.
/// </summary>
[MessagePackObject]
public class CultNetErrorMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.Error;
/// <summary>
/// Gets or sets the error.
/// </summary>
[Key("error")] public string Error { get; set; } = string.Empty;
}
/// <summary>
/// Sample CultNet message used by development clients to change a display name.
/// </summary>
[MessagePackObject]
public class CultNetSampleChangeNameMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.SampleChangeName;
/// <summary>
/// Gets or sets the name.
/// </summary>
[Key("name")] public string Name { get; set; } = string.Empty;
}
/// <summary>
/// Sample CultNet chat message used by development clients.
/// </summary>
[MessagePackObject]
public class CultNetSampleChatMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.SampleChat;
/// <summary>
/// Gets or sets the text.
/// </summary>
[Key("text")] public string Text { get; set; } = string.Empty;
}
/// <summary>
/// Raw document record carried over CultNet.
/// </summary>
[MessagePackObject]
public class CultNetRawDocumentRecord
{
/// <summary>
/// Gets or sets the schema id.
/// </summary>
[Key("schemaId")] public string SchemaId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the record key.
/// </summary>
[Key("recordKey")] public string RecordKey { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the stored at.
/// </summary>
[Key("storedAt")] public string StoredAt { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the payload encoding.
/// </summary>
[Key("payloadEncoding")] public string PayloadEncoding { get; set; } = "messagepack";
/// <summary>
/// Gets or sets the payload.
/// </summary>
[Key("payload")] public byte[] Payload { get; set; } = Array.Empty<byte>();
/// <summary>
/// Gets or sets the source runtime id.
/// </summary>
[Key("sourceRuntimeId")] public string? SourceRuntimeId { get; set; }
/// <summary>
/// Gets or sets the source agent id.
/// </summary>
[Key("sourceAgentId")] public string? SourceAgentId { get; set; }
/// <summary>
/// Gets or sets the source role.
/// </summary>
[Key("sourceRole")] public string? SourceRole { get; set; }
/// <summary>
/// Gets or sets the tags.
/// </summary>
[Key("tags")] public string[]? Tags { get; set; }
}
/// <summary>
/// CultNet message requesting deletion of a document record.
/// </summary>
[MessagePackObject]
public class CultNetDocumentDeleteMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.DocumentDelete;
/// <summary>
/// Gets or sets the message id.
/// </summary>
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the schema id.
/// </summary>
[Key("schemaId")] public string SchemaId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the record key.
/// </summary>
[Key("recordKey")] public string RecordKey { get; set; } = string.Empty;
}
/// <summary>
/// CultNet message carrying one raw document record.
/// </summary>
[MessagePackObject]
public class CultNetDocumentPutRawMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.DocumentPutRaw;
/// <summary>
/// Gets or sets the message id.
/// </summary>
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the document.
/// </summary>
[Key("document")] public CultNetRawDocumentRecord Document { get; set; } = new CultNetRawDocumentRecord();
}
/// <summary>
/// CultNet message requesting a document snapshot.
/// </summary>
[MessagePackObject]
public class CultNetSnapshotRequestMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.SnapshotRequest;
/// <summary>
/// Gets or sets the message id.
/// </summary>
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the schema ids.
/// </summary>
[Key("schemaIds")] public string[]? SchemaIds { get; set; }
/// <summary>
/// Gets or sets the record keys.
/// </summary>
[Key("recordKeys")] public string[]? RecordKeys { get; set; }
}
/// <summary>
/// CultNet message returning raw document records from a snapshot request.
/// </summary>
[MessagePackObject]
public class CultNetSnapshotResponseRawMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.SnapshotResponseRaw;
/// <summary>
/// Gets or sets the message id.
/// </summary>
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the documents.
/// </summary>
[Key("documents")] public CultNetRawDocumentRecord[] Documents { get; set; } = Array.Empty<CultNetRawDocumentRecord>();
}
/// <summary>
/// Describes one schema exposed through the CultNet schema catalog.
/// </summary>
[MessagePackObject]
public class CultNetSchemaDescriptor
{
/// <summary>
/// Gets or sets the schema id.
/// </summary>
[Key("schemaId")] public string SchemaId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the kind.
/// </summary>
[Key("kind")] public string Kind { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string? SchemaVersion { get; set; }
/// <summary>
/// Gets or sets the document type.
/// </summary>
[Key("documentType")] public string? DocumentType { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
[Key("title")] public string? Title { get; set; }
/// <summary>
/// Gets or sets the wire contracts.
/// </summary>
[Key("wireContracts")] public string[] WireContracts { get; set; } = Array.Empty<string>();
/// <summary>
/// Gets or sets the content hash.
/// </summary>
[Key("contentHash")] public string ContentHash { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the schema json.
/// </summary>
[Key("schemaJson")] public string? SchemaJson { get; set; }
}
/// <summary>
/// CultNet message requesting schema catalog entries.
/// </summary>
[MessagePackObject]
public class CultNetSchemaCatalogRequestMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.SchemaCatalogRequest;
/// <summary>
/// Gets or sets the message id.
/// </summary>
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the include schema json.
/// </summary>
[Key("includeSchemaJson")] public bool IncludeSchemaJson { get; set; }
/// <summary>
/// Gets or sets the schema ids.
/// </summary>
[Key("schemaIds")] public string[]? SchemaIds { get; set; }
/// <summary>
/// Gets or sets the kinds.
/// </summary>
[Key("kinds")] public string[]? Kinds { get; set; }
}
/// <summary>
/// CultNet message returning schema catalog entries.
/// </summary>
[MessagePackObject]
public class CultNetSchemaCatalogResponseMessage : ICultNetSchemaMessage
{
/// <summary>
/// Gets or sets the schema version.
/// </summary>
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.SchemaCatalogResponse;
/// <summary>
/// Gets or sets the message id.
/// </summary>
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the schemas.
/// </summary>
[Key("schemas")] public CultNetSchemaDescriptor[] Schemas { get; set; } = Array.Empty<CultNetSchemaDescriptor>();
}
}

View file

@ -17,6 +17,9 @@ namespace GameCult.Networking
{
private readonly Dictionary<string, RegisteredSchema> _entries = new Dictionary<string, RegisteredSchema>(StringComparer.Ordinal);
/// <summary>
/// Creates a schema registry with optional initial entries.
/// </summary>
public CultNetSchemaRegistry(IEnumerable<CultNetSchemaRegistration>? entries = null)
{
if (entries == null)
@ -30,6 +33,9 @@ namespace GameCult.Networking
}
}
/// <summary>
/// Adds or replaces one schema registration.
/// </summary>
public CultNetSchemaRegistry Register(CultNetSchemaRegistration entry)
{
if (entry == null) throw new ArgumentNullException(nameof(entry));
@ -47,6 +53,9 @@ namespace GameCult.Networking
return this;
}
/// <summary>
/// Gets one schema descriptor by schema identifier.
/// </summary>
public CultNetSchemaDescriptor? Get(string schemaId, bool includeSchemaJson = false)
{
if (schemaId == null) throw new ArgumentNullException(nameof(schemaId));
@ -55,6 +64,9 @@ namespace GameCult.Networking
: null;
}
/// <summary>
/// Lists schema descriptors, optionally filtered by identifier or kind.
/// </summary>
public CultNetSchemaDescriptor[] List(
bool includeSchemaJson = false,
IEnumerable<string>? schemaIds = null,
@ -75,6 +87,9 @@ namespace GameCult.Networking
.ToArray();
}
/// <summary>
/// Creates a schema catalog response for a request.
/// </summary>
public CultNetSchemaCatalogResponseMessage CreateCatalogResponse(
CultNetSchemaCatalogRequestMessage request)
{
@ -90,6 +105,9 @@ namespace GameCult.Networking
};
}
/// <summary>
/// Creates a registry populated from embedded CultNet schema resources.
/// </summary>
public static CultNetSchemaRegistry CreateBuiltIn()
{
return new CultNetSchemaRegistry(BuiltInSchemaManifest.Select(LoadEmbeddedRegistration));
@ -98,6 +116,9 @@ namespace GameCult.Networking
private static readonly Lazy<CultNetSchemaRegistry> BuiltInRegistry =
new Lazy<CultNetSchemaRegistry>(CreateBuiltIn);
/// <summary>
/// Gets the lazily initialized built-in schema registry.
/// </summary>
public static CultNetSchemaRegistry BuiltIn => BuiltInRegistry.Value;
private static CultNetSchemaRegistration LoadEmbeddedRegistration(SchemaResourceSpec spec)
@ -357,12 +378,33 @@ namespace GameCult.Networking
/// </summary>
public sealed class CultNetSchemaRegistration
{
/// <summary>
/// Gets or sets the schema identifier.
/// </summary>
public string SchemaId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the schema kind.
/// </summary>
public string Kind { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the wire contracts implemented by the schema.
/// </summary>
public string[] WireContracts { get; set; } = Array.Empty<string>();
/// <summary>
/// Gets or sets the schema document.
/// </summary>
public string SchemaJson { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the message or document schema version.
/// </summary>
public string? SchemaVersion { get; set; }
/// <summary>
/// Gets or sets the document type associated with the schema.
/// </summary>
public string? DocumentType { get; set; }
/// <summary>
/// Gets or sets the display title.
/// </summary>
public string? Title { get; set; }
}
}

View file

@ -4,20 +4,35 @@ using MessagePack;
namespace GameCult.Networking
{
/// <summary>
/// Basic player account document used by the sample networking stack.
/// </summary>
[CultDocument("gamecult.player_data", "gamecult.player_data.v1")]
public class PlayerData
{
/// <summary>
/// Unique player identifier.
/// </summary>
[Key(0)]
[CultIndex]
public Guid PlayerId = Guid.NewGuid();
/// <summary>
/// Player email address.
/// </summary>
[Key(1)]
[CultIndex]
public string Email = string.Empty;
/// <summary>
/// Stored password hash.
/// </summary>
[Key(2)]
public string PasswordHash = string.Empty;
/// <summary>
/// Player display name.
/// </summary>
[Key(3)]
[CultName]
public string Username = string.Empty;