51 lines
1.1 KiB
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 22:26:23 +01:00
using UnityEngine;
2024-01-27 10:19:32 +01:00
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-28 00:59:12 +01:00
public double creationDate;
2024-01-27 10:19:32 +01:00
[JsonConstructor]
2024-01-28 00:59:12 +01:00
public Player(string _name, string _id, double _creationDate)
{
name = _name;
id = _id;
2024-01-27 22:26:23 +01:00
creationDate = _creationDate;
}
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-28 00:59:12 +01:00
creationDate = DateTime.Now.ToOADate();
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;
}
}