mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-24 12:15:17 +00:00
"banning the same person multiple times" should now be fixed
This commit is contained in:
parent
33fdd69e15
commit
fc2f9b1417
1 changed files with 16 additions and 16 deletions
|
@ -206,9 +206,9 @@ server.PacketHandler = (c, p) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
(List<string> failToFind, List<Client> toActUpon, List<(string arg, IEnumerable<string> amb)> ambig) MultiUserCommandHelper(string[] args) {
|
(HashSet<string> failToFind, HashSet<Client> toActUpon, List<(string arg, IEnumerable<string> amb)> ambig) MultiUserCommandHelper(string[] args) {
|
||||||
List<string> failToFind = new();
|
HashSet<string> failToFind = new();
|
||||||
List<Client> toActUpon;
|
HashSet<Client> toActUpon;
|
||||||
List<(string arg, IEnumerable<string> amb)> ambig = new();
|
List<(string arg, IEnumerable<string> amb)> ambig = new();
|
||||||
if (args[0] == "*")
|
if (args[0] == "*")
|
||||||
toActUpon = new(server.Clients.Where(c => c.Connected));
|
toActUpon = new(server.Clients.Where(c => c.Connected));
|
||||||
|
@ -230,6 +230,7 @@ server.PacketHandler = (c, p) => {
|
||||||
toActUpon.Add(exact);
|
toActUpon.Add(exact);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!ambig.Any(x => x.arg == arg))
|
||||||
ambig.Add((arg, 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
|
foreach (var rem in search.ToList()) //need copy because can't remove from list while iterating over it
|
||||||
toActUpon.Remove(rem);
|
toActUpon.Remove(rem);
|
||||||
|
@ -255,13 +256,12 @@ CommandHandler.RegisterCommand("rejoin", args => {
|
||||||
var res = MultiUserCommandHelper(args);
|
var res = MultiUserCommandHelper(args);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.Append(res.toActUpon.Count > 0 ? "Crashed: " + string.Join(", ", res.toActUpon.Select(x => $"\"{x.Name}\"")) + "\n" : "");
|
sb.Append(res.toActUpon.Count > 0 ? "Banned: " + string.Join(", ", res.toActUpon.Select(x => $"\"{x.Name}\"")) : "");
|
||||||
sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : "");
|
sb.Append(res.failToFind.Count > 0 ? "\nFailed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) : "");
|
||||||
if (res.ambig.Count > 0) {
|
if (res.ambig.Count > 0) {
|
||||||
res.ambig.ForEach(x => {
|
res.ambig.ForEach(x => {
|
||||||
sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
|
sb.Append($"\nAmbiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}");
|
||||||
});
|
});
|
||||||
sb.Remove(sb.Length - 1, 1); //remove extra nl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Client user in res.toActUpon) {
|
foreach (Client user in res.toActUpon) {
|
||||||
|
@ -279,13 +279,12 @@ CommandHandler.RegisterCommand("crash", args => {
|
||||||
var res = MultiUserCommandHelper(args);
|
var res = MultiUserCommandHelper(args);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.Append(res.toActUpon.Count > 0 ? "Crashed: " + string.Join(", ", res.toActUpon.Select(x => $"\"{x.Name}\"")) + "\n" : "");
|
sb.Append(res.toActUpon.Count > 0 ? "Banned: " + string.Join(", ", res.toActUpon.Select(x => $"\"{x.Name}\"")) : "");
|
||||||
sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : "");
|
sb.Append(res.failToFind.Count > 0 ? "\nFailed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) : "");
|
||||||
if (res.ambig.Count > 0) {
|
if (res.ambig.Count > 0) {
|
||||||
res.ambig.ForEach(x => {
|
res.ambig.ForEach(x => {
|
||||||
sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
|
sb.Append($"\nAmbiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}");
|
||||||
});
|
});
|
||||||
sb.Remove(sb.Length - 1, 1); //remove extra nl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Client user in res.toActUpon) {
|
foreach (Client user in res.toActUpon) {
|
||||||
|
@ -309,6 +308,8 @@ CommandHandler.RegisterCommand("ban", args => {
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Testing
|
#region Testing
|
||||||
|
//server.Clients.Clear();
|
||||||
|
|
||||||
//void TestAddClients()
|
//void TestAddClients()
|
||||||
//{
|
//{
|
||||||
// Client c1 = new Client(null!);
|
// Client c1 = new Client(null!);
|
||||||
|
@ -348,13 +349,12 @@ CommandHandler.RegisterCommand("ban", args => {
|
||||||
var res = MultiUserCommandHelper(args);
|
var res = MultiUserCommandHelper(args);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.Append(res.toActUpon.Count > 0 ? "Banned: " + string.Join(", ", res.toActUpon.Select(x => $"\"{x.Name}\"")) + "\n" : "");
|
sb.Append(res.toActUpon.Count > 0 ? "Banned: " + string.Join(", ", res.toActUpon.Select(x => $"\"{x.Name}\"")) : "");
|
||||||
sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : "");
|
sb.Append(res.failToFind.Count > 0 ? "\nFailed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) : "");
|
||||||
if (res.ambig.Count > 0) {
|
if (res.ambig.Count > 0) {
|
||||||
res.ambig.ForEach(x => {
|
res.ambig.ForEach(x => {
|
||||||
sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
|
sb.Append($"\nAmbiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}");
|
||||||
});
|
});
|
||||||
sb.Remove(sb.Length - 1, 1); //remove extra nl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Client user in res.toActUpon) {
|
foreach (Client user in res.toActUpon) {
|
||||||
|
|
Loading…
Reference in a new issue