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 = []
|
||||
|
||||
# Loads servers in from the servers_file, if it does not exist, trigger adding first server via create_servers.
|
||||
def load_servers():
|
||||
global servers
|
||||
if os.path.isfile(servers_file):
|
||||
|
@ -15,15 +16,17 @@ def load_servers():
|
|||
else:
|
||||
create_server(True)
|
||||
|
||||
# Write the contents to the servers variable to the servers_file.
|
||||
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:
|
||||
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):
|
||||
index = int(0)
|
||||
for x in servers:
|
||||
for x in servers: # for each dict in the servers array as x.
|
||||
strindex = str(index)
|
||||
print('ID: '+strindex+' ===')
|
||||
print(' Name:'+x['name'])
|
||||
|
@ -31,7 +34,6 @@ def list_servers(mode=int(1)):
|
|||
print(' Port:'+x['port'])
|
||||
print(' Password: **********\n')
|
||||
index += 1
|
||||
initial_choice()
|
||||
elif(mode==2):
|
||||
index = int(0)
|
||||
for x in servers:
|
||||
|
@ -39,6 +41,7 @@ def list_servers(mode=int(1)):
|
|||
print('ID: '+strindex+' ('+x['name']+')')
|
||||
index += 1
|
||||
|
||||
# Creates new server dicts in the server array.
|
||||
def create_server(isfirstrun=False):
|
||||
global servers
|
||||
if(isfirstrun):
|
||||
|
@ -115,6 +118,7 @@ def initial_choice():
|
|||
pop_server()
|
||||
case "3":
|
||||
list_servers()
|
||||
initial_choice()
|
||||
case "4":
|
||||
send_commands()
|
||||
case "5":
|
||||
|
|
Loading…
Reference in a new issue