This commit is contained in:
vis2k 2020-07-30 22:38:30 +02:00
parent 0cb84baf97
commit 566c41733d
11 changed files with 69 additions and 39 deletions

View File

@ -3,6 +3,28 @@
namespace Mirror.Authenticators
{
public struct AuthRequestMessage : IMessageBase
{
// use whatever credentials make sense for your game
// for example, you might want to pass the accessToken if using oauth
public string authUsername;
public string authPassword;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
public struct AuthResponseMessage : IMessageBase
{
public byte code;
public string message;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
[AddComponentMenu("Network/Authenticators/BasicAuthenticator")]
public class BasicAuthenticator : NetworkAuthenticator
{
@ -14,20 +36,6 @@ public class BasicAuthenticator : NetworkAuthenticator
public string username;
public string password;
public class AuthRequestMessage : MessageBase
{
// use whatever credentials make sense for your game
// for example, you might want to pass the accessToken if using oauth
public string authUsername;
public string authPassword;
}
public class AuthResponseMessage : MessageBase
{
public byte code;
public string message;
}
public override void OnStartServer()
{
// register a handler for the authentication request we expect from client

View File

@ -1,4 +1,9 @@
namespace Mirror.Discovery
{
public class ServerRequest : MessageBase { }
public struct ServerRequest : IMessageBase
{
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
}

View File

@ -3,7 +3,7 @@
namespace Mirror.Discovery
{
public class ServerResponse : MessageBase
public struct ServerResponse : IMessageBase
{
// The server that sent this
// this is a property so that it is not serialized, but the
@ -14,5 +14,9 @@ public class ServerResponse : MessageBase
// Prevent duplicate server appearance when a connection can be made via LAN on multiple NICs
public long serverId;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
}
}

View File

@ -14,9 +14,13 @@ public void SetHostname(string hostname)
public ChatWindow chatWindow;
public class CreatePlayerMessage : MessageBase
public struct CreatePlayerMessage : IMessageBase
{
public string name;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
public override void OnStartServer()

View File

@ -10,6 +10,7 @@ public interface IMessageBase
void Serialize(NetworkWriter writer);
}
[Obsolete("Please make your message a struct, implement IMessageBase and add empty OnSerialize/OnDeserialize methods. MessageBase was for classes, and we should never send classes to avoid runtime allocations and redundant code. We only use structs in the future. OnSerialize/OnDeserialize content is still auto generated.")]
public abstract class MessageBase : IMessageBase
{
// De-serialize the contents of the reader into this message

View File

@ -11,9 +11,13 @@ public class ArraySegmentWriterTest
// ArraySegment<byte> is a special case, optimized for no copy and no allocation
// other types are generated by the weaver
class ByteArraySegmentMessage : MessageBase
struct ByteArraySegmentMessage : IMessageBase
{
public ArraySegment<byte> array;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
[Test]
@ -84,9 +88,13 @@ public void TestSegmentByteArray()
#region ArraySegment<int>
class IntArraySegmentMessage : MessageBase
struct IntArraySegmentMessage : IMessageBase
{
public ArraySegment<int> array;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
[Test]
@ -140,6 +148,5 @@ public void TestSegmentIntArray()
Assert.That(unpacked.array, Is.EquivalentTo(new int[] { 3, 4 }));
}
#endregion
}
}

View File

@ -4,9 +4,13 @@ namespace Mirror.Tests
[TestFixture]
public class ArrayWriterTest
{
class ArrayByteMessage : MessageBase
struct ArrayByteMessage : IMessageBase
{
public byte[] array;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
[Test]
@ -58,9 +62,13 @@ public void TestDataByteArray()
Assert.That(unpacked.array, Is.EquivalentTo(new byte[] { 3, 4, 5 }));
}
class ArrayIntMessage : MessageBase
struct ArrayIntMessage : IMessageBase
{
public int[] array;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
[Test]

View File

@ -1,22 +1,11 @@
using NUnit.Framework;
using Mirror.Authenticators;
namespace Mirror.Tests
{
[TestFixture]
public class BasicAuthenticatorTest
{
public class AuthRequestMessage : MessageBase
{
public string authUsername;
public string authPassword;
}
public class AuthResponseMessage : MessageBase
{
public byte code;
public string message;
}
[Test]
public void AuthRequestMessageTest()
{

View File

@ -23,7 +23,7 @@ public static void WriteQuest(this NetworkWriter writer, MockQuest quest)
{
writer.WritePackedInt32(quest.Id);
}
public static MockQuest WriteQuest(this NetworkReader reader)
public static MockQuest ReadQuest(this NetworkReader reader)
{
return new MockQuest(reader.ReadPackedInt32());
}
@ -32,10 +32,13 @@ public static MockQuest WriteQuest(this NetworkReader reader)
[TestFixture]
public class CustomRWTest
{
class QuestMessage : MessageBase
struct QuestMessage : IMessageBase
{
public MockQuest quest;
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) {}
public void Deserialize(NetworkReader reader) {}
}
[Test]

View File

@ -4,6 +4,7 @@
"Mirror",
"Mirror.Weaver",
"Mirror.Components",
"Mirror.Authenticators",
"Mirror.Tests.Common"
],
"optionalUnityReferences": [

View File

@ -6,7 +6,7 @@ public struct SomeStructMessage : IMessageBase
{
public int someValue;
// Mirror will automatically implement message that are empty
// Weaver will generate serialization
public void Serialize(NetworkWriter writer) { }
public void Deserialize(NetworkReader reader) { }
}