• 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!

Linux Whosonline.php

Wraskly

Member
Joined
Jun 17, 2010
Messages
244
Reaction score
7
For some reason my whosonline.php doesnt change the player from 1 to 0 on logout, well i think the code is the problem but im not totally sure, can someone tell me if there is a problem with my code? It just doesnt remove the players that has been online from the whos online page, when they arent even online. Heres my whosonline.php
PHP:
<?PHP
$order = $_REQUEST['order'];
if($order == 'name') {
	$orderby = 'name';
}
if($order == 'level') {
	$orderby = 'level';
}
if($order == 'vocation') {
	$orderby = 'vocation';
}
if(empty($orderby)) {
	$orderby = 'name';
}
$players_online_data = $SQL->query('SELECT * FROM players WHERE online = 1 ORDER BY '.$orderby);
$number_of_players_online = 0;
foreach($players_online_data as $player) {
	$number_of_players_online++;
	if(is_int($number_of_players_online / 2)) {
		$bgcolor = $config['site']['darkborder'];
	}
	else
	{
		$bgcolor = $config['site']['lightborder'];
	}
	$players_rows .= '<TR BGCOLOR='.$bgcolor.'><TD WIDTH=70%><A HREF="index.php?subtopic=characters&name='.$player['name'].'">'.$player['name'].'</A></TD><TD WIDTH=10%>'.$player['level'].'</TD><TD WIDTH=20%>'.$config_vocations[$player['vocation']].'</TD></TR>';
}
if($number_of_players_online == 0) {
	//server status - server empty
	$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><B>Server Status</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1><TR><TD>Currently no one is playing on '.$config['server']['serverName'].'.</TD></TR></TABLE></TD></TR></TABLE><BR>';
}
else
{
	//server status - someone is online
	$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><B>Server Status</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1><TR><TD>Currently '.$number_of_players_online.' players are online.</TD></TR></TABLE></TD></TR></TABLE><BR>';
	//list of players
	$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD><A HREF="index.php?subtopic=whoisonline&order=name" CLASS=white>Name</A></TD><TD><A HREF="index.php?subtopic=whoisonline&order=level" CLASS=white>Level</A></TD><TD><A HREF="index.php?subtopic=whoisonline&order=vocation" CLASS=white>Vocation</TD></TR>'.$players_rows.'</TABLE>';
	//search bar
	$main_content .= '<BR><FORM ACTION="index.php?subtopic=characters" METHOD=post>  <TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4><TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>Search Character</B></TD></TR><TR><TD BGCOLOR="'.$config['site']['darkborder'].'"><TABLE BORDER=0 CELLPADDING=1><TR><TD>Name:</TD><TD><INPUT NAME="name" VALUE=""SIZE=29 MAXLENGTH=29></TD><TD><INPUT TYPE=image NAME="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD></TR></TABLE></TD></TR></TABLE></FORM>';
}
?>
 
This has probably happened after a server crash.

After a crash, the online field in players doesn't change back to 0 because the players don't log out normaly. The solution for that problem is either manually change every field to 0 in players table. Or wait for each person to log in or out again.

When a server crashes, I do believe on startup the server sets everyone's flag back to "0". So it would start fresh again and everyone that was marked as logged in would be placed as logged out. I've created a test server using the Revision Wraskley is using and it happens to my server also. I can't figure it out either...
 
yep, a script that does that hasn't been added to it yet
Lua:
function onStartup()
	db.query('UPDATE `players` SET `online` = 0')
	return true
end
this should do
 
Noo cyco! :/ When I restart the server, the player online flags are correct. Its when the server is running and players log in and out that the flag doesn't change. The function onStartup only effects when the server starts correct? I'm trying to figure out why the flag doesn't change while the server is running.
 
yep, a script that does that hasn't been added to it yet
Lua:
function onStartup()
	db.query('UPDATE `players` SET `online` = 0')
	return true
end
this should do
(This is me Talking Out Loud So Don't Implement)

Hmm, isn't this for when the server starts up? Can I create an onLogout function? Something like:

Lua:
function onLogout(cid)
	db.query('UPDATE `players` SET `online` = 0 where `id` = "..getPlayerGUID(cid).."')
	return true
end

I found the code in creatureevent.cpp where the onLogout is called. Would something like that work?

Code:
uint32_t CreatureEvents::playerLogout(Player* player)
{
	//fire global event if is registered
	for(CreatureEventList::iterator it = m_creatureEvents.begin(); it != m_creatureEvents.end(); ++it)
	{
		if(it->second->getEventType() == CREATURE_EVENT_LOGOUT)
		{
			if(!it->second->executeOnLogout(player))
				return 0;
		}
	}
	return 1;
 
Last edited:
It's weird, i just tried it on my PC and it works fine, but when i run it on linux it doesnt change the flag from 1 to 0, but on my pc it does .-.
 
Back
Top