public bool Start()
        {
            // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
            // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).
            string address      = this.region.HostAndPort;
            int    indexOfColon = address.LastIndexOf(':');

            if (indexOfColon > 1)
            {
                address = address.Substring(0, indexOfColon);
            }
            this.regionAddress = ResolveHost(address);


            this.ping = this.GetPingImplementation();


            this.Done           = false;
            this.CurrentAttempt = 0;

            #if PING_VIA_COROUTINE
            GameObject go = new GameObject();
            go.name = "RegionPing_" + this.region.Code + "_" + this.region.Cluster;
            this.coroutineMonoBehaviour = go.AddComponent <MonoBehaviourEmpty>();        // is defined below, as special case for Unity WegGL
            this.coroutineMonoBehaviour.StartCoroutine(this.RegionPingCoroutine());
            #else
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0, "RegionPing_" + this.region.Code + "_" + this.region.Cluster);
            #endif

            return(true);
        }
        public bool Start()
        {
            // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
            // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).
            string address      = this.region.HostAndPort;
            int    indexOfColon = address.LastIndexOf(':');

            if (indexOfColon > 1)
            {
                address = address.Substring(0, indexOfColon);
            }
            this.regionAddress = ResolveHost(address);


            this.ping = this.GetPingImplementation();


            this.Done           = false;
            this.CurrentAttempt = 0;
            this.rttResults     = new List <int>(Attempts);

            #if PING_VIA_COROUTINE
            MonoBehaviourEmpty.Instance.StartCoroutine(this.RegionPingCoroutine());
            #elif UNITY_SWITCH
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0);
            #else
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0, "RegionPing_" + this.region.Code + "_" + this.region.Cluster);
            #endif

            return(true);
        }
Beispiel #3
0
    public static void StartFallbackSendAckThread()
    {
            #if !UNITY_WEBGL
        if (sendThreadShouldRun)
        {
            return;
        }

        sendThreadShouldRun = true;
        SupportClassPun.CallInBackground(FallbackSendAckThread);   // thread will call this every 100ms until method returns false
            #endif
    }
Beispiel #4
0
        /// <summary>
        /// Connects this client to the Photon Chat Cloud service, which will also authenticate the user (and set a UserId).
        /// </summary>
        /// <param name="appId">Get your Photon Chat AppId from the <a href="https://www.photonengine.com/en/Chat/Dashboard">Dashboard</a>.</param>
        /// <param name="appVersion">Any version string you make up. Used to separate users and variants of your clients, which might be incompatible.</param>
        /// <param name="authValues">Values for authentication. You can leave this null, if you set a UserId before. If you set authValues, they will override any UserId set before.</param>
        /// <returns></returns>
        public bool Connect(string appId, string appVersion, AuthenticationValues authValues)
        {
            this.chatPeer.TimePingInterval = 3000;
            this.DisconnectedCause         = ChatDisconnectCause.None;

            if (authValues != null)
            {
                this.AuthValues = authValues;
                if (string.IsNullOrEmpty(this.AuthValues.UserId))
                {
                    if (this.DebugOut >= DebugLevel.ERROR)
                    {
                        this.listener.DebugReturn(DebugLevel.ERROR, "Connect failed: no UserId specified in authentication values.");
                    }
                    return(false);
                }
            }
            else
            {
                if (this.DebugOut >= DebugLevel.ERROR)
                {
                    this.listener.DebugReturn(DebugLevel.ERROR, "Connect failed: no authentication values specified");
                }
                return(false);
            }
            this.AppId           = appId;
            this.AppVersion      = appVersion;
            this.didAuthenticate = false;
            this.chatPeer.QuickResendAttempts = 2;
            this.chatPeer.SentCountAllowance  = 7;


            // clean all channels
            this.PublicChannels.Clear();
            this.PrivateChannels.Clear();
            this.PublicChannelsUnsubscribing.Clear();

            this.NameServerAddress = this.chatPeer.NameServerAddress;
            bool isConnecting = this.chatPeer.Connect();

            if (isConnecting)
            {
                this.State = ChatState.ConnectingToNameServer;
            }

            if (this.UseBackgroundWorkerForSending)
            {
                SupportClass.StartBackgroundCalls(this.SendOutgoingInBackground, this.msDeltaForServiceCalls, "ChatClient Service Thread");
            }

            return(isConnecting);
        }
