Пример #1
0
        private void Dispatch(OutgoingNetworkBusEnvelope outgoingNetworkBusEnvelope)
        {
            var message = outgoingNetworkBusEnvelope.Envelope;

            if (!isLocalPlayer)
            {
                return;
            }

            var data = BinarySerializationHelper.Serialize(message);

            if (data.Length > MaxBufferSize)
            {
                ThreadStart threadStart = () => SplitOutgoingEnvelope(outgoingNetworkBusEnvelope, data);
                Thread      spliThread  = new Thread(threadStart);
                spliThread.Start();
                return;
            }

            if (isServer)
            {
                Broadcast(data, outgoingNetworkBusEnvelope.SendToSelf);
            }
            else
            {
                CmdSendToServer(data);
            }
        }
Пример #2
0
        private void SplitOutgoingEnvelope(OutgoingNetworkBusEnvelope outgoingNetworkBusEnvelope, byte[] data)
        {
            var splitSize = MaxBufferSize / 2;
            var groupId   = Guid.NewGuid();
            var groupSize = (int)Math.Ceiling((float)data.Length / splitSize);

            for (var i = 0; i < groupSize; i++)
            {
                var payload      = data.Skip(i * splitSize).Take(splitSize).ToArray();
                var subEnveloppe = new NetworkBusEnvelope(
                    groupId,
                    i,
                    groupSize,
                    payload);

                outbox.Enqueue(
                    new OutgoingNetworkBusEnvelope
                {
                    Envelope   = subEnveloppe,
                    SendToSelf = outgoingNetworkBusEnvelope.SendToSelf
                });
            }
        }