HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Reconnecting clients to a game  (Read 1900 times)

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Reconnecting clients to a game
« on: Sep 25, 16, 10:50:22 PM »

Has anyone experimented successfully with the reconnection mechanism in HeroEngine by enabling "allowReconnection" in unique method _OnPlayerConnectionDisconnect() of server class _Account?

I tried it out a little bit in the past, but found sometimes it would not seem to reconnect properly (I don't remember what the problem was off-hand). Plus there is still the issue of recreating the client-side state of things for the reconnected client.  I am at the point where I will be investigating this again and I am curious about anyone else's experiences.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: Reconnecting clients to a game
« Reply #1 on: Sep 26, 16, 11:53:52 AM »

I have not and was not even aware of this.

What are you trying to do with this?

Reconnecting works fine for me in that I can log in after closing HE and load my character fine. I would think in your case you just write the hook during the onload() in the area and character classes. During that time you sync your special game content with the client via your systems. For me this is house loading, city status, guild information etc. for you it should be the current monsters on board, deck, cards in hand, turn etc. so I am interested in why you would want to work with this when it seems to work properly already.

I am deeply interested in this topic because in my game if a player experiences a disconnect their character will be idle for 5 minutes before logging off unless inside a safe area. The reconnect feature will mean a lot to me in regards to avoid dupes and exploits during reload. Though at this time I have seen nothing wrong with the reconnect except sometimes the character is positioned at 0,0,0

« Last Edit: Sep 26, 16, 12:00:24 PM by nocake »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Reconnecting clients to a game
« Reply #2 on: Sep 26, 16, 01:44:54 PM »

Hmm. When you re-login I am guessing you go through the standard character select and then start in the standard starting area, is that correct?

The default engine behavior when a player logs off is that their account and all other player connection root nodes are unloaded.  This reconnection mechanism allows for a delay of some developer-defined time during which those nodes are detached and thus not unloaded.  When you reconnect while these nodes are still saved, there is no character select and the player is sent directly to the last area and position they were at when they disconnected and their saved root nodes are reestablished just as they were.  If you have ever played Heroes of the Storm, or similar games, when you disconnect during a game and then reconnect, it takes you directly back into the game so you can pick up where you left off. That is what we are aiming for.

With the fact that we are not using seamless areas and each game instance is in a separate area instance, it is possible we could manually put players back in games, but I think this mechanism will save us some time.  But there is really not documentation on the HeroWiki that I can find about this.

Maybe HE-Christopher or some other engineer can better clarify the implications of detaching the root node hierarchies from the player connection.  I am guessing it basically means that non-persisted data about your player account, current character, etc. are not lost when disconnected.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

HE-CHRISTOPHER

  • HeroEngine
  • *****
  • Posts: 424
    • View Profile
Re: Reconnecting clients to a game
« Reply #3 on: Oct 01, 16, 10:07:19 PM »

Reconnection is complicated, and because so much of the logic depends on game specific processing post reconnection.  Root nodes persist automatically independently of the connection.  In order to handle reconnection logic, you must leave the root nodes loaded during a disconnection and then move the connection back to the same area server (reconnecting the account root node) during the reconnection.  In the intervening time, the game logic must interact with the disconnected root nodes to process combat (etc) or provide level of immunity in the game during the disconnection (which can be abused by players since you as a developer can't tell the difference between a "real" disconnect and a forced disconnection by a player trying to cheat).

While we prototyped some reconnection mechanics, ultimately we hit a wall trying to figure out how to generically handle countless game implementations (like yours) when reconnecting a user to the server.  Consequently, while the roughed in mechanics exist we have not been able to extensively test it against (countless) third party implementations.  I believe the existing interface should support reconnection mechanics for your game, but it is possible there are issues we have not foreseen. 

Honestly, reconnection is a very complicated issue with about 30% on our side and 70% relying on the game specific logic to properly restore state upon the player reconnecting.


Ultimately, it should work to allow the root node hierarchies associated to the connection to be unassociated and left loaded in an area server.  The connection on reconnection can (with game specific logic) be redirected to the area server in which the root nodes are loaded and the root nodes associated to the connection (at that point).

There also needs to be some thought on the game logic side for what happens when a user is disconnected (e.g. do you want the server AI to slaughter  your users...what happens if they disconnected on purpose...etc).


All in all, a complicated issue.
Logged
Christopher Larsen
CTO
HeroEngine

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Reconnecting clients to a game
« Reply #4 on: Oct 02, 16, 10:02:17 AM »

Thanks for the insight.

My testing so far shows that the reconnection mechanism in place currently works for the server side.  I did simple tests having 2 players in a clean test area and then disconnecting one. When that player logged back in, the system automatically by-passed the character select and took them (after the splash screen loading) directly to that same clean test area and the character was in the same location.

Since the server continues running, all of the server-side things, including system nodes, should be fine.  The difficulty for us will really come in recreating the client-side state.  Things such as data stored in client system nodes is lost and the disconnect is too fast to try to save it (I think).  So, short of continually saving their updated states to the server (which would be unwieldy to say the least) I believe we will need to recreate their state procedurally based on what the server knows.  Definitely a challenge. And also the set of nodes that were replicated to that client.

As to how to handle it in a gameplay standpoint we are planning to go with a simple approach of pausing gameplay for a period of time where the player can reconnect.  During that time, remaining players may optionally vote to continue without them or end the game, or just continue to wait out the period.

So, I guess no one else has ventured into this, yet.  I'll update on how it goes with any pointers I may come across.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Reconnecting clients to a game
« Reply #5 on: Oct 02, 16, 08:14:16 PM »

Here is one thing I found right away:

The default code for a disconnected client in _OnPlayerConnectionDisconnect() is to glom the class "_playerConnectionDisconnect" onto the account node and it has a timer that unloads the player connection root nodes when it ticks.  But I found that when that unloading happened, there did not seem to be any notification of it happening (that I could find anyways).

So what I did was to derive a class from _playerConnectionDisconnect so that I could override the tick method, and then I used the  override method HE_OnPlayerConnectionDisconnect() to glom my class on instead of the base version.  That allows me to respond to the situation where the player did not reconnect in time.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

ThorShort

  • General Accounts
  • *
  • Posts: 1
    • View Profile
Re: Reconnecting clients to a game
« Reply #6 on: Oct 03, 16, 01:17:11 AM »

Here is one thing I found right away:

The default code for a disconnected client in _OnPlayerConnectionDisconnect() is to glom the class "_playerConnectionDisconnect" onto the account node and it has a timer that unloads the phen24 pills reviewed player connection root nodes when it ticks.  But I found that when that unloading happened, there did not seem to be any notification of it happening (that I could find anyways).

So what I did was to derive a class from _playerConnectionDisconnect so that I could override the tick method, and then I used the  override method HE_OnPlayerConnectionDisconnect() to glom my class on instead of the base version.  That allows me to respond to the situation where the player did not reconnect in time.

And does this solution work well?
« Last Edit: Apr 10, 17, 04:28:22 AM by ThorShort »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Reconnecting clients to a game
« Reply #7 on: Oct 03, 16, 07:46:44 PM »

Yes, in that inside of the overridden tick method I can at that point do what is required of our game for when the player does not reconnect in time.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: Reconnecting clients to a game
« Reply #8 on: Oct 04, 16, 03:14:18 PM »

Thanks for the find on _playerconnectiondisconnect. That will come in handy for me.

Why will recreating your local state be difficult for you? You should be able to write into all the same initiation hooks or copy and slightly alter them to handle the replicated data.

If you need help in testing this just let me know. I have done a lot of work in loading areas and ensuring everything initiates correctly. As well I am willing to bet my house construction mode works on a similar concept as your game mode and reconnect feature will.

I played a few games and I saw what the client represented. It seems like it should be 5-6 systems you need sync?
Monsters on board + info
Turn Information
Player Information (deck,hand,status)
Enemy Players Information(status)
Verify Initiate, tell server you are good
Start Time on server unpausing the game for all the clients and starting into your normal functionality.