Esempio n. 1
0
        /// <summary>
        /// Broadcasts a message to all connections except specified; should NOT be used for
        /// messages which uses the string table read/write methods!
        /// </summary>
        public int Broadcast(NetMessage msg, NetChannel channel, NetConnection except)
        {
            int  numSentTo    = 0;
            bool originalSent = false;

            foreach (NetConnection conn in Connections)
            {
                if (conn == null || conn == except || (conn.Status != NetConnectionStatus.Connected && conn.Status != NetConnectionStatus.Reconnecting))
                {
                    continue;
                }

                numSentTo++;

                if (!originalSent)
                {
                    // send original
                    conn.SendMessage(msg, channel);
                    originalSent = true;
                }
                else
                {
                    // send refcloned message
                    NetMessage clone = NetMessage.CreateReferenceClone(msg);
                    conn.SendMessage(clone, channel);
                    numSentTo++;
                }
            }

            return(numSentTo);
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a message to several connections using the channel specified; should NOT be
        /// used for messages which uses the string table read/write methods!
        /// </summary>
        /// <returns>number of messages sent</returns>
        public int SendMessage(NetMessage msg, IEnumerable <NetConnection> connections, NetChannel channel)
        {
            if (connections == null)
            {
                throw new ArgumentNullException("connection");
            }

            int  numSentTo    = 0;
            bool originalSent = false;

            foreach (NetConnection connection in connections)
            {
                if (connection == null || (connection.Status != NetConnectionStatus.Connected && connection.Status != NetConnectionStatus.Reconnecting))
                {
                    continue;
                }

                if (!originalSent)
                {
                    connection.SendMessage(msg, channel);
                    originalSent = true;
                }
                else
                {
                    // send refcloned message
                    NetMessage clone = NetMessage.CreateReferenceClone(msg);
                    connection.SendMessage(clone, channel);
                }
                numSentTo++;
            }

            // Log.Debug("Broadcast to " + numSentTo + " connections...");

            return(numSentTo);
        }