@@ -8,64 +8,15 @@ namespace MLAPI.Internal
8
8
{
9
9
internal static partial class InternalMessageHandler
10
10
{
11
- internal static void Send ( uint clientId , byte messageType , string channelName , Stream messageStream , SecuritySendFlags securityOptions , bool skipQueue = false )
11
+ internal static void Send ( uint clientId , byte messageType , string channelName , Stream messageStream , bool skipQueue = false )
12
12
{
13
13
if ( NetworkingManager . singleton . isServer && clientId == NetworkingManager . singleton . ServerClientId ) return ;
14
14
using ( PooledBitStream stream = PooledBitStream . Get ( ) )
15
15
{
16
16
using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
17
17
{
18
- bool encrypted = ( ( securityOptions & SecuritySendFlags . Encrypted ) == SecuritySendFlags . Encrypted ) && netManager . NetworkConfig . EnableEncryption ;
19
- bool authenticated = ( ( securityOptions & SecuritySendFlags . Authenticated ) == SecuritySendFlags . Authenticated ) && netManager . NetworkConfig . EnableEncryption ;
20
- writer . WriteBit ( encrypted ) ;
21
- writer . WriteBit ( authenticated ) ;
22
-
23
- if ( encrypted || authenticated )
24
- {
25
- writer . WritePadBits ( ) ;
26
-
27
- long hmacPosition = stream . Position ; // Save the position where the HMAC should be written.
28
- if ( authenticated ) stream . Position += 32 ; // Skip 32 bytes. These will be replaced later on by the HMAC.
29
-
30
- if ( encrypted )
31
- {
32
- using ( RijndaelManaged rijndael = new RijndaelManaged ( ) )
33
- {
34
- rijndael . Key = netManager . isServer ? netManager . ConnectedClients [ clientId ] . AesKey : netManager . clientAesKey ;
35
- rijndael . GenerateIV ( ) ;
36
- rijndael . Padding = PaddingMode . PKCS7 ;
37
- writer . WriteByteArray ( rijndael . IV , 16 ) ;
38
- using ( CryptoStream cryptoStream = new CryptoStream ( stream , rijndael . CreateEncryptor ( ) , CryptoStreamMode . Write ) )
39
- {
40
- using ( PooledBitWriter encryptedWriter = PooledBitWriter . Get ( cryptoStream ) )
41
- {
42
- encryptedWriter . WriteByte ( messageType ) ;
43
- // Copy data
44
- messageStream . Position = 0 ;
45
- int messageByte ;
46
- while ( ( messageByte = messageStream . ReadByte ( ) ) != - 1 ) encryptedWriter . WriteByte ( ( byte ) messageByte ) ;
47
- }
48
- }
49
- }
50
- }
51
-
52
- if ( authenticated )
53
- {
54
- if ( ! encrypted ) writer . WriteByte ( messageType ) ; // If we are not using encryption, write the byte. Note that the current position in the stream is just after the HMAC.
55
-
56
- stream . Position = hmacPosition ; // Set the position to where the HMAC should be written.
57
- using ( HMACSHA256 hmac = new HMACSHA256 ( netManager . isServer ? netManager . ConnectedClients [ clientId ] . AesKey : netManager . clientAesKey ) )
58
- {
59
- writer . WriteByteArray ( hmac . ComputeHash ( stream . GetBuffer ( ) , ( 32 + 1 ) , ( int ) stream . Length - ( 32 + 1 ) ) , 32 ) ;
60
- }
61
- stream . CopyFrom ( messageStream ) ;
62
- }
63
- }
64
- else
65
- {
66
- writer . WriteBits ( messageType , 6 ) ;
67
- stream . CopyFrom ( messageStream ) ;
68
- }
18
+ writer . WriteByte ( messageType ) ;
19
+ stream . CopyFrom ( messageStream ) ;
69
20
70
21
NetworkProfiler . StartEvent ( TickType . Send , ( uint ) stream . Length , channelName , MLAPIConstants . MESSAGE_NAMES [ messageType ] ) ;
71
22
byte error ;
@@ -78,28 +29,13 @@ internal static void Send(uint clientId, byte messageType, string channelName, S
78
29
}
79
30
}
80
31
81
- internal static void Send ( byte messageType , string channelName , Stream messageStream , SecuritySendFlags securityOptions )
32
+ internal static void Send ( byte messageType , string channelName , Stream messageStream )
82
33
{
83
- bool encrypted = ( ( securityOptions & SecuritySendFlags . Encrypted ) == SecuritySendFlags . Encrypted ) && netManager . NetworkConfig . EnableEncryption ;
84
- bool authenticated = ( ( securityOptions & SecuritySendFlags . Authenticated ) == SecuritySendFlags . Authenticated ) && netManager . NetworkConfig . EnableEncryption ;
85
-
86
- if ( authenticated || encrypted )
87
- {
88
- for ( int i = 0 ; i < netManager . ConnectedClientsList . Count ; i ++ )
89
- {
90
- Send ( netManager . ConnectedClientsList [ i ] . ClientId , messageType , channelName , messageStream , securityOptions ) ;
91
- }
92
- return ;
93
- }
94
-
95
34
using ( PooledBitStream stream = PooledBitStream . Get ( ) )
96
35
{
97
36
using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
98
37
{
99
- writer . WriteBool ( false ) ; // Encryption
100
- writer . WriteBool ( false ) ; // Authentication
101
-
102
- writer . WriteBits ( messageType , 6 ) ;
38
+ writer . WriteByte ( messageType ) ;
103
39
stream . CopyFrom ( messageStream ) ;
104
40
105
41
NetworkProfiler . StartEvent ( TickType . Send , ( uint ) stream . Length , channelName , MLAPIConstants . MESSAGE_NAMES [ messageType ] ) ;
@@ -113,30 +49,14 @@ internal static void Send(byte messageType, string channelName, Stream messageSt
113
49
}
114
50
}
115
51
}
116
-
117
- internal static void Send ( byte messageType , string channelName , uint clientIdToIgnore , Stream messageStream , SecuritySendFlags securityOptions )
52
+
53
+ internal static void Send ( byte messageType , string channelName , uint clientIdToIgnore , Stream messageStream )
118
54
{
119
- bool encrypted = ( ( securityOptions & SecuritySendFlags . Encrypted ) == SecuritySendFlags . Encrypted ) && netManager . NetworkConfig . EnableEncryption ;
120
- bool authenticated = ( ( securityOptions & SecuritySendFlags . Authenticated ) == SecuritySendFlags . Authenticated ) && netManager . NetworkConfig . EnableEncryption ;
121
-
122
- if ( authenticated || encrypted )
123
- {
124
- for ( int i = 0 ; i < netManager . ConnectedClientsList . Count ; i ++ )
125
- {
126
- if ( netManager . ConnectedClientsList [ i ] . ClientId == clientIdToIgnore ) continue ;
127
- Send ( netManager . ConnectedClientsList [ i ] . ClientId , messageType , channelName , messageStream , securityOptions ) ;
128
- }
129
- return ;
130
- }
131
-
132
55
using ( PooledBitStream stream = PooledBitStream . Get ( ) )
133
56
{
134
57
using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
135
58
{
136
- writer . WriteBool ( false ) ; // Encryption
137
- writer . WriteBool ( false ) ; // Authentication
138
-
139
- writer . WriteBits ( messageType , 6 ) ;
59
+ writer . WriteByte ( messageType ) ;
140
60
stream . CopyFrom ( messageStream ) ;
141
61
142
62
NetworkProfiler . StartEvent ( TickType . Send , ( uint ) stream . Length , channelName , MLAPIConstants . MESSAGE_NAMES [ messageType ] ) ;
0 commit comments