コード例 #1
0
        public void fireAndForgetMessage(RCONMessageType type, string command)
        {
            if (!this.isConfigured)
            {
                return;
            }

            this.internalSendMessage(type, command, true);
        }
コード例 #2
0
        public string sendMessage(RCONMessageType type, string command)
        {
            if (!this.isConfigured)
            {
                return(RCONMessageAnswer.EMPTY.Answer);
            }

            return(this.internalSendMessage(type, command).Answer);
        }
コード例 #3
0
        private RCONMessageAnswer internalSendMessage(RCONMessageType type, string command, bool fireAndForget = false)
        {
            try
            {
                var messageNumber = 0;

                try
                {
                    this.threadLock.EnterWriteLock();

                    // Is a reconnection necessary?
                    if (!this.isInit || this.tcp == null || !this.tcp.Connected)
                    {
                        this.internalDispose();
                        this.openConnection();
                    }

                    // Build the message:
                    messageNumber = ++this.messageCounter;
                    var msg = new List <byte>();
                    msg.AddRange(BitConverter.GetBytes(10 + Encoding.UTF8.GetByteCount(command)));
                    msg.AddRange(BitConverter.GetBytes(messageNumber));
                    msg.AddRange(BitConverter.GetBytes(type.Value));
                    msg.AddRange(Encoding.UTF8.GetBytes(command));
                    msg.AddRange(PADDING);

                    // Write the message to the wire:
                    this.writer.Write(msg.ToArray());
                    this.writer.Flush();
                }
                finally
                {
                    this.threadLock.ExitWriteLock();
                }

                if (fireAndForget && rconServerIsMultiThreaded)
                {
                    var id = messageNumber;
                    Task.Factory.StartNew(() =>
                    {
                        waitReadMessage(id);
                    });

                    return(RCONMessageAnswer.EMPTY);
                }

                return(waitReadMessage(messageNumber));
            }
            catch (Exception e)
            {
                //Console.WriteLine("Exception while sending: " + e.Message);
                ErrorMsg = "Exception while sending: " + e.Message;

                return(RCONMessageAnswer.EMPTY);
            }
        }
コード例 #4
0
		private RCONMessageAnswer internalSendMessage(RCONMessageType type, string command, bool fireAndForget = false)
		{
			try
			{
				var messageNumber = 0;

				try
				{
					this.threadLock.EnterWriteLock();

					// Is a reconnection necessary?
					if (!this.isInit || this.tcp == null || !this.tcp.Connected)
					{
						this.internalDispose();
						this.openConnection();
					}

					// Build the message:
					messageNumber = ++this.messageCounter;
					var msg = new List<byte>();
					msg.AddRange(BitConverter.GetBytes(10 + command.Length));
					msg.AddRange(BitConverter.GetBytes(messageNumber));
					msg.AddRange(BitConverter.GetBytes(type.Value));
					msg.AddRange(ASCIIEncoding.UTF8.GetBytes(command));
					msg.AddRange(PADDING);

					// Write the message to the wire:
					this.writer.Write(msg.ToArray());
					this.writer.Flush();
				}
				finally
				{
					this.threadLock.ExitWriteLock();
				}

				if (fireAndForget && rconServerIsMultiThreaded)
				{
					var id = messageNumber;
					Task.Factory.StartNew(() =>
					{
						waitReadMessage(id);
					});

					return RCONMessageAnswer.EMPTY;
				}

				return waitReadMessage(messageNumber);
			}
			catch (Exception e)
			{
				Console.WriteLine("Exception while sending: " + e.Message);
				return RCONMessageAnswer.EMPTY;
			}
		}
コード例 #5
0
		public void fireAndForgetMessage(RCONMessageType type, string command)
		{
			if (!this.isConfigured)
			{
				return;
			}

			this.internalSendMessage(type, command, true);
		}
コード例 #6
0
		public string sendMessage(RCONMessageType type, string command)
		{
			if (!this.isConfigured)
			{
				return RCONMessageAnswer.EMPTY.Answer;
			}

			return this.internalSendMessage(type, command).Answer;
		}