YourMain12

Basic Anticheat (PYTHON)

Jan 6th, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. class AntiCheat:
  2.     def __init__(self):
  3.         self.players = {}
  4.         self.baselines = {}
  5.    
  6.     def log_action(self, player_name, value):
  7.         player = self.players.get(player_name)
  8.         if player is None:
  9.             player = Player(player_name)
  10.             self.players[player_name] = player
  11.         player.add_action(value)
  12.        
  13.         baseline = self.baselines.get(player_name)
  14.         if baseline is None:
  15.             baseline = self.calculate_baseline(player)
  16.             self.baselines[player_name] = baseline
  17.        
  18.         if abs(value - baseline) > self.threshold:
  19.             print(f"Detected unusual activity from player {player_name}: {value}")
  20.             # Take appropriate action (e.g. ban player)
  21.    
  22.     def calculate_baseline(self, player):
  23.         # Calculate baseline of normal behavior for player
  24.  
  25. class Player:
  26.     def __init__(self, name):
  27.         self.name = name
  28.         self.actions = []
  29.    
  30.     def add_action(self, value):
  31.         self.actions.append(value)
  32.  
Tags: python
Add Comment
Please, Sign In to add comment