From 7b42bbfd3a72ebd190df2a4c038ccd83d562bda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Cor=C3=A9n?= <2108U9@gmail.com> Date: Sat, 31 Mar 2018 09:07:42 +0200 Subject: [PATCH] Added XML documentation to public methods --- MLAPI/Attributes/SyncedVar.cs | 6 + MLAPI/Data/ClientIdKey.cs | 16 ++- MLAPI/Data/FieldType.cs | 3 + MLAPI/Data/NetworkedClient.cs | 15 +++ MLAPI/Data/NetworkingConfiguration.cs | 94 ++++++++++++- .../MonoBehaviours/Core/NetworkedBehaviour.cs | 123 +++++++++++++++++- MLAPI/MonoBehaviours/Core/NetworkedObject.cs | 45 ++++++- .../MonoBehaviours/Core/NetworkingManager.cs | 65 ++++++++- .../CryptographyHelper.cs | 12 ++ .../LagCompensationManager.cs | 10 ++ .../MessageChunker.cs | 36 ++++- .../NetworkPoolManager.cs | 22 +++- .../NetworkSceneManager.cs | 4 + 13 files changed, 439 insertions(+), 12 deletions(-) diff --git a/MLAPI/Attributes/SyncedVar.cs b/MLAPI/Attributes/SyncedVar.cs index 5147a3f..49758c5 100644 --- a/MLAPI/Attributes/SyncedVar.cs +++ b/MLAPI/Attributes/SyncedVar.cs @@ -2,9 +2,15 @@ namespace MLAPI.Attributes { + /// + /// The attribute to use for variables that should be automatically. replicated from Server to Client. + /// [AttributeUsage(AttributeTargets.Field)] public class SyncedVar : Attribute { + /// + /// The method name to invoke when the SyncVar get's updated. + /// public string hook; public SyncedVar() diff --git a/MLAPI/Data/ClientIdKey.cs b/MLAPI/Data/ClientIdKey.cs index 885a373..cf8d941 100644 --- a/MLAPI/Data/ClientIdKey.cs +++ b/MLAPI/Data/ClientIdKey.cs @@ -1,10 +1,24 @@ namespace MLAPI.Data { - struct ClientIdKey + /// + /// A struct representing a client. Contains a hostId and a connectionId. + /// + internal struct ClientIdKey { + /// + /// The NetworkTransport hostId + /// internal readonly int hostId; + /// + /// The NetworkTransport connectionId + /// internal readonly int connectionId; + /// + /// Creates a new ClientIdKey + /// + /// The NetworkTransport hostId + /// The NetworkTransport connectionId internal ClientIdKey (int hostId, int connectionId) { this.hostId = hostId; diff --git a/MLAPI/Data/FieldType.cs b/MLAPI/Data/FieldType.cs index 2c935e7..ed9be12 100644 --- a/MLAPI/Data/FieldType.cs +++ b/MLAPI/Data/FieldType.cs @@ -1,5 +1,8 @@ namespace MLAPI.Data { + /// + /// The datatype used to classify SyncedVars + /// internal enum FieldType { Bool, diff --git a/MLAPI/Data/NetworkedClient.cs b/MLAPI/Data/NetworkedClient.cs index 135e778..d21736e 100644 --- a/MLAPI/Data/NetworkedClient.cs +++ b/MLAPI/Data/NetworkedClient.cs @@ -3,11 +3,26 @@ using UnityEngine; namespace MLAPI { + /// + /// A NetworkedClient + /// public class NetworkedClient { + /// + /// The Id of the NetworkedClient + /// public int ClientId; + /// + /// The PlayerObject of the Client + /// public GameObject PlayerObject; + /// + /// The NetworkedObject's owned by this Client + /// public List OwnedObjects = new List(); + /// + /// The encryption key used for this client + /// public byte[] AesKey; } } diff --git a/MLAPI/Data/NetworkingConfiguration.cs b/MLAPI/Data/NetworkingConfiguration.cs index f313ce3..fd4fd15 100644 --- a/MLAPI/Data/NetworkingConfiguration.cs +++ b/MLAPI/Data/NetworkingConfiguration.cs @@ -8,38 +8,123 @@ namespace MLAPI { public class NetworkingConfiguration { + /// + /// The protocol version. Different versions doesn't talk to each other. + /// public ushort ProtocolVersion = 0; + /// + /// Channels used by the NetworkedTransport + /// public SortedDictionary Channels = new SortedDictionary(); + /// + /// Registered MessageTypes + /// public List MessageTypes = new List(); + /// + /// List of MessageTypes that can be passed through by Server. MessageTypes in this list should thus not be trusted to as great of an extent as normal messages. + /// public List PassthroughMessageTypes = new List(); + /// + /// Internal collection of Passthrough MessageTypes + /// internal HashSet RegisteredPassthroughMessageTypes = new HashSet(); + /// + /// Set of channels that will have all message contents encrypted when used + /// public HashSet EncryptedChannels = new HashSet(); + /// + /// A list of SceneNames that can be used during networked games. + /// public List RegisteredScenes = new List(); + /// + /// The size of the receive message buffer. This is the max message size. + /// public int MessageBufferSize = 65535; + /// + /// Amount of times per second the receive queue is emptied and all messages inside are processed. + /// public int ReceiveTickrate = 64; + /// + /// The max amount of messages to process per ReceiveTickrate. This is to prevent flooding. + /// public int MaxReceiveEventsPerTickRate = 500; + /// + /// The amount of times per second every pending message will be sent away. + /// public int SendTickrate = 64; + /// + /// The amount of times per second internal frame events will occur, examples include SyncedVar send checking. + /// public int EventTickrate = 64; + /// + /// The max amount of Clients that can connect. + /// public int MaxConnections = 100; + /// + /// The port for the NetworkTransport to use + /// public int Port = 7777; + /// + /// The address to connect to + /// public string Address = "127.0.0.1"; + /// + /// The amount of seconds to wait for handshake to complete before timing out a client + /// public int ClientConnectionBufferTimeout = 10; + /// + /// Wheter or not to use connection approval + /// public bool ConnectionApproval = false; + /// + /// The callback to invoke when a connection has to be decided if it should get approved + /// public Action> ConnectionApprovalCallback = null; + /// + /// The data to send during connection which can be used to decide on if a client should get accepted + /// public byte[] ConnectionData = new byte[0]; + /// + /// The amount of seconds to keep a lag compensation position history + /// public float SecondsHistory = 5; + /// + /// Wheter or not to make the library handle object spawning + /// public bool HandleObjectSpawning = true; - + /// + /// Wheter or not to enable encryption + /// public bool EnableEncryption = true; + /// + /// Wheter or not to enable signed diffie hellman key exchange. + /// public bool SignKeyExchange = true; + /// + /// Private RSA XML key to use for signing key exchange + /// public string RSAPrivateKey = "vBEvOQki/EftWOgwh4G8/nFRvcDJLylc8P7Dhz5m/hpkkNtAMzizNKYUrGbs7sYWlEuMYBOWrzkIDGOMoOsYc9uCi+8EcmNoHDlIhK5yNfZUexYBF551VbvZ625LSBR7kmBxkyo4IPuA09fYCHeUFm3prt4h6aTD0Hjc7ZsJHUU=EQ==

ydgcrq5qLJOdDQibD3m9+o3/dkKoFeCC110dnMgdpEteCruyBdL0zjGKKvjjgy3XTSSp43EN591NiXaBp0JtDw==

7obHrUnUCsSHUsIJ7+JOrupcGrQ0XaYcQ+Uwb2v7d2YUzwZ46U4gI9snfD2J0tc3DGEh3v3G0Q8q7bxEe3H4aw==L34k3c6vkgSdbHp+1nb/hj+HZx6+I0PijQbZyolwYuSOmR0a1DGjA1bzVWe9D86NAxevgM9OkOjG8yrxVIgZqQ==OB+2gyBuIKa2bdNNodrlVlVC2RtXnZB/HwjAGjeGdnJfP8VJoE6eJo3rLEq3BG7fxq1xYaUfuLhGVg4uOyngGQ==o97PimYu58qH5eFmySRCIsyhBr/tK2GM17Zd9QQPJZRSorrhIJn1m6gwQ/G5aJLIM/3Yl04CoyqmQGsPXMzW2w==CxAR1i22w4vCquB7U0Pd8Nl9R2Wxez6rHTwpnoszPB+rkAzlqKj7e5FMgpykhoQfciKPyWqQZKkAeTMIRbN56JinvpAt5POId/28HDd5xjGymHE81k3RzoHqzQXFIOF1TSYKUWzjPPF/TU4nn7auD4i6lOODATsMqtLr5DRBN/0=
"; //CHANGE THESE FOR PRODUCTION! + /// + /// Public RSA XML key to use for signing key exchange + /// public string RSAPublicKey = "vBEvOQki/EftWOgwh4G8/nFRvcDJLylc8P7Dhz5m/hpkkNtAMzizNKYUrGbs7sYWlEuMYBOWrzkIDGOMoOsYc9uCi+8EcmNoHDlIhK5yNfZUexYBF551VbvZ625LSBR7kmBxkyo4IPuA09fYCHeUFm3prt4h6aTD0Hjc7ZsJHUU=EQ=="; //CHANGE THESE FOR PRODUCTION! - + /// + /// Wheter or not to allow any type of passthrough messages + /// public bool AllowPassthroughMessages = true; + /// + /// Wheter or not to enable scene switching + /// public bool EnableSceneSwitching = false; //Cached config hash private byte[] ConfigHash = null; + + /// + /// Gets a SHA256 hash of parts of the NetworkingConfiguration instance + /// + /// + /// public byte[] GetConfig(bool cache = true) { if (ConfigHash != null && cache) @@ -92,6 +177,11 @@ namespace MLAPI } } + /// + /// Compares a SHA256 hash with the current NetworkingConfiguration instances hash + /// + /// + /// public bool CompareConfig(byte[] hash) { byte[] localConfigHash = GetConfig(); diff --git a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs index 5997db2..8836a71 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs @@ -12,7 +12,13 @@ namespace MLAPI { public abstract class NetworkedBehaviour : MonoBehaviour { + /// + /// The minimum delay in seconds between SyncedVar sends + /// public float SyncVarSyncDelay = 0.1f; + /// + /// Gets if the object is the the personal clients player object + /// public bool isLocalPlayer { get @@ -20,6 +26,9 @@ namespace MLAPI return networkedObject.isLocalPlayer; } } + /// + /// Gets if the object is owned by the local player + /// public bool isOwner { get @@ -27,6 +36,9 @@ namespace MLAPI return networkedObject.isOwner; } } + /// + /// Gets if we are executing as server + /// protected bool isServer { get @@ -34,6 +46,9 @@ namespace MLAPI return NetworkingManager.singleton.isServer; } } + /// + /// Gets if we are executing as client + /// protected bool isClient { get @@ -41,6 +56,9 @@ namespace MLAPI return NetworkingManager.singleton.isClient; } } + /// + /// Gets if we are executing as Host, I.E Server and Client + /// protected bool isHost { get @@ -48,6 +66,9 @@ namespace MLAPI return NetworkingManager.singleton.isHost; } } + /// + /// The NetworkedObject that owns this NetworkedBehaviour instance + /// public NetworkedObject networkedObject { get @@ -60,6 +81,9 @@ namespace MLAPI } } private NetworkedObject _networkedObject = null; + /// + /// The NetworkId of the NetworkedObject that owns the NetworkedBehaviour instance + /// public uint networkId { get @@ -67,7 +91,9 @@ namespace MLAPI return networkedObject.NetworkId; } } - + /// + /// The clientId that owns the NetworkedObject + /// public int ownerClientId { get @@ -617,6 +643,12 @@ namespace MLAPI #endregion #region SEND METHODS + /// + /// Sends a buffer to the server from client + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToServer(string messageType, string channelName, byte[] data) { if(MessageManager.messageTypes[messageType] < 32) @@ -632,6 +664,12 @@ namespace MLAPI NetworkingManager.singleton.Send(NetworkingManager.singleton.serverClientId, messageType, channelName, data); } + /// + /// Sends a buffer to the server from client. Only handlers on this NetworkedBehaviour will get invoked + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToServerTarget(string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -647,6 +685,12 @@ namespace MLAPI NetworkingManager.singleton.Send(NetworkingManager.singleton.serverClientId, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to the server from client + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToLocalClient(string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -662,6 +706,12 @@ namespace MLAPI NetworkingManager.singleton.Send(ownerClientId, messageType, channelName, data); } + /// + /// Sends a buffer to the client that owns this object from the server. Only handlers on this NetworkedBehaviour will get invoked + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToLocalClientTarget(string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -677,6 +727,12 @@ namespace MLAPI NetworkingManager.singleton.Send(ownerClientId, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to all clients except to the owner object from the server + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToNonLocalClients(string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -692,6 +748,12 @@ namespace MLAPI NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId); } + /// + /// Sends a buffer to all clients except to the owner object from the server. Only handlers on this NetworkedBehaviour will get invoked + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToNonLocalClientsTarget(string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -707,6 +769,13 @@ namespace MLAPI NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to a client with a given clientId from Server + /// + /// The clientId to send the message to + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClient(int clientId, string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -722,6 +791,13 @@ namespace MLAPI NetworkingManager.singleton.Send(clientId, messageType, channelName, data); } + /// + /// Sends a buffer to a client with a given clientId from Server. Only handlers on this NetworkedBehaviour gets invoked + /// + /// The clientId to send the message to + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClientTarget(int clientId, string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -737,6 +813,13 @@ namespace MLAPI NetworkingManager.singleton.Send(clientId, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to multiple clients from the server + /// + /// The clientId's to send to + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClients(int[] clientIds, string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -752,6 +835,13 @@ namespace MLAPI NetworkingManager.singleton.Send(clientIds, messageType, channelName, data); } + /// + /// Sends a buffer to multiple clients from the server. Only handlers on this NetworkedBehaviour gets invoked + /// + /// The clientId's to send to + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClientsTarget(int[] clientIds, string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -767,6 +857,13 @@ namespace MLAPI NetworkingManager.singleton.Send(clientIds, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to multiple clients from the server + /// + /// The clientId's to send to + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClients(List clientIds, string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -782,6 +879,13 @@ namespace MLAPI NetworkingManager.singleton.Send(clientIds, messageType, channelName, data); } + /// + /// Sends a buffer to multiple clients from the server. Only handlers on this NetworkedBehaviour gets invoked + /// + /// The clientId's to send to + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClientsTarget(List clientIds, string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -797,6 +901,12 @@ namespace MLAPI NetworkingManager.singleton.Send(clientIds, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to all clients from the server + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClients(string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -812,6 +922,12 @@ namespace MLAPI NetworkingManager.singleton.Send(messageType, channelName, data); } + /// + /// Sends a buffer to all clients from the server. Only handlers on this NetworkedBehaviour will get invoked + /// + /// User defined messageType + /// User defined channelName + /// The binary data to send protected void SendToClientsTarget(string messageType, string channelName, byte[] data) { if (MessageManager.messageTypes[messageType] < 32) @@ -828,6 +944,11 @@ namespace MLAPI } #endregion + /// + /// Gets the local instance of a object with a given NetworkId + /// + /// + /// protected NetworkedObject GetNetworkedObject(uint networkId) { return SpawnManager.spawnedObjects[networkId]; diff --git a/MLAPI/MonoBehaviours/Core/NetworkedObject.cs b/MLAPI/MonoBehaviours/Core/NetworkedObject.cs index ab48ca2..62f9c1d 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkedObject.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkedObject.cs @@ -8,19 +8,43 @@ namespace MLAPI [AddComponentMenu("MLAPI/NetworkedObject", -99)] public class NetworkedObject : MonoBehaviour { + /// + /// The unique ID of this object that is synced across the network + /// [HideInInspector] public uint NetworkId; + /// + /// The clientId of the owner of this NetworkedObject + /// [HideInInspector] public int OwnerClientId = -2; + /// + /// The index of the prefab used to spawn this in the spawnablePrefabs list + /// [HideInInspector] public int SpawnablePrefabIndex; + /// + /// Gets if this object is a player object + /// [HideInInspector] public bool isPlayerObject = false; + /// + /// Gets or sets if this object should be replicated across the network + /// public bool ServerOnly = false; + /// + /// Gets if this object is part of a pool + /// [HideInInspector] public bool isPooledObject = false; + /// + /// Gets the poolId this object is part of + /// [HideInInspector] public ushort PoolId; + /// + /// Gets if the object is the the personal clients player object + /// public bool isLocalPlayer { get @@ -28,7 +52,9 @@ namespace MLAPI return isPlayerObject && (OwnerClientId == NetworkingManager.singleton.MyClientId || (OwnerClientId == -1 && NetworkingManager.singleton.isHost)); } } - + /// + /// Gets if the object is owned by the local player + /// public bool isOwner { get @@ -44,21 +70,32 @@ namespace MLAPI internal bool isSpawned = false; + /// + /// Spawns this GameObject across the network. Can only be called from the Server + /// public void Spawn() { SpawnManager.OnSpawnObject(this); } - + /// + /// Spawns an object across the network with a given owner. Can only be called from server + /// + /// The clientId to own the object public void SpawnWithOwnership(int clientId) { SpawnManager.OnSpawnObject(this, clientId); } - + /// + /// Removes all ownership of an object from any client. Can only be called from server + /// public void RemoveOwnership() { SpawnManager.RemoveOwnership(NetworkId); } - + /// + /// Changes the owner of the object. Can only be called from server + /// + /// The new owner clientId public void ChangeOwnership(int newOwnerClientId) { SpawnManager.ChangeOwnership(NetworkId, newOwnerClientId); diff --git a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs index d9f244a..034bff8 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs @@ -14,16 +14,39 @@ namespace MLAPI [AddComponentMenu("MLAPI/NetworkingManager", -100)] public class NetworkingManager : MonoBehaviour { + /// + /// A syncronized time, represents the time in seconds since the server application started. Is replicated across all clients + /// public static float NetworkTime; + /// + /// Gets or sets if the NetworkingManager should be marked as DontDestroyOnLoad + /// public bool DontDestroy = true; + /// + /// Gets or sets if the application should be set to run in background + /// public bool RunInBackground = true; + /// + /// A list of spawnable prefabs + /// public List SpawnablePrefabs; + /// + /// The default prefab to give to players + /// public GameObject DefaultPlayerPrefab; + /// + /// The singleton instance of the NetworkingManager + /// public static NetworkingManager singleton; - //Client only, what my connectionId is on the server + /// + /// The clientId the server calls the local client by, only valid for clients + /// [HideInInspector] public int MyClientId; internal Dictionary connectedClients; + /// + /// Gets a dictionary of connected clients + /// public Dictionary ConnectedClients { get @@ -34,6 +57,9 @@ namespace MLAPI internal HashSet pendingClients; internal bool isServer; internal bool isClient; + /// + /// Gets if we are running as host + /// public bool isHost { get @@ -44,12 +70,26 @@ namespace MLAPI private bool isListening; private byte[] messageBuffer; internal int serverClientId; + /// + /// Gets if we are connected as a client + /// [HideInInspector] public bool IsClientConnected; + /// + /// The callback to invoke once a client connects + /// public Action OnClientConnectedCallback = null; + /// + /// The callback to invoke when a client disconnects + /// public Action OnClientDisconnectCallback = null; + /// + /// The callback to invoke once the server is ready + /// public Action OnServerStarted = null; - + /// + /// The current NetworkingConfiguration + /// public NetworkingConfiguration NetworkConfig; private EllipticDiffieHellman clientDiffieHellman; @@ -199,6 +239,10 @@ namespace MLAPI return cConfig; } + /// + /// Starts a server with a given NetworkingConfiguration + /// + /// The NetworkingConfiguration to use public void StartServer(NetworkingConfiguration netConfig) { ConnectionConfig cConfig = Init(netConfig); @@ -219,6 +263,10 @@ namespace MLAPI OnServerStarted.Invoke(); } + /// + /// Starts a client with a given NetworkingConfiguration + /// + /// The NetworkingConfiguration to use public void StartClient(NetworkingConfiguration netConfig) { ConnectionConfig cConfig = Init(netConfig); @@ -231,6 +279,9 @@ namespace MLAPI serverClientId = NetworkTransport.Connect(hostId, NetworkConfig.Address, NetworkConfig.Port, 0, out error); } + /// + /// Stops the running server + /// public void StopServer() { HashSet sentIds = new HashSet(); @@ -254,18 +305,28 @@ namespace MLAPI Shutdown(); } + /// + /// Stops the running host + /// public void StopHost() { StopServer(); //We don't stop client since we dont actually have a transport connection to our own host. We just handle host messages directly in the MLAPI } + /// + /// Stops the running client + /// public void StopClient() { NetworkTransport.Disconnect(hostId, serverClientId, out error); Shutdown(); } + /// + /// Starts a Host with a given NetworkingConfiguration + /// + /// The NetworkingConfiguration to use public void StartHost(NetworkingConfiguration netConfig) { ConnectionConfig cConfig = Init(netConfig); diff --git a/MLAPI/NetworkingManagerComponents/CryptographyHelper.cs b/MLAPI/NetworkingManagerComponents/CryptographyHelper.cs index 02344e8..126f418 100644 --- a/MLAPI/NetworkingManagerComponents/CryptographyHelper.cs +++ b/MLAPI/NetworkingManagerComponents/CryptographyHelper.cs @@ -6,6 +6,12 @@ namespace MLAPI.NetworkingManagerComponents { public static class CryptographyHelper { + /// + /// Decrypts a message with AES with a given key and a salt that is encoded as the first 16 bytes of the buffer + /// + /// The buffer with the salt + /// The key to use + /// The decrypted byte array public static byte[] Decrypt(byte[] encryptedBuffer, byte[] key) { byte[] iv = new byte[16]; @@ -26,6 +32,12 @@ namespace MLAPI.NetworkingManagerComponents } } + /// + /// Encrypts a message with AES with a given key and a random salt that gets encoded as the first 16 bytes of the encrypted buffer + /// + /// The buffer to be encrypted + /// The key to use + /// The encrypted byte array with encoded salt public static byte[] Encrypt(byte[] clearBuffer, byte[] key) { using (MemoryStream stream = new MemoryStream()) diff --git a/MLAPI/NetworkingManagerComponents/LagCompensationManager.cs b/MLAPI/NetworkingManagerComponents/LagCompensationManager.cs index de73c0d..41e9d51 100644 --- a/MLAPI/NetworkingManagerComponents/LagCompensationManager.cs +++ b/MLAPI/NetworkingManagerComponents/LagCompensationManager.cs @@ -10,6 +10,11 @@ namespace MLAPI.NetworkingManagerComponents { public static List SimulationObjects = new List(); + /// + /// Turns time back a given amount of seconds, invokes an action and turns it back + /// + /// The amount of seconds + /// The action to invoke when time is turned back public static void Simulate(float secondsAgo, Action action) { if(!NetworkingManager.singleton.isServer) @@ -31,6 +36,11 @@ namespace MLAPI.NetworkingManagerComponents } private static byte error = 0; + /// + /// Turns time back a given amount of seconds, invokes an action and turns it back. The time is based on the estimated RTT of a clientId + /// + /// The clientId's RTT to use + /// The action to invoke when time is turned back public static void Simulate(int clientId, Action action) { if (!NetworkingManager.singleton.isServer) diff --git a/MLAPI/NetworkingManagerComponents/MessageChunker.cs b/MLAPI/NetworkingManagerComponents/MessageChunker.cs index 60b25b0..8df47e6 100644 --- a/MLAPI/NetworkingManagerComponents/MessageChunker.cs +++ b/MLAPI/NetworkingManagerComponents/MessageChunker.cs @@ -5,6 +5,12 @@ namespace MLAPI.NetworkingManagerComponents { public static class MessageChunker { + /// + /// Chunks a large byte array to smaller chunks + /// + /// The large byte array + /// The amount of bytes of non header data to use for each chunk + /// List of chunks public static List GetChunkedMessage(ref byte[] message, int chunkSize) { List chunks = new List((int)Math.Ceiling((double)message.Length / chunkSize)); @@ -36,6 +42,12 @@ namespace MLAPI.NetworkingManagerComponents return chunks; } + /// + /// Checks if a list of chunks has missing parts + /// + /// The list of chunks + /// The expected amount of chunks + /// If list of chunks has missing parts public static bool HasMissingParts(ref List chunks, uint expectedChunksCount) { if (chunks.Count < expectedChunksCount) @@ -54,6 +66,11 @@ namespace MLAPI.NetworkingManagerComponents return chunks.Count - duplicateCount != expectedChunksCount; } + /// + /// Checks if a list of chunks is in correct order + /// + /// The list of chunks + /// If all chunks are in order public static bool IsOrdered(ref List chunks) { uint lastChunkIndex = 0; @@ -69,6 +86,12 @@ namespace MLAPI.NetworkingManagerComponents return true; } + /// + /// Checks if a list of chunks have any duplicates inside of it + /// + /// The list of chunks + /// The expected amount of chunks + /// If a list of chunks has duplicate chunks in it public static bool HasDuplicates(ref List chunks, uint expectedChunksCount) { if (chunks.Count > expectedChunksCount) @@ -86,7 +109,12 @@ namespace MLAPI.NetworkingManagerComponents return false; } - + /// + /// Converts a list of chunks back into the original buffer, this requires the list to be in correct order and properly verified + /// + /// The list of chunks + /// The size of each chunk. Optional + /// public static byte[] GetMessageOrdered(ref List chunks, int chunkSize = -1) { if (chunks.Count == 0) @@ -107,6 +135,12 @@ namespace MLAPI.NetworkingManagerComponents return message; } + /// + /// Converts a list of chunks back into the original buffer, this does not require the list to be in correct order and properly verified + /// + /// The list of chunks + /// The size of each chunk. Optional + /// public static byte[] GetMessageUnordered(ref List chunks, int chunkSize = -1) { if (chunks.Count == 0) diff --git a/MLAPI/NetworkingManagerComponents/NetworkPoolManager.cs b/MLAPI/NetworkingManagerComponents/NetworkPoolManager.cs index 730c691..b9eb3bb 100644 --- a/MLAPI/NetworkingManagerComponents/NetworkPoolManager.cs +++ b/MLAPI/NetworkingManagerComponents/NetworkPoolManager.cs @@ -11,7 +11,12 @@ namespace MLAPI.NetworkingManagerComponents private static ushort PoolIndex = 0; internal static Dictionary PoolNamesToIndexes; - //Server only + /// + /// Creates a networked object pool. Can only be called from the server + /// + /// Name of the pool + /// The index of the prefab to use in the spawnablePrefabs array + /// The amount of objects in the pool public static void CreatePool(string poolName, int spawnablePrefabIndex, uint size = 16) { if(!NetworkingManager.singleton.isServer) @@ -24,6 +29,10 @@ namespace MLAPI.NetworkingManagerComponents PoolIndex++; } + /// + /// This destroys an object pool and all of it's objects. Can only be called from the server + /// + /// The name of the pool public static void DestroyPool(string poolName) { if (!NetworkingManager.singleton.isServer) @@ -38,6 +47,13 @@ namespace MLAPI.NetworkingManagerComponents Pools.Remove(PoolNamesToIndexes[poolName]); } + /// + /// Spawns a object from the pool at a given position and rotation. Can only be called from server. + /// + /// The name of the pool + /// The position to spawn the object at + /// The rotation to spawn the object at + /// public static GameObject SpawnPoolObject(string poolName, Vector3 position, Quaternion rotation) { if (!NetworkingManager.singleton.isServer) @@ -63,6 +79,10 @@ namespace MLAPI.NetworkingManagerComponents return go; } + /// + /// Destroys a NetworkedObject if it's part of a pool. Use this instead of the MonoBehaviour Destroy method. Can only be called from Server. + /// + /// The NetworkedObject instance to destroy public static void DestroyPoolObject(NetworkedObject netObject) { if (!NetworkingManager.singleton.isServer) diff --git a/MLAPI/NetworkingManagerComponents/NetworkSceneManager.cs b/MLAPI/NetworkingManagerComponents/NetworkSceneManager.cs index e971799..a61f0b9 100644 --- a/MLAPI/NetworkingManagerComponents/NetworkSceneManager.cs +++ b/MLAPI/NetworkingManagerComponents/NetworkSceneManager.cs @@ -26,6 +26,10 @@ namespace MLAPI.NetworkingManagerComponents CurrentSceneIndex = sceneNameToIndex[SceneManager.GetActiveScene().name]; } + /// + /// Switches to a scene with a given name. Can only be called from Server + /// + /// The name of the scene to switch to public static void SwitchScene(string sceneName) { if(!NetworkingManager.singleton.NetworkConfig.EnableSceneSwitching)