functional scripts!!!

This commit is contained in:
Bitl 2023-01-05 11:02:55 -07:00
parent f46b7d9a9c
commit 39f99b1470
2 changed files with 27 additions and 22 deletions

View File

@ -81,7 +81,7 @@ error:
foreach (CompilerError error in result.Errors)
{
ErrorHandler(error, filePath, error.IsWarning, false);
ErrorHandler(error, filePath, error.IsWarning);
}
if (result.Errors.HasErrors)
@ -92,17 +92,17 @@ error:
return result.CompiledAssembly;
}
public static void ErrorHandler(string error, bool finalError = false)
public static void ErrorHandler(string error)
{
ErrorHandler(error, false, finalError);
ErrorHandler(error, false);
}
private static void ErrorHandler(string error, bool warning, bool finalError)
private static void ErrorHandler(string error, bool warning)
{
Util.ConsolePrint(warning ? "[SCRIPT WARNING] - " : "[SCRIPT ERROR] - " + error, warning ? 5 : 2);
}
private static void ErrorHandler(CompilerError error, string fileName, bool warning, bool finalError)
private static void ErrorHandler(CompilerError error, string fileName, bool warning)
{
Util.ConsolePrint(warning ? "[SCRIPT WARNING] - " : "[SCRIPT ERROR] - " + fileName + " (" + error.Line + "," + error.Column + "): " + error.ErrorText, warning ? 5 : 2);
}

View File

@ -16,7 +16,7 @@ namespace Novetus.Core
{
public class IWebProxyExtension
{
public virtual string Name { get; set; } = "Unnamed Web Proxy Extension";
public virtual string Name() { return "Unnamed Web Proxy Extension"; }
public virtual void OnExtensionLoad() { }
public virtual void OnProxyStart() { }
public virtual void OnProxyStopped() { }
@ -24,9 +24,7 @@ namespace Novetus.Core
public virtual bool IsValidURL(string absolutePath, string host) { return false; }
public virtual Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) { return Task.CompletedTask; }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public virtual async Task OnRequest(object sender, SessionEventArgs e) { }
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
public virtual Task OnRequest(object sender, SessionEventArgs e) { return Task.CompletedTask; }
}
public class WebProxy
@ -60,12 +58,12 @@ namespace Novetus.Core
{
IWebProxyExtension newExt = (IWebProxyExtension)Script.LoadScriptFromContent(file);
ExtensionList.Add(newExt);
Util.ConsolePrint("Web Proxy: Loaded extension " + newExt.Name + " from " + Path.GetFileName(file), 3);
Util.ConsolePrint("Web Proxy: Loaded extension " + newExt.Name() + " from " + Path.GetFileName(file), 3);
newExt.OnExtensionLoad();
}
catch (Exception e)
catch (Exception)
{
Util.LogExceptions(e);
Util.ConsolePrint("Web Proxy: Failed to load script " + Path.GetFileName(file), 2);
}
}
}
@ -121,9 +119,16 @@ namespace Novetus.Core
Server.BeforeRequest += new AsyncEventHandler<SessionEventArgs>(OnRequest);
UpdateEndPoint(true);
Util.ConsolePrint("Web Proxy started on port " + GlobalVars.WebProxyPort, 3);
foreach (IWebProxyExtension extension in ExtensionList.ToArray())
try
{
extension.OnProxyStart();
foreach (IWebProxyExtension extension in ExtensionList.ToArray())
{
extension.OnProxyStart();
}
}
catch (Exception ex)
{
Script.ErrorHandler(ex.Message);
}
}
catch (Exception e)
@ -193,7 +198,7 @@ namespace Novetus.Core
return (ua.Contains("mozilla/4.0") || ua.Contains("roblox"));
}
private Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
{
if (!IsValidURL(e.HttpClient))
{
@ -208,11 +213,11 @@ namespace Novetus.Core
{
try
{
extension.OnBeforeTunnelConnectRequest(sender, e);
await extension.OnBeforeTunnelConnectRequest(sender, e);
}
catch (Exception ex)
{
Util.LogExceptions(ex);
Script.ErrorHandler(ex.Message);
}
}
else
@ -220,8 +225,6 @@ namespace Novetus.Core
e.DecryptSsl = false;
}
}
return Task.CompletedTask;
}
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
@ -246,7 +249,7 @@ namespace Novetus.Core
}
catch (Exception ex)
{
Util.LogExceptions(ex);
Script.ErrorHandler(ex.Message);
e.GenericResponse("", HttpStatusCode.InternalServerError);
return;
}
@ -268,11 +271,13 @@ namespace Novetus.Core
{
extension.OnProxyStopped();
}
catch (Exception e)
catch (Exception ex)
{
Util.LogExceptions(e);
Script.ErrorHandler(ex.Message);
}
}
ExtensionList.Clear();
}
}
}