コード例 #1
0
        public SendResult SendEvent(IEventData eventData, SendParameters sendParameters)
        {
            if (eventData == null)
            {
                throw new ArgumentNullException("eventData");
            }
            if (sendParameters.Encrypted && ((this.CryptoProvider == null) || !this.CryptoProvider.IsInitialized))
            {
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat("SendEvent - Cryptography has not been initialized.", new object[0]);
                }
                this.OnSendFailed(SendResult.EncryptionNotSupported, sendParameters, 0);
                return(SendResult.EncryptionNotSupported);
            }
            byte[] data = sendParameters.Encrypted ? this.Protocol.SerializeEventDataEncrypted(eventData, this.cryptoProvider) : eventData.Serialize(this.Protocol);
            if (data == null)
            {
                return(SendResult.Failed);
            }
            SendResult sendResult = this.SendData(data, sendParameters);

            PhotonCounter.EventSentCount.Increment();
            PhotonCounter.EventSentPerSec.Increment();
            if (log.IsDebugEnabled || operationDataLogger.IsDebugEnabled)
            {
                this.LogEvent(eventData, sendParameters.ChannelId, data, sendResult);
            }
            return(sendResult);
        }
コード例 #2
0
        /// <summary>
        /// Sends an event to a list of peers.
        /// This method serializes the data just once per protocol instead of once per peer.
        /// </summary>
        /// <typeparam name="TPeer">A <see cref="T:Photon.SocketServer.PeerBase"/> subclass type.</typeparam>
        /// <param name="eventData">The event to send.</param>
        /// <param name="peers">The peers to send the event to.</param>
        /// <param name="sendParameters">The send options.</param>
        public void BroadCastEvent <TPeer>(IEventData eventData, IEnumerable <TPeer> peers, SendParameters sendParameters) where TPeer : PeerBase
        {
            if (sendParameters.Encrypted)
            {
                foreach (TPeer local in peers)
                {
                    local.SendEvent(eventData, sendParameters);
                }
            }
            else
            {
                BroadcastEventData[] dataArray = new BroadcastEventData[Protocol.MaxProtocolType];
                foreach (TPeer local2 in peers)
                {
                    BroadcastEventData data = dataArray[(int)local2.Protocol.ProtocolType];
                    if (data == null)
                    {
                        byte[] introduced14 = eventData.Serialize(local2.Protocol);
                        data = new BroadcastEventData(introduced14, local2.MessageContentType);
                        dataArray[(int)local2.Protocol.ProtocolType] = data;
                    }
                    data.Peers.Add(local2);
                    local2.OnSend(data.Data.Length);
                }
                MessageReliablity reliability = sendParameters.Unreliable ? MessageReliablity.UnReliable : MessageReliablity.Reliable;
                if (sendParameters.Flush)
                {
                    reliability |= MessageReliablity.Flush;
                }
                for (int i = 0; i < dataArray.Length; i++)
                {
                    if (dataArray[i] != null)
                    {
                        SendResults[] resultsArray;
                        IPhotonPeer[] unmanagedPeers = dataArray[i].GetUnmanagedPeers();
                        bool          flag           = this.ApplicationSink.BroadcastEvent(unmanagedPeers, dataArray[i].Data, reliability, sendParameters.ChannelId, dataArray[i].MessageContentType, out resultsArray);
                        PhotonCounter.EventSentCount.IncrementBy((long)dataArray[i].Peers.Count);
                        PhotonCounter.EventSentPerSec.IncrementBy((long)dataArray[i].Peers.Count);
                        if (!flag)
                        {
                            if (resultsArray == null)
                            {
                                if (log.IsWarnEnabled)
                                {
                                    log.WarnFormat("BroadcastEvent returned unexpected null for sendResults parameter.", new object[0]);
                                }
                            }
                            else
                            {
                                for (int j = 0; j < dataArray[i].Peers.Count; j++)
                                {
                                    switch (resultsArray[j])
                                    {
                                    case SendResults.SendBufferFull:
                                        dataArray[i].Peers[j].OnSendBufferFull();
                                        break;

                                    case SendResults.SendDisconnected:
                                    case SendResults.SendMsgTooBig:
                                    case SendResults.SendFailed:
                                    case SendResults.SendInvalidChannel:
                                        dataArray[i].Peers[j].OnSendFailed((SendResult)resultsArray[j], sendParameters, dataArray[i].Data.Length);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
 /// <summary>
 ///  Initializes a new instance of the <see cref="T:Photon.SocketServer.SerializedEventData"/> class.
 /// </summary>
 /// <param name="eventData">The event data.</param>
 /// <param name="rpcProtocol">The rpc protocol.</param>
 public SerializedEventData(IEventData eventData, IRpcProtocol rpcProtocol)
 {
     this.eventData      = eventData;
     this.rpcProtocol    = rpcProtocol;
     this.serializedData = eventData.Serialize(rpcProtocol);
 }