From 5af8001398f11ca5b4630e9e3009c3003e992457 Mon Sep 17 00:00:00 2001 From: TheUbMunster <66451362+TheUbMunster@users.noreply.github.com> Date: Wed, 27 Jul 2022 14:48:18 -0600 Subject: [PATCH] Fixed adding quotes around Ambiguous for "user": , fixed showing correct casing of arguments. --- Server/Program.cs | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/Server/Program.cs b/Server/Program.cs index df2fee2..ecf595c 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -173,7 +173,7 @@ server.PacketHandler = (c, p) => { IEnumerable search = server.Clients.Where(c => c.Connected && (c.Name.ToLower().StartsWith(arg.ToLower()) || (Guid.TryParse(arg, out Guid res) && res == c.Id))); if (!search.Any()) - failToFind.Add(arg.ToLower()); //none found + failToFind.Add(arg); //none found else if (search.Count() > 1) { Client? exact = search.FirstOrDefault(x => x.Name == arg); if (!ReferenceEquals(exact, null)) { @@ -184,7 +184,7 @@ server.PacketHandler = (c, p) => { toActUpon.Add(exact); } else { - ambig.Add((arg.ToLower(), search.Select(x => x.Name))); //more than one match + ambig.Add((arg, search.Select(x => x.Name))); //more than one match foreach (var rem in search.ToList()) //need copy because can't remove from list while iterating over it toActUpon.Remove(rem); } @@ -213,7 +213,7 @@ CommandHandler.RegisterCommand("rejoin", args => { sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : ""); if (res.ambig.Count > 0) { res.ambig.ForEach(x => { - sb.Append($"Ambiguous for {x.arg}: {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n"); + sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n"); }); sb.Remove(sb.Length - 1, 1); //remove extra nl } @@ -237,7 +237,7 @@ CommandHandler.RegisterCommand("crash", args => { sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : ""); if (res.ambig.Count > 0) { res.ambig.ForEach(x => { - sb.Append($"Ambiguous for {x.arg}: {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n"); + sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n"); }); sb.Remove(sb.Length - 1, 1); //remove extra nl } @@ -262,6 +262,43 @@ CommandHandler.RegisterCommand("ban", args => { return "Usage: ban <* | !* (usernames to not ban...) | (usernames to ban...)>"; } + #region Testing + //void TestAddClients() + //{ + // Client c1 = new Client(null!); + // c1.Id = new Guid("00000000000000000000000000000000"); + // c1.Connected = true; + // c1.Name = "Moo"; + // server.Clients.Add(c1); + + // Client c2 = new Client(null!); + // c2.Id = new Guid("00000000000000000000000000000001"); + // c2.Connected = true; + // c2.Name = "Moomoss"; + // server.Clients.Add(c2); + + // Client c3 = new Client(null!); + // c3.Id = new Guid("00000000000000000000000000000002"); + // c3.Connected = true; + // c3.Name = "mo"; + // server.Clients.Add(c3); + + // Client c4 = new Client(null!); + // c4.Id = new Guid("00000000000000000000000000000003"); + // c4.Connected = true; + // c4.Name = "Bar"; + // server.Clients.Add(c4); + + // Client c5 = new Client(null!); + // c5.Id = new Guid("00000000000000000000000000000004"); + // c5.Connected = true; + // c5.Name = "Foo"; + // server.Clients.Add(c5); + //} + + //TestAddClients(); + #endregion + var res = MultiUserCommandHelper(args); StringBuilder sb = new StringBuilder(); @@ -269,7 +306,7 @@ CommandHandler.RegisterCommand("ban", args => { sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : ""); if (res.ambig.Count > 0) { res.ambig.ForEach(x => { - sb.Append($"Ambiguous for {x.arg}: {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n"); + sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n"); }); sb.Remove(sb.Length - 1, 1); //remove extra nl }