Skip to content

Commit aa8e31f

Browse files
committed
Finished base of the new messaging system
1 parent 0926635 commit aa8e31f

13 files changed

+458
-2303
lines changed

MLAPI-Editor/NetworkingManagerEditor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ public class NetworkingManagerEditor : Editor
1313
private SerializedProperty LogLevelProperty;
1414
private SerializedProperty NetworkConfigProperty;
1515

16-
17-
18-
1916
private ReorderableList networkPrefabsList;
2017
private ReorderableList channelsList;
2118
private ReorderableList messageTypesList;
@@ -84,6 +81,7 @@ private void OnEnable()
8481
EditorGUI.LabelField(rect, "NetworkedPrefabs (Auto Sorted)");
8582
};
8683

84+
/*
8785
messageTypesList = new ReorderableList(serializedObject, serializedObject.FindProperty("NetworkConfig").FindPropertyRelative("MessageTypes"), true, true, true, true);
8886
messageTypesList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
8987
{
@@ -110,6 +108,7 @@ private void OnEnable()
110108
messageTypesList.drawHeaderCallback = (Rect rect) => {
111109
EditorGUI.LabelField(rect, "MessageTypes (Auto Sorted)");
112110
};
111+
*/
113112

114113

115114
channelsList = new ReorderableList(serializedObject, serializedObject.FindProperty("NetworkConfig").FindPropertyRelative("Channels"), true, true, true, true);

MLAPI/Data/AttributeMessageMode.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
namespace MLAPI.Data
1+
using System;
2+
using System.Reflection;
3+
using System.Runtime.InteropServices.ComTypes;
4+
using MLAPI.NetworkingManagerComponents.Binary;
5+
6+
namespace MLAPI.Data
27
{
38
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
49
public enum AttributeMessageMode
@@ -7,5 +12,52 @@ public enum AttributeMessageMode
712
WovenFourByte,
813
WovenEightByte
914
}
15+
16+
public delegate void RpcDelegate(uint clientId, BitReader reader);
17+
18+
public class ReflectionMehtod
19+
{
20+
public MethodInfo method;
21+
public Type[] parameterTypes;
22+
public object[] parameterRefs;
23+
24+
public ReflectionMehtod(MethodInfo methodInfo)
25+
{
26+
method = methodInfo;
27+
ParameterInfo[] parameters = methodInfo.GetParameters();
28+
parameterTypes = new Type[parameters.Length];
29+
parameterRefs = new object[parameters.Length];
30+
31+
for (int i = 0; i < parameters.Length; i++)
32+
{
33+
parameterTypes[i] = parameters[i].ParameterType;
34+
}
35+
}
36+
37+
public void Invoke(object instance, BitReader reader)
38+
{
39+
for (int i = 0; i < parameterTypes.Length; i++)
40+
{
41+
//TODO: BitReader ReadType
42+
parameterRefs[i] = reader.ReadObject(parameterTypes[i]);
43+
}
44+
45+
method.Invoke(instance, parameterRefs);
46+
}
47+
}
48+
49+
public class ServerRPC : Attribute
50+
{
51+
public bool RequireOwnership = true;
52+
internal ReflectionMehtod reflectionMethod;
53+
internal RpcDelegate rpcDelegate;
54+
}
55+
56+
public class ClientRPC : Attribute
57+
{
58+
internal ReflectionMehtod reflectionMethod;
59+
internal RpcDelegate rpcDelegate;
60+
}
61+
1062
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
1163
}

