Rework data structures, storing all front-end network data in Network objects

This commit is contained in:
Al Beano
2019-08-11 21:58:14 +01:00
parent f6657cb905
commit e5adcfef4c
24 changed files with 258 additions and 284 deletions

View File

@@ -9,40 +9,42 @@ class RelayCommand:
if authed:
if length == 7:
if spl[1] == "add":
if spl[2] in main.relay.keys():
failure("Relay already exists: %s" % spl[2])
if spl[2] not in main.network.keys():
failure("No such network: %s" % spl[2])
return
if not spl[4].isdigit():
failure("Port must be an integer, not %s" % spl[4])
return
else:
main.relay[spl[2]] = {"host": spl[3],
"port": spl[4],
"user": spl[5],
"password": spl[6]}
success("Successfully created relay: %s" % spl[2])
main.saveConf("relay")
id, alias = main.network[spl[2]].add_relay(spl[3], spl[4], spl[5], spl[6])
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
main.saveConf("network")
return
else:
incUsage("relay")
return
elif length == 3:
elif length == 4:
if spl[1] == "del":
if spl[2] in main.relay.keys():
del main.relay[spl[2]]
success("Successfully removed relay: %s" % spl[2])
main.saveConf("relay")
if spl[2] not in main.network.keys():
failure("No such network: %s" % spl[2])
return
else:
failure("No such relay: %s" % spl[2])
if int(spl[3]) not in main.network[spl[2]].relays.keys():
failure("No such relay: %s on network %s" % (spl[3], spl[2]))
return
main.network[spl[2]].delete_relay(int(spl[3]))
success("Successfully deleted relay %s on network %s" % (spl[3], spl[2]))
main.saveConf("network")
return
else:
incUsage("relay")
return
elif length == 2:
elif length == 3:
if spl[1] == "list":
info(dump(main.relay))
if spl[2] not in main.network.keys():
failure("No such network: %s" % spl[2])
return
info(dump(main.network[spl[2]].relays))
return
else:
incUsage("relay")