Esempio n. 1
0
        /// <summary>
        /// Polls Steam for messages/persona states. Making a Poll also assures Steam that you are online.
        /// </summary>
        /// <param name="secTimeOut">Seconds until a timeout event occurs?</param>
        /// <param name="secIdleTime">Seconds idle, I assume Steam uses this to set your state to "away"</param>
        /// <param name="useAccountIds">Probably always true.</param>
        /// <returns>PollResponse object</returns>
        public PollResponse Poll(int secTimeOut = 0, int secIdleTime = 0, bool useAccountIds = true)
        {
            const string url    = BaseAuthUrl + "Poll/v0001/";
            string       jQuery = string.Format(_basejQuery, UnixTimeNow());
            var          data   = new Dictionary <string, string>
            {
                { "jsonp", jQuery },
                { "umqid", _auth.UmqId },
                { "message", _message.ToString() },
                { "pollid", _pollId.ToString() },
                { "sectimeout", secTimeOut.ToString() },
                { "secidletime", secIdleTime.ToString() },
                { "use_accountids", useAccountIds.IntValue().ToString() },
                { "access_token", _accessToken }
            };

            string response = _web.Fetch(url, "GET", data, xHeaders: false).ReadStream();

            _pollId++;
            response = StripjQueryArtifacts(response);
            PollResponse pollResponse = JsonConvert.DeserializeObject <PollResponse>(response);

            if (pollResponse.MessageLast != 0)
            {
                _message = pollResponse.MessageLast;
            }
            return(pollResponse);
        }
Esempio n. 2
0
        /// <summary>
        /// Starts a message loop that allows events to be subsribed to.
        /// </summary>
        /// <param name="waitAfterPoll">Wait before each poll.</param>
        private void MessageLoop(TimeSpan waitAfterPoll, int secTimeOut = 0)
        {
            _searching = true;
            while (_searching)
            {
                Thread.Sleep(waitAfterPoll);
                PollResponse response = _chatHandler.Poll(secTimeOut);
                PollReceived?.Invoke(this, new PollArgs(response));

                if (response.Messages == null)
                {
                    continue;
                }
                foreach (Message message in response.Messages)
                {
                    MessageReceived?.Invoke(this, new MessageArgs(message));
                    switch (message.Type.ToLower())
                    {
                    case "saytext":
                        ChatMessageReceived?.Invoke(this, new ChatMessageArgs(message));
                        break;

                    case "typing":
                        OnUserTyping?.Invoke(this, new TypingArgs(message));
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
 public PollArgs(PollResponse response)
 {
     Response = response;
 }
 public PollArgs(PollResponse response)
 {
     Response = response;
 }