40 lines
888 B
C#
Raw Normal View History

2024-01-27 20:05:24 +01:00
using Newtonsoft.Json;
2024-01-27 19:58:02 +01:00
using System;
2024-01-27 10:19:32 +01:00
using System.Text.RegularExpressions;
2024-01-27 19:58:02 +01:00
[Serializable]
2024-01-27 20:05:24 +01:00
[JsonObject]
2024-01-27 10:19:32 +01:00
public class Player
{
public string name;
public string id;
2024-01-27 17:54:37 +01:00
public Player(string _name)
{
2024-01-27 19:58:02 +01:00
id = Guid.NewGuid().ToString();
2024-01-27 19:57:11 +01:00
SetName( _name);
2024-01-27 17:54:37 +01:00
}
2024-01-27 10:19:32 +01:00
/// <summary>
/// Will sanitize the text and set it for the player
/// </summary>
public void SetName(string _name)
{
name = SanitizeString(_name);
}
private string SanitizeString(string input)
{
// Utilisez une expression régulière pour supprimer tout ce qui n'est pas une lettre ou un chiffre
string sanitized = Regex.Replace(input, @"[^a-zA-Z0-9]", "");
// Limitez la longueur à 16 caractères maximum
if (sanitized.Length > 16)
{
2024-01-27 19:58:02 +01:00
sanitized = sanitized[..16];
2024-01-27 10:19:32 +01:00
}
return sanitized;
}
}