コード例 #1
0
ファイル: SendCommand.cs プロジェクト: rohanaceres/hermes
        private static void HandleNewJoke(SendRequest request)
        {
            TocTocJoke joke = AsyncListener.PendingJokes
                              .Where(j => j.UserId == request.UserId)
                              .FirstOrDefault();

            if (joke != null)
            {
                SendCommand.HandleJokeError(request.UserId, joke);
                return;
            }

            // Create joke for the request user:
            joke        = JokeProvider.GetNew();
            joke.UserId = request.UserId;

            // Add a joke message into the container of pending messages.
            // In this case, the next time a receive request is sent by this user,
            // It'll return the joke message.
            Message jokeMsg = new Message()
            {
                Data = joke.ServerInteractions[joke.ServerInteractionIndex],
                DestinationUserId = request.UserId
            };

            AsyncListener.PendingMessages.Add(jokeMsg);

            // Increment the server interaction index, so the next
            // interaction is called.
            joke.ServerInteractionIndex++;

            // Add this joke to the container of pending jokes:
            AsyncListener.PendingJokes.Add(joke);
        }
コード例 #2
0
ファイル: JokeProvider.cs プロジェクト: rohanaceres/hermes
 static JokeProvider()
 {
     Jokes    = new TocTocJoke[2];
     Jokes[0] = new TocTocJoke()
     {
         ServerInteractions = new string[]
         {
             TocTocJoke.EntryText,
             "Você sabe",
             "AVADA KEDAVRA!"
         },
         ClientInteractions = new string[]
         {
             TocTocJoke.ForcedInteraction,
             "Você sabe quem?"
         }
     };
     Jokes[1] = new TocTocJoke()
     {
         ServerInteractions = new string[]
         {
             TocTocJoke.EntryText,
             "Bará",
             "Baráquem obama"
         },
         ClientInteractions = new string[]
         {
             TocTocJoke.ForcedInteraction,
             "Bará quem?"
         }
     };
 }
コード例 #3
0
ファイル: SendCommand.cs プロジェクト: rohanaceres/hermes
        private static void HandleJokeError(string userId, TocTocJoke joke)
        {
            // Return error message and remove the joke fromthe bunch:
            Message errorMsg = new Message()
            {
                Data = "(Piada removida)",
                DestinationUserId = userId
            };

            AsyncListener.PendingMessages.Add(errorMsg);
            AsyncListener.PendingJokes.Remove(joke);
        }
コード例 #4
0
ファイル: SendCommand.cs プロジェクト: rohanaceres/hermes
        private static void HandlePreviousJoke(SendRequest request)
        {
            TocTocJoke joke = AsyncListener.PendingJokes
                              .Where(j => j.UserId == request.UserId)
                              .FirstOrDefault();

            if (joke != null)
            {
                // If the interaction was correct:
                if (joke.ClientInteractions[joke.ClientInteractionIndex]
                    .Equals(request.Data, StringComparison.OrdinalIgnoreCase) == true)
                {
                    // Increments interaction from both client and server, and adds
                    // the new joke interaction to the pending messages container.
                    joke.ClientInteractionIndex++;

                    Message jokeMsg = new Message()
                    {
                        Data = joke.ServerInteractions[joke.ServerInteractionIndex],
                        DestinationUserId = request.UserId
                    };

                    joke.ServerInteractionIndex++;

                    AsyncListener.PendingMessages.Add(jokeMsg);

                    // If the joke is over, remove it from the bunch:
                    if (joke.ServerInteractionIndex >= joke.ServerInteractions.Length)
                    {
                        AsyncListener.PendingJokes.Remove(joke);
                    }
                }
                else
                {
                    SendCommand.HandleJokeError(request.UserId, joke);
                }
            }
        }