|
| 1 | +using Atlasd.Battlenet.Protocols.Game.Messages; |
| 2 | +using Atlasd.Daemon; |
| 3 | +using Atlasd.Localization; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | + |
| 9 | +namespace Atlasd.Battlenet.Protocols.Game.ChatCommands |
| 10 | +{ |
| 11 | + /** |
| 12 | + * [3/6/2023 5:39:55 PM] islanti: *resurrects author of miragechat to patch msgbox. carl starts disconnecting everybody with post-enterchat auth_check failure |
| 13 | + * [3/6/2023 5:41:48 PM] islanti: have no comb through my code to find all instances of voluntary disconnect and verify it is within-sequence |
| 14 | + * [3/6/2023 5:41:58 PM] islanti: *to comb |
| 15 | + */ |
| 16 | + class AdminBotFuckeryCommand : ChatCommand |
| 17 | + { |
| 18 | + public AdminBotFuckeryCommand(byte[] rawBuffer, List<string> arguments) : base(rawBuffer, arguments) { } |
| 19 | + |
| 20 | + public override bool CanInvoke(ChatCommandContext context) |
| 21 | + { |
| 22 | + return context != null && context.GameState != null && context.GameState.ActiveAccount != null; |
| 23 | + } |
| 24 | + |
| 25 | + public override void Invoke(ChatCommandContext context) |
| 26 | + { |
| 27 | + var t = Arguments.Count == 0 ? "" : Arguments[0]; // target |
| 28 | + string r; // reply |
| 29 | + |
| 30 | + if (t.Length == 0 || !Battlenet.Common.GetClientByOnlineName(t, out var target) || target == null) |
| 31 | + { |
| 32 | + r = Resources.UserNotLoggedOn; |
| 33 | + foreach (var line in r.Split(Environment.NewLine)) |
| 34 | + new ChatEvent(ChatEvent.EventIds.EID_ERROR, context.GameState.ChannelFlags, context.GameState.Client.RemoteIPAddress, context.GameState.Ping, context.GameState.OnlineName, line).WriteTo(context.GameState.Client); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + Arguments.RemoveAt(0); // remove target |
| 39 | + // Calculates and removes (target+' ') from (raw) which prints into (newRaw): |
| 40 | + RawBuffer = RawBuffer[(Encoding.UTF8.GetByteCount(t) + (Arguments.Count > 0 ? 1 : 0))..]; |
| 41 | + var type = string.Join(' ', Arguments); |
| 42 | + |
| 43 | + if (string.IsNullOrEmpty(type)) |
| 44 | + { |
| 45 | + r = Resources.AdminBotFuckeryCommandInvalid; |
| 46 | + foreach (var line in r.Split(Environment.NewLine)) |
| 47 | + new ChatEvent(ChatEvent.EventIds.EID_ERROR, context.GameState.ChannelFlags, context.GameState.Client.RemoteIPAddress, context.GameState.Ping, context.GameState.OnlineName, line).WriteTo(context.GameState.Client); |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + var realmName = Settings.GetString(new string[] { "battlenet", "realm", "name" }, Resources.Battlenet); |
| 52 | + var targetEnv = new Dictionary<string, string>() |
| 53 | + { |
| 54 | + { "accountName", target.Username }, |
| 55 | + { "channel", target.ActiveChannel == null ? "(null)" : target.ActiveChannel.Name }, |
| 56 | + { "game", Product.ProductName(target.Product, true) }, |
| 57 | + { "host", Settings.GetString(new string[] { "battlenet", "realm", "host" }, "(null)") }, |
| 58 | + { "localTime", target.LocalTime.ToString(Common.HumanDateTimeFormat).Replace(" 0", " ") }, |
| 59 | + { "name", target.OnlineName }, |
| 60 | + { "onlineName", target.OnlineName }, |
| 61 | + { "realm", realmName }, |
| 62 | + { "realmTime", DateTime.Now.ToString(Common.HumanDateTimeFormat).Replace(" 0", " ") }, |
| 63 | + { "realmTimezone", $"UTC{DateTime.Now:zzz}" }, |
| 64 | + { "user", target.OnlineName }, |
| 65 | + { "username", target.OnlineName }, |
| 66 | + { "userName", target.OnlineName }, |
| 67 | + }; |
| 68 | + var env = targetEnv.Concat(context.Environment); |
| 69 | + |
| 70 | + SID_AUTH_CHECK.Statuses status = type.ToLowerInvariant().Replace(" ", string.Empty) switch |
| 71 | + { |
| 72 | + "bannedkey" => SID_AUTH_CHECK.Statuses.GameKeyBanned, |
| 73 | + "bannedkey2" => SID_AUTH_CHECK.Statuses.GameKeyBanned | SID_AUTH_CHECK.Statuses.GameKeyExpansion, |
| 74 | + "inusekey" => SID_AUTH_CHECK.Statuses.GameKeyInUse, |
| 75 | + "inusekey2" => SID_AUTH_CHECK.Statuses.GameKeyInUse | SID_AUTH_CHECK.Statuses.GameKeyExpansion, |
| 76 | + "invalidkey" => SID_AUTH_CHECK.Statuses.GameKeyInvalid, |
| 77 | + "invalidkey2" => SID_AUTH_CHECK.Statuses.GameKeyInvalid | SID_AUTH_CHECK.Statuses.GameKeyExpansion, |
| 78 | + "invalidversion" => SID_AUTH_CHECK.Statuses.InvalidVersion, |
| 79 | + "success" => SID_AUTH_CHECK.Statuses.Success, |
| 80 | + "toonew" => SID_AUTH_CHECK.Statuses.VersionTooNew, |
| 81 | + "tooold" => SID_AUTH_CHECK.Statuses.VersionTooOld, |
| 82 | + "wronggamekey" => SID_AUTH_CHECK.Statuses.GameKeyProductMismatch, |
| 83 | + "wronggamekey2" => SID_AUTH_CHECK.Statuses.GameKeyProductMismatch | SID_AUTH_CHECK.Statuses.GameKeyExpansion, |
| 84 | + _ => SID_AUTH_CHECK.Statuses.InvalidVersion, |
| 85 | + }; |
| 86 | + |
| 87 | + new SID_AUTH_CHECK().Invoke(new MessageContext(target.Client, MessageDirection.ServerToClient, new Dictionary<string, dynamic>(){ |
| 88 | + { "status", status }, { "info", Array.Empty<byte>() } |
| 89 | + })); |
| 90 | + |
| 91 | + r = Resources.AdminBotFuckeryCommand; |
| 92 | + foreach (var kv in env) r = r.Replace("{" + kv.Key + "}", kv.Value); |
| 93 | + foreach (var line in r.Split(Battlenet.Common.NewLine)) |
| 94 | + new ChatEvent(ChatEvent.EventIds.EID_INFO, context.GameState.ChannelFlags, context.GameState.Client.RemoteIPAddress, context.GameState.Ping, context.GameState.OnlineName, line).WriteTo(context.GameState.Client); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments