Ejemplo n.º 1
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);

        if (cPlayerActor != null)
        {
            CPlayerAirMotor cAirMotor = cPlayerActor.GetComponent <CPlayerAirMotor>();

            while (_cStream.HasUnreadData)
            {
                ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

                switch (eNetworkAction)
                {
                case ENetworkAction.UpdateStates:
                    cAirMotor.m_usMovementStates = _cStream.ReadUInt();
                    break;

                default:
                    Debug.LogError(string.Format("Unknown network action ({0})", (int)eNetworkAction));
                    break;
                }
            }
        }
    }
Ejemplo n.º 2
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction          = (ENetworkAction)_cStream.ReadByte();
            CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId();

            GameObject          cModuleGunObject    = cModuleGunViewId.GameObject;
            CToolInterface      cToolInterface      = cModuleGunObject.GetComponent <CToolInterface>();
            CModuleGunBehaviour cModuleGunBehaviour = cModuleGunObject.GetComponent <CModuleGunBehaviour>();

            switch (eAction)
            {
            case ENetworkAction.OpenDui:
                cModuleGunBehaviour.OpenDui(cToolInterface.OwnerPlayerActor.GetComponent <CPlayerInteractor>().TargetActorObject);
                break;

            case ENetworkAction.CloseDui:
                cModuleGunBehaviour.CloseDui();
                break;

            default:
                Debug.LogError("Unknown network action");
                break;
            }
        }
    }
Ejemplo n.º 3
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        GameObject      cPlayerObject   = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);
        CPlayerBackPack cPlayerBackPack = cPlayerObject.GetComponent <CPlayerBackPack>();

        // Process stream data
        while (_cStream.HasUnreadData)
        {
            // Extract action
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();

            // Handle action
            switch (eAction)
            {
            case ENetworkAction.PickupModule:
                CNetworkViewId cModuleViewId = _cStream.ReadNetworkViewId();
                cPlayerBackPack.PickupModule(_cNetworkPlayer.PlayerId, cModuleViewId);

                break;

            case ENetworkAction.DropModule:
                cPlayerBackPack.DropModule();
                break;

            case ENetworkAction.InsertCell:
                CNetworkViewId cCellSlotViewId = _cStream.ReadNetworkViewId();
                cPlayerBackPack.InsertCell(_cNetworkPlayer.PlayerId, cCellSlotViewId);
                break;
            }
        }
    }
Ejemplo n.º 4
0
    public static void UnserializeData(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        // While there is unread data in the stream
        while (_cStream.HasUnreadData)
        {
            // Save the first byte as the network action
            ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

            // Switch on the network action
            switch (eNetworkAction)
            {
            // New player message was sent
            case ENetworkAction.ActionSendPlayerMessage:
            {
                // Read out messages into output strings
                string strName    = _cStream.ReadString();
                string strMessage = _cStream.ReadString();

                // Find all players within 'hearing' range of the source player
                foreach (CNetworkPlayer Player in CheckPlayerDistances(_cNetworkPlayer))
                {
                    // Invoke RPC call to send the message to each player
                    Instance.InvokeRpc(Player.PlayerId, "ReceivePlayerMessage", strName, strMessage);
                }

                break;
            }
            }
        }
    }
Ejemplo n.º 5
0
	public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		while (_cStream.HasUnreadData)
		{
			CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId();
			GameObject cTurretObject = CNetwork.Factory.FindObject(cTurretViewId);
			
			if (cTurretObject != null)
			{
				CLaserTurretBehaviour cLaserTurretBehaviour = cTurretObject.GetComponent<CLaserTurretBehaviour>();
				ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
				
				switch (eAction)
				{
				case ENetworkAction.FireLasers:
					cLaserTurretBehaviour.FireLasers();
					break;
					
				default:
					Debug.LogError(string.Format("Unknown network action ({0})", eAction));
					break;
				}
			}
		}
	}
Ejemplo n.º 6
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction          = (ENetworkAction)_cStream.ReadByte();
            CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId();

            GameObject     cModuleGunObject = cModuleGunViewId.GameObject;
            CToolInterface cToolInterface   = cModuleGunObject.GetComponent <CToolInterface>();
            CTorchLight    cTorchLight      = cModuleGunObject.GetComponent <CTorchLight>();

            switch (eAction)
            {
            case ENetworkAction.TurnOnLight:
                cTorchLight.SetActive(true);
                break;

            case ENetworkAction.TurnOffLight:
                cTorchLight.SetActive(false);
                break;

            case ENetworkAction.ToggleColour:
                cTorchLight.ToggleColour();
                break;


            default:
                Debug.LogError("Unknown network action: " + eAction);
                break;
            }
        }
    }
