JH
action

Preciso de script que delete player apos 3 dias sem logar

Por jhowzikah, 21 de mar. de 2013 em Scripts

logar
script
apagar
player
database
resolvido
19
2.1k
jhowzikahJ
21 de março de 2013 às 17:27

gente preciso de um script que se o player nao logar no ot em 3 dias automaticamente exclua esse player da database.

 

 

NAO SEI SE ESSA É O LOCAL CERTO O POST!

SE NAO FOR POR FAVOR MOVA PARA O LOCAL CORRETO

AlexclusiveA
21 de março de 2013 às 17:35

Talvez isso seja util..

 

Executa isso na sua Database :

 

Deletar players inativos, level baiaxo de 50, 20 days Inativo. Recomendo voce fazer um backup do seu banco de dados antes desta ação.

 

DELETE FROM players WHERE level < 50 AND lastlogin < UNIX_TIMESTAMP() - 20*24*60*60

 

Azul = Level

Verde = Dias

 

Vlw

Editado Março 21 por Alexclusive

RoksasR
21 de março de 2013 às 17:35

data/globalevents/scripts, crie um arquivo chamado deleteplayers.lua e ponah isso dentro:

 

 

function onTime()

db.executeQuery(DELETE FROM players WHERE lastlogin < UNIX_TIMESTAMP() - 3*24*60*60)

return true

end

 

 

Globalevents.xml adicione essa tag:

 

    <globalevent name="deleteall" time="18:00" event="script" value="deleteplayers.lua"/>

 

Ali aonde está 18:00 é só por o horário do dia que vai deletá-los, pus 18:00 pra tu testa agora :)

Editado Março 21 por Roksas

ThiagoBjiT
21 de março de 2013 às 17:38

Vá em Pasta do seu OT -> data -> globalevents -> globalevents.xml:

 

 

<globalevent name="dbcleaner" type="startup" event="script" value="dbcleaner.lua"/>

 

 

Agora, vá em Pasta do seu OT -> data -> globalevents -> scripts -> dbcleaner.lua:

 

 

------------------------------------------------------------------------------*

----- [[> Automated Database Cleanup 1.1 Structure //By Cybermaster <]] ------|

-------------- [[> System 2.0 Revamped by Teh Maverick <3 <]] ----------------|

------------- [[> Removal of empty accounts by darkaos :) <]] ---------------|

--------------- [[> Function getDBPlayersCount() by Elf <]] ------------------|

------------------------------------------------------------------------------|

------------------------------------------------------------------------------|

--- ~!READ THIS!~ ------------------------------------------------------------|

--- Be sure to back up your database and test this on your server first, -----|

--- I(Teh Maverick) cannot guarantee it will work the same for every core. ---|

--- It is very easy to test, with the log file and values that are printed ---|

-----------------------------------Enjoy!-------------------------------------|

------------------------------------------------------------------------------*

function countRowsWhereInTable(table, field, condition)

local result = db.getResult("SELECT COUNT(" .. field .. ") as count FROM " .. table .. " WHERE " .. field .. " = '" .. condition .. "';")

local tmp = result:getDataInt("count")

result:free()

return tmp

end

function getDBPlayersCount()

local result = db.getResult("SELECT COUNT(id) as count FROM `players`;")

local tmp = result:getDataInt("count")

result:free()

return tmp

end

function getDBAccountsCount()

local result = db.getResult("SELECT COUNT(id) as count FROM `accounts`;")

local tmp = result:getDataInt("count")

result:free()

return tmp

end

function onStartup()

local DB_BEFORE = {players = getDBPlayersCount(), accounts = getDBAccountsCount()}

local result,result1, ii, numPlayersToDelete, numAccountsDeleted, tmp = 0, 0, 0, 0, 0

local pid, aid = {}, {}

local dropCount = {players={},accounts={}}

local config = {

deleteAccountWithNoPlayers = true,

cleanChildTables = true,

printResult = true,

saveResultToFile = true,

logFileName = 'db_cleanup.txt'

}

--In each table, players with below specified level, and days of inactivity will be deleted from db on server startup

local cleanup = {

[1] = {level = 11, time = 5 * 24 * 60 * 60},

[2] = {level = 20, time = 15 * 24 * 60 * 60},

[3] = {level = 50, time = 30 * 24 * 60 * 60},

[4] = {level = 100, time = 60 * 24 * 60 * 60},

[5] = {level = 130, time = 90 * 24 * 60 * 60}

}

local childAttributeTables = {

players = {

[1] = {table = "`player_viplist`", idField = "`player_id`"},

[2] = {table = "`player_storage`", idField = "`player_id`"},

[3] = {table = "`player_spells`", idField = "`player_id`"},

[4] = {table = "`player_skills`", idField = "`player_id`"},

[5] = {table = "`player_namelocks`", idField = "`player_id`"},

[6] = {table = "`player_items`", idField = "`player_id`"},

[7] = {table = "`player_depotitems`", idField = "`player_id`"},

[8] = {table = "`houses`", idField = "`owner`"},

[9] = {table = "`house_auctions`", idField = "`player_id`"},

[10] = {table = "`players`", idField = "`id`"} -- Keep this as the last item in the array

--Note: `houses` and `bans` are in the DB triggers for TFS so don't worry about them.

--Also I did not want to put killers, or deaths on here because that is historic data,

--do so at your own risk.

},

accounts = {

[1] = {table = "`accounts`", idField = "`id`"},

[2] = {table = "`account_viplist`", idField = "`account_id`"}

}

}

--Clean up all the players and player data

for i = 1, #cleanup do

result = db.getResult("SELECT `id`,`name`,`account_id` FROM `players` WHERE `level` < ".. cleanup.level .." AND `name` NOT IN('Account Manager', 'Sorcerer Sample', 'Druid Sample', 'Paladin Sample', 'Knight Sample', 'Rook Sample') AND `group_id` < 2 AND `lastlogin` < UNIX_TIMESTAMP() - ".. cleanup.time ..";")

if(result:getID() ~= -1) then

ii = 1

repeat

pid[ii] = result:getDataInt("id") -- list the players id into an array

aid[ii] = result:getDataInt("account_id") -- list the account id of each player being removed into an array

ii = ii + 1

until not(result:next())

result:free()

end

numPlayersToDelete = ii - 1

--Drop players and their child table attribute data such as skills, items, etc.

for j = 1, numPlayersToDelete do

if(config.cleanChildTables) then

for k = 1, #childAttributeTables.players do

if childAttributeTables.players[k].table == "houses" then

house = getHouseByPlayerGUID(pid[j])

if house ~= 0 or house ~= nil then

doCleanHouse(house)

doUpdateHouseAuctions()

end

else

dropCount.players[k] = ((dropCount.players[k] or 0) + countRowsWhereInTable(childAttributeTables.players[k].table, childAttributeTables.players[k].idField, pid[j]))

db.executeQuery("DELETE FROM " .. childAttributeTables.players[k].table .. " WHERE " .. childAttributeTables.players[k].idField .. " = '" .. pid[j] .. "';")

end

end

else

db.executeQuery("DELETE FROM `players` WHERE `id` = '" .. pid[j] .. "';")

end

end

end

--Drop all the accounts that have 0 players linked to them (at the moment its only checking from the list of players removed)

if config.deleteAccountWithNoPlayers then

--This part was scripted by Darkhaos, modified/fixed by Teh Maverick --[[

for acc = 1, #aid do

result1 = db.getResult("SELECT `id` FROM `accounts` WHERE `id` = '" .. aid[acc] .. "';")

if result1:getID() ~= -1 then -- check to make sure the account exists

result1:free()

for i = 1, #childAttributeTables.accounts do

--Make sure there are no other players on the account

result1 = db.getResult("SELECT COUNT(id) as count FROM `players` WHERE `account_id` = '" .. aid[acc] .. "';")

tmp = result1:getDataInt("count")

if(tmp <= 0) then

--Remove accounts

dropCount.accounts = ((dropCount.accounts or 0) + countRowsWhereInTable(childAttributeTables.accounts.table, childAttributeTables.accounts.idField, aid[acc]))

db.executeQuery("DELETE FROM " .. childAttributeTables.accounts.table .. " WHERE " .. childAttributeTables.accounts.idField .. " = '" .. aid[acc] .. "';")

end

end

end

end

end

--]]

--Print and Save results (configurable)

local DB_NOW = {players = DB_BEFORE.players - getDBPlayersCount(), accounts = DB_BEFORE.accounts - getDBAccountsCount()}

if DB_NOW.players > 0 or DB_NOW.accounts > 0 then

local text = ">> [DBCLEANUP] " .. DB_NOW.players .. " inactive players" .. (config.deleteAccountWithNoPlayers and " and " .. DB_NOW.accounts .. " empty accounts" or "") .. " have been deleted from the database."

--Write to console

if config.printResult then

print("")

print(text)

if config.cleanChildTables then

--Write player info

for i = 1,#dropCount.players do

print("[!] --> Dropped: " .. dropCount.players .. " from " .. childAttributeTables.players.table .. " table")

end

--Write account info

if config.deleteAccountWithNoPlayers then

for i = 1,#dropCount.accounts do

print("[!] --> Dropped: " .. dropCount.accounts .. " from " .. childAttributeTables.accounts.table .. " table")

end

end

print("")

end

end

--Write to file

if config.saveResultToFile then

local file = io.open("data/logs/"..config.logFileName, "a")

file:write("[" .. os.date("%d %B %Y %X ", os.time()) .. "] " .. text .. "\n")

if config.cleanChildTables then

--Write player info

for i = 1, #dropCount.players do

file:write("[!] --> Dropped: " .. dropCount.players .. " from " .. childAttributeTables.players.table .. " table\n")

end

--Write account info

if config.deleteAccountWithNoPlayers then

for i = 1, #dropCount.accounts do

file:write("[!] --> Dropped: " .. dropCount.accounts .. " from " .. childAttributeTables.accounts.table .. " table\n")

end

end

file:write("\n")

end

file:close()

end

end

return true

end

 

 

Não se esqueça de editar o script, nessa parte:

 

 

[1] = {level = 11, time = 5 * 24 * 60 * 60},

[2] = {level = 20, time = 15 * 24 * 60 * 60},

[3] = {level = 50, time = 30 * 24 * 60 * 60},

[4] = {level = 100, time = 60 * 24 * 60 * 60},

[5] = {level = 130, time = 90 * 24 * 60 * 60}

 

 

Os leveis dos players e os dias pra ser deletado se não logar.

Editado Março 21 por ThiagoBjiW

jhowzikahJ
21 de março de 2013 às 17:41

qualquer jeito, com tanto qu delete *_*

 

Vá em Pasta do seu OT -> data -> globalevents -> globalevents.xml:

 

<globalevent name="dbcleaner" type="startup" event="script" value="dbcleaner.lua"/>

 

Agora, vá em Pasta do seu OT -> data -> globalevents -> scripts -> dbcleaner.lua:

 

 

------------------------------------------------------------------------------*

----- [[> Automated Database Cleanup 1.1 Structure //By Cybermaster <]] ------|

-------------- [[> System 2.0 Revamped by Teh Maverick <3 <]] ----------------|

------------- [[> Removal of empty accounts by darkaos :) <]] ---------------|

--------------- [[> Function getDBPlayersCount() by Elf <]] ------------------|

------------------------------------------------------------------------------|

------------------------------------------------------------------------------|

--- ~!READ THIS!~ ------------------------------------------------------------|

--- Be sure to back up your database and test this on your server first, -----|

--- I(Teh Maverick) cannot guarantee it will work the same for every core. ---|

--- It is very easy to test, with the log file and values that are printed ---|

-----------------------------------Enjoy!-------------------------------------|

------------------------------------------------------------------------------*

function countRowsWhereInTable(table, field, condition)

local result = db.getResult("SELECT COUNT(" .. field .. ") as count FROM " .. table .. " WHERE " .. field .. " = '" .. condition .. "';")

local tmp = result:getDataInt("count")

result:free()

return tmp

end

function getDBPlayersCount()

local result = db.getResult("SELECT COUNT(id) as count FROM `players`;")

local tmp = result:getDataInt("count")

result:free()

return tmp

end

function getDBAccountsCount()

local result = db.getResult("SELECT COUNT(id) as count FROM `accounts`;")

local tmp = result:getDataInt("count")

result:free()

return tmp

end

function onStartup()

local DB_BEFORE = {players = getDBPlayersCount(), accounts = getDBAccountsCount()}

local result,result1, ii, numPlayersToDelete, numAccountsDeleted, tmp = 0, 0, 0, 0, 0

local pid, aid = {}, {}

local dropCount = {players={},accounts={}}

local config = {

deleteAccountWithNoPlayers = true,

cleanChildTables = true,

printResult = true,

saveResultToFile = true,

logFileName = 'db_cleanup.txt'

}

--In each table, players with below specified level, and days of inactivity will be deleted from db on server startup

local cleanup = {

[1] = {level = 11, time = 5 * 24 * 60 * 60},

[2] = {level = 20, time = 15 * 24 * 60 * 60},

[3] = {level = 50, time = 30 * 24 * 60 * 60},

[4] = {level = 100, time = 60 * 24 * 60 * 60},

[5] = {level = 130, time = 90 * 24 * 60 * 60}

}

local childAttributeTables = {

players = {

[1] = {table = "`player_viplist`", idField = "`player_id`"},

[2] = {table = "`player_storage`", idField = "`player_id`"},

[3] = {table = "`player_spells`", idField = "`player_id`"},

[4] = {table = "`player_skills`", idField = "`player_id`"},

[5] = {table = "`player_namelocks`", idField = "`player_id`"},

[6] = {table = "`player_items`", idField = "`player_id`"},

[7] = {table = "`player_depotitems`", idField = "`player_id`"},

[8] = {table = "`houses`", idField = "`owner`"},

[9] = {table = "`house_auctions`", idField = "`player_id`"},

[10] = {table = "`players`", idField = "`id`"} -- Keep this as the last item in the array

--Note: `houses` and `bans` are in the DB triggers for TFS so don't worry about them.

--Also I did not want to put killers, or deaths on here because that is historic data,

--do so at your own risk.

},

accounts = {

[1] = {table = "`accounts`", idField = "`id`"},

[2] = {table = "`account_viplist`", idField = "`account_id`"}

}

}

--Clean up all the players and player data

for i = 1, #cleanup do

result = db.getResult("SELECT `id`,`name`,`account_id` FROM `players` WHERE `level` < ".. cleanup.level .." AND `name` NOT IN('Account Manager', 'Sorcerer Sample', 'Druid Sample', 'Paladin Sample', 'Knight Sample', 'Rook Sample') AND `group_id` < 2 AND `lastlogin` < UNIX_TIMESTAMP() - ".. cleanup.time ..";")

if(result:getID() ~= -1) then

ii = 1

repeat

pid[ii] = result:getDataInt("id") -- list the players id into an array

aid[ii] = result:getDataInt("account_id") -- list the account id of each player being removed into an array

ii = ii + 1

until not(result:next())

result:free()

end

numPlayersToDelete = ii - 1

--Drop players and their child table attribute data such as skills, items, etc.

for j = 1, numPlayersToDelete do

if(config.cleanChildTables) then

for k = 1, #childAttributeTables.players do

if childAttributeTables.players[k].table == "houses" then

house = getHouseByPlayerGUID(pid[j])

if house ~= 0 or house ~= nil then

doCleanHouse(house)

doUpdateHouseAuctions()

end

else

dropCount.players[k] = ((dropCount.players[k] or 0) + countRowsWhereInTable(childAttributeTables.players[k].table, childAttributeTables.players[k].idField, pid[j]))

db.executeQuery("DELETE FROM " .. childAttributeTables.players[k].table .. " WHERE " .. childAttributeTables.players[k].idField .. " = '" .. pid[j] .. "';")

end

end

else

db.executeQuery("DELETE FROM `players` WHERE `id` = '" .. pid[j] .. "';")

end

end

end

--Drop all the accounts that have 0 players linked to them (at the moment its only checking from the list of players removed)

if config.deleteAccountWithNoPlayers then

--This part was scripted by Darkhaos, modified/fixed by Teh Maverick --[[

for acc = 1, #aid do

result1 = db.getResult("SELECT `id` FROM `accounts` WHERE `id` = '" .. aid[acc] .. "';")

if result1:getID() ~= -1 then -- check to make sure the account exists

result1:free()

for i = 1, #childAttributeTables.accounts do

--Make sure there are no other players on the account

result1 = db.getResult("SELECT COUNT(id) as count FROM `players` WHERE `account_id` = '" .. aid[acc] .. "';")

tmp = result1:getDataInt("count")

if(tmp <= 0) then

--Remove accounts

dropCount.accounts = ((dropCount.accounts or 0) + countRowsWhereInTable(childAttributeTables.accounts.table, childAttributeTables.accounts.idField, aid[acc]))

db.executeQuery("DELETE FROM " .. childAttributeTables.accounts.table .. " WHERE " .. childAttributeTables.accounts.idField .. " = '" .. aid[acc] .. "';")

end

end

end

end

end

--]]

--Print and Save results (configurable)

local DB_NOW = {players = DB_BEFORE.players - getDBPlayersCount(), accounts = DB_BEFORE.accounts - getDBAccountsCount()}

if DB_NOW.players > 0 or DB_NOW.accounts > 0 then

local text = ">> [DBCLEANUP] " .. DB_NOW.players .. " inactive players" .. (config.deleteAccountWithNoPlayers and " and " .. DB_NOW.accounts .. " empty accounts" or "") .. " have been deleted from the database."

--Write to console

if config.printResult then

print("")

print(text)

if config.cleanChildTables then

--Write player info

for i = 1,#dropCount.players do

print("[!] --> Dropped: " .. dropCount.players .. " from " .. childAttributeTables.players.table .. " table")

end

--Write account info

if config.deleteAccountWithNoPlayers then

for i = 1,#dropCount.accounts do

print("[!] --> Dropped: " .. dropCount.accounts .. " from " .. childAttributeTables.accounts.table .. " table")

end

end

print("")

end

end

--Write to file

if config.saveResultToFile then

local file = io.open("data/logs/"..config.logFileName, "a")

file:write("[" .. os.date("%d %B %Y %X ", os.time()) .. "] " .. text .. "\n")

if config.cleanChildTables then

--Write player info

for i = 1, #dropCount.players do

file:write("[!] --> Dropped: " .. dropCount.players .. " from " .. childAttributeTables.players.table .. " table\n")

end

--Write account info

if config.deleteAccountWithNoPlayers then

for i = 1, #dropCount.accounts do

file:write("[!] --> Dropped: " .. dropCount.accounts .. " from " .. childAttributeTables.accounts.table .. " table\n")

end

end

file:write("\n")

end

file:close()

end

end

return true

end

 

Não se esqueça de editar o script, nessa parte:

 

[1] = {level = 11, time = 5 * 24 * 60 * 60},

[2] = {level = 20, time = 15 * 24 * 60 * 60},

[3] = {level = 50, time = 30 * 24 * 60 * 60},

[4] = {level = 100, time = 60 * 24 * 60 * 60},

[5] = {level = 130, time = 90 * 24 * 60 * 60}

 

Os leveis dos players e os dias pra ser deletado se não logar.

cara

,[1] = {level = 11, time = 5 * 24 * 60 * 60},

 

[2] = {level = 20, time = 15 * 24 * 60 * 60},

[3] = {level = 50, time = 30 * 24 * 60 * 60},

[4] = {level = 100, time = 60 * 24 * 60 * 60},

[5] = {level = 130, time = 90 * 24 * 60 * 60}

isso aqui é o dia e level dos player que eu escolho que dele e em quanto tempo

 

 

o vermelho sao os dias?

RoksasR
21 de março de 2013 às 17:42

Exato /\

Eu editei meu post lá em cimão. Ele ta bem simples, mas funcional :)

Meu deus Thiago que código grande kk

jhowzikahJ
21 de março de 2013 às 17:46

data/globalevents/scripts, crie um arquivo chamado deleteplayers.lua e ponah isso dentro:

 

 

function onTime()

db.executeQuery(DELETE FROM players WHERE lastlogin < UNIX_TIMESTAMP() - 3*24*60*60)

return true

end

 

 

Globalevents.xml adicione essa tag:

 

	<globalevent name="deleteall" time="18:00" event="script" value="deleteplayers.lua"/>

 

Ali aonde está 18:00 é só por o horário do dia que vai deletá-los, pus 18:00 pra tu testa agora :)

 

 

