예제 #1
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);
                }
            }
        }
    }
예제 #2
0
 public void Write(CNetworkStream _cStream)
 {
     _cStream.SetReadOffset(0);
     m_cBitStream.Write(_cStream.BitStream);
     _cStream.SetReadOffset(0);
 }
예제 #3
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); 		
				}
			}
		}
	}
예제 #4
0
    public void SyncNetworkVar(ulong _ulPlayerId, byte _bNetworkVarId)
    {
        // Ensure only servers can sync network vars
        Logger.WriteErrorOn(!CNetwork.IsServer, "Clients cannot sync network vars fool!");

        // Instance new packet stream
        CNetworkStream cVarStream = new CNetworkStream();

        // View id
        cVarStream.Write(this.ViewId);

        // Prodecure type
        cVarStream.Write((byte)EProdecure.SyncNetworkVar);

        // Network var identifier
        cVarStream.Write(_bNetworkVarId);

        // Network var value
        cVarStream.Write(m_mNetworkVars[_bNetworkVarId].GetValueObject(), m_mNetworkVars[_bNetworkVarId].GetValueType());

        // Send to all players
        if (_ulPlayerId == 0)
        {
			// Process on server straight away
			CNetworkView.ProcessInboundStream(0, cVarStream);
			cVarStream.SetReadOffset(0);

			// Append network var sync stream to connected non-host players
            foreach (KeyValuePair<ulong, CNetworkPlayer> tEntry in CNetwork.Server.FindNetworkPlayers())
            {
                // Make host execute sync straight away
                if (!tEntry.Value.IsHost)
                {
                    // Append packet data
                    tEntry.Value.NetworkViewStream.Write(cVarStream);
                }
            }

			// Notice
            //Logger.Write("Sent network var sync (id {0}) to all players", _bNetworkVarId);
        }

        // Send to individual player
        else
        {
            // Retieve player instance
            CNetworkPlayer cNetworkPlayer = CNetwork.Server.FindNetworkPlayer(_ulPlayerId);

            // Make host execute sync straight away
            if (cNetworkPlayer.IsHost)
            {
                CNetworkView.ProcessInboundStream(0, cVarStream);
                cVarStream.SetReadOffset(0);
            }
            else
            {
                // Append packet data
                cNetworkPlayer.NetworkViewStream.Write(cVarStream);
            }

			// Notice
            //Logger.Write("Sent network var sync id ({0}) to player id ({1})", _bNetworkVarId, _ulPlayerId);
        }
    }
예제 #5
0
    public void InvokeRpc(ulong _ulPlayerId, Component _cComponent, string _sFunction, params object[] _caParameterValues)
	{
        // Ensure sure only servers can invoke rpcs
        Logger.WriteErrorOn(!CNetwork.IsServer, "Only servers can invoke RPCs douche");

        // Extract method from component using its name
        MethodInfo tMethodInfo = _cComponent.GetType().GetMethod(_sFunction, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

        // Ensure the method exists
        Logger.WriteErrorOn(tMethodInfo == null, "Could not find method ({0}) in component ({1})", _sFunction, _cComponent.GetType().Name);
 
        // Find network rpc index using the method info
        byte bNetworkRpcId = FindNetworkRpcIndexUsingMethodInfo(tMethodInfo);

        // Ensure the network rpc was found
        Logger.WriteErrorOn(bNetworkRpcId == 0, "The network rpc method ({0}) in component ({1}) is not connected to this network view id ({2})", _sFunction, _cComponent.GetType().Name, this.ViewId);

        // Instance new packet stream
        CNetworkStream cRpcStream = new CNetworkStream();

        // View id
        cRpcStream.Write(this.ViewId);

        // Prodecure type
        cRpcStream.Write((byte)EProdecure.InvokeNetworkRpc);

        // Rpc identifier
        cRpcStream.Write(bNetworkRpcId);

        // Method parameter values
        cRpcStream.Write(tMethodInfo, _caParameterValues);

        // Send to all players
        if (_ulPlayerId == 0)
        {
			// Process on server straight away
			CNetworkView.ProcessInboundStream(0, cRpcStream);
			cRpcStream.SetReadOffset(0);

			// Append rpc stream to connected non-host players
            foreach (KeyValuePair<ulong, CNetworkPlayer> tEntry in CNetwork.Server.FindNetworkPlayers())
            {
                // Make host execute RPC straight away
                if (!tEntry.Value.IsHost)
                {
                    // Append packet data
                    tEntry.Value.NetworkViewStream.Write(cRpcStream);	

                    //Logger.WriteError("Written {0} bytes into player ({1})", cRpcStream.Size, tEntry.Value.PlayerId);
                }
            }

			// Notice
            Logger.Write("Sent RPC call for ({0}) to all players", _sFunction);
        }

        // Send to individual player
        else
        {
            // Retrieve player instance
            CNetworkPlayer cNetworkPlayer = CNetwork.Server.FindNetworkPlayer(_ulPlayerId);

            // Make host execute RPC straight away
            if (cNetworkPlayer.IsHost)
            {
                CNetworkView.ProcessInboundStream(0, cRpcStream);
                cRpcStream.SetReadOffset(0);
            }
            else
            {
                // Append packet data
                cNetworkPlayer.NetworkViewStream.Write(cRpcStream);
            }

            Logger.Write("Sent RPC call for ({0}) to player id ({1})", _sFunction, _ulPlayerId);
        }
	}
예제 #6
0
	public void TransmitMicrophoneAudio(ulong _ulPlayerId, CNetworkStream _cAudioDataStream)
	{
		m_cRnPeer.Send(_cAudioDataStream.BitStream, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.UNRELIABLE_SEQUENCED, (char)1, FindNetworkPlayer(_ulPlayerId).SystemAddress, false);
		_cAudioDataStream.SetReadOffset(0);			
	}
예제 #7
0
 public void TransmitMicrophoneAudio(ulong _ulPlayerId, CNetworkStream _cAudioDataStream)
 {
     m_cRnPeer.Send(_cAudioDataStream.BitStream, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.UNRELIABLE_SEQUENCED, (char)1, FindNetworkPlayer(_ulPlayerId).SystemAddress, false);
     _cAudioDataStream.SetReadOffset(0);
 }