Josiahiscool73

eeeeee

Jul 1st, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. # aim_server.py (Version 4 - Final Fix)
  2. # This script runs on your more powerful Windows PC.
  3.  
  4. import cv2
  5. import numpy as np
  6. import base64
  7. from flask import Flask
  8. from flask_socketio import SocketIO
  9. from ultralytics import YOLO
  10. import os
  11.  
  12. # --- Configuration ---
  13. # Make sure to set your IP here.
  14. SERVER_HOST = 'YOUR_WINDOWS_LAPTOP_IP' # e.g., '192.168.1.15'
  15. SERVER_PORT = 5000
  16. CONFIDENCE_THRESHOLD = 0.4
  17.  
  18. # --- AI Model Setup ---
  19. print("Loading AI model...")
  20. try:
  21. # This loads your custom fortnite model, which you've named 'yolov8n.pt'
  22. model = YOLO('yolov8n.pt')
  23. print("AI Model loaded successfully.")
  24. except Exception as e:
  25. print(f"Error loading model: {e}")
  26. exit()
  27.  
  28. # --- Server Setup ---
  29. app = Flask(__name__)
  30. socketio = SocketIO(app, async_mode='threading', cors_allowed_origins="*")
  31.  
  32. # --- Image Processing Function ---
  33. def process_frame(data_url):
  34. try:
  35. encoded_data = data_url.split(',')[1]
  36. nparr = np.frombuffer(base64.b64decode(encoded_data), np.uint8)
  37. frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
  38. if frame is None: return None
  39.  
  40. results = model(frame, classes=[0], verbose=False) # Assumes your player class is 0
  41. best_target = None
  42. highest_conf = 0
  43.  
  44. for result in results:
  45. for box in result.boxes:
  46. conf = box.conf[0].item()
  47. if conf > CONFIDENCE_THRESHOLD and conf > highest_conf:
  48. highest_conf = conf
  49. xyxy = box.xyxy[0].cpu().numpy()
  50. center_x = int((xyxy[0] + xyxy[2]) / 2)
  51. center_y = int((xyxy[1] + xyxy[3]) / 2)
  52. best_target = {'x': center_x, 'y': center_y}
  53. return best_target
  54. except Exception:
  55. return None
  56.  
  57. # --- WebSocket Event Handlers ---
  58. @socketio.on('connect')
  59. def handle_connect():
  60. print(f"Client connected securely!")
  61. @socketio.on('disconnect')
  62. def handle_disconnect():
  63. print("Client disconnected.")
  64. @socketio.on('frame')
  65. def handle_frame(data_url):
  66. target = process_frame(data_url)
  67. if target:
  68. socketio.emit('aim_target', target)
  69.  
  70. # --- Main Entry Point ---
  71. if __name__ == '__main__':
  72. if SERVER_HOST == 'YOUR_WINDOWS_LAPTOP_IP':
  73. print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  74. print("!!! ERROR: You must edit the SERVER_HOST variable in !!!")
  75. print("!!! this script before running. !!!")
  76. print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  77. elif not os.path.exists('cert.pem') or not os.path.exists('key.pem'):
  78. print("!!! ERROR: cert.pem or key.pem not found. Run generate_cert.py first! !!!")
  79. else:
  80. print(f"Starting secure server on https://{SERVER_HOST}:{SERVER_PORT}")
  81.  
  82. # =======================================================================
  83. # === THIS IS THE FIX. We now use ssl_context instead of keyfile. ===
  84. # =======================================================================
  85. socketio.run(app, host=SERVER_HOST, port=SERVER_PORT, debug=False,
  86. ssl_context=('cert.pem', 'key.pem'))
Add Comment
Please, Sign In to add comment