Compare commits

..

No commits in common. "master" and "v1.0.0" have entirely different histories.

9 changed files with 17 additions and 198 deletions

View file

@ -10,10 +10,7 @@ on:
branches: [ "master" ]
jobs:
publish-aot:
strategy:
matrix:
runtime-id: [win-x64]
build:
runs-on: windows-latest
@ -25,16 +22,13 @@ jobs:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release
- name: Test
run: dotnet test --verbosity normal
- name: Publish
run: dotnet publish FireflySR.Tool.Proxy.csproj -c Release -r ${{ matrix.runtime-id }}
- name: Remove .pdb debug symbols
run: |
rm bin/Release/net8.0/${{ matrix.runtime-id }}/publish/*.pdb
rm bin/Release/net8.0/${{ matrix.runtime-id }}/publish/**/*.pdb
run: dotnet test --no-build --verbosity normal
- name: Upload
uses: actions/upload-artifact@v4
with:
name: FireflySR.Tool.Proxy_${{ matrix.runtime-id }}
path: bin/Release/net8.0/${{ matrix.runtime-id }}/publish
name: FireflySR.Tool.Proxy
path: bin/Release/net7.0
retention-days: 7

View file

@ -1,26 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<RollForward>Major</RollForward>
<LangVersion>Latest</LangVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<Version>2.0.0</Version>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Guardian\**" />
<EmbeddedResource Remove="Guardian\**" />
<None Remove="Guardian\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Unobtanium.Web.Proxy" Version="0.1.1" />
<PackageReference Include="Titanium.Web.Proxy" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
@ -29,9 +19,4 @@
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="$(Os) == 'Windows_NT'">
<Exec Condition="$(RuntimeIdentifier) == ''" Command="echo ProjectDir: $(ProjectDir)&#xD;&#xA;echo Configuration: $(Configuration)&#xD;&#xA;echo OutDir: $(OutDir)&#xD;&#xA;echo Os: $(Os)&#xD;&#xA;echo RuntimeIdentifier: (unused)&#xD;&#xA;dotnet build $(ProjectDir)\Guardian --configuration $(Configuration) --output $(OutDir)\tool" />
<Exec Condition="$(RuntimeIdentifier) != ''" Command="echo ProjectDir: $(ProjectDir)&#xD;&#xA;echo Configuration: $(Configuration)&#xD;&#xA;echo OutDir: $(OutDir)&#xD;&#xA;echo Os: $(Os)&#xD;&#xA;echo RuntimeIdentifier: $(RuntimeIdentifier)&#xD;&#xA;dotnet publish $(ProjectDir)\Guardian --configuration $(Configuration) --output $(OutDir)\publish\tool" />
</Target>
</Project>

View file

