YourMain12

Basic Anticheat (SWIFT)

Jan 7th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.96 KB | None | 0 0
  1. import Foundation
  2.  
  3. // Set a flag to determine if the user is cheating
  4. var isCheating = false
  5.  
  6. // Define a function to check if the user is cheating
  7. func checkForCheats(input: String) {
  8.     // Set a list of cheats
  9.     let cheats = ["cheat1", "cheat2", "cheat3"]
  10.  
  11.     // Iterate through the list of cheats
  12.     for cheat in cheats {
  13.         // If the input contains a cheat, set the flag to true and break out of the loop
  14.         if input.contains(cheat) {
  15.             isCheating = true
  16.             break
  17.         }
  18.     }
  19. }
  20.  
  21. // Prompt the user for input
  22. print("Enter a command: ", terminator: "")
  23. if let userInput = readLine() {
  24.     // Check if the user is cheating
  25.     checkForCheats(input: userInput)
  26.  
  27.     // If the user is cheating, display a message and exit the program
  28.     if isCheating {
  29.         print("Cheating is not allowed!")
  30.         exit(0)
  31.     }
  32.  
  33.     // If the user is not cheating, continue with the program
  34.     print("Valid input")
  35. }
  36.  
Tags: swift
Add Comment
Please, Sign In to add comment