//RTFScrolledBottom newConsole = new RTFScrolledBottom(); private void Form1_Load(object sender, EventArgs e) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit); AutoCompleteStringCollection sc = new AutoCompleteStringCollection(); string[] cmds = JsonConvert.DeserializeObject <string[]>(Properties.Settings.Default.AutocompleteList); sc.AddRange(cmds); tbInput.AutoCompleteCustomSource = sc; lastCommands = JsonConvert.DeserializeObject <List <string> >(Properties.Settings.Default.LastCommands); if (lastCommands == null) { lastCommands = new List <string>(); } //Console.WriteLine(opacity); this.Opacity = opacity; console = tbConsole; OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; switch (pid) { case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: OS = RunningOS.Windows; break; case PlatformID.Unix: OS = RunningOS.Unix; break; default: OS = RunningOS.Invalid; break; } this.ActiveControl = tbInput; toolStripMenuItemSettings.MouseEnter += new EventHandler(Menu_MouseEnter); toolStripMenuItemSettings.MouseLeave += new EventHandler(Menu_MouseLeave); ToolStripControlHost tsHost = new ToolStripControlHost(keepAliveItem); toolStripMenuItemSettings.DropDownItems.Insert(toolStripMenuItemSettings.DropDownItems.Count - 1, tsHost); //toolStripMenuItemSettings.DropDownItems.Insert(toolStripMenuItemSettings.DropDownItems.Count - 1, new ToolStripSeparator()); toolStripMenuItemSettings.DropDown.AutoSize = true; int fullheight = 0; foreach (var item in toolStripMenuItemSettings.DropDownItems) { ToolStripDropDownItem x = item as ToolStripDropDownItem; if (x != null) { fullheight += x.Height; } } fullheight += keepAliveItem.Height; toolStripMenuItemSettings.DropDown.MinimumSize = new Size(toolStripMenuItemSettings.DropDown.Width, toolStripMenuItemSettings.Height + fullheight); toolStripMenuItemSettings.DropDown.Size = new Size(toolStripMenuItemSettings.DropDown.Width, toolStripMenuItemSettings.Height + fullheight); //toolStripMenuItemSettings.DropDown.Closing += DropDown_Closing; keepAliveToolStripMenuItem.Checked = Properties.Settings.Default.KeepAlive; hideAliveCMDOutputToolStripMenuItem.Checked = Properties.Settings.Default.SuppressAlive; numUpDownAlive.Value = Properties.Settings.Default.AliveFreqSec; timerAlive.Interval = Properties.Settings.Default.AliveFreqSec * 1000; numUpDownAlive.LostFocus += NumUpDownAlive_LostFocus; lastServer = JsonConvert.DeserializeObject <ServerEntry>(Properties.Settings.Default.LastServer); // Decrypt for use in app - only crypt when saving in props lastServer.Password = lastServer.Password; servers = new List <ServerEntry>(); servers = JsonConvert.DeserializeObject <List <ServerEntry> >(Properties.Settings.Default.Servers); if (lastServer.ServerName == "LastServerEntry") { StatusLabel.Text = "Server: Unsaved Server"; } else { StatusLabel.Text = "Server: " + lastServer.ServerName; } //Console.WriteLine(JsonConvert.DeserializeObject(Properties.Settings.Default.LastServer)); if (lastServer != null && lastServer.ServerName == "LastServerEntry" && lastServer.IP == "INVALID") { IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); foreach (IPAddress addr in localIPs) { if (addr.AddressFamily == AddressFamily.InterNetwork) { if (addr.ToString().StartsWith("192.")) { lastServer.IP = addr.ToString(); break; } } } } //StatusLabel.Text = lastServer.ServerName; tbIP.Text = lastServer.IP; tbPort.Value = lastServer.Port; //tbPw.Text = XCRYPT.DecryptString(lastServer.Password); tbPw.Text = lastServer.Password; this.ActiveControl = btnConnect; btnConnect.Focus(); this.Show(); missedVersions = getMissedVersions(); if (missedVersions != null && missedVersions.Count > 0) { using (var updateForm = new Update(this)) { updateForm.ShowDialog(); updateAvailableToolStripMenuItem.Visible = true; checkUpdateTimer.Start(); } } fullyLoaded = true; }
private void btnAdd_Click(object sender, EventArgs e) { if (ServerList == null) { ServerList = new List <ServerEntry>(); } // Name filled check if (string.IsNullOrEmpty(tbServername.Text)) { MessageBox.Show("Please enter a Servername!"); return; } // Name exists check if (ServerList.Count > 0) { if (ServerList.Any(item => item.ServerName == tbServername.Text)) { MessageBox.Show("Server with this name does already exists!"); return; } } // IP "convert" if (tbIP.Text.ToLower() == "localhost" || tbIP.Text.ToLower() == "127.0.0.1") { IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); foreach (IPAddress addr in localIPs) { if (addr.AddressFamily == AddressFamily.InterNetwork) { if (addr.ToString().StartsWith("192.")) { tbIP.Text = addr.ToString(); break; } } } } // IP check if (string.IsNullOrEmpty(tbIP.Text)) { MessageBox.Show("Please enter an IP-Adress!"); return; } Match match = Regex.Match(tbIP.Text, @"((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))"); if (tbIP.Text.StartsWith("0.") || !match.Success) { MessageBox.Show("Invalid IP"); return; } // Password Empty check and confirmation if (string.IsNullOrEmpty(tbPassword.Text)) { var result = MessageBox.Show("Save this Server without Password?", "Info - Empty Password", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { tbPassword.Focus(); this.ActiveControl = tbPassword; return; } } newServerEntryData = new ServerEntry(tbServername.Text, tbIP.Text, (int)tbPort.Value, tbPassword.Text); this.DialogResult = DialogResult.OK; // Update Lastserver & Label if needed // check if same as in form to update statuslabel when server is same as in mainform inputs & set the last server to the new one after successful add if (tbIP.Text == mainForm.tbIP.Text && tbPort.Value == mainForm.tbPort.Value && tbPassword.Text == mainForm.tbPw.Text && mainForm.lastServer.ServerName == "LastServerEntry") { // change last server to just saved one mainForm.lastServer = new ServerEntry(tbServername.Text, tbIP.Text, Convert.ToInt32(tbPort.Value), tbPassword.Text); // Handle update label mainForm.DataChanged(null, null); // save new as last server Properties.Settings.Default.LastServer = JsonConvert.SerializeObject(mainForm.lastServer); Properties.Settings.Default.Save(); } else { } ////////////////////////////////////// this.Close(); }
private void Sr_ConnectionSuccess(bool info) { if (info) { console.BeginInvoke((MethodInvoker) delegate() { tbIP.Enabled = false; tbPort.Enabled = false; tbPw.Enabled = false; //btnConnect.Enabled = false; btnConnect.Text = "Disconnect"; btnConnect.Enabled = true; tbInput.Enabled = true; btnSend.Enabled = true; //tbIP.BackColor = Color.Orange; //tbPort.BackColor = Color.Orange; //tbPw.BackColor = Color.Orange; //btnConnect.BackColor = Color.Orange; //tbInput.BackColor = Color.DarkGray; //btnSend.BackColor = Color.Gray; tbConsole.AppendText(SourceRcon.ConnectionSuccessString + Environment.NewLine, colorConSuc); tbInput.Focus(); this.ActiveControl = tbInput; StatusDot.ForeColor = Color.Green; //StatusDot.Invalidate(); if (lastServer.IP == tbIP.Text && lastServer.Port == Convert.ToInt32(tbPort.Value) && lastServer.Password == tbPw.Text) // it's last server { if (lastServer.ServerName != "LastServerEntry") { StatusLabel.Text = "Connected to " + lastServer.ServerName; ServerEntry tmpServerEntry = new ServerEntry(lastServer.ServerName, tbIP.Text, Convert.ToInt32(tbPort.Value), tbPw.Text); Properties.Settings.Default.LastServer = JsonConvert.SerializeObject(tmpServerEntry); } else { //Console.WriteLine("ELSE"); } } else // not last server { // Connected successfully to a server. Save it as lastserver "without name" StatusLabel.Text = $"Connected to {tbIP.Text}:{Convert.ToInt32(tbPort.Value)}"; ServerEntry tmpServerEntry = new ServerEntry("LastServerEntry", tbIP.Text, Convert.ToInt32(tbPort.Value), tbPw.Text); Properties.Settings.Default.LastServer = JsonConvert.SerializeObject(tmpServerEntry); } Properties.Settings.Default.Save(); }); Sr.ServerCommand("alive"); // initial alive if (Sr != null && Sr.Connected && Properties.Settings.Default.KeepAlive) { timerAlive.Start(); } } else { console.BeginInvoke((MethodInvoker) delegate() { btnConnect.Enabled = true; }); } }