2024-01-27 19:05:24 +00:00
|
|
|
using Newtonsoft.Json;
|
2024-01-27 18:58:02 +00:00
|
|
|
using System;
|
2024-01-27 09:19:32 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2024-01-27 21:26:23 +00:00
|
|
|
using UnityEngine;
|
2024-01-27 09:19:32 +00:00
|
|
|
|
2024-01-27 18:58:02 +00:00
|
|
|
[Serializable]
|
2024-01-27 19:05:24 +00:00
|
|
|
[JsonObject]
|
2024-01-27 09:19:32 +00:00
|
|
|
public class Player
|
|
|
|
{
|
|
|
|
public string name;
|
|
|
|
public string id;
|
2024-01-27 23:59:12 +00:00
|
|
|
public double creationDate;
|
2024-01-27 09:19:32 +00:00
|
|
|
|
2024-01-27 20:27:17 +00:00
|
|
|
[JsonConstructor]
|
2024-01-27 23:59:12 +00:00
|
|
|
public Player(string _name, string _id, double _creationDate)
|
2024-01-27 20:27:17 +00:00
|
|
|
{
|
|
|
|
name = _name;
|
|
|
|
id = _id;
|
2024-01-27 21:26:23 +00:00
|
|
|
creationDate = _creationDate;
|
|
|
|
|
2024-01-27 20:27:17 +00:00
|
|
|
}
|
|
|
|
|
2024-01-27 16:54:37 +00:00
|
|
|
public Player(string _name)
|
|
|
|
{
|
2024-01-27 18:58:02 +00:00
|
|
|
id = Guid.NewGuid().ToString();
|
2024-01-27 23:59:12 +00:00
|
|
|
creationDate = DateTime.Now.ToOADate();
|
2024-01-27 20:27:17 +00:00
|
|
|
SetName(_name);
|
2024-01-27 16:54:37 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2024-01-27 18:58:02 +00:00
|
|
|
sanitized = sanitized[..16];
|
2024-01-27 09:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sanitized;
|
|
|
|
}
|
|
|
|
}
|