• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent Anti-Dupe - Delete all items with duplicated serial from your database.

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
Here is the second version of my Anti-Dupe system that you can see here http://otland.net/f81/basic-anti-dupe-system-131898/

This new script brings a better configuration, now it checks the tables that you want and some optimizations made.

//TODO
  • You can configure the tables that will be checked.
  • It saves the info on a log file, declared by yourself.
  • When a duplicated item is deleted, scripts prints it on console, showing the player who has the item, item-id, count and serial of the item.
  • With the function 'generateSerial()' you can set an unique serial to every item.

First of all, you need to paste this function at your lib/functions.lua:
Lua:
function generateSerial()
    local strings = "AaBbCcDdEeFfGgHhIiJjKkLlMmOoPpQqRrSsTtUuVvWwXxYyZz"
    local newSerialStr, newSerialInt = "", 0
    local newSerial = ""
    local query, query2, query3
    repeat
        for k = 1, math.random(1, 10) do
            local l = math.random(1, string.len(strings))
            newSerialStr = newSerialStr .. string.sub(strings, l, l)
        end
        newSerialInt = math.random(999999)
        newSerial = newSerialStr .. "-" .. newSerialInt
        query = db.getResult("select * from player_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
        query2 = db.getResult("select * from player_depotitems where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
        query3 = db.getResult("select * from tile_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
    until query:getID() == -1 and query2:getID() == -1 and query3:getID() == -1
    return "!" .. newSerial
end

Now, everytime that do you want to set an unique serial to an item, just use:
Lua:
doItemSetAttribute(uid, "serial", generateSerial())

This is the script that will delete items with duplicated serial when serer starts:
Create a file of globalevents/scripts called trackitems.lua and paste:
Lua:
tablesToCheck = {"player_items", "player_depotitems", "tile_items", {"player_items", {"player_depotitems", "tile_items"}}, {"player_depotitems", "tile_items"}}

function onStartup()
    local text, final = "", ""
    local filex = "data/logs/duplicated.txt"
    local f = io.open(filex, "a+")
    local count = 0
    for i = 1, table.maxn(tablesToCheck) do
        if type(tablesToCheck[i]) == "string" then
            local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 1)")
            if query:getID() ~= -1 then
                while(true) do
                    local delete = db.executeQuery("delete from " .. tablesToCheck[i] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. " and player_id = " .. query:getDataInt("player_id") .. ";")
                    text = "[!] -> Deleting items with duplicated serial from '" .. tablesToCheck[i] .. "': [Player: " .. getPlayerNameByGUID(query:getDataInt("player_id")) .. ", Item: " .. query:getDataInt("itemtype") .. ", Count: " .. query:getDataInt("count") .. ", Serial: " .. query:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!")
                    count = (delete and count + 1 or count)
                    final = final .. (final ~= "" and "\n" or "") .. text
                    print(text)
                    if not query:next() then break end
                end
            end
        else
            if type(tablesToCheck[i][2]) == "string" then
                local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][1] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][2] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
                if query:getID() ~= -1 then
                    while(true) do
                        local query_ = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][2] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][1] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
                        local delete = db.executeQuery("delete from " .. tablesToCheck[i][1] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
                        count = (delete and count + 1 or count)
                        local delete2 = db.executeQuery("delete from " .. tablesToCheck[i][2] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
                        count = (delete2 and count + 1 or count)
                        text = "[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][1] .. "' [Player: " .. getPlayerNameByGUID(query:getDataInt("player_id")) .. ", Item: " .. query:getDataInt("itemtype") .. ", Count: " .. query:getDataInt("count") .. ", Serial: " .. query:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!") ..
                        "\n[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][2] .. "' [Player: " .. getPlayerNameByGUID(query_:getDataInt("player_id")) .. ", Item: " .. query_:getDataInt("itemtype") .. ", Count: " .. query_:getDataInt("count") .. ", Serial: " .. query_:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!")
                        final = final .. (final ~= "" and "\n" or "") .. text
                        print(text)
                        if not query:next() then break end
                    end
                end
            else
                for j = 1, #tablesToCheck[i][2] do
                    local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][1] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][2][j] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
                    if query:getID() ~= -1 then
                        while(true) do
                            local query_ = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][2][j] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][1] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
                            local delete = db.executeQuery("delete from " .. tablesToCheck[i][1] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
                            count = (delete and count + 1 or count)
                            local delete2 = db.executeQuery("delete from " .. tablesToCheck[i][2][j] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
                            count = (delete2 and count + 1 or count)
                            text = "[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][1] .. "' [Player: " .. getPlayerNameByGUID(query:getDataInt("player_id")) .. ", Item: " .. query:getDataInt("itemtype") .. ", Count: " .. query:getDataInt("count") .. ", Serial: " .. query:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!") ..
                            "\n[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][2][j] .. "' [Player: " .. getPlayerNameByGUID(query_:getDataInt("player_id")) .. ", Item: " .. query_:getDataInt("itemtype") .. ", Count: " .. query_:getDataInt("count") .. ", Serial: " .. query_:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!")
                            final = final .. (final ~= "" and "\n" or "") .. text
                            print(text)
                            if not query:next() then break end
                        end
                    end
                end
            end
        end
    end
    if f ~= nil then
        f:write("[" .. os.date("%d %B %Y %X ", os.time()) .. "] >> [Anti-Dupe] " .. count .. " duplicated items have been deleted from the database.\n" .. (final == "" and "[!] -> No duplicated item was found in the database" or final) .. "\n\n")
        f:close()
    else
        print("[!] -> [Anti-Dupe] Cannot save info to file!")
    end
    return true
end

XML:
    <globalevent name="trackitems" type="start" event="script" value="trackitems.lua"/>
Also you can see items with serial from phpMyAdmin with this command:
SQL:
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS  'serial'
FROM player_items
WHERE CONVERT( attributes
USING latin1 ) LIKE  '%serial%'
ippb3n.png


And you can see items with duplicated serials with the following commands:
SQL:
--Use this command to see duplicated items on players inventory
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS  'duplicated serials'
FROM player_items
WHERE SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
IN (

SELECT SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
FROM player_items
WHERE CONVERT( attributes
USING latin1 ) LIKE  '%serial%'
GROUP BY SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
HAVING COUNT( * ) >1
)

--Use this command to see duplicated items on players inventory or depot items
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS 'duplicated serials'
FROM player_items
WHERE SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
IN (
 
SELECT SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
FROM player_depotitems
WHERE CONVERT( attributes
USING latin1 ) LIKE '%serial%'
GROUP BY SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
HAVING COUNT( * ) >1
)

--Use this command to see duplicated items on players depots
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS 'duplicated serials'
FROM player_depotitems
WHERE SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
IN (
 
SELECT SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
FROM player_depotitems
WHERE CONVERT( attributes
USING latin1 ) LIKE '%serial%'
GROUP BY SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
HAVING COUNT( * ) >1
)

--Use this command to see duplicated items on player_items and player_depotitems (Example of usage)
--Use this command to see duplicated items on players depots
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS 'duplicated serials'
FROM player_items
WHERE SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
IN (
 
SELECT SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
FROM player_depotitems
WHERE CONVERT( attributes
USING latin1 ) LIKE '%serial%'
GROUP BY SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
HAVING COUNT( * ) >0

709ovs.png

Note that you can change the table 'player_items' to 'player_depotitems' to get info about items on depot

Please, comment with constructive criticism :)!
Rep++ is appreciated!
 
Last edited:
Good, where I put the function in my shop.lua ?

Script Here:
Lua:
local SHOP_MSG_TYPE = MESSAGE_EVENT_ORANGE
local SQL_interval = 30
 
function onThink(interval, lastExecution)
	local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")
	if(result_plr:getID() ~= -1) then
		while(true) do
			local id = tonumber(result_plr:getDataInt("id"))
			local action = tostring(result_plr:getDataString("action"))
			local delete = tonumber(result_plr:getDataInt("delete_it"))
			local cid = getCreatureByName(tostring(result_plr:getDataString("name")))
			if isPlayer(cid) then
				local itemtogive_id = tonumber(result_plr:getDataInt("param1"))
				local itemtogive_count = tonumber(result_plr:getDataInt("param2"))
				local container_id = tonumber(result_plr:getDataInt("param3"))
				local container_count = tonumber(result_plr:getDataInt("param4"))
				local add_item_type = tostring(result_plr:getDataString("param5"))
				local add_item_name = tostring(result_plr:getDataString("param6"))
				local received_item = 0
				local full_weight = 0
				if add_item_type == 'container' then
					container_weight = getItemWeightById(container_id, 1)
					if isItemRune(itemtogive_id) == TRUE then
						items_weight = container_count * getItemWeightById(itemtogive_id, 1)
					else
						items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)
					end
					full_weight = items_weight + container_weight
				else
					full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
					if isItemRune(itemtogive_id) == TRUE then
						full_weight = getItemWeightById(itemtogive_id, 1)
					else
						full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
					end
				end
				local free_cap = getPlayerFreeCap(cid)
				if full_weight <= free_cap then
					if add_item_type == 'container' then
						local new_container = doCreateItemEx(container_id, 1)
						local iter = 0
						while iter ~= container_count do
							doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
							iter = iter + 1
						end
						received_item = doPlayerAddItemEx(cid, new_container)
					else
						local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
						doItemSetAttribute(new_item, "description", "This item was purchased at the shop by the player ".. getPlayerName(cid) ..".")
						doItemSetAttribute(new_item, "aid", getPlayerGUID(cid)+10000)
						received_item = doPlayerAddItemEx(cid, new_item)
					end
					if received_item == RETURNVALUE_NOERROR then
						doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')
						db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
						db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
					else
						doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
					end
				else
					doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
				end
			end
			if not(result_plr:next()) then
				break
			end
		end
		result_plr:free()
	end
	return true
end

I tried and NotWork:
Lua:
...
local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
						doItemSetAttribute(new_item, "description", "This item was purchased at the shop by the player ".. getPlayerName(cid) ..".")
						doItemSetAttribute(new_item, "aid", getPlayerGUID(cid)+10000)
						received_item = doPlayerAddItemEx(cid, new_item)
                                                doItemSetAttribute(uid, "serial", generateSerial())
...

and
Lua:
                                                doItemSetAttribute(new_item, "serial", generateSerial())
 
It won't work if items has more than one attribute, item should have only the serial and no more attributes
 
Fixed the problem with connection lost?

I never got that problem, so i cannot fix that, you should try with this script and post here if you find problem with connection.
Also you should post here the distro used by you and the sqlType (Remember, this script has been tested on TFS 0.3.6pl1 and works with MySql)
 
Bro, no have command /track ?? and i used command to see duplicated items on players inventory in mysql and my server down.
 
So if someone duplicate items and hide inside the house will not be detected any more.

EDIT: msql connection lost tsf0.4
 
Last edited:
i used the query and now i got a problem x.x


There are many variables that could be causing this error (Note: That isn't an error from my script, that's a server error, caused maybe because your pc don't have enough memory or have too many connections)

Possible reasons for that:
Firewall (Try closing it).
Not enough memory (Try increasing with set global max_allowed_packet = x).
Too much connections.

You should try updating your mysql version.
 
Last edited:
There are many variables that could be causing this error (Note: That isn't an error from my script, that's a server error, caused maybe because your pc don't have enough memory or have too many connections)

Possible reasons for that:
Firewall (Try closing it).
Not enough memory (Try increasing with set global max_allowed_packet = x).
Too much connections.

You should try updating your mysql version.

Are you crazy? Install a new mysql will not fix the problem.
Your code idea is good... but the code still a mess. You open mysql connections but don't close.
Lua:
function generateSerial()
	--[[local strings = "AaBbCcDdEeFfGgHhIiJjKkLlMmOoPpQqRrSsTtUuVvWwXxYyZz"
	local newSerialStr, newSerialInt = "", 0
	local newSerial = ""
	local query, query2, query3
	repeat
		for k = 1, math.random(1, 10) do
			local l = math.random(1, string.len(strings))
			newSerialStr = newSerialStr .. string.sub(strings, l, l)
		end
		newSerialInt = math.random(999999)
		newSerial = newSerialStr .. "-" .. newSerialInt]]
		query = db.getResult("select * from player_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
		query2 = db.getResult("select * from player_depotitems where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
		query3 = db.getResult("select * from tile_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
	until query:getID() == -1 and query2:getID() == -1 and query3:getID() == -1
	return "!" .. newSerial
end

why you dont close the connection? ¬¬'''
To stop this error:
RKlhRCaufS.png

use this modified function.
Lua:
function generateSerial()
	local strings = "AaBbCcDdEeFfGgHhIiJjKkLlMmOoPpQqRrSsTtUuVvWwXxYyZz"
	local newSerialStr, newSerialInt = "", 0
	local newSerial = ""
	local query, query2, query3
	repeat
		for k = 1, math.random(1, 10) do
			local l = math.random(1, string.len(strings))
			newSerialStr = newSerialStr .. string.sub(strings, l, l)
		end
		newSerialInt = math.random(999999)
		newSerial = newSerialStr .. "-" .. newSerialInt
		query = db.getResult("select * from player_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
		query2 = db.getResult("select * from player_depotitems where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
		query3 = db.getResult("select * from tile_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
	until query:getID() == -1 and query2:getID() == -1 and query3:getID() == -1
	if query:getID() ~= -1 then query:free() end
        if query2:getID() ~= -1 then query2:free() end
        if query3:getID() ~= -1 then query3:free() end
        return "!" .. newSerial
end

Do the same for the main code and will works.

Lua:
Lua Code:

tablesToCheck = {"player_items", "player_depotitems", "tile_items", {"player_items", {"player_depotitems", "tile_items"}}, {"player_depotitems", "tile_items"}}
 
function onStartup()
	local text, final = "", ""
	local filex = "data/logs/duplicated.txt"
	local f = io.open(filex, "a+")
	local count = 0
	for i = 1, table.maxn(tablesToCheck) do
		if type(tablesToCheck[i]) == "string" then
			local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 1)")
			if query:getID() ~= -1 then
				while(true) do
					local delete = db.executeQuery("delete from " .. tablesToCheck[i] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. " and player_id = " .. query:getDataInt("player_id") .. ";")
					text = "[!] -> Deleting items with duplicated serial from '" .. tablesToCheck[i] .. "': [Player: " .. getPlayerNameByGUID(query:getDataInt("player_id")) .. ", Item: " .. query:getDataInt("itemtype") .. ", Count: " .. query:getDataInt("count") .. ", Serial: " .. query:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!")
					count = (delete and count + 1 or count)
					final = final .. (final ~= "" and "\n" or "") .. text
					print(text)
					if not query:next() then break end
				end
				query:free()
			end
		else
			if type(tablesToCheck[i][2]) == "string" then
				local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][1] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][2] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
				if query:getID() ~= -1 then
					while(true) do
						local query_ = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][2] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][1] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
						local delete = db.executeQuery("delete from " .. tablesToCheck[i][1] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
						count = (delete and count + 1 or count)
						local delete2 = db.executeQuery("delete from " .. tablesToCheck[i][2] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
						count = (delete2 and count + 1 or count)
						text = "[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][1] .. "' [Player: " .. getPlayerNameByGUID(query:getDataInt("player_id")) .. ", Item: " .. query:getDataInt("itemtype") .. ", Count: " .. query:getDataInt("count") .. ", Serial: " .. query:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!") ..
						"\n[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][2] .. "' [Player: " .. getPlayerNameByGUID(query_:getDataInt("player_id")) .. ", Item: " .. query_:getDataInt("itemtype") .. ", Count: " .. query_:getDataInt("count") .. ", Serial: " .. query_:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!")
						final = final .. (final ~= "" and "\n" or "") .. text
						print(text)
						if not query:next() then query:free() break end
					end
				end
			else
				for j = 1, #tablesToCheck[i][2] do
					local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][1] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][2][j] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
					if query:getID() ~= -1 then
						while(true) do
							local query_ = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i][2][j] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i][1] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 0)")
							local delete = db.executeQuery("delete from " .. tablesToCheck[i][1] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
							count = (delete and count + 1 or count)
							local delete2 = db.executeQuery("delete from " .. tablesToCheck[i][2][j] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
							count = (delete2 and count + 1 or count)
							text = "[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][1] .. "' [Player: " .. getPlayerNameByGUID(query:getDataInt("player_id")) .. ", Item: " .. query:getDataInt("itemtype") .. ", Count: " .. query:getDataInt("count") .. ", Serial: " .. query:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!") ..
							"\n[!] -> Deleting item with duplicated serial from '" .. tablesToCheck[i][2][j] .. "' [Player: " .. getPlayerNameByGUID(query_:getDataInt("player_id")) .. ", Item: " .. query_:getDataInt("itemtype") .. ", Count: " .. query_:getDataInt("count") .. ", Serial: " .. query_:getDataString("track") .."]... " .. (delete and "Success!" or "Failed!")
							final = final .. (final ~= "" and "\n" or "") .. text
							print(text)
							if not query:next() then break end
						end
						query:free()
					end
				end
			end
		end
	end
	if f ~= nil then
		f:write("[" .. os.date("%d %B %Y %X ", os.time()) .. "] >> [Anti-Dupe] " .. count .. " duplicated items have been deleted from the database.\n" .. (final == "" and "[!] -> No duplicated item was found in the database" or final) .. "\n\n")
		f:close()
	else
		print("[!] -> [Anti-Dupe] Cannot save info to file!")
	end
	return true
end
 
You open mysql connections but don't close.
this isn't LuaSQL. db.getResult doesn't open any connection, it always uses the persistent db connection of TFS
why you dont close the connection? ¬¬'''
result.free(res) doesn't close anything, but only frees the allocated resources

just correcting you, not saying :free shouldn't be used.
 
this isn't LuaSQL. db.getResult doesn't open any connection, it always uses the persistent db connection of TFS

result.free(res) doesn't close anything, but only frees the allocated resources

just correcting you, not saying :free shouldn't be used.

Since tfs 0.3.4 we have to free the results because every db.getResult open a new connection, you checked if its really true about it? I already tested on 0.3.4, if you run like 500 db.getResult the mysql block the new connections and some times close the server db connection.
 
well, i modified the scripts, to the ones you posted Mock, but i still have the same error x.x

Im using tfs 0.4 btw
 
Back
Top