// Unique Character Names v1.1.2 // Author: Felladrin // Started: 2013-08-01 // Updated: 2016-07-28 using System; using Server; using Server.Gumps; using Server.Misc; using Server.Mobiles; using Server.Network; namespace Felladrin.Automations { public static class UniqueCharacterNames { public static void Initialize() { EventSink.Login += OnLogin; } static void OnLogin(LoginEventArgs args) { Mobile from = args.Mobile; if (HasValidName(from)) return; from.SendMessage(33, "Your character name '{0}' is already in use by player character or it has been marked as invalid. Please choose a new one.", from.Name); from.RawName = "Generic Player"; from.SendGump(new NameChangeGump()); } static bool HasValidName(Mobile m) { if (m.AccessLevel != AccessLevel.Player) return true; if (m.RawName == null || m.RawName.Trim() == String.Empty || m.RawName == "Generic Player" || !NameVerification.Validate(m.RawName, 2, 16, true, false, true, 1, NameVerification.SpaceDashPeriodQuote)) return false; foreach (Mobile otherPlayer in World.Mobiles.Values) if (otherPlayer is PlayerMobile && otherPlayer != m && otherPlayer.RawName != null && m.RawName != null && otherPlayer.RawName.ToLower() == m.RawName.ToLower() && m.CreationTime > otherPlayer.CreationTime) return false; return true; } public class NameChangeGump : Gump { void AddBlackAlpha(int x, int y, int width, int height) { AddImageTiled(x, y, width, height, 2624); AddAlphaRegion(x, y, width, height); } void AddTextField(int x, int y, int width, int height, int index) { AddBackground(x - 2, y - 2, width + 4, height + 4, 0x2486); AddTextEntry(x + 2, y + 2, width - 4, height - 4, 0, index, ""); } static string Center(string text) { return String.Format("