Advertisement
MoonlightOwl

Quantum Linker

Sep 19th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. -- Quantum Link Linker  by Totoro --
  2. -- Version 2. All right reserved! --
  3.  
  4. local fs = require('filesystem')
  5. local com = require('component')
  6. local serial = require('serialization')
  7. local modem = com.modem
  8.  
  9. local proxy = ...
  10. fs.mount(proxy, '/linker')
  11.  
  12. local users = {}
  13. function loadUsers()
  14.   if fs.exists("linker/userlist.txt") then
  15.     local file = io.open("linker/userlist.txt", "r")
  16.     local data = file:read("*a")
  17.     users = serial.unserialize(data)
  18.     file:close()
  19.     if users == nil then users = {} end
  20.   end
  21. end
  22. function saveUsers()
  23.   local file = io.open("linker/userlist.txt", "w")
  24.   local data = serial.serialize(users)
  25.   file:write(data)
  26.   file:close()
  27. end
  28.  
  29. print("[ Quantum Linker ]")
  30. print("get - получить адрес, set - установить таблицу, clear - очистить таблицу")
  31. local command = io.read()
  32.  
  33. if command == 'get' then
  34.   if modem == nil then
  35.     print("Отсутствует сетевая плата. Этот компьютер не может быть клиентом.")
  36.   else
  37.     print("Описание (можно опустить): ")
  38.     desc = io.read()
  39.     loadUsers()
  40.     table.insert(users, {address = modem.address, description = desc})
  41.     saveUsers()
  42.     print("Готово. Адрес в таблице.")
  43.   end
  44. elseif command == 'set' then
  45.   if fs.exists("linker/userlist.txt") then
  46.     fs.copy("linker/userlist.txt", "userlist.txt")
  47.     print("Готово. Новая таблица установлена.")
  48.   end
  49. elseif command == 'clear' then
  50.   if fs.exists("linker/userlist.txt") then
  51.     fs.remove("linker/userlist.txt")
  52.     print("Готово. Таблица удалена.")
  53.   end
  54. else
  55.   print("'"..command.."' - неверная команда.")
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement