Skip to content

Commit

Permalink
feat(networkedvar): Added support for safe networked vars that doesnt…
Browse files Browse the repository at this point in the history
… spill data (#205)
  • Loading branch information
TwoTenPvP committed Apr 15, 2019
1 parent bbfea9a commit 16b7fc7
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 52 deletions.
4 changes: 4 additions & 0 deletions MLAPI-Editor/NetworkingManagerEditor.cs
Expand Up @@ -33,6 +33,7 @@ public class NetworkingManagerEditor : Editor
private SerializedProperty secondsHistoryProperty;
private SerializedProperty enableTimeResyncProperty;
private SerializedProperty enableNetworkedVarProperty;
private SerializedProperty ensureNetworkedVarLengthSafetyProperty;
private SerializedProperty forceSamePrefabsProperty;
private SerializedProperty usePrefabSyncProperty;
private SerializedProperty rpcHashSizeProperty;
Expand Down Expand Up @@ -106,6 +107,7 @@ private void Init()
secondsHistoryProperty = networkConfigProperty.FindPropertyRelative("SecondsHistory");
enableTimeResyncProperty = networkConfigProperty.FindPropertyRelative("EnableTimeResync");
enableNetworkedVarProperty = networkConfigProperty.FindPropertyRelative("EnableNetworkedVar");
ensureNetworkedVarLengthSafetyProperty = networkConfigProperty.FindPropertyRelative("EnsureNetworkedVarLengthSafety");
forceSamePrefabsProperty = networkConfigProperty.FindPropertyRelative("ForceSamePrefabs");
usePrefabSyncProperty = networkConfigProperty.FindPropertyRelative("UsePrefabSync");
rpcHashSizeProperty = networkConfigProperty.FindPropertyRelative("RpcHashSize");
Expand Down Expand Up @@ -139,6 +141,7 @@ private void CheckNullProperties()
secondsHistoryProperty = networkConfigProperty.FindPropertyRelative("SecondsHistory");
enableTimeResyncProperty = networkConfigProperty.FindPropertyRelative("EnableTimeResync");
enableNetworkedVarProperty = networkConfigProperty.FindPropertyRelative("EnableNetworkedVar");
ensureNetworkedVarLengthSafetyProperty = networkConfigProperty.FindPropertyRelative("EnsureNetworkedVarLengthSafety");
forceSamePrefabsProperty = networkConfigProperty.FindPropertyRelative("ForceSamePrefabs");
usePrefabSyncProperty = networkConfigProperty.FindPropertyRelative("UsePrefabSync");
rpcHashSizeProperty = networkConfigProperty.FindPropertyRelative("RpcHashSize");
Expand Down Expand Up @@ -279,6 +282,7 @@ public override void OnInspectorGUI()
using (new EditorGUI.DisabledScope(!networkingManager.NetworkConfig.EnableNetworkedVar))
{
EditorGUILayout.PropertyField(maxObjectUpdatesPerTickProperty);
EditorGUILayout.PropertyField(ensureNetworkedVarLengthSafetyProperty);
}

EditorGUILayout.LabelField("Connection", EditorStyles.boldLabel);
Expand Down
8 changes: 8 additions & 0 deletions MLAPI/Data/NetworkConfig.cs
Expand Up @@ -102,6 +102,11 @@ public class NetworkConfig
[Tooltip("Whether or not to enable the NetworkedVar system")]
public bool EnableNetworkedVar = true;
/// <summary>
/// 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.
/// </summary>
[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")]
public bool EnsureNetworkedVarLengthSafety = false;
/// <summary>
/// Wheter or not the MLAPI should check for differences in the prefabs at connection.
/// If you dynamically add prefabs at runtime, turn this OFF
/// </summary>
Expand Down Expand Up @@ -206,6 +211,7 @@ public string ToBase64()
writer.WriteBool(config.SignKeyExchange);
writer.WriteInt32Packed(config.LoadSceneTimeOut);
writer.WriteBool(config.EnableTimeResync);
writer.WriteBool(config.EnsureNetworkedVarLengthSafety);
writer.WriteBits((byte)config.RpcHashSize, 3);
writer.WriteBool(ForceSamePrefabs);
writer.WriteBool(UsePrefabSync);
Expand Down Expand Up @@ -250,6 +256,7 @@ public void FromBase64(string base64)
config.SignKeyExchange = reader.ReadBool();
config.LoadSceneTimeOut = reader.ReadInt32Packed();
config.EnableTimeResync = reader.ReadBool();
config.EnsureNetworkedVarLengthSafety = reader.ReadBool();
config.RpcHashSize = (HashSize)reader.ReadBits(3);
config.ForceSamePrefabs = reader.ReadBool();
config.UsePrefabSync = reader.ReadBool();
Expand Down Expand Up @@ -296,6 +303,7 @@ public ulong GetConfig(bool cache = true)
writer.WriteBool(EnableNetworkedVar);
writer.WriteBool(ForceSamePrefabs);
writer.WriteBool(UsePrefabSync);
writer.WriteBool(EnsureNetworkedVarLengthSafety);
writer.WriteBool(EnableEncryption);
writer.WriteBool(SignKeyExchange);
writer.WriteBits((byte)RpcHashSize, 3);
Expand Down

0 comments on commit 16b7fc7

Please sign in to comment.