Advertisement
Guest User

RemoteRequestValidator

a guest
Jul 23rd, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. --RemoteRequestValidator module:
  2. local RemoteParam = require(script.RemoteParam)
  3.  
  4. local RemoteRequestValidator = {}
  5. RemoteRequestValidator.__index = RemoteRequestValidator
  6.  
  7. function RemoteRequestValidator.New()
  8.     return setmetatable({
  9.         _RemoteParams = {}
  10.     }, RemoteRequestValidator)
  11. end
  12.  
  13. function RemoteRequestValidator:AddParam()
  14.     local RemoteParamObj = RemoteParam.New()
  15.    
  16.     table.insert(self._RemoteParams, RemoteParamObj)
  17.     return RemoteParamObj
  18. end
  19.  
  20. function RemoteRequestValidator:Validate(...)
  21.     local Params = {...}
  22.  
  23.     if (#Params ~= #self._RemoteParams) then
  24.         return false
  25.     end
  26.    
  27.     for Key, Param in ipairs(Params) do
  28.         if (not self._RemoteParams[Key]:Validate(Param)) then
  29.             return false
  30.         end
  31.     end
  32.  
  33.     return true
  34. end
  35.  
  36. return RemoteRequestValidator
  37.  
  38. --RemoteParam module:
  39. local RemoteParam = {}
  40. RemoteParam.__index = RemoteParam
  41.  
  42. function RemoteParam.New()
  43.     return setmetatable({}, RemoteParam)
  44. end
  45.  
  46. function RemoteParam:SetSanityCallback(Callback)
  47.     assert(typeof(Callback) == "function", "RemoteParam Callback must be a function")
  48.     self._Callback = Callback
  49. end
  50.  
  51. function RemoteParam:Validate(Value)
  52.     return self._Callback(Value)
  53. end
  54.  
  55. return RemoteParam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement