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

FEAT(server): Add rememberduration option #4147

Merged
merged 1 commit into from Jul 8, 2020
Merged

FEAT(server): Add rememberduration option #4147

merged 1 commit into from Jul 8, 2020

Conversation

deluxghost
Copy link
Contributor

@deluxghost deluxghost commented May 8, 2020

This option allows to set a threshold on how long a user's channel
should be remembered. This is useful for scenarios where users usually
don't want their channel to be remembered by the server unless they had
a disconnect (aka have ot re-connect after a short period of time).

Implements #4143

@deluxghost deluxghost changed the title feat: remember channel duration WIP: feat: remember channel duration May 8, 2020
@deluxghost
Copy link
Contributor Author

@Krzmbrzl updated

@deluxghost deluxghost changed the title WIP: feat: remember channel duration feat: remember channel duration May 10, 2020
Copy link
Member

@Krzmbrzl Krzmbrzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also do 2 more things, please?

  1. Remove the unrelated whitespace changes ( I guess you have used some sort of auto-formatter?)
  2. Prefix your commit message with src/murmur:

src/murmur/Messages.cpp Show resolved Hide resolved
Copy link
Member

@Krzmbrzl Krzmbrzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you have tested this to be working (using different values for rememberduration including disabling and not setting it), right?

@Krzmbrzl Krzmbrzl added this to the 1.4.0 milestone May 10, 2020
@deluxghost
Copy link
Contributor Author

I assume you have tested this to be working (using different values for rememberduration including disabling and not setting it), right?

Wait, I think I found a problem

@deluxghost
Copy link
Contributor Author

OK, the problem is the last_active in the user table is updated while a user enters a channel, instead of leaving it. The behavior blocks this PR currently.

Should I update that value upon user leaving (by any means)? Any tips?

@Krzmbrzl
Copy link
Member

The behavior blocks this PR currently.

How so? Because the time difference is now between rejoining and entering a channel vs. leaving it?

Hm... A quick check revealed that last_active is used in several places, so I'm not sure whether it's a good idea to temper with it. Who knows: Maybe for one of these situations it's actually important for this timestamp to represent the last time a channel was joined...

I guess the easiest way would be to change the documentation of that option to state that the time interval is relative to when that channel was joined. If we also change the unit of that option to be hours, I think the difference doesn't matter that much in a lot of cases.
It's a bit of a sloppy workaround though 🤔

@deluxghost
Copy link
Contributor Author

I think that will be a bit strange. If the user has been in the channel for a long time (> duration), he won't auto re-join upon he lost his connection accidentally. but if we change the duration to a large value just for that case, the option will become meaningless. The remember feature is only useful in several minutes after disconnecting, similar to multiplayer games.

I think we still need a way to get the time of user leaving, that makes more sense, i.e. "when you lost connection, you have x minutes to reconnect, we will take you to the last channel."

Is is easy to add a new column to represent user leaving time?

@Krzmbrzl
Copy link
Member

Is is easy to add a new column to represent user leaving time?

Yeah it should be relatively straight forward. You just have to make sure that any existing table will be extended by that new column as well. That's part of the whole setup code that is at the top of ServerDB.cpp. I haven't done much with that yet, so I'll have to look into this as well 👀

@deluxghost
Copy link
Contributor Author

Looks like the whole setup code is trying to modify db manually by the internal "version"?

I guess what I need to do is

  • bumping current db version to 7 (?)
  • adding the new column if version<7
  • creating new table with the new column if version==0 (I assume this means no db exists?)

It's difficult to read anything from tons of SQL queries... I still prefer any migration mechanism

@Krzmbrzl
Copy link
Member

Sounds about right, yes. And while you're on it, it might be a good idea to create a member variable that holds the current db version...

It's difficult to read anything from tons of SQL queries...

Agreed. The code is quite messy

@deluxghost deluxghost changed the title feat: remember channel duration WIP: feat: remember channel duration May 13, 2020
@Krzmbrzl
Copy link
Member

