From 36e8c79cca2465f0cb7dbc0e7324e6f738bbf3b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albin=20Cor=C3=A9n?= <2108U9@gmail.com>
Date: Wed, 18 Apr 2018 15:22:47 +0200
Subject: [PATCH] Added warnings when trying to send a message on a invalid
MessageType
---
.../MonoBehaviours/Core/NetworkedBehaviour.cs | 72 ++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs
index 228c34b..b74b4b4 100644
--- a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs
+++ b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs
@@ -923,7 +923,12 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToServer(string messageType, string channelName, byte[] data)
{
- if(MessageManager.messageTypes[messageType] < 32)
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
+ if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
return;
@@ -956,6 +961,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToServerTarget(string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -989,6 +999,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToLocalClient(string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1022,6 +1037,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToLocalClientTarget(string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1055,6 +1075,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToNonLocalClients(string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1088,6 +1113,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToNonLocalClientsTarget(string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1122,6 +1152,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClient(uint clientId, string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1157,6 +1192,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClientTarget(uint clientId, string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1192,6 +1232,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClients(uint[] clientIds, string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1227,6 +1272,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClientsTarget(uint[] clientIds, string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1262,6 +1312,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClients(List clientIds, string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1297,6 +1352,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClientsTarget(List clientIds, string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1331,6 +1391,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClients(string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
@@ -1364,6 +1429,11 @@ namespace MLAPI.MonoBehaviours.Core
/// The binary data to send
protected void SendToClientsTarget(string messageType, string channelName, byte[] data)
{
+ if (!MessageManager.messageTypes.ContainsKey(messageType))
+ {
+ Debug.LogWarning("MLAPI: Invalid message type \"" + channelName + "\"");
+ return;
+ }
if (MessageManager.messageTypes[messageType] < 32)
{
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");