Ejemplo n.º 7
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            CNetworkViewId cCockpitObjectViewId = _cStream.ReadNetworkViewId();
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();

            GameObject cCockpitObject = CNetwork.Factory.FindObject(cCockpitObjectViewId);

            CCockpit cCockpit = cCockpitObject.GetComponent <CCockpit>();

            switch (eAction)
            {
            case ENetworkAction.EnterCockpit:
                cCockpit.HandleEnterCockpit(_cNetworkPlayer.PlayerId);
                break;

            case ENetworkAction.LeaveCockpit:
                cCockpit.HandleLeaveCockpit(_cNetworkPlayer.PlayerId);
                break;

            default:
                Debug.LogError(string.Format("Unknown network action ({0})"));
                break;
            }
        }
    }
Ejemplo n.º 8
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId();
            GameObject     cTurretObject = CNetwork.Factory.FindObject(cTurretViewId);

            if (cTurretObject != null)
            {
                CLaserTurretBehaviour cLaserTurretBehaviour = cTurretObject.GetComponent <CLaserTurretBehaviour>();
                ENetworkAction        eAction = (ENetworkAction)_cStream.ReadByte();

                switch (eAction)
                {
                case ENetworkAction.FireLasers:
                    cLaserTurretBehaviour.FireLasers();
                    break;

                default:
                    Debug.LogError(string.Format("Unknown network action ({0})", eAction));
                    break;
                }
            }
        }
    }
Ejemplo n.º 9
0
    public static void UnserializeData(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

        switch (eNetworkAction)
        {
        case ENetworkAction.ActionSendPlayerName:
        {
            string sPlayerName = _cStream.ReadString();

            //Send all dictionary entries to new player
            foreach (KeyValuePair <ulong, string> entry in CGamePlayers.s_cInstance.m_mPlayersNames)
            {
                //Make sure you don't send RPC to yourself. Foreach loops will not let you modify the collections object (dictionary) you are operating on.
                if (_cNetworkPlayer.PlayerId != CNetwork.PlayerId)
                {
                    CGamePlayers.s_cInstance.InvokeRpc(_cNetworkPlayer.PlayerId, "RegisterPlayerName", entry.Key, entry.Value);
                }
            }

            // Send new player name to all other players
            CGamePlayers.s_cInstance.InvokeRpcAll("RegisterPlayerName", _cNetworkPlayer.PlayerId, sPlayerName);

            break;
        }
        }
    }
Ejemplo n.º 10
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
            CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId();

            GameObject cModuleGunObject = cModuleGunViewId.GameObject;
            CToolInterface cToolInterface = cModuleGunObject.GetComponent<CToolInterface>();
            CTorchLight cTorchLight = cModuleGunObject.GetComponent<CTorchLight>();

            switch (eAction)
            {
                case ENetworkAction.TurnOnLight:
                    cTorchLight.SetActive(true);
                    break;

                case ENetworkAction.TurnOffLight:
                    cTorchLight.SetActive(false);
                    break;

                case ENetworkAction.ToggleColour:
                    cTorchLight.ToggleColour();
                    break;


                default:
                    Debug.LogError("Unknown network action: " + eAction);
                    break;
            }
        }
    }
Ejemplo n.º 11
0
    public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        GameObject     cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);
        CPlayerRagdoll ragdoll      = cPlayerActor.GetComponent <CPlayerRagdoll>();

        while (_cStream.HasUnreadData)
        {
            // Extract action
            ragdoll.m_bRagdollState.Set(_cStream.ReadByte());
        }
    }
Ejemplo n.º 12
0
    public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);

        if (cPlayerActor != null)
        {
            //while (_cStream.HasUnreadData)
            {
                // Retrieve player actor motor
                CPlayerGroundMotor cPlayerActorMotor = cPlayerActor.GetComponent <CPlayerGroundMotor>();

                ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

                switch (eNetworkAction)
                {
                case ENetworkAction.UpdateStates:
                {
                    cPlayerActorMotor.m_uiMovementStates = _cStream.ReadByte();

                    if (cPlayerActor != CGamePlayers.SelfActor)
                    {
                        cPlayerActor.transform.eulerAngles = new Vector3(0.0f, _cStream.ReadFloat(), 0.0f);
                    }
                    else
                    {
                        _cStream.ReadFloat();
                    }

                    cPlayerActorMotor.m_bStates.Set((byte)cPlayerActorMotor.m_uiMovementStates);
                }
                break;


                default:
                    Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction));
                    break;
                }
            }
        }
    }
Ejemplo n.º 13
0
    public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            // Extract action
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();

            switch (eAction)
            {
            case ENetworkAction.SetRepairState:
            {
                //Figure out which kits sent it's new state
                CCircuitryKitBehaviour CircuitryKit = _cStream.ReadNetworkViewId().GameObject.GetComponent <CCircuitryKitBehaviour>();

                CircuitryKit.m_TargetComponent = _cStream.ReadNetworkViewId().GameObject.GetComponent <CComponentInterface>();
                CircuitryKit.m_eRepairState    = (ERepairState)_cStream.ReadByte();

                break;
            }
            }
        }
    }
