mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
so far
This commit is contained in:
parent
0cb84baf97
commit
566c41733d
@ -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
|
||||
|
@ -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) {}
|
||||
}
|
||||
}
|
||||
|
@ -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) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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]
|
||||
|
@ -4,6 +4,7 @@
|
||||
"Mirror",
|
||||
"Mirror.Weaver",
|
||||
"Mirror.Components",
|
||||
"Mirror.Authenticators",
|
||||
"Mirror.Tests.Common"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
|
@ -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) { }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user