Skip to content

Commit 9c67396

Browse files
committed
Added checks to prevent sending on the MLAPI channels
1 parent 82d4498 commit 9c67396

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

+70
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ private void OnDestroy()
102102

103103
protected void SendToServer(string messageType, string channelName, byte[] data)
104104
{
105+
if(MessageManager.messageTypes[messageType] < 32)
106+
{
107+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
108+
return;
109+
}
105110
if (isServer)
106111
{
107112
MessageManager.InvokeMessageHandlers(messageType, data, -1);
@@ -114,6 +119,11 @@ protected void SendToServer(string messageType, string channelName, byte[] data)
114119

115120
protected void SendToServerTarget(string messageType, string channelName, byte[] data)
116121
{
122+
if (MessageManager.messageTypes[messageType] < 32)
123+
{
124+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
125+
return;
126+
}
117127
if (isServer)
118128
{
119129
MessageManager.InvokeTargetedMessageHandler(messageType, data, -1, networkId);
@@ -126,6 +136,11 @@ protected void SendToServerTarget(string messageType, string channelName, byte[]
126136

127137
protected void SendToLocalClient(string messageType, string channelName, byte[] data)
128138
{
139+
if (MessageManager.messageTypes[messageType] < 32)
140+
{
141+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
142+
return;
143+
}
129144
if (!isServer && (!NetworkingManager.singleton.NetworkConfig.AllowPassthroughMessages || !NetworkingManager.singleton.NetworkConfig.PassthroughMessageTypes.Contains(messageType)))
130145
{
131146
Debug.LogWarning("MLAPI: Invalid Passthrough send. Ensure AllowPassthroughMessages are turned on and that the MessageType " + messageType + " is registered as a passthroughMessageType");
@@ -136,6 +151,11 @@ protected void SendToLocalClient(string messageType, string channelName, byte[]
136151

137152
protected void SendToLocalClientTarget(string messageType, string channelName, byte[] data)
138153
{
154+
if (MessageManager.messageTypes[messageType] < 32)
155+
{
156+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
157+
return;
158+
}
139159
if (!isServer && (!NetworkingManager.singleton.NetworkConfig.AllowPassthroughMessages || !NetworkingManager.singleton.NetworkConfig.PassthroughMessageTypes.Contains(messageType)))
140160
{
141161
Debug.LogWarning("MLAPI: Invalid Passthrough send. Ensure AllowPassthroughMessages are turned on and that the MessageType " + messageType + " is registered as a passthroughMessageType");
@@ -146,6 +166,11 @@ protected void SendToLocalClientTarget(string messageType, string channelName, b
146166

147167
protected void SendToNonLocalClients(string messageType, string channelName, byte[] data)
148168
{
169+
if (MessageManager.messageTypes[messageType] < 32)
170+
{
171+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
172+
return;
173+
}
149174
if (!isServer)
150175
{
151176
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
@@ -156,6 +181,11 @@ protected void SendToNonLocalClients(string messageType, string channelName, byt
156181

157182
protected void SendToNonLocalClientsTarget(string messageType, string channelName, byte[] data)
158183
{
184+
if (MessageManager.messageTypes[messageType] < 32)
185+
{
186+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
187+
return;
188+
}
159189
if (!isServer)
160190
{
161191
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
@@ -166,6 +196,11 @@ protected void SendToNonLocalClientsTarget(string messageType, string channelNam
166196

167197
protected void SendToClient(int clientId, string messageType, string channelName, byte[] data)
168198
{
199+
if (MessageManager.messageTypes[messageType] < 32)
200+
{
201+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
202+
return;
203+
}
169204
if (!isServer && (!NetworkingManager.singleton.NetworkConfig.AllowPassthroughMessages || !NetworkingManager.singleton.NetworkConfig.PassthroughMessageTypes.Contains(messageType)))
170205
{
171206
Debug.LogWarning("MLAPI: Invalid Passthrough send. Ensure AllowPassthroughMessages are turned on and that the MessageType " + messageType + " is registered as a passthroughMessageType");
@@ -176,6 +211,11 @@ protected void SendToClient(int clientId, string messageType, string channelName
176211

177212
protected void SendToClientTarget(int clientId, string messageType, string channelName, byte[] data)
178213
{
214+
if (MessageManager.messageTypes[messageType] < 32)
215+
{
216+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
217+
return;
218+
}
179219
if (!isServer && (!NetworkingManager.singleton.NetworkConfig.AllowPassthroughMessages || !NetworkingManager.singleton.NetworkConfig.PassthroughMessageTypes.Contains(messageType)))
180220
{
181221
Debug.LogWarning("MLAPI: Invalid Passthrough send. Ensure AllowPassthroughMessages are turned on and that the MessageType " + messageType + " is registered as a passthroughMessageType");
@@ -186,6 +226,11 @@ protected void SendToClientTarget(int clientId, string messageType, string chann
186226

187227
protected void SendToClients(int[] clientIds, string messageType, string channelName, byte[] data)
188228
{
229+
if (MessageManager.messageTypes[messageType] < 32)
230+
{
231+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
232+
return;
233+
}
189234
if (!isServer)
190235
{
191236
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
@@ -196,6 +241,11 @@ protected void SendToClients(int[] clientIds, string messageType, string channel
196241

197242
protected void SendToClientsTarget(int[] clientIds, string messageType, string channelName, byte[] data)
198243
{
244+
if (MessageManager.messageTypes[messageType] < 32)
245+
{
246+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
247+
return;
248+
}
199249
if (!isServer)
200250
{
201251
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
@@ -206,6 +256,11 @@ protected void SendToClientsTarget(int[] clientIds, string messageType, string c
206256

207257
protected void SendToClients(List<int> clientIds, string messageType, string channelName, byte[] data)
208258
{
259+
if (MessageManager.messageTypes[messageType] < 32)
260+
{
261+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
262+
return;
263+
}
209264
if (!isServer)
210265
{
211266
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
@@ -216,6 +271,11 @@ protected void SendToClients(List<int> clientIds, string messageType, string cha
216271

217272
protected void SendToClientsTarget(List<int> clientIds, string messageType, string channelName, byte[] data)
218273
{
274+
if (MessageManager.messageTypes[messageType] < 32)
275+
{
276+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
277+
return;
278+
}
219279
if (!isServer)
220280
{
221281
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
@@ -226,6 +286,11 @@ protected void SendToClientsTarget(List<int> clientIds, string messageType, stri
226286

227287
protected void SendToClients(string messageType, string channelName, byte[] data)
228288
{
289+
if (MessageManager.messageTypes[messageType] < 32)
290+
{
291+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
292+
return;
293+
}
229294
if (!isServer)
230295
{
231296
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
@@ -236,6 +301,11 @@ protected void SendToClients(string messageType, string channelName, byte[] data
236301

237302
protected void SendToClientsTarget(string messageType, string channelName, byte[] data)
238303
{
304+
if (MessageManager.messageTypes[messageType] < 32)
305+
{
306+
Debug.LogWarning("MLAPI: Sending messages on the internal MLAPI channels is not allowed!");
307+
return;
308+
}
239309
if (!isServer)
240310
{
241311
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");

0 commit comments

Comments
 (0)