AquaJD

HostRAM

Sep 26th, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. --[[
  2.  
  3.     host
  4.     By Dave-ee Jones
  5.    
  6.     Local DNS hosting
  7.  
  8. --]]
  9.  
  10. RECORDS = RECORDS or {}
  11.  
  12. -- Create a new entry
  13. function new(_NAME,_ID)
  14.     if type(_NAME) == "string" then
  15.         if type(_ID) == "number" then
  16.             RECORDS[_NAME] = _ID
  17.             return true
  18.         else
  19.             error("host: ID needs to be a number",0)
  20.         end
  21.     else
  22.         error("host: NAME needs to be a string",0)
  23.     end
  24. end
  25.  
  26. -- Change the ID of the name given
  27. function setID(_NAME,_ID)
  28.     if type(_NAME) == "string" then
  29.         if type(_ID) == "number" then
  30.             if RECORDS[_NAME] then
  31.                 RECORDS[_NAME] = _ID
  32.             else
  33.                 error("host: Record for ".._NAME.." doesn't exist",0)
  34.             end
  35.         else
  36.             error("host: ID needs to be a number",0)
  37.         end
  38.     else
  39.         error("host: NAME needs to be a string",0)
  40.     end
  41. end
  42.  
  43. -- Change the name of the ID given
  44. function setName(_ID,_NAME)
  45.     if type(_NAME) == "string" then
  46.         if type(_ID) == "number" then
  47.             local b_FOUND = false
  48.             for k,v in pairs(RECORDS) do
  49.                 if v == _ID then
  50.                     b_FOUND = true
  51.                     delete(k)
  52.                     new(_NAME,_ID)
  53.                 end
  54.             end
  55.             if not b_FOUND then
  56.                 error("host: Record for "..tostring(_ID).." doesn't exist",0)
  57.             end
  58.         else
  59.             error("host: NAME needs to be a string",0)
  60.         end
  61.     else
  62.         error("host: NAME needs to be a string",0)
  63.     end
  64. end
  65.  
  66. -- Returns name of ID given or false if there isn't one
  67. function getName(_ID)
  68.     if type(_ID) == "number" then
  69.         for k,v in pairs(RECORDS) do
  70.             if v == _ID then
  71.                 return k
  72.             end
  73.         end
  74.     else
  75.         error("host: ID needs to be a number",0)
  76.     end
  77.     return false
  78. end
  79.  
  80. -- Returns ID of name given or false if there isn't one
  81. function getID(_NAME)
  82.     if type(_NAME) == "string" then
  83.         if RECORDS[_NAME] then
  84.             return RECORDS[_NAME]
  85.         else
  86.             return false
  87.         end
  88.     else
  89.         error("host: NAME needs to be a string",0)
  90.     end
  91. end
  92.  
  93. -- Deletes a DNS entry
  94. function delete(_NAME)
  95.     RECORDS[_NAME] = nil
  96. end
Advertisement
Add Comment
Please, Sign In to add comment