Doggynub
LUA / C++
- Joined
- Sep 28, 2008
- Messages
- 2,541
- Reaction score
- 186
Advanced Auto-DB Clean:
* Features :
1- Ability to Delete accounts on a time of inactive (deleting acc empty of players).
2- Ability to delete inactive players.
3- Ability to delete all players data when they are deleted.
4- prevent to delte players who havnt logged yet, or their lastlog not yet created.
5- prevent of deleting of Toutor's +, and acc manager and samples.
6- Ability to write logs in external file to show character deleted with names and the account deleted ,time indicated.
7- Ability to write on console how much player and acc deleted on this startup.
*When it works :
This will work on server start, it will delete players first who are inactive, if all players from an account was deleted then after that the clean account empty of players will start working till it clean db from them.
* Now lets install it :
Goto globalevent --> globalevent.xml :
Now go into globalEvent--> scripts --> make new file "db.lua" paste
P.S:
Please make sure to make a backup of db before using , just incase somehtng happened.
Regards,
Doggynub
* Features :
1- Ability to Delete accounts on a time of inactive (deleting acc empty of players).
2- Ability to delete inactive players.
3- Ability to delete all players data when they are deleted.
4- prevent to delte players who havnt logged yet, or their lastlog not yet created.
5- prevent of deleting of Toutor's +, and acc manager and samples.
6- Ability to write logs in external file to show character deleted with names and the account deleted ,time indicated.
7- Ability to write on console how much player and acc deleted on this startup.
*When it works :
This will work on server start, it will delete players first who are inactive, if all players from an account was deleted then after that the clean account empty of players will start working till it clean db from them.
* Now lets install it :
Goto globalevent --> globalevent.xml :
XML:
<globalevent name="db" type="startup" event="script" value="db.lua"/>
Now go into globalEvent--> scripts --> make new file "db.lua" paste
Lua:
--[[ Advanced Auto-DB Clean By >>Doggynub<< ]]--
--[[ tiny little part from : Automated Database Cleanup 1.1 //By Cybermaster ]]--
-- [[ credits for a better loop through database get result to :SpiderOt ]] --
local c = {
accounts = true , -- delete accounts that doenst contain players(same as deleting acc after the time down, as on deleting players that been inactive account will be emty so account will be deleted)
players = true, -- delete players who are inactive?(this must be enabled)
time = 45, -- in days
remove_all = true, -- remove all players data from data baase whe he is deleted?
log_File = true, -- make a log file state amount of player cleaned in every clean with their names?
print_console = true -- print amount of player and accounts deleted on each start up
}
local players = {}
local names = {}
function cleanPlayers()
local Info = db.getResult("SELECT players.id AS id , players.name AS name FROM players WHERE players.name NOT IN ('Account Manager','Druid Sample','Knight Sample','Paladin Sample','Sorcerer Sample') AND group_id < 2 AND lastlogin > 0 AND lastlogin < UNIX_TIMESTAMP() - '".. (c.time*24*60*60) .."' ;")
if (Info:getID() ~= -1) then
while true do
table.insert(players, Info:getDataInt("id"))
table.insert(names, Info:getDataString("name"))
if not Info:next() then
break
end
end
Info:free()
end
if #players > 0 then
db.executeQuery("DELETE FROM players WHERE players.id IN ("..table.concat(players,",")..") ;")
if c.remove_all == true then
db.executeQuery("DELETE FROM player_skills WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_items WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_depotitems WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_deaths WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_storage WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_killers WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_namelocks WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_spells WHERE player_id IN ("..table.concat(players,",")..") ;")
db.executeQuery("DELETE FROM player_viplist WHERE player_id IN ("..table.concat(players,",")..") ;")
end
if c.print_console == true then
print(">> [DB] : "..#players.." players have been removed for not loggin for long time.")
end
if c.log_File == true then
doWriteLogFile("data/logs/Database clean.txt"," : "..#players.." players cleaned --> (".. table.concat(names,", ")..") \n\n ")
end
end
end
local accounts = {}
function cleanDBAcc()
function getDB()
local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `accounts`;")
local tmp = result:getDataInt("count")
result:free()
return tmp
end
local before = getDB()
local Info = db.getResult("SELECT accounts.id AS `id` FROM accounts INNER JOIN players ON accounts.id = players.account_id ;")
if (Info:getID() ~= -1) then
while true do
table.insert(accounts, Info:getDataInt("id"))
if not Info:next() then
break
end
end
Info:free()
end
db.executeQuery("DELETE FROM accounts WHERE accounts.id NOT IN("..table.concat(accounts,",")..");")
local new = before - getDB()
if c.print_console == true then
if new > 0 then
if c.print_console == true then
print("\n>>>>[DB] : "..new.." Accounts were deleted\n")
end
if c.log_File == true then
doWriteLogFile("data/logs/Database clean.txt"," : "..new.." accounts cleaned \n\n ")
end
end
end
return true
end
function onStartup()
cleanPlayers()
if c.accounts == true then
cleanDBAcc()
end
return true
end
P.S:
Please make sure to make a backup of db before using , just incase somehtng happened.
Regards,
Doggynub
Last edited: