Esempio n. 1
0
        /// <summary>
        /// Sends the specified <see cref="DataMessage"/> to the server.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        protected bool Send(DataMessage message, QosType channel, out NetworkError error)
        {
            //Debug.Log(this.ToString() + " Sending message of type: " + message.type.ToString() + " on channel: " + type.ToString());
            var buffer = message.Serialize();

            return(base.Send(_localConnectionId, buffer, channel, message.GetTotalByteSize(), out error));
        }
        /// <summary>
        /// Sends the given <see cref="DataMessage"/> to all valid connections, except the one provided as exceptNetId.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="exceptNetId">The player whose netId to ignore.</param>
        /// <returns>True when no error</returns>
        public bool SendToAll(DataMessage message, QosType channel, short exceptNetId)
        {
            if (_controller.players.Count == 0)
            {
                return(false);
            }

            var error    = false;
            var buffer   = message.Serialize();
            var byteSize = message.GetTotalByteSize();

            var enumerator = _controller.players.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    var player = enumerator.Current.Value;
                    if (!player.isPlayer)
                    {
                        continue;
                    }

                    var netId = player.netId;
                    if (netId == exceptNetId)
                    {
                        continue;
                    }

                    if (!Send(netId, buffer, channel, byteSize))
                    {
                        error = true;
                    }
                }
            }
            finally
            {
                enumerator.Dispose();
            }

            return(!error);
        }
        /// <summary>
        /// Sends the <see cref="DataMessage"/> to the player with the given net identifier (netId).
        /// </summary>
        /// <param name="netId">The net identifier.</param>
        /// <param name="message">The message.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="error">The error.</param>
        /// <returnsTrue when no error></returns>
        public bool Send(short netId, DataMessage message, QosType channel, out NetworkError error)
        {
            var buffer = message.Serialize();

            return(Send(netId, buffer, channel, message.GetTotalByteSize(), out error));
        }