Snaparazzi/Assets/Scripts/DatabaseClasses/Player.cs

40 lines
949 B
C#
Raw Normal View History

2024-01-27 09:19:32 +00:00
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
2024-01-27 11:24:47 +00:00
[System.Serializable]
2024-01-27 18:54:06 +00:00
[Newtonsoft.Json.JsonObject]
2024-01-27 09:19:32 +00:00
public class Player
{
public string name;
public string id;
2024-01-27 16:54:37 +00:00
public Player(string _name)
{
id = System.Guid.NewGuid().ToString();
name = _name;
}
2024-01-27 09:19:32 +00: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)
{
sanitized = sanitized.Substring(0, 16);
}
return sanitized;
}
}