public void StartSession(ChatType chatType, string channelId)
 {
     if (this.sessionState == ChatSessionState.Disconnected)
     {
         this.sessionState = ChatSessionState.Connecting;
         uint          unixTimestamp = ChatTimeConversionUtils.GetUnixTimestamp();
         uint          num           = unixTimestamp + 86400u;
         CurrentPlayer currentPlayer = Service.Get <CurrentPlayer>();
         string        locale        = Service.Get <Lang>().ExtractLanguageFromLocale();
         string        json          = ChatSessionUtils.CreateSessionString(currentPlayer.PlayerId, currentPlayer.PlayerName, locale, num.ToString(), chatType, channelId);
         this.signedSession = ChatSessionUtils.GetSignedString(json);
         this.channelUrl    = string.Format("https://startswin-prod-chat-manager.playdom.com/dsg/chat/v1/strtw/getChannel?session={0}", new object[]
         {
             this.signedSession
         });
         Service.Get <Engine>().StartCoroutine(this.ConnectToChannel());
     }
 }
        private IEnumerator ConnectToChannel()
        {
            WWW wWW = new WWW(this.channelUrl);

            WWWManager.Add(wWW);
            yield return(wWW);

            if (WWWManager.Remove(wWW) && this.sessionState == ChatSessionState.Connecting)
            {
                string error = wWW.error;
                string text  = wWW.text;
                if (error == null)
                {
                    this.wwwRetryCount = 0;
                    this.sessionState  = ChatSessionState.Connected;
                    this.sessionUrl    = ChatSessionUtils.GetSessionUrlFromChannelResponse(text);
                    if (!string.IsNullOrEmpty(this.sessionUrl))
                    {
                        this.Poll();
                    }
                    else
                    {
                        Service.Get <StaRTSLogger>().Error("Invalid chat channel response: " + text);
                    }
                }
                else
                {
                    int num = this.wwwRetryCount + 1;
                    this.wwwRetryCount = num;
                    if (num < this.wwwMaxRetry)
                    {
                        this.ReconnectSession();
                        Service.Get <StaRTSLogger>().Warn("Unable to start chat session. Retrying: " + error);
                    }
                    else
                    {
                        this.sessionState = ChatSessionState.Disconnected;
                        Service.Get <StaRTSLogger>().Warn("Unable to start chat session: " + error);
                    }
                }
            }
            wWW.Dispose();
            yield break;
        }