public bool playerIsElegible(int requestID, int slotID, Player player) { if (player.getRequestIDForSlotID(slotID) == -1) //player has no spell { Console.WriteLine("[SpellChecker] player has no spell"); return false; } string spellName = GameRequest.getSpellNameByRequest(requestID); double expires = player.PlayerObject.GetObject(DBProperties.SPELL_OBJECT) .GetObject(spellName) .GetDouble(DBProperties.SPELL_EXPIRES); if (Utils.unixSecs() > expires + 20) //spell expired. 20 seconds buffer for possible time async { if (!activationBuffer.Contains(spellName)) //if spell i snot being activated at the moment { Console.WriteLine("[SpellChecker] spell expired"); return false; } Console.WriteLine( "[SpellChecker] spell expired but activation transaction is being processed, allowing usage"); } if (!lastUses.ContainsKey(player.realID + requestID)) lastUses[player.realID + requestID] = new DateTime(1970, 1, 1); //just fill in, so that key exists TimeSpan sp = DateTime.UtcNow - lastUses[player.realID + requestID]; if (GameConfig.getCooldownTimeByRequest(requestID) >= sp.TotalMilliseconds + 1500) //add some buffer, allowing for whatever delays/differences might be. Client checks properly, so it matters only in case of cheating { Console.WriteLine("[SpellChecker] spell did not cool down"); return false; } //we are good, may use lastUses[player.realID + requestID] = DateTime.UtcNow; //update last usage time return true; }
private void tryUseSpell(int slotID, Player requester) { int requestID = requester.getRequestIDForSlotID(slotID); Console.WriteLine("Game: try use spell: reqID: " + requestID + " slotID: " + slotID); //Commented down so that game runs on the Free Playerio plan (not paying for services for now) //if (_spellChecker.playerIsElegible(requestID, slotID, requester) && specificPowerupCheck()) //{ if (requestID == GameRequest.CHARM_BALLS) { var opponent = getOtherPlayers(requester, true)[0] as Player; opponent.goWiggle(); } else if (requestID == GameRequest.FREEZE) { var opponent = getOtherPlayers(requester, true)[0] as Player; opponent.goFreeze(); } else if (requestID == GameRequest.ROCKET) { var opponent = getOtherPlayers(requester, true)[0] as Player; opponent.goLaunchRocket(); } else //used for checking non-attacking spells. Because client insta-launches suvh spells we check them at server on execution requester.addAllowedSpell(requestID); //} //else //should not happen. Clicnt does all the checks. If we get here it means player is cheating //{ // Console.WriteLine("Unexpected spell usage attempt", "PlayerID: " + requester.realID + " RequestID: " + requestID + " SlotID: " + slotID, ""); // roomLink.PlayerIO.ErrorLog.WriteError("Unexpected spell usage attempt", "PlayerID: " + requester.realID + " RequestID: " + requestID + " SlotID: " + slotID, "", null); //} }