Ejemplo n.º 14
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        if (CGamePlayers.SelfActor == null)
        {
            return;
        }

        CPlayerInteractor cPlayerInteractor = CGamePlayers.SelfActor.GetComponent <CPlayerInteractor>();

        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction          = (ENetworkAction)_cStream.ReadByte();
            CNetworkViewId cNewTargetViewId = _cStream.ReadNetworkViewId();

            switch (eAction)
            {
            case ENetworkAction.UpdateTarget:
                if (cNewTargetViewId != null)
                {
                    cPlayerInteractor.m_cTargetActorObject = cNewTargetViewId.GameObject;
                    if (cPlayerInteractor.EventServerTargetChange != null)
                    {
                        cPlayerInteractor.EventServerTargetChange(cPlayerInteractor.m_cTargetActorObject);
                    }

                    // Debug.LogError("Found new target: " + cPlayerInteractor.m_cTargetActorObject);
                }
                else
                {
                    cPlayerInteractor.m_cTargetActorObject = null;
                    if (cPlayerInteractor.EventServerTargetChange != null)
                    {
                        cPlayerInteractor.EventServerTargetChange(null);
                    }

                    //Debug.LogError("Found new target: " + null);
                }
                break;

            default:
                Debug.LogError("Unknown network action");
                break;
            }
        }
    }
Ejemplo n.º 15
0
    public static void UnserializeBeltState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction     = (ENetworkAction)_cStream.ReadByte();
            CPlayerBelt    cPlayerBelt = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent <CPlayerBelt>();

            switch (eAction)
            {
            case ENetworkAction.PickupTool:
            {
                CNetworkViewId cToolViewId = _cStream.ReadNetworkViewId();
                cPlayerBelt.PickupTool(cToolViewId.GameObject);
            }
            break;
            }
        }
    }
Ejemplo n.º 16
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            CNetworkViewId oxygenRefillViewId = _cStream.ReadNetworkViewId();
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();

            GameObject cOxygenRefillerObject = oxygenRefillViewId.GameObject;

            COxygenRefillerBehaviour blah = cOxygenRefillerObject.GetComponent<COxygenRefillerBehaviour>();

            switch (eAction)
            {
                case ENetworkAction.RefillOxygen:
                    blah.HandlePlayerOxygenRefill(_cNetworkPlayer.PlayerId);
                    break;
            }
        }
    }
Ejemplo n.º 17
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            CNetworkViewId oxygenRefillViewId = _cStream.ReadNetworkViewId();
            ENetworkAction eAction            = (ENetworkAction)_cStream.ReadByte();

            GameObject cOxygenRefillerObject = oxygenRefillViewId.GameObject;

            COxygenRefillerBehaviour blah = cOxygenRefillerObject.GetComponent <COxygenRefillerBehaviour>();

            switch (eAction)
            {
            case ENetworkAction.RefillOxygen:
                blah.HandlePlayerOxygenRefill(_cNetworkPlayer.PlayerId);
                break;
            }
        }
    }
Ejemplo n.º 18
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
        CNetworkViewId cFireExtinguisherViewId = _cStream.ReadNetworkViewId();

        switch (eAction)
        {
        case ENetworkAction.ExtinguishFireStart:
            cFireExtinguisherViewId.GameObject.GetComponent <CFireExtinguisherSpray>().m_bActive.Set(true);
            break;

        case ENetworkAction.ExtinguishFireEnd:
            cFireExtinguisherViewId.GameObject.GetComponent <CFireExtinguisherSpray>().m_bActive.Set(false);
            break;

        default:
            Debug.LogError("Unknown network action");
            break;
        }
    }
Ejemplo n.º 19
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
        CNetworkViewId cMedicalSpayViewId = _cStream.ReadNetworkViewId();

        switch (eAction)
        {
            case ENetworkAction.SprayStart:
                cMedicalSpayViewId.GameObject.GetComponent<CMedicalSpray>().m_bActive.Set(true);
                break;

            case ENetworkAction.SprayEnd:
                cMedicalSpayViewId.GameObject.GetComponent<CMedicalSpray>().m_bActive.Set(false);
                break;

            default:
                Debug.LogError("Unknown network action");
                break;
        }
    }
