using System; using LiteNetLib; using MessagePack; namespace GameCult.Networking { /// /// Base type for all network messages exchanged by the client and server. /// [Union(0, typeof(LoginMessage)), Union(1, typeof(RegisterMessage)), Union(2, typeof(VerifyMessage)), Union(3, typeof(LoginSuccessMessage)), Union(4, typeof(ErrorMessage)), // Sample application payload tags preserved for cross-runtime compatibility. Union(5, typeof(ChangeNameMessage)), Union(6, typeof(ChatMessage)), Union(7, typeof(SchemaCatalogRequestMessage)), Union(8, typeof(SchemaCatalogResponseMessage)), MessagePackObject] public abstract class Message { /// /// Gets or sets the peer associated with the received message. /// [IgnoreMember] public NetPeer? Peer { get; set; } } /// /// Base type for encrypted messages that carry a nonce. /// public class EncryptedMessage : Message { /// /// Nonce used for AES-GCM encryption of the message payload. /// [Key(0)] public byte[] Nonce = Array.Empty(); } /// /// Requests authentication with an email or username and password. /// [MessagePackObject] public class LoginMessage : EncryptedMessage { /// /// Encrypted email address or username. /// [Key(1)] public byte[] Auth = Array.Empty(); /// /// Encrypted password payload. /// [Key(2)] public byte[] Password = Array.Empty(); } /// /// Requests registration of a new player account. /// [MessagePackObject] public class RegisterMessage : EncryptedMessage { /// /// Encrypted email address. /// [Key(1)] public byte[] Email = Array.Empty(); /// /// Encrypted password payload. /// [Key(2)] public byte[] Password = Array.Empty(); /// /// Encrypted display name payload. /// [Key(3)] public byte[] Name = Array.Empty(); } /// /// Attempts to restore a previously issued session. /// [MessagePackObject] public class VerifyMessage : EncryptedMessage { /// /// Encrypted session identifier. /// [Key(1)] public byte[] Session = Array.Empty(); } /// /// Indicates successful authentication or verification. /// [MessagePackObject] public class LoginSuccessMessage : EncryptedMessage { /// /// Encrypted session identifier. /// [Key(1)] public byte[] Session = Array.Empty(); } /// /// Sends a non-success error back to the client. /// [MessagePackObject] public class ErrorMessage : Message { /// /// Human-readable error text. /// [Key(0)] public string Error = string.Empty; } /// /// Requests a catalog of schemas that the remote runtime can safely exchange. /// [MessagePackObject] public class SchemaCatalogRequestMessage : Message { /// /// Correlation identifier for the discovery request. /// [Key(0)] public string MessageId = string.Empty; /// /// Whether the remote runtime should include inline JSON schema bodies. /// [Key(1)] public bool IncludeSchemaJson; /// /// Optional schema-id filter. /// [Key(2)] public string[]? SchemaIds; /// /// Optional schema-kind filter. /// [Key(3)] public string[]? Kinds; } /// /// Describes one schema that the runtime knows how to exchange safely. /// [MessagePackObject] public class SchemaDescriptorMessage { /// /// Stable canonical schema identifier. /// [Key(0)] public string SchemaId = string.Empty; /// /// Discovery kind such as wire_message, document_payload, or shared_contract. /// [Key(1)] public string Kind = string.Empty; /// /// Optional runtime message schema version. /// [Key(2)] public string? SchemaVersion; /// /// Optional CultCache/CultNet document type name. /// [Key(3)] public string? DocumentType; /// /// Human-facing schema title. /// [Key(4)] public string? Title; /// /// Wire contracts that can transport this schema safely. /// [Key(5)] public string[] WireContracts = Array.Empty(); /// /// SHA-256 hash of the canonical schema JSON. /// [Key(6)] public string ContentHash = string.Empty; /// /// Optional canonical JSON Schema body as a string. /// [Key(7)] public string? SchemaJson; } /// /// Returns the remote runtime's schema catalog for safe exchange planning. /// [MessagePackObject] public class SchemaCatalogResponseMessage : Message { /// /// Correlation identifier matching the request. /// [Key(0)] public string MessageId = string.Empty; /// /// Discovered schemas available for safe exchange. /// [Key(1)] public SchemaDescriptorMessage[] Schemas = Array.Empty(); } }