@@ -8,64 +8,15 @@ namespace MLAPI.Internal
88{
99 internal static partial class InternalMessageHandler
1010 {
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 )
1212 {
1313 if ( NetworkingManager . singleton . isServer && clientId == NetworkingManager . singleton . ServerClientId ) return ;
1414 using ( PooledBitStream stream = PooledBitStream . Get ( ) )
1515 {
1616 using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
1717 {
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 ) ;
6920
7021 NetworkProfiler . StartEvent ( TickType . Send , ( uint ) stream . Length , channelName , MLAPIConstants . MESSAGE_NAMES [ messageType ] ) ;
7122 byte error ;
@@ -78,28 +29,13 @@ internal static void Send(uint clientId, byte messageType, string channelName, S
7829 }
7930 }
8031
81- internal static void Send ( byte messageType , string channelName , Stream messageStream , SecuritySendFlags securityOptions )
32+ internal static void Send ( byte messageType , string channelName , Stream messageStream )
8233 {
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-
9534 using ( PooledBitStream stream = PooledBitStream . Get ( ) )
9635 {
9736 using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
9837 {
99- writer . WriteBool ( false ) ; // Encryption
100- writer . WriteBool ( false ) ; // Authentication
101-
102- writer . WriteBits ( messageType , 6 ) ;
38+ writer . WriteByte ( messageType ) ;
10339 stream . CopyFrom ( messageStream ) ;
10440
10541 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
11349 }
11450 }
11551 }
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 )
11854 {
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-
13255 using ( PooledBitStream stream = PooledBitStream . Get ( ) )
13356 {
13457 using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
13558 {
136- writer . WriteBool ( false ) ; // Encryption
137- writer . WriteBool ( false ) ; // Authentication
138-
139- writer . WriteBits ( messageType , 6 ) ;
59+ writer . WriteByte ( messageType ) ;
14060 stream . CopyFrom ( messageStream ) ;
14161
14262 NetworkProfiler . StartEvent ( TickType . Send , ( uint ) stream . Length , channelName , MLAPIConstants . MESSAGE_NAMES [ messageType ] ) ;
0 commit comments