~nickwinston123/armagetronad/arma_chatbot_config

« back to all changes in this revision

Viewing changes to game_manager/game_manager.py

  • Committer: hackermans
  • Date: 2025-05-29 20:16:47 UTC
  • Revision ID: nickwinston123@gmail.com-20250529201647-ybinllbs3ntf7xld
- arma_terminal
 - added clear_key setting that will clear the log buffer
 - added ability to click line and copy to clipboard or press f2 to copy entire buffer
- ollama_chat
 - smart_processor param to enable AI if there are smart_processor_active_players active players or less
 - Ractor/fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    logging.error(f"Error retrieving configuration values: {e}")
35
35
    sys.exit(1)
36
36
 
 
37
IP_SERVICES = [
 
38
    'https://httpbin.org/ip',               # returns {"origin": "x.x.x.x"}
 
39
    'https://api.ipify.org?format=json',    # returns {"ip": "x.x.x.x"}
 
40
    'https://ipinfo.io/json',               # returns {"ip": "x.x.x.x", ...}
 
41
    'https://icanhazip.com',                # returns plain text "x.x.x.x\n"
 
42
    'https://checkip.amazonaws.com'         # returns plain text "x.x.x.x\n"
 
43
]
 
44
 
37
45
 
38
46
log_formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s", datefmt="%H:%M:%S")
39
47
 
328
336
    logging.warning("Timeout reached waiting for VPN initialization.")
329
337
    return False
330
338
 
 
339
def fetch_ip_from_service(url):
 
340
    try:
 
341
        resp = requests.get(url, timeout=5)
 
342
        resp.raise_for_status()
 
343
        if url.endswith('/ip'):
 
344
            return resp.json()['origin'].strip()
 
345
        elif 'ipify' in url or 'ipinfo' in url:
 
346
            return resp.json()['ip'].strip()
 
347
        else:
 
348
            return resp.text.strip()
 
349
    except Exception as e:
 
350
        logging.warning(f"Failed to get IP from {url}: {e}")
 
351
        return None
 
352
 
331
353
def get_current_ip(real_ip, retry_interval=1, max_retries=30):
332
354
    retries = 0
333
355
    while retries < max_retries:
334
 
        try:
335
 
            resp = requests.get('https://httpbin.org/ip', timeout=5)
336
 
            current_ip = resp.json()['origin'].strip()
337
 
            logging.info(f"Fetched IP: {current_ip}")
338
 
            if current_ip != real_ip:
 
356
        for service in IP_SERVICES:
 
357
            current_ip = fetch_ip_from_service(service)
 
358
            if current_ip and current_ip != real_ip:
 
359
                logging.info(f"Fetched new IP: {current_ip} from {service}")
339
360
                return current_ip
340
 
            logging.warning("Current IP still matches REAL_IP. Waiting for new IP...")
341
 
        except Exception as e:
342
 
            logging.error(f"Error fetching IP (retrying): {e}")
 
361
            elif current_ip == real_ip:
 
362
                logging.warning(f"IP from {service} still matches REAL_IP. Retrying...")
343
363
        time.sleep(retry_interval)
344
364
        retries += 1
 
365
    logging.error("Max retries reached. Failed to get a new IP.")
345
366
    return None
346
367
 
347
368
def connect_until_new_ip(real_ip, banned_ip=None):