Update main.py
This commit is contained in:
64
main.py
64
main.py
@@ -1,9 +1,11 @@
|
||||
from rcon.battleye import Client
|
||||
import socket
|
||||
from rcon.battleye import Client, ServerMessage
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
|
||||
# Define the server details
|
||||
SERVER_ADDRESS = ''
|
||||
SERVER_PORT = 0
|
||||
@@ -37,7 +39,8 @@ def print_menu():
|
||||
print("3. Locking")
|
||||
print("4. Kicking")
|
||||
print("5. Banning")
|
||||
print("6. Exit")
|
||||
print("6. Server menu")
|
||||
print("7. Exit")
|
||||
|
||||
def handle_input(choice):
|
||||
if choice == "1":
|
||||
@@ -59,6 +62,10 @@ def handle_input(choice):
|
||||
banning_choice = input("Enter your choice: ")
|
||||
handle_banning_input(banning_choice)
|
||||
elif choice == "6":
|
||||
print_server_menu()
|
||||
server_choice = input("Enter your choice: ")
|
||||
handle_server_input(server_choice)
|
||||
elif choice == "7":
|
||||
sys.exit()
|
||||
else:
|
||||
print("Invalid choice. Please try again.")
|
||||
@@ -68,6 +75,11 @@ def print_message_menu():
|
||||
print("2. Send Direct Message")
|
||||
print("3. Back")
|
||||
|
||||
def print_server_menu():
|
||||
print("1. Soft Server Restart (Restart within 3 minutes with warning messages sent to the players)")
|
||||
print("2. Hard Server Restart (Restart immediately without warning messages)")
|
||||
print("3. Back")
|
||||
|
||||
def print_locking_menu():
|
||||
print("1. Lock Server")
|
||||
print("2. Unlock Server")
|
||||
@@ -129,6 +141,20 @@ def handle_banning_input(choice):
|
||||
else:
|
||||
print("Invalid choice. Please try again.")
|
||||
|
||||
def handle_server_input(choice):
|
||||
if choice == "1":
|
||||
soft_restart()
|
||||
elif choice == "2":
|
||||
confirm = input("Are you sure you want to perform a hard restart? (y/n): ")
|
||||
if confirm.lower() == "y":
|
||||
hard_restart()
|
||||
else:
|
||||
print("Hard restart cancelled.")
|
||||
elif choice == "3":
|
||||
print_menu()
|
||||
else:
|
||||
print("Invalid choice. Please try again.")
|
||||
|
||||
def send_global_message():
|
||||
message = input("Enter the message to send: ")
|
||||
with Client(SERVER_ADDRESS, SERVER_PORT, passwd=RCON_PASSWORD) as client:
|
||||
@@ -143,6 +169,11 @@ def send_direct_message():
|
||||
response = client.run(f'Say -{player_name} {message}')
|
||||
print(response)
|
||||
|
||||
def hard_restart():
|
||||
with Client(SERVER_ADDRESS, SERVER_PORT, passwd=RCON_PASSWORD) as client:
|
||||
response = client.run('#shutdown')
|
||||
print(response)
|
||||
|
||||
def list_players():
|
||||
try:
|
||||
with Client(SERVER_ADDRESS, SERVER_PORT, passwd=RCON_PASSWORD) as client:
|
||||
@@ -164,9 +195,9 @@ def kick_single_player():
|
||||
else:
|
||||
print(response)
|
||||
|
||||
def kick_all_players(): ##UNOPERATIONAL
|
||||
def kick_all_players():
|
||||
with Client(SERVER_ADDRESS, SERVER_PORT, passwd=RCON_PASSWORD) as client:
|
||||
response = client.run('kick -1')
|
||||
response = client.run('#kick -1')
|
||||
print(response)
|
||||
|
||||
def show_banlist():
|
||||
@@ -186,6 +217,18 @@ def ban_player():
|
||||
else:
|
||||
print(response)
|
||||
|
||||
def server_monitor():
|
||||
while True:
|
||||
try:
|
||||
with Client(SERVER_ADDRESS, SERVER_PORT, passwd=RCON_PASSWORD) as client:
|
||||
response = client.run('status')
|
||||
print(response)
|
||||
except socket.timeout:
|
||||
print("Connection timed out. Please check the server address, port, and network settings.")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
sleep(30)
|
||||
|
||||
def ban_player_by_steamid():
|
||||
steamid = input("Enter the SteamID of the player to ban: ")
|
||||
ban_time = input("Enter the ban time in minutes: ")
|
||||
@@ -226,19 +269,8 @@ def unlock_server():
|
||||
print("Connection timed out. Please check the server address, port, and network settings.")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
def handle_input(choice):
|
||||
if choice == "1":
|
||||
lock_server()
|
||||
elif choice == "2":
|
||||
unlock_server()
|
||||
elif choice == "3":
|
||||
sys.exit()
|
||||
elif choice == "4":
|
||||
list_players()
|
||||
else:
|
||||
print("Invalid choice. Please try again.")
|
||||
|
||||
def list_players():
|
||||
def list_players():
|
||||
try:
|
||||
with Client(SERVER_ADDRESS, SERVER_PORT, passwd=RCON_PASSWORD) as client:
|
||||
response = client.run('players')
|
||||
|
||||
Reference in New Issue
Block a user