Beispiel #5
0
    public static void StartFallbackSendAckThread()
    {
        if (Application.platform == RuntimePlatform.WebGLPlayer)
        {
            if (sendThreadShouldRun)
            {
                return;
            }

            sendThreadShouldRun = true;
            SupportClassPun.CallInBackground(FallbackSendAckThread);               // thread will call this every 100ms until method returns false
        }
    }
Beispiel #6
0
        private void ReadPingResult(byte[] inbuff)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 1;

            Protocol.Deserialize(out num, inbuff, ref num3);
            Protocol.Deserialize(out num2, inbuff, ref num3);
            this.lastRoundTripTime = SupportClass.GetTickCount() - num2;
            bool flag = !this.serverTimeOffsetIsAvailable;

            if (flag)
            {
                this.roundTripTime = this.lastRoundTripTime;
            }
            base.UpdateRoundTripTimeAndVariance(this.lastRoundTripTime);
            bool flag2 = !this.serverTimeOffsetIsAvailable;

            if (flag2)
            {
                this.serverTimeOffset            = num + (this.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
                this.serverTimeOffsetIsAvailable = true;
            }
        }
Beispiel #7
0
        protected internal void ReadPingResult(OperationResponse operationResponse)
        {
            int num  = (int)operationResponse.Parameters[2];
            int num2 = (int)operationResponse.Parameters[1];

            this.lastRoundTripTime = SupportClass.GetTickCount() - num2;
            bool flag = !this.serverTimeOffsetIsAvailable;

            if (flag)
            {
                this.roundTripTime = this.lastRoundTripTime;
            }
            base.UpdateRoundTripTimeAndVariance(this.lastRoundTripTime);
            bool flag2 = !this.serverTimeOffsetIsAvailable;

            if (flag2)
            {
                this.serverTimeOffset            = num + (this.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
                this.serverTimeOffsetIsAvailable = true;
            }
        }
Beispiel #8
0
        public static string DictionaryToString(IDictionary dictionary, bool includeTypes)
        {
            bool   flag = dictionary == null;
            string result;

            if (flag)
            {
                result = "null";
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("{");
                foreach (object obj in dictionary.Keys)
                {
                    bool flag2 = stringBuilder.Length > 1;
                    if (flag2)
                    {
                        stringBuilder.Append(", ");
                    }
                    bool   flag3 = dictionary[obj] == null;
                    Type   type;
                    string text;
                    if (flag3)
                    {
                        type = typeof(object);
                        text = "null";
                    }
                    else
                    {
                        type = dictionary[obj].GetType();
                        text = dictionary[obj].ToString();
                    }
                    bool flag4 = typeof(IDictionary) == type || typeof(Hashtable) == type;
                    if (flag4)
                    {
                        text = SupportClass.DictionaryToString((IDictionary)dictionary[obj]);
                    }
                    bool flag5 = typeof(string[]) == type;
                    if (flag5)
                    {
                        text = string.Format("{{{0}}}", string.Join(",", (string[])dictionary[obj]));
                    }
                    bool flag6 = typeof(byte[]) == type;
                    if (flag6)
                    {
                        text = string.Format("byte[{0}]", ((byte[])dictionary[obj]).Length);
                    }
                    if (includeTypes)
                    {
                        stringBuilder.AppendFormat("({0}){1}=({2}){3}", new object[]
                        {
                            obj.GetType().Name,
                            obj,
                            type.Name,
                            text
                        });
                    }
                    else
                    {
                        stringBuilder.AppendFormat("{0}={1}", obj, text);
                    }
                }
                stringBuilder.Append("}");
                result = stringBuilder.ToString();
            }
            return(result);
        }
Beispiel #9
0
        internal override void ReceiveIncomingCommands(byte[] inbuff, int dataLength)
        {
            bool flag = inbuff == null;

            if (flag)
            {
                bool flag2 = base.debugOut >= DebugLevel.ERROR;
                if (flag2)
                {
                    base.EnqueueDebugReturn(DebugLevel.ERROR, "checkAndQueueIncomingCommands() inBuff: null");
                }
            }
            else
            {
                this.timestampOfLastReceive = SupportClass.GetTickCount();
                this.timeInt = SupportClass.GetTickCount() - this.timeBase;
                this.timeLastSendOutgoing = this.timeInt;
                this.bytesIn += (long)(inbuff.Length + 7);
                bool trafficStatsEnabled = base.TrafficStatsEnabled;
                if (trafficStatsEnabled)
                {
                    TrafficStats expr_7B = base.TrafficStatsIncoming;
                    int          num     = expr_7B.TotalPacketCount;
                    expr_7B.TotalPacketCount = num + 1;
                    TrafficStats expr_91 = base.TrafficStatsIncoming;
                    num = expr_91.TotalCommandsInPackets;
                    expr_91.TotalCommandsInPackets = num + 1;
                }
                bool flag3 = inbuff[0] == 243 || inbuff[0] == 244;
                if (flag3)
                {
                    Queue <byte[]> obj = this.incomingList;
                    lock (obj)
                    {
                        this.incomingList.Enqueue(inbuff);
                        bool flag4 = this.incomingList.Count % this.warningSize == 0;
                        if (flag4)
                        {
                            base.EnqueueStatusCallback(StatusCode.QueueIncomingReliableWarning);
                        }
                    }
                }
                else
                {
                    bool flag5 = inbuff[0] == 240;
                    if (flag5)
                    {
                        base.TrafficStatsIncoming.CountControlCommand(inbuff.Length);
                        this.ReadPingResult(inbuff);
                    }
                    else
                    {
                        bool flag6 = base.debugOut >= DebugLevel.ERROR;
                        if (flag6)
                        {
                            base.EnqueueDebugReturn(DebugLevel.ERROR, "receiveIncomingCommands() MagicNumber should be 0xF0, 0xF3 or 0xF4. Is: " + inbuff[0]);
                        }
                    }
                }
            }
        }
Beispiel #10
0
        public override object Deserialize(StreamBuffer din, byte type)
        {
            switch (type)
            {
            case 105:
                return(this.DeserializeInteger(din));

            case 115:
                return(this.DeserializeString(din));

            case 97:
                return(this.DeserializeStringArray(din));

            case 120:
                return(this.DeserializeByteArray(din, -1));

            case 110:
                return(this.DeserializeIntArray(din, -1));

            case 104:
                return(this.DeserializeHashTable(din));

            case 68:
                return(this.DeserializeDictionary(din));

            case 111:
                return(this.DeserializeBoolean(din));

            case 107:
                return(this.DeserializeShort(din));

            case 108:
                return(this.DeserializeLong(din));

            case 98:
                return(this.DeserializeByte(din));

            case 102:
                return(this.DeserializeFloat(din));

            case 100:
                return(this.DeserializeDouble(din));

            case 121:
                return(this.DeserializeArray(din));

            case 99:
            {
                byte customTypeCode = din.ReadByte();
                return(this.DeserializeCustom(din, customTypeCode));
            }

            case 122:
                return(this.DeserializeObjectArray(din));

            case 101:
                return(this.DeserializeEventData(din, null));

            case 113:
                return(this.DeserializeOperationRequest(din));

            case 112:
                return(this.DeserializeOperationResponse(din));

            case 0:
            case 42:
                return(null);

            default:
                throw new Exception("Deserialize(): " + type + " pos: " + din.Position + " bytes: " + din.Length + ". " + SupportClass.ByteArrayToString(din.GetBuffer()));
            }
        }
Beispiel #11
0
 /// <summary>
 /// Returns a string-representation of the IDictionary's content, inlcuding type-information.
 /// Note: This might turn out a "heavy-duty" call if used frequently but it's usfuly to debug Dictionary or Hashtable content.
 /// </summary>
 /// <param name="origin">Some Dictionary or Hashtable.</param>
 /// <returns>String of the content of the IDictionary.</returns>
 public static string ToStringFull(this IDictionary origin)
 {
     return(SupportClassPun.DictionaryToString(origin, false));
 }
Beispiel #12
0
 internal override bool SendAcksOnly()
 {
     if (this.rt == null || !this.rt.Connected || (this.peerConnectionState != PeerBase.ConnectionStateValue.Connected || SupportClass.GetTickCount() - this.lastPingResult <= this.timePingInterval))
     {
         return(false);
     }
     this.SendPing();
     return(false);
 }
Beispiel #13
0
        internal virtual bool DeserializeMessageAndCallback(StreamBuffer stream)
        {
            if (stream.IntLength < 2)
            {
                if ((int)this.debugOut >= 1)
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Incoming UDP data too short! " + stream.IntLength);
                }
                return(false);
            }
            byte b = stream.ReadByteAsByte();

            if (b != 243 && b != 253)
            {
                if ((int)this.debugOut >= 1)
                {
                    this.Listener.DebugReturn(DebugLevel.ALL, "No regular operation UDP message: " + b);
                }
                return(false);
            }
            byte b2   = stream.ReadByteAsByte();
            byte b3   = (byte)(b2 & 0x7F);
            bool flag = (b2 & 0x80) > 0;

            if (b3 != 1)
            {
                try
                {
                    if (flag)
                    {
                        byte[] buf = this.CryptoProvider.Decrypt(stream.GetBuffer(), 2, stream.IntLength - 2);
                        stream = new StreamBuffer(buf);
                    }
                    else
                    {
                        stream.Seek(2L, SeekOrigin.Begin);
                    }
                }
                catch (Exception ex)
                {
                    if ((int)this.debugOut >= 1)
                    {
                        this.Listener.DebugReturn(DebugLevel.ERROR, "msgType: " + b3 + " exception: " + ex.ToString());
                    }
                    SupportClass.WriteStackTrace(ex);
                    return(false);
                }
            }
            if (FullLogging)
            {
                Listener.DebugReturn(DebugLevel.ERROR, SupportClass.StreamBufferToString(stream));
            }
            int num = 0;

            switch (b3)
            {
            case 3:
            {
                OperationResponse operationResponse = this.SerializationProtocol.DeserializeOperationResponse(stream);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch);
                    num = SupportClass.GetTickCount();
                }
                this.Listener.OnOperationResponse(operationResponse);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse.OperationCode, SupportClass.GetTickCount() - num);
                }
                break;
            }

            case 4:
            {
                try
                {
                    EventData eventData = this.SerializationProtocol.DeserializeEventData(stream, this.reusableEventData);
                    if (this.TrafficStatsEnabled)
                    {
                        this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch);
                        num = SupportClass.GetTickCount();
                    }
                    this.Listener.OnEvent(eventData);
                    if (this.TrafficStatsEnabled)
                    {
                        this.TrafficStatsGameLevel.TimeForEventCallback(eventData.Code, SupportClass.GetTickCount() - num);
                    }
                    if (this.photonPeer.ReuseEventInstance)
                    {
                        this.reusableEventData = eventData;
                    }
                }
                catch (Exception e)
                {
                    if (debugOut >= DebugLevel.INFO)
                    {
                        this.EnqueueDebugReturn(DebugLevel.ERROR, "Received abnormal EventData: " + e.Message + "\nException: " + e.StackTrace);
                    }
                    return(true);
                }
                break;
            }

            case 1:
                this.InitCallback();
                break;

            case 7:
            {
                OperationResponse operationResponse = this.SerializationProtocol.DeserializeOperationResponse(stream);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch);
                    num = SupportClass.GetTickCount();
                }
                if (operationResponse.OperationCode == PhotonCodes.InitEncryption)
                {
                    this.DeriveSharedKey(operationResponse);
                }
                else if (operationResponse.OperationCode == PhotonCodes.Ping)
                {
                    TPeer tPeer = this as TPeer;
                    if (tPeer != null)
                    {
                        tPeer.ReadPingResult(operationResponse);
                    }
                }
                else
                {
                    this.EnqueueDebugReturn(DebugLevel.ERROR, "Received unknown internal operation. " + operationResponse.ToStringFull());
                }
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse.OperationCode, SupportClass.GetTickCount() - num);
                }
                break;
            }

            case 8:
            {
                object obj = this.SerializationProtocol.DeserializeMessage(stream);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch);
                    num = SupportClass.GetTickCount();
                }
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.TimeForMessageCallback(SupportClass.GetTickCount() - num);
                }
                break;
            }

            case 9:
            {
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch);
                    num = SupportClass.GetTickCount();
                }
                byte[] array = stream.ToArrayFromPos();
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.TimeForRawMessageCallback(SupportClass.GetTickCount() - num);
                }
                break;
            }

            default:
                this.EnqueueDebugReturn(DebugLevel.ERROR, "unexpected msgType " + b3);
                break;
            }
            return(true);
        }
