Reject clan invites when IsBotAccount

Also make it possible for quite rare situation of ASF accepting invite to SteamMasterClanID if it couldn't join due to group being non-public
This commit is contained in:
JustArchi
2016-12-11 04:23:44 +01:00
parent 8eeab55d0b
commit 9d0cc07d4e
5 changed files with 102 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using ArchiSteamFarm.CMsgs;
using SteamKit2;
using SteamKit2.Internal;
@@ -212,6 +213,24 @@ namespace ArchiSteamFarm {
}
}
internal void AcceptClanInvite(ulong clanID, bool accept) {
if (clanID == 0) {
ArchiLogger.LogNullError(nameof(clanID));
return;
}
if (!Client.IsConnected) {
return;
}
ClientMsg<CMsgClientClanInviteAction> request = new ClientMsg<CMsgClientClanInviteAction>();
request.Body.ClanID = clanID;
request.Body.AcceptInvite = accept;
Client.Send(request);
}
private void HandleFSOfflineMessageNotification(IPacketMsg packetMsg) {
if (packetMsg == null) {
ArchiLogger.LogNullError(nameof(packetMsg));

View File

@@ -116,6 +116,7 @@
<Compile Include="ASF.cs" />
<Compile Include="Bot.cs" />
<Compile Include="BotConfig.cs" />
<Compile Include="CMsgs\CMsgClientClanInviteAction.cs" />
<Compile Include="ConcurrentEnumerator.cs" />
<Compile Include="ConcurrentHashSet.cs" />
<Compile Include="CryptoHelper.cs" />

View File

@@ -799,6 +799,15 @@ namespace ArchiSteamFarm {
return false;
}
private bool IsMasterClanID(ulong steamID) {
if (steamID != 0) {
return steamID == BotConfig.SteamMasterClanID;
}
ArchiLogger.LogNullError(nameof(steamID));
return false;
}
private static bool IsOwner(ulong steamID) {
if (steamID != 0) {
return (steamID == Program.GlobalConfig.SteamOwnerID) || (Debugging.IsDebugBuild && (steamID == SharedInfo.ArchiSteamID));
@@ -1095,10 +1104,18 @@ namespace ArchiSteamFarm {
}
foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList.Where(friend => friend.Relationship == EFriendRelationship.RequestRecipient)) {
if (IsMaster(friend.SteamID)) {
SteamFriends.AddFriend(friend.SteamID);
} else if (BotConfig.IsBotAccount) {
SteamFriends.RemoveFriend(friend.SteamID);
if (friend.SteamID.AccountType == EAccountType.Clan) {
if (IsMasterClanID(friend.SteamID)) {
ArchiHandler.AcceptClanInvite(friend.SteamID, true);
} else if (BotConfig.IsBotAccount) {
ArchiHandler.AcceptClanInvite(friend.SteamID, false);
}
} else {
if (IsMaster(friend.SteamID)) {
SteamFriends.AddFriend(friend.SteamID);
} else if (BotConfig.IsBotAccount) {
SteamFriends.RemoveFriend(friend.SteamID);
}
}
}
}

View File

@@ -0,0 +1,58 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
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.IO;
using SteamKit2;
using SteamKit2.Internal;
namespace ArchiSteamFarm.CMsgs {
internal sealed class CMsgClientClanInviteAction : ISteamSerializableMessage {
internal bool AcceptInvite { private get; set; }
internal ulong ClanID { private get; set; }
void ISteamSerializable.Deserialize(Stream stream) {
if (stream == null) {
ASF.ArchiLogger.LogNullError(nameof(stream));
return;
}
BinaryReader binaryReader = new BinaryReader(stream);
ClanID = binaryReader.ReadUInt64();
AcceptInvite = binaryReader.ReadBoolean();
}
EMsg ISteamSerializableMessage.GetEMsg() => EMsg.ClientAcknowledgeClanInvite;
void ISteamSerializable.Serialize(Stream stream) {
if (stream == null) {
ASF.ArchiLogger.LogNullError(nameof(stream));
return;
}
BinaryWriter binaryWriter = new BinaryWriter(stream);
binaryWriter.Write(ClanID);
binaryWriter.Write(AcceptInvite);
}
}
}

View File

@@ -103,6 +103,9 @@
<Compile Include="..\ArchiSteamFarm\CardsFarmer.cs">
<Link>CardsFarmer.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\CMsgs\CMsgClientClanInviteAction.cs">
<Link>CMsgs\CMsgClientClanInviteAction.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\ConcurrentEnumerator.cs">
<Link>ConcurrentEnumerator.cs</Link>
</Compile>