From 325ec12697d3bc4ee021411e9d821cd4b6a85959 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Thu, 25 May 2017 06:13:59 +0200 Subject: [PATCH] Improve greatly proper order of splitted messages There's too high chance Valve servers will get it in wrong order when not using delay, 300ms is sufficient in ArchiBoT, so we make it 500ms in ASF. There's no delay enforced when message is not being split. --- ArchiSteamFarm/Bot.cs | 20 ++++++++++++++------ ArchiSteamFarm/SteamTarget.cs | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 5104f55f8..f49b7a3d9 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -780,16 +780,16 @@ namespace ArchiSteamFarm { } } - internal void SendMessage(ulong steamID, string message) { + internal async Task SendMessage(ulong steamID, string message) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return; } if (new SteamID(steamID).IsChatAccount) { - SendMessageToChannel(steamID, message); + await SendMessageToChannel(steamID, message).ConfigureAwait(false); } else { - SendMessageToUser(steamID, message); + await SendMessageToUser(steamID, message).ConfigureAwait(false); } } @@ -988,7 +988,7 @@ namespace ArchiSteamFarm { return; } - SendMessage(chatID, response); + await SendMessage(chatID, response).ConfigureAwait(false); } private async Task HeartBeat() { @@ -3452,7 +3452,7 @@ namespace ArchiSteamFarm { return null; } - private void SendMessageToChannel(ulong steamID, string message) { + private async Task SendMessageToChannel(ulong steamID, string message) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return; @@ -3463,12 +3463,16 @@ namespace ArchiSteamFarm { } for (int i = 0; i < message.Length; i += MaxSteamMessageLength - 2) { + if (i > 0) { + await Task.Delay(CallbackSleep).ConfigureAwait(false); + } + string messagePart = (i > 0 ? "…" : "") + message.Substring(i, Math.Min(MaxSteamMessageLength - 2, message.Length - i)) + (MaxSteamMessageLength - 2 < message.Length - i ? "…" : ""); SteamFriends.SendChatRoomMessage(steamID, EChatEntryType.ChatMsg, messagePart); } } - private void SendMessageToUser(ulong steamID, string message) { + private async Task SendMessageToUser(ulong steamID, string message) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return; @@ -3479,6 +3483,10 @@ namespace ArchiSteamFarm { } for (int i = 0; i < message.Length; i += MaxSteamMessageLength - 2) { + if (i > 0) { + await Task.Delay(CallbackSleep).ConfigureAwait(false); + } + string messagePart = (i > 0 ? "…" : "") + message.Substring(i, Math.Min(MaxSteamMessageLength - 2, message.Length - i)) + (MaxSteamMessageLength - 2 < message.Length - i ? "…" : ""); SteamFriends.SendChatMessage(steamID, EChatEntryType.ChatMsg, messagePart); } diff --git a/ArchiSteamFarm/SteamTarget.cs b/ArchiSteamFarm/SteamTarget.cs index 4252a9560..1e08ea640 100644 --- a/ArchiSteamFarm/SteamTarget.cs +++ b/ArchiSteamFarm/SteamTarget.cs @@ -48,7 +48,7 @@ namespace ArchiSteamFarm { // Keeping date in default layout also doesn't make much sense, so we remove it by default public SteamTarget() => Layout = "${level:uppercase=true}|${logger}|${message}"; - protected override void Write(LogEventInfo logEvent) { + protected override async void Write(LogEventInfo logEvent) { if (logEvent == null) { ASF.ArchiLogger.LogNullError(nameof(logEvent)); return; @@ -79,7 +79,7 @@ namespace ArchiSteamFarm { return; } - bot.SendMessage(SteamID, message); + await bot.SendMessage(SteamID, message).ConfigureAwait(false); } } } \ No newline at end of file