示例#1
0
文件: CCockpit.cs 项目: dacuster/VOID
    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;
            }
        }
    }
示例#2
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;
				}
			}
		}
	}
    void DecodeAudio(object _rawData)
    {
        //Convert incoming data to a CNetworkStream.
        CNetworkStream _cAudioDataStream = (CNetworkStream)_rawData;

        //Pull relevant information out of the network stream.
        int iFrequency       = _cAudioDataStream.ReadInt();
        int iNumSamples      = _cAudioDataStream.ReadInt();
        int iNumEncodedBytes = _cAudioDataStream.ReadInt();

        byte[]         baEncodedData = _cAudioDataStream.ReadBytes(iNumEncodedBytes);
        CNetworkViewId cSenderViewID = _cAudioDataStream.ReadNetworkViewId();

        // Decode
        short[] saDecodedFrames  = new short[iNumSamples];
        int     iNumDecodedBytes = m_eDecoder.Decode(baEncodedData, 0, iNumEncodedBytes, saDecodedFrames, 0, false);
        //Debug.Log("Decoded audio data size: " + iNumDecodedBytes + " : " + saDecodedFrames.Length);

        //Populate a new struct which can be accessed later.
        DecodeInformation decodedFrameInfo;

        decodedFrameInfo.saDecodedData = saDecodedFrames;
        decodedFrameInfo.iFrequency    = iFrequency;
        decodedFrameInfo.cSenderViewID = cSenderViewID;
        decodedFrameInfo.iNumSamples   = iNumSamples;

        s_decodedFrames.Enqueue(decodedFrameInfo);
    }
示例#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;
            }
            }
        }
    }
示例#5
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;
        }
        }
    }
    void OnRecievedPlayerMicrophoneAudio(CNetworkPlayer _cPlayer, CNetworkStream _cAudioDataStream)
    {
        GameObject     playerActor  = CGamePlayers.GetPlayerActor(_cPlayer.PlayerId);
        CNetworkViewId playerViewID = playerActor.GetComponent <CNetworkView>().ViewId;

        _cAudioDataStream.SetReadOffset(0);
        byte[] streamData = _cAudioDataStream.ReadBytes(_cAudioDataStream.NumUnreadBytes);

        CNetworkStream dataStream = new CNetworkStream();

        dataStream.Write(streamData);
        dataStream.Write(playerViewID);

        Dictionary <ulong, CNetworkPlayer> players = CNetwork.Server.FindNetworkPlayers();

        foreach (ulong playerID in players.Keys)
        {
            if (m_bReturnToSender)
            {
                CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream);
            }
            else
            {
                if (_cPlayer.PlayerId != playerID)
                {
                    CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream);
                }
            }
        }
    }
示例#7
0
    static void CompileThrottledSerializeTargetsOutboundData(CNetworkStream _cOutboundStream)
    {
        // Create packet stream
        CNetworkStream cSerializedDataStream = new CNetworkStream();

        foreach (KeyValuePair <byte, TSerializationMethods> tEntry in s_mThrottledSerializeTargets)
        {
            tEntry.Value.nSerializeMethod(cSerializedDataStream);

            if (cSerializedDataStream.BitSize > 0)
            {
                // Write the control identifier
                _cOutboundStream.Write(tEntry.Key);

                // Write the size of the data
                _cOutboundStream.WriteBits(cSerializedDataStream.BitSize, 10);

                // Write the data
                _cOutboundStream.Write(cSerializedDataStream);

                // Clear target stream
                cSerializedDataStream.Clear();
            }
        }
    }
示例#8
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;
            }
        }
    }
示例#9
0
    void ProcessOutboundPackets()
    {
        if (!m_bDownloadingInitialGameState)
        {
            // Increment outbound timer
            m_fPacketOutboundTimer += Time.deltaTime;

            if (m_fPacketOutboundTimer > m_fPacketOutboundInterval)
            {
                CNetworkStream cOutboundStream = new CNetworkStream();
                cOutboundStream.Write((byte)RakNet.DefaultMessageIDTypes.ID_TIMESTAMP);
                cOutboundStream.Write(RakNet.RakNet.GetTime());
                cOutboundStream.Write((byte)CNetworkServer.EPacketId.PlayerSerializedData);

                CompileThrottledSerializeTargetsOutboundData(cOutboundStream);

                // Check player has data to be sent to the server
                if (cOutboundStream.ByteSize > 10)                 // (byte)Packet Id + (ulong)timestamp + (byte)Packet Id
                {
                    m_tOutboundRateData.uiBytes      += cOutboundStream.ByteSize;
                    m_tOutboundRateData.uiNumEntries += 1;

                    // Dispatch data to the server
                    m_cRnPeer.Send(cOutboundStream.BitStream, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.RELIABLE_ORDERED, (char)0, m_cServerSystemAddress, false);

                    // Reset stream
                    s_cUntrottledSerializationStream.Clear();
                }

                // Decrement timer by interval
                m_fPacketOutboundTimer -= m_fPacketOutboundInterval;
            }
        }
    }
