wip: add some security

This commit is contained in:
Fangh 2024-02-04 13:02:58 +01:00
parent 2de1611c4d
commit 6454b54dc6
2 changed files with 15 additions and 16 deletions

View File

@ -467,6 +467,7 @@ public void OnClickSubmitSignIn()
public void onClickSamePlayers()
{
Debug.Log("Play with same players !", this);
Room newRoom = myRoom;
newRoom.currentState = (int)GameState.Explanation;
newRoom.questions.Clear();
@ -484,11 +485,13 @@ public void onClickSamePlayers()
}
public void onClickNewPlayers()
{
myRoom.currentState = (int)GameState.EnteringName;
myRoom.currentQuestionId = 0;
myRoom.questions = null;
myRoom.players = null;
string json = JsonConvert.SerializeObject(myRoom);
Debug.Log("Play with new players !", this);
Room newRoom = myRoom;
newRoom.currentState = (int)GameState.EnteringName;
newRoom.currentQuestionId = 0;
newRoom.questions = null;
newRoom.players = null;
string json = JsonConvert.SerializeObject(newRoom);
myOnlineRoom.SetRawJsonValueAsync(json).ContinueWithOnMainThread(task =>
{
@ -502,6 +505,9 @@ public void onClickNewPlayers()
private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlineValue)
{
if (onlineValue == null || onlineValue.Snapshot == null || onlineValue.Snapshot.Value == null)
return;
int questionId = onlineValue.Snapshot.Value.ConvertTo<int>();
Debug.Log($"new question ! Q{(onlineValue.Snapshot.Value.ConvertTo<int>())}");

View File

@ -12,7 +12,7 @@ public class QuestionHandler : MonoBehaviour
public PromptList promptList;
private GameManager gameManager;
private List<Question> questionsToAnswer;
private List<Question> questionsToAnswer = new List<Question>();
private int activeAnsweredQuestionIndex = 0;
private const int FirstQuestionIndex = 0;
@ -25,21 +25,14 @@ public class QuestionHandler : MonoBehaviour
/// </summary>
void OnEnable()
{
activeAnsweredQuestionIndex = FirstQuestionIndex;
submitButton.interactable = true;
submitButton.GetComponent<TextMeshProUGUI>().text = "Submit";
gameManager = managers.GetComponent<GameManager>();
questionsToAnswer = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer);
Redraw(activeAnsweredQuestionIndex);
}
/// <summary>
/// Called when the script is disabled.
/// Cleans up resources and resets the activeAnsweredQuestionIndex.
/// </summary>
void OnDisable()
{
questionsToAnswer = null;
activeAnsweredQuestionIndex = FirstQuestionIndex;
}
/// <summary>
/// Redraws the UI with the information from the current question.
/// </summary>