diff --git a/src/GameCult.Networking/Messages.cs b/src/GameCult.Networking/Messages.cs index b775e298..331dfa43 100644 --- a/src/GameCult.Networking/Messages.cs +++ b/src/GameCult.Networking/Messages.cs @@ -12,6 +12,7 @@ namespace GameCult.Networking 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)), MessagePackObject] @@ -109,27 +110,4 @@ namespace GameCult.Networking [Key(0)] public string Error = string.Empty; } - /// - /// Requests a username change for the authenticated user. - /// - [MessagePackObject] - public class ChangeNameMessage : Message - { - /// - /// Requested new username. - /// - [Key(0)] public string Name = string.Empty; - } - - /// - /// Carries plain chat text. - /// - [MessagePackObject] - public class ChatMessage : Message - { - /// - /// Chat text content. - /// - [Key(0)] public string Text = string.Empty; - } } diff --git a/src/GameCult.Networking/README.md b/src/GameCult.Networking/README.md index 226304c1..3aa7ad3b 100644 --- a/src/GameCult.Networking/README.md +++ b/src/GameCult.Networking/README.md @@ -4,6 +4,9 @@ It is intended for game or game-service scenarios where you want a compact transport layer with a small set of built-in authentication flows rather than a full HTTP stack. +The networking/auth layer is the durable organ. Some payloads in this repo are +just sample application messages riding that organ. + ## Scope The library currently includes: @@ -14,9 +17,18 @@ The library currently includes: - encrypted login, register, and verify flows - signed session-token generation and validation - `PlayerData` integration with `CultCache` +- sample application payloads under `Samples/` The library is focused on the built-in authentication and session flows in this repository. +Keep the distinction clean: + +- auth/session semantics belong to the core library +- application payload contracts should be explicit, versioned, and kept in sync + across runtimes +- if multiple apps share a message contract, they should be able to talk + directly without bespoke translation sludge + ## Main Types - `Message`: base type for all wire messages @@ -25,6 +37,14 @@ The library is focused on the built-in authentication and session flows in this - `Secret`: encryption and signed-token helper methods - `PlayerData`: cache-backed player record type +Sample payloads: + +- `ChangeNameMessage` +- `ChatMessage` + +Those now live under `Samples/` to make it obvious they are example application +messages, not the entire meaning of the library. + ## Authentication Model The built-in flow is: @@ -181,3 +201,11 @@ public class CustomPingMessage : Message ``` If you extend the built-in message set, update the union and serialization model accordingly. + +If you want cross-runtime compatibility with TypeScript, Rust, Python, or +anything else, treat message tags and field keys like CultCache schema: + +- explicit +- stable +- shared +- boring in exactly the useful way diff --git a/src/GameCult.Networking/Samples/README.md b/src/GameCult.Networking/Samples/README.md new file mode 100644 index 00000000..8d4fc3f5 --- /dev/null +++ b/src/GameCult.Networking/Samples/README.md @@ -0,0 +1,24 @@ +# Sample Payload Messages + +`ChangeNameMessage` and `ChatMessage` are example application payloads. + +They are kept in the base union because they are useful for smoke tests, sample +client/server code, and cross-runtime compatibility checks. They are not meant +to imply that CultNet itself is only for game chat or lobby glue. + +The actual durable contract is: + +- transport + framing +- encryption and verify/login/register session flow +- shared MessagePack message layout + +Applications should define their own domain messages with the same discipline +used by CultCache document contracts: + +- explicit field keys +- stable tag assignments +- shared definitions across runtimes +- no casual drift between language bindings + +If two apps share a message contract, they should be able to share data without +translating through bespoke middleware fog. That is the point. diff --git a/src/GameCult.Networking/Samples/SamplePayloadMessages.cs b/src/GameCult.Networking/Samples/SamplePayloadMessages.cs new file mode 100644 index 00000000..0b285bfe --- /dev/null +++ b/src/GameCult.Networking/Samples/SamplePayloadMessages.cs @@ -0,0 +1,38 @@ +using MessagePack; + +namespace GameCult.Networking +{ + /// + /// Sample authenticated payload for changing a player-visible name. + /// + /// + /// This is example application payload riding the shared networking contract, + /// not a claim that CultNet itself is spiritually about chat lobbies forever. + /// Keep the wire tag stable if other runtimes depend on it. + /// + [MessagePackObject] + public class ChangeNameMessage : Message + { + /// + /// Requested new username. + /// + [Key(0)] public string Name = string.Empty; + } + + /// + /// Sample plain chat payload. + /// + /// + /// This exists as a dead-simple reference payload for message extension and + /// cross-runtime compatibility tests. Real applications should define their + /// own domain messages and keep those contracts in sync across languages. + /// + [MessagePackObject] + public class ChatMessage : Message + { + /// + /// Chat text content. + /// + [Key(0)] public string Text = string.Empty; + } +}