示例#10
0
    public static void SerializeIKTarget(CNetworkStream _cStream)
    {
        GameObject          cSelfActor        = CGamePlayers.SelfActor;
        CPlayerIKController cSelfIKController = cSelfActor.GetComponent <CPlayerIKController>();

        if (cSelfActor != null && cSelfIKController.m_RightHandTarget != null)
        {
            // Write rotation states
            _cStream.Write((byte)ENetworkAction.SetRightTransform);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.position.x);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.position.y);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.position.z);

            _cStream.Write((float)cSelfIKController.m_RightHandTarget.rotation.eulerAngles.x);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.rotation.eulerAngles.y);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.rotation.eulerAngles.z);
        }

        if (cSelfActor != null && cSelfIKController.m_LeftHandTarget != null)
        {
            // Write rotation states
            _cStream.Write((byte)ENetworkAction.SetLeftTransform);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.position.x);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.position.y);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.position.z);

            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.rotation.eulerAngles.x);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.rotation.eulerAngles.y);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.rotation.eulerAngles.z);
        }
    }
示例#11
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;
            }
        }
    }
示例#12
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;
                }
            }
        }
    }
示例#13
0
 public static void Serialize(CNetworkStream _cStream)
 {
     // Write in internal stream
     _cStream.Write(s_cSerializeStream);
     s_cSerializeStream.Clear();
     
 }
示例#14
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;
				}
			}
		}
	}
示例#15
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;
            }
        }
    }
示例#16
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;
            }
        }
    }
示例#17
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;
                }
            }
        }
    }
示例#18
0
    public void TransmitMicrophoneAudio(CNetworkStream _cAudioDataStream)
    {
        CNetworkStream cTransmitStream = new CNetworkStream();

        cTransmitStream.Write((byte)CNetworkServer.EPacketId.PlayerMicrophoneAudio);
        cTransmitStream.Write(_cAudioDataStream);

        m_cRnPeer.Send(cTransmitStream.BitStream, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.UNRELIABLE_SEQUENCED, (char)1, m_cServerSystemAddress, false);
    }
示例#19
0
    protected void HandlePlayerMicrophoneAudio(RakNet.RakNetGUID _cPlayerGuid, byte[] _baData)
    {
        if (EventRecievedPlayerMicrophoneAudio != null)
        {
            CNetworkStream cAudioDataStream = new CNetworkStream(_baData);
            cAudioDataStream.IgnoreBytes(1);

            EventRecievedPlayerMicrophoneAudio(FindNetworkPlayer(_cPlayerGuid.g), cAudioDataStream);
        }
    }
示例#20
0
    public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        // Retrieve player actors head
        CPlayerHead cMyActorHead = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent <CPlayerHead>();

        // Write my head's x-rotation
        float fRotationX = _cStream.ReadFloat();

        cMyActorHead.m_fHeadEulerX.Set(fRotationX);
    }
示例#21
0
    void HandleMicrophoneAudio(byte[] _bAudioData)
    {
        if (EventRecievedMicrophoneAudio != null)
        {
            CNetworkStream cAudioDataStream = new CNetworkStream(_bAudioData);
            cAudioDataStream.IgnoreBytes(1);

            EventRecievedMicrophoneAudio(cAudioDataStream);
        }
    }
示例#22
0
    public static void SerializeData(CNetworkStream _cStream)
    {
        if (m_bSerializeName)
        {
            _cStream.Write((byte)ENetworkAction.ActionSendPlayerName);
            _cStream.WriteString(CGamePlayers.s_cInstance.m_sPlayerName);

            CGamePlayers.m_bSerializeName = false;
        }
    }
示例#23
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());
        }
    }
