web proxy changes. redesigned console

This commit is contained in:
Bitl 2023-01-06 15:56:26 -07:00
parent 4c98b40874
commit abeece85dc
6 changed files with 80 additions and 42 deletions

View File

@ -117,6 +117,12 @@ namespace Novetus.Core
public void Start()
{
if (Server.ProxyRunning)
{
Util.ConsolePrint("The web proxy is already on and running.", 2);
return;
}
try
{
LoadExtensions();
@ -268,6 +274,12 @@ namespace Novetus.Core
public void Stop()
{
if (!Server.ProxyRunning)
{
Util.ConsolePrint("The web proxy is already turned off.", 2);
return;
}
Util.ConsolePrint("Web Proxy stopping on port " + GlobalVars.WebProxyPort, 3);
Server.BeforeRequest -= new AsyncEventHandler<SessionEventArgs>(OnRequest);
Server.Stop();

View File

@ -2,7 +2,9 @@
#region Usings
using Mono.Nat;
using System;
using System.Collections.Generic;
using System.Web;
using Titanium.Web.Proxy.Models;
#endregion
namespace Novetus.Core
@ -61,6 +63,21 @@ namespace Novetus.Core
{
return HttpUtility.ParseQueryString(query)[searchQuery];
}
public static IEnumerable<HttpHeader> GenerateHeaders(string content, string contenttype = "")
{
List<HttpHeader> HeaderList = new List<HttpHeader>();
if (!string.IsNullOrWhiteSpace(contenttype))
{
HeaderList.Add(new HttpHeader("Content-Type", contenttype));
}
HeaderList.Add(new HttpHeader("Content-Length", content));
HeaderList.Add(new HttpHeader("Cache-Control", "no-cache"));
return HeaderList;
}
}
#endregion
}

View File

@ -189,7 +189,7 @@ namespace NovetusLauncher
{
DiscordRPC.Shutdown();
}
if (GlobalVars.Proxy.HasStarted())
if (GlobalVars.UserConfiguration.WebProxyEnabled)
{
GlobalVars.Proxy.Stop();
}

View File

@ -30,6 +30,8 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NovetusConsole));
this.ConsoleBox = new System.Windows.Forms.RichTextBox();
this.CommandBox = new System.Windows.Forms.TextBox();
this.EnterButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// ConsoleBox
@ -43,16 +45,43 @@
this.ConsoleBox.ForeColor = System.Drawing.Color.White;
this.ConsoleBox.Location = new System.Drawing.Point(0, 0);
this.ConsoleBox.Name = "ConsoleBox";
this.ConsoleBox.Size = new System.Drawing.Size(857, 411);
this.ConsoleBox.ReadOnly = true;
this.ConsoleBox.Size = new System.Drawing.Size(868, 389);
this.ConsoleBox.TabIndex = 0;
this.ConsoleBox.Text = "";
this.ConsoleBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ProcessConsole);
//
// CommandBox
//
this.CommandBox.BackColor = System.Drawing.SystemColors.WindowText;
this.CommandBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.CommandBox.ForeColor = System.Drawing.Color.White;
this.CommandBox.Location = new System.Drawing.Point(3, 391);
this.CommandBox.Name = "CommandBox";
this.CommandBox.Size = new System.Drawing.Size(783, 20);
this.CommandBox.TabIndex = 1;
//
// EnterButton
//
this.EnterButton.BackColor = System.Drawing.SystemColors.ControlText;
this.EnterButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.EnterButton.ForeColor = System.Drawing.Color.Lime;
this.EnterButton.Location = new System.Drawing.Point(789, 390);
this.EnterButton.Name = "EnterButton";
this.EnterButton.Size = new System.Drawing.Size(75, 21);
this.EnterButton.TabIndex = 2;
this.EnterButton.Text = "Enter";
this.EnterButton.UseVisualStyleBackColor = false;
this.EnterButton.Click += new System.EventHandler(this.EnterButton_Click);
//
// NovetusConsole
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(858, 411);
this.BackColor = System.Drawing.SystemColors.ControlText;
this.ClientSize = new System.Drawing.Size(869, 415);
this.Controls.Add(this.EnterButton);
this.Controls.Add(this.CommandBox);
this.Controls.Add(this.ConsoleBox);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(357, 205);
@ -61,11 +90,14 @@
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ConsoleClose);
this.Load += new System.EventHandler(this.NovetusConsole_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public System.Windows.Forms.RichTextBox ConsoleBox;
private System.Windows.Forms.TextBox CommandBox;
private System.Windows.Forms.Button EnterButton;
}
}

View File

@ -222,6 +222,8 @@ namespace NovetusLauncher
if (disableCommands)
return;
CommandBox.Text = "";
switch (cmd)
{
case string server when server.Contains("server", StringComparison.InvariantCultureIgnoreCase) == true:
@ -365,12 +367,6 @@ namespace NovetusLauncher
if (vals[1].Equals("on", StringComparison.InvariantCultureIgnoreCase))
{
if (GlobalVars.Proxy.HasStarted())
{
Util.ConsolePrint("The web proxy is already on and running.", 2);
return;
}
if (GlobalVars.UserConfiguration.WebProxyInitialSetupRequired)
{
// this is wierd and really dumb if we are just using console mode.....
@ -388,12 +384,6 @@ namespace NovetusLauncher
}
else if (vals[1].Equals("off", StringComparison.InvariantCultureIgnoreCase))
{
if (!GlobalVars.Proxy.HasStarted())
{
Util.ConsolePrint("The web proxy is already turned off.", 2);
return;
}
if (!GlobalVars.UserConfiguration.WebProxyEnabled)
{
Util.ConsolePrint("The web proxy is disabled. Please turn it on in order to use this command.", 2);
@ -415,10 +405,7 @@ namespace NovetusLauncher
GlobalVars.UserConfiguration.WebProxyEnabled = false;
}
if (GlobalVars.Proxy.HasStarted())
{
GlobalVars.Proxy.Stop();
}
GlobalVars.Proxy.Stop();
Util.ConsolePrint("The web proxy has been disabled. To re-enable it, use the 'proxy on' command.", 2);
}
@ -467,32 +454,22 @@ namespace NovetusLauncher
return;
}
//Command proxy
int totalLines = ConsoleBox.Lines.Length;
if (totalLines > 0)
if (e.KeyCode == Keys.Enter)
{
string lastLine = ConsoleBox.Lines[totalLines - 1];
ConsoleProcessCommands(CommandBox.Text);
e.Handled = true;
}
}
if (e.KeyCode == Keys.Enter)
{
ConsoleProcessCommands(lastLine);
e.Handled = true;
}
private void EnterButton_Click(object sender, EventArgs e)
{
if (helpMode)
{
ConsoleForm.CloseEventInternal();
return;
}
if (e.Modifiers == Keys.Control)
{
switch (e.KeyCode)
{
case Keys.X:
case Keys.Z:
e.Handled = true;
break;
default:
break;
}
}
ConsoleProcessCommands(CommandBox.Text);
}
private void ClearConsole()

View File

@ -109,7 +109,7 @@ namespace NovetusURI
GlobalVars.GameOpened = ScriptType.None;
}
if (GlobalVars.Proxy.HasStarted())
if (GlobalVars.UserConfiguration.WebProxyEnabled)
{
GlobalVars.Proxy.Stop();
}