Esempio n. 1
0
        /// <summary>
        /// Enter a parse tree produced by <see cref="BBSCodeParser.bbsCodeElement"/>.
        /// </summary>
        /// <param name="context">The parse tree.</param>
        public override void EnterBbsCodeElement([NotNull] BBSCodeParser.BbsCodeElementContext context)
        {
            string tagName = context.children[1].GetText().Trim().ToUpper();
            Tags   tag;

            if (TagsTable.TryGetValue(tagName, out tag))
            {
                Parsed.TextPush();
                switch (tag)
                {
                case Tags.BLINK:
                    ANSI.SetMode(ANSICodes.Modes.Blink);
                    Parsed.TextConcat(ANSI.WriteMode());
                    break;

                case Tags.REVERSE:
                    ANSI.SetMode(ANSICodes.Modes.Reverse);
                    Parsed.TextConcat(ANSI.WriteMode());
                    break;

                case Tags.BOLD:
                    ANSI.SetMode(ANSICodes.Modes.Bold);
                    Parsed.TextConcat(ANSI.WriteMode());
                    break;

                case Tags.UNDERLINE:
                    ANSI.SetMode(ANSICodes.Modes.Underline);
                    Parsed.TextConcat(ANSI.WriteMode());
                    break;

                case Tags.HEADER:
                case Tags.FOOTER:
                case Tags.BODY:
                case Tags.HIDDEN:
                    Parsed.TextClear();
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="BBSCodeParser.bbsCodeElement"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitBbsCodeElement([NotNull] BBSCodeParser.BbsCodeElementContext context)
 {
 }
Esempio n. 3
0
        /// <summary>
        /// Exit a parse tree produced by <see cref="BBSCodeParser.bbsCodeElement"/>.
        /// </summary>
        /// <param name="context">The parse tree.</param>
        public override void ExitBbsCodeElement([NotNull] BBSCodeParser.BbsCodeElementContext context)
        {
            string tagName = context.children[1].GetText().Trim().ToUpper();
            Tags   tag;

            if (TagsTable.TryGetValue(tagName, out tag))
            {
                Attributes attr = AttributesTable.GetAttributes(tag);
                string     value;
                string     value1;
                switch (tag)
                {
                case Tags.CLS:
                    if (attr.TryGetValue("FORECOLOR", out value))
                    {
                        ANSI.pushForeColor(value);
                    }
                    if (attr.TryGetValue("BACKCOLOR", out value))
                    {
                        ANSI.pushBackColor(value);
                    }
                    Parsed.TextConcat(ANSI.ClearScreen());
                    Parsed.TextPop(true);
                    break;

                case Tags.BLINK:
                    ANSI.ResetMode(ANSICodes.Modes.Blink);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.REVERSE:
                    ANSI.ResetMode(ANSICodes.Modes.Reverse);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.BOLD:
                    ANSI.ResetMode(ANSICodes.Modes.Bold);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.UNDERLINE:
                    ANSI.ResetMode(ANSICodes.Modes.Underline);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.COLOR:
                    ANSI.popForeColor();
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.BACKCOLOR:
                    ANSI.popBackColor();
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.P:
                    Parsed.TextAssign(string.Join('\n',
                                                  TextHelper.WordWrap(Parsed.Parsed,
                                                                      Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.MOVE:
                    if (!attr.TryGetValue("ROW", out value))
                    {
                        value = "0";
                    }
                    if (!attr.TryGetValue("COL", out value1))
                    {
                        value1 = "0";
                    }
                    Parsed.TextConcat(ANSI.Move(value1, value));
                    Parsed.TextPop(true);
                    break;

                case Tags.FIGGLE:
                    if (!attr.TryGetValue("FONT", out value))
                    {
                        value = "standard";
                    }
                    try
                    {
                        Parsed.TextAssign(Figgle.FiggleFonts.Lookup(value.ToLower()).Render(Parsed.Parsed));
                    }
                    catch (Exception)
                    { }
                    Parsed.TextPop(true);
                    break;

                case Tags.ACTION:
                    action = new BBSCodeResult.Action(attr);
                    if (!string.IsNullOrWhiteSpace(action.requires))
                    {
                        if (string.IsNullOrWhiteSpace(Client.username))
                        {
                            Parsed.TextPop(true);
                            return;
                        }
                        using (bbsContext bbs = new bbsContext())
                        {
                            User user    = bbs.GetUserByUsername(Client.username);
                            bool allowed = user.HasRights(action.requires);
                            Parsed.TextPop(allowed);
                            if (!allowed)
                            {
                                return;
                            }
                        }
                    }
                    else
                    {
                        Parsed.TextPop(true);
                    }
                    if (!Parsed.Actions.TryAdd(action.key, action))
                    {
                        EventLogger.Write(string.Format("Error adding action '{0}' in '{1}'", action.key, FileName), 0);
                    }
                    break;

                case Tags.BEEP:
                    Parsed.TextConcat((char)7);
                    Parsed.TextPop(true);
                    break;

                case Tags.HR:
                    Parsed.TextConcat(TextHelper.HR('-', Client.screenWidth));
                    Parsed.TextPop(true);
                    break;

                case Tags.HEADER:
                    if (attr.TryGetValue("BACKCOLOR", out value))
                    {
                        Parsed.HeaderBackground = ANSI.GetColorByName(value, true);
                    }
                    Parsed.Header = Parsed.Parsed;
                    Parsed.TextClear();
                    break;

                case Tags.FOOTER:
                    if (attr.TryGetValue("BACKCOLOR", out value))
                    {
                        Parsed.FooterBackground = ANSI.GetColorByName(value, true);
                    }
                    Parsed.Footer = Parsed.Parsed;
                    Parsed.TextClear();
                    break;

                case Tags.BODY:
                    if (attr.TryGetValue("ALTERNATECOLOR", out value))
                    {
                        Parsed.BodyAlternateBackground = ANSI.GetColorByName(value, true);
                    }
                    if (attr.TryGetValue("FOCUSEDCOLOR", out value))
                    {
                        Parsed.BodyFocusedBackground = ANSI.GetColorByName(value, true);
                    }
                    Parsed.Body = Parsed.Parsed;
                    Parsed.TextClear();
                    break;

                case Tags.HIDDEN:
                    Parsed.TextClear();
                    break;

                case Tags.H1:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 1,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.H2:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 2,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.H3:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 3,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.H4:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 1,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                default:
                    break;
                }
            }
        }