_=[[ ######################################################################### Filename: vh_registration.lua Released: December 05, 2005 Version: 0.802 Copyright (c) 2005, Ro (lamehub.lame.hu:8998) (elite.4242.hu:4242) перевод igorsh Lua 5: The Programming Language Open-Source Program for HubOwners ===================================================================================== Software by: Lua is a powerful light-weight programming language designed for extending applications. Lua is also frequently used as a general-purpose, stand-alone language. Lua is free software. ######################################################################### ]] botnick = "HubDweller" function VH_OnParsedMsgChat(nick, data) res, UserClass = VH:GetUserClass(nick) if not res then return 1 else end --//префикс команды if (string.sub(data, 1,1) == "?") then --// список зарегистрированных пользователей if (string.sub(data, 2, 8) == "reglist") and (UserClass >= 3) then if string.len(data) < 9 or (string.sub(data, 10, 13) ~= "nick") and (string.sub(data, 10, 14) ~= "class") and (string.sub(data, 10, 17) ~= "reg_date") then VH:SendDataToUser("<"..botnick.."> Неправильный параметр! (Синтаксис: ?reglist nick,class,reg_date)|", nick) else local order = string.sub(data, 10 ,string.len(data)) query = "SELECT nick,class,reg_date FROM reglist ORDER BY "..order.."" res,rows = VH:SQLQuery(query) totalregs = rows if res then VH:SendDataToUser("Зарегистрированные пользователи отсортированы по: "..order..":\nКласс:\tДата:\t\t\tНик:|",nick) for x=0, rows-1 do res, reg, class, reg_date = VH:SQLFetch(x) if reg_date == nil then reg_date = 1 end VH:SendDataToUser(""..class .. "\t" ..(ConvertUnixTimeToDate(reg_date)).."\t" .. reg .. "|", nick) end end VH:SendDataToUser("Total: "..totalregs.." OK|",nick) end --// информация о зарегистрированном elseif (string.sub(data, 2, 8) == "reginfo") and (UserClass >= 3) then if string.len(data) > 9 then local user = string.sub(data, 10 ,string.len(data)) query = "SELECT nick,class,class_protect,reg_date,reg_op,login_last,logout_last,login_cnt,login_pwd,login_ip, note_usr FROM reglist ORDER BY class" res,rows = VH:SQLQuery(query) if res then local out = "Информация о "..user..":\n\t" for x=0, rows-1 do res, reg, class, class_protect, reg_date, reg_op, login_last, logout_last, login_cnt, login_pwd, login_ip, note_usr = VH:SQLFetch(x) if reg == user then out = out .. "Класс:\t\t\t\t" .. class .. "\n\t" if class_protect ~= nil then out = out .. "Защищён от уровня ниже, чем:\t"..class_protect.."\n\t" end if reg_date ~= nil then out = out .. "Дата регистрации:\t\t"..ConvertUnixTimeToDate(reg_date)..", " .. TimeDiff(((os.time()) - (tonumber(reg_date)))).." назад\n\t" end if reg_op ~= nil then out = out .. "Зарегистрирован оператором:\t"..reg_op.."\n\t" end if login_last ~= nil then out = out .. "Последний раз входил:\t\t"..ConvertUnixTimeToDate(login_last)..", " .. TimeDiff(((os.time()) - (tonumber(login_last)))).. " назад\n\t" end if logout_last ~= nil then out = out .. "Последний раз выходил:\t\t"..ConvertUnixTimeToDate(logout_last)..", " .. TimeDiff(((os.time()) - (tonumber(logout_last)))).." назад\n\t" end if login_cnt ~= nil then out = out .. "Всего входов:\t\t\t"..login_cnt.."\n\t" end if login_pwd ~= nil and tonumber(class) < 3 then out = out .. "Пароль:\t\t\t\t->"..login_pwd.."<-\n\t" end if login_ip ~= nil then out = out .. "Последний адрес:\t\t\t"..login_ip.."\n\t" end if note_usr == nil then out = out .. "Последние слова:\t\t\tN/A\n\t" else out = out .. "Последние слова:\t\t\t"..note_usr.."\n\t" end VH:SendDataToUser("<"..botnick.."> "..out.."|", nick) end end end else VH:SendDataToUser("<"..botnick.."> Bad parameter. (Use: ?reginfo )|", nick) end --// регистрация пользователя elseif (string.sub(data, 2, 6) == "regme") then local pass = nil if string.len(data) < 8 then VH:SendDataToUser("<"..botnick.."> Parameter hiba! Adj meg jelszot is! (?regme jelszavad).|", nick) else pass = (string.sub(data, 8, (string.len(data)))) end if not PassMinLen then res, PassMinLen = VH:GetConfig("config", "password_min_len") end if UserClass > 0 then VH:SendDataToUser("<"..botnick.."> Вы уже зарегистрированы.|", nick) elseif string.len(pass) < tonumber(PassMinLen) then VH:SendDataToUser("<"..botnick.."> Слишком короткий пароль.Минимальная число символов в пароле - "..PassMinLen.."! Пробуйте снова.|", nick) elseif string.len(pass) >= tonumber(PassMinLen) then query = "INSERT INTO reglist (nick,class,reg_date,reg_op,pwd_change,login_pwd,pwd_crypt,note_op) ".."VALUES ('"..nick.."','1','"..(os.time()).."','Lua','0','"..pass.."','0','Lua')" res,rows = VH:SQLQuery(query) if res then res, old_timer_reloadcfg_period = VH:GetConfig("config", "timer_reloadcfg_period") if not res then return 1 else end res, err = VH:SetConfig("config" , "timer_reloadcfg_period", "0") Time = 5 VH:SendDataToUser("<"..botnick.."> Регистрация завершена. Ваш пароль на этом хабе: ->"..pass.."<- Хаб закрывает соединение, чтобы вы вошли как зарегистрированный пользователь.|", nick) VH:CloseConnection(nick) VH:SendDataToAll("<"..botnick.."> Новый зарегистрированный пользователь: "..nick.." :-)|",0,10) else VH:SendDataToUser("<"..botnick.."> Ошибка, попробуйте ещё раз.|", nick) end else VH:SendDataToUser("<"..botnick.."> Хм... Не пошло...|", nick) end return 0 end else if UserClass > 0 then local tmp = "["..(os.date("20%y %m %d - %H:%M:%S")).."] <"..nick.."> "..data.."" query = "UPDATE reglist SET note_usr='"..tmp.."' WHERE nick='"..nick.."'" res,rows = VH:SQLQuery(query) end end return 1 end function VH_OnTimer() if Time ~= nil and Time > 0 then Time = Time - 1 return end if Time == 0 then res, err = VH:SetConfig("config" , "timer_reloadcfg_period", old_timer_reloadcfg_period) Time = nil end return 1 end function ConvertUnixTimeToDate(tempin) if tonumber(tempin) < 0 or tonumber(tempin) == nil then temp = "N/A" else local tp = os.date("*t", tempin) temp = "" if tp["year"] ~= nil then temp = temp .. tp["year"] end if tp["month"] ~= nil then if string.len(tp["month"]) == 1 then temp = temp.." 0"..tp["month"] else temp = temp.." "..tp["month"] end end if tp["day"] ~= nil then if string.len(tp["day"]) == 1 then temp = temp.." 0"..tp["day"] else temp = temp.." "..tp["day"] end end if tp["hour"] ~= nil then if string.len(tp["hour"]) == 1 then temp = temp.." - 0"..tp["hour"] else temp = temp.." - "..tp["hour"] end end if tp["min"] ~= nil then if string.len(tp["min"]) == 1 then temp = temp..":0"..tp["min"] else temp = temp..":"..tp["min"] end end if tp["sec"] ~= nil then if string.len(tp["sec"]) == 1 then temp = temp..":0"..tp["sec"] else temp = temp..":"..tp["sec"] end end end return temp end function TimeDiff(diffsec) temp = "" local okay = 1 if diffsec < 0 then temp = "(Неправильные часы)" okay = 0 end if okay == 1 then local second = " сек" local minute = " мин" local hour = " ч" local day = " д" local week = " нед" local month = " мес" local year = " г" local difftmp = 0 difftmp = math.floor ( diffsec / 60 / 60 / 24 / 360 ) if difftmp > 0 then if difftmp > 1 then year = year.." " else year = year .. " " end year = difftmp .. year else year = "" end diffsec = diffsec - difftmp * 60 * 60 * 24 * 360 difftmp = math.floor ( diffsec / 60 / 60 / 24 / 30 ) if difftmp > 0 then if difftmp > 1 then month = month .. " " else month = month .. " " end month = difftmp .. month else month = "" end diffsec = diffsec - difftmp * 30 * 24 * 60 * 60 difftmp = math.floor ( diffsec / 60 / 60 / 24 / 7 ) if difftmp > 0 then if difftmp > 1 then week = week .. " " else week = week .. " " end week = difftmp .. week else week = "" end diffsec = diffsec - difftmp * 7 * 24 * 60 * 60 difftmp = math.floor ( diffsec / 60 / 60 / 24 ) if difftmp > 0 then if difftmp > 1 then day = day .. " " else day = day .. " " end day = difftmp .. day else day = "" end diffsec = diffsec - difftmp * 24 * 60 * 60 difftmp = math.floor ( diffsec / 60 / 60 ) if difftmp > 0 then if difftmp > 1 then hour = hour .. " " else hour = hour .. " " end hour = difftmp .. hour else hour = "" end diffsec = diffsec - difftmp * 60 * 60 difftmp = math.floor ( diffsec / 60 ) if difftmp > 0 then if difftmp > 1 then minute = minute .. " " else minute = minute .. " " end minute = difftmp .. minute else minute = "" end diffsec = diffsec - difftmp * 60 difftmp = diffsec if difftmp > 0 then if difftmp > 1 then second = second .. " " else second = second .. " " end second = difftmp .. second else second = "" end temp = year .. month .. week .. day .. hour .. minute .. second end return temp end