Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add live player count tracking #450

Open
HailStorm32 opened this issue Feb 9, 2022 · 8 comments · May be fixed by #1550
Open

ENH: Add live player count tracking #450

HailStorm32 opened this issue Feb 9, 2022 · 8 comments · May be fixed by #1550
Labels
enhancement New feature or request P-Fixer This issue is confirmed, but is not prioritized to be fixed.

Comments

@HailStorm32
Copy link
Contributor

HailStorm32 commented Feb 9, 2022

Is your feature request related to a problem?

No

Describe the solution you'd like

Add the ability for the number of currently online players to be tracked in the database. This would allow for easier moderation and allow for an external program to grab the current player count for display purposes.

Having the server update a new column in the accounts table called something like is_online which would be a boolean 0 for offline and 1 for online.

Each time a user logs in, their is_online would be changed to a 1
When a user logs off, their is_online value would be changed to a 0

Repository breaking implications

The accounts table would need an additional column.

Describe alternatives you've considered

A couple alternatives,

  • Have a seperate table called online_accounts that is updated with the accounts that are currently online. (this is inefficient, and not ideal)
  • Write the total number of online accounts to a file (downside of not getting who is online, and a bit unelegent having to write to a file)

Additional context

Briefly going through the code, its already tracked when user logs on/off, see

Game::logger->Log("WorldServer", "User %s authenticated with correct key.\n", username.c_str());

and
Game::logger->Log("UserManager", "Deleted user %i\n", user->GetAccountID());

@HailStorm32 HailStorm32 added enhancement New feature or request triage An issue that needs triage labels Feb 9, 2022
@codeshaunted
Copy link
Member

Ideally this would be done through some sort of API on the MasterServer. Updating a value in a database is a bandaid solution at best.

@HailStorm32
Copy link
Contributor Author

Ideally this would be done through some sort of API on the MasterServer. Updating a value in a database is a bandaid solution at best.

Is this somthing #309 will handle? A bandaid solution might be necessary if the API is still a ways off from being merged.

@codeshaunted
Copy link
Member

Ideally this would be done through some sort of API on the MasterServer. Updating a value in a database is a bandaid solution at best.

Is this somthing #309 will handle? A bandaid solution might be necessary if the API is still a ways off from being merged.

I don’t know if it’s in #309 but it could likely be added somewhat easily. This isn’t a critical issue and can wait for a proper solution.

@HailStorm32
Copy link
Contributor Author

Gotcha

If I end up implementing this myself in the meantime (the database version), should I create a pull request so others can pull it if they want, or should I just keep it in my fork?

@IAmMajo
Copy link
Contributor

IAmMajo commented Feb 10, 2022

You can kind of already get the currently online players from the table activity_log. I execute a query like this once per minute to show an online list of all players on my Discord server:

SELECT
  (SELECT `name`
   FROM `charinfo`
   WHERE `id` = `outer`.`character_id`) AS `Minifigure`,

  (SELECT `name`
   FROM `accounts`
   WHERE `id` =
       (SELECT `account_id`
        FROM `charinfo`
        WHERE `id` = `outer`.`character_id`)) AS `Account`,

  (SELECT `name`
   FROM `map`
   WHERE `id` = `outer`.`map_id`) AS `World`
FROM `activity_log` `outer`
WHERE `activity` = 0
  AND `time` > UNIX_TIMESTAMP() - 21600
  AND `id` =
    (SELECT MAX(`id`)
     FROM `activity_log`
     WHERE `character_id` IN
         (SELECT `id`
          FROM `charinfo`
          WHERE `account_id` =
              (SELECT `account_id`
               FROM `charinfo`
               WHERE `id` = `outer`.`character_id`)));

For this query to work you need to add an extra table map with the columns id and name to the database and fill it with the ids and names of all maps (https://explorer.lu-dev.net/zones).

The query works perfectly most of the time. However, sometimes the activity_log table is inaccurate if for example the chat server crashes. That is why I have added AND `time` > UNIX_TIMESTAMP() - 21600 to the query. So if according to activity_log players are online for more than six hours in the same world, they are no longer displayed in the online list.

@Jettford
Copy link
Collaborator

This isn't really helpful for actually getting who is online in live time, it just gives you people on within the last 6 hours, which is not what the issue was about. However yes #309 will contain a method of getting all online players.

@Jettford Jettford removed the triage An issue that needs triage label Feb 11, 2022
@codeshaunted codeshaunted added the P-low This issue can affect gameplay, but does not prevent a user from playing or progressing label Feb 11, 2022
@IAmMajo
Copy link
Contributor

IAmMajo commented Feb 12, 2022

This isn't really helpful for actually getting who is online in live time, it just gives you people on within the last 6 hours, which is not what the issue was about. However yes #309 will contain a method of getting all online players.

No, it does not just give the people that were online within the last 6 hours. It looks for the newest row of each account in the activity_log table. If the value of activity in that row is 0, they are online and get displayed in the list. If the value of activity in that row is 1, they are not online and are not displayed in the list.

@Jettford
Copy link
Collaborator

Ah yeah, after further looking into how that table works again I realise I am wrong, apologies. That would be the only way to get online players.

@EmosewaMC EmosewaMC added P-Fixer This issue is confirmed, but is not prioritized to be fixed. and removed P-low This issue can affect gameplay, but does not prevent a user from playing or progressing labels Aug 4, 2022
@aronwk-aaron aronwk-aaron linked a pull request Apr 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P-Fixer This issue is confirmed, but is not prioritized to be fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants