forked from Rollocraft/CS2MultiplayerMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplayerService.cs
More file actions
589 lines (517 loc) · 28.6 KB
/
Copy pathMultiplayerService.cs
File metadata and controls
589 lines (517 loc) · 28.6 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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using CS2MultiplayerMod.Core.Diagnostics;
using CS2MultiplayerMod.Core.Protocol.Messages;
using CS2MultiplayerMod.Core.Session;
using CS2MultiplayerMod.Game.Diagnostics;
namespace CS2MultiplayerMod.Game
{
/// <summary>
/// Where a joining client stands in the world-handover flow. Gameplay sync is
/// gated on <see cref="MultiplayerService.GameplaySyncReady"/>: no command is
/// captured or applied until the host's world has actually finished loading, so
/// remote edits never land in a half-replaced city.
/// </summary>
public enum ClientWorldPhase
{
None,
Connecting,
WaitingForMap,
LoadingMap,
WaitingForResume,
InSession,
}
/// <summary>
/// Process-wide bridge between the mod lifecycle / UI and the portable
/// <see cref="MultiplayerSession"/>. Created once in <see cref="Mod.OnLoad"/> and
/// pumped every simulation tick by <see cref="MultiplayerSystem"/>.
/// It owns the monotonic clock the session needs and translates the settings screen's
/// strings into a <see cref="MultiplayerConfig"/>. It also registers the security
/// allow-lists: which blob channels a client accepts and which command ids peers may send.
/// </summary>
public sealed partial class MultiplayerService
{
private const int DefaultPort = 25001;
private const int DefaultMaxPlayers = 8;
/// <summary>Ceiling for a streamed savegame (real saves are tens of MB).</summary>
private const int MaxSaveBlobBytes = 256 * 1024 * 1024;
/// <summary>If a received world never starts loading in this time, give up and recover.</summary>
private const long MapLoadTimeoutMs = 120000;
private const string MapChannel = "map";
private readonly IModLogger _log;
private readonly MultiplayerSession _session;
private readonly Stopwatch _clock = Stopwatch.StartNew();
private readonly ConcurrentDictionary<int, RemotePlayer> _remotePlayers =
new ConcurrentDictionary<int, RemotePlayer>();
private ClientWorldPhase _phase = ClientWorldPhase.None;
private long _worldInstallGeneration;
private long _phaseChangedMs;
private bool _sawLoading;
private string _lastFault;
// The service observer runs before the individual realization observers. Keeping
// this breadcrumb here means it is flushed before a received command can enter a
// crash-prone game operation, including failures in native code with no stack trace.
private long _appliedCommandTotal;
private ushort _lastAppliedCommandId;
private int _lastAppliedCommandOrigin;
private int _lastAppliedCommandBytes;
private long _lastAppliedCommandMs;
private ushort _lastLoggedCommandId;
private long _lastCommandLogMs;
private long _lastCommandLoggedTotal;
public MultiplayerService(IModLogger log)
{
_log = log;
_session = new MultiplayerSession(log);
_session.AddObserver(new ServiceObserver(this));
// Security allow-lists (secure by default in the core): the one blob channel
// a client may receive, and the complete set of gameplay command ids. A peer
// sending anything outside these is disconnected.
_session.AllowBlobChannel(MapChannel, MaxSaveBlobBytes);
GameplayCommandRegistry.Register(_session);
}
public MultiplayerSession Session => _session;
/// <summary>Monotonic millisecond clock shared with systems that need timing.</summary>
public long NowMs => _clock.ElapsedMilliseconds;
/// <summary>Latest known positions of the other players, for rendering their cursors.</summary>
public IEnumerable<RemotePlayer> RemotePlayers => _remotePlayers.Values;
/// <summary>The joining client's place in the world-handover flow.</summary>
public ClientWorldPhase WorldPhase => _phase;
/// <summary>
/// Client-local generation of successfully installed authoritative worlds. It advances
/// only when a Resume is accepted after WaitingForResume; aborting back to the old world
/// deliberately leaves it unchanged.
/// </summary>
public long WorldInstallGeneration => _worldInstallGeneration;
/// <summary>Master switch from the settings screen.</summary>
public static bool ModEnabled => Mod.Setting == null || Mod.Setting.EnableMod;
/// <summary>
/// The one gate every sync system checks before capturing or applying gameplay:
/// mod enabled, session connected, and - on a client - the host's world fully
/// loaded. The host is always "in session" with its own world.
/// </summary>
public bool GameplaySyncReady =>
ModEnabled &&
_session.Status == SessionStatus.Connected &&
!_worldSyncBarrierActive &&
(_session.Role == SessionRole.Host || _phase == ClientWorldPhase.InSession);
/// <summary>
/// Whether the host chose to replicate the simulation's own decisions this session -
/// zone-grown buildings, their occupants and tenants, and the demand behind them. The
/// host answers from its setting; a client answers with what the host announced when it
/// was accepted. Player edits do not consult this at all.
/// </summary>
public bool SimulationSyncEnabled => _session.SimulationSyncEnabled;
/// <summary>
/// <see cref="GameplaySyncReady"/> for the simulation half of the mod. Off, those systems
/// take the same branch a closed session takes: they drain what is queued and hand the
/// native simulation back the systems they were holding, so each city grows its own.
/// </summary>
public bool SimulationSyncReady => GameplaySyncReady && _session.SimulationSyncEnabled;
internal string CommandDiagnosticSnapshot(long nowMs)
{
if (_appliedCommandTotal == 0) return "commands=0 lastCommand=none";
long age = nowMs - _lastAppliedCommandMs;
if (age < 0) age = 0;
return "commands=" + _appliedCommandTotal +
" lastCommand=" + CommandName(_lastAppliedCommandId) +
" lastCommandId=" + _lastAppliedCommandId +
" lastCommandOrigin=" + _lastAppliedCommandOrigin +
" lastCommandBytes=" + _lastAppliedCommandBytes +
" lastCommandAgeMS=" + age;
}
private void RecordAppliedCommand(SimulationCommandMessage command)
{
if (command == null) return;
long now = _clock.ElapsedMilliseconds;
_appliedCommandTotal++;
_lastAppliedCommandId = command.CommandId;
_lastAppliedCommandOrigin = command.OriginPlayerId;
_lastAppliedCommandBytes = command.Body != null ? command.Body.Length : 0;
_lastAppliedCommandMs = now;
// Continuous brushes and road drags can produce many commands per second.
// Log the first, every operation-type change, and one sample per second so
// the file remains small without losing the operation active at a CTD.
if (_lastCommandLoggedTotal != 0 &&
command.CommandId == _lastLoggedCommandId &&
now - _lastCommandLogMs < 1000)
return;
long commandsSinceLog = _appliedCommandTotal - _lastCommandLoggedTotal;
_lastLoggedCommandId = command.CommandId;
_lastCommandLogMs = now;
_lastCommandLoggedTotal = _appliedCommandTotal;
SyncLog.Trace(LogTopic.Session, "command-apply name=" + CommandName(command.CommandId) +
" id=" + command.CommandId + " origin=" + command.OriginPlayerId + " tick=" +
command.Tick + " bytes=" + _lastAppliedCommandBytes + " sinceLast=" +
commandsSinceLog + " total=" + _appliedCommandTotal);
}
private void ResetCommandDiagnostics()
{
_appliedCommandTotal = 0;
_lastAppliedCommandId = 0;
_lastAppliedCommandOrigin = 0;
_lastAppliedCommandBytes = 0;
_lastAppliedCommandMs = 0;
_lastLoggedCommandId = 0;
_lastCommandLogMs = 0;
_lastCommandLoggedTotal = 0;
}
private static string CommandName(ushort id)
{
return GameplayCommandRegistry.Name(id);
}
// All Status*/UiStatus* texts are re-read every UI frame by the options screen
// and the cs2mp bindings, so resolving them through L10n here makes them follow
// the game language live (including a language switch mid-session).
// ---- Autosave guard (client only) -------------------------------------
private bool _autosaveSuppressed;
private bool _autosaveWasEnabled;
public void SendChat(string text) => _session.SendChat(text);
/// <summary>/sync: ask the host for a fresh world stream (host: refresh everyone).</summary>
public void RequestWorldSync() => _session.RequestWorldSync();
/// <summary>
/// One unresolved remote edit (a missed native capture, an owned sub-element that would not
/// resolve) must never loop the whole tens-of-MB world through recovery. A single automatic
/// recovery repairs a genuine divergence; a second inside this window is a storm — it freezes
/// both players for the length of a save+stream and does not fix the offending edit, which
/// simply re-triggers after every reload (the exact 52 MB epoch-loop seen in the field). EVERY
/// automatic caller funnels through here so none can bypass the cap; only manual /sync and the
/// settings button call <see cref="RequestWorldSync"/> directly.
/// </summary>
private const long AutoRecoveryCooldownMs = 90000;
private long _lastAutoRecoveryMs = long.MinValue;
/// <summary>True while a world reload is already under way, in either role.</summary>
private bool WorldRecoveryInFlight =>
_worldSyncBarrierActive ||
_phase == ClientWorldPhase.WaitingForMap ||
_phase == ClientWorldPhase.LoadingMap ||
_phase == ClientWorldPhase.WaitingForResume;
/// <summary>A settled report waiting for the service tick to act on it. Main thread only.</summary>
private Diagnostics.ResyncReport _settledReport;
/// <summary>
/// Set when this client must re-ask the host for a world it is otherwise never going to
/// receive. It deliberately bypasses the resync arbiter and the in-flight guard: this is
/// not a claim that the two cities diverged, it is a client saying the handover broke and
/// it is still waiting. See the Resume-before-load case in WorldSync.
/// </summary>
private bool _mapReRequestPending;
internal void RequestMapAgainNextTick() => _mapReRequestPending = true;
/// <summary>
/// Ask again for a world whose handover broke, once the session has actually left the epoch
/// that broke. Waiting for that is why this is a pumped flag rather than a direct call: the
/// session coalesces any request made while it is still inside the epoch.
/// </summary>
private void PumpMapReRequest()
{
if (!_mapReRequestPending) return;
if (_session == null || _session.Status != SessionStatus.Connected)
{
_mapReRequestPending = false;
return;
}
if (_session.WorldSyncSuspended) return;
_mapReRequestPending = false;
Diagnostics.SyncLog.Warn(LogTopic.Session,
"World sync: asking the host to stream this city again - the previous handover " +
"resumed before the snapshot had been installed.");
_session.RequestAutomaticWorldSync("resume arrived before the snapshot finished loading");
}
/// <summary>
/// The synchronous resync gate wired into <see cref="Sync.Infrastructure.SyncInbox.Arbitrate"/>.
/// A caller that can still hold its work puts its evidence here and acts on the verdict:
/// only <see cref="Diagnostics.ResyncVerdict.Settled"/> reloads the world.
///
/// The VERDICT is synchronous - the caller is mid-frame and has to know right now whether to
/// keep its work. The reload is not: it is handed to the service tick, where world recovery
/// has always been started from, rather than being kicked off from inside a ToolUpdate.
/// </summary>
public Diagnostics.ResyncVerdict SettleResyncReport(Diagnostics.ResyncReport report)
{
if (report == null) return Diagnostics.ResyncVerdict.Settled;
if (_session == null || _session.Status != SessionStatus.Connected)
return Diagnostics.ResyncVerdict.AlreadyRecovering;
Diagnostics.ResyncVerdict verdict =
Diagnostics.ResyncArbiter.Submit(report, NowMs, WorldRecoveryInFlight);
// First settled report wins; a second one this frame is a consequence of the same
// divergence and the one reload answers both.
if (verdict == Diagnostics.ResyncVerdict.Settled && _settledReport == null)
_settledReport = report;
return verdict;
}
public void RequestAutomaticWorldRecovery(string reason)
{
RequestAutomaticWorldRecovery(Diagnostics.ResyncReport.FromReason(reason));
}
/// <summary>
/// Weigh a queued report and, if it settles, reload the world. Requests that arrive here
/// have already let go of their work, so a held verdict simply means the world is left
/// alone and the arbiter keeps watching for the fault to recur.
/// </summary>
public void RequestAutomaticWorldRecovery(Diagnostics.ResyncReport report)
{
if (report == null || _session == null || _session.Status != SessionStatus.Connected) return;
if (Diagnostics.ResyncArbiter.Submit(report, NowMs, WorldRecoveryInFlight) !=
Diagnostics.ResyncVerdict.Settled) return;
RunAutomaticWorldRecovery(report);
}
/// <summary>
/// Reload the world for reports whose hold elapsed with nothing withdrawing them. Held is
/// never "dismissed": a subsystem that can retry withdraws its report when it succeeds, and
/// one that dropped its work simply lets the hold run out, which is what lands here.
/// </summary>
private void PumpMaturedResyncReports()
{
if (_session == null || _session.Status != SessionStatus.Connected) return;
// A reload already running supersedes anything held: leave the evidence alone rather
// than announcing a verdict on it that nothing is going to act on.
if (WorldRecoveryInFlight) return;
// Verdicts settled inside a frame (see SettleResyncReport) are acted on here.
Diagnostics.ResyncReport settled = _settledReport;
_settledReport = null;
if (settled != null) RunAutomaticWorldRecovery(settled);
System.Collections.Generic.List<Diagnostics.ResyncReport> matured =
Diagnostics.ResyncArbiter.TakeMatured(NowMs);
if (matured == null || matured.Count == 0) return;
// One reload settles every one of them; the rest are folded into it.
RunAutomaticWorldRecovery(matured[0]);
}
private void RunAutomaticWorldRecovery(Diagnostics.ResyncReport report)
{
long now = NowMs;
// Guard the sentinel before subtracting it. `now - long.MinValue` wraps negative in
// unchecked arithmetic, which otherwise makes the first automatic recovery look as if
// it were inside the cooldown forever.
bool coolingDown = _lastAutoRecoveryMs != long.MinValue &&
now - _lastAutoRecoveryMs < AutoRecoveryCooldownMs;
if (coolingDown)
{
Diagnostics.SyncLog.Warn(LogTopic.Session,
"World sync: skipped a second automatic reload within " +
(AutoRecoveryCooldownMs / 1000) + " s (" + report.Summary() +
"). The edit behind it is left un-synced; use /sync if the city looks out of step.");
return;
}
_lastAutoRecoveryMs = now;
Diagnostics.SyncLog.Event(LogTopic.Session,
"World sync: reloading this city from the host now (" + report.Summary() + ").");
// Include the subject in the existing bounded reason field: host-only logs must
// identify which inbox/operation failed on the client.
_session.RequestAutomaticWorldSync(report.Reason + " [" + report.Subject + "]");
}
// ---- Chat log (in-game hub panel) --------------------------------------
/// <summary>Bounded - old lines fall off so an all-night session cannot grow the UI payload.</summary>
private const int MaxChatEntries = 120;
private readonly object _chatLock = new object();
private readonly List<ChatLogEntry> _chatLog = new List<ChatLogEntry>();
private int _nextChatId = 1;
private string _chatLogJson = "[]";
private string _playerListJson = "[]";
/// <summary>
/// The chat/event feed as a JSON array for the hub panel binding:
/// <c>[{"id":1,"sender":"Name"|null,"text":"...","time":"HH:mm"}, ...]</c>.
/// Cached and rebuilt only on append, so the per-frame UI binding compares
/// the same string instance instead of re-serializing the whole log.
/// </summary>
public string ChatLogJson { get { lock (_chatLock) return _chatLogJson; } }
/// <summary>
/// Host-side participant list used by the in-game panel. It is rebuilt only
/// when session membership changes, avoiding a fresh JSON allocation every UI
/// frame. The local host is included and is never kickable.
/// </summary>
public string PlayerListJson { get { lock (_chatLock) return _playerListJson; } }
/// <summary>Remove one authenticated client selected in the host player list.</summary>
public void KickPlayerFromUi(int playerId)
{
if (!_session.KickPlayer(playerId))
_log.Warn(LogTopic.Session, "Ignored kick request for unavailable player #" +
playerId + ".");
}
/// <summary>Remove a client and block its address for the current hosting session.</summary>
public void BanPlayerFromUi(int playerId)
{
if (!_session.BanPlayer(playerId))
_log.Warn(LogTopic.Session, "Ignored ban request for unavailable player #" +
playerId + ".");
}
private void RefreshPlayerListJson()
{
lock (_chatLock)
{
if (_session.Role != SessionRole.Host)
{
_playerListJson = "[]";
return;
}
var peers = new List<Peer>();
foreach (Peer peer in _session.Peers)
if (peer.Handshaked) peers.Add(peer);
peers.Sort((a, b) => a.PlayerId.CompareTo(b.PlayerId));
var sb = new System.Text.StringBuilder((peers.Count + 1) * 56 + 2);
sb.Append("[{\"id\":").Append(_session.LocalPlayerId).Append(",\"name\":");
AppendJsonString(sb, _session.LocalPlayerName);
sb.Append(",\"isHost\":true}]");
if (peers.Count > 0)
{
// Replace the closing bracket while appending keeps this a single,
// small allocation and reuses the chat JSON escaping rules.
sb.Length--;
for (int i = 0; i < peers.Count; i++)
{
Peer peer = peers[i];
sb.Append(",{\"id\":").Append(peer.PlayerId).Append(",\"name\":");
AppendJsonString(sb, peer.Name);
sb.Append(",\"isHost\":false}");
}
sb.Append(']');
}
_playerListJson = sb.ToString();
}
}
private struct ChatLogEntry
{
public int Id;
public string Sender;
public string Text;
public string Time;
}
/// <summary>Mirrors session events into the mod log and records remote player positions.</summary>
private sealed class ServiceObserver : SessionObserver
{
private readonly MultiplayerService _service;
private readonly IModLogger _log;
public ServiceObserver(MultiplayerService service) { _service = service; _log = service._log; }
public override void OnStatusChanged(SessionStatus status, string detail)
{
_log.Detail(LogTopic.Session, status + ": " + detail);
// Players commonly attach the flight log to a public support post. Keep
// the target IP/hostname in the private main log, but retain the port and
// transport mode needed to diagnose a connection-stage failure here.
string flightDetail = status == SessionStatus.Connecting
? "target=redacted port=" + _service._session.Port +
" encryption=" + _service._session.EncryptionActive
: detail;
SyncLog.Trace(LogTopic.Session, "status " + status + " role=" +
_service._session.Role +
(string.IsNullOrEmpty(flightDetail) ? "" : " detail=" + flightDetail));
if (status == SessionStatus.Connected &&
_service._session.Role == SessionRole.Client &&
_service._phase == ClientWorldPhase.Connecting)
{
// Authenticated; the host streams its world to every fresh join.
_service.SetPhase(ClientWorldPhase.WaitingForMap);
}
else if (status == SessionStatus.Offline || status == SessionStatus.Faulted)
{
// Core teardown deliberately knows nothing about game worlds. If this
// client had already installed the host's temporary city, hand the game
// layer a deferred exit request before clearing the client phase.
if (_service._clientHostWorldActive)
{
string reason = !string.IsNullOrWhiteSpace(detail) && detail != "Stopped"
? detail
: "The connection to the host closed.";
_service.QueueClientMainMenu(reason);
}
if (status == SessionStatus.Faulted) _service._lastFault = detail;
_service.ResetWorldSyncState(restoreSpeed: true);
_service.SetPhase(ClientWorldPhase.None);
_service._remotePlayers.Clear();
}
// Lifecycle lines in the hub feed. Like the core's "X joined." notices
// these stay English: they are shared diagnostics, not translated UI.
// Stop() fires Offline unconditionally (also after faults and no-op
// disconnects), so "closed" is only posted when a session actually ran.
if (status == SessionStatus.Connected && _service._session.Role == SessionRole.Host)
{
_service.AppendChatEntry(null, "Session started - players can join now.");
if (!_service._session.UsesRelay)
{
if (_service._session.PublicExposure)
_service.AppendChatEntry(null, "Friends from another network can only join if you forward TCP port " +
_service._session.Port + " to this PC on your router and allow it through your firewall.");
else
_service.AppendChatEntry(null, "LAN-only is enabled - only players on your local network can join. " +
"If they cannot connect, allow TCP port " + _service._session.Port + " through your firewall.");
}
}
else if (status == SessionStatus.Connected && _service._session.Role == SessionRole.Client)
{
// Joining replaces the client's world with the host's copy. Without this notice
// the swap reads as "my buildings disappeared" when both play the same city:
// anything built outside the session is not in the host's world.
_service.AppendChatEntry(null, "Connected - downloading the host's city. It will replace the world " +
"you have open in a moment, so anything you built outside this shared session (for example just " +
"before joining) is not part of it. Your own saves are untouched.");
}
else if (status == SessionStatus.Offline && _lastStatus == SessionStatus.Connected)
{
// A live session ended cleanly (we left, or the host closed it — both are normal).
// Clear any stale fault text from an earlier failed attempt so the status reads as a
// plain disconnect, not "Connection failed".
_service._lastFault = null;
_service.AppendChatEntry(null, "Session closed.");
}
else if (status == SessionStatus.Faulted)
_service.AppendChatEntry(null, string.IsNullOrEmpty(detail) ? "Connection failed." : detail);
_service.RefreshPlayerListJson();
_lastStatus = status;
}
private SessionStatus _lastStatus = SessionStatus.Offline;
public override void OnPeerJoined(Peer peer)
{
_log.Event(LogTopic.Session, "Peer joined: " + peer);
_service.RefreshPlayerListJson();
// WorldResyncSystem observes joins too and pushes the live world to the newcomer.
}
public override void OnPeerLeft(Peer peer, string reason)
{
_log.Event(LogTopic.Session, "Peer left: " + peer + " (" + reason + ")");
RemotePlayer removed;
_service._remotePlayers.TryRemove(peer.PlayerId, out removed);
_service.RefreshPlayerListJson();
}
public override void OnChatReceived(string sender, string text)
{
_log.Detail(LogTopic.Session, (sender ?? "system") + ": " + text);
_service.AppendChatEntry(sender, text);
}
public override void OnCommandReceived(SimulationCommandMessage command)
{
_service.RecordAppliedCommand(command);
}
public override void OnPlayerStateReceived(PlayerStateMessage state) => _service.RecordRemotePlayer(state);
public override void OnBlobReceived(string channel, long transferId, byte[] data)
{
if (channel == MapChannel) _service.LoadReceivedMap(transferId, data);
}
public override void OnWorldSyncControl(WorldSyncStage stage, long epoch,
float resumeSpeed, Core.Networking.ConnectionId connection)
{
_service.HandleWorldSyncControl(stage, epoch, resumeSpeed);
}
public override void OnError(string message)
{
_service._lastFault = message;
_log.Error(LogTopic.Session, message);
}
}
}
/// <summary>A snapshot of another player's map cursor, kept by <see cref="MultiplayerService"/>.</summary>
public sealed class RemotePlayer
{
public int PlayerId;
// Camera focus on the ground.
public float X;
public float Y;
public float Z;
// Camera eye position in the air.
public float EyeX;
public float EyeY;
public float EyeZ;
public float Yaw;
public Core.Protocol.Messages.PlayerHoverShape[] Hover =
System.Array.Empty<Core.Protocol.Messages.PlayerHoverShape>();
public long LastUpdateMs;
}
}