UNIX_TIMESTAMP() - 3*24*60*60) <<<<<<<<<,, configura pra 5 dias ai por favor,queria saber tbm se ele é deletado totalmente do ot ou eu posso desdeletar ele pelo sql la na lista de player tem la (delete=0 que nao esta deletado e 1= a deletado) << acho que é assim.

 

"desdeletar" Oo kkkkkkk

Editado Março 21 por jhowzikah

ThiagoBjiT
21 de março de 2013 às 17:48

Usa o meu que funciona. 100% testado e funcionando. Script corrigido! Teve uns erros dos códigos do fórum, mais já foi corrigido.

RoksasR
21 de março de 2013 às 17:52

É só trocar por:

 

 

function onTime()

db.executeQuery(DELETE FROM players WHERE lastlogin < UNIX_TIMESTAMP() - 5*24*60*60)

return true

end

 

 

Não entendi sua última pergunta!

jhowzikahJ
21 de março de 2013 às 17:54

ThiagoBjiW

 

voce testou direitinho esse script amigo?

 

preciso de um que funcione

 

alguem ai pode me dizer uma empresa boa pra eu hospedar meu ot?

20cm2
21 de março de 2013 às 17:54

data/globalevents/scripts, crie um arquivo chamado deleteplayers.lua e ponah isso dentro:

 

 

