Start adding some comments, fix an error.
This commit is contained in:
parent
9562deae3d
commit
91a3a2bde6
1 changed files with 8 additions and 4 deletions
|
@ -7,6 +7,7 @@ from rcon.source import Client
|
||||||
servers_file = "./.midnight_servers.json"
|
servers_file = "./.midnight_servers.json"
|
||||||
servers = []
|
servers = []
|
||||||
|
|
||||||
|
# Loads servers in from the servers_file, if it does not exist, trigger adding first server via create_servers.
|
||||||
def load_servers():
|
def load_servers():
|
||||||
global servers
|
global servers
|
||||||
if os.path.isfile(servers_file):
|
if os.path.isfile(servers_file):
|
||||||
|
@ -15,15 +16,17 @@ def load_servers():
|
||||||
else:
|
else:
|
||||||
create_server(True)
|
create_server(True)
|
||||||
|
|
||||||
|
# Write the contents to the servers variable to the servers_file.
|
||||||
def write_servers():
|
def write_servers():
|
||||||
json_obj = json.dumps(servers,indent=4)
|
json_obj = json.dumps(servers,indent=4) # Add indentation when dumping to string.
|
||||||
with open(servers_file, "w") as outfile:
|
with open(servers_file, "w") as outfile:
|
||||||
outfile.write(json_obj)
|
outfile.write(json_obj)
|
||||||
|
|
||||||
def list_servers(mode=int(1)):
|
# Lists servers, default action is to list all information minus password. Second option lists only ID and name.
|
||||||
|
def list_servers(mode=int(1)): # make sure a default is set.
|
||||||
if(mode==1):
|
if(mode==1):
|
||||||
index = int(0)
|
index = int(0)
|
||||||
for x in servers:
|
for x in servers: # for each dict in the servers array as x.
|
||||||
strindex = str(index)
|
strindex = str(index)
|
||||||
print('ID: '+strindex+' ===')
|
print('ID: '+strindex+' ===')
|
||||||
print(' Name:'+x['name'])
|
print(' Name:'+x['name'])
|
||||||
|
@ -31,7 +34,6 @@ def list_servers(mode=int(1)):
|
||||||
print(' Port:'+x['port'])
|
print(' Port:'+x['port'])
|
||||||
print(' Password: **********\n')
|
print(' Password: **********\n')
|
||||||
index += 1
|
index += 1
|
||||||
initial_choice()
|
|
||||||
elif(mode==2):
|
elif(mode==2):
|
||||||
index = int(0)
|
index = int(0)
|
||||||
for x in servers:
|
for x in servers:
|
||||||
|
@ -39,6 +41,7 @@ def list_servers(mode=int(1)):
|
||||||
print('ID: '+strindex+' ('+x['name']+')')
|
print('ID: '+strindex+' ('+x['name']+')')
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
|
# Creates new server dicts in the server array.
|
||||||
def create_server(isfirstrun=False):
|
def create_server(isfirstrun=False):
|
||||||
global servers
|
global servers
|
||||||
if(isfirstrun):
|
if(isfirstrun):
|
||||||
|
@ -115,6 +118,7 @@ def initial_choice():
|
||||||
pop_server()
|
pop_server()
|
||||||
case "3":
|
case "3":
|
||||||
list_servers()
|
list_servers()
|
||||||
|
initial_choice()
|
||||||
case "4":
|
case "4":
|
||||||
send_commands()
|
send_commands()
|
||||||
case "5":
|
case "5":
|
||||||
|
|
Loading…
Reference in a new issue