Ejemplo n.º 20
0
    static public void UnserializeSliderEvents(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            // Get the DUISlider and its network view
            CDUISlider duiSlider = CNetwork.Factory.FindObject(_cStream.ReadNetworkViewId()).GetComponent <CDUISlider>();

            // Get the interaction notification
            ESliderNotificationType notification = (ESliderNotificationType)_cStream.ReadByte();

            // Based on the notification type, update the clients of the event
            switch (notification)
            {
            case ESliderNotificationType.OnValueChange:
                float value = _cStream.ReadFloat();
                duiSlider.SetSliderValue(value);
                break;

            default: break;
            }
        }
    }
Ejemplo n.º 21
0
	static public void UnserializeSliderEvents(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		while(_cStream.HasUnreadData)
		{
			// Get the DUISlider and its network view
			CDUISlider duiSlider = CNetwork.Factory.FindObject(_cStream.ReadNetworkViewId()).GetComponent<CDUISlider>();
			
			// Get the interaction notification
			ESliderNotificationType notification = (ESliderNotificationType)_cStream.ReadByte();
			
			// Based on the notification type, update the clients of the event
			switch(notification) 
			{
			case ESliderNotificationType.OnValueChange:
				float value = _cStream.ReadFloat();
				duiSlider.SetSliderValue(value);
				break;
				
			default:break;
			}
		}
	}
Ejemplo n.º 22
0
    public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
		while (_cStream.HasUnreadData)
        {
            // Extract action
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
           
            switch (eAction)
            {
				case ENetworkAction.SetRepairState:
				{
					//Figure out which ratchet sent it's new state
					CRatchetBehaviour ratchet = _cStream.ReadNetworkViewId().GameObject.GetComponent<CRatchetBehaviour>();
					
					ratchet.m_TargetComponent = _cStream.ReadNetworkViewId().GameObject.GetComponent<CComponentInterface>();
					ratchet.m_eRepairState = (ERepairState)_cStream.ReadByte();
					
					break;
				}
			}
		}
	}
Ejemplo n.º 23
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction     = (ENetworkAction)_cStream.ReadByte();
            CNetworkViewId cAk47ViewId = _cStream.ReadNetworkViewId();

            switch (eAction)
            {
            case ENetworkAction.ShootStart:
                cAk47ViewId.GameObject.GetComponent <CAk47Behaviour>().m_bShoot = true;
                break;

            case ENetworkAction.ShootEnd:
                cAk47ViewId.GameObject.GetComponent <CAk47Behaviour>().m_bShoot = false;
                break;

            default:
                Debug.LogError("Unknown network action");
                break;
            }
        }
    }
Ejemplo n.º 24
0
    public static void ProcessPlayerSerializedData(CNetworkPlayer _cPlayer, byte[] _baData)
    {
        // Create packet stream
        CNetworkStream cStream = new CNetworkStream(_baData);

        // Ignore timestamp packet id
        cStream.IgnoreBytes(1);

        // Retrieve latency
        ulong ulLatency = RakNet.RakNet.GetTime() - cStream.ReadULong();

        // Ignmore serialized data packet id
        cStream.IgnoreBytes(1);

        // Iterate through the packet data
        while (cStream.HasUnreadData &&
               cStream.NumUnreadBits > 18)
        {
            // Extract the target identifier
            byte bTargetIdentifier = cStream.ReadByte();

            // Extract the size of the data
            ushort usBitSize  = cStream.ReadBits <ushort>(10);
            ushort usByteSize = (ushort)((float)usBitSize / 8.0f);

            // Extract the data
            byte[] baData = new byte[usByteSize];
            cStream.BitStream.ReadBits(baData, usBitSize);

            // Create stream for the control
            CNetworkStream cTargetStream = new CNetworkStream();
            cTargetStream.WriteBits(baData, usBitSize);

            // Have the target process its data
            s_mThrottledSerializeTargets[bTargetIdentifier].nUnserializeMethod(_cPlayer, cTargetStream);
        }
    }
Ejemplo n.º 25
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId();
            GameObject     cTurretObject = CNetwork.Factory.FindObject(cTurretViewId);

            if (cTurretObject != null)
            {
                CMiningTurretBehaviour cMiningTurretBehaviour = cTurretObject.GetComponent <CMiningTurretBehaviour>();
                ENetworkAction         eAction = (ENetworkAction)_cStream.ReadByte();

                switch (eAction)
                {
                case ENetworkAction.StartFractureLaser:
                    cMiningTurretBehaviour.m_bFractureLaserButtonDown = true;
                    break;

                case ENetworkAction.StopFractureLaser:
                    cMiningTurretBehaviour.m_bFractureLaserButtonDown = false;
                    break;

                case ENetworkAction.StartExtractorBeam:
                    cMiningTurretBehaviour.m_bExtracterBeamButtonDown = true;
                    break;

                case ENetworkAction.StopExtractorBeam:
                    cMiningTurretBehaviour.m_bExtracterBeamButtonDown = false;
                    break;

                default:
                    Debug.LogError(string.Format("Unknown network action ({0})", eAction));
                    break;
                }
            }
        }
    }
