Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- host
- By Dave-ee Jones
- Local DNS hosting
- --]]
- RECORDS = RECORDS or {}
- -- Create a new entry
- function new(_NAME,_ID)
- if type(_NAME) == "string" then
- if type(_ID) == "number" then
- RECORDS[_NAME] = _ID
- return true
- else
- error("host: ID needs to be a number",0)
- end
- else
- error("host: NAME needs to be a string",0)
- end
- end
- -- Change the ID of the name given
- function setID(_NAME,_ID)
- if type(_NAME) == "string" then
- if type(_ID) == "number" then
- if RECORDS[_NAME] then
- RECORDS[_NAME] = _ID
- else
- error("host: Record for ".._NAME.." doesn't exist",0)
- end
- else
- error("host: ID needs to be a number",0)
- end
- else
- error("host: NAME needs to be a string",0)
- end
- end
- -- Change the name of the ID given
- function setName(_ID,_NAME)
- if type(_NAME) == "string" then
- if type(_ID) == "number" then
- local b_FOUND = false
- for k,v in pairs(RECORDS) do
- if v == _ID then
- b_FOUND = true
- delete(k)
- new(_NAME,_ID)
- end
- end
- if not b_FOUND then
- error("host: Record for "..tostring(_ID).." doesn't exist",0)
- end
- else
- error("host: NAME needs to be a string",0)
- end
- else
- error("host: NAME needs to be a string",0)
- end
- end
- -- Returns name of ID given or false if there isn't one
- function getName(_ID)
- if type(_ID) == "number" then
- for k,v in pairs(RECORDS) do
- if v == _ID then
- return k
- end
- end
- else
- error("host: ID needs to be a number",0)
- end
- return false
- end
- -- Returns ID of name given or false if there isn't one
- function getID(_NAME)
- if type(_NAME) == "string" then
- if RECORDS[_NAME] then
- return RECORDS[_NAME]
- else
- return false
- end
- else
- error("host: NAME needs to be a string",0)
- end
- end
- -- Deletes a DNS entry
- function delete(_NAME)
- RECORDS[_NAME] = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment