Skip to content

Commit 16b7fc7

Browse files
authored
feat(networkedvar): Added support for safe networked vars that doesnt spill data (#205)
1 parent bbfea9a commit 16b7fc7

File tree

5 files changed

+269
-52
lines changed

5 files changed

+269
-52
lines changed

MLAPI-Editor/NetworkingManagerEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class NetworkingManagerEditor : Editor
3333
private SerializedProperty secondsHistoryProperty;
3434
private SerializedProperty enableTimeResyncProperty;
3535
private SerializedProperty enableNetworkedVarProperty;
36+
private SerializedProperty ensureNetworkedVarLengthSafetyProperty;
3637
private SerializedProperty forceSamePrefabsProperty;
3738
private SerializedProperty usePrefabSyncProperty;
3839
private SerializedProperty rpcHashSizeProperty;
@@ -106,6 +107,7 @@ private void Init()
106107
secondsHistoryProperty = networkConfigProperty.FindPropertyRelative("SecondsHistory");
107108
enableTimeResyncProperty = networkConfigProperty.FindPropertyRelative("EnableTimeResync");
108109
enableNetworkedVarProperty = networkConfigProperty.FindPropertyRelative("EnableNetworkedVar");
110+
ensureNetworkedVarLengthSafetyProperty = networkConfigProperty.FindPropertyRelative("EnsureNetworkedVarLengthSafety");
109111
forceSamePrefabsProperty = networkConfigProperty.FindPropertyRelative("ForceSamePrefabs");
110112
usePrefabSyncProperty = networkConfigProperty.FindPropertyRelative("UsePrefabSync");
111113
rpcHashSizeProperty = networkConfigProperty.FindPropertyRelative("RpcHashSize");
@@ -139,6 +141,7 @@ private void CheckNullProperties()
139141
secondsHistoryProperty = networkConfigProperty.FindPropertyRelative("SecondsHistory");
140142
enableTimeResyncProperty = networkConfigProperty.FindPropertyRelative("EnableTimeResync");
141143
enableNetworkedVarProperty = networkConfigProperty.FindPropertyRelative("EnableNetworkedVar");
144+
ensureNetworkedVarLengthSafetyProperty = networkConfigProperty.FindPropertyRelative("EnsureNetworkedVarLengthSafety");
142145
forceSamePrefabsProperty = networkConfigProperty.FindPropertyRelative("ForceSamePrefabs");
143146
usePrefabSyncProperty = networkConfigProperty.FindPropertyRelative("UsePrefabSync");
144147
rpcHashSizeProperty = networkConfigProperty.FindPropertyRelative("RpcHashSize");
@@ -279,6 +282,7 @@ public override void OnInspectorGUI()
279282
using (new EditorGUI.DisabledScope(!networkingManager.NetworkConfig.EnableNetworkedVar))
280283
{
281284
EditorGUILayout.PropertyField(maxObjectUpdatesPerTickProperty);
285+
EditorGUILayout.PropertyField(ensureNetworkedVarLengthSafetyProperty);
282286
}
283287

284288
EditorGUILayout.LabelField("Connection", EditorStyles.boldLabel);

MLAPI/Data/NetworkConfig.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public class NetworkConfig
102102
[Tooltip("Whether or not to enable the NetworkedVar system")]
103103
public bool EnableNetworkedVar = true;
104104
/// <summary>
105+
/// Whether or not to ensure that NetworkedVars can be read even if a client accidentally writes where its not allowed to. This costs some CPU and bandwdith.
106+
/// </summary>
107+
[Tooltip("Ensures that NetworkedVars can be read even if a client accidental writes where its not allowed to. This will cost some CPU time and bandwidth")]
108+
public bool EnsureNetworkedVarLengthSafety = false;
109+
/// <summary>
105110
/// Wheter or not the MLAPI should check for differences in the prefabs at connection.
106111
/// If you dynamically add prefabs at runtime, turn this OFF
107112
/// </summary>
@@ -206,6 +211,7 @@ public string ToBase64()
206211
writer.WriteBool(config.SignKeyExchange);
207212
writer.WriteInt32Packed(config.LoadSceneTimeOut);
208213
writer.WriteBool(config.EnableTimeResync);
214+
writer.WriteBool(config.EnsureNetworkedVarLengthSafety);
209215
writer.WriteBits((byte)config.RpcHashSize, 3);
210216
writer.WriteBool(ForceSamePrefabs);
211217
writer.WriteBool(UsePrefabSync);
@@ -250,6 +256,7 @@ public void FromBase64(string base64)
250256
config.SignKeyExchange = reader.ReadBool();
251257
config.LoadSceneTimeOut = reader.ReadInt32Packed();
252258
config.EnableTimeResync = reader.ReadBool();
259+
config.EnsureNetworkedVarLengthSafety = reader.ReadBool();
253260
config.RpcHashSize = (HashSize)reader.ReadBits(3);
254261
config.ForceSamePrefabs = reader.ReadBool();
255262
config.UsePrefabSync = reader.ReadBool();
@@ -296,6 +303,7 @@ public ulong GetConfig(bool cache = true)
296303
writer.WriteBool(EnableNetworkedVar);
297304
writer.WriteBool(ForceSamePrefabs);
298305
writer.WriteBool(UsePrefabSync);
306+
writer.WriteBool(EnsureNetworkedVarLengthSafety);
299307
writer.WriteBool(EnableEncryption);
300308
writer.WriteBool(SignKeyExchange);
301309
writer.WriteBits((byte)RpcHashSize, 3);

0 commit comments

Comments
 (0)