Skip to content

Commit

Permalink
Reject clan invites when IsBotAccount
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JustArchi committed Dec 11, 2016
1 parent 8eeab55 commit 9d0cc07
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
19 changes: 19 additions & 0 deletions ArchiSteamFarm/ArchiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using ArchiSteamFarm.CMsgs;
using SteamKit2;
using SteamKit2.Internal;

Expand Down Expand Up @@ -212,6 +213,24 @@ internal sealed class ArchiHandler : ClientMsgHandler {
}
}

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));
Expand Down
1 change: 1 addition & 0 deletions ArchiSteamFarm/ArchiSteamFarm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
25 changes: 21 additions & 4 deletions ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,15 @@ internal sealed class Bot : IDisposable {
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));
Expand Down Expand Up @@ -1095,10 +1104,18 @@ internal sealed class Bot : IDisposable {
}

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);
}
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
3 changes: 3 additions & 0 deletions GUI/GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 9d0cc07

Please sign in to comment.