• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Bug Fix] Online List

Avarian

Bring Out Your Dead!
Joined
Jun 14, 2007
Messages
472
Reaction score
1
Location
United States
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 :p

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
 
nice go test here more im not good on luaSQL wait Johern who is the luaSQL scripter for he check the fix
 
Avarian, You've missed this part:
Code:
	if serverStarted == FALSE then
		assert(con:execute("UPDATE `players` SET `online` = 0;"))
		serverStarted = TRUE
	end
It clears all online values when first player does login (of course before adding him again).
Also, it was required to change status with +1/-1 instead of simple 1/0 to support allowClones feature - read Developers Forum and my suggestions about it.
 
Last edited:
The way you've made the script now wont do anything different then the one that's already in the server.
 
The way you've made the script now wont do anything different then the one that's already in the server.

Actually it does, as I explained. Did you test it? no.

But I guess it doesn't matter, I just checked out the development thread like fightingElf said to do and it sounds like it's being removed/changed.
 
Last edited:
Okey, I got your point but the part:
Code:
    if serverStarted == FALSE then
        assert(con:execute("UPDATE `players` SET `online` = 0;"))
        serverStarted = TRUE
    end
Prevent's the bug you talked about. Every time the server starts, it resets all to 0.

serverStarted is a global value added in global.lua.
 
Oh well in that case it doesn't work, which was why I had to edit the files lol

Also it's not just me it doesn't work for it's everyone, cause I keep getting bug reports about players always being shown as online even if they aren't.
 
Anyways, this is handled in the sources now.

Edit: Post 600 :D
 
Back
Top