Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuration #18

Merged
merged 13 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/network-pressure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ jobs:
dotnet-version: '6.0.x'

- name: Restore NuGet packages
run: dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj

run: |
dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)"
dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj

- name: Run tests
run: cd KcpTests/KcpPerformanceTest ; dotnet run --configuration Release -- --packet-size 3500 --packet-repeat-time 5000 --packet-interval 50 --github-actions --clients-count 10

Expand All @@ -49,7 +51,9 @@ jobs:
dotnet-version: '6.0.x'

- name: Restore NuGet packages
run: dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj
run: |
dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)"
dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj

- name: Run tests
run: cd KcpTests/KcpPerformanceTest ; dotnet run --configuration Release -- --packet-size 3500 --packet-repeat-time 5000 --packet-interval 50 --github-actions --clients-count 20
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/network-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ jobs:
dotnet-version: '6.0.x'

- name: Restore NuGet packages
run: dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj
run: |
dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)"
dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj

- name: Run tests
run: cd KcpTests/KcpPerformanceTest ; dotnet run --configuration Release -- --packet-size 3500 --packet-repeat-time 5000 --packet-interval 40 --github-actions --clients-count 2 --packet-delay-log
Expand All @@ -57,7 +59,9 @@ jobs:
dotnet-version: '6.0.x'

- name: Restore NuGet packages
run: dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj
run: |
dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)"
dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj

- name: Run tests
run: cd KcpTests/KcpPerformanceTest ; dotnet run --configuration Release -- --packet-size 3500 --packet-repeat-time 5000 --packet-interval 40 --github-actions --clients-count 2 --packet-delay-log
Expand All @@ -82,7 +86,9 @@ jobs:
dotnet-version: '6.0.x'

- name: Restore NuGet packages
run: dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj
run: |
dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)"
dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj

- name: Run tests
# Generated by ChatGPT
Expand All @@ -108,7 +114,9 @@ jobs:
dotnet-version: '6.0.x'

- name: Restore NuGet packages
run: dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj
run: |
dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)"
dotnet restore KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj

- name: Run tests
# Generated by ChatGPT
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pull-request-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ name: Normal Build
on:
push:
branches:
- protoshift-ex-config-json-read
- protoshift-ex-hotpatch-support
pull_request:
branches:
- main
- protoshift-ex
- protoshift-ex-config-json-read
- protoshift-ex-hotpatch-support

jobs:
Expand All @@ -29,6 +31,9 @@ jobs:
- name: Setup protoc
run: cp bin/protoc HandlerGenerator/protoc ; chmod +x HandlerGenerator/protoc

- name: Setup nuget Integration Source
run: dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)"

- name: Restore Generator NuGet packages
run: dotnet restore HandlerGenerator/HandlerGenerator.csproj

Expand Down
100 changes: 65 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################

# Main Protoshift
/csharp-Protoshift/bin
/csharp-Protoshift/obj
/.vs
/YSFreedomServer-v2
/csharp-Protoshift/logs
/csharp-Protoshift/Properties
/csharp-Protoshift/windy_temp
/csharp-Protoshift/config.json
/csharp-Protoshift/protoshift_hotpatch_config.json
/csharp-Protoshift/skillissue_fix_config.json
/csharp-Protoshift/windy_config.json

# Replay Debugger
/csharp-Protoshift-Replay/bin
/csharp-Protoshift-Replay/obj
/csharp-Protoshift-Replay/logs

# Protos
/NewProtoHandlers/bin
/NewProtoHandlers/obj
/NewProtoHandlers/Backup
Expand All @@ -13,48 +27,64 @@
/OldProtoHandlers/obj
/OldProtoHandlers/Backup
/OldProtoHandlers/AskCmdId.cs
/csharp-Protoshift/bin/Release/net6.0/logs
/csharp-Protoshift/bin/Debug/net6.0/logs
/csharp-Protoshift/bin/Debug/net6.0/Temp
/XC.RSAUtil/bin
/XC.RSAUtil/obj
/csharp-Protoshift/bin
/CSharp-Logger/bin
/CSharp-Logger/obj
/.config
/OldProtoHandlers/Google.Protobuf.3.4

