forked from Rollocraft/CS2MultiplayerMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotify.cs
More file actions
129 lines (113 loc) · 5 KB
/
Copy pathNotify.cs
File metadata and controls
129 lines (113 loc) · 5 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
using System;
using CS2MPMod.Core.Diagnostics;
using CS2MPMod.Core.Networking;
using CS2MPMod.Core.Protocol;
using CS2MPMod.Core.Protocol.Messages;
namespace CS2MPMod.Core.Session
{
public sealed partial class MultiplayerSession
{
private void SendTo(ConnectionId connection, INetMessage message)
{
if (_transport == null) return;
_transport.Send(connection, _codec.Encode(message));
}
private void BroadcastToAll(INetMessage message, ConnectionId exclude)
{
if (_transport == null) return;
byte[] payload = _codec.Encode(message);
foreach (var pair in _peers)
{
Peer peer = pair.Value;
if (!peer.Handshaked) continue;
if (peer.Connection == exclude) continue;
_transport.Send(peer.Connection, payload);
}
}
private void SetStatus(SessionStatus status, string detail)
{
Status = status;
_log.Event(LogTopic.Session, "Session status: " + status + " (" + detail + ")");
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnStatusChanged(status, detail); }
catch (Exception ex) { LogObserverError("OnStatusChanged", ex); }
}
private void Fault(string message)
{
_log.Error(LogTopic.Session, "Session fault: " + message);
SetStatus(SessionStatus.Faulted, message);
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnError(message); }
catch (Exception ex) { LogObserverError("OnError", ex); }
Stop();
}
private void NotifyPeerJoined(Peer peer)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnPeerJoined(peer); }
catch (Exception ex) { LogObserverError("OnPeerJoined", ex); }
}
private void NotifyPeerLeft(Peer peer, string reason)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnPeerLeft(peer, reason); }
catch (Exception ex) { LogObserverError("OnPeerLeft", ex); }
}
private void NotifyChat(string sender, string text)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnChatReceived(sender, text); }
catch (Exception ex) { LogObserverError("OnChatReceived", ex); }
}
private void NotifyCommand(SimulationCommandMessage command)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnCommandReceived(command); }
catch (Exception ex) { LogObserverError("OnCommandReceived", ex); }
}
private void NotifyState(StateSnapshotMessage snapshot)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnStateReceived(snapshot); }
catch (Exception ex) { LogObserverError("OnStateReceived", ex); }
}
private void NotifyStateEdit(StateEditMessage edit)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnStateEditReceived(edit); }
catch (Exception ex) { LogObserverError("OnStateEditReceived", ex); }
}
private void NotifyResyncRequested(int playerId, ConnectionId connection)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnResyncRequested(playerId, connection); }
catch (Exception ex) { LogObserverError("OnResyncRequested", ex); }
}
private void NotifyPlayerState(PlayerStateMessage state)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnPlayerStateReceived(state); }
catch (Exception ex) { LogObserverError("OnPlayerStateReceived", ex); }
}
private void NotifyBlob(string channel, long transferId, byte[] data)
{
_log.Detail(LogTopic.Session, "Blob '" + channel + "' transfer " + transferId +
" received (" + data.Length + " bytes).");
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnBlobReceived(channel, transferId, data); }
catch (Exception ex) { LogObserverError("OnBlobReceived", ex); }
}
private void NotifyWorldSync(WorldSyncStage stage, long epoch, float resumeSpeed,
ConnectionId connection)
{
for (int i = 0; i < _observers.Count; i++)
try { _observers[i].OnWorldSyncControl(stage, epoch, resumeSpeed, connection); }
catch (Exception ex) { LogObserverError("OnWorldSyncControl", ex); }
}
private void LogObserverError(string callback, Exception ex)
{
_log.Error(LogTopic.Session, "Observer crashed in " + callback +
" (session continues): " + ex);
}
}
}