mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-23 17:56:49 +00:00
Compare commits
144 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33e0675177 | ||
|
|
f840f28657 | ||
|
|
64eb4a51b6 | ||
|
|
97affa7b54 | ||
|
|
65f1d790da | ||
|
|
0107185f2a | ||
|
|
b8e98f58ac | ||
|
|
be9217f493 | ||
|
|
b60b864aca | ||
|
|
4c64141462 | ||
|
|
4b50596709 | ||
|
|
622f060575 | ||
|
|
20038e8c86 | ||
|
|
b8faca2517 | ||
|
|
6f93139a18 | ||
|
|
50b5c7b87f | ||
|
|
b60448ef4c | ||
|
|
fad08a1fa9 | ||
|
|
a180c100c6 | ||
|
|
9d97ca16e8 | ||
|
|
e833415718 | ||
|
|
6bb296a674 | ||
|
|
f1e5874868 | ||
|
|
38e2088d09 | ||
|
|
8447e07aa0 | ||
|
|
fbe4e4bc6d | ||
|
|
f1213607ce | ||
|
|
de832c530b | ||
|
|
0c872b17e2 | ||
|
|
5fcbb85b4c | ||
|
|
3cdc93d373 | ||
|
|
36e99d9139 | ||
|
|
7bee2d468b | ||
|
|
8630cc40c8 | ||
|
|
3683195a0e | ||
|
|
7f5b946645 | ||
|
|
fdb194fe67 | ||
|
|
9063b9206b | ||
|
|
8d300894e5 | ||
|
|
3a0d3c444e | ||
|
|
8118fe0690 | ||
|
|
344c2ad23d | ||
|
|
d1a6613541 | ||
|
|
3dc88c65aa | ||
|
|
46384829c9 | ||
|
|
415ee8cc57 | ||
|
|
351d45e049 | ||
|
|
f81bbc60c5 | ||
|
|
eb6e93a172 | ||
|
|
e17c3ecf2a | ||
|
|
048b0fb538 | ||
|
|
ac7ecb6bb4 | ||
|
|
fcaf038dac | ||
|
|
f3da5d6afc | ||
|
|
84f33fcef4 | ||
|
|
22f0d423a3 | ||
|
|
f1d7609796 | ||
|
|
77386ecae5 | ||
|
|
4e86d21ef8 | ||
|
|
044fc87691 | ||
|
|
79fad62a4d | ||
|
|
6622d3b147 | ||
|
|
6b6d5429ad | ||
|
|
d59d0a8415 | ||
|
|
e3100d3938 | ||
|
|
42c020e552 | ||
|
|
554273833b | ||
|
|
093a29df62 | ||
|
|
31aa6b2e4a | ||
|
|
9f7ecdf054 | ||
|
|
7c4c74bf84 | ||
|
|
b8f03abd8b | ||
|
|
47f846540b | ||
|
|
bc14713079 | ||
|
|
770a8fee66 | ||
|
|
1df9af08e6 | ||
|
|
27464f6120 | ||
|
|
dfd45c6e25 | ||
|
|
adc1759cee | ||
|
|
88369ec71a | ||
|
|
a5d8ae53dd | ||
|
|
cd7b65868a | ||
|
|
7575704a01 | ||
|
|
b6ce8f435c | ||
|
|
565acca9fb | ||
|
|
610954ba73 | ||
|
|
74a748b03f | ||
|
|
585a075ec9 | ||
|
|
891d40afe1 | ||
|
|
387f0dd1c7 | ||
|
|
8b4d3c219c | ||
|
|
365877ec89 | ||
|
|
f03a43d573 | ||
|
|
d15a9cbfca | ||
|
|
acfad624fb | ||
|
|
03a7d5f4ac | ||
|
|
0f96d84d36 | ||
|
|
0edc9f4ff6 | ||
|
|
d11e141ece | ||
|
|
9ff3834ed7 | ||
|
|
9806703cfa | ||
|
|
ca0857abd1 | ||
|
|
d32d3bfd36 | ||
|
|
6efb07eada | ||
|
|
2b28f01b1c | ||
|
|
fb350fe792 | ||
|
|
5e73d18cd2 | ||
|
|
3ff95995b9 | ||
|
|
17b2bc2259 | ||
|
|
4a36345635 | ||
|
|
e9d8f271a2 | ||
|
|
6c84f8eb4f | ||
|
|
54ad58a22d | ||
|
|
790e6baf46 | ||
|
|
c8fb715558 | ||
|
|
2ab5e6013d | ||
|
|
3e0c34e62c | ||
|
|
65b31e5537 | ||
|
|
62a6e38e47 | ||
|
|
0b50a45336 | ||
|
|
8d1d162b02 | ||
|
|
dbe13a1965 | ||
|
|
fc13633f5e | ||
|
|
d0cc10f3c6 | ||
|
|
567931a4cc | ||
|
|
396dc17ab2 | ||
|
|
288cc29338 | ||
|
|
844ca7da94 | ||
|
|
b14b9f87c7 | ||
|
|
8aa086cc27 | ||
|
|
cf00989d84 | ||
|
|
8f2f85282c | ||
|
|
fa12ffd9d0 | ||
|
|
ecb27adedd | ||
|
|
6e9be09944 | ||
|
|
6a79a89a10 | ||
|
|
d67be4f092 | ||
|
|
a8e1039e32 | ||
|
|
2ad9d9e197 | ||
|
|
fd6e2c72d7 | ||
|
|
1eed0f7647 | ||
|
|
c018c08260 | ||
|
|
72fa98cb89 | ||
|
|
71215d695e |
@@ -1,4 +1,3 @@
|
|||||||
sudo: false
|
|
||||||
language: csharp
|
language: csharp
|
||||||
solution: ArchiSteamFarm.sln
|
solution: ArchiSteamFarm.sln
|
||||||
|
|
||||||
@@ -8,3 +7,6 @@ git:
|
|||||||
mono:
|
mono:
|
||||||
- weekly
|
- weekly
|
||||||
- latest
|
- latest
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigGenerator", "ConfigGe
|
|||||||
{35AF7887-08B9-40E8-A5EA-797D8B60B30C} = {35AF7887-08B9-40E8-A5EA-797D8B60B30C}
|
{35AF7887-08B9-40E8-A5EA-797D8B60B30C} = {35AF7887-08B9-40E8-A5EA-797D8B60B30C}
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GUI", "GUI\GUI.csproj", "{599121A9-5887-4522-A3D6-61470B90BAD4}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{35AF7887-08B9-40E8-A5EA-797D8B60B30C} = {35AF7887-08B9-40E8-A5EA-797D8B60B30C}
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -30,6 +35,10 @@ Global
|
|||||||
{C3F6FE68-5E75-415E-BEA1-1E7C16D6A433}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C3F6FE68-5E75-415E-BEA1-1E7C16D6A433}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C3F6FE68-5E75-415E-BEA1-1E7C16D6A433}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C3F6FE68-5E75-415E-BEA1-1E7C16D6A433}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C3F6FE68-5E75-415E-BEA1-1E7C16D6A433}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C3F6FE68-5E75-415E-BEA1-1E7C16D6A433}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{599121A9-5887-4522-A3D6-61470B90BAD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{599121A9-5887-4522-A3D6-61470B90BAD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{599121A9-5887-4522-A3D6-61470B90BAD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{599121A9-5887-4522-A3D6-61470B90BAD4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -26,12 +26,24 @@ using SteamKit2;
|
|||||||
using SteamKit2.Internal;
|
using SteamKit2.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal sealed class ArchiHandler : ClientMsgHandler {
|
internal sealed class ArchiHandler : ClientMsgHandler {
|
||||||
|
private readonly Bot Bot;
|
||||||
|
|
||||||
|
internal ArchiHandler(Bot bot) {
|
||||||
|
if (bot == null) {
|
||||||
|
throw new ArgumentNullException(nameof(bot));
|
||||||
|
}
|
||||||
|
|
||||||
|
Bot = bot;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
____ _ _ _ _
|
____ _ _ _ _
|
||||||
/ ___| __ _ | || || |__ __ _ ___ | | __ ___
|
/ ___| __ _ | || || |__ __ _ ___ | | __ ___
|
||||||
@@ -42,69 +54,60 @@ namespace ArchiSteamFarm {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
internal sealed class NotificationsCallback : CallbackMsg {
|
internal sealed class NotificationsCallback : CallbackMsg {
|
||||||
internal sealed class Notification {
|
internal enum ENotification : byte {
|
||||||
internal enum ENotificationType : uint {
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
Trading = 1,
|
Trading = 1,
|
||||||
// Only custom below, different than ones available as user_notification_type
|
// Only custom below, different than ones available as user_notification_type
|
||||||
Items = 514
|
Items = 255
|
||||||
}
|
}
|
||||||
|
|
||||||
internal readonly ENotificationType NotificationType;
|
internal readonly HashSet<ENotification> Notifications;
|
||||||
|
|
||||||
internal Notification(ENotificationType notificationType) {
|
|
||||||
NotificationType = notificationType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal readonly List<Notification> Notifications;
|
|
||||||
|
|
||||||
internal NotificationsCallback(JobID jobID, CMsgClientUserNotifications msg) {
|
internal NotificationsCallback(JobID jobID, CMsgClientUserNotifications msg) {
|
||||||
JobID = jobID;
|
if ((jobID == null) || (msg == null)) {
|
||||||
|
throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));
|
||||||
if (msg == null || msg.notifications == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Notifications = new List<Notification>(msg.notifications.Count);
|
JobID = jobID;
|
||||||
foreach (var notification in msg.notifications) {
|
|
||||||
Notifications.Add(new Notification((Notification.ENotificationType) notification.user_notification_type));
|
Notifications = new HashSet<ENotification>();
|
||||||
|
foreach (CMsgClientUserNotifications.Notification notification in msg.notifications) {
|
||||||
|
Notifications.Add((ENotification) notification.user_notification_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal NotificationsCallback(JobID jobID, CMsgClientItemAnnouncements msg) {
|
internal NotificationsCallback(JobID jobID, CMsgClientItemAnnouncements msg) {
|
||||||
JobID = jobID;
|
if ((jobID == null) || (msg == null)) {
|
||||||
|
throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));
|
||||||
if (msg == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JobID = jobID;
|
||||||
|
|
||||||
if (msg.count_new_items > 0) {
|
if (msg.count_new_items > 0) {
|
||||||
Notifications = new List<Notification>(1) {
|
Notifications = new HashSet<ENotification> {
|
||||||
new Notification(Notification.ENotificationType.Items)
|
ENotification.Items
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class OfflineMessageCallback : CallbackMsg {
|
internal sealed class OfflineMessageCallback : CallbackMsg {
|
||||||
internal readonly uint OfflineMessages;
|
internal readonly uint OfflineMessagesCount;
|
||||||
internal readonly List<uint> Users;
|
|
||||||
|
|
||||||
internal OfflineMessageCallback(JobID jobID, CMsgClientOfflineMessageNotification msg) {
|
internal OfflineMessageCallback(JobID jobID, CMsgClientOfflineMessageNotification msg) {
|
||||||
JobID = jobID;
|
if ((jobID == null) || (msg == null)) {
|
||||||
|
throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));
|
||||||
if (msg == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflineMessages = msg.offline_messages;
|
JobID = jobID;
|
||||||
Users = msg.friends_with_offline_messages;
|
OfflineMessagesCount = msg.offline_messages;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class PurchaseResponseCallback : CallbackMsg {
|
internal sealed class PurchaseResponseCallback : CallbackMsg {
|
||||||
internal enum EPurchaseResult : int {
|
internal enum EPurchaseResult : sbyte {
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
Unknown = -1,
|
Unknown = -1,
|
||||||
OK = 0,
|
OK = 0,
|
||||||
AlreadyOwned = 9,
|
AlreadyOwned = 9,
|
||||||
@@ -115,39 +118,35 @@ namespace ArchiSteamFarm {
|
|||||||
OnCooldown = 53
|
OnCooldown = 53
|
||||||
}
|
}
|
||||||
|
|
||||||
internal readonly EResult Result;
|
|
||||||
internal readonly EPurchaseResult PurchaseResult;
|
internal readonly EPurchaseResult PurchaseResult;
|
||||||
internal readonly KeyValue ReceiptInfo;
|
|
||||||
internal readonly Dictionary<uint, string> Items;
|
internal readonly Dictionary<uint, string> Items;
|
||||||
|
|
||||||
internal PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse msg) {
|
internal PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse msg) {
|
||||||
JobID = jobID;
|
if ((jobID == null) || (msg == null)) {
|
||||||
|
throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));
|
||||||
if (msg == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result = (EResult) msg.eresult;
|
JobID = jobID;
|
||||||
PurchaseResult = (EPurchaseResult) msg.purchase_result_details;
|
PurchaseResult = (EPurchaseResult) msg.purchase_result_details;
|
||||||
|
|
||||||
if (msg.purchase_receipt_info == null) {
|
if (msg.purchase_receipt_info == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiptInfo = new KeyValue();
|
KeyValue receiptInfo = new KeyValue();
|
||||||
using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) {
|
using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) {
|
||||||
if (!ReceiptInfo.TryReadAsBinary(ms)) {
|
if (!receiptInfo.TryReadAsBinary(ms)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<KeyValue> lineItems = ReceiptInfo["lineitems"].Children;
|
List<KeyValue> lineItems = receiptInfo["lineitems"].Children;
|
||||||
Items = new Dictionary<uint, string>(lineItems.Count);
|
Items = new Dictionary<uint, string>(lineItems.Count);
|
||||||
|
|
||||||
foreach (KeyValue lineItem in lineItems) {
|
foreach (KeyValue lineItem in lineItems) {
|
||||||
uint appID = (uint) lineItem["PackageID"].AsUnsignedLong();
|
uint appID = (uint) lineItem["PackageID"].AsUnsignedLong();
|
||||||
string gameName = lineItem["ItemDescription"].AsString();
|
string gameName = lineItem["ItemDescription"].Value;
|
||||||
gameName = WebUtility.UrlDecode(gameName); // Apparently steam expects client to decode sent HTML
|
gameName = WebUtility.HtmlDecode(gameName); // Apparently steam expects client to decode sent HTML
|
||||||
Items.Add(appID, gameName);
|
Items[appID] = gameName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,83 +161,42 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
internal void AcceptClanInvite(ulong clanID) {
|
|
||||||
if (clanID == 0 || !Client.IsConnected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new ClientMsg<CMsgClientClanInviteAction>((int) EMsg.ClientAcknowledgeClanInvite);
|
|
||||||
request.Body.GroupID = clanID;
|
|
||||||
request.Body.AcceptInvite = true;
|
|
||||||
|
|
||||||
Client.Send(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void DeclineClanInvite(ulong clanID) {
|
|
||||||
if (clanID == 0 || !Client.IsConnected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new ClientMsg<CMsgClientClanInviteAction>((int) EMsg.ClientAcknowledgeClanInvite);
|
|
||||||
request.Body.GroupID = clanID;
|
|
||||||
request.Body.AcceptInvite = false;
|
|
||||||
|
|
||||||
Client.Send(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void PlayGame(string gameName) {
|
internal void PlayGame(string gameName) {
|
||||||
if (!Client.IsConnected) {
|
if (!Client.IsConnected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
|
ClientMsgProtobuf<CMsgClientGamesPlayed> request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
|
||||||
|
|
||||||
var gamePlayed = new CMsgClientGamesPlayed.GamePlayed();
|
|
||||||
if (!string.IsNullOrEmpty(gameName)) {
|
if (!string.IsNullOrEmpty(gameName)) {
|
||||||
gamePlayed.game_id = new GameID() {
|
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed {
|
||||||
|
game_extra_info = gameName,
|
||||||
|
game_id = new GameID {
|
||||||
AppType = GameID.GameType.Shortcut,
|
AppType = GameID.GameType.Shortcut,
|
||||||
ModID = uint.MaxValue
|
ModID = uint.MaxValue
|
||||||
};
|
|
||||||
gamePlayed.game_extra_info = gameName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
request.Body.games_played.Add(gamePlayed);
|
|
||||||
|
|
||||||
Client.Send(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void PlayGames(params uint[] gameIDs) {
|
|
||||||
if (!Client.IsConnected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
|
|
||||||
foreach (uint gameID in gameIDs) {
|
|
||||||
if (gameID == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed {
|
|
||||||
game_id = new GameID(gameID),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Client.Send(request);
|
Client.Send(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void PlayGames(ICollection<uint> gameIDs) {
|
internal void PlayGames(uint gameID) {
|
||||||
if (gameIDs == null || !Client.IsConnected) {
|
if (!Client.IsConnected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
|
PlayGames(new HashSet<uint> { gameID });
|
||||||
foreach (uint gameID in gameIDs) {
|
|
||||||
if (gameID == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void PlayGames(ICollection<uint> gameIDs) {
|
||||||
|
if ((gameIDs == null) || !Client.IsConnected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientMsgProtobuf<CMsgClientGamesPlayed> request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
|
||||||
|
foreach (uint gameID in gameIDs.Where(gameID => gameID != 0)) {
|
||||||
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed {
|
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed {
|
||||||
game_id = new GameID(gameID),
|
game_id = new GameID(gameID)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,17 +208,18 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = new ClientMsgProtobuf<CMsgClientRegisterKey>(EMsg.ClientRegisterKey) {
|
ClientMsgProtobuf<CMsgClientRegisterKey> request = new ClientMsgProtobuf<CMsgClientRegisterKey>(EMsg.ClientRegisterKey) {
|
||||||
SourceJobID = Client.GetNextJobID()
|
SourceJobID = Client.GetNextJobID()
|
||||||
};
|
};
|
||||||
|
|
||||||
request.Body.key = key;
|
request.Body.key = key;
|
||||||
|
|
||||||
Client.Send(request);
|
Client.Send(request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await new AsyncJob<PurchaseResponseCallback>(Client, request.SourceJobID);
|
return await new AsyncJob<PurchaseResponseCallback>(Client, request.SourceJobID);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e, Bot.BotName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,8 +232,11 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
SteamID steamID = new SteamID(details.AccountID, details.AccountInstance, Client.ConnectedUniverse, EAccountType.Individual);
|
SteamID steamID = new SteamID(details.AccountID, details.AccountInstance, Client.ConnectedUniverse, EAccountType.Individual);
|
||||||
|
|
||||||
var logon = new ClientMsgProtobuf<CMsgClientLogon>(EMsg.ClientLogon);
|
ClientMsgProtobuf<CMsgClientLogon> logon = new ClientMsgProtobuf<CMsgClientLogon>(EMsg.ClientLogon);
|
||||||
|
if (details.LoginID != null) {
|
||||||
logon.Body.obfustucated_private_ip = details.LoginID.Value;
|
logon.Body.obfustucated_private_ip = details.LoginID.Value;
|
||||||
|
}
|
||||||
|
|
||||||
logon.ProtoHeader.client_sessionid = 0;
|
logon.ProtoHeader.client_sessionid = 0;
|
||||||
logon.ProtoHeader.steamid = steamID.ConvertToUInt64();
|
logon.ProtoHeader.steamid = steamID.ConvertToUInt64();
|
||||||
logon.Body.account_name = details.Username;
|
logon.Body.account_name = details.Username;
|
||||||
@@ -330,7 +292,7 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new ClientMsgProtobuf<CMsgClientOfflineMessageNotification>(packetMsg);
|
ClientMsgProtobuf<CMsgClientOfflineMessageNotification> response = new ClientMsgProtobuf<CMsgClientOfflineMessageNotification>(packetMsg);
|
||||||
Client.PostCallback(new OfflineMessageCallback(packetMsg.TargetJobID, response.Body));
|
Client.PostCallback(new OfflineMessageCallback(packetMsg.TargetJobID, response.Body));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +301,7 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new ClientMsgProtobuf<CMsgClientItemAnnouncements>(packetMsg);
|
ClientMsgProtobuf<CMsgClientItemAnnouncements> response = new ClientMsgProtobuf<CMsgClientItemAnnouncements>(packetMsg);
|
||||||
Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body));
|
Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +310,7 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new ClientMsgProtobuf<CMsgClientPurchaseResponse>(packetMsg);
|
ClientMsgProtobuf<CMsgClientPurchaseResponse> response = new ClientMsgProtobuf<CMsgClientPurchaseResponse>(packetMsg);
|
||||||
Client.PostCallback(new PurchaseResponseCallback(packetMsg.TargetJobID, response.Body));
|
Client.PostCallback(new PurchaseResponseCallback(packetMsg.TargetJobID, response.Body));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,7 +319,7 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new ClientMsgProtobuf<CMsgClientUserNotifications>(packetMsg);
|
ClientMsgProtobuf<CMsgClientUserNotifications> response = new ClientMsgProtobuf<CMsgClientUserNotifications>(packetMsg);
|
||||||
Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body));
|
Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,10 +99,11 @@
|
|||||||
<Compile Include="ArchiWebHandler.cs" />
|
<Compile Include="ArchiWebHandler.cs" />
|
||||||
<Compile Include="Bot.cs" />
|
<Compile Include="Bot.cs" />
|
||||||
<Compile Include="BotConfig.cs" />
|
<Compile Include="BotConfig.cs" />
|
||||||
|
<Compile Include="ConcurrentEnumerator.cs" />
|
||||||
|
<Compile Include="ConcurrentHashSet.cs" />
|
||||||
<Compile Include="GlobalDatabase.cs" />
|
<Compile Include="GlobalDatabase.cs" />
|
||||||
<Compile Include="BotDatabase.cs" />
|
<Compile Include="BotDatabase.cs" />
|
||||||
<Compile Include="CardsFarmer.cs" />
|
<Compile Include="CardsFarmer.cs" />
|
||||||
<Compile Include="CMsgs\CMsgClientClanInviteAction.cs" />
|
|
||||||
<Compile Include="Debugging.cs" />
|
<Compile Include="Debugging.cs" />
|
||||||
<Compile Include="GlobalConfig.cs" />
|
<Compile Include="GlobalConfig.cs" />
|
||||||
<Compile Include="JSON\GitHub.cs" />
|
<Compile Include="JSON\GitHub.cs" />
|
||||||
|
|||||||
@@ -28,46 +28,95 @@ using SteamKit2;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using ArchiSteamFarm.JSON;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal sealed class ArchiWebHandler {
|
internal sealed class ArchiWebHandler {
|
||||||
private const string SteamCommunity = "steamcommunity.com";
|
private const string SteamCommunityHost = "steamcommunity.com";
|
||||||
private const byte MinSessionTTL = 15; // Assume session is valid for at least that amount of seconds
|
private const byte MinSessionTTL = 15; // Assume session is valid for at least that amount of seconds
|
||||||
|
|
||||||
private static string SteamCommunityURL = "https://" + SteamCommunity;
|
private static string SteamCommunityURL = "https://" + SteamCommunityHost;
|
||||||
|
|
||||||
private static int Timeout = GlobalConfig.DefaultHttpTimeout * 1000;
|
private static int Timeout = GlobalConfig.DefaultHttpTimeout * 1000;
|
||||||
|
|
||||||
private readonly Bot Bot;
|
private readonly Bot Bot;
|
||||||
private readonly Dictionary<string, string> Cookie = new Dictionary<string, string>(4);
|
|
||||||
private readonly SemaphoreSlim SessionSemaphore = new SemaphoreSlim(1);
|
private readonly SemaphoreSlim SessionSemaphore = new SemaphoreSlim(1);
|
||||||
|
private readonly WebBrowser WebBrowser;
|
||||||
|
|
||||||
private DateTime LastSessionRefreshCheck = DateTime.MinValue;
|
private DateTime LastSessionRefreshCheck = DateTime.MinValue;
|
||||||
|
|
||||||
internal static void Init() {
|
internal static void Init() {
|
||||||
Timeout = Program.GlobalConfig.HttpTimeout * 1000;
|
Timeout = Program.GlobalConfig.HttpTimeout * 1000;
|
||||||
SteamCommunityURL = (Program.GlobalConfig.ForceHttp ? "http://" : "https://") + SteamCommunity;
|
SteamCommunityURL = (Program.GlobalConfig.ForceHttp ? "http://" : "https://") + SteamCommunityHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetAppIDFromMarketHashName(string hashName) {
|
||||||
|
if (string.IsNullOrEmpty(hashName)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = hashName.IndexOf('-');
|
||||||
|
if (index < 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint appID;
|
||||||
|
return !uint.TryParse(hashName.Substring(0, index), out appID) ? 0 : appID;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Steam.Item.EType GetItemType(string name) {
|
||||||
|
if (string.IsNullOrEmpty(name)) {
|
||||||
|
return Steam.Item.EType.Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (name) {
|
||||||
|
case "Booster Pack":
|
||||||
|
return Steam.Item.EType.BoosterPack;
|
||||||
|
case "Coupon":
|
||||||
|
return Steam.Item.EType.Coupon;
|
||||||
|
case "Gift":
|
||||||
|
return Steam.Item.EType.Gift;
|
||||||
|
case "Steam Gems":
|
||||||
|
return Steam.Item.EType.SteamGems;
|
||||||
|
default:
|
||||||
|
if (name.EndsWith("Emoticon", StringComparison.Ordinal)) {
|
||||||
|
return Steam.Item.EType.Emoticon;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.EndsWith("Foil Trading Card", StringComparison.Ordinal)) {
|
||||||
|
return Steam.Item.EType.FoilTradingCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.EndsWith("Profile Background", StringComparison.Ordinal)) {
|
||||||
|
return Steam.Item.EType.ProfileBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name.EndsWith("Trading Card", StringComparison.Ordinal) ? Steam.Item.EType.TradingCard : Steam.Item.EType.Unknown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal ArchiWebHandler(Bot bot) {
|
internal ArchiWebHandler(Bot bot) {
|
||||||
if (bot == null) {
|
if (bot == null) {
|
||||||
return;
|
throw new ArgumentNullException(nameof(bot));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bot = bot;
|
Bot = bot;
|
||||||
|
|
||||||
|
WebBrowser = new WebBrowser(bot.BotName);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool Init(SteamClient steamClient, string webAPIUserNonce, string parentalPin) {
|
internal bool Init(SteamClient steamClient, string webAPIUserNonce, string parentalPin) {
|
||||||
if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce)) {
|
if ((steamClient == null) || string.IsNullOrEmpty(webAPIUserNonce)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong steamID = steamClient.SteamID;
|
ulong steamID = steamClient.SteamID;
|
||||||
|
if (steamID == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString()));
|
string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString()));
|
||||||
|
|
||||||
@@ -114,15 +163,13 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
Logging.LogGenericInfo("Success!", Bot.BotName);
|
Logging.LogGenericInfo("Success!", Bot.BotName);
|
||||||
|
|
||||||
string steamLogin = authResult["token"].AsString();
|
WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamCommunityHost));
|
||||||
string steamLoginSecure = authResult["tokensecure"].AsString();
|
|
||||||
|
|
||||||
Cookie["sessionid"] = sessionID;
|
string steamLogin = authResult["token"].Value;
|
||||||
Cookie["steamLogin"] = steamLogin;
|
WebBrowser.CookieContainer.Add(new Cookie("steamLogin", steamLogin, "/", "." + SteamCommunityHost));
|
||||||
Cookie["steamLoginSecure"] = steamLoginSecure;
|
|
||||||
|
|
||||||
// The below is used for display purposes only
|
string steamLoginSecure = authResult["tokensecure"].Value;
|
||||||
Cookie["webTradeEligibility"] = "{\"allowed\":0,\"reason\":0,\"allowed_at_time\":0,\"steamguard_required_days\":0,\"sales_this_year\":0,\"max_sales_per_year\":0,\"forms_requested\":0}";
|
WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamCommunityHost));
|
||||||
|
|
||||||
if (!UnlockParentalAccount(parentalPin).Result) {
|
if (!UnlockParentalAccount(parentalPin).Result) {
|
||||||
return false;
|
return false;
|
||||||
@@ -132,49 +179,71 @@ namespace ArchiSteamFarm {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<bool?> IsLoggedIn() {
|
internal async Task<bool> AcceptGift(ulong gid) {
|
||||||
HtmlDocument htmlDocument = null;
|
if (gid == 0) {
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && htmlDocument == null; i++) {
|
return false;
|
||||||
htmlDocument = await WebBrowser.UrlGetToHtmlDocument(SteamCommunityURL + "/my/profile", Cookie).ConfigureAwait(false);
|
}
|
||||||
|
|
||||||
|
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid");
|
||||||
|
if (string.IsNullOrEmpty(sessionID)) {
|
||||||
|
Logging.LogNullError("sessionID");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string request = SteamCommunityURL + "/gifts/" + gid + "/acceptunpack";
|
||||||
|
Dictionary<string, string> data = new Dictionary<string, string>(1) {
|
||||||
|
{ "sessionid", sessionID }
|
||||||
|
};
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && !result; i++) {
|
||||||
|
result = await WebBrowser.UrlPost(request, data).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (htmlDocument == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//span[@id='account_pulldown']");
|
internal async Task<bool> JoinGroup(ulong groupID) {
|
||||||
return htmlNode != null;
|
if (groupID == 0) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<bool> RefreshSessionIfNeeded() {
|
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
||||||
DateTime now = DateTime.Now;
|
return false;
|
||||||
if (now.Subtract(LastSessionRefreshCheck).TotalSeconds < MinSessionTTL) {
|
}
|
||||||
|
|
||||||
|
string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid");
|
||||||
|
if (string.IsNullOrEmpty(sessionID)) {
|
||||||
|
Logging.LogNullError("sessionID");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string request = SteamCommunityURL + "/gid/" + groupID;
|
||||||
|
Dictionary<string, string> data = new Dictionary<string, string>(2) {
|
||||||
|
{ "sessionID", sessionID },
|
||||||
|
{ "action", "join" }
|
||||||
|
};
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && !result; i++) {
|
||||||
|
result = await WebBrowser.UrlPost(request, data).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
|
return false;
|
||||||
now = DateTime.Now;
|
|
||||||
if (now.Subtract(LastSessionRefreshCheck).TotalSeconds < MinSessionTTL) {
|
|
||||||
SessionSemaphore.Release();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool result;
|
|
||||||
|
|
||||||
bool? isLoggedIn = await IsLoggedIn().ConfigureAwait(false);
|
|
||||||
if (isLoggedIn.GetValueOrDefault(true)) {
|
|
||||||
result = true;
|
|
||||||
now = DateTime.Now;
|
|
||||||
LastSessionRefreshCheck = now;
|
|
||||||
} else {
|
|
||||||
Logging.LogGenericInfo("Refreshing our session!", Bot.BotName);
|
|
||||||
result = await Bot.RefreshSession().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionSemaphore.Release();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<Dictionary<uint, string>> GetOwnedGames() {
|
internal async Task<Dictionary<uint, string>> GetOwnedGames() {
|
||||||
@@ -185,8 +254,8 @@ namespace ArchiSteamFarm {
|
|||||||
string request = SteamCommunityURL + "/my/games/?xml=1";
|
string request = SteamCommunityURL + "/my/games/?xml=1";
|
||||||
|
|
||||||
XmlDocument response = null;
|
XmlDocument response = null;
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
|
||||||
response = await WebBrowser.UrlGetToXML(request, Cookie).ConfigureAwait(false);
|
response = await WebBrowser.UrlGetToXML(request).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
@@ -195,7 +264,7 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
XmlNodeList xmlNodeList = response.SelectNodes("gamesList/games/game");
|
XmlNodeList xmlNodeList = response.SelectNodes("gamesList/games/game");
|
||||||
if (xmlNodeList == null || xmlNodeList.Count == 0) {
|
if ((xmlNodeList == null) || (xmlNodeList.Count == 0)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +291,47 @@ namespace ArchiSteamFarm {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<Steam.TradeOffer> GetTradeOffers() {
|
internal Dictionary<uint, string> GetOwnedGames(ulong steamID) {
|
||||||
|
if ((steamID == 0) || string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyValue response = null;
|
||||||
|
using (dynamic iPlayerService = WebAPI.GetInterface("IPlayerService", Bot.BotConfig.SteamApiKey)) {
|
||||||
|
iPlayerService.Timeout = Timeout;
|
||||||
|
|
||||||
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
|
||||||
|
try {
|
||||||
|
response = iPlayerService.GetOwnedGames(
|
||||||
|
steamid: steamID,
|
||||||
|
include_appinfo: 1,
|
||||||
|
secure: !Program.GlobalConfig.ForceHttp
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logging.LogGenericException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response == null) {
|
||||||
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<uint, string> result = new Dictionary<uint, string>(response["games"].Children.Count);
|
||||||
|
foreach (KeyValue game in response["games"].Children) {
|
||||||
|
uint appID = (uint) game["appid"].AsUnsignedLong();
|
||||||
|
if (appID == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[appID] = game["name"].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal HashSet<Steam.TradeOffer> GetTradeOffers() {
|
||||||
if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) {
|
if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -231,11 +340,12 @@ namespace ArchiSteamFarm {
|
|||||||
using (dynamic iEconService = WebAPI.GetInterface("IEconService", Bot.BotConfig.SteamApiKey)) {
|
using (dynamic iEconService = WebAPI.GetInterface("IEconService", Bot.BotConfig.SteamApiKey)) {
|
||||||
iEconService.Timeout = Timeout;
|
iEconService.Timeout = Timeout;
|
||||||
|
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
|
||||||
try {
|
try {
|
||||||
response = iEconService.GetTradeOffers(
|
response = iEconService.GetTradeOffers(
|
||||||
get_received_offers: 1,
|
get_received_offers: 1,
|
||||||
active_only: 1,
|
active_only: 1,
|
||||||
|
get_descriptions: 1,
|
||||||
secure: !Program.GlobalConfig.ForceHttp
|
secure: !Program.GlobalConfig.ForceHttp
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -249,73 +359,92 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Steam.TradeOffer> result = new List<Steam.TradeOffer>();
|
Dictionary<Tuple<ulong, ulong>, Tuple<uint, Steam.Item.EType>> descriptions = new Dictionary<Tuple<ulong, ulong>, Tuple<uint, Steam.Item.EType>>();
|
||||||
|
foreach (KeyValue description in response["descriptions"].Children) {
|
||||||
|
ulong classID = description["classid"].AsUnsignedLong();
|
||||||
|
if (classID == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong instanceID = description["instanceid"].AsUnsignedLong();
|
||||||
|
|
||||||
|
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(classID, instanceID);
|
||||||
|
if (descriptions.ContainsKey(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint appID = 0;
|
||||||
|
Steam.Item.EType type = Steam.Item.EType.Unknown;
|
||||||
|
|
||||||
|
string hashName = description["market_hash_name"].Value;
|
||||||
|
if (!string.IsNullOrEmpty(hashName)) {
|
||||||
|
appID = GetAppIDFromMarketHashName(hashName);
|
||||||
|
}
|
||||||
|
|
||||||
|
string descriptionType = description["type"].Value;
|
||||||
|
if (!string.IsNullOrEmpty(descriptionType)) {
|
||||||
|
type = GetItemType(descriptionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
descriptions[key] = new Tuple<uint, Steam.Item.EType>(appID, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<Steam.TradeOffer> result = new HashSet<Steam.TradeOffer>();
|
||||||
foreach (KeyValue trade in response["trade_offers_received"].Children) {
|
foreach (KeyValue trade in response["trade_offers_received"].Children) {
|
||||||
Steam.TradeOffer tradeOffer = new Steam.TradeOffer {
|
Steam.TradeOffer tradeOffer = new Steam.TradeOffer {
|
||||||
tradeofferid = trade["tradeofferid"].AsString(),
|
TradeOfferID = trade["tradeofferid"].AsUnsignedLong(),
|
||||||
accountid_other = (uint) trade["accountid_other"].AsUnsignedLong(), // TODO: Correct this when SK2 with https://github.com/SteamRE/SteamKit/pull/255 gets released
|
OtherSteamID3 = (uint) trade["accountid_other"].AsUnsignedLong(),
|
||||||
trade_offer_state = trade["trade_offer_state"].AsEnum<Steam.TradeOffer.ETradeOfferState>()
|
State = trade["trade_offer_state"].AsEnum<Steam.TradeOffer.ETradeOfferState>()
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (KeyValue item in trade["items_to_give"].Children) {
|
foreach (KeyValue item in trade["items_to_give"].Children) {
|
||||||
tradeOffer.items_to_give.Add(new Steam.Item {
|
Steam.Item steamItem = new Steam.Item {
|
||||||
appid = item["appid"].AsString(),
|
AppID = (uint) item["appid"].AsUnsignedLong(),
|
||||||
contextid = item["contextid"].AsString(),
|
ContextID = item["contextid"].AsUnsignedLong(),
|
||||||
assetid = item["assetid"].AsString(),
|
AssetID = item["assetid"].AsUnsignedLong(),
|
||||||
classid = item["classid"].AsString(),
|
ClassID = item["classid"].AsUnsignedLong(),
|
||||||
instanceid = item["instanceid"].AsString(),
|
InstanceID = item["instanceid"].AsUnsignedLong(),
|
||||||
amount = item["amount"].AsString(),
|
Amount = (uint) item["amount"].AsUnsignedLong()
|
||||||
});
|
};
|
||||||
|
|
||||||
|
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(steamItem.ClassID, steamItem.InstanceID);
|
||||||
|
|
||||||
|
Tuple<uint, Steam.Item.EType> description;
|
||||||
|
if (descriptions.TryGetValue(key, out description)) {
|
||||||
|
steamItem.RealAppID = description.Item1;
|
||||||
|
steamItem.Type = description.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tradeOffer.ItemsToGive.Add(steamItem);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (KeyValue item in trade["items_to_receive"].Children) {
|
foreach (KeyValue item in trade["items_to_receive"].Children) {
|
||||||
tradeOffer.items_to_receive.Add(new Steam.Item {
|
Steam.Item steamItem = new Steam.Item {
|
||||||
appid = item["appid"].AsString(),
|
AppID = (uint) item["appid"].AsUnsignedLong(),
|
||||||
contextid = item["contextid"].AsString(),
|
ContextID = item["contextid"].AsUnsignedLong(),
|
||||||
assetid = item["assetid"].AsString(),
|
AssetID = item["assetid"].AsUnsignedLong(),
|
||||||
classid = item["classid"].AsString(),
|
ClassID = item["classid"].AsUnsignedLong(),
|
||||||
instanceid = item["instanceid"].AsString(),
|
InstanceID = item["instanceid"].AsUnsignedLong(),
|
||||||
amount = item["amount"].AsString(),
|
Amount = (uint) item["amount"].AsUnsignedLong()
|
||||||
});
|
};
|
||||||
|
|
||||||
|
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(steamItem.ClassID, steamItem.InstanceID);
|
||||||
|
|
||||||
|
Tuple<uint, Steam.Item.EType> description;
|
||||||
|
if (descriptions.TryGetValue(key, out description)) {
|
||||||
|
steamItem.RealAppID = description.Item1;
|
||||||
|
steamItem.Type = description.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tradeOffer.ItemsToReceive.Add(steamItem);
|
||||||
|
}
|
||||||
|
|
||||||
result.Add(tradeOffer);
|
result.Add(tradeOffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<bool> JoinClan(ulong clanID) {
|
|
||||||
if (clanID == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
string sessionID;
|
|
||||||
if (!Cookie.TryGetValue("sessionid", out sessionID)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
string request = SteamCommunityURL + "/gid/" + clanID;
|
|
||||||
|
|
||||||
Dictionary<string, string> data = new Dictionary<string, string>(2) {
|
|
||||||
{"sessionID", sessionID},
|
|
||||||
{"action", "join"}
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
|
||||||
response = await WebBrowser.UrlPost(request, data, Cookie).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal async Task<bool> AcceptTradeOffer(ulong tradeID) {
|
internal async Task<bool> AcceptTradeOffer(ulong tradeID) {
|
||||||
if (tradeID == 0) {
|
if (tradeID == 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -325,41 +454,47 @@ namespace ArchiSteamFarm {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string sessionID;
|
string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid");
|
||||||
if (!Cookie.TryGetValue("sessionid", out sessionID)) {
|
if (string.IsNullOrEmpty(sessionID)) {
|
||||||
|
Logging.LogNullError("sessionID");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string referer = SteamCommunityURL + "/tradeoffer/" + tradeID;
|
string referer = SteamCommunityURL + "/tradeoffer/" + tradeID;
|
||||||
string request = referer + "/accept";
|
string request = referer + "/accept";
|
||||||
|
|
||||||
Dictionary<string, string> data = new Dictionary<string, string>(3) {
|
Dictionary<string, string> data = new Dictionary<string, string>(3) {
|
||||||
{ "sessionid", sessionID },
|
{ "sessionid", sessionID },
|
||||||
{ "serverid", "1" },
|
{ "serverid", "1" },
|
||||||
{ "tradeofferid", tradeID.ToString() }
|
{ "tradeofferid", tradeID.ToString() }
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
bool result = false;
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && !result; i++) {
|
||||||
response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false);
|
result = await WebBrowser.UrlPost(request, data, referer).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
internal async Task<HashSet<Steam.Item>> GetMyTradableInventory() {
|
||||||
}
|
|
||||||
|
|
||||||
internal async Task<List<Steam.Item>> GetMyTradableInventory() {
|
|
||||||
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashSet<Steam.Item> result = new HashSet<Steam.Item>();
|
||||||
|
|
||||||
|
ushort nextPage = 0;
|
||||||
|
while (true) {
|
||||||
|
string request = SteamCommunityURL + "/my/inventory/json/" + Steam.Item.SteamAppID + "/" + Steam.Item.SteamContextID + "?trading=1&start=" + nextPage;
|
||||||
|
|
||||||
JObject jObject = null;
|
JObject jObject = null;
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && jObject == null; i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (jObject == null); i++) {
|
||||||
jObject = await WebBrowser.UrlGetToJObject(SteamCommunityURL + "/my/inventory/json/753/6?trading=1", Cookie).ConfigureAwait(false);
|
jObject = await WebBrowser.UrlGetToJObject(request).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jObject == null) {
|
if (jObject == null) {
|
||||||
@@ -367,26 +502,100 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<JToken> jTokens = jObject.SelectTokens("$.rgInventory.*");
|
IEnumerable<JToken> descriptions = jObject.SelectTokens("$.rgDescriptions.*");
|
||||||
if (jTokens == null) {
|
if (descriptions == null) {
|
||||||
Logging.LogNullError("jTokens", Bot.BotName);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Steam.Item> result = new List<Steam.Item>();
|
Dictionary<Tuple<ulong, ulong>, Tuple<uint, Steam.Item.EType>> descriptionMap = new Dictionary<Tuple<ulong, ulong>, Tuple<uint, Steam.Item.EType>>();
|
||||||
foreach (JToken jToken in jTokens) {
|
foreach (JToken description in descriptions) {
|
||||||
|
string classIDString = description["classid"].ToString();
|
||||||
|
if (string.IsNullOrEmpty(classIDString)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong classID;
|
||||||
|
if (!ulong.TryParse(classIDString, out classID) || (classID == 0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string instanceIDString = description["instanceid"].ToString();
|
||||||
|
if (string.IsNullOrEmpty(instanceIDString)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong instanceID;
|
||||||
|
if (!ulong.TryParse(instanceIDString, out instanceID)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(classID, instanceID);
|
||||||
|
if (descriptionMap.ContainsKey(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint appID = 0;
|
||||||
|
Steam.Item.EType type = Steam.Item.EType.Unknown;
|
||||||
|
|
||||||
|
string hashName = description["market_hash_name"].ToString();
|
||||||
|
if (!string.IsNullOrEmpty(hashName)) {
|
||||||
|
appID = GetAppIDFromMarketHashName(hashName);
|
||||||
|
}
|
||||||
|
|
||||||
|
string descriptionType = description["type"].ToString();
|
||||||
|
if (!string.IsNullOrEmpty(descriptionType)) {
|
||||||
|
type = GetItemType(descriptionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
descriptionMap[key] = new Tuple<uint, Steam.Item.EType>(appID, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<JToken> items = jObject.SelectTokens("$.rgInventory.*");
|
||||||
|
if (items == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (JToken item in items) {
|
||||||
|
|
||||||
|
Steam.Item steamItem;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result.Add(JsonConvert.DeserializeObject<Steam.Item>(jToken.ToString()));
|
steamItem = JsonConvert.DeserializeObject<Steam.Item>(item.ToString());
|
||||||
} catch (Exception e) {
|
} catch (JsonException e) {
|
||||||
Logging.LogGenericException(e, Bot.BotName);
|
Logging.LogGenericException(e, Bot.BotName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (steamItem == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(steamItem.ClassID, steamItem.InstanceID);
|
||||||
|
|
||||||
|
Tuple<uint, Steam.Item.EType> description;
|
||||||
|
if (descriptionMap.TryGetValue(key, out description)) {
|
||||||
|
steamItem.RealAppID = description.Item1;
|
||||||
|
steamItem.Type = description.Item2;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Add(steamItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool more;
|
||||||
|
if (!bool.TryParse(jObject["more"].ToString(), out more) || !more) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ushort.TryParse(jObject["more_start"].ToString(), out nextPage)) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<bool> SendTradeOffer(List<Steam.Item> inventory, ulong partnerID, string token = null) {
|
internal async Task<bool> SendTradeOffer(HashSet<Steam.Item> inventory, ulong partnerID, string token = null) {
|
||||||
if (inventory == null || inventory.Count == 0 || partnerID == 0) {
|
if ((inventory == null) || (inventory.Count == 0) || (partnerID == 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,36 +603,39 @@ namespace ArchiSteamFarm {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string sessionID;
|
string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid");
|
||||||
if (!Cookie.TryGetValue("sessionid", out sessionID)) {
|
if (string.IsNullOrEmpty(sessionID)) {
|
||||||
|
Logging.LogNullError("sessionID");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Steam.TradeOfferRequest> trades = new List<Steam.TradeOfferRequest>(1 + inventory.Count / Trading.MaxItemsPerTrade);
|
Steam.TradeOfferRequest singleTrade = new Steam.TradeOfferRequest();
|
||||||
|
HashSet<Steam.TradeOfferRequest> trades = new HashSet<Steam.TradeOfferRequest> { singleTrade };
|
||||||
|
|
||||||
Steam.TradeOfferRequest singleTrade = null;
|
byte itemID = 0;
|
||||||
for (ushort i = 0; i < inventory.Count; i++) {
|
foreach (Steam.Item item in inventory) {
|
||||||
if (i % Trading.MaxItemsPerTrade == 0) {
|
if (itemID >= Trading.MaxItemsPerTrade) {
|
||||||
if (trades.Count >= Trading.MaxTradesPerAccount) {
|
if (trades.Count >= Trading.MaxTradesPerAccount) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
singleTrade = new Steam.TradeOfferRequest();
|
singleTrade = new Steam.TradeOfferRequest();
|
||||||
trades.Add(singleTrade);
|
trades.Add(singleTrade);
|
||||||
|
itemID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Steam.Item item = inventory[i];
|
singleTrade.ItemsToGive.Assets.Add(new Steam.Item {
|
||||||
singleTrade.me.assets.Add(new Steam.Item() {
|
AppID = Steam.Item.SteamAppID,
|
||||||
appid = "753",
|
ContextID = Steam.Item.SteamContextID,
|
||||||
contextid = "6",
|
Amount = item.Amount,
|
||||||
amount = item.amount,
|
AssetID = item.AssetID
|
||||||
assetid = item.id
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itemID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
string referer = SteamCommunityURL + "/tradeoffer/new";
|
string referer = SteamCommunityURL + "/tradeoffer/new";
|
||||||
string request = referer + "/send";
|
string request = referer + "/send";
|
||||||
|
|
||||||
foreach (Steam.TradeOfferRequest trade in trades) {
|
foreach (Steam.TradeOfferRequest trade in trades) {
|
||||||
Dictionary<string, string> data = new Dictionary<string, string>(6) {
|
Dictionary<string, string> data = new Dictionary<string, string>(6) {
|
||||||
{ "sessionid", sessionID },
|
{ "sessionid", sessionID },
|
||||||
@@ -434,16 +646,18 @@ namespace ArchiSteamFarm {
|
|||||||
{ "trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : $"{{\"trade_offer_access_token\":\"{token}\"}}" }
|
{ "trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : $"{{\"trade_offer_access_token\":\"{token}\"}}" }
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
bool result = false;
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && !result; i++) {
|
||||||
response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false);
|
result = await WebBrowser.UrlPost(request, data, referer).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -457,19 +671,21 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string request = SteamCommunityURL + "/my/badges?p=" + page;
|
||||||
|
|
||||||
HtmlDocument htmlDocument = null;
|
HtmlDocument htmlDocument = null;
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && htmlDocument == null; i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (htmlDocument == null); i++) {
|
||||||
htmlDocument = await WebBrowser.UrlGetToHtmlDocument(SteamCommunityURL + "/my/badges?l=english&p=" + page, Cookie).ConfigureAwait(false);
|
htmlDocument = await WebBrowser.UrlGetToHtmlDocument(request).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (htmlDocument != null) {
|
||||||
|
return htmlDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (htmlDocument == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return htmlDocument;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal async Task<HtmlDocument> GetGameCardsPage(ulong appID) {
|
internal async Task<HtmlDocument> GetGameCardsPage(ulong appID) {
|
||||||
if (appID == 0) {
|
if (appID == 0) {
|
||||||
return null;
|
return null;
|
||||||
@@ -479,117 +695,108 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string request = SteamCommunityURL + "/my/gamecards/" + appID;
|
||||||
|
|
||||||
HtmlDocument htmlDocument = null;
|
HtmlDocument htmlDocument = null;
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && htmlDocument == null; i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (htmlDocument == null); i++) {
|
||||||
htmlDocument = await WebBrowser.UrlGetToHtmlDocument(SteamCommunityURL + "/my/gamecards/" + appID + "?l=english", Cookie).ConfigureAwait(false);
|
htmlDocument = await WebBrowser.UrlGetToHtmlDocument(request).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (htmlDocument != null) {
|
||||||
|
return htmlDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (htmlDocument == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return htmlDocument;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal async Task<bool> MarkInventory() {
|
internal async Task<bool> MarkInventory() {
|
||||||
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
string request = SteamCommunityURL + "/my/inventory";
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
|
||||||
response = await WebBrowser.UrlGet(SteamCommunityURL + "/my/inventory", Cookie).ConfigureAwait(false);
|
bool result = false;
|
||||||
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && !result; i++) {
|
||||||
|
result = await WebBrowser.UrlHead(request).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
private async Task<bool?> IsLoggedIn() {
|
||||||
|
string request = SteamCommunityURL + "/my/profile";
|
||||||
|
|
||||||
|
Uri uri = null;
|
||||||
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (uri == null); i++) {
|
||||||
|
uri = await WebBrowser.UrlHeadToUri(request).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<bool> AcceptGift(ulong gid) {
|
if (uri != null) {
|
||||||
if (gid == 0) {
|
return !uri.AbsolutePath.StartsWith("/login", StringComparison.Ordinal);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
string sessionID;
|
|
||||||
if (!Cookie.TryGetValue("sessionid", out sessionID)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
string request = SteamCommunityURL + "/gifts/" + gid + "/acceptunpack";
|
|
||||||
Dictionary<string, string> data = new Dictionary<string, string>(1) {
|
|
||||||
{ "sessionid", sessionID }
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
|
||||||
response = await WebBrowser.UrlPost(request, data, Cookie).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response == null) {
|
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<bool> RefreshSessionIfNeeded() {
|
||||||
|
if (DateTime.Now.Subtract(LastSessionRefreshCheck).TotalSeconds < MinSessionTTL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (DateTime.Now.Subtract(LastSessionRefreshCheck).TotalSeconds < MinSessionTTL) {
|
||||||
|
SessionSemaphore.Release();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
bool? isLoggedIn = await IsLoggedIn().ConfigureAwait(false);
|
||||||
|
if (isLoggedIn.GetValueOrDefault(true)) {
|
||||||
|
result = true;
|
||||||
|
LastSessionRefreshCheck = DateTime.Now;
|
||||||
|
} else {
|
||||||
|
Logging.LogGenericInfo("Refreshing our session!", Bot.BotName);
|
||||||
|
result = await Bot.RefreshSession().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionSemaphore.Release();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<bool> UnlockParentalAccount(string parentalPin) {
|
private async Task<bool> UnlockParentalAccount(string parentalPin) {
|
||||||
if (string.IsNullOrEmpty(parentalPin) || parentalPin.Equals("0")) {
|
if (string.IsNullOrEmpty(parentalPin) || parentalPin.Equals("0")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LogGenericInfo("Unlocking parental account...", Bot.BotName);
|
Logging.LogGenericInfo("Unlocking parental account...", Bot.BotName);
|
||||||
|
|
||||||
|
string request = SteamCommunityURL + "/parental/ajaxunlock";
|
||||||
Dictionary<string, string> data = new Dictionary<string, string>(1) {
|
Dictionary<string, string> data = new Dictionary<string, string>(1) {
|
||||||
{ "pin", parentalPin }
|
{ "pin", parentalPin }
|
||||||
};
|
};
|
||||||
|
|
||||||
string referer = SteamCommunityURL;
|
bool result = false;
|
||||||
string request = referer + "/parental/ajaxunlock";
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && !result; i++) {
|
||||||
|
result = await WebBrowser.UrlPost(request, data, SteamCommunityURL).ConfigureAwait(false);
|
||||||
HttpResponseMessage response = null;
|
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) {
|
|
||||||
response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null) {
|
if (!result) {
|
||||||
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<string> setCookieValues;
|
|
||||||
if (!response.Headers.TryGetValues("Set-Cookie", out setCookieValues)) {
|
|
||||||
Logging.LogNullError("setCookieValues", Bot.BotName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string setCookieValue in setCookieValues) {
|
|
||||||
if (!setCookieValue.Contains("steamparental=")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=", StringComparison.Ordinal) + 14);
|
|
||||||
|
|
||||||
int index = setCookie.IndexOf(';');
|
|
||||||
if (index > 0) {
|
|
||||||
setCookie = setCookie.Substring(0, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
Cookie["steamparental"] = setCookie;
|
|
||||||
Logging.LogGenericInfo("Success!", Bot.BotName);
|
Logging.LogGenericInfo("Success!", Bot.BotName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LogGenericWarning("Failed to unlock parental account!", Bot.BotName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,8 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
|
// ReSharper disable once ClassCannotBeInstantiated
|
||||||
|
// ReSharper disable once ClassNeverInstantiated.Global
|
||||||
internal sealed class BotConfig {
|
internal sealed class BotConfig {
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal bool Enabled { get; private set; } = false;
|
internal bool Enabled { get; private set; } = false;
|
||||||
@@ -36,10 +38,10 @@ namespace ArchiSteamFarm {
|
|||||||
internal bool StartOnLaunch { get; private set; } = true;
|
internal bool StartOnLaunch { get; private set; } = true;
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
internal string SteamLogin { get; set; } = null;
|
internal string SteamLogin { get; set; }
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
internal string SteamPassword { get; set; } = null;
|
internal string SteamPassword { get; set; }
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
internal string SteamParentalPIN { get; set; } = "0";
|
internal string SteamParentalPIN { get; set; } = "0";
|
||||||
@@ -68,6 +70,9 @@ namespace ArchiSteamFarm {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal bool AcceptGifts { get; private set; } = false;
|
internal bool AcceptGifts { get; private set; } = false;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
internal bool SteamTradeMatcher { get; private set; } = false;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal bool ForwardKeysToOtherBots { get; private set; } = false;
|
internal bool ForwardKeysToOtherBots { get; private set; } = false;
|
||||||
|
|
||||||
@@ -96,7 +101,7 @@ namespace ArchiSteamFarm {
|
|||||||
internal string CustomGamePlayedWhileIdle { get; private set; } = null;
|
internal string CustomGamePlayedWhileIdle { get; private set; } = null;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal HashSet<uint> GamesPlayedWhileIdle { get; private set; } = new HashSet<uint>() { 0 };
|
internal HashSet<uint> GamesPlayedWhileIdle { get; private set; } = new HashSet<uint> { 0 };
|
||||||
|
|
||||||
|
|
||||||
internal static BotConfig Load(string filePath) {
|
internal static BotConfig Load(string filePath) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SteamAuth;
|
using SteamAuth;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
@@ -92,11 +93,16 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
// This constructor is used when creating new database
|
// This constructor is used when creating new database
|
||||||
private BotDatabase(string filePath) {
|
private BotDatabase(string filePath) {
|
||||||
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
FilePath = filePath;
|
FilePath = filePath;
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This constructor is used only by deserializer
|
// This constructor is used only by deserializer
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
private BotDatabase() { }
|
private BotDatabase() { }
|
||||||
|
|
||||||
internal void Save() {
|
internal void Save() {
|
||||||
|
|||||||
@@ -35,10 +35,10 @@ using System.Threading.Tasks;
|
|||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal sealed class CardsFarmer {
|
internal sealed class CardsFarmer {
|
||||||
internal readonly ConcurrentDictionary<uint, float> GamesToFarm = new ConcurrentDictionary<uint, float>();
|
internal readonly ConcurrentDictionary<uint, float> GamesToFarm = new ConcurrentDictionary<uint, float>();
|
||||||
internal readonly HashSet<uint> CurrentGamesFarming = new HashSet<uint>();
|
internal readonly ConcurrentHashSet<uint> CurrentGamesFarming = new ConcurrentHashSet<uint>();
|
||||||
|
|
||||||
private readonly ManualResetEvent FarmResetEvent = new ManualResetEvent(false);
|
private readonly ManualResetEventSlim FarmResetEvent = new ManualResetEventSlim(false);
|
||||||
private readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1);
|
private readonly SemaphoreSlim FarmingSemaphore = new SemaphoreSlim(1);
|
||||||
private readonly Bot Bot;
|
private readonly Bot Bot;
|
||||||
private readonly Timer Timer;
|
private readonly Timer Timer;
|
||||||
|
|
||||||
@@ -48,12 +48,12 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
internal CardsFarmer(Bot bot) {
|
internal CardsFarmer(Bot bot) {
|
||||||
if (bot == null) {
|
if (bot == null) {
|
||||||
return;
|
throw new ArgumentNullException(nameof(bot));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bot = bot;
|
Bot = bot;
|
||||||
|
|
||||||
if (Timer == null && Program.GlobalConfig.IdleFarmingPeriod > 0) {
|
if ((Timer == null) && (Program.GlobalConfig.IdleFarmingPeriod > 0)) {
|
||||||
Timer = new Timer(
|
Timer = new Timer(
|
||||||
async e => await CheckGamesForFarming().ConfigureAwait(false),
|
async e => await CheckGamesForFarming().ConfigureAwait(false),
|
||||||
null,
|
null,
|
||||||
@@ -84,25 +84,25 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Semaphore.WaitAsync().ConfigureAwait(false);
|
await FarmingSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
if (NowFarming || ManualMode) {
|
if (NowFarming || ManualMode) {
|
||||||
Semaphore.Release(); // We have nothing to do, don't forget to release semaphore
|
FarmingSemaphore.Release(); // We have nothing to do, don't forget to release semaphore
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await IsAnythingToFarm().ConfigureAwait(false)) {
|
if (!await IsAnythingToFarm().ConfigureAwait(false)) {
|
||||||
Semaphore.Release(); // We have nothing to do, don't forget to release semaphore
|
FarmingSemaphore.Release(); // We have nothing to do, don't forget to release semaphore
|
||||||
Logging.LogGenericInfo("We don't have anything to farm on this account!", Bot.BotName);
|
Logging.LogGenericInfo("We don't have anything to farm on this account!", Bot.BotName);
|
||||||
|
await Bot.OnFarmingFinished(false).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games to farm on this account...", Bot.BotName);
|
Logging.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games to farm on this account...", Bot.BotName);
|
||||||
NowFarming = true;
|
NowFarming = true;
|
||||||
Semaphore.Release(); // From this point we allow other calls to shut us down
|
FarmingSemaphore.Release(); // From this point we allow other calls to shut us down
|
||||||
|
|
||||||
bool farmedSomething = false;
|
|
||||||
|
|
||||||
|
do {
|
||||||
// Now the algorithm used for farming depends on whether account is restricted or not
|
// Now the algorithm used for farming depends on whether account is restricted or not
|
||||||
if (Bot.BotConfig.CardDropsRestricted) { // If we have restricted card drops, we use complex algorithm
|
if (Bot.BotConfig.CardDropsRestricted) { // If we have restricted card drops, we use complex algorithm
|
||||||
Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName);
|
Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName);
|
||||||
@@ -112,7 +112,6 @@ namespace ArchiSteamFarm {
|
|||||||
while (gamesToFarmSolo.Count > 0) {
|
while (gamesToFarmSolo.Count > 0) {
|
||||||
uint appID = gamesToFarmSolo.First();
|
uint appID = gamesToFarmSolo.First();
|
||||||
if (await FarmSolo(appID).ConfigureAwait(false)) {
|
if (await FarmSolo(appID).ConfigureAwait(false)) {
|
||||||
farmedSomething = true;
|
|
||||||
gamesToFarmSolo.Remove(appID);
|
gamesToFarmSolo.Remove(appID);
|
||||||
gamesToFarmSolo.TrimExcess();
|
gamesToFarmSolo.TrimExcess();
|
||||||
} else {
|
} else {
|
||||||
@@ -134,27 +133,20 @@ namespace ArchiSteamFarm {
|
|||||||
while (GamesToFarm.Count > 0) {
|
while (GamesToFarm.Count > 0) {
|
||||||
uint appID = GamesToFarm.Keys.FirstOrDefault();
|
uint appID = GamesToFarm.Keys.FirstOrDefault();
|
||||||
if (await FarmSolo(appID).ConfigureAwait(false)) {
|
if (await FarmSolo(appID).ConfigureAwait(false)) {
|
||||||
farmedSomething = true;
|
continue;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
NowFarming = false;
|
NowFarming = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (await IsAnythingToFarm().ConfigureAwait(false));
|
||||||
|
|
||||||
CurrentGamesFarming.Clear();
|
CurrentGamesFarming.ClearAndTrim();
|
||||||
CurrentGamesFarming.TrimExcess();
|
|
||||||
NowFarming = false;
|
NowFarming = false;
|
||||||
|
|
||||||
// We finished our queue for now, make sure that everything is indeed farmed before proceeding further
|
|
||||||
// Some games could be added in the meantime
|
|
||||||
if (await IsAnythingToFarm().ConfigureAwait(false)) {
|
|
||||||
StartFarming().Forget();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logging.LogGenericInfo("Farming finished!", Bot.BotName);
|
Logging.LogGenericInfo("Farming finished!", Bot.BotName);
|
||||||
await Bot.OnFarmingFinished(farmedSomething).ConfigureAwait(false);
|
await Bot.OnFarmingFinished(true).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task StopFarming() {
|
internal async Task StopFarming() {
|
||||||
@@ -162,10 +154,10 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Semaphore.WaitAsync().ConfigureAwait(false);
|
await FarmingSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
if (!NowFarming) {
|
if (!NowFarming) {
|
||||||
Semaphore.Release();
|
FarmingSemaphore.Release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +165,7 @@ namespace ArchiSteamFarm {
|
|||||||
FarmResetEvent.Set();
|
FarmResetEvent.Set();
|
||||||
|
|
||||||
Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName);
|
Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName);
|
||||||
for (byte i = 0; i < Program.GlobalConfig.HttpTimeout && NowFarming; i++) {
|
for (byte i = 0; (i < Program.GlobalConfig.HttpTimeout) && NowFarming; i++) {
|
||||||
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +175,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
FarmResetEvent.Reset();
|
FarmResetEvent.Reset();
|
||||||
Logging.LogGenericInfo("Farming stopped!", Bot.BotName);
|
Logging.LogGenericInfo("Farming stopped!", Bot.BotName);
|
||||||
Semaphore.Release();
|
FarmingSemaphore.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task RestartFarming() {
|
internal async Task RestartFarming() {
|
||||||
@@ -197,20 +189,14 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HashSet<uint> result = new HashSet<uint>();
|
HashSet<uint> result = new HashSet<uint>();
|
||||||
foreach (KeyValuePair<uint, float> keyValue in gamesToFarm) {
|
foreach (KeyValuePair<uint, float> keyValue in gamesToFarm.Where(keyValue => keyValue.Value >= 2)) {
|
||||||
if (keyValue.Value >= 2) {
|
|
||||||
result.Add(keyValue.Key);
|
result.Add(keyValue.Key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> IsAnythingToFarm() {
|
private async Task<bool> IsAnythingToFarm() {
|
||||||
if (NowFarming) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logging.LogGenericInfo("Checking badges...", Bot.BotName);
|
Logging.LogGenericInfo("Checking badges...", Bot.BotName);
|
||||||
|
|
||||||
// Find the number of badge pages
|
// Find the number of badge pages
|
||||||
@@ -223,7 +209,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
byte maxPages = 1;
|
byte maxPages = 1;
|
||||||
HtmlNodeCollection htmlNodeCollection = htmlDocument.DocumentNode.SelectNodes("//a[@class='pagelink']");
|
HtmlNodeCollection htmlNodeCollection = htmlDocument.DocumentNode.SelectNodes("//a[@class='pagelink']");
|
||||||
if (htmlNodeCollection != null && htmlNodeCollection.Count > 0) {
|
if ((htmlNodeCollection != null) && (htmlNodeCollection.Count > 0)) {
|
||||||
HtmlNode htmlNode = htmlNodeCollection[htmlNodeCollection.Count - 1];
|
HtmlNode htmlNode = htmlNodeCollection[htmlNodeCollection.Count - 1];
|
||||||
string lastPage = htmlNode.InnerText;
|
string lastPage = htmlNode.InnerText;
|
||||||
if (!string.IsNullOrEmpty(lastPage)) {
|
if (!string.IsNullOrEmpty(lastPage)) {
|
||||||
@@ -237,16 +223,19 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
CheckPage(htmlDocument);
|
CheckPage(htmlDocument);
|
||||||
|
|
||||||
if (maxPages > 1) {
|
if (maxPages <= 1) {
|
||||||
|
return GamesToFarm.Count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
Logging.LogGenericInfo("Checking other pages...", Bot.BotName);
|
Logging.LogGenericInfo("Checking other pages...", Bot.BotName);
|
||||||
|
|
||||||
List<Task> tasks = new List<Task>(maxPages - 1);
|
List<Task> tasks = new List<Task>(maxPages - 1);
|
||||||
for (byte page = 2; page <= maxPages; page++) {
|
for (byte page = 2; page <= maxPages; page++) {
|
||||||
byte currentPage = page; // We need a copy of variable being passed when in for loops, as loop will proceed before task is launched
|
byte currentPage = page; // We need a copy of variable being passed when in for loops, as loop will proceed before task is launched
|
||||||
tasks.Add(CheckPage(currentPage));
|
tasks.Add(CheckPage(currentPage));
|
||||||
}
|
}
|
||||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
return GamesToFarm.Count > 0;
|
return GamesToFarm.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,21 +366,15 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (maxHour >= 2) {
|
if (maxHour >= 2) {
|
||||||
CurrentGamesFarming.Clear();
|
CurrentGamesFarming.ClearAndTrim();
|
||||||
CurrentGamesFarming.TrimExcess();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LogGenericInfo("Now farming: " + string.Join(", ", CurrentGamesFarming), Bot.BotName);
|
Logging.LogGenericInfo("Now farming: " + string.Join(", ", CurrentGamesFarming), Bot.BotName);
|
||||||
if (FarmHours(maxHour, CurrentGamesFarming)) {
|
|
||||||
CurrentGamesFarming.Clear();
|
bool result = FarmHours(maxHour, CurrentGamesFarming);
|
||||||
CurrentGamesFarming.TrimExcess();
|
CurrentGamesFarming.ClearAndTrim();
|
||||||
return true;
|
return result;
|
||||||
} else {
|
|
||||||
CurrentGamesFarming.Clear();
|
|
||||||
CurrentGamesFarming.TrimExcess();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> FarmSolo(uint appID) {
|
private async Task<bool> FarmSolo(uint appID) {
|
||||||
@@ -402,20 +385,22 @@ namespace ArchiSteamFarm {
|
|||||||
CurrentGamesFarming.Add(appID);
|
CurrentGamesFarming.Add(appID);
|
||||||
|
|
||||||
Logging.LogGenericInfo("Now farming: " + appID, Bot.BotName);
|
Logging.LogGenericInfo("Now farming: " + appID, Bot.BotName);
|
||||||
if (await Farm(appID).ConfigureAwait(false)) {
|
|
||||||
CurrentGamesFarming.Clear();
|
bool result = await Farm(appID).ConfigureAwait(false);
|
||||||
CurrentGamesFarming.TrimExcess();
|
CurrentGamesFarming.ClearAndTrim();
|
||||||
float hours;
|
|
||||||
if (GamesToFarm.TryRemove(appID, out hours)) {
|
if (!result) {
|
||||||
TimeSpan timeSpan = TimeSpan.FromHours(hours);
|
|
||||||
Logging.LogGenericInfo("Done farming: " + appID + " after " + timeSpan.ToString(@"hh\:mm") + " hours of playtime!", Bot.BotName);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
CurrentGamesFarming.Clear();
|
|
||||||
CurrentGamesFarming.TrimExcess();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float hours;
|
||||||
|
if (!GamesToFarm.TryRemove(appID, out hours)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeSpan timeSpan = TimeSpan.FromHours(hours);
|
||||||
|
Logging.LogGenericInfo("Done farming: " + appID + " after " + timeSpan.ToString(@"hh\:mm") + " hours of playtime!", Bot.BotName);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> Farm(uint appID) {
|
private async Task<bool> Farm(uint appID) {
|
||||||
@@ -428,8 +413,8 @@ namespace ArchiSteamFarm {
|
|||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
bool? keepFarming = await ShouldFarm(appID).ConfigureAwait(false);
|
bool? keepFarming = await ShouldFarm(appID).ConfigureAwait(false);
|
||||||
for (ushort farmingTime = 0; farmingTime <= 60 * Program.GlobalConfig.MaxFarmingTime && keepFarming.GetValueOrDefault(true); farmingTime += Program.GlobalConfig.FarmingDelay) {
|
for (ushort farmingTime = 0; (farmingTime <= 60 * Program.GlobalConfig.MaxFarmingTime) && keepFarming.GetValueOrDefault(true); farmingTime += Program.GlobalConfig.FarmingDelay) {
|
||||||
if (FarmResetEvent.WaitOne(60 * 1000 * Program.GlobalConfig.FarmingDelay)) {
|
if (FarmResetEvent.Wait(60 * 1000 * Program.GlobalConfig.FarmingDelay)) {
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -447,8 +432,8 @@ namespace ArchiSteamFarm {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool FarmHours(float maxHour, HashSet<uint> appIDs) {
|
private bool FarmHours(float maxHour, ConcurrentHashSet<uint> appIDs) {
|
||||||
if (maxHour < 0 || appIDs == null || appIDs.Count == 0) {
|
if ((maxHour < 0) || (appIDs == null) || (appIDs.Count == 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +445,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
while (maxHour < 2) {
|
while (maxHour < 2) {
|
||||||
if (FarmResetEvent.WaitOne(60 * 1000 * Program.GlobalConfig.FarmingDelay)) {
|
if (FarmResetEvent.Wait(60 * 1000 * Program.GlobalConfig.FarmingDelay)) {
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,45 +22,37 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using SteamKit2;
|
|
||||||
using SteamKit2.Internal;
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal sealed class CMsgClientClanInviteAction : ISteamSerializableMessage {
|
internal sealed class ConcurrentEnumerator<T> : IEnumerator<T> {
|
||||||
internal ulong GroupID { get; set; } = 0;
|
public T Current => Enumerator.Current;
|
||||||
internal bool AcceptInvite { get; set; } = true;
|
|
||||||
|
|
||||||
EMsg ISteamSerializableMessage.GetEMsg() {
|
object IEnumerator.Current => Current;
|
||||||
return EMsg.ClientAcknowledgeClanInvite;
|
|
||||||
|
private readonly IEnumerator<T> Enumerator;
|
||||||
|
private readonly ReaderWriterLockSlim Lock;
|
||||||
|
|
||||||
|
internal ConcurrentEnumerator(ICollection<T> collection, ReaderWriterLockSlim @lock) {
|
||||||
|
if ((collection == null) || (@lock == null)) {
|
||||||
|
throw new ArgumentNullException(nameof(collection) + " || " + nameof(@lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISteamSerializable.Serialize(Stream stream) {
|
@lock.EnterReadLock();
|
||||||
if (stream == null) {
|
|
||||||
return;
|
Lock = @lock;
|
||||||
|
Enumerator = collection.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
public bool MoveNext() => Enumerator.MoveNext();
|
||||||
BinaryWriter binaryWriter = new BinaryWriter(stream);
|
public void Reset() => Enumerator.Reset();
|
||||||
binaryWriter.Write(GroupID);
|
|
||||||
binaryWriter.Write(AcceptInvite);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logging.LogGenericException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ISteamSerializable.Deserialize(Stream stream) {
|
public void Dispose() {
|
||||||
if (stream == null) {
|
if (Lock != null) {
|
||||||
return;
|
Lock.ExitReadLock();
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
BinaryReader binaryReader = new BinaryReader(stream);
|
|
||||||
GroupID = binaryReader.ReadUInt64();
|
|
||||||
AcceptInvite = binaryReader.ReadBoolean();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logging.LogGenericException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
123
ArchiSteamFarm/ConcurrentHashSet.cs
Normal file
123
ArchiSteamFarm/ConcurrentHashSet.cs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
_ _ _ ____ _ _____
|
||||||
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||||
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||||
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
|
|
||||||
|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
|
||||||
|
Contact: JustArchi@JustArchi.net
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace ArchiSteamFarm {
|
||||||
|
internal sealed class ConcurrentHashSet<T> : ICollection<T>, IDisposable {
|
||||||
|
private readonly HashSet<T> HashSet = new HashSet<T>();
|
||||||
|
private readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
|
||||||
|
|
||||||
|
public bool IsReadOnly => false;
|
||||||
|
public IEnumerator<T> GetEnumerator() => new ConcurrentEnumerator<T>(HashSet, Lock);
|
||||||
|
|
||||||
|
public int Count {
|
||||||
|
get {
|
||||||
|
Lock.EnterReadLock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return HashSet.Count;
|
||||||
|
} finally {
|
||||||
|
Lock.ExitReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
|
||||||
|
public bool Add(T item) {
|
||||||
|
Lock.EnterWriteLock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return HashSet.Add(item);
|
||||||
|
} finally {
|
||||||
|
Lock.ExitWriteLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear() {
|
||||||
|
Lock.EnterWriteLock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
HashSet.Clear();
|
||||||
|
} finally {
|
||||||
|
Lock.ExitWriteLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearAndTrim() {
|
||||||
|
Lock.EnterWriteLock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
HashSet.Clear();
|
||||||
|
HashSet.TrimExcess();
|
||||||
|
} finally {
|
||||||
|
Lock.ExitWriteLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains(T item) {
|
||||||
|
Lock.EnterReadLock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return HashSet.Contains(item);
|
||||||
|
} finally {
|
||||||
|
Lock.ExitReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Remove(T item) {
|
||||||
|
Lock.EnterWriteLock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return HashSet.Remove(item);
|
||||||
|
} finally {
|
||||||
|
Lock.ExitWriteLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
if (Lock != null) {
|
||||||
|
Lock.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CopyTo(T[] array, int arrayIndex) {
|
||||||
|
Lock.EnterReadLock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
HashSet.CopyTo(array, arrayIndex);
|
||||||
|
} finally {
|
||||||
|
Lock.ExitReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ICollection<T>.Add(T item) => Add(item);
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,19 +24,20 @@
|
|||||||
|
|
||||||
using SteamKit2;
|
using SteamKit2;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal static class Debugging {
|
internal static class Debugging {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
[SuppressMessage("ReSharper", "ConvertToConstant.Global")]
|
||||||
internal static readonly bool IsDebugBuild = true;
|
internal static readonly bool IsDebugBuild = true;
|
||||||
#else
|
#else
|
||||||
|
[SuppressMessage("ReSharper", "ConvertToConstant.Global")]
|
||||||
internal static readonly bool IsDebugBuild = false;
|
internal static readonly bool IsDebugBuild = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal static bool IsReleaseBuild => !IsDebugBuild;
|
internal static bool NetHookAlreadyInitialized { get; set; }
|
||||||
|
|
||||||
internal static bool NetHookAlreadyInitialized { get; set; } = false;
|
|
||||||
|
|
||||||
internal sealed class DebugListener : IDebugListener {
|
internal sealed class DebugListener : IDebugListener {
|
||||||
private readonly string FilePath;
|
private readonly string FilePath;
|
||||||
|
|||||||
@@ -25,11 +25,14 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
|
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated"), SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
|
||||||
internal sealed class GlobalConfig {
|
internal sealed class GlobalConfig {
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal enum EUpdateChannel : byte {
|
internal enum EUpdateChannel : byte {
|
||||||
Unknown,
|
Unknown,
|
||||||
Stable,
|
Stable,
|
||||||
@@ -49,9 +52,15 @@ namespace ArchiSteamFarm {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal bool Debug { get; private set; } = false;
|
internal bool Debug { get; private set; } = false;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
internal bool Headless { get; private set; } = false;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal bool AutoUpdates { get; private set; } = true;
|
internal bool AutoUpdates { get; private set; } = true;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
internal bool AutoRestart { get; private set; } = true;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal EUpdateChannel UpdateChannel { get; private set; } = EUpdateChannel.Stable;
|
internal EUpdateChannel UpdateChannel { get; private set; } = EUpdateChannel.Stable;
|
||||||
|
|
||||||
@@ -104,8 +113,11 @@ namespace ArchiSteamFarm {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal HashSet<uint> Blacklist { get; private set; } = new HashSet<uint>(GlobalBlacklist);
|
internal HashSet<uint> Blacklist { get; private set; } = new HashSet<uint>(GlobalBlacklist);
|
||||||
|
|
||||||
internal static GlobalConfig Load() {
|
internal static GlobalConfig Load(string filePath) {
|
||||||
string filePath = Path.Combine(Program.ConfigDirectory, Program.GlobalConfigFile);
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!File.Exists(filePath)) {
|
if (!File.Exists(filePath)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -151,10 +163,12 @@ namespace ArchiSteamFarm {
|
|||||||
globalConfig.HttpTimeout = DefaultHttpTimeout;
|
globalConfig.HttpTimeout = DefaultHttpTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalConfig.WCFPort == 0) {
|
if (globalConfig.WCFPort != 0) {
|
||||||
|
return globalConfig;
|
||||||
|
}
|
||||||
|
|
||||||
Logging.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort + ". Value of " + DefaultWCFPort + " will be used instead");
|
Logging.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort + ". Value of " + DefaultWCFPort + " will be used instead");
|
||||||
globalConfig.WCFPort = DefaultWCFPort;
|
globalConfig.WCFPort = DefaultWCFPort;
|
||||||
}
|
|
||||||
|
|
||||||
return globalConfig;
|
return globalConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,11 @@
|
|||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal sealed class GlobalDatabase {
|
internal sealed class GlobalDatabase {
|
||||||
private static readonly string FilePath = Path.Combine(Program.ConfigDirectory, Program.GlobalDatabaseFile);
|
|
||||||
|
|
||||||
internal uint CellID {
|
internal uint CellID {
|
||||||
get {
|
get {
|
||||||
return _CellID;
|
return _CellID;
|
||||||
@@ -47,23 +46,45 @@ namespace ArchiSteamFarm {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
private uint _CellID;
|
private uint _CellID;
|
||||||
|
|
||||||
internal static GlobalDatabase Load() {
|
private string FilePath;
|
||||||
if (!File.Exists(FilePath)) {
|
|
||||||
return new GlobalDatabase();
|
internal static GlobalDatabase Load(string filePath) {
|
||||||
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(filePath)) {
|
||||||
|
return new GlobalDatabase(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalDatabase globalDatabase;
|
GlobalDatabase globalDatabase;
|
||||||
try {
|
try {
|
||||||
globalDatabase = JsonConvert.DeserializeObject<GlobalDatabase>(File.ReadAllText(FilePath));
|
globalDatabase = JsonConvert.DeserializeObject<GlobalDatabase>(File.ReadAllText(filePath));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (globalDatabase == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
globalDatabase.FilePath = filePath;
|
||||||
return globalDatabase;
|
return globalDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This constructor is used when creating new database
|
||||||
|
private GlobalDatabase(string filePath) {
|
||||||
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath = filePath;
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
// This constructor is used only by deserializer
|
// This constructor is used only by deserializer
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
private GlobalDatabase() { }
|
private GlobalDatabase() { }
|
||||||
|
|
||||||
private void Save() {
|
private void Save() {
|
||||||
|
|||||||
@@ -22,11 +22,14 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm.JSON {
|
||||||
internal static class GitHub {
|
internal static class GitHub {
|
||||||
|
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global"), SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")]
|
||||||
|
internal sealed class ReleaseResponse {
|
||||||
internal sealed class Asset {
|
internal sealed class Asset {
|
||||||
[JsonProperty(PropertyName = "name", Required = Required.Always)]
|
[JsonProperty(PropertyName = "name", Required = Required.Always)]
|
||||||
internal string Name { get; private set; }
|
internal string Name { get; private set; }
|
||||||
@@ -35,7 +38,6 @@ namespace ArchiSteamFarm {
|
|||||||
internal string DownloadURL { get; private set; }
|
internal string DownloadURL { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class ReleaseResponse {
|
|
||||||
[JsonProperty(PropertyName = "tag_name", Required = Required.Always)]
|
[JsonProperty(PropertyName = "tag_name", Required = Required.Always)]
|
||||||
internal string Tag { get; private set; }
|
internal string Tag { get; private set; }
|
||||||
|
|
||||||
|
|||||||
@@ -22,46 +22,176 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SteamKit2;
|
using SteamKit2;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm.JSON {
|
||||||
internal static class Steam {
|
internal static class Steam {
|
||||||
internal sealed class Item {
|
internal sealed class Item { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset
|
||||||
// REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset
|
internal const ushort SteamAppID = 753;
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
internal const byte SteamContextID = 6;
|
||||||
internal string appid { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
internal enum EType : byte {
|
||||||
internal string contextid { get; set; }
|
Unknown,
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
BoosterPack,
|
||||||
internal string assetid { get; set; }
|
Coupon,
|
||||||
|
Gift,
|
||||||
|
SteamGems,
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
Emoticon,
|
||||||
internal string id {
|
FoilTradingCard,
|
||||||
get { return assetid; }
|
ProfileBackground,
|
||||||
set { assetid = value; }
|
TradingCard
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(Required = Required.AllowNull)]
|
internal uint AppID { get; set; }
|
||||||
internal string classid { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(Required = Required.AllowNull)]
|
[JsonProperty(PropertyName = "appid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
internal string instanceid { get; set; }
|
private string AppIDString {
|
||||||
|
get {
|
||||||
[JsonProperty(Required = Required.Always)]
|
return AppID.ToString();
|
||||||
internal string amount { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class ItemList {
|
set {
|
||||||
[JsonProperty(Required = Required.Always)]
|
if (string.IsNullOrEmpty(value)) {
|
||||||
internal List<Steam.Item> assets { get; } = new List<Steam.Item>();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class TradeOffer {
|
uint result;
|
||||||
// REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer
|
if (!uint.TryParse(value, out result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppID = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal ulong ContextID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "contextid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
|
private string ContextIDString {
|
||||||
|
get {
|
||||||
|
return ContextID.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
if (string.IsNullOrEmpty(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong result;
|
||||||
|
if (!ulong.TryParse(value, out result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextID = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal ulong AssetID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "assetid", Required = Required.DisallowNull)]
|
||||||
|
private string AssetIDString {
|
||||||
|
get {
|
||||||
|
return AssetID.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
if (string.IsNullOrEmpty(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong result;
|
||||||
|
if (!ulong.TryParse(value, out result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetID = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "id", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
|
private string ID {
|
||||||
|
get { return AssetIDString; }
|
||||||
|
set { AssetIDString = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal ulong ClassID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "classid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
|
private string ClassIDString {
|
||||||
|
get {
|
||||||
|
return ClassID.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
if (string.IsNullOrEmpty(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong result;
|
||||||
|
if (!ulong.TryParse(value, out result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassID = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal ulong InstanceID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "instanceid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
|
private string InstanceIDString {
|
||||||
|
get {
|
||||||
|
return InstanceID.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
if (string.IsNullOrEmpty(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong result;
|
||||||
|
if (!ulong.TryParse(value, out result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InstanceID = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal uint Amount { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "amount", Required = Required.Always), SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
|
private string AmountString {
|
||||||
|
get {
|
||||||
|
return Amount.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
if (string.IsNullOrEmpty(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint result;
|
||||||
|
if (!uint.TryParse(value, out result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Amount = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal uint RealAppID { get; set; }
|
||||||
|
internal EType Type { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class TradeOffer { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal enum ETradeOfferState : byte {
|
internal enum ETradeOfferState : byte {
|
||||||
Unknown,
|
Unknown,
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -77,46 +207,119 @@ namespace ArchiSteamFarm {
|
|||||||
OnHold
|
OnHold
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
internal ulong TradeOfferID { get; set; }
|
||||||
internal string tradeofferid { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(PropertyName = "tradeofferid", Required = Required.Always), SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
internal uint accountid_other { get; set; }
|
private string TradeOfferIDString {
|
||||||
|
get {
|
||||||
|
return TradeOfferID.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
set {
|
||||||
internal ETradeOfferState trade_offer_state { get; set; }
|
if (string.IsNullOrEmpty(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
ulong result;
|
||||||
internal List<Steam.Item> items_to_give { get; } = new List<Steam.Item>();
|
if (!ulong.TryParse(value, out result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
TradeOfferID = result;
|
||||||
internal List<Steam.Item> items_to_receive { get; } = new List<Steam.Item>();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "accountid_other", Required = Required.Always)]
|
||||||
|
internal uint OtherSteamID3 { private get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "trade_offer_state", Required = Required.Always)]
|
||||||
|
internal ETradeOfferState State { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "items_to_give", Required = Required.Always)]
|
||||||
|
internal HashSet<Item> ItemsToGive { get; } = new HashSet<Item>();
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "items_to_receive", Required = Required.Always)]
|
||||||
|
internal HashSet<Item> ItemsToReceive { get; } = new HashSet<Item>();
|
||||||
|
|
||||||
// Extra
|
// Extra
|
||||||
private ulong _OtherSteamID64 = 0;
|
internal ulong OtherSteamID64 => OtherSteamID3 == 0 ? 0 : new SteamID(OtherSteamID3, EUniverse.Public, EAccountType.Individual);
|
||||||
internal ulong OtherSteamID64 {
|
|
||||||
get {
|
|
||||||
if (_OtherSteamID64 == 0 && accountid_other != 0) {
|
|
||||||
_OtherSteamID64 = new SteamID(accountid_other, EUniverse.Public, EAccountType.Individual).ConvertToUInt64();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _OtherSteamID64;
|
internal bool IsSteamCardsOnlyTradeForUs() => ItemsToGive.All(item => (item.AppID == Item.SteamAppID) && (item.ContextID == Item.SteamContextID) && ((item.Type == Item.EType.FoilTradingCard) || (item.Type == Item.EType.TradingCard)));
|
||||||
|
|
||||||
|
internal bool IsPotentiallyDupesTradeForUs() {
|
||||||
|
Dictionary<uint, Dictionary<Item.EType, uint>> itemsToGivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>();
|
||||||
|
foreach (Item item in ItemsToGive) {
|
||||||
|
Dictionary<Item.EType, uint> itemsPerType;
|
||||||
|
if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) {
|
||||||
|
itemsPerType = new Dictionary<Item.EType, uint> { [item.Type] = item.Amount };
|
||||||
|
itemsToGivePerGame[item.RealAppID] = itemsPerType;
|
||||||
|
} else {
|
||||||
|
uint amount;
|
||||||
|
if (itemsPerType.TryGetValue(item.Type, out amount)) {
|
||||||
|
itemsPerType[item.Type] = amount + item.Amount;
|
||||||
|
} else {
|
||||||
|
itemsPerType[item.Type] = item.Amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dictionary<uint, Dictionary<Item.EType, uint>> itemsToReceivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>();
|
||||||
|
foreach (Item item in ItemsToReceive) {
|
||||||
|
Dictionary<Item.EType, uint> itemsPerType;
|
||||||
|
if (!itemsToReceivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) {
|
||||||
|
itemsPerType = new Dictionary<Item.EType, uint> { [item.Type] = item.Amount };
|
||||||
|
itemsToReceivePerGame[item.RealAppID] = itemsPerType;
|
||||||
|
} else {
|
||||||
|
uint amount;
|
||||||
|
if (itemsPerType.TryGetValue(item.Type, out amount)) {
|
||||||
|
itemsPerType[item.Type] = amount + item.Amount;
|
||||||
|
} else {
|
||||||
|
itemsPerType[item.Type] = item.Amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that amount of items to give is at least amount of items to receive (per game and per type)
|
||||||
|
foreach (KeyValuePair<uint, Dictionary<Item.EType, uint>> itemsPerGame in itemsToGivePerGame) {
|
||||||
|
Dictionary<Item.EType, uint> otherItemsPerType;
|
||||||
|
if (!itemsToReceivePerGame.TryGetValue(itemsPerGame.Key, out otherItemsPerType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (KeyValuePair<Item.EType, uint> itemsPerType in itemsPerGame.Value) {
|
||||||
|
uint otherAmount;
|
||||||
|
if (!otherItemsPerType.TryGetValue(itemsPerType.Key, out otherAmount)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemsPerType.Value > otherAmount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal sealed class TradeOfferRequest {
|
internal sealed class TradeOfferRequest {
|
||||||
[JsonProperty(Required = Required.Always)]
|
internal sealed class ItemList {
|
||||||
internal bool newversion { get; } = true;
|
[JsonProperty(PropertyName = "assets", Required = Required.Always)]
|
||||||
|
internal HashSet<Item> Assets { get; } = new HashSet<Item>();
|
||||||
|
}
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(PropertyName = "newversion", Required = Required.Always)]
|
||||||
internal int version { get; } = 2;
|
internal bool NewVersion { get; } = true;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(PropertyName = "version", Required = Required.Always)]
|
||||||
internal Steam.ItemList me { get; } = new Steam.ItemList();
|
internal byte Version { get; } = 2;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(PropertyName = "me", Required = Required.Always)]
|
||||||
internal Steam.ItemList them { get; } = new Steam.ItemList();
|
internal ItemList ItemsToGive { get; } = new ItemList();
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "them", Required = Required.Always)]
|
||||||
|
internal ItemList ItemsToReceive { get; } = new ItemList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
@@ -36,18 +37,25 @@ namespace ArchiSteamFarm {
|
|||||||
internal static void Init() {
|
internal static void Init() {
|
||||||
LogToFile = Program.GlobalConfig.LogToFile;
|
LogToFile = Program.GlobalConfig.LogToFile;
|
||||||
|
|
||||||
if (LogToFile) {
|
if (!LogToFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lock (FileLock) {
|
lock (FileLock) {
|
||||||
|
if (!LogToFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.Delete(Program.LogFile);
|
File.Delete(Program.LogFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
LogToFile = false;
|
||||||
LogGenericException(e);
|
LogGenericException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal static void LogGenericWTF(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericWTF(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -55,7 +63,7 @@ namespace ArchiSteamFarm {
|
|||||||
Log("[!!] WTF: " + previousMethodName + "() <" + botName + "> " + message + ", WTF?");
|
Log("[!!] WTF: " + previousMethodName + "() <" + botName + "> " + message + ", WTF?");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogGenericError(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericError(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -63,7 +71,8 @@ namespace ArchiSteamFarm {
|
|||||||
Log("[!!] ERROR: " + previousMethodName + "() <" + botName + "> " + message);
|
Log("[!!] ERROR: " + previousMethodName + "() <" + botName + "> " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogGenericException(Exception exception, string botName = "Main", [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericException(Exception exception, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
|
||||||
|
while (true) {
|
||||||
if (exception == null) {
|
if (exception == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -72,11 +81,15 @@ namespace ArchiSteamFarm {
|
|||||||
Log("[!] StackTrace:" + Environment.NewLine + exception.StackTrace);
|
Log("[!] StackTrace:" + Environment.NewLine + exception.StackTrace);
|
||||||
|
|
||||||
if (exception.InnerException != null) {
|
if (exception.InnerException != null) {
|
||||||
LogGenericException(exception.InnerException, botName, previousMethodName);
|
exception = exception.InnerException;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogGenericWarning(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericWarning(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -84,7 +97,7 @@ namespace ArchiSteamFarm {
|
|||||||
Log("[!] WARNING: " + previousMethodName + "() <" + botName + "> " + message);
|
Log("[!] WARNING: " + previousMethodName + "() <" + botName + "> " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogGenericInfo(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericInfo(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -92,7 +105,8 @@ namespace ArchiSteamFarm {
|
|||||||
Log("[*] INFO: " + previousMethodName + "() <" + botName + "> " + message);
|
Log("[*] INFO: " + previousMethodName + "() <" + botName + "> " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogNullError(string nullObjectName, string botName = "Main", [CallerMemberName] string previousMethodName = "") {
|
[SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")]
|
||||||
|
internal static void LogNullError(string nullObjectName, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(nullObjectName)) {
|
if (string.IsNullOrEmpty(nullObjectName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -100,8 +114,8 @@ namespace ArchiSteamFarm {
|
|||||||
LogGenericError(nullObjectName + " is null!", botName, previousMethodName);
|
LogGenericError(nullObjectName + " is null!", botName, previousMethodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
[Conditional("DEBUG"), SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal static void LogGenericDebug(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericDebug(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -120,11 +134,21 @@ namespace ArchiSteamFarm {
|
|||||||
if (!Program.ConsoleIsBusy) {
|
if (!Program.ConsoleIsBusy) {
|
||||||
try {
|
try {
|
||||||
Console.Write(loggedMessage);
|
Console.Write(loggedMessage);
|
||||||
} catch { }
|
}
|
||||||
|
catch {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!LogToFile) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LogToFile) {
|
|
||||||
lock (FileLock) {
|
lock (FileLock) {
|
||||||
|
if (!LogToFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.AppendAllText(Program.LogFile, loggedMessage);
|
File.AppendAllText(Program.LogFile, loggedMessage);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -135,4 +159,3 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ using Newtonsoft.Json;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ArchiSteamFarm.JSON;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal static class Program {
|
internal static class Program {
|
||||||
@@ -48,51 +50,54 @@ namespace ArchiSteamFarm {
|
|||||||
WCFHostname
|
WCFHostname
|
||||||
}
|
}
|
||||||
|
|
||||||
internal enum EMode : byte {
|
private enum EMode : byte {
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
Unknown,
|
Unknown,
|
||||||
Normal, // Standard most common usage
|
Normal, // Standard most common usage
|
||||||
Client, // WCF client only
|
Client, // WCF client only
|
||||||
Server // Normal + WCF server
|
Server // Normal + WCF server
|
||||||
}
|
}
|
||||||
|
|
||||||
internal const string ASF = "ASF";
|
|
||||||
internal const string ConfigDirectory = "config";
|
internal const string ConfigDirectory = "config";
|
||||||
internal const string DebugDirectory = "debug";
|
internal const string DebugDirectory = "debug";
|
||||||
internal const string LogFile = "log.txt";
|
internal const string LogFile = "log.txt";
|
||||||
internal const string GithubRepo = "JustArchi/ArchiSteamFarm";
|
internal const string GithubRepo = "JustArchi/ArchiSteamFarm";
|
||||||
internal const string GlobalConfigFile = ASF + ".json";
|
|
||||||
internal const string GlobalDatabaseFile = ASF + ".db";
|
|
||||||
|
|
||||||
|
private const string ASF = "ASF";
|
||||||
private const string GithubReleaseURL = "https://api.github.com/repos/" + GithubRepo + "/releases"; // GitHub API is HTTPS only
|
private const string GithubReleaseURL = "https://api.github.com/repos/" + GithubRepo + "/releases"; // GitHub API is HTTPS only
|
||||||
|
private const string GlobalConfigFile = ASF + ".json";
|
||||||
|
private const string GlobalDatabaseFile = ASF + ".db";
|
||||||
|
|
||||||
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
|
internal static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version;
|
||||||
internal static readonly Version Version = Assembly.GetName().Version;
|
|
||||||
|
|
||||||
private static readonly object ConsoleLock = new object();
|
private static readonly object ConsoleLock = new object();
|
||||||
private static readonly SemaphoreSlim SteamSemaphore = new SemaphoreSlim(1);
|
private static readonly ManualResetEventSlim ShutdownResetEvent = new ManualResetEventSlim(false);
|
||||||
private static readonly ManualResetEvent ShutdownResetEvent = new ManualResetEvent(false);
|
private static readonly string ExecutableFile = Assembly.GetEntryAssembly().Location;
|
||||||
private static readonly string ExecutableFile = Assembly.Location;
|
|
||||||
private static readonly string ExecutableName = Path.GetFileName(ExecutableFile);
|
private static readonly string ExecutableName = Path.GetFileName(ExecutableFile);
|
||||||
private static readonly string ExecutableDirectory = Path.GetDirectoryName(ExecutableFile);
|
private static readonly string ExecutableDirectory = Path.GetDirectoryName(ExecutableFile);
|
||||||
private static readonly WCF WCF = new WCF();
|
private static readonly WCF WCF = new WCF();
|
||||||
|
|
||||||
internal static GlobalConfig GlobalConfig { get; private set; }
|
internal static GlobalConfig GlobalConfig { get; private set; }
|
||||||
internal static GlobalDatabase GlobalDatabase { get; private set; }
|
internal static GlobalDatabase GlobalDatabase { get; private set; }
|
||||||
internal static bool ConsoleIsBusy { get; private set; } = false;
|
internal static bool ConsoleIsBusy { get; private set; }
|
||||||
|
|
||||||
private static Timer AutoUpdatesTimer;
|
private static Timer AutoUpdatesTimer;
|
||||||
private static EMode Mode = EMode.Normal;
|
private static EMode Mode = EMode.Normal;
|
||||||
|
private static WebBrowser WebBrowser;
|
||||||
|
|
||||||
internal static async Task CheckForUpdate() {
|
internal static async Task CheckForUpdate(bool updateOverride = false) {
|
||||||
string oldExeFile = ExecutableFile + ".old";
|
string oldExeFile = ExecutableFile + ".old";
|
||||||
|
|
||||||
// We booted successfully so we can now remove old exe file
|
// We booted successfully so we can now remove old exe file
|
||||||
if (File.Exists(oldExeFile)) {
|
if (File.Exists(oldExeFile)) {
|
||||||
|
// It's entirely possible that old process is still running, allow at least a second before trying to remove the file
|
||||||
|
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.Delete(oldExeFile);
|
File.Delete(oldExeFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e);
|
||||||
return;
|
Logging.LogGenericError("Could not remove old ASF binary, please remove " + oldExeFile + " manually in order for update function to work!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +112,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
string response = null;
|
string response = null;
|
||||||
Logging.LogGenericInfo("Checking new version...");
|
Logging.LogGenericInfo("Checking new version...");
|
||||||
for (byte i = 0; i < WebBrowser.MaxRetries && string.IsNullOrEmpty(response); i++) {
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && string.IsNullOrEmpty(response); i++) {
|
||||||
response = await WebBrowser.UrlGetToContent(releaseURL).ConfigureAwait(false);
|
response = await WebBrowser.UrlGetToContent(releaseURL).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +138,7 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (releases == null || releases.Count == 0) {
|
if ((releases == null) || (releases.Count == 0)) {
|
||||||
Logging.LogGenericWarning("Could not check latest version!");
|
Logging.LogGenericWarning("Could not check latest version!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -151,40 +156,41 @@ namespace ArchiSteamFarm {
|
|||||||
Logging.LogGenericInfo("Local version: " + Version + " | Remote version: " + newVersion);
|
Logging.LogGenericInfo("Local version: " + Version + " | Remote version: " + newVersion);
|
||||||
|
|
||||||
if (Version.CompareTo(newVersion) >= 0) { // If local version is the same or newer than remote version
|
if (Version.CompareTo(newVersion) >= 0) { // If local version is the same or newer than remote version
|
||||||
if (AutoUpdatesTimer == null && GlobalConfig.AutoUpdates) {
|
if ((AutoUpdatesTimer != null) || !GlobalConfig.AutoUpdates) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Logging.LogGenericInfo("ASF will automatically check for new versions every 24 hours");
|
Logging.LogGenericInfo("ASF will automatically check for new versions every 24 hours");
|
||||||
|
|
||||||
AutoUpdatesTimer = new Timer(
|
AutoUpdatesTimer = new Timer(
|
||||||
async e => await CheckForUpdate().ConfigureAwait(false),
|
async e => await CheckForUpdate().ConfigureAwait(false),
|
||||||
null,
|
null,
|
||||||
TimeSpan.FromDays(1), // Delay
|
TimeSpan.FromDays(1), // Delay
|
||||||
TimeSpan.FromDays(1) // Period
|
TimeSpan.FromDays(1) // Period
|
||||||
);
|
);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GlobalConfig.AutoUpdates) {
|
if (!updateOverride && !GlobalConfig.AutoUpdates) {
|
||||||
Logging.LogGenericInfo("New version is available!");
|
Logging.LogGenericInfo("New version is available!");
|
||||||
Logging.LogGenericInfo("Consider updating yourself!");
|
Logging.LogGenericInfo("Consider updating yourself!");
|
||||||
await Utilities.SleepAsync(5000).ConfigureAwait(false);
|
await Utilities.SleepAsync(5000).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (File.Exists(oldExeFile)) {
|
||||||
|
Logging.LogGenericWarning("Refusing to proceed with auto update as old " + oldExeFile + " binary could not be removed, please remove it manually");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Auto update logic starts here
|
// Auto update logic starts here
|
||||||
if (releaseResponse.Assets == null) {
|
if (releaseResponse.Assets == null) {
|
||||||
Logging.LogGenericWarning("Could not proceed with update because that version doesn't include assets!");
|
Logging.LogGenericWarning("Could not proceed with update because that version doesn't include assets!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GitHub.Asset binaryAsset = null;
|
GitHub.ReleaseResponse.Asset binaryAsset = releaseResponse.Assets.FirstOrDefault(asset => !string.IsNullOrEmpty(asset.Name) && asset.Name.Equals(ExecutableName, StringComparison.OrdinalIgnoreCase));
|
||||||
foreach (var asset in releaseResponse.Assets) {
|
|
||||||
if (string.IsNullOrEmpty(asset.Name) || !asset.Name.Equals(ExecutableName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
binaryAsset = asset;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (binaryAsset == null) {
|
if (binaryAsset == null) {
|
||||||
Logging.LogGenericWarning("Could not proceed with update because there is no asset that relates to currently running binary!");
|
Logging.LogGenericWarning("Could not proceed with update because there is no asset that relates to currently running binary!");
|
||||||
@@ -196,21 +202,22 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] result = null;
|
||||||
|
for (byte i = 0; (i < WebBrowser.MaxRetries) && (result == null); i++) {
|
||||||
Logging.LogGenericInfo("Downloading new version...");
|
Logging.LogGenericInfo("Downloading new version...");
|
||||||
Stream newExe = await WebBrowser.UrlGetToStream(binaryAsset.DownloadURL).ConfigureAwait(false);
|
result = await WebBrowser.UrlGetToBytes(binaryAsset.DownloadURL).ConfigureAwait(false);
|
||||||
if (newExe == null) {
|
}
|
||||||
Logging.LogGenericWarning("Could not download new version!");
|
|
||||||
|
if (result == null) {
|
||||||
|
Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We start deep update logic here
|
|
||||||
string newExeFile = ExecutableFile + ".new";
|
string newExeFile = ExecutableFile + ".new";
|
||||||
|
|
||||||
// Firstly we create new exec
|
// Firstly we create new exec
|
||||||
try {
|
try {
|
||||||
using (FileStream fileStream = File.Open(newExeFile, FileMode.Create)) {
|
File.WriteAllBytes(newExeFile, result);
|
||||||
await newExe.CopyToAsync(fileStream).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e);
|
||||||
return;
|
return;
|
||||||
@@ -224,7 +231,9 @@ namespace ArchiSteamFarm {
|
|||||||
try {
|
try {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
File.Delete(newExeFile);
|
File.Delete(newExeFile);
|
||||||
} catch { }
|
} catch {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,31 +246,38 @@ namespace ArchiSteamFarm {
|
|||||||
// Cleanup
|
// Cleanup
|
||||||
File.Move(oldExeFile, ExecutableFile);
|
File.Move(oldExeFile, ExecutableFile);
|
||||||
File.Delete(newExeFile);
|
File.Delete(newExeFile);
|
||||||
} catch { }
|
} catch {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LogGenericInfo("Update process is finished! ASF will now restart itself...");
|
Logging.LogGenericInfo("Update process finished!");
|
||||||
await Utilities.SleepAsync(5000);
|
|
||||||
|
|
||||||
|
if (GlobalConfig.AutoRestart) {
|
||||||
|
Logging.LogGenericInfo("Restarting...");
|
||||||
|
await Utilities.SleepAsync(5000).ConfigureAwait(false);
|
||||||
Restart();
|
Restart();
|
||||||
|
} else {
|
||||||
|
Logging.LogGenericInfo("Exiting...");
|
||||||
|
await Utilities.SleepAsync(5000).ConfigureAwait(false);
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void Exit(int exitCode = 0) {
|
||||||
|
WCF.StopServer();
|
||||||
|
Environment.Exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Restart() {
|
internal static void Restart() {
|
||||||
try {
|
try {
|
||||||
Process.Start(ExecutableFile, string.Join(" ", Environment.GetCommandLineArgs().Skip(1)));
|
Process.Start(ExecutableFile, string.Join(" ", Environment.GetCommandLineArgs().Skip(1)));
|
||||||
Environment.Exit(0);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal static async Task LimitSteamRequestsAsync() {
|
Exit();
|
||||||
await SteamSemaphore.WaitAsync().ConfigureAwait(false);
|
|
||||||
Task.Run(async () => {
|
|
||||||
await Utilities.SleepAsync(GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false);
|
|
||||||
SteamSemaphore.Release();
|
|
||||||
}).Forget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetUserInput(EUserInputType userInputType, string botName = null, string extraInformation = null) {
|
internal static string GetUserInput(EUserInputType userInputType, string botName = null, string extraInformation = null) {
|
||||||
@@ -269,6 +285,11 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GlobalConfig.Headless) {
|
||||||
|
Logging.LogGenericWarning("Received a request for user input, but process is running in headless mode!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
string result;
|
string result;
|
||||||
lock (ConsoleLock) {
|
lock (ConsoleLock) {
|
||||||
ConsoleIsBusy = true;
|
ConsoleIsBusy = true;
|
||||||
@@ -295,7 +316,7 @@ namespace ArchiSteamFarm {
|
|||||||
Console.Write((string.IsNullOrEmpty(botName) ? "" : "<" + botName + "> ") + "Please enter steam parental PIN: ");
|
Console.Write((string.IsNullOrEmpty(botName) ? "" : "<" + botName + "> ") + "Please enter steam parental PIN: ");
|
||||||
break;
|
break;
|
||||||
case EUserInputType.RevocationCode:
|
case EUserInputType.RevocationCode:
|
||||||
Console.Write((string.IsNullOrEmpty(botName) ? "" : "<" + botName + "> ") + "PLEASE WRITE DOWN YOUR REVOCATION CODE: " + extraInformation);
|
Console.WriteLine((string.IsNullOrEmpty(botName) ? "" : "<" + botName + "> ") + "PLEASE WRITE DOWN YOUR REVOCATION CODE: " + extraInformation);
|
||||||
Console.Write("Hit enter once ready...");
|
Console.Write("Hit enter once ready...");
|
||||||
break;
|
break;
|
||||||
case EUserInputType.TwoFactorAuthentication:
|
case EUserInputType.TwoFactorAuthentication:
|
||||||
@@ -308,8 +329,11 @@ namespace ArchiSteamFarm {
|
|||||||
Console.Write((string.IsNullOrEmpty(botName) ? "" : "<" + botName + "> ") + "Please enter not documented yet value of \"" + userInputType + "\": ");
|
Console.Write((string.IsNullOrEmpty(botName) ? "" : "<" + botName + "> ") + "Please enter not documented yet value of \"" + userInputType + "\": ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = Console.ReadLine();
|
result = Console.ReadLine();
|
||||||
|
if (!Console.IsOutputRedirected) {
|
||||||
Console.Clear(); // For security purposes
|
Console.Clear(); // For security purposes
|
||||||
|
}
|
||||||
ConsoleIsBusy = false;
|
ConsoleIsBusy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,11 +341,9 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal static void OnBotShutdown() {
|
internal static void OnBotShutdown() {
|
||||||
foreach (Bot bot in Bot.Bots.Values) {
|
if (Bot.Bots.Values.Any(bot => bot.KeepRunning)) {
|
||||||
if (bot.KeepRunning) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (WCF.IsServerRunning()) {
|
if (WCF.IsServerRunning()) {
|
||||||
return;
|
return;
|
||||||
@@ -333,26 +355,32 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void InitServices() {
|
private static void InitServices() {
|
||||||
GlobalConfig = GlobalConfig.Load();
|
GlobalConfig = GlobalConfig.Load(Path.Combine(ConfigDirectory, GlobalConfigFile));
|
||||||
if (GlobalConfig == null) {
|
if (GlobalConfig == null) {
|
||||||
Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.json exists and is valid!");
|
Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.json exists and is valid!");
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
Environment.Exit(1);
|
Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalDatabase = GlobalDatabase.Load();
|
GlobalDatabase = GlobalDatabase.Load(Path.Combine(ConfigDirectory, GlobalDatabaseFile));
|
||||||
if (GlobalDatabase == null) {
|
if (GlobalDatabase == null) {
|
||||||
Logging.LogGenericError("Global database could not be loaded!");
|
Logging.LogGenericError("Global database could not be loaded!");
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
Environment.Exit(1);
|
Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiWebHandler.Init();
|
ArchiWebHandler.Init();
|
||||||
WebBrowser.Init();
|
WebBrowser.Init();
|
||||||
WCF.Init();
|
WCF.Init();
|
||||||
|
|
||||||
|
WebBrowser = new WebBrowser("Main");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ParseArgs(IEnumerable<string> args) {
|
||||||
|
if (args == null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ParseArgs(string[] args) {
|
|
||||||
foreach (string arg in args) {
|
foreach (string arg in args) {
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case "--client":
|
case "--client":
|
||||||
@@ -363,7 +391,7 @@ namespace ArchiSteamFarm {
|
|||||||
WCF.StartServer();
|
WCF.StartServer();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (arg.StartsWith("--")) {
|
if (arg.StartsWith("--", StringComparison.Ordinal)) {
|
||||||
Logging.LogGenericWarning("Unrecognized parameter: " + arg);
|
Logging.LogGenericWarning("Unrecognized parameter: " + arg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -388,7 +416,7 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
|
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
|
||||||
if (sender == null || args == null) {
|
if ((sender == null) || (args == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,14 +424,14 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) {
|
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) {
|
||||||
if (sender == null || args == null) {
|
if ((sender == null) || (args == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LogGenericException(args.Exception);
|
Logging.LogGenericException(args.Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Init(string[] args) {
|
private static void Init(IEnumerable<string> args) {
|
||||||
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
|
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
|
||||||
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
|
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
|
||||||
|
|
||||||
@@ -415,7 +443,7 @@ namespace ArchiSteamFarm {
|
|||||||
if (Debugging.IsDebugBuild) {
|
if (Debugging.IsDebugBuild) {
|
||||||
|
|
||||||
// Common structure is bin/(x64/)Debug/ArchiSteamFarm.exe, so we allow up to 4 directories up
|
// Common structure is bin/(x64/)Debug/ArchiSteamFarm.exe, so we allow up to 4 directories up
|
||||||
for (var i = 0; i < 4; i++) {
|
for (byte i = 0; i < 4; i++) {
|
||||||
Directory.SetCurrentDirectory("..");
|
Directory.SetCurrentDirectory("..");
|
||||||
if (Directory.Exists(ConfigDirectory)) {
|
if (Directory.Exists(ConfigDirectory)) {
|
||||||
break;
|
break;
|
||||||
@@ -436,7 +464,7 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
Directory.CreateDirectory(DebugDirectory);
|
Directory.CreateDirectory(DebugDirectory);
|
||||||
|
|
||||||
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(Program.DebugDirectory, "debug.txt")));
|
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(DebugDirectory, "debug.txt")));
|
||||||
SteamKit2.DebugLog.Enabled = true;
|
SteamKit2.DebugLog.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +473,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
// If we ran ASF as a client, we're done by now
|
// If we ran ASF as a client, we're done by now
|
||||||
if (Mode == EMode.Client) {
|
if (Mode == EMode.Client) {
|
||||||
Environment.Exit(0);
|
Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// From now on it's server mode
|
// From now on it's server mode
|
||||||
@@ -454,7 +482,7 @@ namespace ArchiSteamFarm {
|
|||||||
if (!Directory.Exists(ConfigDirectory)) {
|
if (!Directory.Exists(ConfigDirectory)) {
|
||||||
Logging.LogGenericError("Config directory doesn't exist!");
|
Logging.LogGenericError("Config directory doesn't exist!");
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
Environment.Exit(1);
|
Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckForUpdate().Wait();
|
CheckForUpdate().Wait();
|
||||||
@@ -464,8 +492,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
|
|
||||||
foreach (var configFile in Directory.EnumerateFiles(ConfigDirectory, "*.json")) {
|
foreach (string botName in Directory.EnumerateFiles(ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension)) {
|
||||||
string botName = Path.GetFileNameWithoutExtension(configFile);
|
|
||||||
switch (botName) {
|
switch (botName) {
|
||||||
case ASF:
|
case ASF:
|
||||||
case "example":
|
case "example":
|
||||||
@@ -474,8 +501,10 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bot bot = new Bot(botName);
|
Bot bot = new Bot(botName);
|
||||||
if (bot.BotConfig != null && bot.BotConfig.Enabled) {
|
if ((bot.BotConfig != null) && bot.BotConfig.Enabled) {
|
||||||
|
if (bot.BotConfig.StartOnLaunch) {
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
|
Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
|
||||||
}
|
}
|
||||||
@@ -491,10 +520,10 @@ namespace ArchiSteamFarm {
|
|||||||
Init(args);
|
Init(args);
|
||||||
|
|
||||||
// Wait for signal to shutdown
|
// Wait for signal to shutdown
|
||||||
ShutdownResetEvent.WaitOne();
|
ShutdownResetEvent.Wait();
|
||||||
|
|
||||||
// We got a signal to shutdown
|
// We got a signal to shutdown
|
||||||
Environment.Exit(0);
|
Exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
@@ -10,7 +9,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("ArchiSteamFarm")]
|
[assembly: AssemblyProduct("ArchiSteamFarm")]
|
||||||
[assembly: AssemblyCopyright("Copyright © Łukasz Domeradzki 2015-2016")]
|
[assembly: AssemblyCopyright("Copyright © ArchiSteamFarm 2015-2016")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
@@ -32,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("2.0.2.2")]
|
[assembly: AssemblyVersion("2.0.4.7")]
|
||||||
[assembly: AssemblyFileVersion("2.0.2.2")]
|
[assembly: AssemblyFileVersion("2.0.4.7")]
|
||||||
|
|||||||
@@ -23,9 +23,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using SteamAuth;
|
using SteamAuth;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ArchiSteamFarm.JSON;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal sealed class Trading {
|
internal sealed class Trading {
|
||||||
@@ -49,23 +52,19 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
internal Trading(Bot bot) {
|
internal Trading(Bot bot) {
|
||||||
if (bot == null) {
|
if (bot == null) {
|
||||||
return;
|
throw new ArgumentNullException(nameof(bot));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bot = bot;
|
Bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task CheckTrades() {
|
internal async Task CheckTrades() {
|
||||||
bool shouldRun = false;
|
|
||||||
lock (TradesSemaphore) {
|
lock (TradesSemaphore) {
|
||||||
if (ParsingTasks < 2) {
|
if (ParsingTasks >= 2) {
|
||||||
ParsingTasks++;
|
return;
|
||||||
shouldRun = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shouldRun) {
|
ParsingTasks++;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await TradesSemaphore.WaitAsync().ConfigureAwait(false);
|
await TradesSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
@@ -79,52 +78,133 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task ParseActiveTrades() {
|
private async Task ParseActiveTrades() {
|
||||||
List<Steam.TradeOffer> tradeOffers = Bot.ArchiWebHandler.GetTradeOffers();
|
HashSet<Steam.TradeOffer> tradeOffers = Bot.ArchiWebHandler.GetTradeOffers();
|
||||||
if (tradeOffers == null) {
|
if ((tradeOffers == null) || (tradeOffers.Count == 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tradeOffers.RemoveWhere(tradeoffer => tradeoffer.State != Steam.TradeOffer.ETradeOfferState.Active);
|
||||||
|
tradeOffers.TrimExcess();
|
||||||
|
|
||||||
|
if (tradeOffers.Count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await tradeOffers.ForEachAsync(ParseTrade).ConfigureAwait(false);
|
await tradeOffers.ForEachAsync(ParseTrade).ConfigureAwait(false);
|
||||||
await Bot.AcceptConfirmations(Confirmation.ConfirmationType.Trade).ConfigureAwait(false);
|
await Bot.AcceptConfirmations(true, Confirmation.ConfirmationType.Trade).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ParseTrade(Steam.TradeOffer tradeOffer) {
|
private async Task ParseTrade(Steam.TradeOffer tradeOffer) {
|
||||||
if (tradeOffer == null || tradeOffer.trade_offer_state != Steam.TradeOffer.ETradeOfferState.Active) {
|
if ((tradeOffer == null) || (tradeOffer.State != Steam.TradeOffer.ETradeOfferState.Active)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong tradeID;
|
if (await ShouldAcceptTrade(tradeOffer).ConfigureAwait(false)) {
|
||||||
if (!ulong.TryParse(tradeOffer.tradeofferid, out tradeID)) {
|
Logging.LogGenericInfo("Accepting trade: " + tradeOffer.TradeOfferID, Bot.BotName);
|
||||||
return;
|
await Bot.ArchiWebHandler.AcceptTradeOffer(tradeOffer.TradeOfferID).ConfigureAwait(false);
|
||||||
}
|
|
||||||
|
|
||||||
if (ShouldAcceptTrade(tradeOffer)) {
|
|
||||||
Logging.LogGenericInfo("Accepting trade: " + tradeID, Bot.BotName);
|
|
||||||
await Bot.ArchiWebHandler.AcceptTradeOffer(tradeID).ConfigureAwait(false);
|
|
||||||
} else {
|
} else {
|
||||||
Logging.LogGenericInfo("Ignoring trade: " + tradeID, Bot.BotName);
|
Logging.LogGenericInfo("Ignoring trade: " + tradeOffer.TradeOfferID, Bot.BotName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldAcceptTrade(Steam.TradeOffer tradeOffer) {
|
private async Task<bool> ShouldAcceptTrade(Steam.TradeOffer tradeOffer) {
|
||||||
if (tradeOffer == null) {
|
if (tradeOffer == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always accept trades when we're not losing anything
|
// Always accept trades when we're not losing anything
|
||||||
if (tradeOffer.items_to_give.Count == 0) {
|
if (tradeOffer.ItemsToGive.Count == 0) {
|
||||||
return true;
|
// Unless it's steam fuckup and we're dealing with broken trade
|
||||||
|
return tradeOffer.ItemsToReceive.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always accept trades from SteamMasterID
|
// Always accept trades from SteamMasterID
|
||||||
if (tradeOffer.OtherSteamID64 != 0 && tradeOffer.OtherSteamID64 == Bot.BotConfig.SteamMasterID) {
|
if ((tradeOffer.OtherSteamID64 != 0) && (tradeOffer.OtherSteamID64 == Bot.BotConfig.SteamMasterID)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add optional SteamTradeMatcher integration here
|
// If we don't have SteamTradeMatcher enabled, this is the end for us
|
||||||
|
if (!Bot.BotConfig.SteamTradeMatcher) {
|
||||||
// If no rule above matched this trade, reject it
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decline trade if we're giving more count-wise
|
||||||
|
if (tradeOffer.ItemsToGive.Count > tradeOffer.ItemsToReceive.Count) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decline trade if we're losing anything but steam cards, or if it's non-dupes trade
|
||||||
|
if (!tradeOffer.IsSteamCardsOnlyTradeForUs() || !tradeOffer.IsPotentiallyDupesTradeForUs()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point we're sure that STM trade is valid
|
||||||
|
// Now check if it's worth for us to do the trade
|
||||||
|
HashSet<Steam.Item> inventory = await Bot.ArchiWebHandler.GetMyTradableInventory().ConfigureAwait(false);
|
||||||
|
if ((inventory == null) || (inventory.Count == 0)) {
|
||||||
|
return true; // OK, assume that this trade is valid, we can't check our EQ
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get appIDs we're interested in
|
||||||
|
HashSet<uint> appIDs = new HashSet<uint>(tradeOffer.ItemsToGive.Select(item => item.RealAppID));
|
||||||
|
|
||||||
|
// Now remove from our inventory all items we're NOT interested in
|
||||||
|
inventory.RemoveWhere(item => !appIDs.Contains(item.RealAppID));
|
||||||
|
inventory.TrimExcess();
|
||||||
|
|
||||||
|
// If for some reason Valve is talking crap and we can't find mentioned items, assume OK
|
||||||
|
if (inventory.Count == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now let's create a map which maps items to their amount in our EQ
|
||||||
|
Dictionary<Tuple<ulong, ulong>, uint> amountMap = new Dictionary<Tuple<ulong, ulong>, uint>();
|
||||||
|
foreach (Steam.Item item in inventory) {
|
||||||
|
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(item.ClassID, item.InstanceID);
|
||||||
|
|
||||||
|
uint amount;
|
||||||
|
if (amountMap.TryGetValue(key, out amount)) {
|
||||||
|
amountMap[key] = amount + item.Amount;
|
||||||
|
} else {
|
||||||
|
amountMap[key] = item.Amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate our value of items to give
|
||||||
|
List<uint> amountsToGive = new List<uint>(tradeOffer.ItemsToGive.Count);
|
||||||
|
foreach (Tuple<ulong, ulong> key in tradeOffer.ItemsToGive.Select(item => new Tuple<ulong, ulong>(item.ClassID, item.InstanceID))) {
|
||||||
|
uint amount;
|
||||||
|
if (!amountMap.TryGetValue(key, out amount)) {
|
||||||
|
amountsToGive.Add(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
amountsToGive.Add(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort it ascending
|
||||||
|
amountsToGive.Sort();
|
||||||
|
|
||||||
|
// Calculate our value of items to receive
|
||||||
|
List<uint> amountsToReceive = new List<uint>(tradeOffer.ItemsToReceive.Count);
|
||||||
|
foreach (Tuple<ulong, ulong> key in tradeOffer.ItemsToReceive.Select(item => new Tuple<ulong, ulong>(item.ClassID, item.InstanceID))) {
|
||||||
|
uint amount;
|
||||||
|
if (!amountMap.TryGetValue(key, out amount)) {
|
||||||
|
amountsToReceive.Add(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
amountsToReceive.Add(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort it ascending
|
||||||
|
amountsToReceive.Sort();
|
||||||
|
|
||||||
|
// Check actual difference
|
||||||
|
int difference = amountsToGive.Select((t, i) => (int) (t - amountsToReceive[i])).Sum();
|
||||||
|
|
||||||
|
// Trade is worth for us if the difference is greater than 0
|
||||||
|
return difference > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,38 +24,27 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal static class Utilities {
|
internal static class Utilities {
|
||||||
|
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
|
||||||
internal static void Forget(this Task task) { }
|
internal static void Forget(this Task task) { }
|
||||||
|
|
||||||
internal static Task ForEachAsync<T>(this IEnumerable<T> sequence, Func<T, Task> action) {
|
internal static Task ForEachAsync<T>(this IEnumerable<T> sequence, Func<T, Task> action) => action == null ? Task.FromResult(true) : Task.WhenAll(sequence.Select(action));
|
||||||
return Task.WhenAll(sequence.Select(action));
|
|
||||||
|
internal static string GetCookieValue(this CookieContainer cookieContainer, string url, string name) {
|
||||||
|
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(name)) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Task SleepAsync(int miliseconds) {
|
CookieCollection cookies = cookieContainer.GetCookies(new Uri(url));
|
||||||
if (miliseconds < 0) {
|
return cookies.Count == 0 ? null : (from Cookie cookie in cookies where cookie.Name.Equals(name, StringComparison.Ordinal) select cookie.Value).FirstOrDefault();
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.Delay(miliseconds);
|
internal static Task SleepAsync(int miliseconds) => miliseconds < 0 ? Task.FromResult(true) : Task.Delay(miliseconds);
|
||||||
}
|
|
||||||
|
|
||||||
internal static uint GetCharCountInString(string s, char c) {
|
|
||||||
if (string.IsNullOrEmpty(s)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint count = 0;
|
|
||||||
foreach (char singleChar in s) {
|
|
||||||
if (singleChar == c) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,14 +44,15 @@ namespace ArchiSteamFarm {
|
|||||||
internal static void Init() {
|
internal static void Init() {
|
||||||
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) {
|
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) {
|
||||||
Program.GlobalConfig.WCFHostname = Program.GetUserInput(Program.EUserInputType.WCFHostname);
|
Program.GlobalConfig.WCFHostname = Program.GetUserInput(Program.EUserInputType.WCFHostname);
|
||||||
|
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
URL = "http://" + Program.GlobalConfig.WCFHostname + ":" + Program.GlobalConfig.WCFPort + "/ASF";
|
URL = "http://" + Program.GlobalConfig.WCFHostname + ":" + Program.GlobalConfig.WCFPort + "/ASF";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool IsServerRunning() {
|
internal bool IsServerRunning() => ServiceHost != null;
|
||||||
return ServiceHost != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void StartServer() {
|
internal void StartServer() {
|
||||||
if (ServiceHost != null) {
|
if (ServiceHost != null) {
|
||||||
@@ -98,28 +99,16 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] args = input.Split(' ');
|
Bot bot = Bot.Bots.Values.FirstOrDefault();
|
||||||
|
if (bot == null) {
|
||||||
string botName;
|
return "ERROR: No bots are enabled!";
|
||||||
|
|
||||||
if (args.Length > 1) { // If we have args[1] provided, use given botName
|
|
||||||
botName = args[1];
|
|
||||||
} else { // If not, just pick first one
|
|
||||||
botName = Bot.Bots.Keys.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(botName)) {
|
if (Program.GlobalConfig.SteamOwnerID == 0) {
|
||||||
return "ERROR: Invalid botName: " + botName;
|
return "Refusing to handle request because SteamOwnerID is not set!";
|
||||||
}
|
}
|
||||||
|
|
||||||
Bot bot;
|
string command = "!" + input;
|
||||||
if (!Bot.Bots.TryGetValue(botName, out bot)) {
|
|
||||||
return "ERROR: Couldn't find any bot named: " + botName;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logging.LogGenericInfo("Received command: " + input);
|
|
||||||
|
|
||||||
string command = '!' + input;
|
|
||||||
string output = bot.Response(Program.GlobalConfig.SteamOwnerID, command).Result; // TODO: This should be asynchronous
|
string output = bot.Response(Program.GlobalConfig.SteamOwnerID, command).Result; // TODO: This should be asynchronous
|
||||||
|
|
||||||
Logging.LogGenericInfo("Answered to command: " + input + " with: " + output);
|
Logging.LogGenericInfo("Answered to command: " + input + " with: " + output);
|
||||||
|
|||||||
@@ -23,37 +23,30 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal static class WebBrowser {
|
internal sealed class WebBrowser {
|
||||||
internal const byte MaxRetries = 5; // Defines maximum number of retries, UrlRequest() does not handle retry by itself (it's app responsibility)
|
internal const byte MaxRetries = 5; // Defines maximum number of retries, UrlRequest() does not handle retry by itself (it's app responsibility)
|
||||||
|
|
||||||
private const byte MaxConnections = 10; // Defines maximum number of connections per ServicePoint. Be careful, as it also defines maximum number of sockets in CLOSE_WAIT state
|
private const byte MaxConnections = 10; // Defines maximum number of connections per ServicePoint. Be careful, as it also defines maximum number of sockets in CLOSE_WAIT state
|
||||||
private const byte MaxIdleTime = 15; // In seconds, how long socket is allowed to stay in CLOSE_WAIT state after there are no connections to it
|
private const byte MaxIdleTime = 15; // In seconds, how long socket is allowed to stay in CLOSE_WAIT state after there are no connections to it
|
||||||
|
|
||||||
private static readonly string DefaultUserAgent = "ArchiSteamFarm/" + Program.Version;
|
private static readonly string DefaultUserAgent = "ArchiSteamFarm/" + Program.Version;
|
||||||
private static readonly HttpClient HttpClient = new HttpClient(new HttpClientHandler {
|
|
||||||
UseCookies = false
|
internal readonly CookieContainer CookieContainer = new CookieContainer();
|
||||||
}) {
|
|
||||||
Timeout = TimeSpan.FromSeconds(60)
|
private readonly HttpClient HttpClient;
|
||||||
};
|
private readonly string Identifier;
|
||||||
|
|
||||||
internal static void Init() {
|
internal static void Init() {
|
||||||
HttpClient.Timeout = TimeSpan.FromSeconds(Program.GlobalConfig.HttpTimeout);
|
|
||||||
|
|
||||||
// Most web services expect that UserAgent is set, so we declare it globally
|
|
||||||
// Any request can override that on as-needed basis (see: RequestOptions.FakeUserAgent)
|
|
||||||
HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(DefaultUserAgent);
|
|
||||||
|
|
||||||
// Set max connection limit from default of 2 to desired value
|
// Set max connection limit from default of 2 to desired value
|
||||||
ServicePointManager.DefaultConnectionLimit = MaxConnections;
|
ServicePointManager.DefaultConnectionLimit = MaxConnections;
|
||||||
|
|
||||||
@@ -63,84 +56,101 @@ namespace ArchiSteamFarm {
|
|||||||
// Don't use Expect100Continue, we're sure about our POSTs, save some TCP packets
|
// Don't use Expect100Continue, we're sure about our POSTs, save some TCP packets
|
||||||
ServicePointManager.Expect100Continue = false;
|
ServicePointManager.Expect100Continue = false;
|
||||||
|
|
||||||
// Reuse ports if possible
|
#if !__MonoCS__
|
||||||
// TODO: Mono doesn't support that feature yet
|
// Reuse ports if possible (since .NET 4.6+)
|
||||||
//ServicePointManager.ReusePort = true;
|
//ServicePointManager.ReusePort = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<HttpResponseMessage> UrlGet(string request, Dictionary<string, string> cookies = null, string referer = null) {
|
internal WebBrowser(string identifier) {
|
||||||
|
if (string.IsNullOrEmpty(identifier)) {
|
||||||
|
throw new ArgumentNullException(nameof(identifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
Identifier = identifier;
|
||||||
|
|
||||||
|
HttpClientHandler httpClientHandler = new HttpClientHandler {
|
||||||
|
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
|
||||||
|
CookieContainer = CookieContainer
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpClient = new HttpClient(httpClientHandler) {
|
||||||
|
Timeout = TimeSpan.FromSeconds(Program.GlobalConfig.HttpTimeout)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Most web services expect that UserAgent is set, so we declare it globally
|
||||||
|
HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(DefaultUserAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async Task<bool> UrlHead(string request, string referer = null) {
|
||||||
|
if (string.IsNullOrEmpty(request)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (HttpResponseMessage response = await UrlHeadToResponse(request, referer).ConfigureAwait(false)) {
|
||||||
|
return response != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async Task<Uri> UrlHeadToUri(string request, string referer = null) {
|
||||||
if (string.IsNullOrEmpty(request)) {
|
if (string.IsNullOrEmpty(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await UrlRequest(request, HttpMethod.Get, null, cookies, referer).ConfigureAwait(false);
|
using (HttpResponseMessage response = await UrlHeadToResponse(request, referer).ConfigureAwait(false)) {
|
||||||
|
return response == null ? null : response.RequestMessage.RequestUri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<HttpResponseMessage> UrlPost(string request, Dictionary<string, string> data = null, Dictionary<string, string> cookies = null, string referer = null) {
|
internal async Task<string> UrlGetToContent(string request, string referer = null) {
|
||||||
if (string.IsNullOrEmpty(request)) {
|
if (string.IsNullOrEmpty(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await UrlRequest(request, HttpMethod.Post, data, cookies, referer).ConfigureAwait(false);
|
using (HttpResponseMessage httpResponse = await UrlGetToResponse(request, referer).ConfigureAwait(false)) {
|
||||||
}
|
|
||||||
|
|
||||||
internal static async Task<string> UrlGetToContent(string request, Dictionary<string, string> cookies = null, string referer = null) {
|
|
||||||
if (string.IsNullOrEmpty(request)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpResponseMessage httpResponse = await UrlGet(request, cookies, referer).ConfigureAwait(false);
|
|
||||||
if (httpResponse == null) {
|
if (httpResponse == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (httpResponse.Content == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
|
return await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static async Task<Stream> UrlGetToStream(string request, Dictionary<string, string> cookies = null, string referer = null) {
|
internal async Task<byte[]> UrlGetToBytes(string request, string referer = null) {
|
||||||
if (string.IsNullOrEmpty(request)) {
|
if (string.IsNullOrEmpty(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponseMessage httpResponse = await UrlGet(request, cookies, referer).ConfigureAwait(false);
|
using (HttpResponseMessage httpResponse = await UrlGetToResponse(request, referer).ConfigureAwait(false)) {
|
||||||
if (httpResponse == null) {
|
if (httpResponse == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (httpResponse.Content == null) {
|
return await httpResponse.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
internal async Task<HtmlDocument> UrlGetToHtmlDocument(string request, string referer = null) {
|
||||||
}
|
|
||||||
|
|
||||||
internal static async Task<HtmlDocument> UrlGetToHtmlDocument(string request, Dictionary<string, string> cookies = null, string referer = null) {
|
|
||||||
if (string.IsNullOrEmpty(request)) {
|
if (string.IsNullOrEmpty(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string content = await UrlGetToContent(request, cookies, referer).ConfigureAwait(false);
|
string content = await UrlGetToContent(request, referer).ConfigureAwait(false);
|
||||||
if (string.IsNullOrEmpty(content)) {
|
if (string.IsNullOrEmpty(content)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = WebUtility.HtmlDecode(content);
|
|
||||||
HtmlDocument htmlDocument = new HtmlDocument();
|
HtmlDocument htmlDocument = new HtmlDocument();
|
||||||
htmlDocument.LoadHtml(content);
|
htmlDocument.LoadHtml(WebUtility.HtmlDecode(content));
|
||||||
|
|
||||||
return htmlDocument;
|
return htmlDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<JObject> UrlGetToJObject(string request, Dictionary<string, string> cookies = null, string referer = null) {
|
internal async Task<JObject> UrlGetToJObject(string request, string referer = null) {
|
||||||
if (string.IsNullOrEmpty(request)) {
|
if (string.IsNullOrEmpty(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string content = await UrlGetToContent(request, cookies, referer).ConfigureAwait(false);
|
string content = await UrlGetToContent(request, referer).ConfigureAwait(false);
|
||||||
if (string.IsNullOrEmpty(content)) {
|
if (string.IsNullOrEmpty(content)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -149,20 +159,20 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jObject = JObject.Parse(content);
|
jObject = JObject.Parse(content);
|
||||||
} catch (Exception e) {
|
} catch (JsonException e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e, Identifier);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return jObject;
|
return jObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<XmlDocument> UrlGetToXML(string request, Dictionary<string, string> cookies = null, string referer = null) {
|
internal async Task<XmlDocument> UrlGetToXML(string request, string referer = null) {
|
||||||
if (string.IsNullOrEmpty(request)) {
|
if (string.IsNullOrEmpty(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string content = await UrlGetToContent(request, cookies, referer).ConfigureAwait(false);
|
string content = await UrlGetToContent(request, referer).ConfigureAwait(false);
|
||||||
if (string.IsNullOrEmpty(content)) {
|
if (string.IsNullOrEmpty(content)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -172,41 +182,67 @@ namespace ArchiSteamFarm {
|
|||||||
try {
|
try {
|
||||||
xmlDocument.LoadXml(content);
|
xmlDocument.LoadXml(content);
|
||||||
} catch (XmlException e) {
|
} catch (XmlException e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e, Identifier);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return xmlDocument;
|
return xmlDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<HttpResponseMessage> UrlRequest(string request, HttpMethod httpMethod, Dictionary<string, string> data = null, Dictionary<string, string> cookies = null, string referer = null) {
|
internal async Task<bool> UrlPost(string request, Dictionary<string, string> data = null, string referer = null) {
|
||||||
if (string.IsNullOrEmpty(request) || httpMethod == null) {
|
if (string.IsNullOrEmpty(request)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (HttpResponseMessage response = await UrlPostToResponse(request, data, referer).ConfigureAwait(false)) {
|
||||||
|
return response != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<HttpResponseMessage> UrlGetToResponse(string request, string referer = null) {
|
||||||
|
if (string.IsNullOrEmpty(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.StartsWith("https://") && Program.GlobalConfig.ForceHttp) {
|
return await UrlRequest(request, HttpMethod.Get, null, referer).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<HttpResponseMessage> UrlHeadToResponse(string request, string referer = null) {
|
||||||
|
if (string.IsNullOrEmpty(request)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await UrlRequest(request, HttpMethod.Head, null, referer).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<HttpResponseMessage> UrlPostToResponse(string request, Dictionary<string, string> data = null, string referer = null) {
|
||||||
|
if (string.IsNullOrEmpty(request)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await UrlRequest(request, HttpMethod.Post, data, referer).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<HttpResponseMessage> UrlRequest(string request, HttpMethod httpMethod, Dictionary<string, string> data = null, string referer = null) {
|
||||||
|
if (string.IsNullOrEmpty(request) || (httpMethod == null)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.StartsWith("https://", StringComparison.Ordinal) && Program.GlobalConfig.ForceHttp) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponseMessage responseMessage;
|
HttpResponseMessage responseMessage;
|
||||||
using (HttpRequestMessage requestMessage = new HttpRequestMessage(httpMethod, request)) {
|
using (HttpRequestMessage requestMessage = new HttpRequestMessage(httpMethod, request)) {
|
||||||
if (data != null && data.Count > 0) {
|
if ((data != null) && (data.Count > 0)) {
|
||||||
try {
|
try {
|
||||||
requestMessage.Content = new FormUrlEncodedContent(data);
|
requestMessage.Content = new FormUrlEncodedContent(data);
|
||||||
} catch (UriFormatException e) {
|
} catch (UriFormatException e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e, Identifier);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cookies != null && cookies.Count > 0) {
|
|
||||||
StringBuilder cookieHeader = new StringBuilder();
|
|
||||||
foreach (KeyValuePair<string, string> cookie in cookies) {
|
|
||||||
cookieHeader.Append(cookie.Key + "=" + cookie.Value + ";");
|
|
||||||
}
|
|
||||||
requestMessage.Headers.Add("Cookie", cookieHeader.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(referer)) {
|
if (!string.IsNullOrEmpty(referer)) {
|
||||||
requestMessage.Headers.Referrer = new Uri(referer);
|
requestMessage.Headers.Referrer = new Uri(referer);
|
||||||
}
|
}
|
||||||
@@ -222,16 +258,18 @@ namespace ArchiSteamFarm {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!responseMessage.IsSuccessStatusCode) {
|
if (responseMessage.IsSuccessStatusCode) {
|
||||||
if (Debugging.IsDebugBuild || Program.GlobalConfig.Debug) {
|
|
||||||
Logging.LogGenericError("Request: " + request + " failed!");
|
|
||||||
Logging.LogGenericError("Status code: " + responseMessage.StatusCode);
|
|
||||||
Logging.LogGenericError("Content: " + Environment.NewLine + await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseMessage;
|
return responseMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Debugging.IsDebugBuild || Program.GlobalConfig.Debug) {
|
||||||
|
Logging.LogGenericError("Request: " + request + " failed!", Identifier);
|
||||||
|
Logging.LogGenericError("Status code: " + responseMessage.StatusCode, Identifier);
|
||||||
|
Logging.LogGenericError("Content: " + Environment.NewLine + await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false), Identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
responseMessage.Dispose();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"Debug": false,
|
"Debug": false,
|
||||||
|
"Headless": false,
|
||||||
"AutoUpdates": true,
|
"AutoUpdates": true,
|
||||||
|
"AutoRestart": true,
|
||||||
"UpdateChannel": 1,
|
"UpdateChannel": 1,
|
||||||
"SteamProtocol": 6,
|
"SteamProtocol": 6,
|
||||||
"SteamOwnerID": 0,
|
"SteamOwnerID": 0,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"FarmOffline": false,
|
"FarmOffline": false,
|
||||||
"HandleOfflineMessages": false,
|
"HandleOfflineMessages": false,
|
||||||
"AcceptGifts": false,
|
"AcceptGifts": false,
|
||||||
|
"SteamTradeMatcher": false,
|
||||||
"ForwardKeysToOtherBots": false,
|
"ForwardKeysToOtherBots": false,
|
||||||
"DistributeKeys": false,
|
"DistributeKeys": false,
|
||||||
"UseAsfAsMobileAuthenticator": false,
|
"UseAsfAsMobileAuthenticator": false,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
internal class ASFConfig {
|
internal abstract class ASFConfig {
|
||||||
internal static readonly HashSet<ASFConfig> ASFConfigs = new HashSet<ASFConfig>();
|
internal static readonly HashSet<ASFConfig> ASFConfigs = new HashSet<ASFConfig>();
|
||||||
|
|
||||||
internal string FilePath { get; set; }
|
internal string FilePath { get; set; }
|
||||||
@@ -38,10 +38,14 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ASFConfig(string filePath) : this() {
|
protected ASFConfig(string filePath) : this() {
|
||||||
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
FilePath = filePath;
|
FilePath = filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void Save() {
|
internal void Save() {
|
||||||
lock (FilePath) {
|
lock (FilePath) {
|
||||||
try {
|
try {
|
||||||
File.WriteAllText(FilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
File.WriteAllText(FilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||||
@@ -51,7 +55,7 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void Remove() {
|
internal void Remove() {
|
||||||
string queryPath = Path.GetFileNameWithoutExtension(FilePath);
|
string queryPath = Path.GetFileNameWithoutExtension(FilePath);
|
||||||
lock (FilePath) {
|
lock (FilePath) {
|
||||||
foreach (string botFile in Directory.EnumerateFiles(Program.ConfigDirectory, queryPath + ".*")) {
|
foreach (string botFile in Directory.EnumerateFiles(Program.ConfigDirectory, queryPath + ".*")) {
|
||||||
@@ -62,10 +66,11 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASFConfigs.Remove(this);
|
ASFConfigs.Remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void Rename(string botName) {
|
internal void Rename(string botName) {
|
||||||
if (string.IsNullOrEmpty(botName)) {
|
if (string.IsNullOrEmpty(botName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -79,6 +84,7 @@ namespace ConfigGenerator {
|
|||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath = Path.Combine(Program.ConfigDirectory, botName + ".json");
|
FilePath = Path.Combine(Program.ConfigDirectory, botName + ".json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,12 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
|
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global"), SuppressMessage("ReSharper", "CollectionNeverQueried.Global"), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal sealed class BotConfig : ASFConfig {
|
internal sealed class BotConfig : ASFConfig {
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool Enabled { get; set; } = false;
|
public bool Enabled { get; set; } = false;
|
||||||
@@ -38,7 +41,7 @@ namespace ConfigGenerator {
|
|||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string SteamLogin { get; set; } = null;
|
public string SteamLogin { get; set; } = null;
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty, PasswordPropertyText(true)]
|
||||||
public string SteamPassword { get; set; } = null;
|
public string SteamPassword { get; set; } = null;
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
@@ -68,6 +71,9 @@ namespace ConfigGenerator {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool AcceptGifts { get; set; } = false;
|
public bool AcceptGifts { get; set; } = false;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
public bool SteamTradeMatcher { get; set; } = false;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool ForwardKeysToOtherBots { get; set; } = false;
|
public bool ForwardKeysToOtherBots { get; set; } = false;
|
||||||
|
|
||||||
@@ -124,11 +130,14 @@ namespace ConfigGenerator {
|
|||||||
return botConfig;
|
return botConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This constructor is used only by deserializer
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
private BotConfig() { }
|
private BotConfig() { }
|
||||||
|
|
||||||
private BotConfig(string filePath) : base(filePath) {
|
private BotConfig(string filePath) : base(filePath) {
|
||||||
FilePath = filePath;
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
GamesPlayedWhileIdle.Add(0);
|
GamesPlayedWhileIdle.Add(0);
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
<Compile Include="Properties\Resources.Designer.cs">
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
</Compile>
|
</Compile>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
@@ -104,12 +105,12 @@
|
|||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent Condition=" '$(OS)' != 'Unix' AND '$(ConfigurationName)' == 'Release' ">
|
<PostBuildEvent Condition=" '$(OS)' != 'Unix' AND '$(ConfigurationName)' == 'Release' ">
|
||||||
"$(SolutionDir)tools\ILRepack\ILRepack.exe" /ndebug /internalize /parallel /targetplatform:v4 /wildcards /out:"$(SolutionDir)out\ASF-GUI.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll"
|
"$(SolutionDir)tools\ILRepack\ILRepack.exe" /ndebug /internalize /parallel /targetplatform:v4 /wildcards /out:"$(SolutionDir)out\ASF-ConfigGenerator.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll"
|
||||||
del "$(SolutionDir)out\ASF-GUI.exe.config"
|
del "$(SolutionDir)out\ASF-ConfigGenerator.exe.config"
|
||||||
</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
<PostBuildEvent Condition=" '$(OS)' == 'Unix' AND '$(ConfigurationName)' == 'Release' ">
|
<PostBuildEvent Condition=" '$(OS)' == 'Unix' AND '$(ConfigurationName)' == 'Release' ">
|
||||||
mono -O=all "$(SolutionDir)tools/ILRepack/ILRepack.exe" /ndebug /internalize /parallel /targetplatform:v4 /wildcards /out:"$(SolutionDir)out/ASF-GUI.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll"
|
mono -O=all "$(SolutionDir)tools/ILRepack/ILRepack.exe" /ndebug /internalize /parallel /targetplatform:v4 /wildcards /out:"$(SolutionDir)out/ASF-ConfigGenerator.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll"
|
||||||
rm "$(SolutionDir)out/ASF-GUI.exe.config"
|
rm "$(SolutionDir)out/ASF-ConfigGenerator.exe.config"
|
||||||
</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ using System.IO;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
internal class ConfigPage : TabPage {
|
internal sealed class ConfigPage : TabPage {
|
||||||
internal readonly ASFConfig ASFConfig;
|
internal readonly ASFConfig ASFConfig;
|
||||||
|
|
||||||
internal ConfigPage(ASFConfig config) {
|
internal ConfigPage(ASFConfig config) {
|
||||||
@@ -42,8 +42,6 @@ namespace ConfigGenerator {
|
|||||||
Controls.Add(enhancedPropertyGrid);
|
Controls.Add(enhancedPropertyGrid);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RefreshText() {
|
internal void RefreshText() => Text = Path.GetFileNameWithoutExtension(ASFConfig.FilePath);
|
||||||
Text = Path.GetFileNameWithoutExtension(ASFConfig.FilePath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,16 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
internal static class Debugging {
|
internal static class Debugging {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
[SuppressMessage("ReSharper", "ConvertToConstant.Global")]
|
||||||
internal static readonly bool IsDebugBuild = true;
|
internal static readonly bool IsDebugBuild = true;
|
||||||
#else
|
#else
|
||||||
|
[SuppressMessage("ReSharper", "ConvertToConstant.Global")]
|
||||||
internal static readonly bool IsDebugBuild = false;
|
internal static readonly bool IsDebugBuild = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal static bool IsReleaseBuild => !IsDebugBuild;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,92 +25,95 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using ConfigGenerator.Properties;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
class DialogBox {
|
internal static class DialogBox {
|
||||||
public static DialogResult InputBox(string title, string promptText, out string value) {
|
internal static DialogResult InputBox(string title, string promptText, out string value) {
|
||||||
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(promptText)) {
|
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(promptText)) {
|
||||||
value = null;
|
value = null;
|
||||||
return DialogResult.Abort;
|
return DialogResult.Abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
Form form = new Form();
|
TextBox textBox = new TextBox {
|
||||||
Label label = new Label();
|
Anchor = AnchorStyles.Right,
|
||||||
TextBox textBox = new TextBox();
|
Bounds = new Rectangle(12, 36, 372, 20),
|
||||||
|
Width = 1000
|
||||||
|
};
|
||||||
|
|
||||||
textBox.Width = 1000;
|
Button buttonOk = new Button {
|
||||||
Button buttonOk = new Button();
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
||||||
Button buttonCancel = new Button();
|
Bounds = new Rectangle(228, 72, 75, 23),
|
||||||
|
DialogResult = DialogResult.OK,
|
||||||
|
Text = Resources.OK
|
||||||
|
};
|
||||||
|
|
||||||
form.Text = title;
|
Button buttonCancel = new Button {
|
||||||
label.Text = promptText;
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
||||||
|
Bounds = new Rectangle(309, 72, 75, 23),
|
||||||
|
DialogResult = DialogResult.Cancel,
|
||||||
|
Text = Resources.Cancel
|
||||||
|
};
|
||||||
|
|
||||||
buttonOk.Text = "OK";
|
Label label = new Label {
|
||||||
buttonCancel.Text = "Cancel";
|
AutoSize = true,
|
||||||
buttonOk.DialogResult = DialogResult.OK;
|
Bounds = new Rectangle(9, 20, 372, 13),
|
||||||
buttonCancel.DialogResult = DialogResult.Cancel;
|
Text = promptText
|
||||||
|
};
|
||||||
|
|
||||||
label.SetBounds(9, 20, 372, 13);
|
Form form = new Form {
|
||||||
textBox.SetBounds(12, 36, 372, 20);
|
AcceptButton = buttonOk,
|
||||||
buttonOk.SetBounds(228, 72, 75, 23);
|
CancelButton = buttonCancel,
|
||||||
buttonCancel.SetBounds(309, 72, 75, 23);
|
ClientSize = new Size(Math.Max(300, label.Right + 10), 107),
|
||||||
|
Controls = { label, textBox, buttonOk, buttonCancel },
|
||||||
label.AutoSize = true;
|
FormBorderStyle = FormBorderStyle.FixedDialog,
|
||||||
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
|
MinimizeBox = false,
|
||||||
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
MaximizeBox = false,
|
||||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
StartPosition = FormStartPosition.CenterScreen,
|
||||||
|
Text = title
|
||||||
form.ClientSize = new Size(396, 107);
|
};
|
||||||
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
|
|
||||||
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
|
|
||||||
form.FormBorderStyle = FormBorderStyle.FixedDialog;
|
|
||||||
form.StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
form.MinimizeBox = false;
|
|
||||||
form.MaximizeBox = false;
|
|
||||||
form.AcceptButton = buttonOk;
|
|
||||||
form.CancelButton = buttonCancel;
|
|
||||||
|
|
||||||
DialogResult dialogResult = form.ShowDialog();
|
DialogResult dialogResult = form.ShowDialog();
|
||||||
value = textBox.Text;
|
value = textBox.Text;
|
||||||
return dialogResult;
|
return dialogResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DialogResult YesNoBox(string title, string promptText) {
|
internal static DialogResult YesNoBox(string title, string promptText) {
|
||||||
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(promptText)) {
|
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(promptText)) {
|
||||||
return DialogResult.Abort;
|
return DialogResult.Abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
Form form = new Form();
|
Button buttonYes = new Button {
|
||||||
Label label = new Label();
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
||||||
|
Bounds = new Rectangle(228, 72, 75, 23),
|
||||||
|
DialogResult = DialogResult.Yes,
|
||||||
|
Text = Resources.Yes
|
||||||
|
};
|
||||||
|
|
||||||
Button buttonOk = new Button();
|
Button buttonNo = new Button {
|
||||||
Button buttonCancel = new Button();
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
||||||
|
Bounds = new Rectangle(309, 72, 75, 23),
|
||||||
|
DialogResult = DialogResult.No,
|
||||||
|
Text = Resources.No
|
||||||
|
};
|
||||||
|
|
||||||
form.Text = title;
|
Label label = new Label {
|
||||||
label.Text = promptText;
|
AutoSize = true,
|
||||||
|
Bounds = new Rectangle(9, 20, 372, 13),
|
||||||
|
Text = promptText
|
||||||
|
};
|
||||||
|
|
||||||
buttonOk.Text = "Yes";
|
Form form = new Form {
|
||||||
buttonCancel.Text = "No";
|
AcceptButton = buttonYes,
|
||||||
buttonOk.DialogResult = DialogResult.Yes;
|
CancelButton = buttonNo,
|
||||||
buttonCancel.DialogResult = DialogResult.No;
|
ClientSize = new Size(Math.Max(300, label.Right + 10), 107),
|
||||||
|
Controls = { label, buttonYes, buttonNo },
|
||||||
label.SetBounds(9, 20, 372, 13);
|
FormBorderStyle = FormBorderStyle.FixedDialog,
|
||||||
buttonOk.SetBounds(228, 50, 75, 23);
|
MinimizeBox = false,
|
||||||
buttonCancel.SetBounds(309, 50, 75, 23);
|
MaximizeBox = false,
|
||||||
|
StartPosition = FormStartPosition.CenterScreen,
|
||||||
label.AutoSize = true;
|
Text = title
|
||||||
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
};
|
||||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
||||||
|
|
||||||
form.ClientSize = new Size(396, 80);
|
|
||||||
form.Controls.AddRange(new Control[] { label, buttonOk, buttonCancel });
|
|
||||||
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
|
|
||||||
form.FormBorderStyle = FormBorderStyle.FixedDialog;
|
|
||||||
form.StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
form.MinimizeBox = false;
|
|
||||||
form.MaximizeBox = false;
|
|
||||||
form.AcceptButton = buttonOk;
|
|
||||||
form.CancelButton = buttonCancel;
|
|
||||||
|
|
||||||
DialogResult dialogResult = form.ShowDialog();
|
DialogResult dialogResult = form.ShowDialog();
|
||||||
return dialogResult;
|
return dialogResult;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
@@ -30,7 +31,7 @@ namespace ConfigGenerator {
|
|||||||
|
|
||||||
internal EnhancedPropertyGrid(ASFConfig config) {
|
internal EnhancedPropertyGrid(ASFConfig config) {
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
return;
|
throw new ArgumentNullException(nameof(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASFConfig = config;
|
ASFConfig = config;
|
||||||
@@ -52,21 +53,34 @@ namespace ConfigGenerator {
|
|||||||
|
|
||||||
BotConfig botConfig = ASFConfig as BotConfig;
|
BotConfig botConfig = ASFConfig as BotConfig;
|
||||||
if (botConfig != null) {
|
if (botConfig != null) {
|
||||||
if (botConfig.Enabled) {
|
if (!botConfig.Enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Tutorial.OnAction(Tutorial.EPhase.BotEnabled);
|
Tutorial.OnAction(Tutorial.EPhase.BotEnabled);
|
||||||
if (!string.IsNullOrEmpty(botConfig.SteamLogin) && !string.IsNullOrEmpty(botConfig.SteamPassword)) {
|
if (!string.IsNullOrEmpty(botConfig.SteamLogin) && !string.IsNullOrEmpty(botConfig.SteamPassword)) {
|
||||||
Tutorial.OnAction(Tutorial.EPhase.BotReady);
|
Tutorial.OnAction(Tutorial.EPhase.BotReady);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalConfig globalConfig = ASFConfig as GlobalConfig;
|
GlobalConfig globalConfig = ASFConfig as GlobalConfig;
|
||||||
if (globalConfig != null) {
|
if (globalConfig == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (globalConfig.SteamOwnerID != 0) {
|
if (globalConfig.SteamOwnerID != 0) {
|
||||||
Tutorial.OnAction(Tutorial.EPhase.GlobalConfigReady);
|
Tutorial.OnAction(Tutorial.EPhase.GlobalConfigReady);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnGotFocus(EventArgs e) {
|
||||||
|
if (e == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnGotFocus(e);
|
||||||
|
ASFConfig.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,14 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
|
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global"), SuppressMessage("ReSharper", "CollectionNeverQueried.Global"), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal sealed class GlobalConfig : ASFConfig {
|
internal sealed class GlobalConfig : ASFConfig {
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal enum EUpdateChannel : byte {
|
internal enum EUpdateChannel : byte {
|
||||||
Unknown,
|
Unknown,
|
||||||
Stable,
|
Stable,
|
||||||
@@ -43,14 +46,20 @@ namespace ConfigGenerator {
|
|||||||
private const ProtocolType DefaultSteamProtocol = ProtocolType.Tcp;
|
private const ProtocolType DefaultSteamProtocol = ProtocolType.Tcp;
|
||||||
|
|
||||||
// This is hardcoded blacklist which should not be possible to change
|
// 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 };
|
private static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 267420, 303700, 335590, 368020, 425280 };
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool Debug { get; set; } = false;
|
public bool Debug { get; set; } = false;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
public bool Headless { get; set; } = false;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool AutoUpdates { get; set; } = true;
|
public bool AutoUpdates { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
public bool AutoRestart { get; set; } = true;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public EUpdateChannel UpdateChannel { get; set; } = EUpdateChannel.Stable;
|
public EUpdateChannel UpdateChannel { get; set; } = EUpdateChannel.Stable;
|
||||||
|
|
||||||
@@ -96,7 +105,6 @@ namespace ConfigGenerator {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool Statistics { get; set; } = true;
|
public bool Statistics { get; set; } = true;
|
||||||
|
|
||||||
// TODO: Please remove me immediately after https://github.com/SteamRE/SteamKit/issues/254 gets fixed
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool HackIgnoreMachineID { get; set; } = false;
|
public bool HackIgnoreMachineID { get; set; } = false;
|
||||||
|
|
||||||
@@ -155,19 +163,24 @@ namespace ConfigGenerator {
|
|||||||
globalConfig.HttpTimeout = DefaultHttpTimeout;
|
globalConfig.HttpTimeout = DefaultHttpTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalConfig.WCFPort == 0) {
|
if (globalConfig.WCFPort != 0) {
|
||||||
|
return globalConfig;
|
||||||
|
}
|
||||||
|
|
||||||
Logging.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort + ". Value of " + DefaultWCFPort + " will be used instead");
|
Logging.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort + ". Value of " + DefaultWCFPort + " will be used instead");
|
||||||
globalConfig.WCFPort = DefaultWCFPort;
|
globalConfig.WCFPort = DefaultWCFPort;
|
||||||
}
|
|
||||||
|
|
||||||
return globalConfig;
|
return globalConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This constructor is used only by deserializer
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
private GlobalConfig() { }
|
private GlobalConfig() { }
|
||||||
|
|
||||||
private GlobalConfig(string filePath) : base(filePath) {
|
private GlobalConfig(string filePath) : base(filePath) {
|
||||||
FilePath = filePath;
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
Blacklist.AddRange(GlobalBlacklist);
|
Blacklist.AddRange(GlobalBlacklist);
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using ConfigGenerator.Properties;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
internal static class Logging {
|
internal static class Logging {
|
||||||
@@ -34,60 +34,40 @@ namespace ConfigGenerator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show(message, Resources.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogGenericWTF(string message, [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericError(string message, [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageBox.Show(previousMethodName + "() " + message, "WTF", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(previousMethodName + @"() " + message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogGenericError(string message, [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
while (true) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageBox.Show(previousMethodName + "() " + message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = "") {
|
|
||||||
if (exception == null) {
|
if (exception == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageBox.Show(previousMethodName + "() " + exception.Message + Environment.NewLine + exception.StackTrace, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(previousMethodName + @"() " + exception.Message + Environment.NewLine + exception.StackTrace, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|
||||||
if (exception.InnerException != null) {
|
if (exception.InnerException != null) {
|
||||||
LogGenericException(exception.InnerException, previousMethodName);
|
exception = exception.InnerException;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = "") {
|
internal static void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageBox.Show(previousMethodName + "() " + message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
MessageBox.Show(previousMethodName + @"() " + message, Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
}
|
|
||||||
|
|
||||||
internal static void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = "") {
|
|
||||||
if (string.IsNullOrEmpty(nullObjectName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogGenericError(nullObjectName + " is null!", previousMethodName);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
internal static void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = "") {
|
|
||||||
if (string.IsNullOrEmpty(message)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageBox.Show(previousMethodName + "() " + message, "Debug", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,25 +26,27 @@ using System;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ConfigGenerator {
|
namespace ConfigGenerator {
|
||||||
public partial class MainForm : Form {
|
internal sealed partial class MainForm : Form {
|
||||||
private const byte ReservedTabs = 3;
|
private const byte ReservedTabs = 3;
|
||||||
|
|
||||||
private readonly TabPage NewTab = new TabPage { Text = "+" };
|
private readonly TabPage NewTab = new TabPage { Text = @"+" };
|
||||||
private readonly TabPage RemoveTab = new TabPage { Text = "-" };
|
private readonly TabPage RemoveTab = new TabPage { Text = @"-" };
|
||||||
private readonly TabPage RenameTab = new TabPage { Text = "~" };
|
private readonly TabPage RenameTab = new TabPage { Text = @"~" };
|
||||||
|
|
||||||
private ConfigPage ASFTab;
|
private ConfigPage ASFTab;
|
||||||
private TabPage OldTab;
|
private TabPage OldTab;
|
||||||
|
|
||||||
public MainForm() {
|
internal MainForm() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs e) {
|
private void MainForm_Load(object sender, EventArgs e) {
|
||||||
if (sender == null || e == null) {
|
if ((sender == null) || (e == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ namespace ConfigGenerator {
|
|||||||
|
|
||||||
MainTab.TabPages.Add(ASFTab);
|
MainTab.TabPages.Add(ASFTab);
|
||||||
|
|
||||||
foreach (var configFile in Directory.EnumerateFiles(Program.ConfigDirectory, "*.json")) {
|
foreach (string configFile in Directory.EnumerateFiles(Program.ConfigDirectory, "*.json")) {
|
||||||
string botName = Path.GetFileNameWithoutExtension(configFile);
|
string botName = Path.GetFileNameWithoutExtension(configFile);
|
||||||
switch (botName) {
|
switch (botName) {
|
||||||
case Program.ASF:
|
case Program.ASF:
|
||||||
@@ -70,7 +72,7 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void MainTab_Selected(object sender, TabControlEventArgs e) {
|
private void MainTab_Selected(object sender, TabControlEventArgs e) {
|
||||||
if (sender == null || e == null) {
|
if ((sender == null) || (e == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +123,9 @@ namespace ConfigGenerator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get rid of any potential whitespaces in bot name
|
||||||
|
input = Regex.Replace(input, @"\s+", "");
|
||||||
|
|
||||||
configPage.ASFConfig.Rename(input);
|
configPage.ASFConfig.Rename(input);
|
||||||
configPage.RefreshText();
|
configPage.RefreshText();
|
||||||
} else if (e.TabPage == NewTab) {
|
} else if (e.TabPage == NewTab) {
|
||||||
@@ -144,12 +149,13 @@ namespace ConfigGenerator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ASFConfig config in ASFConfig.ASFConfigs) {
|
// Get rid of any potential whitespaces in bot name
|
||||||
if (Path.GetFileNameWithoutExtension(config.FilePath).Equals(input)) {
|
input = Regex.Replace(input, @"\s+", "");
|
||||||
|
|
||||||
|
if (ASFConfig.ASFConfigs.Select(config => Path.GetFileNameWithoutExtension(config.FilePath)).Any(fileNameWithoutExtension => (fileNameWithoutExtension == null) || fileNameWithoutExtension.Equals(input))) {
|
||||||
Logging.LogGenericError("Bot with such name exists already!");
|
Logging.LogGenericError("Bot with such name exists already!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
input = Path.Combine(Program.ConfigDirectory, input + ".json");
|
input = Path.Combine(Program.ConfigDirectory, input + ".json");
|
||||||
|
|
||||||
@@ -163,7 +169,7 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void MainTab_Deselecting(object sender, TabControlCancelEventArgs e) {
|
private void MainTab_Deselecting(object sender, TabControlCancelEventArgs e) {
|
||||||
if (sender == null || e == null) {
|
if ((sender == null) || (e == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +177,7 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Shown(object sender, EventArgs e) {
|
private void MainForm_Shown(object sender, EventArgs e) {
|
||||||
if (sender == null || e == null) {
|
if ((sender == null) || (e == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +185,7 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_HelpButtonClicked(object sender, CancelEventArgs e) {
|
private void MainForm_HelpButtonClicked(object sender, CancelEventArgs e) {
|
||||||
if (sender == null || e == null) {
|
if ((sender == null) || (e == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace ConfigGenerator {
|
|||||||
|
|
||||||
private const string ASFDirectory = "ArchiSteamFarm";
|
private const string ASFDirectory = "ArchiSteamFarm";
|
||||||
|
|
||||||
private static readonly string ExecutableDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
private static readonly string ExecutableDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
@@ -61,11 +61,13 @@ namespace ConfigGenerator {
|
|||||||
// Common structure is bin/(x64/)Debug/ArchiSteamFarm.exe, so we allow up to 4 directories up
|
// Common structure is bin/(x64/)Debug/ArchiSteamFarm.exe, so we allow up to 4 directories up
|
||||||
for (byte i = 0; i < 4; i++) {
|
for (byte i = 0; i < 4; i++) {
|
||||||
Directory.SetCurrentDirectory("..");
|
Directory.SetCurrentDirectory("..");
|
||||||
if (Directory.Exists(ASFDirectory)) {
|
if (!Directory.Exists(ASFDirectory)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Directory.SetCurrentDirectory(ASFDirectory);
|
Directory.SetCurrentDirectory(ASFDirectory);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If config directory doesn't exist after our adjustment, abort all of that
|
// If config directory doesn't exist after our adjustment, abort all of that
|
||||||
if (!Directory.Exists(ConfigDirectory)) {
|
if (!Directory.Exists(ConfigDirectory)) {
|
||||||
@@ -73,14 +75,16 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Directory.Exists(ConfigDirectory)) {
|
if (Directory.Exists(ConfigDirectory)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Logging.LogGenericError("Config directory could not be found!");
|
Logging.LogGenericError("Config directory could not be found!");
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
|
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
|
||||||
if (sender == null || args == null) {
|
if ((sender == null) || (args == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +92,7 @@ namespace ConfigGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) {
|
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) {
|
||||||
if (sender == null || args == null) {
|
if ((sender == null) || (args == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
@@ -10,7 +9,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("ConfigGenerator")]
|
[assembly: AssemblyProduct("ConfigGenerator")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
[assembly: AssemblyCopyright("Copyright © ArchiSteamFarm 2015-2016")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
|||||||
75
ConfigGenerator/Properties/Resources.Designer.cs
generated
75
ConfigGenerator/Properties/Resources.Designer.cs
generated
@@ -9,6 +9,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace ConfigGenerator.Properties {
|
namespace ConfigGenerator.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -37,7 +38,7 @@ namespace ConfigGenerator.Properties {
|
|||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
get {
|
get {
|
||||||
if ((resourceMan == null)) {
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConfigGenerator.Properties.Resources", typeof(Resources).Assembly);
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConfigGenerator.Properties.Resources", typeof(Resources).Assembly);
|
||||||
resourceMan = temp;
|
resourceMan = temp;
|
||||||
}
|
}
|
||||||
@@ -58,5 +59,77 @@ namespace ConfigGenerator.Properties {
|
|||||||
resourceCulture = value;
|
resourceCulture = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Cancel.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Cancel {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Cancel", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Error.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Error {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Error", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Exception.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Exception {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Exception", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Information.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Information {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Information", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to No.
|
||||||
|
/// </summary>
|
||||||
|
internal static string No {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("No", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to OK.
|
||||||
|
/// </summary>
|
||||||
|
internal static string OK {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("OK", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Warning.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Warning {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Warning", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Yes.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Yes {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Yes", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,4 +114,28 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<data name="Information" xml:space="preserve">
|
||||||
|
<value>Information</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error" xml:space="preserve">
|
||||||
|
<value>Error</value>
|
||||||
|
</data>
|
||||||
|
<data name="Exception" xml:space="preserve">
|
||||||
|
<value>Exception</value>
|
||||||
|
</data>
|
||||||
|
<data name="Warning" xml:space="preserve">
|
||||||
|
<value>Warning</value>
|
||||||
|
</data>
|
||||||
|
<data name="OK" xml:space="preserve">
|
||||||
|
<value>OK</value>
|
||||||
|
</data>
|
||||||
|
<data name="Cancel" xml:space="preserve">
|
||||||
|
<value>Cancel</value>
|
||||||
|
</data>
|
||||||
|
<data name="Yes" xml:space="preserve">
|
||||||
|
<value>Yes</value>
|
||||||
|
</data>
|
||||||
|
<data name="No" xml:space="preserve">
|
||||||
|
<value>No</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -35,15 +35,15 @@ namespace ConfigGenerator {
|
|||||||
BotEnabled,
|
BotEnabled,
|
||||||
BotReady,
|
BotReady,
|
||||||
GlobalConfigOpened,
|
GlobalConfigOpened,
|
||||||
GlobalConfigReady,
|
GlobalConfigReady
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool Enabled { get; set; } = true;
|
internal static bool Enabled { private get; set; } = true;
|
||||||
|
|
||||||
private static EPhase NextPhase = EPhase.Start;
|
private static EPhase NextPhase = EPhase.Start;
|
||||||
|
|
||||||
internal static void OnAction(EPhase phase) {
|
internal static void OnAction(EPhase phase) {
|
||||||
if (!Enabled || phase != NextPhase) {
|
if (!Enabled || (phase != NextPhase)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,20 +61,20 @@ namespace ConfigGenerator {
|
|||||||
Logging.LogGenericInfo("Please click the help button to continue.");
|
Logging.LogGenericInfo("Please click the help button to continue.");
|
||||||
break;
|
break;
|
||||||
case EPhase.Help:
|
case EPhase.Help:
|
||||||
Logging.LogGenericInfo("That's right! On ASF wiki you can find detailed help about every config property you're going to configure in a moment.");
|
Logging.LogGenericInfo("Well done! On ASF wiki you can find detailed help about every config property you're going to configure in a moment.");
|
||||||
break;
|
break;
|
||||||
case EPhase.HelpFinished:
|
case EPhase.HelpFinished:
|
||||||
Logging.LogGenericInfo("Alright, let's start configuring our ASF. Click on the plus [+] button to add your first steam account to ASF!");
|
Logging.LogGenericInfo("Alright, let's start configuring our ASF. Click on the plus [+] button to add your first steam account to ASF!");
|
||||||
break;
|
break;
|
||||||
case EPhase.BotNickname:
|
case EPhase.BotNickname:
|
||||||
Logging.LogGenericInfo("That's right! You'll be asked for your bot name now. A good example would be a nickname that you're using for the steam account you're configuring right now, or any other name of your choice which will be easy for you to connect with bot instance that is being configured.");
|
Logging.LogGenericInfo("Good job! You'll be asked for your bot name now. A good example would be a nickname that you're using for the steam account you're configuring right now, or any other name of your choice which will be easy for you to connect with bot instance that is being configured. Please don't use spaces in the name.");
|
||||||
break;
|
break;
|
||||||
case EPhase.BotNicknameFinished:
|
case EPhase.BotNicknameFinished:
|
||||||
Logging.LogGenericInfo("As you can see your bot config is now ready to configure!");
|
Logging.LogGenericInfo("As you can see your bot config is now ready to configure!");
|
||||||
Logging.LogGenericInfo("First thing that you want to do is switching \"Enabled\" property from False to True, try it!");
|
Logging.LogGenericInfo("First thing that you want to do is switching \"Enabled\" property from False to True, try it!");
|
||||||
break;
|
break;
|
||||||
case EPhase.BotEnabled:
|
case EPhase.BotEnabled:
|
||||||
Logging.LogGenericInfo("That's right! Now your bot instance is enabled. You need to configure at least 2 more config properties - \"SteamLogin\" and \"SteamPassword\". The tutorial will continue after you're done with it. Remember to visit ASF wiki by clicking the help icon if you're unsure how given property should be configured!");
|
Logging.LogGenericInfo("Excellent! Now your bot instance is enabled. You need to configure at least 2 more config properties - \"SteamLogin\" and \"SteamPassword\". The tutorial will continue after you're done with it. Remember to visit ASF wiki by clicking the help icon if you're unsure how given property should be configured!");
|
||||||
break;
|
break;
|
||||||
case EPhase.BotReady:
|
case EPhase.BotReady:
|
||||||
Logging.LogGenericInfo("If the data you put is proper, then your bot is ready to run! We need to do only one more thing now. Visit global ASF config, which is labelled as \"ASF\" on your config tab.");
|
Logging.LogGenericInfo("If the data you put is proper, then your bot is ready to run! We need to do only one more thing now. Visit global ASF config, which is labelled as \"ASF\" on your config tab.");
|
||||||
@@ -86,7 +86,7 @@ namespace ConfigGenerator {
|
|||||||
case EPhase.GlobalConfigReady:
|
case EPhase.GlobalConfigReady:
|
||||||
Logging.LogGenericInfo("Your ASF is now ready! Simply launch ASF process by double-clicking ASF.exe binary and if you did everything properly, you should now notice that ASF logs in on your account and starts farming. If you have SteamGuard or 2FA authorization enabled, ASF will ask you for that once");
|
Logging.LogGenericInfo("Your ASF is now ready! Simply launch ASF process by double-clicking ASF.exe binary and if you did everything properly, you should now notice that ASF logs in on your account and starts farming. If you have SteamGuard or 2FA authorization enabled, ASF will ask you for that once");
|
||||||
Logging.LogGenericInfo("Congratulations! You've done everything that is needed in order to make ASF \"work\". I highly recommend reading the wiki now, as ASF offers some really neat features for you to configure, such as offline farming or deciding upon most efficient cards farming algorithm.");
|
Logging.LogGenericInfo("Congratulations! You've done everything that is needed in order to make ASF \"work\". I highly recommend reading the wiki now, as ASF offers some really neat features for you to configure, such as offline farming or deciding upon most efficient cards farming algorithm.");
|
||||||
Logging.LogGenericInfo("If you'd like to add another steam account for farming, simply click the plus [+] button and add another instance. You can also rename bots and remove them with 2 other buttons. Good luck!");
|
Logging.LogGenericInfo("If you'd like to add another steam account for farming, simply click the plus [+] button and add another instance. You can also rename bots [~] and remove them [-]. Good luck!");
|
||||||
Enabled = false;
|
Enabled = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
6
GUI/App.config
Normal file
6
GUI/App.config
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
||||||
35
GUI/Debugging.cs
Normal file
35
GUI/Debugging.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
_ _ _ ____ _ _____
|
||||||
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||||
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||||
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
|
|
||||||
|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
|
||||||
|
Contact: JustArchi@JustArchi.net
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
internal static class Debugging {
|
||||||
|
#if DEBUG
|
||||||
|
internal static readonly bool IsDebugBuild = true;
|
||||||
|
#else
|
||||||
|
internal static readonly bool IsDebugBuild = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
internal static bool IsReleaseBuild => !IsDebugBuild;
|
||||||
|
}
|
||||||
|
}
|
||||||
513
GUI/Form1.Designer.cs
generated
Normal file
513
GUI/Form1.Designer.cs
generated
Normal file
@@ -0,0 +1,513 @@
|
|||||||
|
namespace GUI {
|
||||||
|
partial class Form1 {
|
||||||
|
/// <summary>
|
||||||
|
/// Erforderliche Designervariable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verwendete Ressourcen bereinigen.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
|
||||||
|
protected override void Dispose(bool disposing) {
|
||||||
|
if (disposing && (components != null)) {
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Vom Windows Form-Designer generierter Code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Erforderliche Methode für die Designerunterstützung.
|
||||||
|
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent() {
|
||||||
|
this.components = new System.ComponentModel.Container();
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
|
||||||
|
this.button5 = new System.Windows.Forms.Button();
|
||||||
|
this.button4 = new System.Windows.Forms.Button();
|
||||||
|
this.button3 = new System.Windows.Forms.Button();
|
||||||
|
this.button2 = new System.Windows.Forms.Button();
|
||||||
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.textBox2 = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
||||||
|
this.checkBox3 = new System.Windows.Forms.CheckBox();
|
||||||
|
this.checkBox2 = new System.Windows.Forms.CheckBox();
|
||||||
|
this.checkBox1 = new System.Windows.Forms.CheckBox();
|
||||||
|
this.textBox3 = new System.Windows.Forms.TextBox();
|
||||||
|
this.ASFGUI = new System.Windows.Forms.NotifyIcon(this.components);
|
||||||
|
this.checkBox4 = new System.Windows.Forms.CheckBox();
|
||||||
|
this.button6 = new System.Windows.Forms.Button();
|
||||||
|
this.button7 = new System.Windows.Forms.Button();
|
||||||
|
this.button8 = new System.Windows.Forms.Button();
|
||||||
|
this.button9 = new System.Windows.Forms.Button();
|
||||||
|
this.button10 = new System.Windows.Forms.Button();
|
||||||
|
this.button11 = new System.Windows.Forms.Button();
|
||||||
|
this.button12 = new System.Windows.Forms.Button();
|
||||||
|
this.button13 = new System.Windows.Forms.Button();
|
||||||
|
this.button14 = new System.Windows.Forms.Button();
|
||||||
|
this.button15 = new System.Windows.Forms.Button();
|
||||||
|
this.button16 = new System.Windows.Forms.Button();
|
||||||
|
this.button17 = new System.Windows.Forms.Button();
|
||||||
|
this.button18 = new System.Windows.Forms.Button();
|
||||||
|
this.button19 = new System.Windows.Forms.Button();
|
||||||
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
|
this.label4 = new System.Windows.Forms.Label();
|
||||||
|
this.button20 = new System.Windows.Forms.Button();
|
||||||
|
this.label5 = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// button5
|
||||||
|
//
|
||||||
|
this.button5.Location = new System.Drawing.Point(86, 204);
|
||||||
|
this.button5.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button5.Name = "button5";
|
||||||
|
this.button5.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button5.TabIndex = 27;
|
||||||
|
this.button5.Text = "2fa ok";
|
||||||
|
this.button5.UseVisualStyleBackColor = true;
|
||||||
|
this.button5.Click += new System.EventHandler(this.button5_Click);
|
||||||
|
//
|
||||||
|
// button4
|
||||||
|
//
|
||||||
|
this.button4.Location = new System.Drawing.Point(26, 204);
|
||||||
|
this.button4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button4.Name = "button4";
|
||||||
|
this.button4.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button4.TabIndex = 26;
|
||||||
|
this.button4.Text = "2fa code";
|
||||||
|
this.button4.UseVisualStyleBackColor = true;
|
||||||
|
this.button4.Click += new System.EventHandler(this.button4_Click);
|
||||||
|
//
|
||||||
|
// button3
|
||||||
|
//
|
||||||
|
this.button3.Location = new System.Drawing.Point(26, 286);
|
||||||
|
this.button3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button3.Name = "button3";
|
||||||
|
this.button3.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button3.TabIndex = 24;
|
||||||
|
this.button3.Text = "Redeem";
|
||||||
|
this.button3.UseVisualStyleBackColor = true;
|
||||||
|
this.button3.Click += new System.EventHandler(this.button3_Click);
|
||||||
|
//
|
||||||
|
// button2
|
||||||
|
//
|
||||||
|
this.button2.Location = new System.Drawing.Point(26, 171);
|
||||||
|
this.button2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button2.Name = "button2";
|
||||||
|
this.button2.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button2.TabIndex = 23;
|
||||||
|
this.button2.Text = "Loot";
|
||||||
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
|
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
this.button1.Location = new System.Drawing.Point(169, 130);
|
||||||
|
this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button1.Name = "button1";
|
||||||
|
this.button1.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button1.TabIndex = 22;
|
||||||
|
this.button1.Text = "Send";
|
||||||
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(579, 13);
|
||||||
|
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(39, 13);
|
||||||
|
this.label2.TabIndex = 21;
|
||||||
|
this.label2.Text = "Output";
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(258, 39);
|
||||||
|
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(31, 13);
|
||||||
|
this.label1.TabIndex = 20;
|
||||||
|
this.label1.Text = "Input";
|
||||||
|
//
|
||||||
|
// textBox2
|
||||||
|
//
|
||||||
|
this.textBox2.Location = new System.Drawing.Point(413, 34);
|
||||||
|
this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.textBox2.Multiline = true;
|
||||||
|
this.textBox2.Name = "textBox2";
|
||||||
|
this.textBox2.ReadOnly = true;
|
||||||
|
this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||||
|
this.textBox2.Size = new System.Drawing.Size(432, 370);
|
||||||
|
this.textBox2.TabIndex = 19;
|
||||||
|
//
|
||||||
|
// textBox1
|
||||||
|
//
|
||||||
|
this.textBox1.Location = new System.Drawing.Point(169, 61);
|
||||||
|
this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.textBox1.Multiline = true;
|
||||||
|
this.textBox1.Name = "textBox1";
|
||||||
|
this.textBox1.Size = new System.Drawing.Size(223, 65);
|
||||||
|
this.textBox1.TabIndex = 18;
|
||||||
|
//
|
||||||
|
// comboBox1
|
||||||
|
//
|
||||||
|
this.comboBox1.FormattingEnabled = true;
|
||||||
|
this.comboBox1.Location = new System.Drawing.Point(26, 116);
|
||||||
|
this.comboBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.comboBox1.Name = "comboBox1";
|
||||||
|
this.comboBox1.Size = new System.Drawing.Size(92, 21);
|
||||||
|
this.comboBox1.TabIndex = 17;
|
||||||
|
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// checkBox3
|
||||||
|
//
|
||||||
|
this.checkBox3.AutoSize = true;
|
||||||
|
this.checkBox3.Location = new System.Drawing.Point(26, 94);
|
||||||
|
this.checkBox3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.checkBox3.Name = "checkBox3";
|
||||||
|
this.checkBox3.Size = new System.Drawing.Size(102, 17);
|
||||||
|
this.checkBox3.TabIndex = 16;
|
||||||
|
this.checkBox3.Text = "Send to specific";
|
||||||
|
this.checkBox3.UseVisualStyleBackColor = true;
|
||||||
|
this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
|
||||||
|
//
|
||||||
|
// checkBox2
|
||||||
|
//
|
||||||
|
this.checkBox2.AutoSize = true;
|
||||||
|
this.checkBox2.Location = new System.Drawing.Point(26, 72);
|
||||||
|
this.checkBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.checkBox2.Name = "checkBox2";
|
||||||
|
this.checkBox2.Size = new System.Drawing.Size(100, 17);
|
||||||
|
this.checkBox2.TabIndex = 15;
|
||||||
|
this.checkBox2.Text = "Send to all Bots";
|
||||||
|
this.checkBox2.UseVisualStyleBackColor = true;
|
||||||
|
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
|
||||||
|
//
|
||||||
|
// checkBox1
|
||||||
|
//
|
||||||
|
this.checkBox1.AutoSize = true;
|
||||||
|
this.checkBox1.Location = new System.Drawing.Point(107, 11);
|
||||||
|
this.checkBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.checkBox1.Name = "checkBox1";
|
||||||
|
this.checkBox1.Size = new System.Drawing.Size(74, 17);
|
||||||
|
this.checkBox1.TabIndex = 14;
|
||||||
|
this.checkBox1.Text = "Safemode";
|
||||||
|
this.checkBox1.UseVisualStyleBackColor = true;
|
||||||
|
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
|
||||||
|
//
|
||||||
|
// textBox3
|
||||||
|
//
|
||||||
|
this.textBox3.Location = new System.Drawing.Point(26, 387);
|
||||||
|
this.textBox3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.textBox3.Name = "textBox3";
|
||||||
|
this.textBox3.Size = new System.Drawing.Size(366, 20);
|
||||||
|
this.textBox3.TabIndex = 28;
|
||||||
|
this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
|
||||||
|
//
|
||||||
|
// ASFGUI
|
||||||
|
//
|
||||||
|
this.ASFGUI.Text = "notifyIcon1";
|
||||||
|
this.ASFGUI.Visible = true;
|
||||||
|
this.ASFGUI.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.ASFGUI_MouseDoubleClick);
|
||||||
|
//
|
||||||
|
// checkBox4
|
||||||
|
//
|
||||||
|
this.checkBox4.AutoSize = true;
|
||||||
|
this.checkBox4.Location = new System.Drawing.Point(26, 11);
|
||||||
|
this.checkBox4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.checkBox4.Name = "checkBox4";
|
||||||
|
this.checkBox4.Size = new System.Drawing.Size(83, 17);
|
||||||
|
this.checkBox4.TabIndex = 29;
|
||||||
|
this.checkBox4.Text = "Send to any";
|
||||||
|
this.checkBox4.UseVisualStyleBackColor = true;
|
||||||
|
this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged);
|
||||||
|
//
|
||||||
|
// button6
|
||||||
|
//
|
||||||
|
this.button6.Location = new System.Drawing.Point(26, 41);
|
||||||
|
this.button6.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button6.Name = "button6";
|
||||||
|
this.button6.Size = new System.Drawing.Size(94, 27);
|
||||||
|
this.button6.TabIndex = 30;
|
||||||
|
this.button6.Text = "generate Botlist";
|
||||||
|
this.button6.UseVisualStyleBackColor = true;
|
||||||
|
this.button6.Click += new System.EventHandler(this.button6_Click);
|
||||||
|
//
|
||||||
|
// button7
|
||||||
|
//
|
||||||
|
this.button7.Location = new System.Drawing.Point(147, 204);
|
||||||
|
this.button7.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button7.Name = "button7";
|
||||||
|
this.button7.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button7.TabIndex = 31;
|
||||||
|
this.button7.Text = "2fano";
|
||||||
|
this.button7.UseVisualStyleBackColor = true;
|
||||||
|
this.button7.Click += new System.EventHandler(this.button7_Click);
|
||||||
|
//
|
||||||
|
// button8
|
||||||
|
//
|
||||||
|
this.button8.Location = new System.Drawing.Point(87, 286);
|
||||||
|
this.button8.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button8.Name = "button8";
|
||||||
|
this.button8.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button8.TabIndex = 32;
|
||||||
|
this.button8.Text = "2faoff";
|
||||||
|
this.button8.UseVisualStyleBackColor = true;
|
||||||
|
this.button8.Click += new System.EventHandler(this.button8_Click);
|
||||||
|
//
|
||||||
|
// button9
|
||||||
|
//
|
||||||
|
this.button9.Location = new System.Drawing.Point(148, 286);
|
||||||
|
this.button9.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button9.Name = "button9";
|
||||||
|
this.button9.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button9.TabIndex = 33;
|
||||||
|
this.button9.Text = "exit";
|
||||||
|
this.button9.UseVisualStyleBackColor = true;
|
||||||
|
this.button9.Click += new System.EventHandler(this.button9_Click);
|
||||||
|
//
|
||||||
|
// button10
|
||||||
|
//
|
||||||
|
this.button10.Location = new System.Drawing.Point(86, 171);
|
||||||
|
this.button10.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button10.Name = "button10";
|
||||||
|
this.button10.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button10.TabIndex = 34;
|
||||||
|
this.button10.Text = "farm";
|
||||||
|
this.button10.UseVisualStyleBackColor = true;
|
||||||
|
this.button10.Click += new System.EventHandler(this.button10_Click);
|
||||||
|
//
|
||||||
|
// button11
|
||||||
|
//
|
||||||
|
this.button11.Location = new System.Drawing.Point(147, 171);
|
||||||
|
this.button11.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button11.Name = "button11";
|
||||||
|
this.button11.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button11.TabIndex = 35;
|
||||||
|
this.button11.Text = "help";
|
||||||
|
this.button11.UseVisualStyleBackColor = true;
|
||||||
|
this.button11.Click += new System.EventHandler(this.button11_Click);
|
||||||
|
//
|
||||||
|
// button12
|
||||||
|
//
|
||||||
|
this.button12.Location = new System.Drawing.Point(208, 171);
|
||||||
|
this.button12.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button12.Name = "button12";
|
||||||
|
this.button12.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button12.TabIndex = 36;
|
||||||
|
this.button12.Text = "start";
|
||||||
|
this.button12.UseVisualStyleBackColor = true;
|
||||||
|
this.button12.Click += new System.EventHandler(this.button12_Click);
|
||||||
|
//
|
||||||
|
// button13
|
||||||
|
//
|
||||||
|
this.button13.Location = new System.Drawing.Point(268, 171);
|
||||||
|
this.button13.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button13.Name = "button13";
|
||||||
|
this.button13.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button13.TabIndex = 37;
|
||||||
|
this.button13.Text = "stop";
|
||||||
|
this.button13.UseVisualStyleBackColor = true;
|
||||||
|
this.button13.Click += new System.EventHandler(this.button13_Click);
|
||||||
|
//
|
||||||
|
// button14
|
||||||
|
//
|
||||||
|
this.button14.Location = new System.Drawing.Point(329, 171);
|
||||||
|
this.button14.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button14.Name = "button14";
|
||||||
|
this.button14.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button14.TabIndex = 38;
|
||||||
|
this.button14.Text = "pause";
|
||||||
|
this.button14.UseVisualStyleBackColor = true;
|
||||||
|
this.button14.Click += new System.EventHandler(this.button14_Click);
|
||||||
|
//
|
||||||
|
// button15
|
||||||
|
//
|
||||||
|
this.button15.Location = new System.Drawing.Point(268, 204);
|
||||||
|
this.button15.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button15.Name = "button15";
|
||||||
|
this.button15.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button15.TabIndex = 39;
|
||||||
|
this.button15.Text = "status";
|
||||||
|
this.button15.UseVisualStyleBackColor = true;
|
||||||
|
this.button15.Click += new System.EventHandler(this.button15_Click);
|
||||||
|
//
|
||||||
|
// button16
|
||||||
|
//
|
||||||
|
this.button16.Location = new System.Drawing.Point(329, 204);
|
||||||
|
this.button16.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button16.Name = "button16";
|
||||||
|
this.button16.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button16.TabIndex = 40;
|
||||||
|
this.button16.Text = "status all";
|
||||||
|
this.button16.UseVisualStyleBackColor = true;
|
||||||
|
this.button16.Click += new System.EventHandler(this.button16_Click);
|
||||||
|
//
|
||||||
|
// button17
|
||||||
|
//
|
||||||
|
this.button17.Location = new System.Drawing.Point(26, 318);
|
||||||
|
this.button17.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button17.Name = "button17";
|
||||||
|
this.button17.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button17.TabIndex = 41;
|
||||||
|
this.button17.Text = "owns";
|
||||||
|
this.button17.UseVisualStyleBackColor = true;
|
||||||
|
this.button17.Click += new System.EventHandler(this.button17_Click);
|
||||||
|
//
|
||||||
|
// button18
|
||||||
|
//
|
||||||
|
this.button18.Location = new System.Drawing.Point(147, 318);
|
||||||
|
this.button18.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button18.Name = "button18";
|
||||||
|
this.button18.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button18.TabIndex = 42;
|
||||||
|
this.button18.Text = "addlicense";
|
||||||
|
this.button18.UseVisualStyleBackColor = true;
|
||||||
|
this.button18.Click += new System.EventHandler(this.button18_Click);
|
||||||
|
//
|
||||||
|
// button19
|
||||||
|
//
|
||||||
|
this.button19.Location = new System.Drawing.Point(87, 318);
|
||||||
|
this.button19.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button19.Name = "button19";
|
||||||
|
this.button19.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button19.TabIndex = 43;
|
||||||
|
this.button19.Text = "play";
|
||||||
|
this.button19.UseVisualStyleBackColor = true;
|
||||||
|
this.button19.Click += new System.EventHandler(this.button19_Click);
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
this.label3.AutoSize = true;
|
||||||
|
this.label3.Location = new System.Drawing.Point(24, 245);
|
||||||
|
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||||
|
this.label3.Name = "label3";
|
||||||
|
this.label3.Size = new System.Drawing.Size(235, 13);
|
||||||
|
this.label3.TabIndex = 44;
|
||||||
|
this.label3.Text = "The following do not work with \"Send to all\" and";
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
this.label4.AutoSize = true;
|
||||||
|
this.label4.Location = new System.Drawing.Point(24, 259);
|
||||||
|
this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||||
|
this.label4.Name = "label4";
|
||||||
|
this.label4.Size = new System.Drawing.Size(224, 13);
|
||||||
|
this.label4.TabIndex = 45;
|
||||||
|
this.label4.Text = "require confirmation even without \"Safemode\"";
|
||||||
|
//
|
||||||
|
// button20
|
||||||
|
//
|
||||||
|
this.button20.Location = new System.Drawing.Point(231, 130);
|
||||||
|
this.button20.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button20.Name = "button20";
|
||||||
|
this.button20.Size = new System.Drawing.Size(56, 19);
|
||||||
|
this.button20.TabIndex = 46;
|
||||||
|
this.button20.Text = "clear";
|
||||||
|
this.button20.UseVisualStyleBackColor = true;
|
||||||
|
this.button20.Click += new System.EventHandler(this.button20_Click);
|
||||||
|
//
|
||||||
|
// label5
|
||||||
|
//
|
||||||
|
this.label5.AutoSize = true;
|
||||||
|
this.label5.Location = new System.Drawing.Point(29, 370);
|
||||||
|
this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||||
|
this.label5.Name = "label5";
|
||||||
|
this.label5.Size = new System.Drawing.Size(221, 13);
|
||||||
|
this.label5.TabIndex = 47;
|
||||||
|
this.label5.Text = "If you don\'t know what this is... Don\'t touch it!";
|
||||||
|
//
|
||||||
|
// Form1
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(854, 414);
|
||||||
|
this.Controls.Add(this.label5);
|
||||||
|
this.Controls.Add(this.button20);
|
||||||
|
this.Controls.Add(this.label4);
|
||||||
|
this.Controls.Add(this.label3);
|
||||||
|
this.Controls.Add(this.button19);
|
||||||
|
this.Controls.Add(this.button18);
|
||||||
|
this.Controls.Add(this.button17);
|
||||||
|
this.Controls.Add(this.button16);
|
||||||
|
this.Controls.Add(this.button15);
|
||||||
|
this.Controls.Add(this.button14);
|
||||||
|
this.Controls.Add(this.button13);
|
||||||
|
this.Controls.Add(this.button12);
|
||||||
|
this.Controls.Add(this.button11);
|
||||||
|
this.Controls.Add(this.button10);
|
||||||
|
this.Controls.Add(this.button9);
|
||||||
|
this.Controls.Add(this.button8);
|
||||||
|
this.Controls.Add(this.button7);
|
||||||
|
this.Controls.Add(this.button6);
|
||||||
|
this.Controls.Add(this.checkBox4);
|
||||||
|
this.Controls.Add(this.textBox3);
|
||||||
|
this.Controls.Add(this.button5);
|
||||||
|
this.Controls.Add(this.button4);
|
||||||
|
this.Controls.Add(this.button3);
|
||||||
|
this.Controls.Add(this.button2);
|
||||||
|
this.Controls.Add(this.button1);
|
||||||
|
this.Controls.Add(this.label2);
|
||||||
|
this.Controls.Add(this.label1);
|
||||||
|
this.Controls.Add(this.textBox2);
|
||||||
|
this.Controls.Add(this.textBox1);
|
||||||
|
this.Controls.Add(this.comboBox1);
|
||||||
|
this.Controls.Add(this.checkBox3);
|
||||||
|
this.Controls.Add(this.checkBox2);
|
||||||
|
this.Controls.Add(this.checkBox1);
|
||||||
|
this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.Name = "Form1";
|
||||||
|
this.Text = "Form1";
|
||||||
|
this.Load += new System.EventHandler(this.Form1_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button button5;
|
||||||
|
private System.Windows.Forms.Button button4;
|
||||||
|
private System.Windows.Forms.Button button3;
|
||||||
|
private System.Windows.Forms.Button button2;
|
||||||
|
private System.Windows.Forms.Button button1;
|
||||||
|
private System.Windows.Forms.Label label2;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
|
private System.Windows.Forms.TextBox textBox2;
|
||||||
|
private System.Windows.Forms.TextBox textBox1;
|
||||||
|
private System.Windows.Forms.ComboBox comboBox1;
|
||||||
|
private System.Windows.Forms.CheckBox checkBox3;
|
||||||
|
private System.Windows.Forms.CheckBox checkBox2;
|
||||||
|
private System.Windows.Forms.CheckBox checkBox1;
|
||||||
|
private System.Windows.Forms.TextBox textBox3;
|
||||||
|
private System.Windows.Forms.NotifyIcon ASFGUI;
|
||||||
|
private System.Windows.Forms.CheckBox checkBox4;
|
||||||
|
private System.Windows.Forms.Button button6;
|
||||||
|
private System.Windows.Forms.Button button7;
|
||||||
|
private System.Windows.Forms.Button button8;
|
||||||
|
private System.Windows.Forms.Button button9;
|
||||||
|
private System.Windows.Forms.Button button10;
|
||||||
|
private System.Windows.Forms.Button button11;
|
||||||
|
private System.Windows.Forms.Button button12;
|
||||||
|
private System.Windows.Forms.Button button13;
|
||||||
|
private System.Windows.Forms.Button button14;
|
||||||
|
private System.Windows.Forms.Button button15;
|
||||||
|
private System.Windows.Forms.Button button16;
|
||||||
|
private System.Windows.Forms.Button button17;
|
||||||
|
private System.Windows.Forms.Button button18;
|
||||||
|
private System.Windows.Forms.Button button19;
|
||||||
|
private System.Windows.Forms.Label label3;
|
||||||
|
private System.Windows.Forms.Label label4;
|
||||||
|
private System.Windows.Forms.Button button20;
|
||||||
|
private System.Windows.Forms.Label label5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
310
GUI/Form1.cs
Normal file
310
GUI/Form1.cs
Normal file
@@ -0,0 +1,310 @@
|
|||||||
|
/*
|
||||||
|
_ _ _ ____ _ _____
|
||||||
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||||
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||||
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
|
|
||||||
|
Copyright 2015-2016 Florian "KlappPC" Lang
|
||||||
|
Contact: ichhoeremusik@gmx.net
|
||||||
|
|
||||||
|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
|
||||||
|
Contact: JustArchi@JustArchi.net
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.ServiceModel;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
public partial class Form1 : Form {
|
||||||
|
private bool safeMode = false;
|
||||||
|
private bool sendAll = false;
|
||||||
|
private bool sendAny = true;
|
||||||
|
private bool sendOne = false;
|
||||||
|
private string botName = "";
|
||||||
|
string[] botList;
|
||||||
|
private string URL = "";
|
||||||
|
ServerProcess proc;
|
||||||
|
private Client Client;
|
||||||
|
public Form1() {
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
// So either the ASF.exe is in the same directory, or we assume development environment.
|
||||||
|
string ASF = "ASF.exe";
|
||||||
|
if (!File.Exists(ASF)) {
|
||||||
|
ASF = "../../../ArchiSteamFarm/bin/" + (Debugging.IsDebugBuild ? "Debug" : "Release") + "/ArchiSteamFarm.exe";
|
||||||
|
if (!File.Exists(ASF)) {
|
||||||
|
Logging.LogGenericError("ASF binary could not be found!");
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proc = new ServerProcess(ASF, "--server", textBox2);
|
||||||
|
proc.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnFormClosing(FormClosingEventArgs e) {
|
||||||
|
proc.Stop();
|
||||||
|
base.OnFormClosing(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a single command. can be lead by a ! but it does not have to.
|
||||||
|
*/
|
||||||
|
private string sendCommand(string command) {
|
||||||
|
if (command.StartsWith("!")) {
|
||||||
|
command = command.Substring(1);
|
||||||
|
}
|
||||||
|
if (Client == null) {
|
||||||
|
Client = new Client(new BasicHttpBinding(), new EndpointAddress(URL));
|
||||||
|
}
|
||||||
|
return Client.HandleCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximize again when double clicked on tray icon
|
||||||
|
*/
|
||||||
|
private void ASFGUI_MouseDoubleClick(object sender, MouseEventArgs e) {
|
||||||
|
this.Show();
|
||||||
|
this.WindowState = FormWindowState.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Form1_Load(object sender, System.EventArgs e) {
|
||||||
|
this.Resize += new System.EventHandler(this.Form1_Resize);
|
||||||
|
textBox2.ScrollBars = ScrollBars.Vertical;
|
||||||
|
textBox1.ScrollBars = ScrollBars.Vertical;
|
||||||
|
checkBox4.Checked = true;
|
||||||
|
textBox3.Text = "http://localhost:1242/ASF";
|
||||||
|
URL = "http://localhost:1242/ASF";
|
||||||
|
textBox2.Anchor = (AnchorStyles.Right | AnchorStyles.Left);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Minimize to tray instead of taskbar
|
||||||
|
*/
|
||||||
|
private void Form1_Resize(object sender, EventArgs e) {
|
||||||
|
if (FormWindowState.Minimized == this.WindowState) {
|
||||||
|
ASFGUI.Visible = true;
|
||||||
|
this.Hide();
|
||||||
|
} else if (FormWindowState.Normal == this.WindowState) {
|
||||||
|
ASFGUI.Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generate a command from a simple command
|
||||||
|
* That means, adds a botName or makes multiple commands for multiple bots.
|
||||||
|
*/
|
||||||
|
private string generateCommand(string command, string arg = "") {
|
||||||
|
if (sendOne)
|
||||||
|
return command + " " + botName + " " + arg;
|
||||||
|
if (sendAll) {
|
||||||
|
string ret = "";
|
||||||
|
foreach (string str in botList) {
|
||||||
|
ret = ret + command + " " + str + " " + arg + "\r\n";
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return command + arg;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* One of the simple buttons got pressed
|
||||||
|
*/
|
||||||
|
private void buttonPressed(string command) {
|
||||||
|
textBox1.Text = generateCommand(command);
|
||||||
|
if (!safeMode)
|
||||||
|
button1_Click(this, null);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* One of the complicated buttons was pressed
|
||||||
|
* We get an argumentlist
|
||||||
|
*/
|
||||||
|
private void multiCommand(string command) {
|
||||||
|
if (sendAll)
|
||||||
|
return;
|
||||||
|
string[] arr = textBox1.Lines;
|
||||||
|
string cmd = "";
|
||||||
|
for (int i = 0; i < arr.Length; i++) {
|
||||||
|
if (!String.IsNullOrEmpty(arr[i].Trim())) {
|
||||||
|
cmd = cmd + generateCommand(command, arr[i].Trim()) + "\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
textBox1.Text = cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates the WCF URL in case of custom URL
|
||||||
|
*/
|
||||||
|
private void textBox3_TextChanged(object sender, EventArgs e) {
|
||||||
|
URL = textBox3.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
|
||||||
|
botName = comboBox1.SelectedItem.ToString();
|
||||||
|
}
|
||||||
|
//Ok, radiobuttons would have been better I guess, to lazy to change now.
|
||||||
|
private void checkBox3_CheckedChanged(object sender, EventArgs e) {
|
||||||
|
//specific
|
||||||
|
if (checkBox3.Checked) {
|
||||||
|
sendAll = false;
|
||||||
|
sendAny = false;
|
||||||
|
sendOne = true;
|
||||||
|
checkBox2.Checked = false;
|
||||||
|
checkBox4.Checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox2_CheckedChanged(object sender, EventArgs e) {
|
||||||
|
//all
|
||||||
|
if (checkBox2.Checked) {
|
||||||
|
sendAll = true;
|
||||||
|
sendAny = false;
|
||||||
|
sendOne = false;
|
||||||
|
checkBox3.Checked = false;
|
||||||
|
checkBox4.Checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox4_CheckedChanged(object sender, EventArgs e) {
|
||||||
|
//any
|
||||||
|
if (checkBox4.Checked) {
|
||||||
|
sendAll = false;
|
||||||
|
sendAny = true;
|
||||||
|
sendOne = false;
|
||||||
|
checkBox2.Checked = false;
|
||||||
|
checkBox3.Checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox1_CheckedChanged(object sender, EventArgs e) {
|
||||||
|
safeMode = checkBox1.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send command button.
|
||||||
|
*/
|
||||||
|
private void button1_Click(object sender, System.EventArgs e) {
|
||||||
|
for (int i = 0; i < textBox1.Lines.Length; i++) {
|
||||||
|
string command = textBox1.Lines[i];
|
||||||
|
if (!String.IsNullOrEmpty(command.Trim())) {
|
||||||
|
sendCommand(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Update /Generate Botlist button
|
||||||
|
*/
|
||||||
|
private void button6_Click(object sender, EventArgs e) {
|
||||||
|
string ret = sendCommand("statusall");
|
||||||
|
string[] arr = ret.Split('\n');
|
||||||
|
int botAmount = Convert.ToInt16(arr[arr.Length - 1].Split('/')[1].Trim().Split(' ')[0]);
|
||||||
|
botList = new string[botAmount];
|
||||||
|
for (int i = 0; i < botAmount; i++) {
|
||||||
|
botList[i] = arr[arr.Length - 2 - i].Substring(3).Trim().Split(' ')[0];
|
||||||
|
}
|
||||||
|
comboBox1.Items.AddRange(botList);
|
||||||
|
}
|
||||||
|
|
||||||
|
//The Rest are simple buttons.
|
||||||
|
private void button3_Click(object sender, EventArgs e) {
|
||||||
|
multiCommand("redeem");
|
||||||
|
}
|
||||||
|
private void button2_Click(object sender, EventArgs e) {
|
||||||
|
textBox1.Text = generateCommand("loot");
|
||||||
|
if (!safeMode)
|
||||||
|
button1_Click(this, null);
|
||||||
|
}
|
||||||
|
private void button4_Click(object sender, EventArgs e) {
|
||||||
|
//2fa
|
||||||
|
textBox1.Text = generateCommand("2fa");
|
||||||
|
if (!safeMode)
|
||||||
|
button1_Click(this, null);
|
||||||
|
}
|
||||||
|
private void button5_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("2faok");
|
||||||
|
}
|
||||||
|
private void button7_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("2fano");
|
||||||
|
}
|
||||||
|
private void button8_Click(object sender, EventArgs e) {
|
||||||
|
if (sendAll)
|
||||||
|
return;
|
||||||
|
textBox1.Text = generateCommand("2faoff");
|
||||||
|
}
|
||||||
|
private void button9_Click(object sender, EventArgs e) {
|
||||||
|
textBox1.Text = "exit";
|
||||||
|
}
|
||||||
|
private void button10_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("farm");
|
||||||
|
}
|
||||||
|
private void button11_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("help");
|
||||||
|
}
|
||||||
|
private void button12_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("start");
|
||||||
|
}
|
||||||
|
private void button13_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("stop");
|
||||||
|
}
|
||||||
|
private void button14_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("pause");
|
||||||
|
}
|
||||||
|
private void button15_Click(object sender, EventArgs e) {
|
||||||
|
buttonPressed("status");
|
||||||
|
}
|
||||||
|
private void button16_Click(object sender, EventArgs e) {
|
||||||
|
textBox1.Text = "statusall";
|
||||||
|
if (!safeMode)
|
||||||
|
button1_Click(this, null);
|
||||||
|
}
|
||||||
|
private void button17_Click(object sender, EventArgs e) {
|
||||||
|
multiCommand("owns");
|
||||||
|
}
|
||||||
|
private void button18_Click(object sender, EventArgs e) {
|
||||||
|
multiCommand("addlicense");
|
||||||
|
}
|
||||||
|
private void button19_Click(object sender, EventArgs e) {
|
||||||
|
multiCommand("play");
|
||||||
|
}
|
||||||
|
private void button20_Click(object sender, EventArgs e) {
|
||||||
|
textBox1.Text = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//############### After this point copied from Archie's WCF ###################
|
||||||
|
[ServiceContract]
|
||||||
|
interface IWCF {
|
||||||
|
[OperationContract]
|
||||||
|
string HandleCommand(string input);
|
||||||
|
}
|
||||||
|
class Client : ClientBase<IWCF>, IWCF {
|
||||||
|
internal Client(System.ServiceModel.Channels.Binding binding, EndpointAddress address) : base(binding, address) { }
|
||||||
|
|
||||||
|
public string HandleCommand(string input) {
|
||||||
|
try {
|
||||||
|
return Channel.HandleCommand(input);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//Logging.LogGenericException(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6296
GUI/Form1.resx
Normal file
6296
GUI/Form1.resx
Normal file
File diff suppressed because it is too large
Load Diff
84
GUI/Form2.Designer.cs
generated
Normal file
84
GUI/Form2.Designer.cs
generated
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
namespace GUI {
|
||||||
|
partial class Form2 {
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing) {
|
||||||
|
if (disposing && (components != null)) {
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent() {
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
|
||||||
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
this.button1.Location = new System.Drawing.Point(134, 93);
|
||||||
|
this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.button1.Name = "button1";
|
||||||
|
this.button1.Size = new System.Drawing.Size(87, 28);
|
||||||
|
this.button1.TabIndex = 0;
|
||||||
|
this.button1.Text = "OK";
|
||||||
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||||
|
//
|
||||||
|
// textBox1
|
||||||
|
//
|
||||||
|
this.textBox1.Location = new System.Drawing.Point(12, 63);
|
||||||
|
this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.textBox1.Name = "textBox1";
|
||||||
|
this.textBox1.Size = new System.Drawing.Size(336, 20);
|
||||||
|
this.textBox1.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(10, 7);
|
||||||
|
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(35, 13);
|
||||||
|
this.label1.TabIndex = 2;
|
||||||
|
this.label1.Text = "label1";
|
||||||
|
//
|
||||||
|
// Form2
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(356, 132);
|
||||||
|
this.Controls.Add(this.label1);
|
||||||
|
this.Controls.Add(this.textBox1);
|
||||||
|
this.Controls.Add(this.button1);
|
||||||
|
this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||||
|
this.Name = "Form2";
|
||||||
|
this.Text = "Input";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button button1;
|
||||||
|
private System.Windows.Forms.TextBox textBox1;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
GUI/Form2.cs
Normal file
44
GUI/Form2.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
_ _ _ ____ _ _____
|
||||||
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||||
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||||
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
|
|
||||||
|
Copyright 2015-2016 Florian "KlappPC" Lang
|
||||||
|
Contact: ichhoeremusik@gmx.net
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
/**
|
||||||
|
* popup Message when Input is required
|
||||||
|
*/
|
||||||
|
public partial class Form2 : Form {
|
||||||
|
ServerProcess proc;
|
||||||
|
public Form2(ServerProcess proc, string msg) {
|
||||||
|
this.proc = proc;
|
||||||
|
InitializeComponent();
|
||||||
|
label1.Text = msg;
|
||||||
|
button1.DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button1_Click(object sender, EventArgs e) {
|
||||||
|
proc.Write(textBox1.Text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6293
GUI/Form2.resx
Normal file
6293
GUI/Form2.resx
Normal file
File diff suppressed because it is too large
Load Diff
156
GUI/GUI.csproj
Normal file
156
GUI/GUI.csproj
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{599121A9-5887-4522-A3D6-61470B90BAD4}</ProjectGuid>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>GUI</RootNamespace>
|
||||||
|
<AssemblyName>GUI</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<PublishUrl>publish\</PublishUrl>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
<UpdateInterval>7</UpdateInterval>
|
||||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
|
<UpdateRequired>false</UpdateRequired>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>none</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>
|
||||||
|
</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationIcon>cirno.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.ServiceModel" />
|
||||||
|
<Reference Include="System.ServiceModel.Web" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Debugging.cs" />
|
||||||
|
<Compile Include="Form1.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Form1.Designer.cs">
|
||||||
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Form2.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Form2.Designer.cs">
|
||||||
|
<DependentUpon>Form2.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Logging.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ServerProcess.cs" />
|
||||||
|
<EmbeddedResource Include="Form1.resx">
|
||||||
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Form2.resx">
|
||||||
|
<DependentUpon>Form2.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
</Compile>
|
||||||
|
<None Include="app.manifest" />
|
||||||
|
<None Include="Properties\Settings.settings">
|
||||||
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
<Compile Include="Properties\Settings.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<WCFMetadata Include="Service References\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
|
||||||
|
<Install>true</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="cirno.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<!--
|
||||||
|
<PostBuildEvent Condition=" '$(OS)' != 'Unix' AND '$(ConfigurationName)' == 'Release' ">
|
||||||
|
"$(SolutionDir)tools\ILRepack\ILRepack.exe" /ndebug /internalize /parallel /targetplatform:v4 /wildcards /out:"$(SolutionDir)out\ASF-GUI.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll"
|
||||||
|
del "$(SolutionDir)out\ASF-GUI.exe.config"
|
||||||
|
</PostBuildEvent>
|
||||||
|
<PostBuildEvent Condition=" '$(OS)' == 'Unix' AND '$(ConfigurationName)' == 'Release' ">
|
||||||
|
mono -O=all "$(SolutionDir)tools/ILRepack/ILRepack.exe" /ndebug /internalize /parallel /targetplatform:v4 /wildcards /out:"$(SolutionDir)out/ASF-GUI.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll"
|
||||||
|
rm "$(SolutionDir)out/ASF-GUI.exe.config"
|
||||||
|
</PostBuildEvent>
|
||||||
|
-->
|
||||||
|
</PropertyGroup>
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
||||||
93
GUI/Logging.cs
Normal file
93
GUI/Logging.cs
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
_ _ _ ____ _ _____
|
||||||
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||||
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||||
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
|
|
||||||
|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
|
||||||
|
Contact: JustArchi@JustArchi.net
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
internal static class Logging {
|
||||||
|
internal static void LogGenericInfo(string message) {
|
||||||
|
if (string.IsNullOrEmpty(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void LogGenericWTF(string message, [CallerMemberName] string previousMethodName = "") {
|
||||||
|
if (string.IsNullOrEmpty(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(previousMethodName + "() " + message, "WTF", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void LogGenericError(string message, [CallerMemberName] string previousMethodName = "") {
|
||||||
|
if (string.IsNullOrEmpty(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(previousMethodName + "() " + message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = "") {
|
||||||
|
if (exception == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(previousMethodName + "() " + exception.Message + Environment.NewLine + exception.StackTrace, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|
||||||
|
if (exception.InnerException != null) {
|
||||||
|
LogGenericException(exception.InnerException, previousMethodName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = "") {
|
||||||
|
if (string.IsNullOrEmpty(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(previousMethodName + "() " + message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = "") {
|
||||||
|
if (string.IsNullOrEmpty(nullObjectName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogGenericError(nullObjectName + " is null!", previousMethodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Conditional("DEBUG")]
|
||||||
|
internal static void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = "") {
|
||||||
|
if (string.IsNullOrEmpty(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(previousMethodName + "() " + message, "Debug", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
GUI/Program.cs
Normal file
16
GUI/Program.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
static class Program {
|
||||||
|
/// <summary>
|
||||||
|
/// Der Haupteinstiegspunkt für die Anwendung.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main() {
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.Run(new Form1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
GUI/Properties/AssemblyInfo.cs
Normal file
36
GUI/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||||
|
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||||
|
// die mit einer Assembly verknüpft sind.
|
||||||
|
[assembly: AssemblyTitle("GUI")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("GUI")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © ArchiSteamFarm 2015-2016")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||||
|
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||||
|
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||||
|
[assembly: Guid("18b85645-1c80-4e25-9dcb-e01684a48fca")]
|
||||||
|
|
||||||
|
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||||
|
//
|
||||||
|
// Hauptversion
|
||||||
|
// Nebenversion
|
||||||
|
// Buildnummer
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||||
|
// übernehmen, indem Sie "*" eingeben:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
63
GUI/Properties/Resources.Designer.cs
generated
Normal file
63
GUI/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Runtime Version:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace GUI.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||||
|
/// </summary>
|
||||||
|
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||||
|
// class via a tool like ResGen or Visual Studio.
|
||||||
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
|
// with the /str option, or rebuild your VS project.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GUI.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
117
GUI/Properties/Resources.resx
Normal file
117
GUI/Properties/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
26
GUI/Properties/Settings.Designer.cs
generated
Normal file
26
GUI/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Runtime Version:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace GUI.Properties {
|
||||||
|
|
||||||
|
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
||||||
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
|
|
||||||
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
|
|
||||||
|
public static Settings Default {
|
||||||
|
get {
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
GUI/Properties/Settings.settings
Normal file
7
GUI/Properties/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||||
|
<Profiles>
|
||||||
|
<Profile Name="(Default)" />
|
||||||
|
</Profiles>
|
||||||
|
<Settings />
|
||||||
|
</SettingsFile>
|
||||||
180
GUI/ServerProcess.cs
Normal file
180
GUI/ServerProcess.cs
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
/*
|
||||||
|
_ _ _ ____ _ _____
|
||||||
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||||
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||||
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
|
|
||||||
|
Copyright 2015-2016 Florian "KlappPC" Lang
|
||||||
|
Contact: ichhoeremusik@gmx.net
|
||||||
|
This file is mostly done by a friend who explicitly does not want to get mentioned in any way.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Threading;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
/*basically a class to run executables as controlled prozess in the background*/
|
||||||
|
public class ServerProcess {
|
||||||
|
//ASF.exe in our case
|
||||||
|
protected Process process;
|
||||||
|
//handling the output.
|
||||||
|
protected Thread outputThread;
|
||||||
|
protected bool stopping;
|
||||||
|
|
||||||
|
//the textbox from our Form, where we want to display output.
|
||||||
|
private TextBox output;
|
||||||
|
|
||||||
|
private object lockObj = new object();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New SeverProcess for filename with arguments and output to textBox.
|
||||||
|
* Console is hidden and IO redirected.
|
||||||
|
*/
|
||||||
|
public ServerProcess(string fileName, string argumants, TextBox textBox) {
|
||||||
|
|
||||||
|
|
||||||
|
output = textBox;
|
||||||
|
process = new System.Diagnostics.Process();
|
||||||
|
|
||||||
|
process.StartInfo.FileName = fileName;
|
||||||
|
process.StartInfo.Arguments = argumants;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardInput = true;
|
||||||
|
process.StartInfo.RedirectStandardError = true;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
//needed for realizing when input is needed.
|
||||||
|
private int dotcounter = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* I'm not quite happy with this. I could not figure a way to notice when input is required
|
||||||
|
* besides reading char by char and searching for keywords. Will stop working, if the "Please enter"
|
||||||
|
* lines gets changed.
|
||||||
|
* Only tested for "Enter Password."
|
||||||
|
*/
|
||||||
|
private void NewOutput(object sender, char e) {
|
||||||
|
MethodInvoker mi = delegate {
|
||||||
|
output.AppendText(e.ToString());
|
||||||
|
};
|
||||||
|
|
||||||
|
if (e == '.') {
|
||||||
|
dotcounter++;
|
||||||
|
} else if (e == ':') {
|
||||||
|
dotcounter = 3;
|
||||||
|
} else {
|
||||||
|
dotcounter = 0;
|
||||||
|
}
|
||||||
|
if (dotcounter == 3) {
|
||||||
|
string[] arr = output.Lines;
|
||||||
|
string str = arr[arr.Length - 1];
|
||||||
|
if (str.Contains("Hit enter")) {
|
||||||
|
str = arr[arr.Length - 2] + " | " + str;
|
||||||
|
Form f = new Form2(this, str);
|
||||||
|
f.ShowDialog();
|
||||||
|
mi = delegate { output.AppendText(e.ToString() + "\n"); };
|
||||||
|
}
|
||||||
|
if (str.Contains("Please enter")) {
|
||||||
|
Form f = new Form2(this, str);
|
||||||
|
f.ShowDialog();
|
||||||
|
mi = delegate { output.AppendText(e.ToString() + "\n"); };
|
||||||
|
}
|
||||||
|
|
||||||
|
dotcounter = 0;
|
||||||
|
}
|
||||||
|
output.Invoke(mi);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NewOutput(object sender, string e) {
|
||||||
|
MethodInvoker mi = delegate {
|
||||||
|
output.AppendText(e + "\n");
|
||||||
|
};
|
||||||
|
output.Invoke(mi);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void printOutPut() {
|
||||||
|
char str;
|
||||||
|
int i;
|
||||||
|
string s;
|
||||||
|
while (!stopping) {
|
||||||
|
//thats ugly, but when using readline we can't catch input.
|
||||||
|
while (((i = process.StandardOutput.Read()) != 0)) {
|
||||||
|
str = System.Convert.ToChar(i);
|
||||||
|
NewOutput(this, str);
|
||||||
|
if (stopping)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (((s = process.StandardError.ReadLine()) != null)) {
|
||||||
|
NewOutput(this, s);
|
||||||
|
if (stopping)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(string msg) {
|
||||||
|
process.StandardInput.WriteLine(msg);
|
||||||
|
process.StandardInput.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop() {
|
||||||
|
Thread stopThread = new Thread(StopProcess);
|
||||||
|
stopThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopProcess() {
|
||||||
|
|
||||||
|
if (process == null)
|
||||||
|
return;
|
||||||
|
stopping = true;
|
||||||
|
|
||||||
|
outputThread.Abort();
|
||||||
|
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
|
if (process == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (process.HasExited)
|
||||||
|
process.Close();
|
||||||
|
else
|
||||||
|
process.Kill();
|
||||||
|
|
||||||
|
process = null;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* starts the process and a second thread to listen for output.
|
||||||
|
*/
|
||||||
|
public void Start() {
|
||||||
|
outputThread = new Thread(printOutPut);
|
||||||
|
process.Start();
|
||||||
|
outputThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Process Process {
|
||||||
|
get {
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
58
GUI/app.manifest
Normal file
58
GUI/app.manifest
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
|
||||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||||
|
<security>
|
||||||
|
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<!-- UAC-Manifestoptionen
|
||||||
|
Wenn Sie die Zugangsebene für das Windows-Benutzerkonto ändern möchten, ersetzen Sie den
|
||||||
|
requestedExecutionLevel-Knoten durch eines der folgenden Elemente.
|
||||||
|
|
||||||
|
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||||
|
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||||
|
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
||||||
|
|
||||||
|
Durch Angeben des requestedExecutionLevel-Knotens wird die Datei- und Registrierungsvirtualisierung deaktiviert.
|
||||||
|
Wenn Sie Datei- und Registrierungsvirtualisierung für Abwärts-
|
||||||
|
kompatibilität verwenden möchten, löschen Sie den requestedExecutionLevel-Knoten.
|
||||||
|
-->
|
||||||
|
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||||
|
</requestedPrivileges>
|
||||||
|
</security>
|
||||||
|
</trustInfo>
|
||||||
|
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- Eine Liste aller Windows-Versionen, mit denen die Anwendung kompatibel ist.
|
||||||
|
Windows wählt automatisch die am stärksten kompatible Umgebung aus.-->
|
||||||
|
|
||||||
|
<!-- Wenn die Anwendung mit Windows Vista kompatibel ist, heben Sie die Auskommentierung des folgenden supportedOS-Knotens auf-->
|
||||||
|
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
|
||||||
|
|
||||||
|
<!-- Wenn die Anwendung mit Windows 7 kompatibel ist, heben Sie die Kommentierung des folgenden supportedOS-Knotens auf.-->
|
||||||
|
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
|
||||||
|
|
||||||
|
<!-- Wenn die Anwendung mit Windows 8 kompatibel ist, heben Sie die Auskommentierung des folgenden supportedOS-Knotens auf-->
|
||||||
|
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
|
||||||
|
|
||||||
|
<!-- Wenn die Anwendung mit Windows 8.1 kompatibel ist, die Kommentierung des folgenden supportedOS-Knotens aufheben.-->
|
||||||
|
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
|
||||||
|
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
|
||||||
|
<!-- Designs für allgemeine Windows-Steuerelemente und -Dialogfelder (Windows XP und höher) aktivieren -->
|
||||||
|
<!-- <dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity
|
||||||
|
type="win32"
|
||||||
|
name="Microsoft.Windows.Common-Controls"
|
||||||
|
version="6.0.0.0"
|
||||||
|
processorArchitecture="*"
|
||||||
|
publicKeyToken="6595b64144ccf1df"
|
||||||
|
language="*"
|
||||||
|
/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>-->
|
||||||
|
|
||||||
|
</asmv1:assembly>
|
||||||
BIN
GUI/cirno.ico
Normal file
BIN
GUI/cirno.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 361 KiB |
9
appveyor.yml
Normal file
9
appveyor.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
version: 1.0.{build}-{branch}
|
||||||
|
image: Visual Studio 2015
|
||||||
|
configuration: Release
|
||||||
|
platform: Any CPU
|
||||||
|
clone_depth: 10
|
||||||
|
build:
|
||||||
|
project: ArchiSteamFarm.sln
|
||||||
|
parallel: true
|
||||||
|
verbosity: minimal
|
||||||
6
run.sh
6
run.sh
@@ -18,6 +18,12 @@ for ARG in "$@"; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ "$BUILD" = "Debug" ]]; then
|
||||||
|
MONO_ARGS+=("--debug")
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$(dirname "$(readlink -f "$0")")"
|
||||||
|
|
||||||
BINARY="ArchiSteamFarm/bin/$BUILD/ArchiSteamFarm.exe"
|
BINARY="ArchiSteamFarm/bin/$BUILD/ArchiSteamFarm.exe"
|
||||||
|
|
||||||
if [[ ! -f "$BINARY" ]]; then
|
if [[ ! -f "$BINARY" ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user