The Wayback Machine - https://web.archive.org/web/20201129043130/https://github.com/MovingBlocks/Terasology/pull/3571
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: Add AFK state for players in multiplayer #3571

Merged
merged 26 commits into from Nov 11, 2020

Conversation

@iHDeveloper
Copy link
Contributor

@iHDeveloper iHDeveloper commented Dec 4, 2018

Contains

As a gamer sometimes I have to go away from the keyboard for some reason and I want to tell my friends who I'm playing with that I'm away so they won't get mad at me or something. So, I made an afk command to do that goal.

How to test

  • Pull from My Fork from branch afk-command
  • Run the game from the source code
  • Make sure you in multiplayer mode like (Hosting game or Playing online)
  • Show the game console
  • Type afk
  • You can now go away without telling your friends that I'm AFK in the chat 😄

Issues

No more issues finally 😁

  • Client can't send request to the server
  • Rebuild the way that client and server communicate in the AFKSystem
  • Auto disable the AFK when the player moves
  • Test it
@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 4, 2018

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 4, 2018

Hooray Jenkins reported success with all tests good!

@iHDeveloper iHDeveloper changed the title [W.I.P] Add new AFK flag and display it on the online players overlay Add new AFK flag and display it on the online players overlay Dec 4, 2018
@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 4, 2018

Hooray Jenkins reported success with all tests good!

1 similar comment
@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 4, 2018

Hooray Jenkins reported success with all tests good!

Copy link

@syntaxi syntaxi left a comment

Substantially better this time round. I've a few minor comments but they're trivial and the GCI task can be approved without them.
Just need to test it out in game and we should be good to go.

@kaen
Copy link
Contributor

@kaen kaen commented Dec 5, 2018

I tested this out locally. First very minor note is that the message in the console uses a curly brace where a square bracket is expected: [AFK} You are AFK!

More importantly, it seems that this only works as intended for the host going afk. Here are some scenarios I tested by hosting with (no saves) launch configuration, then launching 2nd and 3rd client from the configuration dropdown and connecting to localhost server.

Scenario 1 (works as intended)

  • host types afk
  • host shows afk on their own player list
  • host shows afk on 2nd client
  • host shows afk on 3rd client
  • host returns from afk
  • host shows not afk on both client lists

Scenario 2 (not working as intended)

  • 2nd client types afk
  • 2nd client shows afk on their own list
  • 2nd client does not show afk on 3rd client's list
  • 2nd client does not show afk on host's list

Scenario 3 (not working as intended)

  • host, 2nd, and 3rd client type afk
  • host list only shows host afk
  • 2nd client shows host and 2nd client afk
  • 3rd client show host and 3rd client afk
  • clients are not shown afk on other client's lists
Copy link
Member

@Cervator Cervator left a comment

Can confirm as well - AFK shows for the player running the command, but that's it :-)

Also, I get the impression the player is meant to see the "Welcome back, you are no longer AFK!" message in the little chat message bar at the bottom of the screen? It pops up when a player starts moving, but appears blank to me, while the message gets logged in the regular console OK. Unsure if that's bug here or if any input to the console will trigger a blank chat notification as well.

A few times it seemed like I went un-afk without really doing anything. Maybe it is overly sensitive? Perhaps instead of using the move event use the one where the player has sent an actual message? Then they're certainly no longer afk. But if a cat poked their mouse - no more afk! :-)

Can also validate that the afk command doesn't work in single player, where it would be kinda silly. But on the other hand having extra logic for that may not be needed.

I suspect you need one more layer to make this work. See how AFKSystem (which should really be AfkSystem, likewise the component should be AfkComponent) is set to ALWAYS ? That means it'll do the same thing both on clients and the server. Right now it works solely locally.

You may well want to have a Client only system that registers and handles the command, but sends a note to the server "Hey I'm going AFK" (you send an event that's being listened to in an Authority system) and then the server can send a BroadcastEvent that the client systems catch with the name of the now-AFK player in it. Then each client can update their local state to know that player X is AFK and show that in the overlay. When the player comes back you repeat the process to let everybody know that player is back now

So in other words:

  • AfkClientSystem registers the command and when triggered sends an event (that's replicated / sent to the server somehow, I forget how) "Hey I'm going AFK, my player name is X"
  • AfkAuthoritySystem listens to the event indicating that player X is going AFK, re-issues a BroadcastEvent to everybody with that information
  • AfkClientSystem has a listener for the broadcast event, when received you now know to mark that player AFK in the overlay

You should be able to look at the players online overlay itself to see how it transfers state around to the different clients connected with their ping so it all shows up correctly everywhere :-)

@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 5, 2018

Hooray Jenkins reported success with all tests good!

@iHDeveloper
Copy link
Contributor Author

@iHDeveloper iHDeveloper commented Dec 5, 2018

I think we are ready to merge it. I tested it with my friend Falcoph. Thanks, @Cervator for your notes It wasn't gonna happen now without them. Also, Thanks, @kaen for the test scenarios and now this pull can pass all of those scenarios 😄

@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 5, 2018

Hooray Jenkins reported success with all tests good!

@skaldarnar
Copy link
Member

@skaldarnar skaldarnar commented Dec 6, 2018

I will test this out when I get a bit free time ;-)
One thing I'm wondering about is whether you need the boolean field on AFKComponent, or whether the presence of the component is enough to indicate that a player is actually afk, and the absence denotes the opposite (not afk).

