public bool ReceiveMessage(out string receivedMessage, bool decrypted = true, bool isCommand = true) { receivedMessage = ""; byte[] receivedBytes; bool bytes = this.ReceiveBytes(out receivedBytes, decrypted); if (!bytes) { return(false); } try { receivedMessage = Encoding.UTF8.GetString(receivedBytes, 0, receivedBytes.Length); } catch (DecoderFallbackException ex) { if (isCommand) { this.StatusMessage = "Failed to decode server response."; this.m_lastCommandSucceeded = false; this.OnPropertyChanged("Status"); } return(false); } if (isCommand) { this.StatusMessage = receivedMessage; this.m_lastCommandSucceeded = RconStaticLibrary.IsSuccessReply(receivedMessage); this.OnPropertyChanged("Status"); } return(bytes); }
public bool GetData(string getterName, out string[] data) { RconGetter index = this.m_cachedGetterData.Select <KeyValuePair <RconGetter, string[]>, RconGetter>((Func <KeyValuePair <RconGetter, string[]>, RconGetter>)(entry => entry.Key)).Where <RconGetter>((Func <RconGetter, bool>)(key => key.Name.Equals(getterName))).FirstOrDefault <RconGetter>(); if (index == null) { data = new string[0]; return(RconStaticLibrary.FindGetterByName(getterName).GetData(this, out data)); } data = this.m_cachedGetterData[index]; return(true); }
public MainWindow() { this.InitializeComponent(); this.Title = this.Title + " v" + this.VersionString(); RconStaticLibrary.UpdateAvailableCommandsAndGetters(); ConnectDialog connectDialog = new ConnectDialog(new ServerConnectionDetails()); bool? nullable = connectDialog.ShowDialog(); bool flag = false; if ((nullable.GetValueOrDefault() == flag ? (nullable.HasValue ? 1 : 0) : 0) != 0) { this.Close(); } Task.Run((Action)(() => this.StartNewSessionAndCreateUI(connectDialog))); }
public async void UpdateServerInfo() { if (this.Disconnected) { return; } foreach (RconGetter rconGetter in RconStaticLibrary.AvailableGetters.Where <RconGetter>((Func <RconGetter, bool>)(getter => getter.AutoRefresh)).ToList <RconGetter>()) { RconGetter getter = rconGetter; string[] data = new string[1] { "" }; if (!await Task.Run <bool>((Func <bool>)(() => getter.GetData(this, out data)))) { data = new string[1] { "Failed to get data." } } ; else if (RconStaticLibrary.IsFailReply(data[0])) { data = new string[1] { "Getter not supported by the server." } } ; if (this.m_cachedGetterData.ContainsKey(getter)) { this.m_cachedGetterData[getter] = data; } else { this.m_cachedGetterData.Add(getter, data); } } this.OnPropertyChanged("ServerInfo"); }
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(); } }