예제 #1
0
 internal ChatSession(long chatId)
 {
     ChatId          = chatId;
     State           = ChatSessionState.FirstMessage;
     lastUserMessage = DateTime.UtcNow;
     lastBotMessage  = DateTime.UtcNow;
     userMessagesId  = new List <int>();
     botMessagesId   = new List <int>();
 }
예제 #2
0
        public void ChangeChatState(long chatId, ChatSessionState newState)
        {
            ISessionManager sessionManager = ModulesManager.GetSessionManager();

            IChatSession chatSession = sessionManager.GetChatSession(chatId);

            if (chatSession != null)
            {
                chatSession.State = newState;
                chatStateHandlerFactory.GetChatStateHandler(chatSession.State).StartStateMessage(chatId);
            }
        }
예제 #3
0
 private void Reset()
 {
     this.sessionState   = ChatSessionState.Disconnected;
     this.signedSession  = null;
     this.sessionUrl     = null;
     this.channelUrl     = null;
     this.pullRequestId  = 0u;
     this.sessionTimeTag = "&tag=12&time=Mon%2C%2003%20Mar%202014%2001%3A41%3A22%20GMT";
     this.queuedPublishUrls.Clear();
     if (this.publishTimerId != 0u)
     {
         Service.Get <ViewTimerManager>().KillViewTimer(this.publishTimerId);
         this.publishTimerId = 0u;
     }
 }
예제 #4
0
 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());
     }
 }
예제 #5
0
        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;
        }
예제 #6
0
        private void OnPublishTimer(uint id, object cookie)
        {
            if (this.queuedPublishUrls.Count == 0)
            {
                Service.Get <ViewTimerManager>().KillViewTimer(this.publishTimerId);
                this.publishTimerId = 0u;
                return;
            }
            ChatSessionState chatSessionState = this.sessionState;

            if (chatSessionState == ChatSessionState.Connecting)
            {
                return;
            }
            if (chatSessionState != ChatSessionState.Disconnected)
            {
                string url = this.queuedPublishUrls.Dequeue();
                Service.Get <Engine>().StartCoroutine(this.Publish(url));
                return;
            }
            this.ReconnectSession();
        }
예제 #7
0
 public IChatStateHandler GetChatStateHandler(ChatSessionState chatSessionState)
 {
     return(chatStateHandlers[chatSessionState]);
 }
예제 #8
0
 private void ReconnectSession()
 {
     this.sessionState = ChatSessionState.Connecting;
     Service.Get <Engine>().StartCoroutine(this.ConnectToChannel());
 }