Ejemplo n.º 1
0
        /// <summary>
        /// Handle the RESIGN command.
        /// 
        /// CAUTION: The API currently doesn't support resigning topics within a forum, although
        /// the web service apparently seems to. Until this is supported, the resign command will
        /// resign entire forums. For safety, if a topic name is specified in the argument we
        /// bail out and do nothing.
        /// </summary>
        /// <param name="buffer">Input buffer</param>
        /// <param name="parser">Parser</param>
        private void ResignCommand(LineBuffer buffer, Parser parser)
        {
            string forumName = parser.NextArgument();
            if (string.IsNullOrEmpty(forumName))
            {
                if (_currentTopic == null)
                {
                    buffer.WriteString("Conference name? ");
                    forumName = buffer.ReadLine();
                }
                else
                {
                    forumName = _currentTopic.Forum.Name;
                }
            }
            else
            {
                string[] joinParams = forumName.Split(new[] {'/'});
                if (joinParams.Length == 2)
                {
                    return; // Bail out if a topic name was specified.
                }
            }

            if (!_forums.IsJoined(forumName))
            {
                buffer.WriteLine(string.Format("You are not a member of conference '{0}'.", forumName));
                return;
            }

            buffer.WriteLine(string.Format("Resigning from conference '{0}'.", forumName));
            _forums.Resign(forumName);

            ChangeState(CoSyState.MAIN);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Handle the SCPUT command.
 /// </summary>
 /// <param name="parser">Parser</param>
 private void ScputCommand(Parser parser)
 {
     switch (parser.NextArgument())
     {
         case "script":
             _script = _scratch.ToString();
             _scratch.Clear();
             break;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle commands at the Option level
        /// </summary>
        /// <param name="parser">Parser object</param>
        private bool OptionCommand(Parser parser)
        {
            string optionArgument = parser.NextArgument();

            while (optionArgument != "")
            {
                switch (optionArgument)
                {
                    case "q":
                        QuitState();
                        return false;

                    case "file":
                        break;

                    case "terse":
                        _isTerse = true;
                        break;
                }
                optionArgument = parser.NextArgument();
            }
            return false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handle commands at the Read level
        /// </summary>
        /// <param name="buffer">Line buffer</param>
        /// <param name="parser">Parser</param>
        private bool ReadCommand(LineBuffer buffer, Parser parser)
        {
            switch (parser.NextCommand())
            {
                case Parser.ParseToken.COMMENT:
                    CommentCommand(buffer, parser);
                    break;

                case Parser.ParseToken.SAY:
                    SayCommand(buffer);
                    break;

                case Parser.ParseToken.OPTION:
                    ChangeState(CoSyState.OPT);
                    OptionCommand(parser);
                    break;

                case Parser.ParseToken.JOIN:
                    JoinCommand(buffer, parser);
                    break;

                case Parser.ParseToken.RESIGN:
                    ResignCommand(buffer, parser);
                    break;

                case Parser.ParseToken.KILLSCRATCH:
                    _scratch.Clear();
                    buffer.WriteLine("Scratchpad Deleted");
                    break;

                case Parser.ParseToken.BYE:
                    return ByeCommand(buffer, parser);

                case Parser.ParseToken.QUIT:
                    QuitState();
                    break;
            }
            return false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handle commands at the main level.
        /// </summary>
        /// <param name="buffer">Line buffer</param>
        /// <param name="parser">The command parser</param>
        private bool MainCommand(LineBuffer buffer, Parser parser)
        {
            Parser.ParseToken nextCommand = parser.NextCommand();

            if (nextCommand == Parser.ParseToken.FILE)
            {
                buffer.Output = _scratch;
                nextCommand = parser.NextCommand();
            }

            switch (nextCommand)
            {
                case Parser.ParseToken.DOWNLOAD:
                    DownloadCommand(buffer);
                    break;

                case Parser.ParseToken.UPLOAD:
                    UploadCommand(buffer);
                    break;

                case Parser.ParseToken.OPTION:
                    ChangeState(CoSyState.OPT);
                    OptionCommand(parser);
                    break;

                case Parser.ParseToken.SCPUT:
                    ScputCommand(parser);
                    break;

                case Parser.ParseToken.SCRIPT:
                    buffer.Script = _script;
                    break;

                case Parser.ParseToken.JOIN:
                    JoinCommand(buffer, parser);
                    break;

                case Parser.ParseToken.RESIGN:
                    ResignCommand(buffer, parser);
                    break;

                case Parser.ParseToken.READ:
                    if (parser.NextArgument() == "all")
                    {
                        buffer.WriteLine("......");
                        ReadScratchpad(buffer);
                        buffer.WriteLine("");
                        ShowScratchpadSize(buffer);
                    }
                    break;

                case Parser.ParseToken.KILLSCRATCH:
                    _scratch.Clear();
                    buffer.WriteLine("Scratchpad Deleted");
                    break;

                case Parser.ParseToken.BYE:
                    return ByeCommand(buffer, parser);
            }
            return false;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handle the JOIN command.
        /// </summary>
        /// <param name="buffer">Line buffer</param>
        /// <param name="parser">Parser</param>
        private void JoinCommand(LineBuffer buffer, Parser parser)
        {
            string forumName = parser.NextArgument();
            if (!string.IsNullOrEmpty(forumName))
            {
                string topicName = null;

                string[] joinParams = forumName.Split(new[] {'/'});
                if (joinParams.Length == 2)
                {
                    forumName = joinParams[0];
                    topicName = joinParams[1];
                }

                if (!_forums.IsJoined(forumName))
                {
                    buffer.WriteString(string.Format("You are not registered in '{0}'. ", forumName));
                    if (Ask(buffer, "Would you like to register  (y/n)? "))
                    {
                        if (!_forums.Join(forumName))
                        {
                            buffer.WriteRedirectableLine(string.Format("No conference '{0}'.", forumName));
                            return;
                        }
                    }
                }

                Forum thisForum = _forums[forumName];
                Topic thisTopic;

                do
                {
                    if (topicName != null && !thisForum.Topics.Contains(topicName))
                    {
                        buffer.WriteLine("Couldn't find topic: No such file or directory");
                        buffer.WriteLine(string.Format("Topic '{0}' not found.", topicName));

                        topicName = thisForum.Topics[0].Name;
                    }

                    if (topicName == null)
                    {
                        buffer.WriteString("Topics are:");
                        for (int c = 0; c < thisForum.Topics.Count; ++c)
                        {
                            string topicString = thisForum.Topics[c].Name;
                            if (c > 0)
                            {
                                buffer.WriteString(",");
                            }
                            buffer.WriteString(string.Format(" '{0}'", topicString));
                        }
                        buffer.WriteLine("");
                        buffer.WriteString("Topic? ");

                        topicName = buffer.ReadLine();
                        if (topicName == "quit")
                        {
                            return;
                        }
                    }

                    thisTopic = thisForum.Topics[topicName];
                } while (thisTopic == null);

                buffer.WriteRedirectableLine(string.Format("Joining conference '{0}', topic '{1}'. {2} new message(s).", forumName, topicName, thisTopic.Unread));
                _currentTopic = thisTopic;

                ChangeState(CoSyState.READ);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Comment to an existing message in the specified topic. The message body
        /// follows in the input stream. The command array contains the argument to the
        /// comment command.
        /// </summary>
        /// <param name="buffer">Input stream</param>
        /// <param name="parser">Buffer</param>
        private void CommentCommand(LineBuffer buffer, Parser parser)
        {
            if (_currentTopic != null)
            {
                int replyNumber = _currentTopic.MessageID;
                string commentArgument = parser.NextArgument();

                if (commentArgument != "")
                {
                    if (!Int32.TryParse(commentArgument, out replyNumber))
                    {
                        buffer.WriteLine("Invalid comment number");
                        return;
                    }
                }
                SayOrCommentCommand(buffer, replyNumber);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Handle the BYE command.
 /// </summary>
 /// <param name="buffer">Line buffer</param>
 /// <param name="parser">Parser</param>
 private bool ByeCommand(LineBuffer buffer, Parser parser)
 {
     if (parser.NextArgument() != "y" && _scratch.Length > 0)
     {
         buffer.WriteString("OK to delete your scratchpad? (y/n/q)? ");
         string yesNoQuit = buffer.ReadLine();
         if (yesNoQuit == "q")
         {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Direct the specified input to the appropriate command handler depending
        /// on the state which we're in.
        /// </summary>
        /// <param name="buffer">The I/O buffer</param>
        /// <param name="command">The command string</param>
        /// <returns>Return true if the command was a BYE</returns>
        private bool ActionCommand(LineBuffer buffer, string command)
        {
            Parser parser = new Parser(command);
            bool isBye = false;

            switch (CurrentState)
            {
                case CoSyState.MAIN:
                    isBye = MainCommand(buffer, parser);
                    break;

                case CoSyState.OPT:
                    isBye = OptionCommand(parser);
                    break;

                case CoSyState.READ:
                    isBye = ReadCommand(buffer, parser);
                    break;
            }
            return isBye;
        }