예제 #1
0
        public void StartExecuting(ServerSession serverSession)
        {
            List <string> stringList = new List <string>();

            if (this.m_parameters.Count > 0)
            {
                ParameterDialog parameterDialog = new ParameterDialog(this.m_parameters, serverSession);
                bool?           nullable        = parameterDialog.ShowDialog();
                bool            flag            = false;
                if ((nullable.GetValueOrDefault() == flag ? (nullable.HasValue ? 1 : 0) : 0) != 0)
                {
                    return;
                }
                foreach (RconCommandParameter parameter in this.m_parameters)
                {
                    string s = parameterDialog.ParameterToUserInput[parameter].Text;
                    if (parameter.Quoted)
                    {
                        s = RconCommand.QuoteString(s);
                    }
                    stringList.Add(s);
                }
            }
            if (!serverSession.SendMessage(string.Format(this.m_messageTemplate, (object[])stringList.ToArray()), true))
            {
                return;
            }
            string receivedMessage = "";

            serverSession.ReceiveMessage(out receivedMessage, true, true);
        }
예제 #2
0
 protected void OnConnected(Task connectionTask)
 {
     try
     {
         try
         {
             connectionTask.Wait();
         }
         catch (AggregateException ex)
         {
             ex.Handle((Func <Exception, bool>)(x =>
             {
                 throw x;
             }));
         }
     }
     catch (ArgumentNullException ex)
     {
         this.OnConnectionProblems("Provided hostname is null.");
         return;
     }
     catch (ArgumentOutOfRangeException ex)
     {
         this.OnConnectionProblems("Invalid portnumber provided.");
         return;
     }
     catch (SocketException ex)
     {
         this.OnConnectionProblems("The provided address and port are inaccessible.");
         return;
     }
     try
     {
         this.m_communicationMutex.WaitOne();
         if (!this.ReceiveBytes(out this.m_xorKey, false))
         {
             this.StatusMessage = "No response from the server. Are the address and port correct?";
         }
         else
         {
             this.SendMessage(string.Format(ServerSession.s_rconLoginCommand, (object)RconCommand.QuoteString(this.ConnectionDetails.ServerPassword)), true);
             string receivedMessage;
             this.m_lastCommandSucceeded = this.ReceiveMessage(out receivedMessage, true, true) && RconStaticLibrary.IsSuccessReply(receivedMessage);
             this.Authenticated          = this.m_lastCommandSucceeded;
             this.OnPropertyChanged("Disconnected");
             this.OnPropertyChanged("Status");
             if (this.Authenticated)
             {
                 this.StatusMessage = "Login successful.";
                 this.UpdateServerInfo();
             }
             else
             {
                 this.StatusMessage = "Login failed. Is your password correct?";
             }
         }
     }
     catch (ObjectDisposedException ex)
     {
         this.OnConnectionProblems("Internal error: mutex has been disposed.");
     }
     catch (AbandonedMutexException ex)
     {
         this.OnConnectionProblems("Internal error: mutex has been abandoned.");
     }
     catch (InvalidOperationException ex)
     {
         this.OnConnectionProblems("Internal error: invalid mutex operation.");
     }
     catch (ArgumentNullException ex)
     {
         this.OnConnectionProblems("Empty login string provided.");
         this.m_communicationMutex.ReleaseMutex();
     }
     catch (FormatException ex)
     {
         this.OnConnectionProblems("Invalid login string provided.");
         this.m_communicationMutex.ReleaseMutex();
     }
 }