@deluxghost any (planned) progress here? :)

@deluxghost
Copy link
Contributor Author

@Krzmbrzl uhh sorry for the delay. I was just too excited to learn the new Hammer tools for Half Life Alyx recently. I am going to come back to this PR asap.

@Krzmbrzl
Copy link
Member

No problem. Just wanted to get a status update to see if this PR might be abandoned :)

@Krzmbrzl
Copy link
Member

Sounds about right, yes. And while you're on it, it might be a good idea to create a member variable that holds the current db version...

I actually went ahead and did that in #4220

There I also had to dig through the database code, so now I know how stuff works in there. This means I'll be able to better assist you with this project now :D

creating new table with the new column if version==0

I think you should instead create a new column last_seen in the users table that'll get updated every time a user disconnects. That way we have exactly the time we wanted ☝️

@deluxghost
Copy link
Contributor Author

uh yes, that's what i'm going to do

btw, is there any simple db editor with GUI for debugging purposes?

@Krzmbrzl
Copy link
Member

For SQLite (which is the default backend) there seems to be https://sqlitebrowser.org/

@deluxghost
Copy link
Contributor Author

updated something, but i'm not sure if i did it right.

and it might make sense to update last_seen of every online user while server shutting down?

Copy link
Member

@Krzmbrzl Krzmbrzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore you'll also have to change the database version (from 7 to 8) in ServerDB.h and you'll also make sure that the upgrade process involves copying the new column as well (I'm not sure right now whether all columns are copied automatically or whether that has to be done explicitly)

scripts/murmur.ini Outdated Show resolved Hide resolved
src/murmur/ServerDB.cpp Outdated Show resolved Hide resolved
src/murmur/ServerDB.cpp Show resolved Hide resolved
src/murmur/ServerDB.cpp Outdated Show resolved Hide resolved
src/murmur/Server.h Outdated Show resolved Hide resolved
@Krzmbrzl
Copy link
Member

Krzmbrzl commented Jun 2, 2020

and it might make sense to update last_seen of every online user while server shutting down?

Absolutely, yes

@deluxghost
Copy link
Contributor Author

and it might make sense to update last_seen of every online user while server shutting down?

Absolutely, yes

for this, where should I look into? i don't understand where the server handles the shutting down process

you'll also make sure that the upgrade process involves copying the new column as well

it uses INSERT INTO to import old data:

if (version < 4)
SQLDO("INSERT INTO `%1users` (`server_id`, `user_id`, `name`, `pw`, `lastchannel`, `texture`, `last_active`) SELECT `server_id`, `player_id`, `name`, `pw`, `lastchannel`, `texture`, `last_active` FROM `%1players%2`");
else
SQLDO("INSERT INTO `%1users` (`server_id`, `user_id`, `name`, `pw`, `lastchannel`, `texture`, `last_active`) SELECT `server_id`, `user_id`, `name`, `pw`, `lastchannel`, `texture`, `last_active` FROM `%1users%2`");

should I write like this?

if (version < 4)
  // sql
else if (version < 8)
  // sql
else
  // sql with last_seen

@Krzmbrzl
Copy link
Member

Krzmbrzl commented Jun 2, 2020

for this, where should I look into? i don't understand where the server handles the shutting down process

Actually when thinking about this, it might get complicated as you'd have to make sure that you catch the server before it's actually shutting down in order to access the user-list...

I think we might be better off if we ignore the shutdown and instead clear the last_seen field when the user connects (in order to not use an outdated date if the server is shut down).
In this context it might even be a good idea to use a different name for the column. Something like last_disconnect maybe? 🤔

should I write like this?

Yes

@deluxghost
Copy link
Contributor Author

I think we might be better off if we ignore the shutdown and instead clear the last_seen field when the user connects

Looks like this method won't prevent using the old value, because we should use the value first, before clear it (or the valid values will be ignored too).

I think we should clear last_disconnect of every user when starting the server? It might take time, but I don't have a better idea.

If we should do this, could you tell me which part of the code should I look at, please?

@deluxghost
Copy link
Contributor Author

oh, wait, if we don't clear last_disconnect manually, the only problem is the server might forget users' last channel earlier than expected, which isn't a big problem.

so just ignore these things is also an option.

@Krzmbrzl
Copy link
Member

Krzmbrzl commented Jun 7, 2020

Looks like this method won't prevent using the old value, because we should use the value first, before clear it (or the valid values will be ignored too).

Indeed 😄

I think we should clear last_disconnect of every user when starting the server? It might take time, but I don't have a better idea.

That sounds like a good idea to me 🤔

oh, wait, if we don't clear last_disconnect manually, the only problem is the server might forget users' last channel earlier than expected, which isn't a big problem.

True, but if we can fix that, I think it'd still be better to do so :)

If we should do this, could you tell me which part of the code should I look at, please?

I think it could be as simple as adding a new slot to the ServerDB class and connect that to Meta::started(Server *server) signal (you can do the connection in main.cpp as soon as the Meta object and the ServerDB object exist).

This should be after this line:

meta = new Meta();

@Krzmbrzl
Copy link
Member

@deluxghost what's the status here?

@deluxghost
Copy link
Contributor Author

updated

I spent more time on finding out how the hell the moc works 😦

@Krzmbrzl
Copy link
Member

Okay nice 👍
I'll review it in the upcoming days :)

src/murmur/ServerDB.cpp Outdated Show resolved Hide resolved
@deluxghost deluxghost changed the title WIP: feat: remember channel duration feat: remember channel duration Jul 3, 2020
This option allows to set a threshold on how long a user's channel
should be remembered. This is useful for scenarios where users usually
don't want their channel to be remembered by the server unless they had
a disconnect (aka have ot re-connect after a short period of time).

Implements #4143
@Krzmbrzl
Copy link
Member

Krzmbrzl commented Jul 3, 2020

@deluxghost I took the liberty of adjusting your commit message to fit our new commit guidelines ☝️

@Krzmbrzl Krzmbrzl changed the title feat: remember channel duration FEAT(server): Add rememberduration option Jul 8, 2020
@Krzmbrzl Krzmbrzl merged commit 9d24422 into mumble-voip:master Jul 8, 2020
@Krzmbrzl
Copy link
Member

Krzmbrzl commented Jul 8, 2020

Thank you very much for your contribution! :)

