99using NebulaModel . Packets . Session ;
1010using NebulaModel . Utils ;
1111using NebulaWorld ;
12- using NebulaWorld . SocialIntegration ;
12+ using NebulaWorld . GameStates ;
13+ using System . IO ;
1314using System . Net ;
1415using System . Net . Sockets ;
1516using System . Reflection ;
@@ -21,6 +22,7 @@ namespace NebulaNetwork
2122{
2223 public class Client : NetworkProvider , IClient
2324 {
25+ private const float FRAGEMENT_UPDATE_INTERVAL = 0.1f ;
2426 private const float GAME_STATE_UPDATE_INTERVAL = 1f ;
2527 private const float MECHA_SYNCHONIZATION_INTERVAL = 30f ;
2628
@@ -32,7 +34,7 @@ public class Client : NetworkProvider, IClient
3234 private NebulaConnection serverConnection ;
3335 private bool websocketAuthenticationFailure ;
3436
35-
37+ private float fragmentUpdateTimer = 0f ;
3638 private float mechaSynchonizationTimer = 0f ;
3739 private float gameStateUpdateTimer = 0f ;
3840
@@ -186,13 +188,23 @@ public override void Update()
186188 gameStateUpdateTimer = 0f ;
187189 }
188190 }
191+
192+ fragmentUpdateTimer += Time . deltaTime ;
193+ if ( fragmentUpdateTimer >= FRAGEMENT_UPDATE_INTERVAL )
194+ {
195+ if ( GameStatesManager . FragmentSize > 0 )
196+ {
197+ GameStatesManager . UpdateBufferLength ( GetFragmentBufferLength ( ) ) ;
198+ }
199+ fragmentUpdateTimer = 0f ;
200+ }
189201 }
190202
191203 private void ClientSocket_OnMessage ( object sender , MessageEventArgs e )
192204 {
193205 if ( ! Multiplayer . IsLeavingGame )
194206 {
195- PacketProcessor . EnqueuePacketForProcessing ( e . RawData , new NebulaConnection ( clientSocket , serverEndpoint , PacketProcessor ) ) ;
207+ PacketProcessor . EnqueuePacketForProcessing ( e . RawData , serverConnection ) ;
196208 }
197209 }
198210
@@ -322,5 +334,18 @@ private static void DisableNagleAlgorithm(WebSocket socket)
322334 tcpClient . NoDelay = true ;
323335 }
324336 }
337+
338+ private int GetFragmentBufferLength ( )
339+ {
340+ MemoryStream buffer = ( MemoryStream ) AccessTools . Field ( typeof ( WebSocket ) , "_fragmentsBuffer" ) . GetValue ( clientSocket ) ;
341+ if ( buffer != null )
342+ {
343+ return ( int ) buffer . Length ;
344+ }
345+ else
346+ {
347+ return 0 ;
348+ }
349+ }
325350 }
326351}
0 commit comments