This commit is contained in:
mischa 2024-04-24 11:53:20 +08:00 committed by MrGadget
parent 78d511f65f
commit 4a1be60ad7

View File

@ -329,7 +329,7 @@ internal static void OnTransportData(ArraySegment<byte> data, int channelId)
} }
else else
Debug.LogWarning($"NetworkClient: failed to add batch."); Debug.LogWarning($"NetworkClient: failed to add batch.");
return; return;
} }
@ -573,10 +573,10 @@ public static void ReplaceHandler<T>(Action<NetworkConnection, T> handler, bool
// so let's wrap it to ignore the NetworkConnection parameter. // so let's wrap it to ignore the NetworkConnection parameter.
// it's not needed on client. it's always NetworkClient.connection. // it's not needed on client. it's always NetworkClient.connection.
ushort msgType = NetworkMessageId<T>.Id; ushort msgType = NetworkMessageId<T>.Id;
// register Id <> Type in lookup for debugging. // register Id <> Type in lookup for debugging.
NetworkMessages.Lookup[msgType] = typeof(T); NetworkMessages.Lookup[msgType] = typeof(T);
void HandlerWrapped(NetworkConnection _, T value) => handler(_, value); void HandlerWrapped(NetworkConnection _, T value) => handler(_, value);
handlers[msgType] = NetworkMessages.WrapHandler((Action<NetworkConnection, T>)HandlerWrapped, requireAuthentication, exceptionsDisconnect); handlers[msgType] = NetworkMessages.WrapHandler((Action<NetworkConnection, T>)HandlerWrapped, requireAuthentication, exceptionsDisconnect);
} }
@ -591,10 +591,10 @@ public static void ReplaceHandler<T>(Action<T> handler, bool requireAuthenticati
// so let's wrap it to ignore the NetworkConnection parameter. // so let's wrap it to ignore the NetworkConnection parameter.
// it's not needed on client. it's always NetworkClient.connection. // it's not needed on client. it's always NetworkClient.connection.
ushort msgType = NetworkMessageId<T>.Id; ushort msgType = NetworkMessageId<T>.Id;
// register Id <> Type in lookup for debugging. // register Id <> Type in lookup for debugging.
NetworkMessages.Lookup[msgType] = typeof(T); NetworkMessages.Lookup[msgType] = typeof(T);
void HandlerWrapped(NetworkConnection _, T value) => handler(value); void HandlerWrapped(NetworkConnection _, T value) => handler(value);
handlers[msgType] = NetworkMessages.WrapHandler((Action<NetworkConnection, T>)HandlerWrapped, requireAuthentication, exceptionsDisconnect); handlers[msgType] = NetworkMessages.WrapHandler((Action<NetworkConnection, T>)HandlerWrapped, requireAuthentication, exceptionsDisconnect);
} }
@ -609,10 +609,10 @@ public static void ReplaceHandler<T>(Action<T, int> handler, bool requireAuthent
// so let's wrap it to ignore the NetworkConnection parameter. // so let's wrap it to ignore the NetworkConnection parameter.
// it's not needed on client. it's always NetworkClient.connection. // it's not needed on client. it's always NetworkClient.connection.
ushort msgType = NetworkMessageId<T>.Id; ushort msgType = NetworkMessageId<T>.Id;
// register Id <> Type in lookup for debugging. // register Id <> Type in lookup for debugging.
NetworkMessages.Lookup[msgType] = typeof(T); NetworkMessages.Lookup[msgType] = typeof(T);
void HandlerWrapped(NetworkConnection _, T value, int channelId) => handler(value, channelId); void HandlerWrapped(NetworkConnection _, T value, int channelId) => handler(value, channelId);
handlers[msgType] = NetworkMessages.WrapHandler((Action<NetworkConnection, T, int>)HandlerWrapped, requireAuthentication, exceptionsDisconnect); handlers[msgType] = NetworkMessages.WrapHandler((Action<NetworkConnection, T, int>)HandlerWrapped, requireAuthentication, exceptionsDisconnect);
} }