IMessageBase renamed to NetworkMessage

This commit is contained in:
vis2k 2020-09-29 10:18:10 +02:00
parent a565c7c33c
commit 6baaa1d75e
20 changed files with 75 additions and 75 deletions

View File

@ -148,7 +148,7 @@ static bool WeaveMessage(TypeDefinition td)
bool modified = false;
if (td.ImplementsInterface<IMessageBase>())
if (td.ImplementsInterface<NetworkMessage>())
{
// process this and base classes from parent to child order
try

View File

@ -14,7 +14,7 @@ public void SetHostname(string hostname)
public ChatWindow chatWindow;
public class CreatePlayerMessage : IMessageBase
public class CreatePlayerMessage : NetworkMessage
{
public string name;

View File

@ -16,7 +16,7 @@ namespace Mirror
// (probably even shorter)
public static class MessagePacker
{
public static int GetId<T>() where T : IMessageBase
public static int GetId<T>() where T : NetworkMessage
{
return GetId(typeof(T));
}
@ -32,7 +32,7 @@ public static int GetId(Type type)
// pack message before sending
// -> NetworkWriter passed as arg so that we can use .ToArraySegment
// and do an allocation free send before recycling it.
public static void Pack<T>(T message, NetworkWriter writer) where T : IMessageBase
public static void Pack<T>(T message, NetworkWriter writer) where T : NetworkMessage
{
// if it is a value type, just use typeof(T) to avoid boxing
// this works because value types cannot be derived
@ -46,7 +46,7 @@ public static void Pack<T>(T message, NetworkWriter writer) where T : IMessageBa
}
// unpack a message we received
public static T Unpack<T>(byte[] data) where T : IMessageBase, new()
public static T Unpack<T>(byte[] data) where T : NetworkMessage, new()
{
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(data))
{
@ -83,7 +83,7 @@ public static bool UnpackMessage(NetworkReader messageReader, out int msgType)
}
internal static NetworkMessageDelegate MessageHandler<T, C>(Action<C, T> handler, bool requireAuthenication)
where T : IMessageBase, new()
where T : NetworkMessage, new()
where C : NetworkConnection
=> (conn, reader, channelId) =>
{

View File

@ -3,7 +3,7 @@
namespace Mirror
{
public interface IMessageBase
public interface NetworkMessage
{
void Deserialize(NetworkReader reader);
@ -11,7 +11,7 @@ public interface IMessageBase
}
#region Public System Messages
public struct ErrorMessage : IMessageBase
public struct ErrorMessage : NetworkMessage
{
public byte value;
@ -31,42 +31,42 @@ public void Serialize(NetworkWriter writer)
}
}
public struct ReadyMessage : IMessageBase
public struct ReadyMessage : NetworkMessage
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
public struct NotReadyMessage : IMessageBase
public struct NotReadyMessage : NetworkMessage
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
public struct AddPlayerMessage : IMessageBase
public struct AddPlayerMessage : NetworkMessage
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
public struct DisconnectMessage : IMessageBase
public struct DisconnectMessage : NetworkMessage
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
public struct ConnectMessage : IMessageBase
public struct ConnectMessage : NetworkMessage
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
public struct SceneMessage : IMessageBase
public struct SceneMessage : NetworkMessage
{
public string sceneName;
// Normal = 0, LoadAdditive = 1, UnloadAdditive = 2
@ -98,7 +98,7 @@ public enum SceneOperation : byte
#endregion
#region System Messages requried for code gen path
public struct CommandMessage : IMessageBase
public struct CommandMessage : NetworkMessage
{
public uint netId;
public int componentIndex;
@ -125,7 +125,7 @@ public void Serialize(NetworkWriter writer)
}
}
public struct RpcMessage : IMessageBase
public struct RpcMessage : NetworkMessage
{
public uint netId;
public int componentIndex;
@ -154,7 +154,7 @@ public void Serialize(NetworkWriter writer)
#endregion
#region Internal System Messages
public struct SpawnMessage : IMessageBase
public struct SpawnMessage : NetworkMessage
{
/// <summary>
/// netId of new or existing object
@ -228,21 +228,21 @@ public void Serialize(NetworkWriter writer)
}
}
public struct ObjectSpawnStartedMessage : IMessageBase
public struct ObjectSpawnStartedMessage : NetworkMessage
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
public struct ObjectSpawnFinishedMessage : IMessageBase
public struct ObjectSpawnFinishedMessage : NetworkMessage
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
public struct ObjectDestroyMessage : IMessageBase
public struct ObjectDestroyMessage : NetworkMessage
{
public uint netId;
@ -257,7 +257,7 @@ public void Serialize(NetworkWriter writer)
}
}
public struct ObjectHideMessage : IMessageBase
public struct ObjectHideMessage : NetworkMessage
{
public uint netId;
@ -272,7 +272,7 @@ public void Serialize(NetworkWriter writer)
}
}
public struct UpdateVarsMessage : IMessageBase
public struct UpdateVarsMessage : NetworkMessage
{
public uint netId;
// the serialized component data
@ -294,7 +294,7 @@ public void Serialize(NetworkWriter writer)
// A client sends this message to the server
// to calculate RTT and synchronize time
public struct NetworkPingMessage : IMessageBase
public struct NetworkPingMessage : NetworkMessage
{
public double clientTime;
@ -316,7 +316,7 @@ public void Serialize(NetworkWriter writer)
// The server responds with this message
// The client can use this to calculate RTT and sync time
public struct NetworkPongMessage : IMessageBase
public struct NetworkPongMessage : NetworkMessage
{
public double clientTime;
public double serverTime;

View File

@ -172,7 +172,7 @@ static void RemoveTransportHandlers()
/// <param name="message"></param>
/// <param name="channelId"></param>
/// <returns>True if message was sent.</returns>
public static bool Send<T>(T message, int channelId = Channels.DefaultReliable) where T : IMessageBase
public static bool Send<T>(T message, int channelId = Channels.DefaultReliable) where T : NetworkMessage
{
if (connection != null)
{
@ -215,7 +215,7 @@ internal static void RegisterSystemHandlers()
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
int msgType = MessagePacker.GetId<T>();
if (handlers.ContainsKey(msgType))
@ -232,7 +232,7 @@ internal static void RegisterSystemHandlers()
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void RegisterHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void RegisterHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
RegisterHandler((NetworkConnection _, T value) => { handler(value); }, requireAuthentication);
}
@ -244,7 +244,7 @@ internal static void RegisterSystemHandlers()
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void ReplaceHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void ReplaceHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
int msgType = MessagePacker.GetId<T>();
handlers[msgType] = MessagePacker.MessageHandler(handler, requireAuthentication);
@ -257,7 +257,7 @@ internal static void RegisterSystemHandlers()
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void ReplaceHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void ReplaceHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
ReplaceHandler((NetworkConnection _, T value) => { handler(value); }, requireAuthentication);
}
@ -266,7 +266,7 @@ internal static void RegisterSystemHandlers()
/// Unregisters a network message handler.
/// </summary>
/// <typeparam name="T">The message type to unregister.</typeparam>
public static bool UnregisterHandler<T>() where T : IMessageBase
public static bool UnregisterHandler<T>() where T : NetworkMessage
{
// use int to minimize collisions
int msgType = MessagePacker.GetId<T>();

View File

@ -132,7 +132,7 @@ internal void SetHandlers(Dictionary<int, NetworkMessageDelegate> handlers)
/// <param name="msg">The message to send.</param>
/// <param name="channelId">The transport layer channel to send on.</param>
/// <returns></returns>
public bool Send<T>(T msg, int channelId = Channels.DefaultReliable) where T : IMessageBase
public bool Send<T>(T msg, int channelId = Channels.DefaultReliable) where T : NetworkMessage
{
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
{
@ -221,7 +221,7 @@ internal bool InvokeHandler(int msgType, NetworkReader reader, int channelId)
/// <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 : IMessageBase
public bool InvokeHandler<T>(T msg, int channelId) where T : NetworkMessage
{
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
{

View File

@ -309,7 +309,7 @@ public static Uri ReadUri(this NetworkReader reader)
return new Uri(reader.ReadString());
}
public static void ReadMessage<T>(this NetworkReader reader, T msg) where T : IMessageBase
public static void ReadMessage<T>(this NetworkReader reader, T msg) where T : NetworkMessage
{
msg.Deserialize(reader);
}

View File

@ -199,7 +199,7 @@ public static bool RemoveConnection(int connectionId)
/// <param name="identity"></param>
/// <param name="msg"></param>
/// <param name="channelId"></param>
static void SendToObservers<T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable) where T : IMessageBase
static void SendToObservers<T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable) where T : NetworkMessage
{
// Debug.Log("Server.SendToObservers id:" + typeof(T));
@ -238,7 +238,7 @@ static void SendToObservers<T>(NetworkIdentity identity, T msg, int channelId =
/// <param name="channelId">Transport channel to use</param>
/// <param name="sendToReadyOnly">Indicates if only ready clients should receive the message</param>
/// <returns></returns>
public static bool SendToAll<T>(T msg, int channelId = Channels.DefaultReliable, bool sendToReadyOnly = false) where T : IMessageBase
public static bool SendToAll<T>(T msg, int channelId = Channels.DefaultReliable, bool sendToReadyOnly = false) where T : NetworkMessage
{
if (!active)
{
@ -285,7 +285,7 @@ public static bool SendToAll<T>(T msg, int channelId = Channels.DefaultReliable,
/// <param name="msg">Message</param>
/// <param name="channelId">Transport channel to use</param>
/// <returns></returns>
public static bool SendToReady<T>(T msg, int channelId = Channels.DefaultReliable) where T : IMessageBase
public static bool SendToReady<T>(T msg, int channelId = Channels.DefaultReliable) where T : NetworkMessage
{
if (!active)
{
@ -306,7 +306,7 @@ public static bool SendToReady<T>(T msg, int channelId = Channels.DefaultReliabl
/// <param name="includeOwner">Should the owner of the object be included</param>
/// <param name="channelId">Transport channel to use</param>
/// <returns></returns>
public static bool SendToReady<T>(NetworkIdentity identity, T msg, bool includeOwner = true, int channelId = Channels.DefaultReliable) where T : IMessageBase
public static bool SendToReady<T>(NetworkIdentity identity, T msg, bool includeOwner = true, int channelId = Channels.DefaultReliable) where T : NetworkMessage
{
// Debug.Log("Server.SendToReady msgType:" + typeof(T));
@ -352,7 +352,7 @@ public static bool SendToReady<T>(NetworkIdentity identity, T msg, bool includeO
/// <param name="msg">Message</param>
/// <param name="channelId">Transport channel to use</param>
/// <returns></returns>
public static bool SendToReady<T>(NetworkIdentity identity, T msg, int channelId) where T : IMessageBase
public static bool SendToReady<T>(NetworkIdentity identity, T msg, int channelId) where T : NetworkMessage
{
return SendToReady(identity, msg, true, channelId);
}
@ -525,7 +525,7 @@ static void OnError(int connectionId, Exception exception)
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
int msgType = MessagePacker.GetId<T>();
if (handlers.ContainsKey(msgType))
@ -542,7 +542,7 @@ static void OnError(int connectionId, Exception exception)
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void RegisterHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void RegisterHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
RegisterHandler<T>((_, value) => { handler(value); }, requireAuthentication);
}
@ -554,7 +554,7 @@ static void OnError(int connectionId, Exception exception)
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void ReplaceHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void ReplaceHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
int msgType = MessagePacker.GetId<T>();
handlers[msgType] = MessagePacker.MessageHandler(handler, requireAuthentication);
@ -567,7 +567,7 @@ static void OnError(int connectionId, Exception exception)
/// <typeparam name="T">Message type</typeparam>
/// <param name="handler">Function handler which will be invoked when this message type is received.</param>
/// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
public static void ReplaceHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
public static void ReplaceHandler<T>(Action<T> handler, bool requireAuthentication = true) where T : NetworkMessage, new()
{
ReplaceHandler<T>((_, value) => { handler(value); }, requireAuthentication);
}
@ -576,7 +576,7 @@ static void OnError(int connectionId, Exception exception)
/// Unregisters a handler for a particular message type.
/// </summary>
/// <typeparam name="T">Message type</typeparam>
public static void UnregisterHandler<T>() where T : IMessageBase
public static void UnregisterHandler<T>() where T : NetworkMessage
{
int msgType = MessagePacker.GetId<T>();
handlers.Remove(msgType);
@ -596,7 +596,7 @@ public static void ClearHandlers()
/// <typeparam name="T">Message type</typeparam>
/// <param name="identity"></param>
/// <param name="msg"></param>
public static void SendToClientOfPlayer<T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable) where T : IMessageBase
public static void SendToClientOfPlayer<T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable) where T : NetworkMessage
{
if (identity != null)
{

View File

@ -417,7 +417,7 @@ public static void WriteUri(this NetworkWriter writer, Uri uri)
writer.WriteString(uri.ToString());
}
public static void WriteMessage<T>(this NetworkWriter writer, T msg) where T : IMessageBase
public static void WriteMessage<T>(this NetworkWriter writer, T msg) where T : NetworkMessage
{
msg.Serialize(writer);
}

View File

@ -33,7 +33,7 @@ public static MockQuest ReadQuest(this NetworkReader reader)
public class CustomRWTest
{
struct QuestMessage : IMessageBase
struct QuestMessage : NetworkMessage
{
public MockQuest quest;

View File

@ -23,7 +23,7 @@ public static EnumReadWriteTests.MyCustomEnum ReadMyCustomEnum(this NetworkReade
}
public class EnumReadWriteTests
{
public struct ByteMessage : IMessageBase
public struct ByteMessage : NetworkMessage
{
public MyByteEnum byteEnum;
@ -36,7 +36,7 @@ public enum MyByteEnum : byte
A, B, C, D
}
public struct ShortMessage : IMessageBase
public struct ShortMessage : NetworkMessage
{
public MyShortEnum shortEnum;
@ -49,7 +49,7 @@ public enum MyShortEnum : short
E, F, G, H
}
public struct CustomMessage : IMessageBase
public struct CustomMessage : NetworkMessage
{
public MyCustomEnum customEnum;
@ -97,7 +97,7 @@ public void CustomWriterIsUsedForEnum()
// custom writer should write N if it sees O
Assert.That(clientMsg.customEnum, Is.EqualTo(MyCustomEnum.N));
}
T SerializeAndDeserializeMessage<T>(T msg) where T : IMessageBase, new()
T SerializeAndDeserializeMessage<T>(T msg) where T : NetworkMessage, new()
{
NetworkWriter writer = new NetworkWriter();

View File

@ -10,7 +10,7 @@ namespace Mirror.Tests.Generated.CollectionWriters
public class Array_int_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public int[] collection;
@ -78,7 +78,7 @@ public void SendsData()
public class Array_string_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public string[] collection;
@ -146,7 +146,7 @@ public void SendsData()
public class Array_Vector3_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public Vector3[] collection;
@ -214,7 +214,7 @@ public void SendsData()
public class Array_FloatStringStruct_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public FloatStringStruct[] collection;
@ -282,7 +282,7 @@ public void SendsData()
public class Array_ClassWithNoConstructor_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public ClassWithNoConstructor[] collection;
@ -350,7 +350,7 @@ public void SendsData()
public class ArraySegment_int_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public ArraySegment<int> collection;
@ -432,7 +432,7 @@ public void SendsData()
public class ArraySegment_string_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public ArraySegment<string> collection;
@ -514,7 +514,7 @@ public void SendsData()
public class ArraySegment_Vector3_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public ArraySegment<Vector3> collection;
@ -596,7 +596,7 @@ public void SendsData()
public class ArraySegment_FloatStringStruct_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public ArraySegment<FloatStringStruct> collection;
@ -678,7 +678,7 @@ public void SendsData()
public class ArraySegment_ClassWithNoConstructor_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public ArraySegment<ClassWithNoConstructor> collection;
@ -760,7 +760,7 @@ public void SendsData()
public class List_int_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public List<int> collection;
@ -828,7 +828,7 @@ public void SendsData()
public class List_string_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public List<string> collection;
@ -896,7 +896,7 @@ public void SendsData()
public class List_Vector3_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public List<Vector3> collection;
@ -964,7 +964,7 @@ public void SendsData()
public class List_FloatStringStruct_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public List<FloatStringStruct> collection;
@ -1032,7 +1032,7 @@ public void SendsData()
public class List_ClassWithNoConstructor_Test
{
struct Message : IMessageBase
struct Message : NetworkMessage
{
public List<ClassWithNoConstructor> collection;

View File

@ -5,7 +5,7 @@
namespace Mirror.Tests
{
struct TestMessage1 : IMessageBase
struct TestMessage1 : NetworkMessage
{
public int IntValue;
public string StringValue;
@ -33,7 +33,7 @@ public void Serialize(NetworkWriter writer)
}
}
struct TestMessage2 : IMessageBase
struct TestMessage2 : NetworkMessage
{
#pragma warning disable CS0649 // Field is never assigned to
public int IntValue;

View File

@ -2,7 +2,7 @@
namespace Mirror.Tests.MessageTests
{
class NoArgMethodMessage : IMessageBase
struct NoArgMethodMessage : NetworkMessage
{
public int someValue;
@ -15,7 +15,7 @@ public void Serialize(NetworkWriter writer) { }
public void Deserialize(NetworkReader reader) { }
}
class TwoArgMethodMessage : IMessageBase
struct TwoArgMethodMessage : NetworkMessage
{
public int someValue;

View File

@ -16,7 +16,7 @@ public class ScriptableObjectWriterTest
// other types are generated by the weaver
struct ScriptableObjectMessage : IMessageBase
struct ScriptableObjectMessage : NetworkMessage
{
public MyScriptableObject scriptableObject;

View File

@ -2,7 +2,7 @@
namespace Mirror.Tests.StructMessages
{
public struct SomeStructMessage : IMessageBase
public struct SomeStructMessage : NetworkMessage
{
public int someValue;

View File

@ -2,7 +2,7 @@
namespace WeaverMessageTests.AbstractMessageMethods
{
abstract class AbstractMessage : IMessageBase
abstract class AbstractMessage : NetworkMessage
{
public abstract void Deserialize(NetworkReader reader);
public abstract void Serialize(NetworkWriter writer);

View File

@ -6,7 +6,7 @@ namespace WeaverMessageTests.MessageMemberGeneric
{
class HasGeneric<T> { }
struct MessageMemberGeneric : IMessageBase
struct MessageMemberGeneric : NetworkMessage
{
public uint netId;
public Guid assetId;

View File

@ -6,7 +6,7 @@ namespace WeaverMessageTests.MessageMemberInterface
{
interface SuperCoolInterface { }
struct MessageMemberInterface : IMessageBase
struct MessageMemberInterface : NetworkMessage
{
public uint netId;
public Guid assetId;

View File

@ -4,7 +4,7 @@
namespace WeaverMessageTests.MessageValid
{
struct MessageValid : IMessageBase
struct MessageValid : NetworkMessage
{
public uint netId;
public Guid assetId;