All pastes #85680 Raw Edit

Kaelten

public text v1 · immutable
·published 2006-07-12 03:18 UTC
rendered paste body
function KC_Common:AddCode(link, sell, buy)
	if (not link or tonumber(link)) then return end
	sell = (sell and sell ~= 0) and sell or nil
	buy  = (buy and buy ~= 0) and buy or nil
	local code = strfind(link, ":") and self:GetCode(link) or  link
	local id, sub = self:Split(code, "!")
	local data = self.app.db:get(id)

	if (data) then
		local subs, sSell, sBuy = self:Explode(data, ",")
		if (not strfind(subs,"!" .. sub .."!")) then
			self.app.db:set(id, format("%s,%d,%d", subs .. sub .. "!", sell or sSell, buy or sBuy))
			self:UpdateStats(0, 1, sell and 1 or 0, buy and 1 or 0)
		elseif (sell or buy) then
			self.app.db:set(id, format("%s,%d,%d", subs, sell or sSell, buy or sBuy))			
			self:UpdateStats(0, 0, sell and ((sell == sSell) and 0 or 1), buy and ((buy == sBuy) and 0 or 1))
		end
	else
		self.app.db:set(id, format("!%d!,%d,%d", sub, sell or 0, buy or 0))
		self:UpdateStats(1, 1, sell and 1 or 0, buy and 1 or 0)
	end
end