MLAPI/Data/MLAPIConstants.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace MLAPI.Data
2+
{
3+
public static class MLAPIConstants
4+
{
5+
public const string MLAPI_PROTOCOL_VERSION = "2.0.0";
6+
7+
public const ushort MLAPI_CONNECTION_REQUEST = 0;
8+
public const ushort MLAPI_CONNECTION_APPROVED = 1;
9+
public const ushort MLAPI_ADD_OBJECT = 2;
10+
public const ushort MLAPI_CLIENT_DISCONNECT = 3;
11+
public const ushort MLAPI_DESTROY_OBJECT = 4;
12+
public const ushort MLAPI_SWITCH_SCENE = 5;
13+
public const ushort MLAPI_SPAWN_POOL_OBJECT = 6;
14+
public const ushort MLAPI_DESTROY_POOL_OBJECT = 7;
15+
public const ushort MLAPI_CHANGE_OWNER = 8;
16+
public const ushort MLAPI_ADD_OBJECTS = 9;
17+
public const ushort MLAPI_TIME_SYNC = 10;
18+
public const ushort MLAPI_NETWORKED_VAR_DELTA = 11;
19+
public const ushort MLAPI_NETWORKED_VAR_UPDATE = 12;
20+
public const ushort MLAPI_SERVER_RPC = 13;
21+
public const ushort MLAPI_CLIENT_RPC = 14;
22+
}
23+
}

MLAPI/Data/NetworkConfig.cs

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ public class NetworkConfig
4545
[HideInInspector]
4646
public List<Channel> Channels = new List<Channel>();
4747
/// <summary>
48-
/// Registered MessageTypes
49-
/// </summary>
50-
[HideInInspector]
51-
public List<MessageType> MessageTypes = new List<MessageType>();
52-
internal HashSet<ushort> PassthroughMessageHashSet = new HashSet<ushort>();
53-
internal HashSet<string> EncryptedChannelsHashSet = new HashSet<string>();
54-
internal List<string> EncryptedChannels = new List<string>();
55-
/// <summary>
5648
/// A list of SceneNames that can be used during networked games.
5749
/// </summary>
5850
[HideInInspector]
@@ -73,7 +65,7 @@ public class NetworkConfig
7365
/// <summary>
7466
/// The size of the receive message buffer. This is the max message size.
7567
/// </summary>
76-
public int MessageBufferSize = 65535;
68+
public int MessageBufferSize = 1024;
7769
/// <summary>
7870
/// Amount of times per second the receive queue is emptied and all messages inside are processed.
7971
/// </summary>
@@ -142,10 +134,6 @@ public class NetworkConfig
142134
[TextArea]
143135
public string RSAPublicKey = "<RSAKeyValue><Modulus>vBEvOQki/EftWOgwh4G8/nFRvcDJLylc8P7Dhz5m/hpkkNtAMzizNKYUrGbs7sYWlEuMYBOWrzkIDGOMoOsYc9uCi+8EcmNoHDlIhK5yNfZUexYBF551VbvZ625LSBR7kmBxkyo4IPuA09fYCHeUFm3prt4h6aTD0Hjc7ZsJHUU=</Modulus><Exponent>EQ==</Exponent></RSAKeyValue>"; //CHANGE THESE FOR PRODUCTION!
144136
/// <summary>
145-
/// Wheter or not to allow any type of passthrough messages
146-
/// </summary>
147-
public bool AllowPassthroughMessages = true;
148-
/// <summary>
149137
/// Wheter or not to enable scene switching
150138
/// </summary>
151139
public bool EnableSceneSwitching = true;
@@ -156,11 +144,10 @@ public class NetworkConfig
156144
/// <summary>
157145
/// Decides how many bytes to use for Attribute messaging. Leave this to 2 bytes unless you are facing hash collisions
158146
/// </summary>
159-
public AttributeMessageMode AttributeMessageMode = AttributeMessageMode.Disabled;
147+
public AttributeMessageMode AttributeMessageMode = AttributeMessageMode.WovenTwoByte;
160148

161149
private void Sort()
162150
{
163-
MessageTypes = MessageTypes.OrderBy(x => x.Name).ToList();
164151
Channels = Channels.OrderBy(x => x.Name).ToList();
165152
NetworkedPrefabs = NetworkedPrefabs.OrderBy(x => x.name).ToList();
166153
RegisteredScenes.Sort();
@@ -186,13 +173,6 @@ public string ToBase64()
186173
writer.WriteBits((byte)config.Channels[i].Type, 5);
187174
}
188175