@ -5,8 +5,6 @@ VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FireflySR.Tool.Proxy", "FireflySR.Tool.Proxy.csproj", "{C9867CEA-1659-4AC3-8590-7FD72A8867D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Guardian", "Guardian\Guardian.csproj", "{E5E60B4C-AC20-40B9-8C9C-34FE4E1141C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -17,10 +15,6 @@ Global
{C9867CEA-1659-4AC3-8590-7FD72A8867D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9867CEA-1659-4AC3-8590-7FD72A8867D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9867CEA-1659-4AC3-8590-7FD72A8867D6}.Release|Any CPU.Build.0 = Release|Any CPU
{E5E60B4C-AC20-40B9-8C9C-34FE4E1141C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5E60B4C-AC20-40B9-8C9C-34FE4E1141C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5E60B4C-AC20-40B9-8C9C-34FE4E1141C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5E60B4C-AC20-40B9-8C9C-34FE4E1141C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<RootNamespace>FireflySR.Tool.Proxy.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<AssemblyName>FireflySR.Tool.Proxy.$(MSBuildProjectName)</AssemblyName>
</PropertyGroup>
</Project>

View file

@ -1,54 +0,0 @@
using Microsoft.Win32;
using System.Diagnostics;
namespace FireflySR.Tool.Proxy.Guardian;
internal class Program
{
static async Task Main(string[] args)
{
if (args.Length != 1 || !int.TryParse(args[0], out var watchPid))
{
Console.WriteLine("Usage: FireflySR.Tool.Proxy.Guardian [watch-pid]");
Environment.Exit(1);
return;
}
Console.WriteLine("FireflySR.Tool.Proxy.Guardian start.");
Process proc;
try
{
proc = Process.GetProcessById(watchPid);
Console.WriteLine($"Guardian find process {proc.ProcessName}:{watchPid}.");
}
catch
{
DisableSystemProxy();
Environment.Exit(2);
return;
}
while (!proc.HasExited)
{
await Task.Delay(1000);
}
DisableSystemProxy();
}
private static void DisableSystemProxy()
{
try
{
using RegistryKey? key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
key?.SetValue("ProxyEnable", 0);
Console.WriteLine($"Guardian successfully disabled System Proxy.");
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine();
Console.WriteLine($"Guardian failed to disable System Proxy.");
}
}
}

View file

@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Net;
using System.Net;
using System.Text.Json;
namespace FireflySR.Tool.Proxy
@ -9,69 +8,24 @@ namespace FireflySR.Tool.Proxy
private const string Title = "FreeSR Proxy (Alter)";
private const string ConfigPath = "config.json";
private const string ConfigTemplatePath = "config.tmpl.json";
private const string GuardianPath = "tool/FireflySR.Tool.Proxy.Guardian.exe";
private static ProxyService s_proxyService = null!;
private static bool s_clearupd = false;
private static void Main(string[] args)
{
Console.Title = Title;
Console.WriteLine($"Firefly.Tool.Proxy - Credits for original FreeSR Proxy");
_ = Task.Run(WatchGuardianAsync);
CheckProxy();
InitConfig();
var conf = JsonSerializer.Deserialize(File.ReadAllText(ConfigPath), ProxyConfigContext.Default.ProxyConfig) ?? throw new FileLoadException("Please correctly configure config.json.");
var conf = JsonSerializer.Deserialize<ProxyConfig>(File.ReadAllText(ConfigPath)) ?? throw new FileLoadException("Please correctly configure config.json.");
s_proxyService = new ProxyService(conf.DestinationHost, conf.DestinationPort, conf);
Console.WriteLine($"Proxy now running");
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
Console.CancelKeyPress += OnProcessExit;
Thread.Sleep(-1);
}
private static async Task WatchGuardianAsync()
{
var proc = StartGuardian();
if (proc == null)
{
Console.WriteLine("Guardian start failed. Your proxy settings may not be able to recover after closing.");
return;
}
// Notice that on some PTY, closing it may lead
// to Guardian be killed, not the Proxy itself.
// Therefore, Proxy should also watch Guardian
// and exit when Guardian dies.
while (!proc.HasExited)
{
await Task.Delay(1000);
}
Console.WriteLine("! Guardian exit");
OnProcessExit(null, null);
Environment.Exit(0);
}
private static Process? StartGuardian()
{
if (!OperatingSystem.IsWindows()) return null;
try
{
return Process.Start(new ProcessStartInfo(GuardianPath, $"{Environment.ProcessId}")
{
UseShellExecute = false,
});
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine();
return null;
}
}
private static void InitConfig()
{
if (!File.Exists(ConfigPath))
@ -80,11 +34,9 @@ namespace FireflySR.Tool.Proxy
}
}
private static void OnProcessExit(object? sender, EventArgs? args)
private static void OnProcessExit(object? sender, EventArgs args)
{
if (s_clearupd) return;
s_proxyService?.Shutdown();
s_clearupd = true;
s_proxyService.Shutdown();
}
public static void CheckProxy()

View file

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
using System.Text.Json;
namespace FireflySR.Tool.Proxy;
#if NET8_0_OR_GREATER
[JsonSourceGenerationOptions(
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip
)]
[JsonSerializable(typeof(ProxyConfig))]
internal partial class ProxyConfigContext : JsonSerializerContext
{
}
#endif

View file

@ -4,22 +4,7 @@ A simple Proxy for playing Private Servers.
## Usage
Go to [releases page](https://git.xeondev.com/YYHEggEgg/FireflySR.Tool.Proxy/releases) for the latest pre-built binary. It don't require any .NET versions.
## Update
### v2.0.0
- Fixed the issue whereby the proxy has been closed by the user while the System Proxy Settings is still enabled, which may cause the user "can't access the network".
Notice you may still need to change the setting if you meet a PC crash (or just start the Proxy software again and close it).
- Updated the building .NET requirement to `8.0`; however, `PublishAot` is enabled, so the generated binaries won't require any .NET versions. You can generate AOT build by the following command:
```sh
dotnet publish FireflySR.Tool.Proxy.csproj -r win-x64
```
Notice a [Guardian](Guardian/Guardian.csproj) is introduced **only on Windows** and will be copied to the output directory only when the build is triggered on Windows.
- Updated the `BlockUrls` list in `config.tmpl.json`.
`dotnet run` to build and run this program. Pre-built binaries may be uploaded later.
## Configuration
@ -27,5 +12,4 @@ Simple: see [config.json](config.json). You can also see full options in [ProxyC
## Credits
- [FreeSR](https://git.xeondev.com/Moux23333/FreeSR) & `FreeSR.Tool.Proxy`
- Rebooted `Titanium.Web.Proxy` [Unobtanium.Web.Proxy](https://github.com/svrooij/titanium-web-proxy.git)
[FreeSR](https://git.xeondev.com/Moux23333/FreeSR) & `FreeSR.Tool.Proxy`

View file

@ -31,14 +31,7 @@
"/client/event/dataUpload",
"/log",
"/asm/dataUpload",
"/sophon/dataUpload",
"/apm/dataUpload",
"/2g/dataUpload",
"/v1/firelog/legacy/log",
"/h5/upload",
"/_ts",
"/perf/config/verify",
"/ptolemaios_api/api/reportStrategyData"
"/sophon/dataUpload"
],
"ForceRedirectOnUrlContains": [
"query_dispatch",