Esempio n. 1
0
        //This does not need to be in a unity peer. A Unity peer cannot broadcast.
#if !UNITYDEBUG && !UNITYRELEASE
        //TODO: One day we will need to optimize the ability to broadcast messages as we'll have to convert to a NetConnection list at some point when it's being called externally through
        //the exposed API of GladNet.
        protected void BroadcastEvent(IList <Peer> connections, PacketBase packet, byte packetCode, Packet.DeliveryMethod deliveryMethod, byte encrypt = EncryptionBase.NoEncryptionByte, int channel = 0)
        {
            try
            {
                LidgrenTransferPacket transferPacket = new LidgrenTransferPacket(Packet.OperationType.Event, packet.SerializerKey, packetCode, packet.Serialize());

                if (encrypt != EncryptionBase.NoEncryptionByte)
                {
                    EncryptionLidgrenPackage(encrypt, transferPacket);
                }

                //TODO: Encryption because it's ready
                byte[] bytes = Serializer <GladNetProtobufNetSerializer> .Instance.Serialize(transferPacket);


                //Inefficient O(n) casting to a NetConnection list. Not good.
                this.InternalNetConnection.Peer.SendMessage(false, connections.Select(x => x.InternalNetConnection).ToList(), bytes, Packet.LidgrenDeliveryMethodConvert(deliveryMethod), channel);
            }
            catch (LoggableException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new LoggableException("Exception occured in serialization of packet.", e, LogType.Error);
            }
        }
Esempio n. 2
0
        public virtual Packet.SendResult SendMessage(Packet.OperationType type, PacketBase packet, byte packetCode, Packet.DeliveryMethod deliveryMethod, int channel = 0, byte encrypt = EncryptionBase.NoEncryptionByte, bool isInternal = false)
#endif
        {
            try
            {
                LidgrenTransferPacket transferPacket = new LidgrenTransferPacket(type, packet.SerializerKey, packetCode, packet.Serialize());

                if (encrypt != EncryptionBase.NoEncryptionByte)
                {
                    EncryptionLidgrenPackage(encrypt, transferPacket);
                }

                //TODO: encryption because it's ready
                byte[] bytes = Serializer <GladNetProtobufNetSerializer> .Instance.Serialize(transferPacket);

                return((Packet.SendResult) this.InternalNetConnection.SendMessage(isInternal, bytes, Packet.LidgrenDeliveryMethodConvert(deliveryMethod), channel));
            }
            catch (LoggableException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new LoggableException("Exception occured in serialization of packet.", e, LogType.Error);
            }
        }