@iHDeveloper
Copy link
Contributor Author

@iHDeveloper iHDeveloper commented Dec 6, 2018

Thanks for your help @skaldarnar. I implemented new features in the list below:

  • Shows Idle in the Discord RPC when the player is afk
  • Auto afk with no active for like 5 minutes
  • Auto unafk with any move or even touch your keyboard

You can test them and give us the result of your test. That's will be helpful from you 😄
Note: You can also try the scenarios that @kaen did in the last test result from him. 😉

@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 6, 2018

Hooray Jenkins reported success with all tests good!

@syntaxi
Copy link

@syntaxi syntaxi commented Dec 6, 2018

I probably should have been clearer with my explanation.
This is mostly a rehash of my discord message, but here it won't scroll away.

What I meant was that the DelayManager listens for changes made to PeriodicActionComponent
So rather than re-implementing the delay logic from DelayManager I was intending for you to look at the logic only in addPeriodicAction and then copy parts of it.
You'll still use DelayManager behind the scenes, just changing how you access it.

To get more technical and specific, you should delete all the methods you copied except for addPeriodicAction, the PeriodicActionTriggeredEvent handler and getPeriodicComponent.
Then call the add method in postBegin and that should work.

If you can't get it to work then you could either just do the auto afk because it's not strictly needed for the task, or try and move it to the Authority method you have.

iHDeveloper added 2 commits Dec 7, 2018
@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 7, 2018

Hooray Jenkins reported success with all tests good!

1 similar comment
@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 7, 2018

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

@GooeyHub GooeyHub commented Dec 7, 2018

Hooray Jenkins reported success with all tests good!

Copy link
Member

@skaldarnar skaldarnar left a comment

Tests out fine with two clients in a local setup after updating this PR according to NUI extraction.

I'm not sure whether this should live directly in the engine, or whether it should be extracted to a module, but that can be done in a follow-up.

So, better late than never - LGTM!

@In
private NetworkSystem networkSystem;

private int count;

This comment has been minimized.

@skaldarnar

skaldarnar Nov 1, 2020
Member

I'm not sure whether this is actually required. I'm wondering whether it would also work to just rely on the entity information we get on ConnectedEvent and DisconnectedEvent events.

It feels a bit too bulky to keep track of the count and look through all connected players additionally.

This comment has been minimized.

@skaldarnar

skaldarnar Nov 11, 2020
Member

I've created #4242 to keep track of this. @iHDeveloper might this be your next contribution? 😉

This comment has been minimized.

@iHDeveloper

iHDeveloper Nov 11, 2020
Author Contributor

@skaldarnar Sure! I'm currently busy with exams. But, I will work on it during the weekend 😁

@skaldarnar skaldarnar mentioned this pull request Nov 11, 2020
0 of 2 tasks complete
@skaldarnar skaldarnar dismissed Cervator’s stale review Nov 11, 2020

Changes have been addressed

@skaldarnar skaldarnar removed the WIP label Nov 11, 2020
@skaldarnar skaldarnar added this to the v4.1.0 milestone Nov 11, 2020
@skaldarnar skaldarnar changed the title Add new AFK flag and display it on the online players overlay feat: Add AFK state for players in multiplayer Nov 11, 2020
@skaldarnar skaldarnar merged commit d453bd3 into MovingBlocks:develop Nov 11, 2020
13 checks passed
13 checks passed
LGTM analysis: Java No new or fixed alerts
Details
ci/cloudbees/checkstyle 1455 issues
Details
ci/cloudbees/javadoc-warnings 112 issues
Details
ci/cloudbees/open-tasks 437 issues
Details
ci/cloudbees/pmd 471 issues
Details
ci/cloudbees/spotbugs 285 issues
Details
ci/cloudbees/stage/Analytics Finished
Details
ci/cloudbees/stage/Build Finished
Details
ci/cloudbees/stage/Checkout Finished
Details
ci/cloudbees/stage/Publish Finished
Details
ci/cloudbees/stage/Record Finished
Details
ci/cloudbees/tests/Record 14 tests were skipped
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
@pollend pollend mentioned this pull request Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
7 participants
You can’t perform that action at this time.