Esempio n. 1
0
    /**
     * Checks if auth file exists, if not creates it
     * If auth file is empty ask for our token to the server
     * Else go to welcome screen
     **/
    private void ManageRegistrationScreen()
    {
        mTimeout.Reset();
        if (!System.IO.File.Exists(Application.persistentDataPath + "/auth_file.txt"))
        {
            Debug.Log("creating auth.txt");
            System.IO.File.Create(Application.persistentDataPath + "/auth_file.txt");
        }
        else
        {
            if (new System.IO.FileInfo(Application.persistentDataPath + "/auth_file.txt").Length == 0 && timeStart.AddSeconds(10) < DateTime.Now)
            {
                string androidID = mAndroidSID.GetSID();
                Debug.Log("SID is " + androidID);
                timeStart = DateTime.Now;
                if (authentification_state == 0)
                {
                    try
                    {
                        bool auth = mSharingServer.GetAuth();

                        if (auth == true)
                        {
                            authentification_state = 1;
                        }
                        else
                        {
                            mSharingServer.SendToServerAuthentication(androidID);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message);
                    }
                }
                else
                {
                    string token = mSharingServer.GetToken();
                    if (token != null)
                    {
                        using (System.IO.StreamWriter outputFile = new System.IO.StreamWriter(Application.persistentDataPath + "/auth_file.txt"))
                        {
                            outputFile.WriteLine(token);
                        }
                        authentification_state = 2;
                    }
                    else
                    {
                        mSharingServer.SendToServerAskToken(androidID);
                    }
                }
            }
            else if (new System.IO.FileInfo(Application.persistentDataPath + "/auth_file.txt").Length != 0)
            {
                System.IO.StreamReader file = new System.IO.StreamReader(Application.persistentDataPath + "/auth_file.txt");
                string line = file.ReadLine();
                Debug.Log("Token :" + line);
                mSharingServer.SetToken(line);
                authentification_state = 3;
                mCurrentState          = ScreensStates.WELCOME;
                UpdateScreen();
            }
        }
    }