Repository navigation
Expand file tree
/
Copy pathIChat.cs
More file actions
542 lines (450 loc) · 24.1 KB
/
Copy pathIChat.cs
File metadata and controls
542 lines (450 loc) · 24.1 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
using SS.Utilities;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using System.Text;
namespace SS.Core.ComponentInterfaces
{
/// <summary>
/// types of chat messages
/// </summary>
public enum ChatMessageType : byte
{
/// <summary>
/// arena messages (in green)
/// </summary>
Arena = 0,
/// <summary>
/// macros as public arena chat
/// </summary>
PubMacro = 1,
/// <summary>
/// public arena chat
/// </summary>
Pub = 2,
/// <summary>
/// team message
/// </summary>
Freq = 3,
/// <summary>
/// enemy team messages
/// </summary>
EnemyFreq = 4,
/// <summary>
/// within-arena private messages
/// </summary>
Private = 5,
/// <summary>
/// cross-arena or cross-zone private messages
/// </summary>
RemotePrivate = 7,
/// <summary>
/// red sysop warning text
/// </summary>
SysopWarning = 8,
/// <summary>
/// chat channel messages
/// </summary>
Chat = 9,
/// <summary>
/// moderator chat messages (internal only)
/// </summary>
ModChat = 10,
/// <summary>
/// msgs that function as commands (internal only)
/// </summary>
Command = 11,
/// <summary>
/// commands that go to the biller (internal only)
/// </summary>
BillerCommand = 12,
}
/// <summary>
/// Mask that tells what chat message types are allowed/disallowed.
/// </summary>
public struct ChatMask(int data)
{
private BitVector32 _maskVector = new(data);
public static ChatMask operator |(ChatMask a, ChatMask b) => new(a._maskVector.Data | b._maskVector.Data);
public int Value => _maskVector.Data;
public bool IsClear => _maskVector.Data == 0;
public bool IsRestricted(ChatMessageType messageType) => _maskVector[BitVector32Masks.GetMask((int)messageType)];
public bool IsAllowed(ChatMessageType messageType) => !IsRestricted(messageType);
public void SetRestricted(ChatMessageType messageType) => _maskVector[BitVector32Masks.GetMask((int)messageType)] = true;
public void SetAllowed(ChatMessageType messageType) => _maskVector[BitVector32Masks.GetMask((int)messageType)] = false;
public void Set(ChatMessageType messageType, bool isRestricted)
{
if (isRestricted)
SetRestricted(messageType);
else
SetAllowed(messageType);
}
public void Clear() => _maskVector = new BitVector32(0);
}
public interface IChat : IComponentInterface
{
#region SendMessage
/// <summary>
/// Sends a green message to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="handler">The message to send.</param>
void SendMessage(Player player, [InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green message to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
void SendMessage(Player player, IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green message to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="message">The message to send.</param>
void SendMessage(Player player, ReadOnlySpan<char> message);
/// <summary>
/// Sends a green message to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="message">The message to send.</param>
void SendMessage(Player player, string message);
/// <summary>
/// Sends a green message to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="message">The message to send.</param>
void SendMessage(Player player, StringBuilder message);
#endregion
#region SendMessage (with sound)
/// <summary>
/// Sends a green arena message plus sound code to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="handler">The message to send.</param>
void SendMessage(Player player, ChatSound sound, [InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message plus sound code to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
void SendMessage(Player player, ChatSound sound, IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message plus sound code to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendMessage(Player player, ChatSound sound, ReadOnlySpan<char> message);
/// <summary>
/// Sends a green arena message plus sound code to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendMessage(Player player, ChatSound sound, string message);
/// <summary>
/// Sends a green arena message plus sound code to a player.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendMessage(Player player, ChatSound sound, StringBuilder message);
#endregion
#region SendSetMessage
/// <summary>
/// Sends a green arena message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="handler">The message to send.</param>
void SendSetMessage(HashSet<Player> set, [InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
/// <summary>
void SendSetMessage(HashSet<Player> set, IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="message">The message to send.</param>
void SendSetMessage(HashSet<Player> set, ReadOnlySpan<char> message);
/// <summary>
/// Sends a green arena message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="message">The message to send.</param>
void SendSetMessage(HashSet<Player> set, string message);
/// <summary>
/// Sends a green arena message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="message">The message to send.</param>
void SendSetMessage(HashSet<Player> set, StringBuilder message);
#endregion
#region SendSetMessage (with sound)
/// <summary>
/// Sends a green arena message plus sound code to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="handler">The message to send.</param>
void SendSetMessage(HashSet<Player> set, ChatSound sound, [InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message plus sound code to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
void SendSetMessage(HashSet<Player> set, ChatSound sound, IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message plus sound code to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendSetMessage(HashSet<Player> set, ChatSound sound, ReadOnlySpan<char> message);
/// <summary>
/// Sends a green arena message plus sound code to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendSetMessage(HashSet<Player> set, ChatSound sound, string message);
/// <summary>
/// Sends a green arena message plus sound code to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendSetMessage(HashSet<Player> set, ChatSound sound, StringBuilder message);
#endregion
#region SendArenaMessage
/// <summary>
/// Sends a green arena message to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="handler">The message to send.</param>
void SendArenaMessage(Arena? arena, [InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
void SendArenaMessage(Arena? arena, IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="message">The message to send.</param>
void SendArenaMessage(Arena? arena, ReadOnlySpan<char> message);
/// <summary>
/// Sends a green arena message to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="message">The message to send.</param>
void SendArenaMessage(Arena? arena, string message);
/// <summary>
/// Sends a green arena message to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="message">The message to send.</param>
void SendArenaMessage(Arena? arena, StringBuilder message);
#endregion
#region SendArenaMessage (with sound)
/// <summary>
/// Sends a green arena message plus sound code to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="handler">The message to send.</param>
void SendArenaMessage(Arena? arena, ChatSound sound, [InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message plus sound code to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
void SendArenaMessage(Arena? arena, ChatSound sound, IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a green arena message plus sound code to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendArenaMessage(Arena? arena, ChatSound sound, ReadOnlySpan<char> message);
/// <summary>
/// Sends a green arena message plus sound code to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendArenaMessage(Arena? arena, ChatSound sound, string message);
/// <summary>
/// Sends a green arena message plus sound code to all players in an arena.
/// </summary>
/// <param name="arena">The arena to send to, or <see langword="null"/> for all arenas.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="message">The message to send.</param>
void SendArenaMessage(Arena? arena, ChatSound sound, StringBuilder message);
#endregion
#region SendAnyMessage
/// <summary>
/// Sends an arbitrary chat message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="type">The type of message.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="from">The player the message if from.</param>
/// <param name="handler">The message to send.</param>
void SendAnyMessage(HashSet<Player> set, ChatMessageType type, ChatSound sound, Player? from, [InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends an arbitrary chat message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="type">The type of message.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="from">The player the message if from.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
void SendAnyMessage(HashSet<Player> set, ChatMessageType type, ChatSound sound, Player? from, IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends an arbitrary chat message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="type">The type of message.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="from">The player the message if from.</param>
/// <param name="message">The message to send.</param>
void SendAnyMessage(HashSet<Player> set, ChatMessageType type, ChatSound sound, Player? from, ReadOnlySpan<char> message);
/// <summary>
/// Sends an arbitrary chat message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="type">The type of message.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="from">The player the message if from.</param>
/// <param name="message">The message to send.</param>
void SendAnyMessage(HashSet<Player> set, ChatMessageType type, ChatSound sound, Player? from, string message);
/// <summary>
/// Sends an arbitrary chat message to a set of players.
/// </summary>
/// <param name="set">The players to send the message to.</param>
/// <param name="type">The type of message.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="from">The player the message if from.</param>
/// <param name="message">The message to send.</param>
void SendAnyMessage(HashSet<Player> set, ChatMessageType type, ChatSound sound, Player? from, StringBuilder message);
#endregion
#region SendModMessage
/// <summary>
/// Sends a moderator chat message to all connected staff.
/// </summary>
/// <param name="handler">The message to send.</param>
void SendModMessage([InterpolatedStringHandlerArgument("")] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a moderator chat message to all connected staff.
/// </summary>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="handler">The message to send.</param>
void SendModMessage(IFormatProvider provider, [InterpolatedStringHandlerArgument("", nameof(provider))] ref StringBuilderBackedInterpolatedStringHandler handler);
/// <summary>
/// Sends a moderator chat message to all connected staff.
/// </summary>
/// <param name="message">The message to send.</param>
void SendModMessage(ReadOnlySpan<char> message);
/// <summary>
/// Sends a moderator chat message to all connected staff.
/// </summary>
/// <param name="message">The message to send.</param>
void SendModMessage(string message);
/// <summary>
/// Sends a moderator chat message to all connected staff.
/// </summary>
/// <param name="message">The message to send.</param>
void SendModMessage(StringBuilder message);
#endregion
/// <summary>
/// Sends a remote private message to a set of players.
/// </summary>
/// <remarks>
/// This should only be used from billing server modules.
/// </remarks>
/// <param name="set">The players to send the message to.</param>
/// <param name="sound">The sound to send.</param>
/// <param name="squad">The squad the message is for, or <see cref="ReadOnlySpan{byte}.Empty"/> for no squad.</param>
/// <param name="sender">The name of the sender.</param>
/// <param name="message">The message to send.</param>
void SendRemotePrivMessage(HashSet<Player> set, ChatSound sound, ReadOnlySpan<char> squad, ReadOnlySpan<char> sender, ReadOnlySpan<char> message);
#region Chat Mask
/// <summary>
/// Gets the chat mask for an arena.
/// </summary>
/// <param name="arena">The arena to get the chat mask for.</param>
/// <returns>The chat mask.</returns>
ChatMask GetArenaChatMask(Arena arena);
/// <summary>
/// Sets the chat mask for an arena.
/// </summary>
/// <param name="arena">The arena to set the chat mask for.</param>
/// <param name="mask">The chat mask to set.</param>
void SetArenaChatMask(Arena arena, ChatMask mask);
/// <summary>
/// Gets the chat mask for a player.
/// </summary>
/// <param name="player">The player to get the chat mask for.</param>
/// <returns>The chat mask.</returns>
ChatMask GetPlayerChatMask(Player player);
/// <summary>
/// Gets the chat mask for a player, including the remaining time for the mask.
/// </summary>
/// <param name="player">The player to get the chat mask for.</param>
/// <param name="mask">The chat mask.</param>
/// <param name="remaining">The remaining time on the mask. <see langword="null"/> means there is no expiration (valid until the next arena change).</param>
void GetPlayerChatMask(Player player, out ChatMask mask, out TimeSpan? remaining);
/// <summary>
/// Sets the chat mask for a player.
/// </summary>
/// <param name="player">The player to set the mask for.</param>
/// <param name="mask">The chat mask to set.</param>
/// <param name="timeout">Zero to set a session mask (valid until the next arena change), or a number of seconds for the mask to be valid.</param>
void SetPlayerChatMask(Player player, ChatMask mask, int timeout);
#endregion
#region SendWrappedText
/// <summary>
/// A utility function for sending lists of items in a chat message.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="text">The message to send.</param>
void SendWrappedText(Player player, string text);
/// <summary>
/// A utility function for sending lists of items in a chat message.
/// </summary>
/// <param name="player">The player to send the message to.</param>
/// <param name="sb">The message to send.</param>
void SendWrappedText(Player player, StringBuilder sb);
/// <summary>
/// A utility function for sending lists of items in a chat message.
/// </summary>
/// <param name="players">The players to send the message to.</param>
/// <param name="text">The message to send.</param>
void SendWrappedText(HashSet<Player> players, string text);
/// <summary>
/// A utility function for sending lists of items in a chat message.
/// </summary>
/// <param name="players">The players to send the message to.</param>
/// <param name="sb">The message to send.</param>
void SendWrappedText(HashSet<Player> players, StringBuilder sb);
#endregion
}
}