Jump to content
  • 0

User count script misbehaving


Elithe

Question


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  04/03/14
  • Last Seen:  

Hello I'm having difficulties finding the problem with the script I'm using,  I use Cora CP with the user counter script that must be plugged into the game to function however I have ran into an issue where the player count will never properly dispaly or go back down to zero.     Players Peaked seems to work properly though.

-	script	user_counter	-1,{
OnPCLoginEvent:

query_sql("SELECT value FROM mapreg WHERE varname='userOnline'",.@lastOnline);

if(getarraysize(.@lastOnline) == 0) {
	query_sql("INSERT INTO mapreg(varname,value) VALUE('userOnline',1)");
	set .@userOnline,1;
} else {
	query_sql("UPDATE mapreg SET value=value+1 WHERE varname='userOnline'");
	set .@userOnline,.@lastOnline[0]+1;
}

query_sql("SELECT value FROM mapreg WHERE varname='userPeak'",.@userPeak);

if((.@userOnline > .@userPeak[0]) || (getarraysize(.@userPeak) == 0)) {
	if(getarraysize(.@userPeak) == 0)
		.@newPeak$ = "INSERT INTO mapreg(varname,value) VALUE('userPeak',"+.@userOnline+")";
	else
		.@newPeak$ = "UPDATE mapreg SET value="+.@userOnline+" WHERE varname='userPeak'";
	query_sql(.@newPeak$);
	.@peak = .@userOnline;
} else {
	.@peak = .@userPeak[0];
}

end;

OnPCLogoutEvent:
query_sql("SELECT value FROM mapreg WHERE varname='userOnline'",.@lastOnlineB);
if(.@lastOnlineB[0] > 1)
	query_sql("UPDATE mapreg SET value=value-1 WHERE varname='userOnline'");
else
	query_sql("DELETE FROM mapreg WHERE varname='userOnline'");
end;
}

I thought it was just having issues by a single count but later I noticed sometimes the count would not go back down, I have 2 players in the server while the count says 4 it seems to go down then I log out but sometimes it goes up by 1 for good.   Sorry I'm having a hard time explaining my issue here, so my question is.

 

Does anything in this code look like it could be causing the potential problem I looked at it and it looks fine to me I thought of a temp solution is to have it reset on server startup.  but something causes the counter to decide to not go down a digit.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  92
  • Reputation:   17
  • Joined:  08/11/12
  • Last Seen:  

Hello Elithe,

 

I don't understand exactly what is your problem. The main goal of this script is to set up some variables to be read by the Cora CP, I mean this is what I understood from the context until now. If so, I think we can drop all the query_sqls and set all the variables in the "conventional way". Besides that, I need more details because honestly I don't see anything wrong with this script.

 

Where you want to display the count? Where did you got this script? Do you have any link or something else to help us finding the best solution?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  04/03/14
  • Last Seen:  

I'm starting to think its not a problem with the script and more of a problem with the widget provided by Cora CP

 

https://github.com/takari1994/CORA

 

The issue the false player count,  2 players could be logged in but it will still suggest there are 4~5 online,  the issue I'm having is it is not properly updating to the correct value and I can not figure out why this is happening, the script looks fine to me as well.
cab4f5829c.png

 

0d61638fce.png

mapreg-SQL

 

Here is the html for the widget that displays the server status with the players counted

<div id="wid-<?php echo $wuid; ?>" class="panel panel-primary widget wid-ss">
    <div class="panel-heading">
        <span class="panel-title"><?php echo $title; ?></span>
    </div>
    <div class="panel-body">
        
        <table>
            <tr>
                <td class="desc text-right">Map Server</td>
                <td>
                <?php
                
                if(1 == $map)
                    echo '<span class="label label-success">ON</span>';
                else
                    echo '<span class="label label-danger">OFF</span>';
                
                ?>
                </td>
                <?php if(1 == $player_online): ?>
                <td class="desc text-right">Players Online</td>
                <td>
                    <?php
                    $json = file_get_contents(base_url().'community/player_statistics');
                    $ps   = json_decode($json);
                    echo '<span class="label label-warning">'.$ps->player_count.'</span>';
                    ?>
                </td>
                <?php elseif(1 == $player_peak): ?>
                <td class="desc text-right">Online Peak</td>
                <td>
                    <?php
                    $json = file_get_contents(base_url().'community/player_statistics');
                    $ps   = json_decode($json);
                    echo '<span class="label label-warning">'.$ps->player_peak.'</span>';
                    ?>
                </td>
                <?php endif; ?>
            </tr>
            <tr>
                <td class="desc text-right">Char Server</td>
                <td>
                <?php
                
                if(1 == $char)
                    echo '<span class="label label-success">ON</span>';
                else
                    echo '<span class="label label-danger">OFF</span>';
                
                ?>
                </td>
                <?php if(1 == $player_online AND 1 == $player_peak): ?>
                <td class="desc text-right">Players Peak</td>
                <td>
                    <?php
                    $json = file_get_contents(base_url().'community/player_statistics');
                    $ps   = json_decode($json);
                    echo '<span class="label label-warning">'.$ps->player_peak.'</span>';
                    ?>
                </td>
                <?php endif; ?>
            </tr>
            <tr>
                <td class="desc text-right">Login Server</td>
                <td>
                <?php
                
                if(1 == $login)
                    echo '<span class="label label-success">ON</span>';
                else
                    echo '<span class="label label-danger">OFF</span>';
                
                ?>
                </td>
            </tr>
        </table>
    </div>
</div>

(this tells me it just reads and prints off the SQL value.)

 

 

so if this isn't an issue with the script not refreshing the value to reflect how many are online then is it possibly just a SQL permissions issue or a messup in the HTML code?    Sorry that this is now evolving past the issue of being purely the script but i'm lost on what it could even be at this point.

Edited by Elithe
Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

if you want to calculate the current online users. ... calculate it based on the amount of `online` in the char table...

SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  92
  • Reputation:   17
  • Joined:  08/11/12
  • Last Seen:  

Ok, there is a way to debug this sh** to see if the error is on the server side or on the cora cp side. I'm going to merge the solution proposed by Sir Emistry so you can have a better script.
 
Here is the merged solution:
-	script	user_counter	-1,{

OnPCLoginEvent:
	query_sql("SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1",.@userOnline);
	set $userOnline, .@userOnline;

	if(.@userOnline > $userPeak) {
		set $userPeak, .@userOnline;
	}
	set .@peak, $userPeak;
	
	debugmes "Online on Login: " + $userOnline;
	debugmes "Peak: " + $userPeak;

	end;

OnPCLogoutEvent:
	query_sql("SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1",.@userOnline);
	set $userOnline, .@userOnline;

	debugmes "Online on Logout: " + $userOnline;
}

Now you are able to see on Login and Logouts what's the number of players online and the peak of users online till that moment in the map-server console. I have tested it on (http://haru.ws/scriptchecker) and have found "No errors found!" output, but I don't know if it'll work as we expect, I need you to test it.

If you the results on the above script are not what you expect, try this script that is the same as you posted with a few edits to insert two debugs that will try to output the number of users online and user peak on each login and logout in the map-server console just like we did before.


-	script	user_counter	-1,{
OnPCLoginEvent:

query_sql("SELECT value FROM mapreg WHERE varname='userOnline'",.@lastOnline);

if(getarraysize(.@lastOnline) == 0) {
	query_sql("INSERT INTO mapreg(varname,value) VALUE('userOnline',1)");
	set .@userOnline,1;
} else {
	query_sql("UPDATE mapreg SET value=value+1 WHERE varname='userOnline'");
	set .@userOnline,.@lastOnline[0]+1;
}

query_sql("SELECT value FROM mapreg WHERE varname='userPeak'",.@userPeak);

if((.@userOnline > .@userPeak[0]) || (getarraysize(.@userPeak) == 0)) {
	if(getarraysize(.@userPeak) == 0)
		.@newPeak$ = "INSERT INTO mapreg(varname,value) VALUE('userPeak',"+.@userOnline+")";
	else
		.@newPeak$ = "UPDATE mapreg SET value="+.@userOnline+" WHERE varname='userPeak'";
	query_sql(.@newPeak$);
	.@peak = .@userOnline;
} else {
	.@peak = .@userPeak[0];
}

debugmes "Online on Login: " + .@userOnline;
debugmes "Peak: " + .@userPeak;

end;

OnPCLogoutEvent:
query_sql("SELECT value FROM mapreg WHERE varname='userOnline'",.@lastOnlineB);
if(.@lastOnlineB[0] > 1)
	query_sql("UPDATE mapreg SET value=value-1 WHERE varname='userOnline'");
else
	query_sql("DELETE FROM mapreg WHERE varname='userOnline'");

debugmes "Online on Logout: " + .@lastOnlineB;

end;
}

I hope it works, good luck!

Edited by _Okuz_
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  04/03/14
  • Last Seen:  

The code that attempts to gather the data from char_list query does not seem to do anything,  the debug message is kinda helpful it does in fact tell me that the counter refuses to go down sometimes when a player logs out.  judging by the console debug I'm assuming it is indeed the script or an error in mapreg query.  I kinda wish I could draw the information from the char_list now.

Edited by Elithe
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...