Beispiel #14
0
        public IEnumerator ReceiveLoop()
        {
            this.Listener.DebugReturn(DebugLevel.INFO, "ReceiveLoop()");
            while (!this.sock.Connected && this.sock.Error == null)
            {
                yield return(new WaitForSeconds(0.1f));
            }
            if (this.sock.Error != null)
            {
                this.Listener.DebugReturn(DebugLevel.ERROR, "Exiting receive thread due to error: " + this.sock.Error + " Server: " + this.ServerAddress);
                this.HandleException(StatusCode.ExceptionOnConnect);
            }
            else
            {
                if (this.ReportDebugOfLevel(DebugLevel.ALL))
                {
                    this.Listener.DebugReturn(DebugLevel.ALL, "Receiving by websocket. this.State: " + State);
                }
                State = PhotonSocketState.Connected;
                while (State == PhotonSocketState.Connected)
                {
                    if (this.sock.Error != null)
                    {
                        this.Listener.DebugReturn(DebugLevel.ERROR, "Exiting receive thread (inside loop) due to error: " + this.sock.Error + " Server: " + this.ServerAddress);
                        this.HandleException(StatusCode.ExceptionOnReceive);
                        break;
                    }
                    else
                    {
                        byte[] inBuff = this.sock.Recv();
                        if (inBuff == null || inBuff.Length == 0)
                        {
                            yield return(new WaitForSeconds(0.1f));

                            continue;
                        }

                        if (this.ReportDebugOfLevel(DebugLevel.ALL))
                        {
                            this.Listener.DebugReturn(DebugLevel.ALL, "TCP << " + inBuff.Length + " = " + SupportClass.ByteArrayToString(inBuff));
                        }


                        // check if it's a ping-result (first byte = 0xF0). this is 9 bytes in total. no other headers!
                        // note: its a coincidence that ping-result-size == header-size. if this changes we have to refactor this
                        if (inBuff[0] == 0xF0)
                        {
                            try
                            {
                                HandleReceivedDatagram(inBuff, inBuff.Length, false);
                            }
                            catch (Exception e)
                            {
                                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                                {
                                    this.EnqueueDebugReturn(DebugLevel.ERROR, "Receive issue. State: " + this.State + ". Server: '" + this.ServerAddress + "' Exception: " + e);
                                }
                                this.HandleException(StatusCode.ExceptionOnReceive);
                            }
                            continue;
                        }

                        // get data and split the datagram into two buffers: head and body
                        if (inBuff.Length > 0)
                        {
                            try
                            {
                                HandleReceivedDatagram(inBuff, inBuff.Length, false);
                            }
                            catch (Exception e)
                            {
                                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                                {
                                    this.EnqueueDebugReturn(DebugLevel.ERROR, "Receive issue. State: " + this.State + ". Server: '" + this.ServerAddress + "' Exception: " + e);
                                }
                                this.HandleException(StatusCode.ExceptionOnReceive);
                            }
                        }
                    }
                }
            }

            Disconnect();
        }
