Skip to content

Commit

Permalink
scoreboard username sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
bozmir committed Dec 20, 2024
1 parent f753e9e commit d299b66
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Assets/FirebaseWebGL/Scoreboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEngine.UI;
using Newtonsoft.Json.Linq;
using System.Linq;
using System.Text.RegularExpressions;

namespace Netherlands3D.Twin
{
Expand Down Expand Up @@ -51,14 +52,19 @@ void OnEnable()

void Start()
{

nameInputField.characterLimit = 10;
// Attach button click listener
submitButton.onClick.AddListener(() => SubmitScore());

// Listen for updates to the scoreboard
ListenForScoreboardUpdates();
}

public string SanitizeInput(string input)
{
return Regex.Replace(input, @"[^a-zA-Z0-9\s]", ""); // Allows only letters, numbers, and spaces
}

void SubmitScore()
{
string userName = nameInputField.text;
Expand All @@ -70,6 +76,8 @@ void SubmitScore()
return;
}

SanitizeInput(userName);

// Create a score entry
var scoreData = new Dictionary<string, object>
{
Expand Down

0 comments on commit d299b66

Please sign in to comment.