Avarian
Bring Out Your Dead!
I've already created several PHP scripts that take advantage of the new online field in the database. However I also found some bugs in the system and create a better login.lua and logout.lua that are better then the current ones.
The current ones work by simply saying that online = 0 until you login then it adds +1 making online = 1 and when you logout it subtracts -1 making online = 0. However if the server crashes/you close the server then they never activated logout.lua so it never changes subtracts -1 from online field and the next time they login it will be come 2 and if they actually log out it'll become 1, and the bug can continue pretty much forever.
Here's the fixed ones. In mine instead of adding plus +1 and subtracting -1 it simply inserts a 1 when they login and when they logout it inserts a 0. This way even if the server crashes/you close the server, the next time they logout it will set back to 0. This way the bug doesn't simply continue forever. It's solved the next time they logout
login.lua
logout.lua
The current ones work by simply saying that online = 0 until you login then it adds +1 making online = 1 and when you logout it subtracts -1 making online = 0. However if the server crashes/you close the server then they never activated logout.lua so it never changes subtracts -1 from online field and the next time they login it will be come 2 and if they actually log out it'll become 1, and the bug can continue pretty much forever.
Here's the fixed ones. In mine instead of adding plus +1 and subtracting -1 it simply inserts a 1 when they login and when they logout it inserts a 0. This way even if the server crashes/you close the server, the next time they logout it will set back to 0. This way the bug doesn't simply continue forever. It's solved the next time they logout
login.lua
Code:
function onLogin(cid)
registerCreatureEvent(cid, "PlayerDeath")
dofile("./config.lua")
if sqlType == "mysql" then
env = assert(luasql.mysql())
con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
else -- sqlite
env = assert(luasql.sqlite3())
con = assert(env:connect(sqliteDatabase))
end
if serverStarted == FALSE then
assert(con:execute("UPDATE `players` SET `online` = 0;"))
serverStarted = TRUE
end
assert(con:execute("UPDATE `players` SET `online` = 1 WHERE `id` = "..getPlayerGUID(cid)..";"))
con:close()
env:close()
return TRUE
end
logout.lua
Code:
function onLogout(cid)
dofile("./config.lua")
if sqlType == "mysql" then
env = assert(luasql.mysql())
con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
else -- sqlite
env = assert(luasql.sqlite3())
con = assert(env:connect(sqliteDatabase))
end
assert(con:execute("UPDATE `players` SET `online` = 0 WHERE id = "..getPlayerGUID(cid)..";"))
con:close()
env:close()
return TRUE
end