Page MenuHomeWildfire Games

NetClient and NetServer state comments, renames and cleanup
AcceptedPublic

Authored by elexis on Jun 2 2018, 8:52 PM.

Details

Reviewers
Imarok
Summary

The state model of the NetClient and NetServer is intransparent at times and some names are confusing or contradictory.
This patch adds an exact specification to every state, so that it should be easier to keep track of the code flow.

Rename OnAuthenticate to OnAuthenticateResult in the NetClient because it processes the AuthenticateResult packet and
because it should not be confused with OnAuthenticate in the NetServer which processes the Authenticate packet.

Rename SERVER_STATE_PREGAME, NCS_PREGAME to SERVER_STATE_GAMESETUP, NCS_GAMESETUP.
This avoids confusion with NSS_PREGAME which contrary to the renamed ones includes the loading screen.

Rename NCS_INITIAL_GAMESETUP to NCS_AUTHENTICATED to avoid confusion with the gamesetup stage.

Add missing member initialization in the constructors.

Uses 0 as the second argument for enet_peer_timeout to be consistent with the other call.
(causative confirmed in irc yesterday fwiw)
(The second argument is unneeded since the minimum timeout is about infinity, see also http://enet.bespin.org/group__peer.html#gac48f35cdd39a89318a7b4fc19920b21b)

Test Plan

For every state find all ways to achieve that state and the functions processing that state to determine whether my comments and renames are correct.

Diff Detail

Repository
rP 0 A.D. Public Repository
Branch
/ps/trunk
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 6206
Build 10307: Vulcan BuildJenkins
Build 10306: arc lint + arc unit

Event Timeline

elexis created this revision.Jun 2 2018, 8:52 PM
Vulcan added a subscriber: Vulcan.Jun 2 2018, 8:52 PM

Build failure - The Moirai have given mortals hearts that can endure.

Link to build: https://jenkins.wildfiregames.com/job/differential/620/display/redirect

vladislavbelov added inline comments.
source/network/NetServer.cpp
387

static_cast<int>, while you're at it. Btw, why the m_AutostartPlayers is int? I think it should be size_t.

source/network/NetServer.h
1

2018.

elexis added inline comments.Jun 3 2018, 3:35 PM
source/network/NetServer.h
89

To add to NSS_JOIN_SYNCING:

  • The server started to or finished transfering the simulation state to deserialize and the client has not finished loading the map and deserializing the state yet.
elexis added inline comments.Jun 6 2018, 12:21 PM
source/network/NetClient.h
268

If not the implementation, this block needs comments too. Implementation (.cpp) probably better though.

Almost all OnFoo functions are only executed when a CFooMessage is received, but OnStartGame breaks this pattern because it is called for rejoiners (while OnRejoined is only called if an other client rejoined.)

elexis added inline comments.Jun 6 2018, 12:30 PM
source/network/NetClient.h
268

Since CNetFileReceiveTask_ClientRejoin does // Pretend the server told us to start the game

The proposed renames in the patch description sound sane. ?
The added descriptions are also good. (Besides the comments I gave)
(Needs rebase.)

source/network/NetClient.h
53–54

What do you mean with rejoin?
(Maybe I just forgot something, it was a long time ;))

63

Shouldn't that be joining?
If an observer joins he'd go into that state, but he wouldn't rejoin.

source/network/NetServer.h
50

Not sure if we can call loading a started game. From my understanding the game starts after everyone finished loading.

58–60

Maybe not that this state isn't in use currently?
(Or is it?)

68

dot

89

"transfering" → "transferring"

elexis marked 5 inline comments as done.Nov 12 2018, 5:07 PM
elexis added inline comments.
source/network/NetClient.h
53–54

A rejoin is when a client joins the match after it started and thus doesn't see the gamesetup page?

63

I guess it's historical reason (there were no observers back then) that networking jargon equates rejoin with joining after the game started.

That's in particular the case with all the variable names such as IsRejoining, even in the network packet properties.

source/network/NetServer.cpp
387

Dunno, perhaps because it's user-input and not the product of a vector length? There is a lot of stuff wrong with C++ Autostart.

source/network/NetServer.h
50

Why is the button named "launch game" and the message that is then sent "CStartGameMessage" if it doesn't inform server and clients that the game was started? Every client initializes the CGame object when it receives that message.
It's the purpose to define these terms here and the addressee is the developer, not the player.

58–60

It's unused currently yes. I agree that it it is in the scope to correct state descriptions, but I am reluctant to add TODOs. (We have a ticket for that IIRC and we can remove the state as well if we want to correct it to it's current state.)

Imarok added inline comments.Nov 12 2018, 7:37 PM
source/network/NetClient.h
53–54

Hmm, so with was informed if a rejoin needs to be performed. you mean if it can leave out the gamesetup page?
For me rejoin needs to be performed sounds like the client needs to disconnect to the server and connect again.

63

So we should start introducing the correct terms, right?

source/network/NetServer.h
50

Ok, what about The gamesetup was completed, the game was started and now we begin loading the map.?

elexis marked 3 inline comments as done.Nov 12 2018, 9:26 PM
elexis added inline comments.
source/network/NetClient.h
63

There are 126 occurences in the code that use "rejoin" as the name for the procedure.
The purpose of this patch is to describe the states, not to rewrite everything that uses the word rejoin.
If you want to change the connotation that rejoin = join after gamestart, that can be done in a different patch (preferably after all the other networking patches are in). Should this procedure, packet and variable names be called LateJoin? PostGameStartJoin?

source/network/NetServer.h
50

"we begin loading the map" and "now the map is loading" doesn't change much, but why not.
"we" is ambiguous. We are the readers of the code. It could be the NetClients, the NetServer, both, or even further related instances. (I prefered to repeat the word user and Wildfire Games 30 times in the the ToS / PP for that reason too). It should state which instance we talk about.
So it should be "all clients started loading the map".

Imarok added inline comments.Nov 17 2018, 8:50 PM
source/network/NetClient.h
63

What about The client is joining a running match (Called rejoin in most of networking code)?

source/network/NetServer.h
50

What about The gamesetup was completed, the game was started and the map started loading.?

So it should be "all clients started loading the map".

That is also fine.

elexis marked an inline comment as done.Nov 21 2018, 10:16 AM
In D1556#66171, @Imarok wrote:

The proposed renames in the patch description sound sane. ?
The added descriptions are also good. (Besides the comments I gave)

(There are two further small changes in this diff, in case)

(Needs rebase.)

(Can do when committing unless you really want to test it)

source/network/NetClient.h
63

Not most, in _all_ of the C++ and JS code.
The string displayed in the ingame chat for observers is the only place that differs from this.

Imarok accepted this revision.Nov 24 2018, 6:09 PM

Assuming you the renames are correct and the proposed changes are made.

This revision is now accepted and ready to land.Nov 24 2018, 6:09 PM
Imarok added a comment.Mar 3 2019, 5:31 PM

What are you waiting for? ;)