-
Notifications
You must be signed in to change notification settings - Fork 1
/
1_logip.lua
48 lines (42 loc) · 1.35 KB
/
1_logip.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local Folder = "Log" -- Èìÿ ïàïêè äëÿ ëîã-ôàéëà (ìîæíî èçìåíèòü ïî æåëàíèþ)
function Start() _ = {} end
function OnStartup()
folder = Core.GetPtokaXPath().."/scripts/"..Folder.."/"
set = folder.."log_users.txt" -- èìÿ ëîã-ôàéëà (ìîæíî èçìåíèòü ïî æåëàíèþ)
if loadfile(set) then
dofile(set)
else
local _ = "\""
os.execute("mkdir ".._..folder.._)
Start()
end
if loadfile(set) then dofile(set) end
Save()
end
function UserConnected(user)
_ = {}
_[os.date("%d.%m.%Y %X")] = "Âõîä ïîëüçîâàòåëÿ <"..user.sNick.."> ñ IP-àäðåñà: ["..user.sIP.."]"
Save()
end
OpConnected, RegConnected = UserConnected, UserConnected
function Save_Serialize(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName);
for key, value in pairs(tTable) do
local sKey = (type(key) == "string") and string.format(" %q ",key) or string.format(" %d ",key);
if(type(value) == "table") then
Save_Serialize(value, sKey, hFile, sTab);
else
local sValue = (type(value) == "string") and string.format(" %q ",value) or tostring(value);
hFile:write( sTab..sKey..sValue);
end
hFile:write( "\n");
end
hFile:write(sTab);
end
function Save() Save_file(set, _, "-") end
function Save_file(file, table, tablename)
local hFile = io.open (file, "a")
Save_Serialize(table, tablename, hFile);
hFile:close()
end