View Full Version : [Share/Updated] Remove deleted and banned chars from the DB
top-gear
21.05.2006, 16:48
As you know, all deleted chars as long as their skills/items/shortcuts etc are being kept in the database. So the db keeps growing up and lagging more. This is a simple script I just finished to remove that kind of useless data:
declare @var1 varchar(255)
Script_Start:
set @var1 = (select top 1 char_id from lin2world.dbo.user_data where account_id = '-1')
delete from lin2world.dbo.Pledge where ruler_id = @var1
delete from lin2world.dbo.Quest where char_id = @var1
delete from lin2world.dbo.shortcut_data where char_id = @var1
delete from lin2world.dbo.user_Activeskill where char_id = @var1
delete from lin2world.dbo.user_friend where char_id = @var1
delete from lin2world.dbo.user_history where char_id = @var1
delete from lin2world.dbo.user_item where char_id = @var1
delete from lin2world.dbo.user_log where char_id = @var1
delete from lin2world.dbo.user_skill where char_id = @var1
delete from lin2world.dbo.user_data where char_id = @var1
If @var1 IS NULL
PRINT 'Finished'
ELSE
GOTO Script_Start
EDIT:
Second script: That script will change account_id of all characters inside banned accounts to -1. Execute that script and then the first one to remove those characters completeley from the database.
declare @var1 varchar(255)
update lin2db.dbo.user_account set block_flag2 = 1 where block_flag = 1
Script_Start:
set @var1 = (select top 1 account from lin2db.dbo.user_account where block_flag2 = 1)
update lin2world.dbo.user_data set account_id = '-1' where account_name = @var1
update lin2db.dbo.user_account set block_flag2 = 0 where account = @var1
If @var1 IS NULL
PRINT 'Finished'
ELSE
GOTO Script_Start
PS: the banned accounts will remain at the database but empty without chars.
I'm looking forward to finish 1 more script that will delete all banned or empty accounts.
GL
mantrastic
21.05.2006, 17:09
nice :)
top-gear
21.05.2006, 17:42
just added a second script. check the first post
top-gear
Your first script - perfect!
If You can make script, which determinates user logout data and kill all accounts (with chars), what more old, then specified (for instance 30 day or 90 day), this were GRAND BADABOOM!!! 8-)
delete from lin2world.dbo.user_data where char_id in (select char_id from lin2world.dbo.user_data where account_id = '-1') more quicker way, same for other tables
one more way to clear db - take info from user_deleted table
and don't delete warehouse=2 from user_item
top-gear
22.05.2006, 12:19
thank you for the info. warehouse=2 deletion what problems can cause?
gravedemo
22.05.2006, 15:14
clan warehouse - char id = pledge id & warehouse=2
top-gear
22.05.2006, 19:29
clan warehouse - char id = pledge id & warehouse=2
I didn't get it but I suppose there will be a problem to some clan warehouses? Ok I corrected the script
Firedaemon
28.05.2006, 17:40
I have a php script that runs daily durring a automated server maitenance. It removes all accounts which have been inactive for 6 months.
<?php
$con = mssql_connect(bleh,bleh,bleh);
if ($con)
{
$db = mssql_select_db (bleh);
$dTime = date("Y-m-d H:i:s.000", strtotime('-180 days'));
$query = "
SELECT
*
FROM
[user_account]
WHERE
(user_account.last_login < '".$dTime."')
";
$result = mssql_query($query);
$j=0;
while ($row = mssql_fetch_array($result))
{
$user[$j]['account'] = $row['account'];
$user[$j]['uid'] = $row['uid'];
// get the ssn
$query = "
SELECT
ssn
FROM
[user_info]
WHERE
(user_info.account = '".$row['account']."')
";
$ssn = mssql_query($query);
$ssnval = mssql_fetch_assoc($ssn);
$user[$j]['ssn'] = $ssnval['ssn'];
// ssn
$query = "
DELETE FROM
[ssn]
WHERE
(ssn.ssn='".$ssnval['ssn']."')
";
mssql_query($query);
// user_account
$query = "
DELETE FROM
[user_account]
WHERE
(user_account.account='".$row['account']."')
";
mssql_query($query);
// user_account
$query = "
DELETE FROM
[user_auth]
WHERE
(user_auth.account='".$row['account']."')
";
mssql_query($query);
// user_info
$query = "
DELETE FROM
[user_info]
WHERE
(user_info.account='".$row['account']."')
";
mssql_query($query);
// user_time
$query = "
DELETE FROM
[user_time]
WHERE
(user_time.account='".$row['account']."')
";
mssql_query($query);
echo "Deleted Account: ".$row['account']."\r\n";
$j++;
}
$db = mssql_select_db (bleh);
$c=0;
for ($i=0; $i<count($user); $i++)
{
echo "Character Maitenance Starting...\r\n";
// get list of characters
$query = "
SELECT
*
FROM
[user_data]
WHERE
(user_data.account_id=".$user[$i]['uid'].")
";
$result = mssql_query($query);
while ($row = mssql_fetch_array($result))
{
$character[$c] = $row;
echo "\tStarting Maitenance on character ".$row['char_name']."\r\n";
// user_data
$query = "
DELETE FROM
[user_data]
WHERE
(user_data.account_id=".$user[$i]['uid'].")
";
mssql_query($query);
// time_data
$query = "
DELETE FROM
[time_data]
WHERE
(time_data.account_id=".$user[$i]['uid'].")
";
mssql_query($query);
// user_deleted
$query = "
DELETE FROM
[user_deleted]
WHERE
(user_deleted.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_ActiveSkill
$query = "
DELETE FROM
[user_ActiveSkill]
WHERE
(user_ActiveSkill.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_blocklist
$query = "
DELETE FROM
[user_blocklist]
WHERE
(user_blocklist.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_comment
$query = "
DELETE FROM
[user_comment]
WHERE
(user_comment.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_friend
$query = "
DELETE FROM
[user_friend]
WHERE
(user_friend.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_history
$query = "
DELETE FROM
[user_history]
WHERE
(user_history.char_id=".$row['char_id'].")
";
mssql_query($query);
// remove any pets
$query = "
SELECT
*
FROM
[user_item]
WHERE
(user_item.char_id=".$row['char_id'].")
AND
(user_item.warehouse < 2)
";
$item_result = mssql_query($query);
while ($item = mssql_fetch_array($item_result))
{
// user_item
$query = "
DELETE FROM
[pet_data]
WHERE
(pet_data.pet_id=".$item['item_id'].")
";
mssql_query($query);
}
// user_item
$query = "
DELETE FROM
[user_item]
WHERE
(user_item.char_id=".$row['char_id'].")
AND
(user_item.warehouse < 2)
";
mssql_query($query);
// user_punish
$query = "
DELETE FROM
[user_punish]
WHERE
(user_punish.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_skill
$query = "
DELETE FROM
[user_skill]
WHERE
(user_skill.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_surrender
$query = "
DELETE FROM
[user_surrender]
WHERE
(user_surrender.char_id=".$row['char_id'].")
";
mssql_query($query);
// user_warehouse
$query = "
DELETE FROM
[user_warehouse]
WHERE
(user_warehouse.char_id=".$row['char_id'].")
";
mssql_query($query);
// event_items
$query = "
DELETE FROM
[event_items]
WHERE
(event_items.char_id=".$row['char_id'].")
";
mssql_query($query);
// Quest
$query = "
DELETE FROM
[Quest]
WHERE
(Quest.char_id=".$row['char_id'].")
";
mssql_query($query);
// shortcut_data
$query = "
DELETE FROM
[shortcut_data]
WHERE
(shortcut_data.char_id=".$row['char_id'].")
";
mssql_query($query);
// clan & alliance cleanup
$query = "
SELECT
*
FROM
[Pledge]
WHERE
(ruler_id=".$row['char_id'].")
";
$pledge_result = mssql_query($query);
while ($pledge = mssql_fetch_array($pledge_result))
{
// Pledge
$query = "
DELETE FROM
[Pledge]
WHERE
(Pledge.ruler_id=".$row['char_id'].")
";
mssql_query($query);
// Pledge_Crest
$query = "
DELETE FROM
[Pledge_Crest]
WHERE
(Pledge_Crest.crest_id=".$pledge['crest_id'].")
";
mssql_query($query);
// Pledge_War
$query = "
DELETE FROM
[Pledge_War]
WHERE
(Pledge_War.challenger=".$pledge['pledge_id'].") OR
(Pledge_War.challengee=".$pledge['pledge_id'].")
";
mssql_query($query);
// user_item (clan warehouse)
$query = "
DELETE FROM
[user_item]
WHERE
(user_item.char_id=".$pledge['pledge_id'].")
AND
(user_item.warehouse = 2)
";
mssql_query($query);
// get alliance info if it exists
$query = "
SELECT
*
FROM
[Alliance]
WHERE
(Alliance.master_pledge_id=".$pledge['pledge_id'].")
";
$alliance_result = mssql_query($query);
$alliance = mssql_fetch_assoc($alliance_result);
if ($alliance['id'])
{
// Alliance
$query = "
DELETE FROM
[Alliance]
WHERE
(Alliance.master_pledge_id=".$pledge['pledge_id'].")
";
mssql_query($query);
$query = "
UPDATE
[Pledge]
SET
Pledge.alliance_id=0
WHERE
(Pledge.alliance_id=".$alliance['id'].")
";
mssql_query($query);
}
// user_data
$query = "
UPDATE
[user_data]
SET
user_data.pledge_id=0
WHERE
(user_data.pledge_id=".$pledge['pledge_id'].")
";
mssql_query($query);
}
echo "\t Character maitenance finished for character ".$row['char_name']."\r\n";
$c++;
}
}
}
$logdata = print_r($user, true).print_r($character, true);
file_put_contents("lineage_account_maitenance-".time().".log", $logdata);
?>
top-gear
29.05.2006, 11:32
Thank you! very useful script!
// user_item (clan warehouse)
$query = "
DELETE FROM
[user_item]
WHERE
(user_item.char_id=".$pledge['pledge_id'].")
AND
(user_item.warehouse = 2)
";
mssql_query($query);
That one will cause problems to other clan wh's or not?
mantrastic
29.05.2006, 11:44
wow nice firedaemon
Looks very nice, dear FireDeamon. :)
R U can make full-ability-prepared-for-leachers share? ;)
Because your "bleh,bleh,bleh" confused to me. :D
Why don't you go to www.php.net and use search for function and see params it require? :)