mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 22:20:52 +00:00
Implement IPCPrefixes
This makes it possible to not only listen on multiple different host/port combinations, but also different protocols or base URLs (even though this will probably break things up, need to do more tests)
This commit is contained in:
@@ -75,8 +75,8 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty]
|
||||
internal readonly string IPCPassword;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly ushort IPCPort = DefaultIPCPort;
|
||||
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
|
||||
internal readonly HashSet<string> IPCPrefixes = new HashSet<string> { "http://127.0.0.1:" + DefaultIPCPort + "/" };
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte LoginLimiterDelay = DefaultLoginLimiterDelay;
|
||||
@@ -99,9 +99,6 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte UpdatePeriod = 24;
|
||||
|
||||
[JsonProperty]
|
||||
internal string IPCHost { get; set; } = "127.0.0.1";
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal ulong SteamOwnerID { get; private set; }
|
||||
|
||||
@@ -162,11 +159,6 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (globalConfig.IPCPort == 0) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(globalConfig.IPCPort), globalConfig.IPCPort));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (globalConfig.SteamProtocols.HasFlag(ProtocolTypes.WebSocket) && !OS.SupportsWebSockets()) {
|
||||
globalConfig.SteamProtocols &= ~ProtocolTypes.WebSocket;
|
||||
if (globalConfig.SteamProtocols == 0) {
|
||||
|
||||
@@ -90,9 +90,9 @@ namespace ArchiSteamFarm {
|
||||
HistoryTarget = historyTarget;
|
||||
}
|
||||
|
||||
internal static void Start(string host, ushort port) {
|
||||
if (string.IsNullOrEmpty(host) || (port == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(host) + " || " + nameof(port));
|
||||
internal static void Start(HashSet<string> prefixes) {
|
||||
if ((prefixes == null) || (prefixes.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(prefixes));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,21 +101,14 @@ namespace ArchiSteamFarm {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (host) {
|
||||
case "0.0.0.0":
|
||||
case "::":
|
||||
// Silently map INADDR_ANY to match HttpListener expectations
|
||||
host = "*";
|
||||
break;
|
||||
}
|
||||
|
||||
string url = "http://" + host + ":" + port + "/";
|
||||
HttpListener = new HttpListener { IgnoreWriteExceptions = true };
|
||||
|
||||
try {
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.IPCStarting, url));
|
||||
foreach (string prefix in prefixes) {
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.IPCStarting, prefix));
|
||||
HttpListener.Prefixes.Add(prefix);
|
||||
}
|
||||
|
||||
HttpListener.Prefixes.Add(url);
|
||||
HttpListener.Start();
|
||||
} catch (Exception e) {
|
||||
// HttpListener can dispose itself on error, so don't keep it around
|
||||
|
||||
@@ -449,7 +449,12 @@ namespace ArchiSteamFarm {
|
||||
goto default;
|
||||
}
|
||||
|
||||
IPC.Start(GlobalConfig.IPCHost, GlobalConfig.IPCPort);
|
||||
if (GlobalConfig.IPCPrefixes.Count == 0) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, nameof(GlobalConfig.IPCPrefixes)));
|
||||
break;
|
||||
}
|
||||
|
||||
IPC.Start(GlobalConfig.IPCPrefixes);
|
||||
break;
|
||||
case "--service":
|
||||
if (cryptKeyNext) {
|
||||
@@ -471,6 +476,8 @@ namespace ArchiSteamFarm {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
IPC.Start(GlobalConfig.IPCPrefixes);
|
||||
}
|
||||
|
||||
private static void ParsePreInitArgs(IReadOnlyCollection<string> args) {
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
"Headless": false,
|
||||
"IdleFarmingPeriod": 8,
|
||||
"InventoryLimiterDelay": 3,
|
||||
"IPCHost": "127.0.0.1",
|
||||
"IPCPassword": null,
|
||||
"IPCPort": 1242,
|
||||
"IPCPrefixes": [
|
||||
"http://127.0.0.1:1242/"
|
||||
],
|
||||
"LoginLimiterDelay": 10,
|
||||
"MaxFarmingTime": 10,
|
||||
"MaxTradeHoldDuration": 15,
|
||||
|
||||
Reference in New Issue
Block a user