Beispiel #15
0
 internal override bool SendOutgoingCommands()
 {
     if (this.peerConnectionState == PeerBase.ConnectionStateValue.Disconnected || !this.rt.Connected)
     {
         return(false);
     }
     if (this.peerConnectionState == PeerBase.ConnectionStateValue.Connected && SupportClass.GetTickCount() - this.lastPingResult > this.timePingInterval)
     {
         this.SendPing();
     }
     lock (this.outgoingStream)
     {
         if (this.outgoingStream.Position > 0L)
         {
             this.SendData(this.outgoingStream.ToArray());
             this.outgoingStream.Position = 0L;
             this.outgoingStream.SetLength(0L);
             this.outgoingCommandsInStream = 0;
         }
     }
     return(false);
 }
Beispiel #16
0
 public static byte CallInBackground(Func <bool> myThread, int millisecondsInterval = 100, string taskName = "")
 {
     return(SupportClass.StartBackgroundCalls(myThread, millisecondsInterval, null));
 }
Beispiel #17
0
 public static int GetTickCount()
 {
     return(SupportClass.IntegerMilliseconds());
 }
Beispiel #18
0
 public static string HashtableToString(Hashtable hash)
 {
     return(SupportClass.DictionaryToString(hash));
 }
Beispiel #19
0
 /// <summary>Returns a summary of this Room instance as longer string, including Custom Properties.</summary>
 /// <returns>Summary of this Room instance.</returns>
 public new string ToStringFull()
 {
     return(string.Format("Room: '{0}' {1},{2} {4}/{3} players.\ncustomProps: {5}", this.name, this.isVisible ? "visible" : "hidden", this.isOpen ? "open" : "closed", this.maxPlayers, this.PlayerCount, SupportClass.DictionaryToString(this.CustomProperties)));
 }
Beispiel #20
0
        private void ReadPingResult(byte[] inbuff)
        {
            int num1   = 0;
            int num2   = 0;
            int offset = 1;

            Protocol.Deserialize(out num1, inbuff, ref offset);
            Protocol.Deserialize(out num2, inbuff, ref offset);
            this.lastRoundTripTime = SupportClass.GetTickCount() - num2;
            if (!this.serverTimeOffsetIsAvailable)
            {
                this.roundTripTime = this.lastRoundTripTime;
            }
            this.UpdateRoundTripTimeAndVariance(this.lastRoundTripTime);
            if (this.serverTimeOffsetIsAvailable)
            {
                return;
            }
            this.serverTimeOffset            = num1 + (this.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
            this.serverTimeOffsetIsAvailable = true;
        }
Beispiel #21
0
        public string CommandLogToString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = (this.usedTransportProtocol == ConnectionProtocol.Udp) ? ((EnetPeer)this).reliableCommandsRepeated : 0;

            stringBuilder.AppendFormat("PeerId: {0} Now: {1} Server: {2} State: {3} Total Resends: {4} Received {5}ms ago.\n", this.PeerID, this.timeInt, this.ServerAddress, this.peerConnectionState, num, SupportClass.GetTickCount() - this.timestampOfLastReceive);
            if (this.CommandLog == null)
            {
                return(stringBuilder.ToString());
            }
            foreach (CmdLogItem item in this.CommandLog)
            {
                stringBuilder.AppendLine(item.ToString());
            }
            stringBuilder.AppendLine("Received Reliable Log: ");
            foreach (CmdLogItem item2 in this.InReliableLog)
            {
                stringBuilder.AppendLine(item2.ToString());
            }
            return(stringBuilder.ToString());
        }
