summaryrefslogtreecommitdiff
path: root/server/lib/net/protocol.dart
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/net/protocol.dart')
-rw-r--r--server/lib/net/protocol.dart101
1 files changed, 101 insertions, 0 deletions
diff --git a/server/lib/net/protocol.dart b/server/lib/net/protocol.dart
index c3030e1..9356cf1 100644
--- a/server/lib/net/protocol.dart
+++ b/server/lib/net/protocol.dart
@@ -18,10 +18,20 @@ abstract class Protocol {
static const String redo = 'redo';
static const String ping = 'ping';
+ // Phase 6 (settings + multi-save) — players only.
+ static const String setSetting = 'setSetting';
+ static const String save = 'save';
+ static const String loadSave = 'loadSave';
+ static const String deleteSave = 'deleteSave';
+ static const String saveCharacter = 'saveCharacter';
+ static const String loadCharacterSave = 'loadCharacterSave';
+ static const String deleteCharacterSave = 'deleteCharacterSave';
+
// Server -> client message types.
static const String welcome = 'welcome';
static const String update = 'update';
static const String seats = 'seats';
+ static const String settings = 'settings';
static const String error = 'error';
static const String pong = 'pong';
@@ -72,13 +82,24 @@ abstract class Protocol {
/// secrets included and everyone else's masked (PLAN.md section 3.4).
/// [seats] maps every character in the current list to its owning session
/// id, or null when unclaimed.
+ ///
+ /// [settings] carries the server-side (game-relevant) settings + save
+ /// names (Phase 6). [historyLength] / [redoDescription] /
+ /// [undoDescription] let the client render the undo/redo UI without
+ /// holding the history itself (the labels are the reference app's
+ /// `MainMenuViewModel.undoDescription` / `redoDescription` — null when
+ /// that direction is exhausted).
static Map<String, dynamic> welcomeMessage({
required String session,
required String role,
required int index,
required Map<String, dynamic> state,
required Map<String, dynamic> seats,
+ required Map<String, dynamic> settings,
+ required int historyLength,
String? description,
+ String? redoDescription,
+ String? undoDescription,
Object? event,
}) {
return {
@@ -88,30 +109,110 @@ abstract class Protocol {
'role': role,
'index': index,
'description': description,
+ 'historyLength': historyLength,
+ 'redoDescription': redoDescription,
+ 'undoDescription': undoDescription,
'event': event,
'state': state,
'seats': seats,
+ 'settings': settings,
};
}
/// Full-state push sent to every connection after a command, undo or redo
/// (the equivalent of the reference app's `{i, d, e, s}` envelope).
/// [state] is serialized per connection by the server.
+ ///
+ /// [index] always equals the state position (the undo path reports the
+ /// post-decrement index; see `ActionHandler.undo`). [historyLength] /
+ /// [redoDescription] / [undoDescription] let the client render the
+ /// undo/redo UI (enablement + labels) from the snapshot alone.
static Map<String, dynamic> updateMessage({
required int index,
required String description,
required Object? event,
required Map<String, dynamic> state,
+ required int historyLength,
+ String? redoDescription,
+ String? undoDescription,
}) {
return {
't': update,
'index': index,
'description': description,
+ 'historyLength': historyLength,
+ 'redoDescription': redoDescription,
+ 'undoDescription': undoDescription,
'event': event,
'state': state,
};
}
+ /// Settings broadcast (Phase 6): the server-side settings + save names,
+ /// sent to every connection when a setting changes or the save list does.
+ /// Also embedded in `welcome`. The save *content* never crosses the wire.
+ static Map<String, dynamic> settingsMessage(Map<String, dynamic> settings) =>
+ {
+ 't': Protocol.settings,
+ 'settings': settings,
+ };
+
+ // --- Phase 6 client messages (players only) -------------------------------
+
+ /// Client message setting one server-side (game-relevant) setting.
+ /// [name] is one of the known setting names; [value] its new value
+ /// (booleans, or the style enum index / locale code strings).
+ static Map<String, dynamic> setSettingMessage(
+ String name,
+ Object value,
+ ) => {
+ 't': setSetting,
+ 'name': name,
+ 'value': value,
+ };
+
+ /// Client message saving the current game state to a named save slot.
+ static Map<String, dynamic> saveMessage(String name) => {
+ 't': save,
+ 'name': name,
+ };
+
+ /// Client message loading a named save (runs `LoadSaveCommand` — an
+ /// undoable action, so it advances the command index).
+ static Map<String, dynamic> loadSaveMessage(String name) => {
+ 't': loadSave,
+ 'name': name,
+ };
+
+ /// Client message deleting a named save.
+ static Map<String, dynamic> deleteSaveMessage(String name) => {
+ 't': deleteSave,
+ 'name': name,
+ };
+
+ /// Client message saving one character's state under [name].
+ static Map<String, dynamic> saveCharacterMessage(
+ String name,
+ String characterId,
+ ) => {
+ 't': saveCharacter,
+ 'name': name,
+ 'characterId': characterId,
+ };
+
+ /// Client message loading a character save. [saveId] is the
+ /// `"$name\n${characterId}"` key the server stores it under.
+ static Map<String, dynamic> loadCharacterSaveMessage(String saveId) => {
+ 't': loadCharacterSave,
+ 'saveId': saveId,
+ };
+
+ /// Client message deleting a character save.
+ static Map<String, dynamic> deleteCharacterSaveMessage(String saveId) => {
+ 't': deleteCharacterSave,
+ 'saveId': saveId,
+ };
+
/// Seat-ownership broadcast: every character in the current list mapped to
/// its owning session id, or null when unclaimed. The UI enables inputs
/// only on the owning player's screen from this map.