Пример #1
0
 /// <summary>
 /// Disconnects the given connection id.
 /// </summary>
 /// <param name="id">Id to disconnect</param>
 public void Disconnect(ConnectionId id)
 {
     UnityWebRtcNetworkDisconnect(mReference, id.id);
 }
Пример #2
0
 /// <summary>
 /// Sends a byte array
 /// </summary>
 /// <param name="conId">Connection id the message should be delivered to.</param>
 /// <param name="data">Content/Buffer that contains the content</param>
 /// <param name="offset">Start index of the content in data</param>
 /// <param name="length">Length of the content in data</param>
 /// <param name="reliable">True to use the ordered, reliable trainfer, false for unordered and unreliable</param>
 public void SendData(ConnectionId conId, byte[] data, int offset, int length, bool reliable)
 {
     UnityWebRtcNetworkSendData(mReference, conId.id, data, offset, length, reliable);
 }
Пример #3
0
 /// <summary>
 /// Creates a network event with the given content
 /// 
 /// Internal only. Do not use.
 /// </summary>
 /// <param name="t">Typename</param>
 /// <param name="conId">ConnectionId the event is from / relates to</param>
 /// <param name="dt">Data. String or MessageDataBuffer</param>
 internal NetworkEvent(NetEventType t, ConnectionId conId, object dt)
 {
     type = t;
     connectionId = conId;
     data = dt;
 }
Пример #4
0
        /// <summary>
        /// Connects to the given name or address.
        /// </summary>
        /// <param name="name"> The address identifying the server  </param>
        /// <returns>
        /// The connection id. (WebRTCNetwork doesn't allow multiple connections yet! So you can ignore this for now)
        /// </returns>
        public ConnectionId Connect(string name)
        {
            //until fully supported -> block connecting to others while running a server
            if (this.mIsServer == true)
            {
                UnityEngine.Debug.LogError("Can't create outgoing connections while in server mode!");
                return ConnectionId.INVALID;
            }

            ConnectionId id = new ConnectionId();
            id.id = (short)UnityWebRtcNetworkConnect(mReference, name);
            return id;
        }
Пример #5
0
 /// <summary>
 /// Creates a new network event of a certain type setting 
 /// connection id to invalid and data to null.
 /// 
 /// Internal only. Do not use.
 /// </summary>
 /// <param name="t">The type of this event</param>
 internal NetworkEvent(NetEventType t)
 {
     type = t;
     connectionId = ConnectionId.INVALID;
     data = null;
 }
Пример #6
0
 internal NetworkEvent(NetEventType t, ConnectionId conId, object dt)
 {
     type         = t;
     connectionId = conId;
     data         = dt;
 }
Пример #7
0
 internal NetworkEvent(NetEventType t)
 {
     type         = t;
     connectionId = ConnectionId.INVALID;
     data         = null;
 }
Пример #8
0
 public void Disconnect(ConnectionId id)
 {
     SingleEndpointConnection esc = null;
     mKnownPlayers.TryGetValue(id, out esc);
     if (esc != null)
     {
         Network.CloseConnection(esc.ConnectedUser, true);
     }
 }
Пример #9
0
        public void SendData(ConnectionId userId, byte[] data, int offset, int length, bool reliable)
        {
            //if(Network.isServer && method == DeliveryMode.Unreliable && userId != UserIdAll)
            //{
            //    throw new InvalidOperationException("Unity only allows to send to all clients at once from server.");
            //}
            //if(Network.isClient && method == DeliveryMode.Unreliable && (_KnownPlayers.ContainsKey(userId) == false ||_KnownPlayers[userId].player != Network.connections[0]))
            //{
            //    throw new InvalidOperationException("Can only send to server");
            //}



            if (reliable)
            {
                NetworkPlayer pl = this.mKnownPlayers[userId].ConnectedUser;
                NetworkView nv = GetComponent<NetworkView>();
                

                nv.RPC("DeliverMessage", pl, data);
            }
            else
            {
                Queue<ByteArrayBuffer> userOut;
                bool found = mOutgoingUnreliableMessages.TryGetValue(userId, out userOut);
                if(found == false)
                {
                    userOut = new Queue<ByteArrayBuffer>();
                    mOutgoingUnreliableMessages.Add(userId, userOut);
                }
                ByteArrayBuffer msg = ByteArrayBuffer.Get(length);
                msg.CopyFrom(data, offset, length);
                userOut.Enqueue(msg);
            }
        }