Skip to content

Commit

Permalink
Fixed issue with Server/Client event subscribers not being invoked if…
Browse files Browse the repository at this point in the history
… added after the Start/Connect call
  • Loading branch information
tom-weiland committed Dec 31, 2021
1 parent 27d56de commit 7b489c8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
Binary file modified Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.dll
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.dll
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions RiptideNetworking/RiptideNetworking/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public void Connect(string hostAddress, byte messageHandlerGroupId = 0)

CreateMessageHandlersDictionary(Assembly.GetCallingAssembly(), messageHandlerGroupId);

client.Connected += Connected;
client.Connected += OnConnected;
client.ConnectionFailed += OnConnectionFailed;
client.MessageReceived += OnMessageReceived;
client.Disconnected += OnDisconnected;
client.ClientConnected += ClientConnected;
client.ClientDisconnected += ClientDisconnected;
client.ClientConnected += OnClientConnected;
client.ClientDisconnected += OnClientDisconnected;
client.Connect(hostAddress);
}

Expand Down Expand Up @@ -149,14 +149,17 @@ public void Disconnect()

private void LocalDisconnect()
{
client.Connected -= Connected;
client.ConnectionFailed -= ConnectionFailed;
client.Connected -= OnConnected;
client.ConnectionFailed -= OnConnectionFailed;
client.MessageReceived -= OnMessageReceived;
client.Disconnected -= Disconnected;
client.ClientConnected -= ClientConnected;
client.ClientDisconnected -= ClientDisconnected;
client.Disconnected -= OnDisconnected;
client.ClientConnected -= OnClientConnected;
client.ClientDisconnected -= OnClientDisconnected;
}

/// <summary>Invokes the <see cref="Connected"/> event.</summary>
private void OnConnected(object s, EventArgs e) => Connected?.Invoke(this, e);

/// <summary>Invokes the <see cref="ConnectionFailed"/> event.</summary>
private void OnConnectionFailed(object s, EventArgs e)
{
Expand All @@ -181,5 +184,11 @@ private void OnDisconnected(object s, EventArgs e)
LocalDisconnect();
Disconnected?.Invoke(this, e);
}

/// <summary>Invokes the <see cref="ClientConnected"/> event.</summary>
private void OnClientConnected(object s, ClientConnectedEventArgs e) => ClientConnected?.Invoke(this, e);

/// <summary>Invokes the <see cref="ClientDisconnected"/> event.</summary>
private void OnClientDisconnected(object s, ClientDisconnectedEventArgs e) => ClientDisconnected?.Invoke(this, e);
}
}
16 changes: 11 additions & 5 deletions RiptideNetworking/RiptideNetworking/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public void Start(ushort port, ushort maxClientCount, byte messageHandlerGroupId

CreateMessageHandlersDictionary(Assembly.GetCallingAssembly(), messageHandlerGroupId);

server.ClientConnected += ClientConnected;
server.ClientConnected += OnClientConnected;
server.MessageReceived += OnMessageReceived;
server.ClientDisconnected += ClientDisconnected;
server.ClientDisconnected += OnClientDisonnected;
server.Start(port, maxClientCount);

IsRunning = true;
}

/// <inheritdoc/>
protected override void CreateMessageHandlersDictionary(Assembly assembly, byte messageHandlerGroupId)
{
Expand Down Expand Up @@ -141,13 +141,16 @@ public void Stop()
return;

server.Shutdown();
server.ClientConnected -= ClientConnected;
server.ClientConnected -= OnClientConnected;
server.MessageReceived -= OnMessageReceived;
server.ClientDisconnected -= ClientDisconnected;
server.ClientDisconnected -= OnClientDisonnected;

IsRunning = false;
}

/// <summary>Invokes the <see cref="ClientConnected"/> event.</summary>
private void OnClientConnected(object sender, ServerClientConnectedEventArgs e) => ClientConnected?.Invoke(this, e);

/// <summary>Invokes the <see cref="MessageReceived"/> event and initiates handling of the received message.</summary>
private void OnMessageReceived(object s, ServerMessageReceivedEventArgs e)
{
Expand All @@ -158,5 +161,8 @@ private void OnMessageReceived(object s, ServerMessageReceivedEventArgs e)
else
RiptideLogger.Log(LogType.warning, $"No server-side handler method found for message ID {e.MessageId}!");
}

/// <summary>Invokes the <see cref="ClientDisconnected"/> event.</summary>
private void OnClientDisonnected(object sender, ClientDisconnectedEventArgs e) => ClientDisconnected?.Invoke(this, e);
}
}

0 comments on commit 7b489c8

Please sign in to comment.