Metin2 dupe detection with SQL and logs
A dupe usually shows up in your numbers, not as an error message. The queries below check Yang and items, and the end covers what to do once you actually find something.
The queries below use the usual names: a player database with the tables player and item, and Yang in the gold column. If yours differ, SHOW TABLES; and DESCRIBE item; will tell you. What you see in MySQL lags a few minutes behind the game, because the db core keeps characters and items in memory and writes them later. For these checks that doesn't matter.
A lot of Metin2 databases use MyISAM, where a long query on item can block writes while the db core waits. We'd run the heavy ones at night or on a copy restored from a backup.
How you notice a dupe
Almost every dupe comes from a bug in the source, in some system added later (offline shops especially) or in a quest. Or a core crashes at the wrong moment, more on that below. How specific dupes work is left out on purpose.
You rarely notice one through a single report. It shows in the numbers. On a normal server total Yang grows fairly steadily: monsters drop Yang and players sell to NPCs, while NPC shops, the blacksmith and other costs take Yang back out. If the total jumps by several times the usual daily amount on an ordinary day with no event running, take a closer look.
Prices tell you a lot too. When an item gets duped, its price drops because suddenly lots of them are for sale. When Yang gets duped, everything priced in Yang goes up because Yang is worth less. Players usually notice before you do.
Other things that stand out:
- A character nobody noticed yesterday shows up in the top 10 with a few hundred million Yang.
- Low level characters with huge amounts of Yang. Those are often mules where duped goods get parked.
- A weapon that only one boss drops exists far more often than that boss could have died in that time.
- Several items with the exact same five random bonuses. That practically never happens naturally.
- The same core crashes several times in a short period. Someone may be triggering rollbacks on purpose.
- Players report on Discord or in tickets that someone sells Yang for real money at suspiciously low prices.
A GM creating Yang or items for friends isn't a bug, but in the numbers it looks exactly like a dupe. The queries below catch that too.
Checking Yang
First look: total Yang and the top 10.
New names in the top 10 and characters sitting exactly at the Yang cap are the first ones worth checking.
Mules, low level characters with a lot of Yang. Adjust the limits to your server:
To leave out your own GM characters, add AND name NOT IN (SELECT mName FROM common.gmlist), if the column has that name in your files.
Checking items
A full count per vnum doesn't tell you much. The handful of items that are rare and expensive on your server tell you more. Fill in their vnums:
For weapons and armor the last digit of the vnum is usually the upgrade level, so +0 to +9 are ten vnums. To count all levels together, group by FLOOR(vnum / 10).
The check we'd trust most is identical bonuses. This query looks for items with five bonuses where the vnum and every bonus match:
Not every hit is a dupe. Item shop items or quest rewards with fixed bonuses are meant to be identical. With randomly rolled bonuses, though, a hit is a strong sign. To see who has the copies, reuse the same conditions in a SELECT id, owner_id, window FROM item WHERE ....
Two items in the same slot should not exist at all. A hit is either left over from a bug or a dupe:
Careful when reading it: for the storeroom and the item shop storage, owner_id holds the account ID in most files, not the character ID.
Stacks above the limit:
200 is the usual stack limit. If your source sets ITEM_MAX_COUNT to something else, use that.
Looking for duplicate item IDs in item won't find anything. In the usual files id is the primary key there, so the same ID twice can't happen. A dupe creates new items with new IDs. SHOW CREATE TABLE item; shows how it is on your server. It only gets interesting if your files keep items in a second table too, for an offline shop for example. Then check whether the same ID shows up in both. The table and column names here are only an example:
A daily snapshot
Everything above only shows today. You only see whether today is unusual when you compare it with the days before. For that we'd set up a small separate database, apart from the game data, and save the key numbers once a day:
Plus its own database user that can only read the game data:
The snapshot queries go into /root/snapshot.sql. REPLACE means a second run on the same day overwrites the row instead of failing. Per character only balances above one million Yang are stored, so the table stays small:
The credentials go into /root/.my-economy.cnf, protected with chmod 600:
Then add a line with crontab -e. Cron runs with a minimal search path and on FreeBSD /usr/local/bin isn't part of it, so the line has the full path to mysql. Pick a time that doesn't clash with your backup.
On FreeBSD:
On Linux:
After a few days you can compare. Total Yang day to day:
And which characters gained the most Yang since yesterday:
When reading the numbers: trading only moves Yang around, it doesn't create any. If one character gains a lot and another loses about the same, that was most likely a trade. If the server total goes up with it, the Yang is new. Give it a few weeks so you know what normal looks like on your server, and note down your events. A drop event or a new dungeon explains a lot of jumps.
The log database
Most files write to a separate log database next to player, usually called log. You find out which one in the CONFIG of your cores, often on the LOG_SQL line. What ends up in there varies a lot between files, so start with an overview:
In many files who is the character ID, what the item ID for item events and how what happened, plus the time, the vnum and more details. Trades, NPC shops and storage show up in how through parts like EXCHANGE, SHOP or SAFEBOX. There are often also loginlog for logins, command_log for GM commands, refinelog for the blacksmith and a table for Yang such as money_log. DESCRIBE shows you the columns.
To follow one item, use its ID from the item table:
Everything one character did in a time window:
And the latest GM commands, which belong in every check where Yang or items might have come from a GM account:
We'd keep the number of accounts that can create items small and look at command_log regularly. More on that in the guide on how to secure a Metin2 server.
Log tables grow fast, and without an index on who and what these queries are slow. ALTER TABLE log ADD INDEX (what); adds one, but on a large MyISAM table only during maintenance, since the table is locked while the index is built.
We'd never switch logging off to save space, because then there is nothing left to trace. Delete old entries after a fixed period instead. The logs contain IP addresses, so a fixed retention period also helps with privacy rules such as the GDPR.
Dupes from crashes
This one is easy to miss. The game core keeps every character that is currently playing in memory and sends their state to the db core at intervals and on occasions like logging out or moving to another core. The db core caches the data too and writes it to MySQL with a delay. Depending on your files, those intervals are fixed in the source or set in the db core configuration.
When a game core crashes, the characters on it go back to their last save. Annoying, but not a dupe yet. It becomes one when two characters took part in a transfer and only one of them was saved afterwards. Character A gives B Yang in a trade, B logs out right away and gets saved, A hasn't been saved yet, and the core crashes. A comes back with the old state, Yang included, and B keeps the Yang too. Whether your files save both sides right after a trade depends on the source. Something similar happens when the db core crashes before writing its cache: many characters roll back, but not all to the same point in time.
So every crash a player can trigger on purpose is also a possible dupe. The guide on syserr and crash analysis shows how to find the cause in syserr and in the core dump. After a crash, check who traded in the minutes before, if your files log trades:
Then compare total Yang before and after. If your cores crash often, an hourly snapshot helps: a time DATETIME column instead of day DATE and a cron line starting with 0 * * * *. If the same characters or accounts show up around several crashes, that's not a coincidence.
When you find a dupe
Don't change anything yet. Export the affected rows and log entries first, write down the times and take screenshots of whatever got reported on Discord. For items in the storeroom and the item shop storage, add the account IDs to the list:
Keep that day's backup as well, so you can compare states later.
Then block the accounts of the suspects and their mules so nothing moves on. In most files the state of an account is in the status column of the account table, and BLOCK locks it. The first line gets you the account IDs for the characters:
The block takes effect on the next login. If a character is online right now, disconnect it as a GM, in many sources with /dc name.
With the log queries above you can work out when the dupe started, who is involved and where the goods went. Follow every item ID and every large Yang transfer. Several accounts often belong together, for example through the same IP address at login, as far as your files store it. The entries just before the first appearance usually show the method too: a trade, a shop, storage or a crash.
Clean up only what was duped instead of rolling back the whole server. A full rollback hits every honest player, and we'd only do one if the dupe can't be narrowed down anymore. The Metin2 server backup guide explains how to restore one.
Important: only edit player and item while the affected characters are offline and blocked, ideally during maintenance with the cores stopped. The db core keeps data in memory and will otherwise overwrite your change with its own copy.
If honest players bought duped goods, decide how you handle that before you start and say so openly. Otherwise the cleanup hits the wrong people.
A ban alone fixes nothing, the next player uses the same bug. Reproduce it on your test server, fix it in the source or the quest and deploy the fix. Until then switch the affected system off if your files allow it, an offline shop for example. If you can't find the bug in the source yourself, you can ask us to find it as custom work at a fixed price.
Tell your players what happened, what you did and whether honest players are affected. Keep it short and factual, and don't explain how the dupe worked, or the next person tries a variation of it.
Dupe alerts with Servergilde
With Servergilde the daily server check and crash alerts for your cores are free. On the Pro plan (19.99 euros per month, see pricing) the agent sends economy figures once an hour: Yang in circulation, the ten richest characters and rare items per vnum compared with the day before. If Yang jumps or a duplicate item shows up, you get an alert on Discord, but nobody gets banned by it.
Frequently asked questions
Can a server crash cause a dupe?
How do I tell duped Yang from traded Yang?
Does a dupe create duplicate item IDs?
item table, where id is the primary key in the usual files. A dupe creates new items with new IDs. You find duped items more easily through identical random bonuses.How do I ban an account with SQL?
UPDATE account.account SET status = 'BLOCK' WHERE id IN (101, 202);. The block takes effect on the next login. If the character is online, disconnect it as a GM, in many sources with /dc name.