Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.07 KB | None | 0 0
  1. === modified file plugins/Script/examples/access.lua
  2. --- plugins/Script/examples/access.lua  2011-02-16 21:33:10 +0000
  3. +++ plugins/Script/examples/access.lua  2011-03-08 21:26:17 +0000
  4. @@ -67,6 +67,8 @@
  5.     [adchpp.AdcCommand_CMD_RES] = context_direct,
  6.     [adchpp.AdcCommand_CMD_CTM] = context_direct,
  7.     [adchpp.AdcCommand_CMD_RCM] = context_direct,
  8. +   [adchpp.AdcCommand_CMD_NAT] = context_direct,
  9. +   [adchpp.AdcCommand_CMD_RNT] = context_direct,
  10.     [adchpp.AdcCommand_CMD_GPA] = context_hub,
  11.     [adchpp.AdcCommand_CMD_PAS] = context_hub,
  12.     [adchpp.AdcCommand_CMD_QUI] = context_hub,
  13. @@ -92,6 +94,7 @@
  14.  local reasons = {}
  15.  local socketErrors = {}
  16.  local dispatch_stats = false
  17. +local users_saved = true
  18.  
  19.  -- cache for +cfg min*level
  20.  local restricted_commands = {}
  21. @@ -392,6 +395,15 @@
  22.  
  23.     file:write(json.encode(registered_users()))
  24.     file:close()
  25. +   users_saved = true
  26. +end
  27. +
  28. +local function to_save_users()
  29. +base.print(users_saved)
  30. +   if not users_saved then
  31. +       base.pcall(save_users)
  32. +       base.print(users_saved)
  33. +   end
  34.  end
  35.  
  36.  function add_setting(name, options)
  37. @@ -467,8 +479,8 @@
  38.     end
  39.  end
  40.  
  41. -local function make_user(cid, nick, password, level)
  42. -   local user = { cid = cid, nick = nick, password = password, level = level }
  43. +local function make_user(cid, nick, password, level, regby)
  44. +   local user = { cid = cid, nick = nick, password = password, level = level, regby = regby, regtime = os.time(), lasttime = os.time() }
  45.     return user
  46.  end
  47.  
  48. @@ -547,6 +559,7 @@
  49.         end
  50.  
  51.         user.nick = nick
  52. +       user.lasttime = os.time()
  53.         users.nicks[user.nick] = user
  54.         base.pcall(save_users)
  55.         return true, "Registration data updated (new nick)"
  56. @@ -563,16 +576,22 @@
  57.         end
  58.  
  59.         user.cid = cid
  60. +       user.lasttime = os.time()
  61.         users.cids[user.cid] = user
  62.         base.pcall(save_users)
  63.         return true, "Registration data updated (new CID)"
  64.     end
  65.  
  66. +   user.lasttime = os.time()
  67. +   users.cids[user.cid] = user
  68. +   users_saved = false
  69. +   base.print(users_saved)
  70. +
  71.     return true
  72.  end
  73.  
  74. -function register_user(cid, nick, password, level)
  75. -   local user = make_user(cid, nick, password, level)
  76. +function register_user(cid, nick, password, level, regby)
  77. +   local user = make_user(cid, nick, password, level, regby)
  78.     if nick then
  79.         users.nicks[nick] = user
  80.     end
  81. @@ -883,6 +902,20 @@
  82.     return string.format("%d days, %d hours, %d minutes and %d seconds", t_d, t_h, t_m, t_s)
  83.  end
  84.  
  85. +function format_minutes(t)
  86. +   local t_d = math.floor(t / (60*60*24))
  87. +   local t_h = math.floor(t / (60*60)) % 24
  88. +   local t_m = math.floor(t / 60) % 60
  89. +
  90. +   return string.format("%d days, %d hours and %d minutes", t_d, t_h, t_m)
  91. +end
  92. +
  93. +function time_diff(t)
  94. +   local diff = os.difftime(os.time(), t)
  95. +   local time = format_minutes(diff)
  96. +   return time
  97. +end
  98. +
  99.  cut_str = function(str, max)
  100.     if #str > max - 3 then
  101.         return string.sub(str, 1, max - 3) .. "..."
  102. @@ -1244,20 +1277,30 @@
  103.             if v.level <= user.level then
  104.                 local fields = {}
  105.                 if v.nick then
  106. -                   table.insert(fields, "Nick: " .. v.nick)
  107. +                   table.insert(fields, "\tNick: " .. v.nick)
  108.                 end
  109.                 if v.cid then
  110. -                   table.insert(fields, "CID: " .. v.cid)
  111. +                   table.insert(fields, "\n\tCID: " .. v.cid)
  112.                 end
  113.                 if settings.passinlist.value ~=0 and v.level < user.level and v.password then
  114.                     table.insert(fields, "Pass: " .. v.password)
  115.                 end
  116. -               table.insert(list, table.concat(fields, "\t"))
  117. +               if v.regtime then
  118. +                   table.insert(fields, "\n\tRegistered: " .. time_diff(v.regtime) .. " ago")
  119. +               end
  120. +               if v.lasttime then
  121. +                   table.insert(fields, "Last on: " .. time_diff(v.lasttime) .. " ago")
  122. +               end
  123. +               if v.regby then
  124. +                   table.insert(fields, "\n\tRegged By: " .. v.regby)
  125. +               end
  126. +
  127. +               table.insert(list, table.concat(fields, "\t\t"))
  128.             end
  129.         end
  130.         table.sort(list)
  131.  
  132. -       autil.reply(c, "Registered users with a level <= " .. user.level .. " (your level):\n" .. table.concat(list, "\n"))
  133. +       autil.reply(c, "Registered users with a level <= " .. user.level .. " (your level):\n\n" .. table.concat(list, "\n\n") .. "\n")
  134.     end,
  135.  
  136.     protected = function(c) return not get_user_c(c).is_default end,
  137. @@ -1291,7 +1334,7 @@
  138.             base.pcall(save_users)
  139.             autil.reply(c, "Your password has been changed to \"" .. parameters .. "\"")
  140.         elseif settings.allowreg.value ~= 0 then
  141. -           register_user(c:getCID():toBase32(), c:getField("NI"), parameters, 1)
  142. +           register_user(c:getCID():toBase32(), c:getField("NI"), parameters, 1, c:getField("NI"))
  143.             autil.reply(c, "You're now registered with the password \"" .. parameters .. "\"")
  144.         else
  145.             autil.reply(c, "You are not allowed to register by yourself; ask an operator to do it for you")
  146. @@ -1392,7 +1435,7 @@
  147.             return
  148.         end
  149.  
  150. -       register_user(cid, nick, password, level)
  151. +       register_user(cid, nick, password, level, c:getField("NI"))
  152.  
  153.         autil.reply(c, "\"" .. nick .. "\" has been registered")
  154.  
  155. @@ -1591,3 +1634,6 @@
  156.         if reasons[reason] then reasons[reason] = reasons[reason] + 1 else reasons[reason] = 1 end
  157.     end
  158.  end)
  159. +
  160. +save_users_timer = sm:addTimedJob(900000, to_save_users)
  161. +autil.on_unloading(_NAME, save_users_timer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement