diff --git a/Botbases/RSBot.Training/Bundle/Buff/BuffBundle.cs b/Botbases/RSBot.Training/Bundle/Buff/BuffBundle.cs index c35a709c..0f8e705d 100644 --- a/Botbases/RSBot.Training/Bundle/Buff/BuffBundle.cs +++ b/Botbases/RSBot.Training/Bundle/Buff/BuffBundle.cs @@ -51,9 +51,9 @@ var buff in SkillManager.Buffs.Union(new[] { SkillManager.ImbueSkill, SkillManag //#377 bug detected! Log.Notify($"[#377] The buff [{buff.Token}-{buff.Record?.GetRealName()}] expired"); - EventManager.FireEvent("OnRemoveBuff", buff); + EventManager.FireEvent("OnRemoveBuff", info); - var playerSkill = Game.Player.Skills.GetSkillInfoById(buff.Id); + var playerSkill = Game.Player.Skills.GetSkillInfoById(info.Id); playerSkill?.Reset(); Game.Player.State.TryRemoveActiveBuff(info.Token, out _); } diff --git a/Library/RSBot.Core/Components/SkillManager.cs b/Library/RSBot.Core/Components/SkillManager.cs index 954b4f7f..5f0f335b 100644 --- a/Library/RSBot.Core/Components/SkillManager.cs +++ b/Library/RSBot.Core/Components/SkillManager.cs @@ -439,42 +439,64 @@ public static void CastBuff(SkillInfo skill, uint target = 0, bool awaitBuffResp packet.WriteByte(ActionTarget.None); } - var asyncCallback = new AwaitCallback( + var castCallback = new AwaitCallback( response => { - var targetId = response.ReadUInt(); - var castedSkillId = response.ReadUInt(); + var result = response.ReadByte(); - if (targetId == (target == 0 ? Game.Player.UniqueId : target) && castedSkillId == skill.Id) - return AwaitCallbackResult.Success; + if (result != 0x01) + return AwaitCallbackResult.Fail; - return AwaitCallbackResult.ConditionFailed; + var action = Objects.Action.DeserializeBegin(response); + + return action.PlayerIsExecutor && action.SkillId == skill.Id + ? AwaitCallbackResult.Success + : AwaitCallbackResult.ConditionFailed; }, - 0xB0BD + 0xB070 ); - var callback = new AwaitCallback( + var actionStateCallback = new AwaitCallback( response => { - return response.ReadByte() == 0x02 && response.ReadByte() == 0x00 - ? AwaitCallbackResult.Success - : AwaitCallbackResult.ConditionFailed; + var state = response.ReadByte(); + var recurring = response.ReadByte(); + + if (state == 0x02 && recurring == 0x00) + return AwaitCallbackResult.Success; + + if (state == 0x03) + return AwaitCallbackResult.Fail; + + return AwaitCallbackResult.ConditionFailed; }, 0xB074 ); - PacketManager.SendPacket(packet, PacketDestination.Server, asyncCallback, callback); + if (!awaitBuffResponse) + { + PacketManager.SendPacket(packet, PacketDestination.Server); + return; + } - if (awaitBuffResponse) - asyncCallback.AwaitResponse( - skill.Record.Action_CastingTime - + skill.Record.Action_ActionDuration - + skill.Record.Action_PreparingTime - + 1500 - ); + if (skill.Record.Basic_Activity != 1) + PacketManager.SendPacket(packet, PacketDestination.Server, castCallback, actionStateCallback); + else + PacketManager.SendPacket(packet, PacketDestination.Server, castCallback); + + var timeout = + skill.Record.Action_CastingTime + + skill.Record.Action_ActionDuration + + skill.Record.Action_PreparingTime + + 1500; + + castCallback.AwaitResponse(timeout); - if (skill.Record.Basic_Activity != 1 && awaitBuffResponse) - callback.AwaitResponse(); + if (!castCallback.IsCompleted) + return; + + if (skill.Record.Basic_Activity != 1) + actionStateCallback.AwaitResponse(timeout); } /// diff --git a/Library/RSBot.Core/Network/Socket/Server.cs b/Library/RSBot.Core/Network/Socket/Server.cs index 4ae0ef45..c39a91e6 100644 --- a/Library/RSBot.Core/Network/Socket/Server.cs +++ b/Library/RSBot.Core/Network/Socket/Server.cs @@ -1,14 +1,17 @@ -using System; -using System.Net; -using System.Net.Sockets; -using RSBot.Core.Event; +using RSBot.Core.Event; using RSBot.Core.Extensions; using RSBot.Core.Network.Protocol; +using System; +using System.Net; +using System.Net.Sockets; namespace RSBot.Core.Network; public class Server : NetBase { + private bool _receivedInitialHandshake; + private bool _receivedPostInitialHandshakePacket; + /// /// Gets or sets the ip. /// @@ -42,6 +45,8 @@ public void Connect(string ip, ushort port) { _protocol = new SecurityProtocol(); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + _receivedInitialHandshake = false; + _receivedPostInitialHandshakePacket = false; try { @@ -62,7 +67,7 @@ public void Connect(string ip, ushort port) { _socket.Connect(ip, port, 3000); } - } + } catch (AggregateException s) { Log.Error(s.Message); @@ -111,26 +116,26 @@ private void OnBeginReceiveCallback(IAsyncResult ar) try { receivedSize = _socket.EndReceive(ar, out var error); + var rawOpcode = receivedSize >= 4 ? $"0x{BitConverter.ToUInt16(_buffer, 2):X4}" : "n/a"; + if (receivedSize == 0 || error != SocketError.Success) { - Log.Debug($"Socket closed: receivedSize={receivedSize}, error={error}"); - if (_socket != null) - { - try - { - Log.Debug($"Socket.Connected={_socket.Connected}, LocalEndPoint={_socket.LocalEndPoint}, RemoteEndPoint={_socket.RemoteEndPoint}"); - } - catch { } - } + if (!IsClosing && EnablePacketDispatcher && _receivedInitialHandshake && !_receivedPostInitialHandshakePacket) + Log.Notify("Gateway closed immediately after initial 0x5000 before handshake completed. Possible IP/session limit"); + OnDisconnected(); return; } + if (!_receivedInitialHandshake && rawOpcode == "0x5000") + _receivedInitialHandshake = true; + else if (_receivedInitialHandshake) + _receivedPostInitialHandshakePacket = true; + _protocol.Recv(_buffer, 0, receivedSize); } catch (SocketException se) { - Log.Debug($"SocketException: Code={se.SocketErrorCode}, NativeErrorCode={se.NativeErrorCode}, Message={se.Message}"); if (se.SocketErrorCode == SocketError.ConnectionReset) //Client OnDisconnected > Mostly occurs during GW->AS switch OnDisconnected(); } @@ -146,9 +151,8 @@ private void OnBeginReceiveCallback(IAsyncResult ar) if (receivedSize != 0 && _socket != null && _socket.Connected) _socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, OnBeginReceiveCallback, null); } - catch (Exception ex) + catch { - Log.Debug($"Exception in BeginReceive: {ex.Message}"); OnDisconnected(); } } diff --git a/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs b/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs index 4a1dbba2..c34c4c61 100644 --- a/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs +++ b/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs @@ -43,6 +43,16 @@ public AutoPartyBundle() /// public AutoPartyConfig Config { get; set; } + private void ApplyPartySettingsFromConfig() + { + if (!Game.Party.IsInParty) + Game.Party.Settings = new PartySettings( + Config.ExperienceAutoShare, + Config.ItemAutoShare, + Config.AllowInvitations + ); + } + /// /// Refreshes this instance. /// @@ -70,12 +80,7 @@ public void Refresh() AlwaysFollowThePartyMaster = PlayerConfig.Get("RSBot.Party.AlwaysFollowPartyMaster", false), }; - if (!Game.Party.IsInParty) - Game.Party.Settings = new PartySettings( - Config.ExperienceAutoShare, - Config.ItemAutoShare, - Config.AllowInvitations - ); + ApplyPartySettingsFromConfig(); } public void OnTick() @@ -154,6 +159,9 @@ private void CheckForAutoPartyJoin() /// public void CheckForPlayers() { + if (Config == null) + return; + if ( Game.Party.IsInParty && !Game.Party.IsLeader @@ -163,6 +171,8 @@ public void CheckForPlayers() if (Config.LeaveIfMasterNotName != Game.Party.Leader.Name) Game.Party.Leave(); + ApplyPartySettingsFromConfig(); + if (!Game.Party.CanInvite || Game.Party.Settings == null) return; diff --git a/Plugins/RSBot.Skills/Views/Main.cs b/Plugins/RSBot.Skills/Views/Main.cs index e6bf9ae2..26c7edc4 100644 --- a/Plugins/RSBot.Skills/Views/Main.cs +++ b/Plugins/RSBot.Skills/Views/Main.cs @@ -519,7 +519,7 @@ private void OnRemoveBuff(SkillInfo removingBuff) var itemBuffInfo = listItem.Tag as SkillInfo; if ( itemBuffInfo != null - && itemBuffInfo.Id == removingBuff.Id + /*&& itemBuffInfo.Id == removingBuff.Id*/ && itemBuffInfo.Token == removingBuff.Token ) {