189-
writer.WriteUShort((ushort)config.MessageTypes.Count);
190-
for (int i = 0; i < config.MessageTypes.Count; i++)
191-
{
192-
writer.WriteString(config.MessageTypes[i].Name);
193-
writer.WriteBool(config.MessageTypes[i].Passthrough);
194-
}
195-
196176
writer.WriteUShort((ushort)config.RegisteredScenes.Count);
197177
for (int i = 0; i < config.RegisteredScenes.Count; i++)
198178
{
@@ -220,7 +200,6 @@ public string ToBase64()
220200
writer.WriteBool(config.HandleObjectSpawning);
221201
writer.WriteBool(config.EnableEncryption);
222202
writer.WriteBool(config.SignKeyExchange);
223-
writer.WriteBool(config.AllowPassthroughMessages);
224203
writer.WriteBool(config.EnableSceneSwitching);
225204
writer.WriteBool(config.EnableTimeResync);
226205
writer.WriteBits((byte)config.AttributeMessageMode, 3);
@@ -256,18 +235,6 @@ public void FromBase64(string base64, bool createDummyObject = false)
256235
config.Channels.Add(channel);
257236
}
258237

259-
ushort messageTypeCount = reader.ReadUShort();
260-
config.MessageTypes.Clear();
261-
for (int i = 0; i < messageTypeCount; i++)
262-
{
263-
MessageType messageType = new MessageType()
264-
{
265-
Name = reader.ReadString(),
266-
Passthrough = reader.ReadBool()
267-
};
268-
config.MessageTypes.Add(messageType);
269-
}
270-
271238
ushort sceneCount = reader.ReadUShort();
272239
config.RegisteredScenes.Clear();
273240
for (int i = 0; i < sceneCount; i++)
@@ -310,7 +277,6 @@ public void FromBase64(string base64, bool createDummyObject = false)
310277
config.HandleObjectSpawning = reader.ReadBool();
311278
config.EnableEncryption = reader.ReadBool();
312279
config.SignKeyExchange = reader.ReadBool();
313-
config.AllowPassthroughMessages = reader.ReadBool();
314280
config.EnableSceneSwitching = reader.ReadBool();
315281
config.EnableTimeResync = reader.ReadBool();
316282
config.AttributeMessageMode = (AttributeMessageMode)reader.ReadBits(3);
@@ -333,19 +299,15 @@ public ulong GetConfig(bool cache = true)
333299
using (BitWriter writer = BitWriter.Get())
334300
{
335301
writer.WriteUShort(ProtocolVersion);
302+
writer.WriteString(MLAPIConstants.MLAPI_PROTOCOL_VERSION);
303+
336304
for (int i = 0; i < Channels.Count; i++)
337305
{
338306
writer.WriteString(Channels[i].Name);
339307
writer.WriteByte((byte)Channels[i].Type);
340308
if (EnableEncryption)
341309
writer.WriteBool(Channels[i].Encrypted);
342310
}
343-
for (int i = 0; i < MessageTypes.Count; i++)
344-
{
345-
writer.WriteString(MessageTypes[i].Name);
346-
if (AllowPassthroughMessages)
347-
writer.WriteBool(MessageTypes[i].Passthrough);
348-
}
349311
if (EnableSceneSwitching)
350312
{
351313
for (int i = 0; i < RegisteredScenes.Count; i++)
@@ -362,7 +324,6 @@ public ulong GetConfig(bool cache = true)
362324
}
363325
writer.WriteBool(HandleObjectSpawning);
364326
writer.WriteBool(EnableEncryption);
365-
writer.WriteBool(AllowPassthroughMessages);
366327
writer.WriteBool(EnableSceneSwitching);
367328
writer.WriteBool(SignKeyExchange);
368329
writer.WriteBits((byte)AttributeMessageMode, 3);

MLAPI/MLAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<Compile Include="Attributes\TargetRpc.cs" />
9191
<Compile Include="Data\Channel.cs" />
9292
<Compile Include="Data\AttributeMessageMode.cs" />
93+
<Compile Include="Data\MLAPIConstants.cs" />
9394
<Compile Include="Data\NetworkedCollections\NetworkedDictionary.cs" />
9495
<Compile Include="Data\NetworkedCollections\NetworkedList.cs" />
9596
<Compile Include="Data\NetworkedVar.cs" />

0 commit comments

Comments
 (0)