Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === modified file plugins/Script/examples/access.lua
- --- plugins/Script/examples/access.lua 2011-02-16 21:33:10 +0000
- +++ plugins/Script/examples/access.lua 2011-03-08 21:26:17 +0000
- @@ -67,6 +67,8 @@
- [adchpp.AdcCommand_CMD_RES] = context_direct,
- [adchpp.AdcCommand_CMD_CTM] = context_direct,
- [adchpp.AdcCommand_CMD_RCM] = context_direct,
- + [adchpp.AdcCommand_CMD_NAT] = context_direct,
- + [adchpp.AdcCommand_CMD_RNT] = context_direct,
- [adchpp.AdcCommand_CMD_GPA] = context_hub,
- [adchpp.AdcCommand_CMD_PAS] = context_hub,
- [adchpp.AdcCommand_CMD_QUI] = context_hub,
- @@ -92,6 +94,7 @@
- local reasons = {}
- local socketErrors = {}
- local dispatch_stats = false
- +local users_saved = true
- -- cache for +cfg min*level
- local restricted_commands = {}
- @@ -392,6 +395,15 @@
- file:write(json.encode(registered_users()))
- file:close()
- + users_saved = true
- +end
- +
- +local function to_save_users()
- +base.print(users_saved)
- + if not users_saved then
- + base.pcall(save_users)
- + base.print(users_saved)
- + end
- end
- function add_setting(name, options)
- @@ -467,8 +479,8 @@
- end
- end
- -local function make_user(cid, nick, password, level)
- - local user = { cid = cid, nick = nick, password = password, level = level }
- +local function make_user(cid, nick, password, level, regby)
- + local user = { cid = cid, nick = nick, password = password, level = level, regby = regby, regtime = os.time(), lasttime = os.time() }
- return user
- end
- @@ -547,6 +559,7 @@
- end
- user.nick = nick
- + user.lasttime = os.time()
- users.nicks[user.nick] = user
- base.pcall(save_users)
- return true, "Registration data updated (new nick)"
- @@ -563,16 +576,22 @@
- end
- user.cid = cid
- + user.lasttime = os.time()
- users.cids[user.cid] = user
- base.pcall(save_users)
- return true, "Registration data updated (new CID)"
- end
- + user.lasttime = os.time()
- + users.cids[user.cid] = user
- + users_saved = false
- + base.print(users_saved)
- +
- return true
- end
- -function register_user(cid, nick, password, level)
- - local user = make_user(cid, nick, password, level)
- +function register_user(cid, nick, password, level, regby)
- + local user = make_user(cid, nick, password, level, regby)
- if nick then
- users.nicks[nick] = user
- end
- @@ -883,6 +902,20 @@
- return string.format("%d days, %d hours, %d minutes and %d seconds", t_d, t_h, t_m, t_s)
- end
- +function format_minutes(t)
- + local t_d = math.floor(t / (60*60*24))
- + local t_h = math.floor(t / (60*60)) % 24
- + local t_m = math.floor(t / 60) % 60
- +
- + return string.format("%d days, %d hours and %d minutes", t_d, t_h, t_m)
- +end
- +
- +function time_diff(t)
- + local diff = os.difftime(os.time(), t)
- + local time = format_minutes(diff)
- + return time
- +end
- +
- cut_str = function(str, max)
- if #str > max - 3 then
- return string.sub(str, 1, max - 3) .. "..."
- @@ -1244,20 +1277,30 @@
- if v.level <= user.level then
- local fields = {}
- if v.nick then
- - table.insert(fields, "Nick: " .. v.nick)
- + table.insert(fields, "\tNick: " .. v.nick)
- end
- if v.cid then
- - table.insert(fields, "CID: " .. v.cid)
- + table.insert(fields, "\n\tCID: " .. v.cid)
- end
- if settings.passinlist.value ~=0 and v.level < user.level and v.password then
- table.insert(fields, "Pass: " .. v.password)
- end
- - table.insert(list, table.concat(fields, "\t"))
- + if v.regtime then
- + table.insert(fields, "\n\tRegistered: " .. time_diff(v.regtime) .. " ago")
- + end
- + if v.lasttime then
- + table.insert(fields, "Last on: " .. time_diff(v.lasttime) .. " ago")
- + end
- + if v.regby then
- + table.insert(fields, "\n\tRegged By: " .. v.regby)
- + end
- +
- + table.insert(list, table.concat(fields, "\t\t"))
- end
- end
- table.sort(list)
- - autil.reply(c, "Registered users with a level <= " .. user.level .. " (your level):\n" .. table.concat(list, "\n"))
- + autil.reply(c, "Registered users with a level <= " .. user.level .. " (your level):\n\n" .. table.concat(list, "\n\n") .. "\n")
- end,
- protected = function(c) return not get_user_c(c).is_default end,
- @@ -1291,7 +1334,7 @@
- base.pcall(save_users)
- autil.reply(c, "Your password has been changed to \"" .. parameters .. "\"")
- elseif settings.allowreg.value ~= 0 then
- - register_user(c:getCID():toBase32(), c:getField("NI"), parameters, 1)
- + register_user(c:getCID():toBase32(), c:getField("NI"), parameters, 1, c:getField("NI"))
- autil.reply(c, "You're now registered with the password \"" .. parameters .. "\"")
- else
- autil.reply(c, "You are not allowed to register by yourself; ask an operator to do it for you")
- @@ -1392,7 +1435,7 @@
- return
- end
- - register_user(cid, nick, password, level)
- + register_user(cid, nick, password, level, c:getField("NI"))
- autil.reply(c, "\"" .. nick .. "\" has been registered")
- @@ -1591,3 +1634,6 @@
- if reasons[reason] then reasons[reason] = reasons[reason] + 1 else reasons[reason] = 1 end
- end
- end)
- +
- +save_users_timer = sm:addTimedJob(900000, to_save_users)
- +autil.on_unloading(_NAME, save_users_timer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement