--SendPM = nil -- or 1 -- remove above comment for PM -- Globals -- HubAddress = "trucker1.dyndns.org " BotName = "(@)Truckers Garage(@)" SendPM = 1--nil -- or 1 -- remove above comment for PM -- Events -- function NewUserConnected(user) i,j,share = strfind(user.sMyInfoString, "$(%d+)%$") if share==nil then user:Disconnect() else usershare = format("%0.2f", tonumber(share)/(1024*1024*1024)) local tmp tmp = "Hello "..user.sName.." and welcome to "..frmHub:GetHubName().."\r\n\r\n" tmp = tmp.."\tYour IP: "..user.sIP.."\r\n" tmp = tmp.."\tYour Nick: "..user.sName.."\r\n" tmp = tmp.."\tYour share: "..usershare.."\r\n\r\n" tmp = tmp.."\tHub IP:"..HubAddress.."\r\n" tmp = tmp.."\tHub Name: "..frmHub:GetHubName().."\r\n" tmp = tmp.."\tHub Desc: "..frmHub:GetHubDescr().."\r\n\r\n" tmp = tmp.."\tUsers Online: "..frmHub:GetUsersCount().."\r\n" tmp = tmp.."\tOperators Online: "..CountOPs().."\r\n" local hr, mn = GetUpTime() tmp = tmp.."\tUptime: "..hr.." hours, "..mn.." minutes\r\n" if(SendPM) then user:SendPM(BotName,tmp) else SendToAll(BotName,tmp) end end end -- Functions -- function CountOPs() local tmp, count = GetUsersByProfile(GetProfileName(1)), 0; if tmp then for id = 0, getn(tmp) do if GetItemByName(tmp[id]) then count = count + 1; end end end return count end -- Gets the hubs uptime -- return: hrs, mns -- Author: RabidWombat function GetUpTime() local hFile, sFinal = openfile("..\\error.log", "r"), nil if (hFile) then local line = read(hFile) while line do if(strsub(line, -15) == "Serving started") then -- s, e, sFinal = strfind(line, "([^-]+).+") sFinal = strsub(line, 1, strlen(line) - 17) -- changed this line because there are '-' in the time, duh end line = read(hFile) end closefile(hFile) local StartTime = JulianDate(SplitTimeString(sFinal)); -- Changed here too to new format local EndTime = JulianDate(SplitTimeString(date("%d-%m-%Y %H:%M:%S"))); local diff = EndTime - StartTime; return floor(diff) * 24 + floor(frac(diff) * 24), floor(frac(frac(diff)*24)*60); end return 0,0 -- this should NEVER happen end -- Split a specific Time string into its components -- New Format: D-M-Y HR:MN:SC" - 24hr time -- return: D,M,Y,HR,MN,SC HR is in 24hr format function SplitTimeString(TimeString) -- local s,e,D,M,Y,HR,MN,SC = strfind(TimeString, "([^-]+).([^-]+).(%S+)%s([^:]+).([^:]+).(%S+)"); D = tonumber(D) M = tonumber(M) Y = tonumber(Y) HR = tonumber(HR) MN = tonumber(MN) SC = tonumber(SC) assert(HR < 24); assert(MN < 60); assert(SC < 60); return D,M,Y,HR,MN,SC end function JulianDate(DAY, MONTH, YEAR, HOUR, MINUTE, SECOND) -- HOUR is 24hr format local jy, ja, jm; assert(YEAR ~= 0); assert(YEAR ~= 1582 or MONTH ~= 10 or DAY < 4 or DAY > 15); --The dates 5 through 14 October, 1582, do not exist in the Gregorian system!"); if(YEAR < 0 ) then YEAR = YEAR + 1; end if( MONTH > 2) then jy = YEAR; jm = MONTH + 1; else jy = YEAR - 1; jm = MONTH + 13; end local intgr = floor( floor(365.25*jy) + floor(30.6001*jm) + DAY + 1720995 ); --check for switch to Gregorian calendar local gregcal = 15 + 31*( 10 + 12*1582 ); if(DAY + 31*(MONTH + 12*YEAR) >= gregcal ) then ja = floor(0.01*jy); intgr = intgr + 2 - ja + floor(0.25*ja); end --correct for half-day offset local dayfrac = HOUR / 24 - 0.5; if( dayfrac < 0.0 ) then dayfrac = dayfrac + 1.0; intgr = intgr - 1; end --now set the fraction of a day local frac = dayfrac + (MINUTE + SECOND/60.0)/60.0/24.0; --round to nearest second local jd0 = (intgr + frac)*100000; local jd = floor(jd0); if( jd0 - jd > 0.5 ) then jd = jd + 1 end return jd/100000; end function frac(num) return num - floor(num); end --------------------------------------------------------------------------------