public void ApplyEffectsWorks() { ItemData i = new ItemData(); ProgressVerifier.ApplyEffects(effList, i); Assert.AreEqual(0.24, i.Data[1].Tps); Assert.AreEqual(2, i.tofuClickEarnings); }
public void GetAllEffectsOfUpgradeArrayWorks() { Dictionary <int, Upgrade> u = Upgrade.upgradeData; Upgrade[] uArr = { u[100], u[1000], u[1001] }; List <Effect> effList = ProgressVerifier.GetAllEffects(uArr); Assert.AreEqual("0", effList[0].Benefactor); Assert.AreEqual("tps", effList[0].BenefactorProperty); Assert.AreEqual("1", effList[1].Benefactor); Assert.AreEqual(0.1, effList[1].Operand); Assert.AreEqual("1", effList[2].Benefactor); Assert.AreEqual("tps", effList[2].BenefactorProperty); Assert.AreEqual("*", effList[2].Operator); Assert.AreEqual(1.2, effList[2].Operand); }
public void SortEffectsWorks() { effList = new List <Effect>(); Effect e0 = Effect.Parse(@"1.tps*1.2"); Effect e1 = Effect.Parse(@"1.tps+0.1"); Effect e2 = Effect.Parse(@"0.tps+1"); effList.Add(e0); effList.Add(e1); effList.Add(e2); ProgressVerifier.SortEffects(effList); Assert.AreEqual(e0, effList[2]); Assert.AreEqual(e1, effList[0]); Assert.AreEqual(e2, effList[1]); }
public int SaveProgress(ProgressData progress) { //if connection is already invalidated if (!ValidityMap.CurrentInstance.Contains(Context.ConnectionId) || !ValidityMap.CurrentInstance[Context.ConnectionId]) { Debug.WriteLine("INVALID CONNECTION"); return(-1); } string dataRoot = AppDomain.CurrentDomain.GetData("DataDirectory").ToString(); //read cookie string c = AESCryptoStuff.CurrentInstance.AesDecrypt(HttpUtility.UrlDecode(Context.RequestCookies["userID"].Value)); //current time in UTC long utcTime = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; Hmac h = Hmac.CurrentInstance; #region SaveTime limit to 3 / min //check database if it's too soon Database d = Database.CurrentInstance; long[] times = new long[3]; //PRQ stands for Parameterized Reader Query, it returns a DataTable with all the rows //First argument is the query, every argument after that is the parameters //The @ parameters MUST START FROM 1 COUNTS UP FROM THERE //you can have any number of @ parameters and corresponding method arguments for the values DataTable dt = d.PRQ("SELECT * FROM savetime WHERE userID = @1", c); if (dt == null) { return(-2); //if database not up } if (dt.Rows.Count > 0) { //if you want to loop //foreach(DataRow dr in dt.Rows) DataRow dr = dt.Rows[0]; //Field method returns the value of the column specified in the type in the angle brackets times[0] = dr.Field <long>("time1"); times[1] = dr.Field <long>("time2"); times[2] = dr.Field <long>("time3"); } else { //PNQ stands for Parameterized Non Query, it returns nothing d.PNQ("INSERT INTO savetime (userID, time1, time2, time3) VALUES (@1, @2, @3, @4)", c, 0, 0, utcTime); times = new long[] { 0, 0, utcTime }; } if (utcTime - times[0] < 60000) //4th save in a minute { return(0); } else { times[0] = utcTime; Array.Sort(times); d.PNQ("UPDATE savetime SET time1 = @1, time2 = @2, time3 = @3 WHERE userID = @4", times[0], times[1], times[2], c); } #endregion //get previous save data SaveFile prevSave; try { string prevSaveText = System.IO.File.ReadAllText( dataRoot + "\\Saves\\" + h.Encode(c) + ".tusav"); prevSave = SaveFile.Parse(prevSaveText); } catch (FileNotFoundException e) //no existing save { long defaultTime = utcTime - 100000; //100 seconds leeway prevSave = new SaveFile(defaultTime, 0, new Dictionary <int, int>(), new int[] { }); } bool noCheats = ProgressVerifier.VerifyProgress(prevSave, progress, utcTime); Debug.WriteLine("IS CHEATING: " + !noCheats); //verify progress if (!noCheats) { //if caught cheating //insert cheat record into database d.PNQ("INSERT INTO cheatlog (userID, time) VALUES (@1, @2)", c, utcTime); ValidityMap.CurrentInstance[Context.ConnectionId] = false; return(-1); } //save + time on first line string s = "" + utcTime + '\n' + progress.ToString(); Debug.WriteLine("SAVING FOR " + h.Encode(c) + ":\n" + s); //write to file System.IO.File.WriteAllText( dataRoot + "\\Saves\\" + h.Encode(c) + ".tusav", s); return(1); }