Ejemplo n.º 26
0
    public static void UnserializeBeltState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
            CPlayerBelt cPlayerBelt = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent<CPlayerBelt>();

            switch (eAction)
            {
                case ENetworkAction.PickupTool:
                    {
                        CNetworkViewId cToolViewId = _cStream.ReadNetworkViewId();
                        cPlayerBelt.PickupTool(cToolViewId.GameObject);
                    }
                    break;
            }
        }
    }
Ejemplo n.º 27
0
    public static void ProcessInboundStream(ulong _uiLatency, CNetworkStream _cStream)
    {
		List<INetworkVar> cSyncedNetworkVars = new List<INetworkVar>();
		float fSyncedTick = 0.0f;

		if (CNetwork.IsServer)
		{
			fSyncedTick  = ((float)RakNet.RakNet.GetTimeMS()) / 1000.0f;
			fSyncedTick -= Mathf.Floor(fSyncedTick);
			fSyncedTick *= CNetworkServer.k_fSendRate;
		}
		else
		{
			fSyncedTick = CNetwork.Connection.Tick - ((float)_uiLatency / 1000.0f);

			if (fSyncedTick < 0.0f)
			{
				fSyncedTick = CNetworkServer.k_fSendRate - fSyncedTick;
				//Debug.Log(fSyncedTick);
			}
		}

        while (_cStream.HasUnreadData)
        {
            // Extract owner network view id
            CNetworkViewId cNetworkViewId = _cStream.ReadNetworkViewId();

            // Extract procedure type
            EProdecure eProcedure = (EProdecure)_cStream.ReadByte();

            // Retrieve network view instance
            CNetworkView cNetworkView = CNetworkView.FindUsingViewId(cNetworkViewId);
			
            // Process network var sync procedure
            if (eProcedure == EProdecure.SyncNetworkVar)
            {
                // Extract network var identifier
                byte bNetworkVarIdentifier = _cStream.ReadByte();

                // Retrieve network var instance
                INetworkVar cNetworkVar = cNetworkView.m_mNetworkVars[bNetworkVarIdentifier];

                // Retrieve network var type
                Type cVarType = cNetworkVar.GetValueType();

                // Extract value serialized
                object cNewVarValue = _cStream.ReadType(cVarType);

                // Sync with new value
				cNetworkVar.SyncValue(cNewVarValue, fSyncedTick);

				// Add to callback list
				cSyncedNetworkVars.Add(cNetworkVar);
            }

            // Process network rpc procedure
            else if (eProcedure == EProdecure.InvokeNetworkRpc)
            {
                // Extract rpc method identifier
                byte bMethodIdentifier = _cStream.ReadByte();

                // Retrieve method owner instance
                Component cParentComponent = cNetworkView.m_mNetworkRpcs[bMethodIdentifier].cUnityComponent;

                // Retrieve method info
                MethodInfo cMethodInfo = cNetworkView.m_mNetworkRpcs[bMethodIdentifier].cMethodInfo;

                // Extract method parameters
                object[] caParameterValues = _cStream.ReadMethodParameters(cMethodInfo);

                // Invoke the rpc method
                cMethodInfo.Invoke(cParentComponent, caParameterValues);
            }
        }

		// Invoke callbacks for synced network vars
		foreach (INetworkVar cSyncedNetworkVar in cSyncedNetworkVars)
		{
			cSyncedNetworkVar.InvokeSyncCallback();
		}
    }
Ejemplo n.º 28
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
            CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId();

            GameObject cModuleGunObject = cModuleGunViewId.GameObject;
            CToolInterface cToolInterface = cModuleGunObject.GetComponent<CToolInterface>();
            CModuleGunBehaviour cModuleGunBehaviour = cModuleGunObject.GetComponent<CModuleGunBehaviour>();

            switch (eAction)
            {
                case ENetworkAction.OpenDui:
                    cModuleGunBehaviour.OpenDui(cToolInterface.OwnerPlayerActor.GetComponent<CPlayerInteractor>().TargetActorObject);
                    break;

                case ENetworkAction.CloseDui:
                    cModuleGunBehaviour.CloseDui();
                    break;

                default:
                    Debug.LogError("Unknown network action");
                    break;
            }
        }
    }