Beispiel #22
0
 public static void WriteStackTrace(Exception throwable)
 {
     SupportClass.WriteStackTrace(throwable, null);
 }
Beispiel #23
0
 ///<summary>
 /// Returns a string of the most interesting connection statistics.
 /// When you have issues on the client side, these might contain hints about the issue's cause.
 ///</summary>
 ///<param name="all">If true, Incoming and Outgoing low-level stats are included in the string.</param>
 ///<returns>Stats as string.</returns>
 public string VitalStatsToString(bool all)
 {
     if (this.TrafficStatsGameLevel == null)
     {
         return("Stats not available. Use PhotonPeer.TrafficStatsEnabled.");
     }
     if (!all)
     {
         return(string.Format("Rtt(variance): {0}({1}). Ms since last receive: {2}. Stats elapsed: {4}sec.\n{3}", new object[] { this.RoundTripTime, this.RoundTripTimeVariance, SupportClass.GetTickCount() - this.TimestampOfLastSocketReceive, this.TrafficStatsGameLevel.ToStringVitalStats(), this.TrafficStatsElapsedMs / 0x3e8L }));
     }
     return(string.Format("Rtt(variance): {0}({1}). Ms since last receive: {2}. Stats elapsed: {6}sec.\n{3}\n{4}\n{5}", new object[] { this.RoundTripTime, this.RoundTripTimeVariance, SupportClass.GetTickCount() - this.TimestampOfLastSocketReceive, this.TrafficStatsGameLevel.ToStringVitalStats(), this.TrafficStatsIncoming.ToString(), this.TrafficStatsOutgoing.ToString(), this.TrafficStatsElapsedMs / 0x3e8L }));
 }
