@@ -1220,5 +1220,373 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1220
1220
NetworkConfig . NetworkTransport . DisconnectClient ( clientId ) ;
1221
1221
}
1222
1222
}
1223
+ #region SEND METHODS
1224
+ /// <summary>
1225
+ /// Sends a buffer to the server from client
1226
+ /// </summary>
1227
+ /// <param name="messageType">User defined messageType</param>
1228
+ /// <param name="channelName">User defined channelName</param>
1229
+ /// <param name="data">The binary data to send</param>
1230
+ public void SendToServer ( string messageType , string channelName , byte [ ] data )
1231
+ {
1232
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1233
+ {
1234
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1235
+ return ;
1236
+ }
1237
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1238
+ {
1239
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1240
+ return ;
1241
+ }
1242
+ if ( isServer )
1243
+ {
1244
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Server can not send messages to server" ) ;
1245
+ return ;
1246
+ }
1247
+ using ( BitWriter writer = BitWriter . Get ( ) )
1248
+ {
1249
+ writer . WriteByteArray ( data ) ;
1250
+ InternalMessageHandler . Send ( NetworkingManager . singleton . NetworkConfig . NetworkTransport . ServerNetId , messageType , channelName , writer , null ) ;
1251
+ }
1252
+ }
1253
+
1254
+ /// <summary>
1255
+ /// Sends a buffer to the server from client
1256
+ /// </summary>
1257
+ /// <param name="messageType">User defined messageType</param>
1258
+ /// <param name="channelName">User defined channelName</param>
1259
+ /// <param name="writer">The binary data to send</param>
1260
+ public void SendToServer ( string messageType , string channelName , BitWriter writer )
1261
+ {
1262
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1263
+ {
1264
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1265
+ return ;
1266
+ }
1267
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1268
+ {
1269
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1270
+ return ;
1271
+ }
1272
+ if ( isServer )
1273
+ {
1274
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Server can not send messages to server" ) ;
1275
+ return ;
1276
+ }
1277
+ InternalMessageHandler . Send ( NetworkingManager . singleton . NetworkConfig . NetworkTransport . ServerNetId , messageType , channelName , writer , null ) ;
1278
+ }
1279
+
1280
+ /// <summary>
1281
+ /// Sends a binary serialized class to the server from client
1282
+ /// </summary>
1283
+ /// <typeparam name="T">The class type to send</typeparam>
1284
+ /// <param name="messageType">User defined messageType</param>
1285
+ /// <param name="channelName">User defined channelName</param>
1286
+ /// <param name="instance">The instance to send</param>
1287
+ public void SendToServer < T > ( string messageType , string channelName , T instance )
1288
+ {
1289
+ SendToServer ( messageType , channelName , BinarySerializer . Serialize < T > ( instance ) ) ;
1290
+ }
1291
+
1292
+ /// <summary>
1293
+ /// Sends a buffer to a client with a given clientId from Server
1294
+ /// </summary>
1295
+ /// <param name="clientId">The clientId to send the message to</param>
1296
+ /// <param name="messageType">User defined messageType</param>
1297
+ /// <param name="channelName">User defined channelName</param>
1298
+ /// <param name="data">The binary data to send</param>
1299
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1300
+ public void SendToClient ( uint clientId , string messageType , string channelName , byte [ ] data )
1301
+ {
1302
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1303
+ {
1304
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1305
+ return ;
1306
+ }
1307
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1308
+ {
1309
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1310
+ return ;
1311
+ }
1312
+ if ( ! isServer && ( ! NetworkingManager . singleton . NetworkConfig . AllowPassthroughMessages || ! NetworkingManager . singleton . NetworkConfig . PassthroughMessageHashSet . Contains ( MessageManager . messageTypes [ messageType ] ) ) )
1313
+ {
1314
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid Passthrough send. Ensure AllowPassthroughMessages are turned on and that the MessageType " + messageType + " is registered as a passthroughMessageType" ) ;
1315
+ return ;
1316
+ }
1317
+ using ( BitWriter writer = BitWriter . Get ( ) )
1318
+ {
1319
+ writer . WriteByteArray ( data ) ;
1320
+ InternalMessageHandler . Send ( clientId , messageType , channelName , writer , null ) ;
1321
+ }
1322
+ }
1323
+
1324
+
1325
+ /// <summary>
1326
+ /// Sends a buffer to a client with a given clientId from Server
1327
+ /// </summary>
1328
+ /// <param name="clientId">The clientId to send the message to</param>
1329
+ /// <param name="messageType">User defined messageType</param>
1330
+ /// <param name="channelName">User defined channelName</param>
1331
+ /// <param name="writer">The binary data to send</param>
1332
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1333
+ public void SendToClient ( uint clientId , string messageType , string channelName , BitWriter writer )
1334
+ {
1335
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1336
+ {
1337
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1338
+ return ;
1339
+ }
1340
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1341
+ {
1342
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1343
+ return ;
1344
+ }
1345
+ if ( ! isServer && ( ! NetworkingManager . singleton . NetworkConfig . AllowPassthroughMessages || ! NetworkingManager . singleton . NetworkConfig . PassthroughMessageHashSet . Contains ( MessageManager . messageTypes [ messageType ] ) ) )
1346
+ {
1347
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid Passthrough send. Ensure AllowPassthroughMessages are turned on and that the MessageType " + messageType + " is registered as a passthroughMessageType" ) ;
1348
+ return ;
1349
+ }
1350
+ InternalMessageHandler . Send ( clientId , messageType , channelName , writer , null ) ;
1351
+ }
1352
+
1353
+ /// <summary>
1354
+ /// Sends a binary serialized class to a client with a given clientId from Server
1355
+ /// </summary>
1356
+ /// <typeparam name="T">The class type to send</typeparam>
1357
+ /// <param name="clientId">The clientId to send the message to</param>
1358
+ /// <param name="messageType">User defined messageType</param>
1359
+ /// <param name="channelName">User defined channelName</param>
1360
+ /// <param name="instance">The instance to send</param>
1361
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1362
+ public void SendToClient < T > ( int clientId , string messageType , string channelName , T instance )
1363
+ {
1364
+ SendToClient ( clientId , messageType , channelName , BinarySerializer . Serialize < T > ( instance ) ) ;
1365
+ }
1366
+
1367
+ /// <summary>
1368
+ /// Sends a buffer to multiple clients from the server
1369
+ /// </summary>
1370
+ /// <param name="clientIds">The clientId's to send to</param>
1371
+ /// <param name="messageType">User defined messageType</param>
1372
+ /// <param name="channelName">User defined channelName</param>
1373
+ /// <param name="data">The binary data to send</param>
1374
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1375
+ public void SendToClients ( uint [ ] clientIds , string messageType , string channelName , byte [ ] data )
1376
+ {
1377
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1378
+ {
1379
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1380
+ return ;
1381
+ }
1382
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1383
+ {
1384
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1385
+ return ;
1386
+ }
1387
+ if ( ! isServer )
1388
+ {
1389
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages from client to other clients is not yet supported" ) ;
1390
+ return ;
1391
+ }
1392
+ using ( BitWriter writer = BitWriter . Get ( ) )
1393
+ {
1394
+ writer . WriteByteArray ( data ) ;
1395
+ InternalMessageHandler . Send ( clientIds , messageType , channelName , writer , null ) ;
1396
+ }
1397
+ }
1398
+
1399
+ /// <summary>
1400
+ /// Sends a buffer to multiple clients from the server
1401
+ /// </summary>
1402
+ /// <param name="clientIds">The clientId's to send to</param>
1403
+ /// <param name="messageType">User defined messageType</param>
1404
+ /// <param name="channelName">User defined channelName</param>
1405
+ /// <param name="writer">The binary data to send</param>
1406
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1407
+ public void SendToClients ( uint [ ] clientIds , string messageType , string channelName , BitWriter writer )
1408
+ {
1409
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1410
+ {
1411
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1412
+ return ;
1413
+ }
1414
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1415
+ {
1416
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1417
+ return ;
1418
+ }
1419
+ if ( ! isServer )
1420
+ {
1421
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages from client to other clients is not yet supported" ) ;
1422
+ return ;
1423
+ }
1424
+ InternalMessageHandler . Send ( clientIds , messageType , channelName , writer , null ) ;
1425
+ }
1426
+
1427
+ /// <summary>
1428
+ /// Sends a binary serialized class to multiple clients from the server
1429
+ /// </summary>
1430
+ /// <typeparam name="T">The class type to send</typeparam>
1431
+ /// <param name="clientIds">The clientId's to send to</param>
1432
+ /// <param name="messageType">User defined messageType</param>
1433
+ /// <param name="channelName">User defined channelName</param>
1434
+ /// <param name="instance">The instance to send</param>
1435
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1436
+ public void SendToClients < T > ( int [ ] clientIds , string messageType , string channelName , T instance )
1437
+ {
1438
+ SendToClients ( clientIds , messageType , channelName , BinarySerializer . Serialize < T > ( instance ) ) ;
1439
+ }
1440
+
1441
+ /// <summary>
1442
+ /// Sends a buffer to multiple clients from the server
1443
+ /// </summary>
1444
+ /// <param name="clientIds">The clientId's to send to</param>
1445
+ /// <param name="messageType">User defined messageType</param>
1446
+ /// <param name="channelName">User defined channelName</param>
1447
+ /// <param name="data">The binary data to send</param>
1448
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1449
+ public void SendToClients ( List < uint > clientIds , string messageType , string channelName , byte [ ] data )
1450
+ {
1451
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1452
+ {
1453
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1454
+ return ;
1455
+ }
1456
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1457
+ {
1458
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1459
+ return ;
1460
+ }
1461
+ if ( ! isServer )
1462
+ {
1463
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages from client to other clients is not yet supported" ) ;
1464
+ return ;
1465
+ }
1466
+ using ( BitWriter writer = BitWriter . Get ( ) )
1467
+ {
1468
+ writer . WriteByteArray ( data ) ;
1469
+ InternalMessageHandler . Send ( clientIds , messageType , channelName , writer , null ) ;
1470
+ }
1471
+ }
1472
+
1473
+ /// <summary>
1474
+ /// Sends a buffer to multiple clients from the server
1475
+ /// </summary>
1476
+ /// <param name="clientIds">The clientId's to send to</param>
1477
+ /// <param name="messageType">User defined messageType</param>
1478
+ /// <param name="channelName">User defined channelName</param>
1479
+ /// <param name="writer">The binary data to send</param>
1480
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1481
+ public void SendToClients ( List < uint > clientIds , string messageType , string channelName , BitWriter writer )
1482
+ {
1483
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1484
+ {
1485
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1486
+ return ;
1487
+ }
1488
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1489
+ {
1490
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1491
+ return ;
1492
+ }
1493
+ if ( ! isServer )
1494
+ {
1495
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages from client to other clients is not yet supported" ) ;
1496
+ return ;
1497
+ }
1498
+ InternalMessageHandler . Send ( clientIds , messageType , channelName , writer , null ) ;
1499
+ }
1500
+
1501
+ /// <summary>
1502
+ /// Sends a binary serialized class to multiple clients from the server
1503
+ /// </summary>
1504
+ /// <typeparam name="T">The class type to send</typeparam>
1505
+ /// <param name="clientIds">The clientId's to send to</param>
1506
+ /// <param name="messageType">User defined messageType</param>
1507
+ /// <param name="channelName">User defined channelName</param>
1508
+ /// <param name="instance">The instance to send</param>
1509
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1510
+ public void SendToClients < T > ( List < int > clientIds , string messageType , string channelName , T instance )
1511
+ {
1512
+ SendToClients ( clientIds , messageType , channelName , BinarySerializer . Serialize < T > ( instance ) ) ;
1513
+ }
1514
+
1515
+ /// <summary>
1516
+ /// Sends a buffer to all clients from the server
1517
+ /// </summary>
1518
+ /// <param name="messageType">User defined messageType</param>
1519
+ /// <param name="channelName">User defined channelName</param>
1520
+ /// <param name="data">The binary data to send</param>
1521
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1522
+ public void SendToClients ( string messageType , string channelName , byte [ ] data )
1523
+ {
1524
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1525
+ {
1526
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1527
+ return ;
1528
+ }
1529
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1530
+ {
1531
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1532
+ return ;
1533
+ }
1534
+ if ( ! isServer )
1535
+ {
1536
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages from client to other clients is not yet supported" ) ;
1537
+ return ;
1538
+ }
1539
+ using ( BitWriter writer = BitWriter . Get ( ) )
1540
+ {
1541
+ writer . WriteByteArray ( data ) ;
1542
+ InternalMessageHandler . Send ( messageType , channelName , writer , null ) ;
1543
+ }
1544
+ }
1545
+
1546
+ /// <summary>
1547
+ /// Sends a buffer to all clients from the server
1548
+ /// </summary>
1549
+ /// <param name="messageType">User defined messageType</param>
1550
+ /// <param name="channelName">User defined channelName</param>
1551
+ /// <param name="writer">The binary data to send</param>
1552
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1553
+ public void SendToClients ( string messageType , string channelName , BitWriter writer )
1554
+ {
1555
+ if ( ! MessageManager . messageTypes . ContainsKey ( messageType ) )
1556
+ {
1557
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid message type \" " + channelName + "\" " ) ;
1558
+ return ;
1559
+ }
1560
+ if ( MessageManager . messageTypes [ messageType ] < 32 )
1561
+ {
1562
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages on the internal MLAPI channels is not allowed!" ) ;
1563
+ return ;
1564
+ }
1565
+ if ( ! isServer )
1566
+ {
1567
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Sending messages from client to other clients is not yet supported" ) ;
1568
+ return ;
1569
+ }
1570
+ InternalMessageHandler . Send ( messageType , channelName , writer , null ) ;
1571
+ }
1572
+
1573
+ /// <summary>
1574
+ /// Sends a buffer to all clients from the server
1575
+ /// </summary>
1576
+ /// <typeparam name="T">The class type to send</typeparam>
1577
+ /// <param name="messageType">User defined messageType</param>
1578
+ /// <param name="channelName">User defined channelName</param>
1579
+ /// <param name="instance">The instance to send</param>
1580
+ /// <param name="respectObservers">If this is true, the message will only be sent to clients observing the sender object</param>
1581
+ public void SendToClients < T > ( string messageType , string channelName , T instance , bool respectObservers = false )
1582
+ {
1583
+ SendToClients ( messageType , channelName , BinarySerializer . Serialize < T > ( instance ) , respectObservers ) ;
1584
+ }
1585
+
1586
+ public NetworkedObject GetNetworkedObject ( uint networkId )
1587
+ {
1588
+ return SpawnManager . spawnedObjects [ networkId ] ;
1589
+ }
1590
+ #endregion
1223
1591
}
1224
1592
}
0 commit comments