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

breaking: NetworkClient as component #1372

Closed

Conversation

Lymdun
Copy link
Contributor

@Lymdun Lymdun commented Dec 30, 2019

Alternative to #1341 but without singleton. Weaver updated too.

Note that this PR will allows for unit-testing.

@miwarnec
Copy link
Collaborator

miwarnec commented Dec 30, 2019

image
what about this singleton? this greatly increases circular dependencies

@Lymdun
Copy link
Contributor Author

Lymdun commented Dec 30, 2019

I was planning to remove it in another PR, but can do it in this one if you prefer

@miwarnec
Copy link
Collaborator

please try to do it in this pr

Assets/Mirror/Components/NetworkRoomPlayer.cs Show resolved Hide resolved
@@ -163,7 +163,7 @@ void SceneLoadedForPlayer(NetworkConnection conn, GameObject roomPlayer)
return;

// replace room player with game player
NetworkServer.ReplacePlayerForConnection(conn, gamePlayer, true);
NetworkServer.ReplacePlayerForConnection(conn, client, gamePlayer, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the connection anymore?

@@ -46,7 +46,7 @@ private void OnCreatePlayer(NetworkConnection connection, CreatePlayerMessage cr
playergo.GetComponent<Player>().playerName = createPlayerMessage.name;

// set it as the player
NetworkServer.AddPlayerForConnection(connection, playergo);
NetworkServer.AddPlayerForConnection(connection, client, playergo);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps I'm wrong, but what I understood from my tests is that we need it for OnServerAddPlayer. If we get the NetworkConnection from client.connection, we end up with a NetworkConnectionToServer instead of a NetworkConnectionToClient.

Copy link
Contributor

Choose a reason for hiding this comment

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

ohhhh, I see, and why do we need the client here? this method is supposed to be server side no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, it doesn't need it but only in host-mode case. Perhaps a Mirror bug?

@@ -35,7 +35,7 @@ public override void OnStartServer()
public override void OnStartClient()
{
// register a handler for the authentication response we expect from server
NetworkClient.RegisterHandler<AuthResponseMessage>(OnAuthResponseMessage, false);
NetworkManager.singleton.client.RegisterHandler<AuthResponseMessage>(OnAuthResponseMessage, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about the NetworkManager.singleton calls everywhere?
right now, NetworkClient is static. which imho is way better than the singleton usage here.

@miwarnec miwarnec force-pushed the master branch 2 times, most recently from 2007d1e to a71ecdb Compare January 8, 2020 10:32
@miwarnec
Copy link
Collaborator

closing as discussed in discord

@miwarnec miwarnec closed this Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants