MtnMCG

sethmc ndisk terminal

Dec 20th, 2025 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. -- ndisk_terminal.lua
  2. -- Admin Terminal for NDisk
  3. -- Run this ON THE SERVER to manually manage files.
  4. -- It shares the same API instance (and chunklocation.txt) that the server uses.
  5.  
  6. -- Try to use global ndisk if available (when running in server's multishell)
  7. -- Otherwise load it ourselves
  8. local ndisk = _G.ndisk or dofile("ndisk_api.lua")
  9.  
  10. print("NDisk Admin Terminal")
  11. print("Loading API...")
  12. if not _G.ndisk then
  13. ndisk.init()
  14. end
  15.  
  16. local function printHelp()
  17. print("Available commands:")
  18. print(" list [path] - List files")
  19. print(" read <path> - Read a file")
  20. print(" write <path> - Write a file (manual input)")
  21. print(" delete <path> - Delete a file")
  22. print(" space - Show free space")
  23. print(" nodes - Rediscover/Show nodes")
  24. print(" help - Show this menu")
  25. print(" exit - Exit terminal")
  26. end
  27.  
  28. print("Ready. Type 'help' for commands.")
  29.  
  30. while true do
  31. write("ndisk> ")
  32. local input = read()
  33. local command = {}
  34. for word in input:gmatch("%S+") do
  35. table.insert(command, word)
  36. end
  37.  
  38. local cmd = command[1]
  39. local arg1 = command[2]
  40.  
  41. if cmd == "list" then
  42. local path = arg1 or ""
  43. local items = ndisk.list(path)
  44. print("Listing '"..path.."':")
  45. if #items == 0 then print(" (No files found)") end
  46. for _, item in ipairs(items) do
  47. print(" " .. item)
  48. end
  49.  
  50. elseif cmd == "read" and arg1 then
  51. local content, err = ndisk.read(arg1)
  52. if content then
  53. print("--- BEGIN FILE ---")
  54. print(content)
  55. print("--- END FILE ---")
  56. else
  57. print("Error: " .. (err or "Unknown error"))
  58. end
  59.  
  60. elseif cmd == "write" and arg1 then
  61. print("Enter content for '"..arg1.."' (Type 'EOF' on a new line to finish):")
  62. local content = ""
  63. while true do
  64. local line = read()
  65. if line == "EOF" then break end
  66. content = content .. line .. "\n"
  67. end
  68. local success, err = ndisk.write(arg1, content)
  69. if success then
  70. print("File written successfully.")
  71. else
  72. print("Error: " .. (err or "Unknown error"))
  73. end
  74.  
  75. elseif cmd == "delete" and arg1 then
  76. print("Deleting '"..arg1.."'...")
  77. local success, err = ndisk.delete(arg1)
  78. if success then
  79. print("Deleted.")
  80. else
  81. print("Error: " .. (err or "Unknown error"))
  82. end
  83.  
  84. elseif cmd == "space" then
  85. local space = ndisk.getFreeSpace()
  86. print("Total Cluster Free Space: " .. space .. " bytes")
  87.  
  88. elseif cmd == "nodes" then
  89. print("Refreshing node list...")
  90. -- ndisk.init() triggers discovery if needed, but we can force it
  91. -- if we expose a refresh function.
  92. -- If ndisk_api doesn't expose refresh, we just re-init or accept current state.
  93. -- Assuming standard usage:
  94. print("Nodes are managed automatically by the API.")
  95.  
  96. elseif cmd == "help" then
  97. printHelp()
  98.  
  99. elseif cmd == "exit" then
  100. break
  101.  
  102. else
  103. print("Unknown command.")
  104. printHelp()
  105. end
  106. end
  107.  
Advertisement
Add Comment
Please, Sign In to add comment