# protoshift-ex Handlers & Generator
/ProtoshiftHandlers/bin
/ProtoshiftHandlers/obj
/ProtoshiftHandlers/Generated
/ProtoshiftHandlers/ProtoDispatch/Backup
/HandlerGenerator/.vscode
/HandlerGenerator/bin
/HandlerGenerator/obj
/HandlerGenerator/logs
/HandlerGenerator/proto2json/proto2json_output
/ProtoshiftHandlers/bin
/ProtoshiftHandlers/obj
/.vscode
/HandlerGenerator/Proto2json_Output
/HandlerGenerator/.vscode
/KCP
/KcpCsharpTest
/KcpTests
/csharp-Protoshift/logs
/csharp-Protoshift/skillissue_fix_config.json
/KcpTestClient
/KcpTestServer
/HandlerGenerator/ProtoFieldNameAnalyze/Compiled
/HandlerGenerator/ProtoFieldNameAnalyze/GeneratedProtos
/HandlerGenerator/last_build_record.json
/ProtoshiftHandlers/Generated
/ProtoshiftHandlers/ProtoDispatch/Backup
/NewProtoHandlers/AskCmdId.cs
/OldProtoHandlers/AskCmdId.cs
/NewProtoHandlers/Backup
/OldProtoHandlers/Backup

# Benchmark
/ProtoshiftBenchmark/bin
/ProtoshiftBenchmark/obj
/ProtoshiftBenchmark/BenchmarkDotNet.Artifacts
/ProtoshiftBenchmark/logs
/ProtoshiftBenchmark/obj
/ProtoshiftBenchmark/output_benchmark
/csharp-Protoshift-Replay/bin
/csharp-Protoshift-Replay/obj
/csharp-Protoshift-Replay/logs
/OldProtoHandlers/Google.Protobuf.3.4
/csharp-Protoshift/windy_config.json
/ProtoshiftBenchmark/logs
/ProtoshiftBenchmark/Properties

# Other Projects
/XC.RSAUtil/bin
/CSharp-Logger/bin
/CSharp-Logger/obj
/XC.RSAUtil/obj

# Kcp Implement
/KCP/Image
/KCP/KcpDemo
/KCP/TestClient
/KCP/TestServer
/KCP/UnitTestProject1
/KCP/UnityIL2CPPTest
/KCP/ChangeLog.md
/KCP/KCP.sln
/KCP/OpenSource.snk

# Kcp Tests Projects
/KcpCsharpTest
/KcpTestClient
/KcpTests/.vs
/KcpTests/.vscode
/KcpTests/KcpPerformanceTest/bin
/KcpTests/KcpPerformanceTest/obj
/KcpTests/KcpPerformanceTest/logs
/KcpTests/SharedLib/bin
/KcpTests/SharedLib/obj
/KcpTests/SharedLib/logs
/KcpTestServer

# etc
/.config
/.vs
/.vscode
/Builds
/YSFreedomServer-v2
9 changes: 6 additions & 3 deletions HandlerGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Text;
using YYHEggEgg.Logger;

