diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index 0a61d3436..4424e8f28 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -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 request = new ClientMsg(); + + request.Body.ClanID = clanID; + request.Body.AcceptInvite = accept; + + Client.Send(request); + } + private void HandleFSOfflineMessageNotification(IPacketMsg packetMsg) { if (packetMsg == null) { ArchiLogger.LogNullError(nameof(packetMsg)); diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index 3060a18ce..288d68bb0 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -116,6 +116,7 @@ + diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 06bb1ee14..5176b3238 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -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); + } } } } diff --git a/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs b/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs new file mode 100644 index 000000000..84b654651 --- /dev/null +++ b/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/GUI/GUI.csproj b/GUI/GUI.csproj index 199ca51d4..db6599e1b 100644 --- a/GUI/GUI.csproj +++ b/GUI/GUI.csproj @@ -103,6 +103,9 @@ CardsFarmer.cs + + CMsgs\CMsgClientClanInviteAction.cs + ConcurrentEnumerator.cs