Hartmnt added a commit to Hartmnt/mumble that referenced this pull request May 5, 2022
The previous implementation of rememberchannelduration (mumble-voip#4147)
acknowledged the unreliability of the last_disconnect database
field. It used a workaround to set the last_disconnect field
to NULL for every user on every start of the mumble server.
However, with a default behavior for NULL, this created the
unintended side-effect that rememberchannel was erroneously
used for every user on their first connection after a server
restart.

This new implementation reverts the workaround of mumble-voip#4147 and
uses the last_active database field to check if last_disconnect
is reliable. If last_disconnect is unreliable, it will now use
the server uptime and compare it to rememberchanneduration.
We expect last_disconnect to be unreliable when the server
was shut down while clients are still connected.

Fixes mumble-voip#5639
Hartmnt added a commit to Hartmnt/mumble that referenced this pull request May 5, 2022
The previous implementation of rememberchannelduration (mumble-voip#4147)
acknowledged the unreliability of the last_disconnect database
field. It used a workaround to set the last_disconnect field
to NULL for every user on every start of the mumble server.
However, with a default behavior for NULL, this created the
unintended side-effect that rememberchannel was erroneously
used for every user on their first connection after a server
restart.

This new implementation reverts the workaround of mumble-voip#4147 and
uses the last_active database field to check if last_disconnect
is reliable. If last_disconnect is unreliable, it will now use
the server uptime and compare it to rememberchanneduration.
We expect last_disconnect to be unreliable when the server
was shut down while clients are still connected.

Fixes mumble-voip#5639
Hartmnt added a commit to Hartmnt/mumble that referenced this pull request May 5, 2022
The previous implementation of rememberchannelduration (mumble-voip#4147)
acknowledged the unreliability of the last_disconnect database
field. It used a workaround to set the last_disconnect field
to NULL for every user on every start of the mumble server.
However, with a default behavior for NULL, this created the
unintended side-effect that rememberchannel was erroneously
used for every user on their first connection after a server
restart.

This new implementation reverts the workaround of mumble-voip#4147 and
uses the last_active database field to check if last_disconnect
is reliable. If last_disconnect is unreliable, it will now use
the server uptime and compare it to rememberchanneduration.
We expect last_disconnect to be unreliable when the server
was shut down while clients are still connected.

Fixes mumble-voip#5639
Hartmnt added a commit to Hartmnt/mumble that referenced this pull request May 5, 2022
The previous implementation of rememberchannelduration (mumble-voip#4147)
acknowledged the unreliability of the last_disconnect database
field. It used a workaround to set the last_disconnect field
to NULL for every user on every start of the mumble server.
However, with a default behavior for NULL, this created the
unintended side-effect that rememberchannel was erroneously
used for every user on their first connection after a server
restart.

This new implementation reverts the workaround of mumble-voip#4147 and
uses the last_active database field to check if last_disconnect
is reliable. If last_disconnect is unreliable, it will now use
the server uptime and compare it to rememberchanneduration.
We expect last_disconnect to be unreliable when the server
was shut down while clients are still connected.

Fixes mumble-voip#5639
Krzmbrzl pushed a commit to Hartmnt/mumble that referenced this pull request May 5, 2022
The previous implementation of rememberchannelduration (mumble-voip#4147)
acknowledged the unreliability of the last_disconnect database
field. It used a workaround to set the last_disconnect field
to NULL for every user on every start of the mumble server.
However, with a default behavior for NULL, this created the
unintended side-effect that rememberchannel was erroneously
used for every user on their first connection after a server
restart.

This new implementation reverts the workaround of mumble-voip#4147 and
uses the last_active database field to check if last_disconnect
is reliable. If last_disconnect is unreliable, it will now use
the server uptime and compare it to rememberchanneduration.
We expect last_disconnect to be unreliable when the server
was shut down while clients are still connected.

Fixes mumble-voip#5639
Krzmbrzl added a commit that referenced this pull request May 5, 2022
…logic

The previous implementation of rememberchannelduration (#4147)
acknowledged the unreliability of the last_disconnect database
field. It used a workaround to set the last_disconnect field
to NULL for every user on every start of the mumble server.
However, with a default behavior for NULL, this created the
unintended side-effect that rememberchannel was erroneously
used for every user on their first connection after a server
restart.

This new implementation reverts the workaround of #4147 and
uses the last_active database field to check if last_disconnect
is reliable. If last_disconnect is unreliable, it will now use
the server uptime and compare it to rememberchanneduration.
We expect last_disconnect to be unreliable when the server
was shut down while clients are still connected.

Fixes #5639
Krzmbrzl pushed a commit to Krzmbrzl/mumble that referenced this pull request May 8, 2022
The previous implementation of rememberchannelduration (mumble-voip#4147)
acknowledged the unreliability of the last_disconnect database
field. It used a workaround to set the last_disconnect field
to NULL for every user on every start of the mumble server.
However, with a default behavior for NULL, this created the
unintended side-effect that rememberchannel was erroneously
used for every user on their first connection after a server
restart.

This new implementation reverts the workaround of mumble-voip#4147 and
uses the last_active database field to check if last_disconnect
is reliable. If last_disconnect is unreliable, it will now use
the server uptime and compare it to rememberchanneduration.
We expect last_disconnect to be unreliable when the server
was shut down while clients are still connected.

Fixes mumble-voip#5639

(cherry picked from commit ccbf407)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants