1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
// Backwards-compatible protocol version.
const VERSION = 1;
// From the frontend to the relay.
struct CommandMessage {
// The command sequence number will be repeated in responses
// in the respective fields.
u32 command_seq;
union CommandData switch (enum Command {
HELLO,
ACTIVE,
BUFFER_ACTIVATE,
BUFFER_INPUT,
BUFFER_TOGGLE_UNIMPORTANT,
PING_RESPONSE,
PING,
BUFFER_COMPLETE,
BUFFER_LOG,
} command) {
// If the version check succeeds, the client will receive
// an initial stream of SERVER_UPDATE, BUFFER_UPDATE, BUFFER_STATS,
// BUFFER_LINE, and finally a BUFFER_ACTIVATE message.
case HELLO:
u32 version;
case ACTIVE:
void;
case BUFFER_ACTIVATE:
string buffer_name;
case BUFFER_INPUT:
string buffer_name;
string text;
// XXX: Perhaps this should rather be handled through a /buffer command.
case BUFFER_TOGGLE_UNIMPORTANT:
string buffer_name;
case PING_RESPONSE:
u32 event_seq;
// Only these commands may produce Event.RESPONSE, as below,
// but any command may produce an error.
case PING:
void;
case BUFFER_COMPLETE:
string buffer_name;
string text;
u32 position;
case BUFFER_LOG:
string buffer_name;
} data;
};
// From the relay to the frontend.
struct EventMessage {
u32 event_seq;
union EventData switch (enum Event {
PING,
BUFFER_LINE,
BUFFER_UPDATE,
BUFFER_STATS,
BUFFER_RENAME,
BUFFER_REMOVE,
BUFFER_ACTIVATE,
BUFFER_CLEAR,
SERVER_UPDATE,
SERVER_RENAME,
SERVER_REMOVE,
ERROR,
RESPONSE,
} event) {
case PING:
void;
case BUFFER_LINE:
string buffer_name;
// Whether the line should also be displayed in the active buffer.
bool leak_to_active;
bool is_unimportant;
bool is_highlight;
enum Rendition {
BARE,
INDENT,
STATUS,
ERROR,
JOIN,
PART,
ACTION,
} rendition;
// Unix timestamp in milliseconds.
u64 when;
// Broken-up text, with in-band formatting.
union ItemData switch (enum Item {
TEXT,
RESET,
FG_COLOR,
BG_COLOR,
FLIP_BOLD,
FLIP_ITALIC,
FLIP_UNDERLINE,
FLIP_INVERSE,
FLIP_CROSSED_OUT,
FLIP_MONOSPACE,
} kind) {
case TEXT:
string text;
case RESET:
void;
case FG_COLOR:
i16 color;
case BG_COLOR:
i16 color;
case FLIP_BOLD:
case FLIP_ITALIC:
case FLIP_UNDERLINE:
case FLIP_INVERSE:
case FLIP_CROSSED_OUT:
case FLIP_MONOSPACE:
void;
} items<>;
case BUFFER_UPDATE:
string buffer_name;
bool hide_unimportant;
union BufferContext switch (enum BufferKind {
GLOBAL,
SERVER,
CHANNEL,
PRIVATE_MESSAGE,
} kind) {
case GLOBAL:
void;
case SERVER:
string server_name;
case CHANNEL:
string server_name;
ItemData topic<>;
case PRIVATE_MESSAGE:
string server_name;
} context;
case BUFFER_STATS:
string buffer_name;
// These are cumulative, even for lines flushed out from buffers.
// Updates to these values aren't broadcasted, thus handle:
// - BUFFER_LINE by bumping/setting them as appropriate,
// - BUFFER_ACTIVATE by clearing them for the previous buffer
// (this way, they can be used to mark unread messages).
u32 new_messages;
u32 new_unimportant_messages;
bool highlighted;
case BUFFER_RENAME:
string buffer_name;
string new;
case BUFFER_REMOVE:
string buffer_name;
case BUFFER_ACTIVATE:
string buffer_name;
case BUFFER_CLEAR:
string buffer_name;
case SERVER_UPDATE:
string server_name;
union ServerData switch (enum ServerState {
DISCONNECTED,
CONNECTING,
CONNECTED,
REGISTERED,
DISCONNECTING,
} state) {
case DISCONNECTED:
case CONNECTING:
case CONNECTED:
void;
case REGISTERED:
string user;
string user_mode;
// Theoretically, we could also send user information in this state,
// but we'd have to duplicate both fields.
case DISCONNECTING:
void;
} data;
case SERVER_RENAME:
// Buffers aren't sent updates for in this circumstance,
// as that wouldn't be sufficiently atomic anyway.
string server_name;
string new;
case SERVER_REMOVE:
string server_name;
// Restriction: command_seq strictly follows the sequence received
// by the relay, across both of these replies.
case ERROR:
u32 command_seq;
string error;
case RESPONSE:
u32 command_seq;
union ResponseData switch (Command command) {
case PING:
void;
case BUFFER_COMPLETE:
u32 start;
string completions<>;
case BUFFER_LOG:
// UTF-8, but not guaranteed.
u8 log<>;
} data;
} data;
};
|