void OnJoinResult(MyPacket packet)
        {
           JoinResultMsg msg = ReplicationLayer.OnJoinResult(packet);

           OnUserJoined(ref msg);
        }
 void OnClientConnected(MyPacket packet)
 {
     ConnectedClientDataMsg msg = ReplicationLayer.OnClientConnected(packet);
     OnConnectedClient(ref msg);
 }
 void OnWorldBattleData(MyPacket packet)
 {
     ServerBattleDataMsg msg = ReplicationLayer.OnWorldBattleData(packet);
     OnServerBattleData(ref msg);
 }
 void OnReplicationDestroy(MyPacket packet)
 {
     ReplicationLayer.ProcessReplicationDestroy(packet);
 }
 void OnReplicationCreate(MyPacket packet)
 {
     while (MyEntities.HasEntitiesToDelete())
     {
         MyEntities.DeleteRememberedEntities();
     }
     ReplicationLayer.ProcessReplicationCreate(packet);
 }
        private void ProcessEvent( MyPacket packet )
        {
            if ( _networkHandlers.Count == 0 )
            {
                ((MyReplicationLayer)MyMultiplayer.ReplicationLayer).ProcessEvent(packet);
                return;
            }

            //magic: DO NOT TOUCH
            BitStream stream = new BitStream();
            stream.ResetRead( packet );

            NetworkId networkId = stream.ReadNetworkId();
            //this value is unused, but removing this line corrupts the rest of the stream
            NetworkId blockedNetworkId = stream.ReadNetworkId();
            uint eventId = (uint)stream.ReadByte();

            CallSite site;
            IMyNetObject sendAs;
            object obj;
            if ( networkId.IsInvalid ) // Static event
            {
                site = m_typeTable.StaticEventTable.Get( eventId );
                sendAs = null;
                obj = null;
            }
            else // Instance event
            {
                sendAs = ( (MyReplicationLayer)MyMultiplayer.ReplicationLayer ).GetObjectByNetworkId( networkId );
                if ( sendAs == null )
                {
                    return;
                }
                var typeInfo = m_typeTable.Get( sendAs.GetType() );
                int eventCount = typeInfo.EventTable.Count;
                if ( eventId < eventCount ) // Directly
                {
                    obj = sendAs;
                    site = typeInfo.EventTable.Get( eventId );
                }
                else // Through proxy
                {
                    obj = ( (IMyProxyTarget)sendAs ).Target;
                    typeInfo = m_typeTable.Get( obj.GetType() );
                    site = typeInfo.EventTable.Get( eventId - (uint)eventCount ); // Subtract max id of Proxy
                }
            }

            #if DEBUG
            if ( ExtenderOptions.IsDebugging )
            {
                if ( !site.MethodInfo.Name.Contains( "SyncPropertyChanged" ) && !site.MethodInfo.Name.Contains( "OnSimulationInfo" ) )
                    ApplicationLog.Error( $"Caught event {site.MethodInfo.Name} from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( packet.Sender.Value )}:{packet.Sender.Value}" );
            }
            #endif
            //we're handling the network live in the game thread, this needs to go as fast as possible
            bool handled = false;
            Parallel.ForEach( _networkHandlers, handler =>
                                                {
                                                    if ( handler.CanHandle( site ) )
                                                        handled |= handler.Handle( packet.Sender.Value, site, stream, obj );
                                                } );

            if ( !handled )
                ( (MyReplicationLayer)MyMultiplayer.ReplicationLayer ).ProcessEvent( packet );
        }
        void OnValueChanged(MyPacket packet)
        {

        }