示例#24
0
    public static void SerializePlayerState(CNetworkStream _cStream)
    {
        if (CGamePlayers.SelfActor != null)
        {
            // Retrieve my actors head
            CPlayerHead cMyActorHead = CGamePlayers.SelfActor.GetComponent <CPlayerHead>();

            // Write my head's x-rotation
            _cStream.Write(cMyActorHead.m_LocalXRotation);
        }
    }
示例#25
0
    public static void SerializeOutbound(CNetworkStream _cStream)
    {
        if (!s_cInstance.m_InFocus)
        {
            return;
        }

        _cStream.Write(s_cInstance.m_ulInputStates);
        _cStream.Write(s_cInstance.m_fSerializeMouseMovementX);
        _cStream.Write(s_cInstance.m_fSerializeMouseMovementY);

        s_cInstance.m_fSerializeMouseMovementX = 0.0f;
        s_cInstance.m_fSerializeMouseMovementY = 0.0f;
    }
示例#26
0
    public static void SerializeOutbound(CNetworkStream _cStream)
    {
        // Drop
        if (Input.GetKeyDown(s_eDropKey))
        {
            _cStream.Write((byte)ENetworkAction.DropModule);
        }

        // Write in internal stream
        if (s_cSerializeStream.ByteSize > 0)
        {
            _cStream.Write(s_cSerializeStream);
            s_cSerializeStream.Clear();
        }
    }
示例#27
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;
            }
        }
    }
示例#28
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;
            }
        }
    }
示例#29
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;
            }
        }
    }
示例#30
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;
            }
        }
    }
示例#31
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;
        }
    }
示例#32
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;
        }
    }
示例#33
0
    public static void SerializeData(CNetworkStream _cStream)
    {
        if (Instance.m_bSendMessage)
        {
            // Write the first byte to the stream as a network action
            _cStream.Write((byte)ENetworkAction.ActionSendPlayerMessage);

            // Write player's name to stream
            _cStream.WriteString(CGamePlayers.Instance.LocalPlayerName);

            // Write player's message to string
            _cStream.WriteString(m_sPlayerChatInput);

            // Clear player input
            m_sPlayerChatInput = "";

            // Stop sending the message
            Instance.m_bSendMessage = false;
        }
    }
示例#34
0
    void HandleNetworkViewPacket(byte[] _baData)
    {
        if (IsConnected)
        {
            // Create stream with data
            CNetworkStream cStream = new CNetworkStream(_baData);

            // Ignore ID_TIME
            cStream.IgnoreBytes(1);

            // Retrieve latency
            ulong ulLatency = RakNet.RakNet.GetTime() - cStream.ReadULong();
            // Ignore EPacketId.NetworkView identifier
            cStream.IgnoreBytes(1);

            // Process packet data
            CNetworkView.ProcessInboundStream(ulLatency, cStream);

            // Logger.WriteError("Processed Inbound Data of size ({0})", cStream.GetSize());
        }
    }
示例#35
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;
                }
            }
        }
    }
示例#36
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;
				}
			}
		}
	}
示例#37
0
文件: CDUISlider.cs 项目: nulhax/VOID
	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;
			}
		}
	}
示例#38
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;
            }
            }
        }
    }
示例#39
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;
				}
			}
		}
	}
示例#40
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;
                }
            }
		}
	}
示例#41
0
 public static void SerializeCockpitInteractions(CNetworkStream _cStream)
 {
     _cStream.Write(s_cSerializeStream);
     s_cSerializeStream.Clear();
 }