function onTime()

db.executeQuery(DELETE FROM players WHERE lastlogin < UNIX_TIMESTAMP() - 3*24*60*60)

return true

end

 

 

Globalevents.xml adicione essa tag:

 

	<globalevent name="deleteall" time="18:00" event="script" value="deleteplayers.lua"/>

 

Ali aonde está 18:00 é só por o horário do dia que vai deletá-los, pus 18:00 pra tu testa agora :)

 

 

UNIX_TIMESTAMP() - 3*24*60*60) <<<<<<<<<,, configura pra 5 dias ai por favor,queria saber tbm se ele é deletado totalmente do ot ou eu posso desdeletar ele pelo sql la na lista de player tem la (delete=0 que nao esta deletado e 1= a deletado) << acho que é assim.

 

"desdeletar" Oo kkkkkkk

 

Ele vai ser deletado da db =)

jhowzikahJ
21 de março de 2013 às 18:05

AJUDA!

[1] = {level = 11, time = 5 * 24 * 60 * 60},

[2] = {level = 20, time = 15 * 24 * 60 * 60},

[3] = {level = 50, time = 30 * 24 * 60 * 60},

[4] = {level = 100, time = 60 * 24 * 60 * 60},

[5] = {level = 130, time = 90 * 24 * 60 * 60}

ALI ONDE TA LEVEL = 11 É PLAYERS ABAIXO DO LV 11 QUE VAO SER DELETADOS OU PLAYERS SOMENTE LV 11?

RoksasR
21 de março de 2013 às 18:11

Somente. Mas cara, o do Thiago vai deletar as accounts junto ;s

 

function onTime()

db.executeQuery(DELETE FROM players WHERE lastlogin < UNIX_TIMESTAMP() - 5*24*60*60)

return true

end

 

Globalevents.xml adicione essa tag:

 

<globalevent name="deleteall" time="18:00" event="script" value="deleteplayers.lua"/>

jhowzikahJ
21 de março de 2013 às 18:12

Roksas voce ja testou esse ai?

RoksasR
21 de março de 2013 às 18:27

Tipo, eu já usei varias vezes um parecido que fiz, que era a cada 10horas, só que como coloquei ali hora marcada, então tive que mudar a função de onThink pra onTime()

Mas testa ai, só dar /reload globalevents, e antes disso na tag do globalevents.xml colocar um horario pra vc testa