Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <string>
- #include <vector>
- class AntiCheat {
- public:
- AntiCheat() {
- }
- void logAction(const std::string& playerName, double value) {
- auto playerIter = players.find(playerName);
- if (playerIter == players.end()) {
- playerIter = players.emplace(playerName, Player(playerName)).first;
- }
- playerIter->second.addAction(value);
- auto baselineIter = baselines.find(playerName);
- if (baselineIter == baselines.end()) {
- baselineIter = baselines.emplace(playerName, calculateBaseline(playerIter->second)).first;
- }
- if (abs(value - baselineIter->second) > threshold) {
- std::cout << "Detected unusual activity from player " << playerName << ": " << value << std::endl;
- // Take appropriate action (e.g. ban player)
- }
- }
- private:
- double calculateBaseline(const Player& player) {
- // Calculate baseline of normal behavior for player
- }
- class Player {
- public:
- Player(const std::string& name) : name(name) {
- }
- void addAction(double value) {
- actions.push_back(value);
- }
- private:
- std::string name;
- std::vector<double> actions;
- };
- std::map<std::string, Player> players
Add Comment
Please, Sign In to add comment