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

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Darkhaos, Aug 3, 2011.

  1. BeniS

    BeniS Well-Known Member

    Joined:
    Aug 8, 2009
    Messages:
    1,849
    Likes Received:
    182
    Best Answers:
    0
    It doesn't really matter which one is the duplicated item, they are all the same item. As long as one of the duplicated items exist its OK, seeing as the only real way to duplicate in TFS is by a server crash, the duplicated items will be removed upon startup.

    Btw its just good form to make sure the results are freed at the end of a script :p anyway nice idea.
     
    Sublime likes this.
  2. GM Soul Monger

    GM Soul Monger New Member

    Joined:
    Jul 1, 2007
    Messages:
    31
    Likes Received:
    4
    Best Answers:
    0
    Im new in here, but i would like to know where should i implement
    Code (Lua):
    1. doItemSetAttribute(uid, "serial", generateSerial())
    my shop.lua is the next one:

    Code (Lua):
    1. function onThink(interval, lastExecution, thinkInterval)
    2.  
    3.     local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
    4.    
    5.         if(result:getID() ~= -1) then
    6.             while(true) do
    7.                 cid = getCreatureByName(tostring(result:getDataString("player")))
    8.                 product = tonumber(result:getDataInt("product"))
    9.                 itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
    10.                     if isPlayer(cid) then
    11.                         local id = tonumber(itemr:getDataInt("item"))
    12.                         local tid = tonumber(result:getDataInt("id"))
    13.                         local count = tonumber(itemr:getDataInt("count"))
    14.                         local tipe = tonumber(itemr:getDataInt("type"))
    15.                         local productn = tostring(itemr:getDataString("name"))
    16.                             if isInArray({5,8},tipe) then
    17.                                 if getPlayerFreeCap(cid) >= getItemWeightById(id, count) then
    18.                                     if isContainer(getPlayerSlotItem(cid, 3).uid) then
    19.                                         doAddContainerItem(getPlayerSlotItem(cid, 3).uid, id, count)
    20.                     if doAddContainerItem then
    21.                                             doPlayerSendTextMessage(cid,19, "You have received >> "..productn.." << from our shop system")
    22.                                             db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
    23.                                         else
    24.                                             doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space on container to receive >> "..productn.." <<")
    25.                                         end
    26.                                     else
    27.                                         doPlayerSendTextMessage(cid,19, "Sorry, you don't have a container to receive >> "..productn.." <<")
    28.                                     end
    29.                                 else
    30.                                     doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
    31.                                 end
    32.                             elseif isInArray({6,7},tipe) then
    33.                                     if tipe == 6 then
    34.                                         bcap = 8
    35.                                         bid = 1987
    36.                                     elseif tipe == 7 then
    37.                                         bcap = 20
    38.                                         bid = 1988
    39.                                     end
    40.                                     if isItemRune(id) then
    41.                                         count = 1
    42.                                     end
    43.                                     if getPlayerFreeCap(cid) >= (getItemWeightById(1987, 1) + getItemWeightById(id,count * bcap)) then
    44.                                         local bag = doCreateItemEx(bid, 1)
    45.                                             for i = 1,bcap do
    46.                                                 doAddContainerItem(bag, id, count)
    47.                                             end
    48.                                         received = doPlayerAddItemEx(getPlayerSlotItem(cid, 3).uid, bag)
    49.                                         if received == RETURNVALUE_NOERROR then
    50.                                             doPlayerSendTextMessage(cid,19, "You have received >> "..productn.." << from our shop system")
    51.                                             db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
    52.                                         else
    53.                                             doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space to receive >> "..productn.." <<")
    54.                                         end
    55.                                     else
    56.                                         doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
    57.                                     end
    58.                             end
    59.                     end
    60.                 itemr:free()
    61.                 if not(result:next()) then
    62.                     break
    63.                 end
    64.             end
    65.             result:free()
    66.         end
    67.     return true
    68. end
    Thanks in advance =)
     
    Last edited: Nov 17, 2011
  3. skey wulf

    skey wulf New Member

    Joined:
    Jun 23, 2009
    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    i execute query sql ERROR ! #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--Use this command to see duplicated items on players inventory or depot items ' at line 22
     
  4. LucasFerraz

    LucasFerraz Systems Analyst

    Joined:
    Jun 10, 2010
    Messages:
    2,856
    Likes Received:
    86
    Best Answers:
    0
    Is it workin' 100%?
     
  5. LucasFerraz

    LucasFerraz Systems Analyst

    Joined:
    Jun 10, 2010
    Messages:
    2,856
    Likes Received:
    86
    Best Answers:
    0
    Bump. Is it working 100%?
     
  6. BeniS

    BeniS Well-Known Member

    Joined:
    Aug 8, 2009
    Messages:
    1,849
    Likes Received:
    182
    Best Answers:
    0
    no its not
     
  7. LucasFerraz

    LucasFerraz Systems Analyst

    Joined:
    Jun 10, 2010
    Messages:
    2,856
    Likes Received:
    86
    Best Answers:
    0
    If I just use

    this:
    Code (Lua):
    1. function generateSerial()
    2.     local strings = "AaBbCcDdEeFfGgHhIiJjKkLlMmOoPpQqRrSsTtUuVvWwXxYyZz"
    3.     local newSerialStr, newSerialInt = "", 0
    4.     local newSerial = ""
    5.     local query, query2, query3
    6.     repeat
    7.         for k = 1, math.random(1, 10) do
    8.             local l = math.random(1, string.len(strings))
    9.             newSerialStr = newSerialStr .. string.sub(strings, l, l)
    10.         end
    11.         newSerialInt = math.random(999999)
    12.         newSerial = newSerialStr .. "-" .. newSerialInt
    13.         query = db.getResult("select * from player_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
    14.         query2 = db.getResult("select * from player_depotitems where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
    15.         query3 = db.getResult("select * from tile_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
    16.     until query:getID() == -1 and query2:getID() == -1 and query3:getID() == -1
    17.     return "!" .. newSerial
    18. end
    and this:
    Code (Lua):
    1. doItemSetAttribute(uid, "serial", generateSerial())
    Will I have problem?



    ----------
     
    Last edited: Feb 16, 2012
  8. Darkhaos

    Darkhaos (:

    Joined:
    Apr 17, 2008
    Messages:
    1,922
    Likes Received:
    170
    Best Answers:
    0
    No, @about conde2's script, the problem with database lost connection occurs when database has a lot of items to check (A LOT OF ITEM, 1000+, 5000+, etc) So, a way to fixt is make the script checks only certain items, like this one: http://code.google.com/p/antidupe/source/browse/trunk/ad.lua
     
  9. LucasFerraz

    LucasFerraz Systems Analyst

    Joined:
    Jun 10, 2010
    Messages:
    2,856
    Likes Received:
    86
    Best Answers:
    0
    Will you release something?
    Clone, today is something that affects many servers
     
  10. Darkhaos

    Darkhaos (:

    Joined:
    Apr 17, 2008
    Messages:
    1,922
    Likes Received:
    170
    Best Answers:
    0
    Something like what?
     
  11. bok

    bok Member

    Joined:
    Apr 28, 2009
    Messages:
    322
    Likes Received:
    4
    Best Answers:
    0
    a new version.Anti-dupe
     
  12. LucasFerraz

    LucasFerraz Systems Analyst

    Joined:
    Jun 10, 2010
    Messages:
    2,856
    Likes Received:
    86
    Best Answers:
    0
    exactly, can some1 release a stable version?
     
  13. LucasFerraz

    LucasFerraz Systems Analyst

    Joined:
    Jun 10, 2010
    Messages:
    2,856
    Likes Received:
    86
    Best Answers:
    0
    I'm trying to do it using trigger/procedure
     
  14. lucas50

    lucas50 New Member

    Joined:
    Oct 5, 2009
    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    @LucasFerraz
    I'm still waiting for you to answer me about the anti-clone script you sold me with problems, not giving to compile, showing some errors. I look forward to returning. thank you


    @Darkhaos
    Where I put this?
    Code (Text):
    1. doItemSetAttribute(uid, "serial", generateSerial())
     
  15. Lightonia

    Lightonia Lightonia.servegame.com

    Joined:
    Jun 4, 2007
    Messages:
    492
    Likes Received:
    9
    Best Answers:
    0
    Can someone tell me how to dismantle this script on mysql? as im fearing that this script is making my server getting massive lag spikes, not sure if that is the reason but im quite suspicious it is.
     
  16. beenii

    beenii Member

    Joined:
    Jul 26, 2010
    Messages:
    365
    Likes Received:
    7
    Best Answers:
    0
    work for sqlite?

    Code (Text):
    1. [09/07/2014 13:04:48] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: near "using": syntax error (select * from player_items where substring(convert(attributes using latin1) from 18) = 'BmTSB-297586')
    2. [09/07/2014 13:04:48] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: near "using": syntax error (select * from player_depotitems where substring(convert(attributes using latin1) from 18) = 'BmTSB-297586')
    3. [09/07/2014 13:04:48] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: near "using": syntax error (select * from tile_items where substring(convert(attributes using latin1) from 18) = 'BmTSB-297586')
     
  17. Szafi

    Szafi www.querana.com

    Joined:
    Mar 2, 2009
    Messages:
    145
    Likes Received:
    6
    Best Answers:
    0
    Sorry for offtop, my MySQL error fix:
    Code (Text):
    1. #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 19
    Code (Text):
    1.  
    2. SELECT*, SUBSTRING(CONVERT( attributes
    3. USING latin1 )FROM18)AS'duplicated serials'FROM player_itemsWHERE SUBSTRING(CONVERT( attributesUSING latin1 )FROM18)IN(
    4.  
    5. SELECT SUBSTRING(CONVERT( attributesUSING latin1 )FROM18)FROM player_depotitemsWHERECONVERT( attributesUSING latin1 )LIKE'%serial%'GROUPBY SUBSTRING(CONVERT( attributesUSING latin1 )FROM18)HAVING COUNT(*)>0
    6. )
     
  18. lucasmourahere

    lucasmourahere Member

    Joined:
    Feb 24, 2016
    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Is it possible to Revert the queries I executed? If so, could you help me?
     
  19. lucasmourahere

    lucasmourahere Member

    Joined:
    Feb 24, 2016
    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    This error is always being told that the id item it has in the photo disappears from the game .. I wanted to find a way to revert and delete the questions that run my database. It's possible?

    [​IMG]
     

Share This Page

Loading...