Beispiel #24
0
        internal virtual bool DeserializeMessageAndCallback(byte[] inBuff)
        {
            OperationResponse opRes;

            if (inBuff.Length < 2)
            {
                if (this.debugOut >= DebugLevel.ERROR)
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Incoming UDP data too short! " + inBuff.Length);
                }
                return(false);
            }
            if ((inBuff[0] != 0xf3) && (inBuff[0] != 0xfd))
            {
                if (this.debugOut >= DebugLevel.ERROR)
                {
                    this.Listener.DebugReturn(DebugLevel.ALL, "No regular operation UDP message: " + inBuff[0]);
                }
                return(false);
            }
            byte         msgType     = (byte)(inBuff[1] & 0x7f);
            bool         isEncrypted = (inBuff[1] & 0x80) > 0;
            MemoryStream stream      = null;

            if (msgType != 1)
            {
                try
                {
                    if (isEncrypted)
                    {
                        inBuff = this.CryptoProvider.Decrypt(inBuff, 2, inBuff.Length - 2);
                        stream = new MemoryStream(inBuff);
                    }
                    else
                    {
                        stream = new MemoryStream(inBuff);
                        stream.Seek(2L, SeekOrigin.Begin);
                    }
                }
                catch (Exception ex)
                {
                    if (this.debugOut >= DebugLevel.ERROR)
                    {
                        this.Listener.DebugReturn(DebugLevel.ERROR, ex.ToString());
                    }
                    SupportClass.WriteStackTrace(ex, null);
                    return(false);
                }
            }
            int timeBeforeCallback = 0;

            switch (msgType)
            {
            case 1:
                this.InitCallback();
                break;

            case 3:
                opRes = Protocol.DeserializeOperationResponse(stream);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch);
                    timeBeforeCallback = SupportClass.GetTickCount();
                }
                this.Listener.OnOperationResponse(opRes);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.TimeForResponseCallback(opRes.OperationCode, SupportClass.GetTickCount() - timeBeforeCallback);
                }
                break;

            case 4:
            {
                EventData ev = Protocol.DeserializeEventData(stream);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch);
                    timeBeforeCallback = SupportClass.GetTickCount();
                }
                this.Listener.OnEvent(ev);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.TimeForEventCallback(ev.Code, SupportClass.GetTickCount() - timeBeforeCallback);
                }
                break;
            }

            case 7:
                opRes = Protocol.DeserializeOperationResponse(stream);
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch);
                    timeBeforeCallback = SupportClass.GetTickCount();
                }
                if (opRes.OperationCode == PhotonCodes.InitEncryption)
                {
                    this.DeriveSharedKey(opRes);
                }
                else
                {
                    this.EnqueueDebugReturn(DebugLevel.ERROR, "Received unknown internal operation. " + opRes.ToStringFull());
                }
                if (this.TrafficStatsEnabled)
                {
                    this.TrafficStatsGameLevel.TimeForResponseCallback(opRes.OperationCode, SupportClass.GetTickCount() - timeBeforeCallback);
                }
                break;

            default:
                this.EnqueueDebugReturn(DebugLevel.ERROR, "unexpected msgType " + msgType);
                break;
            }
            return(true);
        }
 /// <summary>Turns the response into an easier to read string.</summary>
 /// <returns>String resembling the result.</returns>
 public string ToStringFull()
 {
     return(string.Format("{0}={2}: {1} \"{3}\"", this.Name, SupportClass.DictionaryToString(this.Parameters), this.ResultCode, this.Message));
 }