Ejemplo n.º 29
0
	public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		while (_cStream.HasUnreadData)
		{
			CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId();
			GameObject cTurretObject = CNetwork.Factory.FindObject(cTurretViewId);

			if (cTurretObject != null)
			{
				CMiningTurretBehaviour cMiningTurretBehaviour = cTurretObject.GetComponent<CMiningTurretBehaviour>();		
				ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();

				switch (eAction)
				{
				case ENetworkAction.StartFractureLaser:
                    cMiningTurretBehaviour.m_bFractureLaserButtonDown = true;
					break;

				case ENetworkAction.StopFractureLaser:
                    cMiningTurretBehaviour.m_bFractureLaserButtonDown = false;
					break;

				case ENetworkAction.StartExtractorBeam:
                    cMiningTurretBehaviour.m_bExtracterBeamButtonDown = true;
					break;

				case ENetworkAction.StopExtractorBeam:
                    cMiningTurretBehaviour.m_bExtracterBeamButtonDown = false;
					break;

				default:
					Debug.LogError(string.Format("Unknown network action ({0})", eAction));
					break;
				}
			}
		}
	}
Ejemplo n.º 30
0
    public static void UnserializeData(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        // While there is unread data in the stream
        while (_cStream.HasUnreadData)
        {
            // Save the first byte as the network action
            ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

            // Switch on the network action
            switch (eNetworkAction)
            {
                    // New player message was sent
                case ENetworkAction.ActionSendPlayerMessage:
                {
                    // Read out messages into output strings
                    string strName    = _cStream.ReadString();
                    string strMessage = _cStream.ReadString();

                    // Find all players within 'hearing' range of the source player
                    foreach (CNetworkPlayer Player in CheckPlayerDistances(_cNetworkPlayer))
                    {
                        // Invoke RPC call to send the message to each player
                        Instance.InvokeRpc(Player.PlayerId, "ReceivePlayerMessage", strName, strMessage);
                    }

                    break;
                }
            }
        }
    }
Ejemplo n.º 31
0
	public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);

		if (cPlayerActor != null)
		{
            
            //while (_cStream.HasUnreadData)
            {
                // Retrieve player actor motor  
                CPlayerGroundMotor cPlayerActorMotor = cPlayerActor.GetComponent<CPlayerGroundMotor>();

                ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

                switch (eNetworkAction)
                {
                    case ENetworkAction.UpdateStates:
                        {
                            cPlayerActorMotor.m_uiMovementStates = _cStream.ReadByte();

                            if (cPlayerActor != CGamePlayers.SelfActor)
                            {
                                cPlayerActor.transform.eulerAngles = new Vector3(0.0f, _cStream.ReadFloat(), 0.0f);
                            }
                            else
                            {
                                _cStream.ReadFloat();
                            }

                            cPlayerActorMotor.m_bStates.Set((byte)cPlayerActorMotor.m_uiMovementStates);
                        }
                        break;


                    default:
                        Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction));
                        break;
                }
            }
		}
	}
Ejemplo n.º 32
0
    static public void UnserializeElementEvents(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        while (_cStream.HasUnreadData)
        {
            // Get the DUIElement and its network view
            CDUIElement duiElement = CNetwork.Factory.FindObject(_cStream.ReadNetworkViewId()).GetComponent <CDUIElement>();

            // Get the interaction notification
            EElementNotificationType notification = (EElementNotificationType)_cStream.ReadByte();

            // Based on the notification type, update the clients of the event
            switch (notification)
            {
            case EElementNotificationType.OnClick:
                int click = _cStream.ReadInt();
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, new object[] { click });
                break;

            case EElementNotificationType.OnDoubleClick:
                int dClick = _cStream.ReadInt();
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, new object[] { dClick });
                break;

            case EElementNotificationType.OnPress:
                bool isPressed = _cStream.ReadByte() == 1 ? true : false;
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, new object[] { isPressed });
                break;

            case EElementNotificationType.OnSelect:
                bool isSelected = _cStream.ReadByte() == 1 ? true : false;
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, new object[] { isSelected });
                break;

            case EElementNotificationType.OnHover:
                bool isHovered = _cStream.ReadByte() == 1 ? true : false;
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, new object[] { isHovered });
                break;

            case EElementNotificationType.OnDrag:
                float deltaX = _cStream.ReadFloat();
                float deltaY = _cStream.ReadFloat();
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, new object[] { deltaX, deltaY });
                break;

            case EElementNotificationType.OnDragStart:
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, null);
                break;

            case EElementNotificationType.OnDragEnd:
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, null);
                break;

            case EElementNotificationType.OnScroll:
                float delta = _cStream.ReadFloat();
                NotifyOnEvent(_cNetworkPlayer, duiElement, notification, new object[] { delta });
                break;

            default:
                break;
            }
        }
    }
