public override void Enter() { if (useBase64Encoding.Value) { str.Value = System.Convert.ToBase64String(ES3.LoadRawBytes(GetSettings())); } else { str.Value = ES3.LoadRawString(GetSettings()); } }
// Start is called before the first frame update void Start() { //Disable the SaveFile Conflict Panel (just in case) OnlineLocalSavePanel.SetActive(false); //Check if We're starting the game with a local SaveFile + loading important parameters if (ES3.FileExists("SaveData.es3")) { LocalLastTimeSaved = ES3.Load <string>("LastSaved"); LocalSaveFilePath = Application.persistentDataPath + "/" + SaveFileName; LocalSaveFileData = ES3.LoadRawString(SaveFileName); } else { StartUpWithoutLocalSaveFile = true; //Create a local SaveFile so we can write our Data to it later // Create a file and write a default Json profile using (StreamWriter sw = File.CreateText(Application.persistentDataPath + "/" + SaveFileName)) { sw.WriteLine("{}"); sw.Close(); } LocalSaveFilePath = Application.persistentDataPath + "/" + SaveFileName; Debug.Log("SaveFile File Created"); } //We're Checking for a Key again because User can play the game and create a local SaveFile without logging in if (ES3.KeyExists("SaveFileAssociatedUserID")) { AssociatedUserID = ES3.Load <string>("SaveFileAssociatedUserID"); Debug.Log("SaveFile already has a UserID associated with it " + AssociatedUserID); } //Load the FirstLogin Var if (ES3.KeyExists("FirstLogin")) { FirstLogin = ES3.Load <bool>("FirstLogin"); } //Create the Usr SaveFile (where we store the last UserID we use to sync the SaveFile when the User closes the game) if it doesnt exists if (ES3.FileExists("usr.es3") == false) { // Create a file and write a default Json profile using (StreamWriter sw = File.CreateText(Application.persistentDataPath + "/usr.es3")) { sw.WriteLine("{}"); sw.Close(); } Debug.Log("USR File Created"); } else { Debug.Log("File already exists"); } //start the ConnectToDatabase function from another Thread ThreadStart ThreadRef = new ThreadStart(ConnectToDatabase); Thread ConnectThread = new Thread(ThreadRef); ConnectThread.Start(); }
//Syncs the SaveFile void SaveFileSync() { if (SQLconnectionState == 2) { try { //Update Online SaveFile date We Update the Date first so the other GameObjects have time to save their values so we dont upload an old SaveFile to the Database string sql2 = "UPDATE SaveFiles SET SaveFile_datum = '" + currentTime + "' WHERE SaveFile_id = '" + UserID + "'"; MySqlCommand cmd2 = new MySqlCommand(sql2, conn); cmd2.ExecuteNonQuery(); //Update Online SaveFiles (we have to encode the SaveFile into Base64 format because the " symbols in the SaveFile confuse MySQL) string sql = "UPDATE SaveFiles SET SaveFile_file = '" + Base64Encode(ES3.LoadRawString(SaveFileName)) + "' WHERE SaveFile_id = '" + UserID + "'"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); Debug.Log("Synced SaveFile"); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } } else { Debug.Log("Cant Sync SaveFile: we're not logged in"); } }