Beispiel #26
0
        internal override bool SendAcksOnly()
        {
            bool flag = this.rt == null || !this.rt.Connected;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                this.timeInt = SupportClass.GetTickCount() - this.timeBase;
                this.timeLastSendOutgoing = this.timeInt;
                bool flag2 = this.peerConnectionState == PeerBase.ConnectionStateValue.Connected && SupportClass.GetTickCount() - this.lastPingResult > base.timePingInterval;
                if (flag2)
                {
                    this.SendPing();
                }
                result = false;
            }
            return(result);
        }
Beispiel #27
0
 /// <summary>
 /// This Player's NickName and custom properties as string.
 /// </summary>
 public override string ToString()
 {
     return(this.NickName + " " + SupportClass.DictionaryToString(this.CustomProperties));
 }
Beispiel #28
0
 public static string DictionaryToString(IDictionary dictionary)
 {
     return(SupportClass.DictionaryToString(dictionary, true));
 }
 /// <summary>
 /// Brief summary string of the Player. Includes name or player.ID and if it's the Master Client.
 /// </summary>
 public override string ToString()
 {
     return((string.IsNullOrEmpty(this.NickName) ? this.ActorNumber.ToString() : this.nickName) + " " + SupportClass.DictionaryToString(this.CustomProperties));
 }
Beispiel #30
0
        internal override bool SendOutgoingCommands()
        {
            bool flag = this.peerConnectionState == PeerBase.ConnectionStateValue.Disconnected;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                bool flag2 = !this.rt.Connected;
                if (flag2)
                {
                    result = false;
                }
                else
                {
                    this.timeInt = SupportClass.GetTickCount() - this.timeBase;
                    this.timeLastSendOutgoing = this.timeInt;
                    bool flag3 = this.peerConnectionState == PeerBase.ConnectionStateValue.Connected && SupportClass.GetTickCount() - this.lastPingResult > base.timePingInterval;
                    if (flag3)
                    {
                        this.SendPing();
                    }
                    List <byte[]> obj = this.outgoingStream;
                    lock (obj)
                    {
                        foreach (byte[] current in this.outgoingStream)
                        {
                            this.SendData(current);
                        }
                        this.outgoingStream.Clear();
                        this.outgoingCommandsInStream = 0;
                    }
                    result = false;
                }
            }
            return(result);
        }