Everything works on Windows, pending tests on Mono
This commit is contained in:
JustArchi 2017-02-03 09:54:09 +01:00
parent 0d6942b8ec
commit 24350dcba5
4 changed files with 90 additions and 33 deletions

View file

@ -324,6 +324,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AES/@EntryIndexedValue">AES</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=API/@EntryIndexedValue">API</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ASF/@EntryIndexedValue">ASF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EWCF/@EntryIndexedValue">EWCF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FA/@EntryIndexedValue">FA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FS/@EntryIndexedValue">FS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HTML/@EntryIndexedValue">HTML</s:String>
@ -337,6 +338,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TTL/@EntryIndexedValue">TTL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=URL/@EntryIndexedValue">URL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WCF/@EntryIndexedValue">WCF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WS/@EntryIndexedValue">WS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WTF/@EntryIndexedValue">WTF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XML/@EntryIndexedValue">XML</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="I" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>

View file

@ -38,10 +38,6 @@ namespace ArchiSteamFarm {
internal const byte DefaultConnectionTimeout = 60;
internal const ushort DefaultWCFPort = 1242;
private const byte DefaultFarmingDelay = 15;
private const byte DefaultMaxFarmingTime = 10;
private const ProtocolType DefaultSteamProtocol = ProtocolType.Tcp;
// This is hardcoded blacklist which should not be possible to change
internal static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 267420, 303700, 335590, 368020, 425280, 480730, 566020 };
@ -64,7 +60,7 @@ namespace ArchiSteamFarm {
internal readonly bool Debug = false;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly byte FarmingDelay = DefaultFarmingDelay;
internal readonly byte FarmingDelay = 15;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly byte GiftsLimiterDelay = 1;
@ -82,7 +78,7 @@ namespace ArchiSteamFarm {
internal readonly byte LoginLimiterDelay = 10;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly byte MaxFarmingTime = DefaultMaxFarmingTime;
internal readonly byte MaxFarmingTime = 10;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly byte MaxTradeHoldDuration = 15;
@ -97,16 +93,19 @@ namespace ArchiSteamFarm {
internal readonly ulong SteamOwnerID = 0;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly ProtocolType SteamProtocol = DefaultSteamProtocol;
internal readonly ProtocolType SteamProtocol = ProtocolType.Tcp;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly EUpdateChannel UpdateChannel = EUpdateChannel.Stable;
[JsonProperty]
internal string WCFHost { get; set; } = "127.0.0.1";
[JsonProperty(Required = Required.DisallowNull)]
internal readonly ushort WCFPort = DefaultWCFPort;
[JsonProperty]
internal string WCFHost { get; set; } = "127.0.0.1";
[JsonProperty(Required = Required.DisallowNull)]
internal readonly EWCFProtocol WCFProtocol = EWCFProtocol.NetTcp;
// This constructor is used only by deserializer
private GlobalConfig() { }
@ -182,5 +181,12 @@ namespace ArchiSteamFarm {
Stable,
Experimental
}
[SuppressMessage("ReSharper", "UnusedMember.Global")]
internal enum EWCFProtocol : byte {
NetTcp,
BasicHttp,
WSHttp
}
}
}

View file

@ -39,8 +39,6 @@ namespace ArchiSteamFarm {
}
internal sealed class WCF : IWCF, IDisposable {
private static string URL = "net.tcp://127.0.0.1:1242/ASF";
internal bool IsServerRunning => ServiceHost != null;
private Client Client;
@ -81,12 +79,7 @@ namespace ArchiSteamFarm {
internal static void Init() {
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHost)) {
Program.GlobalConfig.WCFHost = Program.GetUserInput(ASF.EUserInputType.WCFHostname);
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHost)) {
return;
}
}
URL = "net.tcp://" + Program.GlobalConfig.WCFHost + ":" + Program.GlobalConfig.WCFPort + "/ASF";
}
internal string SendCommand(string input) {
@ -95,17 +88,24 @@ namespace ArchiSteamFarm {
return null;
}
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.WCFSendingCommand, input, URL));
Binding binding = GetTargetBinding();
if (binding == null) {
ASF.ArchiLogger.LogNullError(nameof(binding));
return null;
}
string url = GetUrlFromBinding(binding);
if (string.IsNullOrEmpty(url)) {
ASF.ArchiLogger.LogNullError(nameof(url));
return null;
}
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.WCFSendingCommand, input, url));
if (Client == null) {
Client = new Client(
new NetTcpBinding {
// We use SecurityMode.None for Mono compatibility
// Yes, also on Windows, for Mono<->Windows communication
Security = { Mode = SecurityMode.None },
SendTimeout = new TimeSpan(0, 0, Program.GlobalConfig.ConnectionTimeout)
},
new EndpointAddress(URL)
binding,
new EndpointAddress(url)
);
}
@ -117,20 +117,28 @@ namespace ArchiSteamFarm {
return;
}
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.WCFStarting, URL));
Binding binding = GetTargetBinding();
if (binding == null) {
ASF.ArchiLogger.LogNullError(nameof(binding));
return;
}
string url = GetUrlFromBinding(binding);
if (string.IsNullOrEmpty(url)) {
ASF.ArchiLogger.LogNullError(nameof(url));
return;
}
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.WCFStarting, url));
try {
ServiceHost = new ServiceHost(typeof(WCF), new Uri(URL));
ServiceHost = new ServiceHost(typeof(WCF), new Uri(url));
ServiceHost.AddServiceEndpoint(
typeof(IWCF),
new NetTcpBinding {
// We use SecurityMode.None for Mono compatibility
// Yes, also on Windows, for Mono<->Windows communication
Security = { Mode = SecurityMode.None },
SendTimeout = new TimeSpan(0, 0, Program.GlobalConfig.ConnectionTimeout)
},
binding,
string.Empty
);
ServiceHost.Open();
ASF.ArchiLogger.LogGenericInfo(Strings.WCFReady);
@ -157,6 +165,46 @@ namespace ArchiSteamFarm {
ServiceHost = null;
}
private static string GetUrlFromBinding(Binding binding) {
if (binding != null) {
return binding.Scheme + "://" + Program.GlobalConfig.WCFHost + ":" + Program.GlobalConfig.WCFPort + "/ASF";
}
ASF.ArchiLogger.LogNullError(nameof(binding));
return null;
}
private static Binding GetTargetBinding() {
Binding result;
switch (Program.GlobalConfig.WCFProtocol) {
case GlobalConfig.EWCFProtocol.NetTcp:
result = new NetTcpBinding {
// We use SecurityMode.None for Mono compatibility
// Yes, also on Windows, for Mono<->Windows communication
Security = { Mode = SecurityMode.None }
};
break;
case GlobalConfig.EWCFProtocol.BasicHttp:
result = new BasicHttpBinding();
break;
case GlobalConfig.EWCFProtocol.WSHttp:
result = new WSHttpBinding {
// We use SecurityMode.None for Mono compatibility
// Yes, also on Windows, for Mono<->Windows communication
Security = { Mode = SecurityMode.None }
};
break;
default:
ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(Program.GlobalConfig.WCFProtocol), Program.GlobalConfig.WCFProtocol));
goto case GlobalConfig.EWCFProtocol.NetTcp;
}
result.SendTimeout = new TimeSpan(0, 0, Program.GlobalConfig.ConnectionTimeout);
return result;
}
private void StopClient() {
if (Client == null) {
return;

View file

@ -27,5 +27,6 @@
"SteamProtocol": 6,
"UpdateChannel": 1,
"WCFHost": "127.0.0.1",
"WCFPort": 1242
"WCFPort": 1242,
"WCFProtocol": 0
}