Open HailStorm32 opened 2 years ago
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.
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 https://github.com/DarkflameUniverse/DarkflameServer/pull/309 will handle? A bandaid solution might be necessary if the API is still a ways off from being merged.
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.
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?
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.
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.
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.
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.
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 likeis_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 a1
When a user logs off, theiris_online
value would be changed to a0
Repository breaking implications
The
accounts
table would need an additional column.Describe alternatives you've considered
A couple alternatives,
online_accounts
that is updated with the accounts that are currently online. (this is inefficient, and not ideal)Additional context
Briefly going through the code, its already tracked when user logs on/off, see https://github.com/DarkflameUniverse/DarkflameServer/blob/42f6f2f10b5971dd13faa18e2018892ce21ce3c3/dWorldServer/WorldServer.cpp#L800 and https://github.com/DarkflameUniverse/DarkflameServer/blob/d9d27a88fc3306f89e0cfb72e01de3e1bfe203e9/dGame/UserManager.cpp#L139