local function clear()
 term.clear()
 term.setCursorPos(1,1)
end
local function achievements(currentLevel)
 if currentLevel >= 1 then
  print("1. You logged on to localhost, congratz")
 end
 if currentLevel >= 2 then
  print("2. you acessed the hack routine once, wow!")
 end
 if currentLevel >= 3 then
  print("3. you entered uncharted territory")
 end
  if currentLevel >= 4 then
  print("4. you conquered uncharted territory")
 end
end

local function checkForC(input,customfilelist) -- check for command
 if input == "h" or input == "help" then
  if lvl >= 1 or lvl == 2 and currentlvl == 1 then
  print[[localhost help menu
  * alt    show alternate commands
  * (e)xit exit current computer
  * (h)elp display this menu
  * (l)s   list files in this dir
  * (t)ype type out file contents]]
  if lvl >= 2 then print("  * hack  run the hack rutine") end
  elseif lvl >= 2 and currentlvl == 2 then
  print[[hack rutine help menu
  * alt    show alternate commands
  * (e)xit exit routine
  * (h)elp display this menu
  * gateway  access the gateway
  * atip  a tip from the employer]]
  elseif lvl >= 4 and currentlvl == 4 then
   print[[Gateway help menu
  * alt    show alternate commands
  * (e)xit exit gateway
  * (h)elp display this menu
  * (j)ump jump to spesified computer]]
  end
 elseif input == "alt" then
  print[[  * ach  list achievements
  * alt  display these commands
  * answer  solution to this haxor level
  * clr  clear the screen
  * hint  a hint for this haxor level
  * notes  open notepad (WIP)]]
 elseif input == "clr" then
  clear()
 elseif input == "notes" then
  shell.run("edit")
 elseif input == "ach" then
  achievements(lvl)
 elseif input == "e" or input == "exit" then
  return "break"
 elseif input == "l" or input == "ls" then
  print("File list:")
  print(customfilelist)
 elseif string.sub(input,1,2) == "t " or string.sub(input,1,5) == "type " then
  return "typeplz"
 end
end

local function gateway(input)
currentlvl = 3
lvl = 3
clear()
for count = 1,3 do
 write("Username:")
 input = read()
 if input == "alice" then
  write("\n")
  write("Password:")
  input = read()
  if input == "password" then
   clear()
   write("gateway>")
   currentlvl = 4
   lvl = 4
   while true do
   input = read()
   result = checkForC(input,"info         1k -r- --r r-x")
   if result == "break" then
    break
   elseif result == "typeplz" and string.sub(input,6) == "info" or string.sub(input,3) == "info"  then
    print[[You completed the game so far! :D]]
   end --checkfor end
   write("gateway>")
   end -- while end
   end -- password end
  end -- username end
 end -- gateway loop
 print("out of tries, disconnecting")
end --function

local function hack(input)
 if checkForC(input,"") == "break" then
  return "break"
 end
 if input == "gateway" and lvl == 2 then
  gateway()
 end
 if input == "atip" then
  print[[hay, we at 1337 industries think you should hack into 1338 inc's gateway, 
so we found a person named alice, who isn't very bright. 
and we are sure you'll figure out her password.

just login to the gateway using gateway from the hack routine!]]
 end
end

local function localhost(input)
  currentlvl = 1
  checkresult = checkForC(input,"readme         1k -rw wwr r-x")
  if checkresult == "typeplz" then
   if string.sub(input,6) == "readme" or string.sub(input,3) == "readme" then
    print("Dear hacker,  i unlocked your hack routine, providing you with the bare necesseties for hacking, good luck finding it! :D")
	lvl = 2
   end
  end
  if checkresult == "break" then
   return "break"
  end
  if input == "hack" and lvl == 2 then
   clear()
   write("hack>")
   currentlvl = 2
   while true do
    input = read() --get input
    if hack(input) == "break" then --run the hack rutine
	 currentlvl = 1
	 break
	end
    write("hack>")
   end -- while end
  end --start routine if
end

clear()
print[[u ar epic haxors, employed by 1337 inc
ur jab is to haxor 1338 inc, gl hf
type (s)tart to start the VM]]
 lvl = 0
 currentlvl = 0
input = read()
if input == "s" or input == "start" then
 clear()
 print[[
 Type help for help menu
 ]]
 write("localhost>") -- write start
 lvl = 1 --level 1 authed
 while true do --main program loop after startup
 input = read() --get input
  if localhost(input) == "break" then  --exit the localhost
   break
  end
  write("localhost>") -- write new input line, loop
 end
else
 clear()
 print("exited program..")
end