-
Notifications
You must be signed in to change notification settings - Fork 458
fix: fixing MTT-1299 #1227
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
fix: fixing MTT-1299 #1227
Changes from 4 commits
efc6e21
191bd7c
006e26f
00e42a1
3c5ed83
c32d87d
b2ba9f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,17 +69,20 @@ internal void __sendServerRpc(FastBufferWriter writer, uint rpcMethodId, ServerR | |
RpcData = writer | ||
}; | ||
|
||
var rpcMessageSize = 0; | ||
|
||
// If we are a server/host then we just no op and send to ourself | ||
if (IsHost || IsServer) | ||
{ | ||
var tempBuffer = new FastBufferReader(writer, Allocator.Temp); | ||
using var tempBuffer = new FastBufferReader(writer, Allocator.Temp); | ||
message.Handle(tempBuffer, NetworkManager, NetworkBehaviourId); | ||
tempBuffer.Dispose(); | ||
|
||
return; | ||
rpcMessageSize = tempBuffer.Length; | ||
} | ||
else | ||
{ | ||
rpcMessageSize = NetworkManager.SendMessage(message, networkDelivery, NetworkManager.ServerClientId, true); | ||
} | ||
|
||
var rpcMessageSize = NetworkManager.SendMessage(message, networkDelivery, NetworkManager.ServerClientId, true); | ||
|
||
#if DEVELOPMENT_BUILD || UNITY_EDITOR | ||
if (NetworkManager.__rpc_name_table.TryGetValue(rpcMethodId, out var rpcMethodName)) | ||
|
@@ -129,24 +132,59 @@ internal unsafe void __sendClientRpc(FastBufferWriter writer, uint rpcMethodId, | |
}; | ||
int messageSize; | ||
|
||
// We check to see if we need to shortcut for the case where we are the host/server and we can send a clientRPC | ||
// to ourself. Sadly we have to figure that out from the list of clientIds :( | ||
ulong serverClientId = ulong.MaxValue; | ||
|
||
if (rpcParams.Send.TargetClientIds != null) | ||
{ | ||
// Copy into a localArray because SendMessage doesn't take IEnumerable, only IReadOnlyList | ||
ulong* localArray = stackalloc ulong[rpcParams.Send.TargetClientIds.Count()]; | ||
var index = 0; | ||
foreach (var clientId in rpcParams.Send.TargetClientIds) | ||
{ | ||
if (clientId == NetworkManager.ServerClientId) | ||
{ | ||
serverClientId = clientId; | ||
continue; | ||
} | ||
|
||
localArray[index++] = clientId; | ||
} | ||
|
||
messageSize = NetworkManager.SendMessage(message, networkDelivery, localArray, index, true); | ||
|
||
} | ||
else if (rpcParams.Send.TargetClientIdsNativeArray != null) | ||
{ | ||
foreach (var clientId in rpcParams.Send.TargetClientIdsNativeArray) | ||
{ | ||
if (clientId == NetworkManager.ServerClientId) | ||
{ | ||
serverClientId = clientId; | ||
|
||
} | ||
} | ||
|
||
messageSize = NetworkManager.SendMessage(message, networkDelivery, rpcParams.Send.TargetClientIdsNativeArray.Value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we remove |
||
} | ||
else | ||
{ | ||
messageSize = NetworkManager.SendMessage(message, networkDelivery, NetworkManager.ConnectedClientsIds, true); | ||
foreach (var clientId in NetworkManager.ConnectedClientsIds) | ||
|
||
{ | ||
if (clientId == NetworkManager.ServerClientId) | ||
{ | ||
serverClientId = clientId; | ||
|
||
} | ||
} | ||
|
||
messageSize = NetworkManager.SendMessage(message, networkDelivery, NetworkManager.ConnectedClientsIds); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then in this case the |
||
} | ||
|
||
// If we are a server/host then we just no op and send to ourself | ||
if (serverClientId != ulong.MaxValue && (IsHost || IsServer)) | ||
|
||
{ | ||
using var tempBuffer = new FastBufferReader(writer, Allocator.Temp); | ||
message.Handle(tempBuffer, NetworkManager, serverClientId); | ||
messageSize = tempBuffer.Length; | ||
} | ||
|
||
#if DEVELOPMENT_BUILD || UNITY_EDITOR | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@becksebenius-unity don't you guys intentionally 0 out "loopback" sends elsewhere in the framework? I could have sworn I saw something like that in some networkvariable update code recently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do. We're currently reconsidering this though - the question of how we represent loopback has been right in the middle of the "what information scope are showing" conversation as we heard some feedback during the hackweek that our current approach is still confusing. More info here - https://unity.slack.com/archives/C01D91UDGKH/p1632845411151700