示例#42
0
 public static void UnserializeCockpitInteractions(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
 {
 }
示例#43
0
	void OnRecievedMicrophoneAudio(CNetworkStream _cAudioDataStream)
	{
		s_framesToDecode.Enqueue(_cAudioDataStream);
	}
示例#44
0
	public static void SerializePlayerState(CNetworkStream _cStream)
	{
		if (CGamePlayers.SelfActor != null)
		{
			// Retrieve my actors head
			CPlayerHead cMyActorHead = CGamePlayers.SelfActor.GetComponent<CPlayerHead>();

			// Write my head's x-rotation
			_cStream.Write(cMyActorHead.m_LocalXRotation);
		}
	}
示例#45
0
    void HandleNetworkViewPacket(byte[] _baData)
    {
		if (IsConnected)
		{
			// Create stream with data
			CNetworkStream cStream = new CNetworkStream(_baData);

			// Ignore ID_TIME
			cStream.IgnoreBytes(1);
			
			// Retrieve latency
			ulong ulLatency = RakNet.RakNet.GetTime() - cStream.ReadULong();
			// Ignore EPacketId.NetworkView identifier
			cStream.IgnoreBytes(1);
			
			// Process packet data
			CNetworkView.ProcessInboundStream(ulLatency, cStream);

			// Logger.WriteError("Processed Inbound Data of size ({0})", cStream.GetSize());
		}
    }
示例#46
0
    void ProcessOutboundPackets()
    {
		if (!m_bDownloadingInitialGameState)
		{
			// Increment outbound timer
			m_fPacketOutboundTimer += Time.deltaTime;

			if (m_fPacketOutboundTimer > m_fPacketOutboundInterval)
			{
				CNetworkStream cOutboundStream = new CNetworkStream();
				cOutboundStream.Write((byte)RakNet.DefaultMessageIDTypes.ID_TIMESTAMP);
				cOutboundStream.Write(RakNet.RakNet.GetTime());
				cOutboundStream.Write((byte)CNetworkServer.EPacketId.PlayerSerializedData);

				CompileThrottledSerializeTargetsOutboundData(cOutboundStream);

				// Check player has data to be sent to the server
				if (cOutboundStream.ByteSize > 10) // (byte)Packet Id + (ulong)timestamp + (byte)Packet Id
				{
					m_tOutboundRateData.uiBytes += cOutboundStream.ByteSize;
					m_tOutboundRateData.uiNumEntries += 1;

					// Dispatch data to the server
					m_cRnPeer.Send(cOutboundStream.BitStream, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.RELIABLE_ORDERED, (char)0, m_cServerSystemAddress, false);

					// Reset stream
					s_cUntrottledSerializationStream.Clear();
				}

				// Decrement timer by interval
				m_fPacketOutboundTimer -= m_fPacketOutboundInterval;
			}
		}
    }
示例#47
0
	public static void SerializeOutbound(CNetworkStream _cStream)
	{
		_cStream.Write(s_cSerializeStream);
		s_cSerializeStream.Clear();
	}
示例#48
0
    public static void SerializeOutbound(CNetworkStream _cStream)
    {
		// Drop
		if (Input.GetKeyDown(s_eDropKey))
		{
			_cStream.Write((byte)ENetworkAction.DropModule);
		}

		// Write in internal stream
		if (s_cSerializeStream.ByteSize > 0)
		{
			_cStream.Write(s_cSerializeStream);
			s_cSerializeStream.Clear();
		}
	}
示例#49
0
文件: CDUISlider.cs 项目: nulhax/VOID
	static public void SerializeSliderEvents(CNetworkStream _cStream)
	{
		_cStream.Write(s_SliderNotificationStream);
		s_SliderNotificationStream.Clear();
	}
示例#50
0
	public static void SerializePlayerState(CNetworkStream _cStream)
	{
        _cStream.Write(s_cSerializeStream);
        s_cSerializeStream.Clear();
	}
示例#51
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;
			}
		}
	}
示例#52
0
	void HandleMicrophoneAudio(byte[] _bAudioData)
	{
		if (EventRecievedMicrophoneAudio != null)
		{
			CNetworkStream cAudioDataStream = new CNetworkStream(_bAudioData);
			cAudioDataStream.IgnoreBytes(1);
			
			EventRecievedMicrophoneAudio(cAudioDataStream);
		}
	}
示例#53
0
	void OnRecievedPlayerMicrophoneAudio(CNetworkPlayer _cPlayer, CNetworkStream _cAudioDataStream)
	{		
		GameObject playerActor = CGamePlayers.GetPlayerActor(_cPlayer.PlayerId);
		CNetworkViewId playerViewID = playerActor.GetComponent<CNetworkView>().ViewId;
			
		_cAudioDataStream.SetReadOffset(0);		
		byte[] streamData =  _cAudioDataStream.ReadBytes(_cAudioDataStream.NumUnreadBytes);
		
		CNetworkStream dataStream = new CNetworkStream();
		dataStream.Write(streamData);
		dataStream.Write(playerViewID);		
				
		Dictionary<ulong,CNetworkPlayer> players = CNetwork.Server.FindNetworkPlayers();
					
		foreach(ulong playerID in players.Keys)
		{
			if(m_bReturnToSender)
			{
				CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream); 	
			}
			else
			{
				if(_cPlayer.PlayerId != playerID)
				{
					CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream); 		
				}
			}
		}
	}
示例#54
0
    static void CompileThrottledSerializeTargetsOutboundData(CNetworkStream _cOutboundStream)
    {
        // Create packet stream
        CNetworkStream cSerializedDataStream = new CNetworkStream();

        foreach (KeyValuePair<byte, TSerializationMethods> tEntry in s_mThrottledSerializeTargets)
        {
            tEntry.Value.nSerializeMethod(cSerializedDataStream);

            if (cSerializedDataStream.BitSize > 0)
            {
                // Write the control identifier
                _cOutboundStream.Write(tEntry.Key);

                // Write the size of the data
                _cOutboundStream.WriteBits(cSerializedDataStream.BitSize, 10);

                // Write the data
                _cOutboundStream.Write(cSerializedDataStream);

                // Clear target stream
                cSerializedDataStream.Clear();
            }
        }
    }
示例#55
0
文件: CCockpit.cs 项目: nulhax/VOID
	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;
			}
		}
	}
示例#56
0
	public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
	{
		// Retrieve player actors head
		CPlayerHead cMyActorHead = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent<CPlayerHead>();

		// Write my head's x-rotation
		float fRotationX = _cStream.ReadFloat();

		cMyActorHead.m_fHeadEulerX.Set(fRotationX);
	}
示例#57
0
	public void TransmitMicrophoneAudio(CNetworkStream _cAudioDataStream)
	{

		CNetworkStream cTransmitStream = new CNetworkStream();
		cTransmitStream.Write((byte)CNetworkServer.EPacketId.PlayerMicrophoneAudio);
		cTransmitStream.Write(_cAudioDataStream);
		
		m_cRnPeer.Send(cTransmitStream.BitStream, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.UNRELIABLE_SEQUENCED, (char)1, m_cServerSystemAddress, false);
	}
示例#58
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);
		}
	}
示例#59
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());
        }
    }
示例#60
0
	protected void HandleUnconnectPong(byte[] _baData, RakNet.SystemAddress _cServerSystemAddress, RakNet.RakNetGUID _cServerGuid)
	{
		// Create stream
		CNetworkStream cStream = new CNetworkStream(_baData);

		// Ignore message identifier
		cStream.IgnoreBytes(1);

		// Read time
		uint uiTime = cStream.ReadUInt();

		// Read response data
		byte[] baOfflinePingResponse = cStream.ReadBytes(cStream.NumUnreadBytes);

		// Create server info
		TServer tLanServerInfo = new TServer();
		tLanServerInfo.sIp = _cServerSystemAddress.ToString();
		tLanServerInfo.usPort = _cServerSystemAddress.GetPort();
		tLanServerInfo.uiLatency = RakNet.RakNet.GetTimeMS() - uiTime;
		tLanServerInfo.cGuid = new RakNet.RakNetGUID(_cServerGuid.g);

		// Convert response data to server info
		tLanServerInfo.tServerInfo = new CNetworkServer.TServerInfo(baOfflinePingResponse);
	
		
		uint uiLocalNumberOfAddresses = m_cRnPeer.GetNumberOfAddresses();
		string sIpPrefix = _cServerSystemAddress.ToString().Substring(0, _cServerSystemAddress.ToString().IndexOf('.'));
		bool bIsLanServer = false;


		for (uint i = 0; i < uiLocalNumberOfAddresses; ++ i)
		{
			string sMyLanIp = m_cRnPeer.GetLocalIP(i);


			string sLanIpPrefix = sMyLanIp.Substring(0, sMyLanIp.IndexOf('.'));


			if (sLanIpPrefix == sIpPrefix)
			{
				bIsLanServer = true;
				break;
			}
		}


		if (!bIsLanServer)
		{
			m_aOnlineServers.Add(tLanServerInfo);
		}
		else
		{
			m_aLanServers.Add(tLanServerInfo);
		}


		//Logger.WriteError("Added server ({0}:({1}) lan ({2})", tLanServerInfo.sIp, tLanServerInfo.usPort, bIsLanServer);


		// Notify event observers
		if (EventFoundServer != null)
		{
			EventFoundServer(tLanServerInfo);
		}
	}