I am making a virtual terminal for a basic hacking game. Commands need to be given by user. Commands are stored as a dictionary, like the following
commandslist = {"systemtime": systemtime(),
"ping": ping(),
"pwd": pwd(),
"ifconfig": ifconfig(),
"help": helpmenu(),
"shop": shop()}
That references the actual functions
def ifconfig():
ipaddr = user["ipaddr"]
return ipaddr
def ping(ip4="127.0.0.1"):
if ip4 in enemyuser["ipaddr"]:
x = "64 bytes from " + ip4 +": icmp_seq=1"
else:
x ="No ping response"
return x
The code in main.py reads for user input and for loops to find it. I dont want a bunch of messy if statements
while 1:
userinput = input(bash)
if " " in userinput:
command, options = userinput.split(" ")
else:
command = userinput
for i in commandslist:
if i == command:
print(commandslist[i])
Basically I need to pass the ip address of enemy computer to the ping command but I can't figure out a way if I could update the ping() call in the dictionary to include the options that would be good