equal
deleted
inserted
replaced
60 end |
60 end |
61 |
61 |
62 local function callback(username, host, datastore, data) |
62 local function callback(username, host, datastore, data) |
63 for _, f in ipairs(callbacks) do |
63 for _, f in ipairs(callbacks) do |
64 username, host, datastore, data = f(username, host, datastore, data); |
64 username, host, datastore, data = f(username, host, datastore, data); |
65 if not username then break; end |
65 if username == false then break; end |
66 end |
66 end |
67 |
67 |
68 return username, host, datastore, data; |
68 return username, host, datastore, data; |
69 end |
69 end |
70 function add_callback(func) |
70 function add_callback(func) |
121 if not data then |
121 if not data then |
122 data = {}; |
122 data = {}; |
123 end |
123 end |
124 |
124 |
125 username, host, datastore, data = callback(username, host, datastore, data); |
125 username, host, datastore, data = callback(username, host, datastore, data); |
126 if not username then |
126 if username == false then |
127 return true; -- Don't save this data at all |
127 return true; -- Don't save this data at all |
128 end |
128 end |
129 |
129 |
130 -- save the datastore |
130 -- save the datastore |
131 local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+"); |
131 local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+"); |
145 return true; |
145 return true; |
146 end |
146 end |
147 |
147 |
148 function list_append(username, host, datastore, data) |
148 function list_append(username, host, datastore, data) |
149 if not data then return; end |
149 if not data then return; end |
150 if callback and callback(username, host, datastore) then return true; end |
150 if callback(username, host, datastore) == false then return true; end |
151 -- save the datastore |
151 -- save the datastore |
152 local f, msg = io_open(getpath(username, host, datastore, "list", true), "a+"); |
152 local f, msg = io_open(getpath(username, host, datastore, "list", true), "a+"); |
153 if not f then |
153 if not f then |
154 log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); |
154 log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); |
155 return; |
155 return; |
163 |
163 |
164 function list_store(username, host, datastore, data) |
164 function list_store(username, host, datastore, data) |
165 if not data then |
165 if not data then |
166 data = {}; |
166 data = {}; |
167 end |
167 end |
168 if callback and callback(username, host, datastore) then return true; end |
168 if callback(username, host, datastore) == false then return true; end |
169 -- save the datastore |
169 -- save the datastore |
170 local f, msg = io_open(getpath(username, host, datastore, "list", true), "w+"); |
170 local f, msg = io_open(getpath(username, host, datastore, "list", true), "w+"); |
171 if not f then |
171 if not f then |
172 log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); |
172 log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); |
173 return; |
173 return; |