Ejemplo n.º 33
0
    public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        if (CGamePlayers.SelfActor == null)
        {
            return;
        }

        CPlayerInteractor cPlayerInteractor = CGamePlayers.SelfActor.GetComponent<CPlayerInteractor>();

        while (_cStream.HasUnreadData)
        {
            ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();
            CNetworkViewId cNewTargetViewId = _cStream.ReadNetworkViewId();

            switch (eAction)
            {
                case ENetworkAction.UpdateTarget:
                    if (cNewTargetViewId != null)
                    {
                        cPlayerInteractor.m_cTargetActorObject = cNewTargetViewId.GameObject;
                        if (cPlayerInteractor.EventServerTargetChange != null) cPlayerInteractor.EventServerTargetChange(cPlayerInteractor.m_cTargetActorObject);

                       // Debug.LogError("Found new target: " + cPlayerInteractor.m_cTargetActorObject);
                    }
                    else
                    {
                        cPlayerInteractor.m_cTargetActorObject = null;
                        if (cPlayerInteractor.EventServerTargetChange != null) cPlayerInteractor.EventServerTargetChange(null);

                        //Debug.LogError("Found new target: " + null);
                    }
                    break;

                default:
                    Debug.LogError("Unknown network action");
                    break;
            }
        }
    }
Ejemplo n.º 34
0
	public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		while (_cStream.HasUnreadData)
		{
			CNetworkViewId cCockpitObjectViewId = _cStream.ReadNetworkViewId();
			ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();

			GameObject cCockpitObject = CNetwork.Factory.FindObject(cCockpitObjectViewId);

			CCockpit cCockpit = cCockpitObject.GetComponent<CCockpit>();

			switch (eAction)
			{
				case ENetworkAction.EnterCockpit:
					cCockpit.HandleEnterCockpit(_cNetworkPlayer.PlayerId);
					break;

				case ENetworkAction.LeaveCockpit:
					cCockpit.HandleLeaveCockpit(_cNetworkPlayer.PlayerId);
					break;

				default:
					Debug.LogError(string.Format("Unknown network action ({0})"));
					break;
			}
		}
	}
Ejemplo n.º 35
0
    public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);
        CPlayerRagdoll ragdoll = cPlayerActor.GetComponent<CPlayerRagdoll>();

        while (_cStream.HasUnreadData)
        {
            // Extract action
            ragdoll.m_bRagdollState.Set(_cStream.ReadByte());
        }
    }
Ejemplo n.º 36
0
	public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		GameObject cPlayerObject = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);
		CPlayerBackPack cPlayerBackPack = cPlayerObject.GetComponent<CPlayerBackPack>();

		// Process stream data
		while (_cStream.HasUnreadData)
		{
			// Extract action
			ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte();

			// Handle action
			switch (eAction)
			{
				case ENetworkAction.PickupModule:
					CNetworkViewId cModuleViewId = _cStream.ReadNetworkViewId();
					cPlayerBackPack.PickupModule(_cNetworkPlayer.PlayerId, cModuleViewId);
					
					break;

				case ENetworkAction.DropModule:
					cPlayerBackPack.DropModule();
					break;
				
				case ENetworkAction.InsertCell:
					CNetworkViewId cCellSlotViewId = _cStream.ReadNetworkViewId();
					cPlayerBackPack.InsertCell(_cNetworkPlayer.PlayerId, cCellSlotViewId);
					break;
			}
		}
	}
Ejemplo n.º 37
0
	public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);

		if (cPlayerActor != null)
		{
			CPlayerAirMotor cAirMotor = cPlayerActor.GetComponent<CPlayerAirMotor>();

			while (_cStream.HasUnreadData)
			{
				ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

				switch (eNetworkAction)
				{
				case ENetworkAction.UpdateStates:
					cAirMotor.m_usMovementStates = _cStream.ReadUInt();
					break;

				default:
					Debug.LogError(string.Format("Unknown network action ({0})", (int)eNetworkAction));
					break;
				}
			}
		}
	}
Ejemplo n.º 38
0
	public static void UnserializeData(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();
		
		switch (eNetworkAction)
		{
			case ENetworkAction.ActionSendPlayerName:
			{
				string sPlayerName = _cStream.ReadString();

				//Send all dictionary entries to new player
				foreach (KeyValuePair<ulong, string> entry in CGamePlayers.s_cInstance.m_mPlayersNames) 
				{
					//Make sure you don't send RPC to yourself. Foreach loops will not let you modify the collections object (dictionary) you are operating on.
					if(_cNetworkPlayer.PlayerId != CNetwork.PlayerId)
					{
						CGamePlayers.s_cInstance.InvokeRpc(_cNetworkPlayer.PlayerId, "RegisterPlayerName", entry.Key, entry.Value);
					}
				}
						
				// Send new player name to all other players
				CGamePlayers.s_cInstance.InvokeRpcAll("RegisterPlayerName", _cNetworkPlayer.PlayerId, sPlayerName);
				
				break;
			}
		}
	}
Ejemplo n.º 39
0
    public static void UnserializeIKTarget(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);

        if (cPlayerActor != null)
        {
            CPlayerIKController cPlayerIKController = cPlayerActor.GetComponent <CPlayerIKController>();

            ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

            switch (eNetworkAction)
            {
            case ENetworkAction.SetRightTransform:
            {
                Vector3 pos = new Vector3();
                Vector3 rot = new Vector3();

                pos.x = _cStream.ReadFloat();
                pos.y = _cStream.ReadFloat();
                pos.z = _cStream.ReadFloat();

                cPlayerIKController.m_RightHandTarget.position = pos;

                rot.x = _cStream.ReadFloat();
                rot.y = _cStream.ReadFloat();
                rot.z = _cStream.ReadFloat();

                cPlayerIKController.m_RightHandTarget.rotation = Quaternion.Euler(rot);

                cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_RightHandTarget.position);
                cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_RightHandTarget.rotation.eulerAngles);
            }
            break;

            case ENetworkAction.SetLeftTransform:
            {
                Vector3 pos = new Vector3();
                Vector3 rot = new Vector3();

                pos.x = _cStream.ReadFloat();
                pos.y = _cStream.ReadFloat();
                pos.z = _cStream.ReadFloat();

                cPlayerIKController.m_LeftHandTarget.position = pos;

                rot.x = _cStream.ReadFloat();
                rot.y = _cStream.ReadFloat();
                rot.z = _cStream.ReadFloat();

                cPlayerIKController.m_LeftHandTarget.rotation = Quaternion.Euler(rot);

                cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_LeftHandTarget.position);
                cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_LeftHandTarget.rotation.eulerAngles);
            }
            break;

            default:
                Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction));
                break;
            }
        }
    }
Ejemplo n.º 40
0
	public static void UnserializeIKTarget(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);
		
		if (cPlayerActor != null)
		{			
			CPlayerIKController cPlayerIKController = cPlayerActor.GetComponent<CPlayerIKController>();
			
			ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();
			
			switch (eNetworkAction)
			{
			case ENetworkAction.SetRightTransform:
			{
				Vector3 pos = new Vector3();
				Vector3 rot = new Vector3();

				pos.x = _cStream.ReadFloat();
				pos.y = _cStream.ReadFloat();
				pos.z = _cStream.ReadFloat();

				cPlayerIKController.m_RightHandTarget.position = pos;

				rot.x = _cStream.ReadFloat();
				rot.y = _cStream.ReadFloat();
				rot.z = _cStream.ReadFloat();	

				cPlayerIKController.m_RightHandTarget.rotation = Quaternion.Euler(rot);
				
				cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_RightHandTarget.position);              
				cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_RightHandTarget.rotation.eulerAngles);
			}
				break;

			case ENetworkAction.SetLeftTransform:
			{
				Vector3 pos = new Vector3();
				Vector3 rot = new Vector3();
				
				pos.x = _cStream.ReadFloat();
				pos.y = _cStream.ReadFloat();
				pos.z = _cStream.ReadFloat();
				
				cPlayerIKController.m_LeftHandTarget.position = pos;
				
				rot.x = _cStream.ReadFloat();
				rot.y = _cStream.ReadFloat();
				rot.z = _cStream.ReadFloat();	
				
				cPlayerIKController.m_LeftHandTarget.rotation = Quaternion.Euler(rot);
				
				cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_LeftHandTarget.position);              
				cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_LeftHandTarget.rotation.eulerAngles);
			}
				break;
				
			default:
				Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction));
				break;
			}
		}		
	}  
Ejemplo n.º 41
0
	public static void ProcessPlayerSerializedData(CNetworkPlayer _cPlayer, byte[] _baData)
	{
		// Create packet stream
		CNetworkStream cStream = new CNetworkStream(_baData);
        
        // Ignore timestamp packet id
		cStream.IgnoreBytes(1);

		// Retrieve latency
		ulong ulLatency = RakNet.RakNet.GetTime() - cStream.ReadULong();

        // Ignmore serialized data packet id
		cStream.IgnoreBytes(1);

		// Iterate through the packet data
		while (cStream.HasUnreadData &&
               cStream.NumUnreadBits > 18)
		{
			// Extract the target identifier
			byte bTargetIdentifier = cStream.ReadByte();

			// Extract the size of the data
            ushort usBitSize = cStream.ReadBits<ushort>(10);
            ushort usByteSize = (ushort)((float)usBitSize / 8.0f);

			// Extract the data
            byte[] baData = new byte[usByteSize];
            cStream.BitStream.ReadBits(baData, usBitSize);

			// Create stream for the control
			CNetworkStream cTargetStream = new CNetworkStream();
            cTargetStream.WriteBits(baData, usBitSize);

			// Have the target process its data
			s_mThrottledSerializeTargets[bTargetIdentifier].nUnserializeMethod(_cPlayer, cTargetStream);
		}
	}