Skip to content

Commit

Permalink
fix: RPC could be sent to the wrong players
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Jan 19, 2025
1 parent 4ad9255 commit 9db73ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

# Version 2.23.0
## Version 2.23.1
* Fixed RPCs could be sent twice or to the wrong players if a specific target id is used

## Version 2.23.0
* Added ConfigFile BindConfig and BindConfigInOrder extensions for convenience (thx Searica)
* Fixed compatibility with shudnal's ConfigurationManager

Expand Down
15 changes: 9 additions & 6 deletions JotunnLib/Entities/CustomRPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,27 @@ public IEnumerator SendPackageRoutine(long target, ZPackage package)
{
if (!ZNet.instance)
{
return Enumerable.Empty<object>().GetEnumerator();
yield break;
}

List<ZNetPeer> peers = ZRoutedRpc.instance.m_peers;

if (target == ZRoutedRpc.instance.m_id || target == ZRoutedRpc.Everybody)
if (target == ZRoutedRpc.instance.m_id)
{
byte[] originalData = package.GetArray();
ZPackage jotunnpackage = new ZPackage();
jotunnpackage.Write(originalData);
jotunnpackage.SetPos(0);
ZNet.instance.StartCoroutine(HandlePackageRoutine(ZRoutedRpc.instance.m_id, jotunnpackage, JOTUNN_PACKAGE));
yield break;
}
else

List<ZNetPeer> peers = ZRoutedRpc.instance.m_peers;

if (target != ZRoutedRpc.Everybody)
{
peers = peers.Where(p => p.m_uid == target).ToList();
}

return SendPackageRoutine(peers, package);
yield return SendPackageRoutine(peers, package);
}

/// <summary>
Expand All @@ -172,6 +174,7 @@ public IEnumerator SendPackageRoutine(List<ZNetPeer> peers, ZPackage package)
ZPackage jotunnpackage = new ZPackage();
jotunnpackage.Write(JOTUNN_PACKAGE);
jotunnpackage.Write(originalData);
jotunnpackage.SetPos(0);
package = jotunnpackage;

if (package.Size() > CompressMinSize)
Expand Down

0 comments on commit 9db73ec

Please sign in to comment.