string res_dir = StartupWorkingDirChanger.Required_directory
?? throw new InvalidOperationException("Please give a correct res dir in code.");

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Protoshift Ex v1");
StartupWorkingDirChanger.ChangeToDotNetRunPath(new LoggerConfig(
Expand Down Expand Up @@ -58,7 +61,7 @@
Console.ReadLine();
Environment.Exit(272574);
}
ResourcesLoader.CheckForRequiredResources();
ResourcesLoader.CheckForRequiredResources(res_dir);
Directory.CreateDirectory("./../OldProtoHandlers/Backup");
Directory.CreateDirectory("./../NewProtoHandlers/Backup");
Directory.CreateDirectory("./../ProtoshiftHandlers/ProtoDispatch/Backup");
Expand Down Expand Up @@ -609,8 +612,8 @@
#endregion
Log.Info("Conguratulations! Protoshift handlers generated successfully.");
Log.Info("Now generating CmdId related and ProtoshiftDispatch...");
CmdIdDataStructure cmdData = new("./resources/protobuf/oldcmdid.csv",
"./resources/protobuf/newcmdid.csv", messageResults);
CmdIdDataStructure cmdData = new($"{res_dir}/protobuf/oldcmdid.csv",
$"{res_dir}/protobuf/newcmdid.csv", messageResults);

AppDomain.CurrentDomain.ProcessExit += RecoverBackup;
#region Generate CmdId related
Expand Down Expand Up @@ -839,7 +842,7 @@
{
var p = Process.Start(startInfo);
string? rtnvalue = null;
p.WaitForExit();

Check warning on line 845 in HandlerGenerator/Program.cs

View workflow job for this annotation

GitHub Actions / protoshift-ex-rel

Dereference of a possibly null reference.

Check warning on line 845 in HandlerGenerator/Program.cs

View workflow job for this annotation

GitHub Actions / protoshift-ex-rel

Dereference of a possibly null reference.
if (p.ExitCode != 0) return null;
rtnvalue = p.StandardOutput.ReadToEnd();
if (rtnvalue == string.Empty) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ internal class CmdIdDataStructure
public CmdIdDataStructure(string oldcmdid_path, string newcmdid_path,
CollectionResult<MessageResult> messageResults)
{
oldcmdids = ReadCmdIdFromCsv("./resources/protobuf/oldcmdid.csv", ref messages_havecmdid);
newcmdids = ReadCmdIdFromCsv("./resources/protobuf/newcmdid.csv", ref messages_havecmdid);
oldcmdids = ReadCmdIdFromCsv(oldcmdid_path, ref messages_havecmdid);
newcmdids = ReadCmdIdFromCsv(newcmdid_path, ref messages_havecmdid);
supportedMessages = new(new List<string>(
from pair in messageResults.IntersectItems
select pair.LeftItem.messageName));
Expand Down
2 changes: 1 addition & 1 deletion HandlerGenerator/StartupWorkingDirChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace csharp_Protoshift.Enhanced.Handlers.Generator
internal static class StartupWorkingDirChanger
{
public const string? Required_file = "./HandlerGenerator.csproj";
public const string? Required_directory = "./resources";
public const string? Required_directory = "./../csharp-Protoshift/resources";

public const string Terminating_Note = "Can't find source code path. Please run this program with dotnet run. \n" +
"***********WARNING**********\n" +
Expand Down
90 changes: 58 additions & 32 deletions HandlerGenerator/resLoader/ResourcesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,88 @@ public static class ResourcesLoader
" /ServerPri -- Server Private Keys, SPri\n" +
" /2-pri.pem, ..., 5-pri.pem -- PEM format RSA keys with key_id\n" +
" /protobuf\n" +
" /newcmdid.csv -- New Protos CmdIds" +
" /oldcmdid.csv -- Old Protos CmdIds";
" /newcmdid.csv -- New Protos CmdIds\n" +
" /oldcmdid.csv -- Old Protos CmdIds\n" +
" /config-schemas\n" +
" /config_schema_{version}.json -- schema json, DO NOT delete\n" +
" /luac_bins -- windy compilers, DO NOT delete";

private static LoggerChannel? _checklogger = null;

#region Check
/// <summary>
/// Check for resources, if not complete then exit with code 114514.
/// </summary>
public static void CheckForRequiredResources()
public static void CheckForRequiredResources(string resPath = "./resources")
{
_checklogger = Log.GetChannel("ResourcesCheck");
bool passcheck = true;
// Resources
if (!Directory.Exists("resources"))
if (!Directory.Exists(resPath))
{
Log.Erro("resources dir missing! Please copy it from \"/resources\"!", "ResourcesCheck");
Log.Info(StructureDescription, "ResourcesCheck");
_checklogger.LogErro("resources dir missing! Please copy it from \"/resources\"!");
_checklogger.LogInfo(StructureDescription);
passcheck = false;
}
else
{
bool resourcesComplete = true;
if (!File.Exists("resources/protobuf/newcmdid.csv"))
{
Log.Erro("/resources/protobuf/newcmdid.csv not found!");
resourcesComplete = false;
}
if (!File.Exists("resources/protobuf/oldcmdid.csv"))
{
Log.Erro("/resources/protobuf/oldcmdid.csv not found!");
resourcesComplete = false;
}
if (!File.Exists("resources/xor/dispatchKey.bin"))
{
Log.Erro("/resources/xor/dispatchKey.bin not found!");
resourcesComplete = false;
}
if (!Directory.Exists("resources/rsakeys/ClientPri"))
{
Log.Erro("/resources/rsakeys/ClientPri not found!");
resourcesComplete = false;
}
if (!Directory.Exists("resources/rsakeys/ServerPri"))
CheckFileResource("protobuf/newcmdid.csv", resPath, ref resourcesComplete);
CheckFileResource("protobuf/oldcmdid.csv", resPath, ref resourcesComplete);
CheckFileResource("xor/dispatchKey.bin", resPath, ref resourcesComplete);
CheckDirectoryResource("rsakeys/ClientPri", resPath, ref resourcesComplete);
CheckDirectoryResource("rsakeys/ServerPri", resPath, ref resourcesComplete,
continueOnFailure: () =>
{
Log.Erro("/resources/rsakeys/ServerPri not found!");
DirectoryInfo serverpubdir = new("rsakeys/ServerPub");
if (serverpubdir.Exists && serverpubdir.EnumerateFiles().Any())
{
Log.Warn("Detected /resources/rsakeys/ServerPub keys given. ServerPub keys " +
$"are only used for some utils in the program, and ServerPri keys " +
$"are REQUIRED for you to run an actual Protoshift server.", "ResourcesCheck");
}
resourcesComplete = false;
}
});
CheckFileResource("luac_bins/luac_win32.exe", resPath, ref resourcesComplete);
CheckFileResource("luac_bins/luac_win64.exe", resPath, ref resourcesComplete);
CheckFileResource("luac_bins/luac_unix64", resPath, ref resourcesComplete);
if (!resourcesComplete)
{
Log.Info(StructureDescription, "ResourcesCheck");
_checklogger.LogInfo(StructureDescription);
passcheck = false;
}
}
if (!passcheck)
{
Log.Erro("Resources check didn't pass. Press Enter to exit.", "ResourcesCheck");
Console.ReadLine();
_checklogger.LogErro("Resources check didn't pass. Press Enter to exit.");
if (Log.GlobalConfig.Use_Console_Wrapper) ConsoleWrapper.ReadLine();
else Console.ReadLine();
Environment.Exit(114514);
}
}

private static void CheckFileResource(string path, string resBasePath, ref bool isResComplete)
{
var filePath = Path.Combine(resBasePath, path);
if (!File.Exists(filePath))
{
_checklogger?.LogErro($"{filePath} not found!");
isResComplete = false;
}
}

private static void CheckDirectoryResource(string path, string resBasePath,
ref bool isResComplete, Action? continueOnSuccess = null, Action? continueOnFailure = null)
{
var dirPath = Path.Combine(resBasePath, path);
if (!Directory.Exists(dirPath))
{
_checklogger?.LogErro($"{dirPath} not found!");
isResComplete = false;
continueOnFailure?.Invoke();
}
else continueOnSuccess?.Invoke();
}
#endregion
}
}
Loading
Loading