breaking: remove NetworkConnection.InvokeHandler now that it's not needed anymore

This commit is contained in:
vis2k 2021-02-13 16:08:59 +08:00
parent be42976a26
commit 4c12c59f78

View File

@ -185,42 +185,6 @@ internal void RemoveObservers()
visList.Clear();
}
internal bool InvokeHandler(int msgType, NetworkReader reader, int channelId)
{
if (messageHandlers.TryGetValue(msgType, out NetworkMessageDelegate msgDelegate))
{
msgDelegate(this, reader, channelId);
return true;
}
if (logger.LogEnabled()) logger.Log("Unknown message ID " + msgType + " " + this + ". May be due to no existing RegisterHandler for this message.");
return false;
}
/// <summary>
/// This function invokes the registered handler function for a message.
/// <para>Network connections used by the NetworkClient and NetworkServer use this function for handling network messages.</para>
/// </summary>
/// <typeparam name="T">The message type to unregister.</typeparam>
/// <param name="msg">The message object to process.</param>
/// <returns>Returns true if the handler was successfully invoked</returns>
public bool InvokeHandler<T>(T msg, int channelId)
where T : struct, NetworkMessage
{
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
{
// if it is a value type, just use typeof(T) to avoid boxing
// this works because value types cannot be derived
// if it is a reference type (for example NetworkMessage),
// ask the message for the real type
int msgType = MessagePacker.GetId<T>();
MessagePacker.Pack(msg, writer);
ArraySegment<byte> segment = writer.ToArraySegment();
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(segment))
return InvokeHandler(msgType, networkReader, channelId);
}
}
// helper function
protected bool UnpackAndInvoke(NetworkReader reader, int channelId)
{