Ejemplo n.º 1
0
        /// <summary>
        ///     Sends network message from client to server.
        ///     Note that only owner of this entity can send messages.
        /// </summary>
        /// <param name="index">Index of message.</param>
        public QNetEntityOutgoingMessage SendNetworkClientMessage(byte index)
        {
            if (!QNetManager.IsClientActive)
            {
                throw new InvalidOperationException("QNetEntity network client message can only be send from client.");
            }

            var outgoingMessage = new QNetEntityOutgoingMessage(this, false, default(QNetConnection));

            outgoingMessage.Writer.WriteByte(index);
            return(outgoingMessage);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Sends network message from server to all clients.
        /// </summary>
        /// <param name="index">Index of message.</param>
        public QNetEntityOutgoingMessage SendNetworkServerMessage(byte index)
        {
            if (!QNetManager.IsServerActive)
            {
                throw new InvalidOperationException("QNetEntity network server message can only be send from server.");
            }

            var outgoingMessage = new QNetEntityOutgoingMessage(this, true, default(QNetConnection));

            if (IsServer)
            {
                // write server frame
                outgoingMessage.Writer.WriteUInt32(QNetTime.ServerFrame);
            }

            outgoingMessage.Writer.WriteByte(index);
            return(outgoingMessage);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Sends network message from server to given connection.
        /// </summary>
        /// <param name="targetConnection">Target connection of message.</param>
        /// <param name="index">Index of message.</param>
        public QNetEntityOutgoingMessage SendNetworkServerDedicatedMessage(QNetConnection targetConnection, byte index)
        {
            if (!QNetManager.IsServerActive)
            {
                throw new InvalidOperationException("QNetEntity network server message can only be send from server.");
            }
            if (targetConnection.Equals(default(QNetConnection)))
            {
                throw new InvalidOperationException("Default target connection received in server dedicated message.");
            }

            var outgoingMessage = new QNetEntityOutgoingMessage(this, true, targetConnection);

            if (IsServer)
            {
                // write server frame
                outgoingMessage.Writer.WriteUInt32(QNetTime.ServerFrame);
            }

            outgoingMessage.Writer.WriteByte(index);
            return(outgoingMessage);
        }