Code review

This commit is contained in:
JustArchi
2016-06-13 18:08:19 +02:00
parent 60a02a4c6a
commit 7e084bf50b
3 changed files with 42 additions and 36 deletions

View File

@@ -61,8 +61,7 @@ namespace ArchiSteamFarm {
private readonly SteamApps SteamApps;
private readonly SteamFriends SteamFriends;
private readonly SteamUser SteamUser;
private readonly Timer AcceptConfirmationsTimer;
private readonly Timer SendItemsTimer;
private readonly Timer AcceptConfirmationsTimer, SendItemsTimer;
private readonly Trading Trading;
internal bool KeepRunning { get; private set; }
@@ -133,18 +132,16 @@ namespace ArchiSteamFarm {
}
if (!BotConfig.Enabled) {
Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
Logging.LogGenericInfo("Not initializing this instance because it's disabled in config file", botName);
return;
}
lock (Bots) {
if (Bots.ContainsKey(botName)) {
return;
}
Bots[botName] = this;
if (Bots.ContainsKey(botName)) {
throw new Exception("That bot is already defined!");
}
Bots[botName] = this;
SentryFile = botPath + ".bin";
BotDatabase = BotDatabase.Load(botPath + ".db");
@@ -302,7 +299,7 @@ namespace ArchiSteamFarm {
return false;
}
if ((callback == null) || (callback.Result != EResult.OK) || string.IsNullOrEmpty(callback.Nonce)) {
if ((callback == null) || string.IsNullOrEmpty(callback.Nonce)) {
Start().Forget();
return false;
}
@@ -1568,7 +1565,6 @@ namespace ArchiSteamFarm {
TwoFactorCode = BotDatabase.SteamGuardAccount.GenerateSteamGuardCode();
}
// TODO: Please remove me immediately after https://github.com/SteamRE/SteamKit/issues/254 gets fixed
if (Program.GlobalConfig.HackIgnoreMachineID) {
Logging.LogGenericWarning("Using workaround for broken GenerateMachineID()!", BotName);
ArchiHandler.HackedLogOn(new SteamUser.LogOnDetails {
@@ -1585,17 +1581,31 @@ namespace ArchiSteamFarm {
return;
}
SteamUser.LogOn(new SteamUser.LogOnDetails {
Username = BotConfig.SteamLogin,
Password = BotConfig.SteamPassword,
AuthCode = AuthCode,
CellID = Program.GlobalDatabase.CellID,
LoginID = LoginID,
LoginKey = BotDatabase.LoginKey,
TwoFactorCode = TwoFactorCode,
SentryFileHash = sentryHash,
ShouldRememberPassword = true
});
try {
SteamUser.LogOn(new SteamUser.LogOnDetails {
Username = BotConfig.SteamLogin,
Password = BotConfig.SteamPassword,
AuthCode = AuthCode,
CellID = Program.GlobalDatabase.CellID,
LoginID = LoginID,
LoginKey = BotDatabase.LoginKey,
TwoFactorCode = TwoFactorCode,
SentryFileHash = sentryHash,
ShouldRememberPassword = true
});
} catch (Exception) {
ArchiHandler.HackedLogOn(new SteamUser.LogOnDetails {
Username = BotConfig.SteamLogin,
Password = BotConfig.SteamPassword,
AuthCode = AuthCode,
CellID = Program.GlobalDatabase.CellID,
LoginID = LoginID,
LoginKey = BotDatabase.LoginKey,
TwoFactorCode = TwoFactorCode,
SentryFileHash = sentryHash,
ShouldRememberPassword = true
});
}
}
private async void OnDisconnected(SteamClient.DisconnectedCallback callback) {
@@ -1720,18 +1730,10 @@ namespace ArchiSteamFarm {
}
foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList.Where(friend => friend.Relationship == EFriendRelationship.RequestRecipient)) {
switch (friend.SteamID.AccountType) {
case EAccountType.Clan:
// TODO: Accept clan invites from master?
break;
default:
if (IsMaster(friend.SteamID)) {
SteamFriends.AddFriend(friend.SteamID);
} else if (BotConfig.IsBotAccount) {
SteamFriends.RemoveFriend(friend.SteamID);
}
break;
if (IsMaster(friend.SteamID)) {
SteamFriends.AddFriend(friend.SteamID);
} else if (BotConfig.IsBotAccount) {
SteamFriends.RemoveFriend(friend.SteamID);
}
}
}
@@ -1896,7 +1898,7 @@ namespace ArchiSteamFarm {
Logging.LogGenericWarning("Unable to login to Steam: " + callback.Result, BotName);
break;
default: // Unexpected result, shutdown immediately
Logging.LogGenericWarning("Unable to login to Steam: " + callback.Result, BotName);
Logging.LogGenericError("Unable to login to Steam: " + callback.Result, BotName);
Stop();
break;
}

View File

@@ -51,6 +51,11 @@ namespace ArchiSteamFarm {
}
public void WriteLine(string category, string msg) {
if (string.IsNullOrEmpty(category) && string.IsNullOrEmpty(msg)) {
Logging.LogNullError(nameof(category) + " && " + nameof(msg));
return;
}
lock (FilePath) {
try {
File.AppendAllText(FilePath, category + " | " + msg + Environment.NewLine);

View File

@@ -23,7 +23,6 @@
*/
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;