ModernUO/Projects/UOContent/Misc/RenameRequests.cs
Kamron Batman a94814a7ef
fix: Fixes and optimizes NameVerification and ProfanityProtection (#2153)
### Summary

Significantly improves the performance of NameVerification & ProfanityProtection:

```cs
| Method         | Mean      | Error     | StdDev    |
|--------------- |----------:|----------:|----------:|
| ValidateName   | 728.34 ns | 13.244 ns | 11.059 ns |
| ValidateNameSV |  26.62 ns |  0.233 ns |  0.207 ns |
```
2025-04-12 02:26:10 -07:00

31 lines
861 B
C#

using System;
namespace Server.Misc;
public static class RenameRequests
{
public static void RenameRequest(Mobile from, Mobile targ, string name)
{
if (!from.CanSee(targ) || !from.InRange(targ, 12) || !targ.CanBeRenamedBy(from))
{
return;
}
var span = name.AsSpan().Trim();
if (NameVerification.ValidatePetName(span))
{
// Pet ~1_OLDPETNAME~ renamed to ~2_NEWPETNAME~.
from.SendLocalizedMessage(1072623, $"{targ.Name}\t{span}");
targ.Name = span.ToString();
}
else if (span.IndexOfAny(ProfanityProtection.DisallowedSearchValues) != -1)
{
from.SendLocalizedMessage(1072622); // That name isn't very polite.
}
else
{
from.SendMessage("That name is unacceptable.");
}
}
}