Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 21.05.2006, 16:48   #1
top-gear
Архивный участник
 
Join Date: Aug 2005
Posts: 605
Default [Share/Updated] Remove deleted and banned chars from the DB

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:

Code:
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.

Code:
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
top-gear is offline  
Old 21.05.2006, 17:09   #2
mantrastic
Архивный участник
 
Join Date: Apr 2006
Posts: 338
Default

nice
mantrastic is offline  
Old 21.05.2006, 17:42   #3
top-gear
Архивный участник
 
Join Date: Aug 2005
Posts: 605
Default

just added a second script. check the first post
top-gear is offline  
Old 22.05.2006, 06:10   #4
2Rain
Архивный участник
 
Join Date: Aug 2005
Posts: 194
Default

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-)
2Rain is offline  
Old 22.05.2006, 08:12   #5
hr
Архивный участник
 
Join Date: Jun 2005
Posts: 285
Default

Code:
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
hr is offline  
Old 22.05.2006, 12:19   #6
top-gear
Архивный участник
 
Join Date: Aug 2005
Posts: 605
Default

thank you for the info. warehouse=2 deletion what problems can cause?
top-gear is offline  
Old 22.05.2006, 15:14   #7
gravedemo
Архивный участник
 
Join Date: Feb 2006
Posts: 13
Default

clan warehouse - char id = pledge id & warehouse=2
gravedemo is offline  
Old 22.05.2006, 19:29   #8
top-gear
Архивный участник
 
Join Date: Aug 2005
Posts: 605
Default

Quote:
Originally Posted by gravedemo
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
top-gear is offline  
Old 28.05.2006, 17:40   #9
Firedaemon
Архивный участник
 
Join Date: Oct 2005
Posts: 267
Default

I have a php script that runs daily durring a automated server maitenance. It removes all accounts which have been inactive for 6 months.

Code:
<?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);
      
?>
Firedaemon is offline  
Old 29.05.2006, 11:32   #10
top-gear
Архивный участник
 
Join Date: Aug 2005
Posts: 605
Default

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?
top-gear is offline  
Old 29.05.2006, 11:44   #11
mantrastic
Архивный участник
 
Join Date: Apr 2006
Posts: 338
Default

wow nice firedaemon
mantrastic is offline  
Old 29.05.2006, 16:18   #12
2Rain
Архивный участник
 
Join Date: Aug 2005
Posts: 194
Default

Looks very nice, dear FireDeamon.
R U can make full-ability-prepared-for-leachers share?
Because your "bleh,bleh,bleh" confused to me.
2Rain is offline  
Old 29.05.2006, 17:00   #13
ateh
Архивный участник
 
Join Date: Apr 2006
Posts: 118
Default

Why don't you go to www.php.net and use search for function and see params it require?
ateh is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 20:23.