public static void localLoad()
    {
        if (!isLocal)
        {
            return;
        }

        try
        {
            Debug.Log(localIncreData);
            Incre = JsonConvert.DeserializeObject <IncrementalData>(localIncreData);
        }
        catch
        {
            Incre = new IncrementalData();
        }
        try
        {
            Sudoku = JsonConvert.DeserializeObject <sudokuData>(localMasterData);
        }
        catch
        {
            Sudoku = new sudokuData();
        }
        try
        {
            GlobalControl.Instance = JsonConvert.DeserializeObject <GlobalControl>(localSeekerData);
        }
        catch
        {
            GlobalControl.Instance = new GlobalControl();
        }
    }
Exemple #2
0
        //args[0] should be the csv file
        static void Main(string[] args)
        {
            //check if correct amount of arguments are given
            if (args.Length == 0 || args.Length > 1) //only one argument is used
            {
                Console.WriteLine("Please give a single file's pathname as command argument.\n");
                return;
            }

            //check if given csv file exits
            if (!File.Exists(args[0]))
            {
                Console.WriteLine("File does not exist. Please give the CSV file's correct absolute path.\n");
                return;
            }

            MongoServer DBServer = new MongoClient("mongodb://localhost:443").GetServer();

            PlayerCollection = DBServer.GetDatabase("test").GetCollection <BsonDocument>("playersV2");

            //read file line by line
            List <string> lines = File.ReadAllLines(@args[0]).ToList <string>();

            foreach (string line in lines)
            {
                string[] split = line.Split(',');
                //check if username exists in db
                BsonDocument player = PlayerCollection.FindOne(new QueryDocument("Username", split[0]));
                if (player != null)
                {
                    data = JsonConvert.DeserializeObject <IncrementalData>(player.GetValue("Incremental").AsString);

                    //do something with data such as restoring time or stamina
                    double output;
                    if (double.TryParse(split[1], out output))
                    {
                        if (output + data.stamina.cur >= data.stamina.max)
                        {
                            data.stamina.cur = output;
                        }
                        else
                        {
                            data.stamina.cur += output;
                        }
                    }

                    //convert data back to json string
                    string json = JsonConvert.SerializeObject(data);
                    player.Set("Incremental", json);

                    //save changes
                    PlayerCollection.Save(player);
                }
                else
                {
                    //do something since username not found
                }
            }
        }
Exemple #3
0
        public void ReadsIncrementalRetryStrategyValuesFromConfiguration()
        {
            var             settings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(this.configurationSource);
            IncrementalData data     = (IncrementalData)settings.RetryStrategies.Get("Incremental Non Default");

            Assert.AreEqual("Incremental Non Default", data.Name);
            Assert.AreEqual(new TimeSpan(0, 0, 1), data.InitialInterval);
            Assert.AreEqual(new TimeSpan(0, 0, 2), data.RetryIncrement);
            Assert.AreEqual(3, data.MaxRetryCount);
            Assert.AreEqual(false, data.FirstFastRetry);
        }
    public static void load()
    {
        JsonStrings loadedjsonStrings = JsonConvert.DeserializeObject <JsonStrings>(NetworkManager.Instance.loaded_json);

        Debug.Log(loadedjsonStrings.Incremental);
        Debug.Log(loadedjsonStrings.Mastermind);
        Debug.Log(loadedjsonStrings.Conqueror);
        Debug.Log(loadedjsonStrings.Seeker);
        if (loadedjsonStrings.Incremental.Length > 0)
        {
            try
            {
                Incre = JsonConvert.DeserializeObject <IncrementalData>(loadedjsonStrings.Incremental);
            }
            catch
            {
                Incre = new IncrementalData();
            }
        }
        if (loadedjsonStrings.Mastermind.Length > 0)
        {
            try
            {
                Sudoku = JsonConvert.DeserializeObject <sudokuData>(loadedjsonStrings.Mastermind);
            }
            catch
            {
                Sudoku = new sudokuData();
            }
        }
        if (loadedjsonStrings.Conqueror.Length > 0)
        {
            try
            {
                Conqueror = JsonConvert.DeserializeObject <Player>(loadedjsonStrings.Conqueror);
            }
            catch
            {
                Conqueror = new Player();
            }
        }
        if (loadedjsonStrings.Seeker.Length > 0)
        {
            try
            {
                seekerData = JsonConvert.DeserializeObject <seeker>(loadedjsonStrings.Seeker);
            }
            catch
            {
                seekerData = new seeker();
            }
        }
    }
Exemple #5
0
 public static void load(string input, game g)
 {
     try
     {
         if (g == game.incremental)
         {
             Incre = JsonConvert.DeserializeObject <IncrementalData>(input);
         }
         else if (g == game.mastermind)
         {
             Sudoku = JsonConvert.DeserializeObject <sudokuData>(input);
         }
     }
     catch
     {
     }
 }
Exemple #6
0
        public string LogIn(string inputUsername, string inputPassword, ref int status)
        {
            //Check if the player exists
            PlayerDocument = PlayerCollection.FindOne(new QueryDocument("Username", inputUsername));
            //If username is not found in PlayerCollection, it sets PlayerDocument to null, return false in this case
            if (PlayerDocument == null)
            {
                status = -1;  //Error: Username not found
                return(null);
            }
            //Verify password
            //Get the saved hash and separate it into separate hash and salt arrays
            string savedHash = PlayerDocument.GetElement("Password").Value.ToString();

            byte[] hashBytes = Convert.FromBase64String(savedHash);
            byte[] salt      = new byte[16];
            Array.Copy(hashBytes, 0, salt, 0, 16);
            //Compute the hash for the entered password
            var pbkdf2 = new Rfc2898DeriveBytes(inputPassword, salt, 10000);

            byte[] hash = pbkdf2.GetBytes(20);
            //Compare byte by byte. If any bytes don't match, the passwords are incorrect
            for (int i = 0; i < 20; i++)
            {
                if (hashBytes[i + 16] != hash[i])
                {
                    status = -2;
                    return(null);
                }
            }

            //Credentials match, so log player in
            Username = inputUsername;
            string loginCookie;

            //Set login time
            if (!PlayerDocument.Contains("Logins"))
            {
                PlayerDocument.Set("Logins", new BsonArray());
            }
            PlayerLogins = PlayerDocument.GetValue("Logins").AsBsonArray;
            //int LoginIndex = PlayerLogins.Count;
            logger.Debug(LogType.DATABASE, DateTime.Now + ": user " + Username + " logged in");

            Login = new BsonDocument();
            Login.SetElement(new BsonElement("LoginTime", System.DateTime.Now));
            PlayerLogins.Add(Login);
            //Login = PlayerLogins[LoginIndex] as BsonDocument;
            //Login.SetElement(new BsonElement("LoginTime", System.DateTime.Now));

            //Generate unique login cookie
            byte[] lCookie = new byte[16];
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            rng.GetBytes(lCookie);
            loginCookie = Convert.ToBase64String(lCookie);
            if (!PlayerDocument.Contains("LoginCookie"))
            {
                PlayerDocument.SetElement(new BsonElement("LoginCookie", loginCookie));
            }
            SetElement(PlayerDocument, "LoginCookie", loginCookie);

            //Save document now, to store the new login cookie
            PlayerCollection.Save(PlayerDocument);

            //Initialize player's games
            if (!PlayerDocument.Contains("Seeker"))
            {
                PlayerDocument.SetElement(new BsonElement("Seeker", ""));
            }
            PlayersSeeker = PlayerDocument.GetValue("Seeker");

            if (!PlayerDocument.Contains("Conqueror"))
            {
                PlayerDocument.SetElement(new BsonElement("Conqueror", ""));
            }
            PlayersConqueror = PlayerDocument.GetValue("Conqueror");

            if (!PlayerDocument.Contains("Mastermind"))
            {
                PlayerDocument.SetElement(new BsonElement("Mastermind", ""));
            }
            PlayersMastermind = PlayerDocument.GetValue("Mastermind");

            /*
             *          if (!PlayerDocument.Contains("Survival"))
             *                  PlayerDocument.Set("Survival", new BsonDocument());
             *          PlayersSurvival = PlayerDocument.GetValue("Survival").AsBsonDocument;*/

            if (!PlayerDocument.Contains("Incremental"))
            {
                //PlayerDocument.Set("Incremental", "");
                IncrementalData data = new IncrementalData();
                data.stamina.cur = 0;
                PlayerDocument.Set("Incremental", JsonConvert.SerializeObject(data));
            }
            PlayersIncremental = PlayerDocument.GetValue("Incremental");

            //Initialize player's list of achievements

            /*
             * if (!PlayerDocument.Contains("Achievements"))
             *  PlayerDocument.Set("Achievements", new BsonDocument());
             * PlayerAchievements = PlayerDocument.GetValue("Achievements").AsBsonDocument;
             *
             * //Initialize player's list of achievement milestones
             * if (!PlayerDocument.Contains("AchievementMilestones"))
             *  PlayerDocument.Set("AchievementMilestones", new BsonDocument());
             * PlayerMilestones = PlayerDocument.GetValue("AchievementMilestones").AsBsonDocument;
             *
             * //Initialize player's list of achievement stats
             * if (!PlayerDocument.Contains("AchievementStats"))
             *  PlayerDocument.Set("AchievementStats", new BsonDocument());
             * PlayerAchievementStats = PlayerDocument.GetValue("AchievementStats").AsBsonDocument;
             *
             * //Initialize player's list of bonus codes
             * if (!PlayerDocument.Contains("BonusCodes"))
             *  PlayerDocument.Set("BonusCodes", new BsonArray());
             * Bonuses = new List<Bonus>();
             * PlayerBonusCodes = PlayerDocument.GetValue("BonusCodes").AsBsonArray;
             *
             * //Initialize player's inventory
             * if (!PlayerDocument.Contains("Inventory"))
             *  PlayerDocument.Set("Inventory", new BsonArray());
             * PlayerInventory = PlayerDocument.GetValue("Inventory").AsBsonArray;
             *
             * //Initialize recipes
             * if (!PlayerDocument.Contains("Recipes"))
             *  PlayerDocument.Set("Recipes", new BsonDocument());
             * PlayerRecipes = PlayerDocument.GetValue("Recipes").AsBsonDocument;
             *
             * //*/

            //Return the login cookie
            return(loginCookie);
        }
Exemple #7
0
    public static void load()
    {
        JsonStrings loadedjsonStrings;

        try
        {
            loadedjsonStrings = JsonConvert.DeserializeObject <JsonStrings>(NetworkManager.Instance.loaded_json);
        }
        catch
        {
            loadedjsonStrings = new JsonStrings();
        }

        Debug.Log(loadedjsonStrings.incremental);
        Debug.Log(loadedjsonStrings.mastermind);
        Debug.Log(loadedjsonStrings.conqueror);
        Debug.Log(loadedjsonStrings.seeker);
        Debug.Log(loadedjsonStrings.daredevil);
        Debug.Log(loadedjsonStrings.sokoban);

        if (loadedjsonStrings.incremental.Length > 0) //doesn't go in blocks if loaded string is empty string
        {
            try
            {
                Incre = JsonConvert.DeserializeObject <IncrementalData>(loadedjsonStrings.incremental);
            }
            catch
            {
                Incre = new IncrementalData();
            }
        }
        else
        {
            Incre = new IncrementalData();
        }

        if (loadedjsonStrings.mastermind.Length > 0)
        {
            try
            {
                Sudoku = JsonConvert.DeserializeObject <sudokuData>(loadedjsonStrings.mastermind);
            }
            catch
            {
                Sudoku = new sudokuData();
            }
        }
        else
        {
            Sudoku = new sudokuData();
        }

        if (loadedjsonStrings.conqueror.Length > 0)
        {
            try
            {
                conqueror = JsonConvert.DeserializeObject <ConquerorSave>(loadedjsonStrings.conqueror.ToString());
            }
            catch (Exception ex)
            {
                Debug.Log(ex.ToString());
                conqueror = new ConquerorSave();
            }
        }
        else
        {
            conqueror = new ConquerorSave();
        }

        if (loadedjsonStrings.seeker.Length > 0)
        {
            try
            {
                seekerData = JsonConvert.DeserializeObject <seeker>(loadedjsonStrings.seeker);
            }
            catch
            {
                seekerData = new seeker();
            }
        }
        else
        {
            seekerData = new seeker();
        }

        if (loadedjsonStrings.daredevil.Length > 0)
        {
            try
            {
                daredevilSave = JsonConvert.DeserializeObject <DaredevilSave>(loadedjsonStrings.daredevil);
            }
            catch
            {
                daredevilSave = new DaredevilSave();
            }
        }
        else
        {
            daredevilSave = new DaredevilSave();
        }

        if (loadedjsonStrings.daredevil.Length > 0)
        {
            try
            {
                daredevilSave = JsonConvert.DeserializeObject <DaredevilSave>(loadedjsonStrings.daredevil);
            }
            catch
            {
                daredevilSave = new DaredevilSave();
            }
        }
        else
        {
            daredevilSave = new DaredevilSave();
        }

        if (loadedjsonStrings.sokoban.Length > 0)
        {
            try
            {
                sokobanSave = JsonConvert.DeserializeObject <SokobanSave>(loadedjsonStrings.sokoban);
            }
            catch
            {
                sokobanSave = new SokobanSave();
            }
        }
        else
        {
            sokobanSave = new SokobanSave();
        }

        Incre.username = NetworkManager.Instance.GetUsername();
    }