Exemple #1
0
static UTF8 *AcquireColorLetters(dbref player, dbref target)
{
    int   aflags;
    dbref aowner;

    // Get the value of the object's '@color' attribute (or on a parent).
    //
    UTF8 *color_attr = alloc_lbuf("AcquireColor.1");
    atr_pget_str(color_attr, target, A_COLOR, &aowner, &aflags);

    if ('\0' == color_attr[0])
    {
        free_lbuf(color_attr);
        return NULL;
    }
    else
    {
        UTF8 *AnsiCodes = alloc_lbuf("AcquireColor.2");
        UTF8 *ac = AnsiCodes;
        mux_exec(color_attr, LBUF_SIZE-1, AnsiCodes, &ac, player, target, target,
                AttrTrace(aflags, EV_EVAL|EV_TOP|EV_FCHECK), NULL, 0);
        *ac = '\0';
        free_lbuf(color_attr);
        return AnsiCodes;
    }
}
char *CHSInterface::EvalExpression(char *input, HS_DBREF executor,
                                   HS_DBREF caller, HS_DBREF enactor)
{
#ifdef PENNMUSH
    static char tbuf[BUFFER_LEN];
#else
    static char tbuf[LBUF_SIZE];
#endif

    *tbuf = '\0';

#ifdef PENNMUSH                 // No change in code between versions
    char *bp;
    const char *p;
    //char *rsaves[10];

    bp = tbuf;
    p = input;
    process_expression(tbuf, &bp, &p, executor, caller, enactor,
                       PE_DEFAULT, PT_DEFAULT, NULL);
    *bp = '\0';
#endif


#if defined(TM3) || defined(MUX)
    char *bp, *str;
    bp = tbuf;
    str = input;

#ifdef TM3
    exec(tbuf, &bp, 0, executor, enactor, EV_EVAL,
         &input, wenv, m_uiEnvVariableCount);
#endif

#ifdef MUX
    mux_exec(tbuf, &bp, 0, executor, enactor, EV_EVAL,
             &input, wenv, m_uiEnvVariableCount);

#endif

    *bp = '\0';

#endif

    return tbuf;
}
Exemple #3
0
void do_plusemail(dbref executor, dbref cause, dbref enactor, int eval, int key,
                 int nargs, UTF8 *arg1, UTF8 *arg2, const UTF8 *cargs[], int ncargs)
{
    UNUSED_PARAMETER(cause);
    UNUSED_PARAMETER(enactor);
    UNUSED_PARAMETER(eval);
    UNUSED_PARAMETER(key);
    UNUSED_PARAMETER(nargs);
    UNUSED_PARAMETER(cargs);
    UNUSED_PARAMETER(ncargs);

    UTF8 inputline[LBUF_SIZE];

    if ('\0' == mudconf.mail_server[0])
    {
        notify(executor, T("@email: Not configured"));
        return;
    }

    if (!arg1 || !*arg1)
    {
        notify(executor, T("@email: I don\xE2\x80\x99t know who you want to e-mail!"));
        return;
    }

    if (!arg2 || !*arg2)
    {
        notify(executor, T("@email: Not sending an empty e-mail!"));
        return;
    }

    UTF8 *addy = alloc_lbuf("mod_email_do_email.headers");
    UTF8 *bp = addy;
    safe_str(arg1, addy, &bp);
    *bp = '\0';

    UTF8 *subject = (UTF8 *)strchr((char *)addy, '/');
    if (subject)
    {
        *subject = '\0';
        subject++;
    }
    else
    {
        subject = mudconf.mail_subject;
    }

    UTF8 *pMailServer = ConvertCRLFtoSpace(mudconf.mail_server);
    SOCKET mailsock = INVALID_SOCKET;
    int result = mod_email_sock_open(pMailServer, 25, &mailsock);

    if (-1 == result)
    {
        notify(executor, tprintf(T("@email: Unable to resolve hostname %s!"),
            pMailServer));
        free_lbuf(addy);
        return;
    }
    else if (-2 == result)
    {
        // Periodically, we get a failed connect, for reasons which elude me.
        // In almost every case, an immediate retry works.  Therefore, we give
        // it one more shot, before we give up.
        //
        result = mod_email_sock_open(pMailServer, 25, &mailsock);
        if (0 != result)
        {
            notify(executor, T("@email: Unable to connect to mailserver, aborting!"));
            free_lbuf(addy);
            return;
        }
    }

    UTF8 *body = alloc_lbuf("mod_email_do_email.body");
    UTF8 *bodyptr = body;
    mux_exec(arg2, LBUF_SIZE-1, body, &bodyptr, executor, executor, executor,
        EV_TOP | EV_STRIP_CURLY | EV_FCHECK | EV_EVAL, NULL, 0);
    *bodyptr = '\0';

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        mod_email_sock_close(mailsock);
        notify(executor, tprintf(T("@email: Invalid mailserver greeting (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("EHLO %s\r\n"), ConvertCRLFtoSpace(mudconf.mail_ehlo));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on EHLO (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("MAIL FROM:<%s>\r\n"), ConvertCRLFtoSpace(mudconf.mail_sendaddr));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on MAIL FROM (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("RCPT TO:<%s>\r\n"), ConvertCRLFtoSpace(addy));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on RCPT TO (%s)"),
            inputline));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    mod_email_sock_printf(mailsock, T("DATA\r\n"));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('3' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on DATA (%s)"),
            inputline));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    UTF8 *pSendName = StringClone(ConvertCRLFtoSpace(mudconf.mail_sendname));
    mod_email_sock_printf(mailsock, T("From: %s <%s>\r\n"),  pSendName, ConvertCRLFtoSpace(mudconf.mail_sendaddr));
    MEMFREE(pSendName);

    mod_email_sock_printf(mailsock, T("To: %s\r\n"), ConvertCRLFtoSpace(addy));
    mod_email_sock_printf(mailsock, T("X-Mailer: TinyMUX %s\r\n"), mudstate.short_ver);
    mod_email_sock_printf(mailsock, T("Subject: %s\r\n\r\n"), ConvertCRLFtoSpace(subject));

    // The body is encoded to include the CRLF.CRLF at the end.
    //
    mod_email_sock_printf(mailsock, T("%s"), EncodeBody(body));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);

        // Remove trailing CR and LF characters.
        //
        while (  0 < result
              && (  '\n' == inputline[result-1]
                 || '\r' == inputline[result-1]))
        {
            result--;
            inputline[result] = '\0';
        }
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Message rejected (%s)"), inputline));
    }
    else
    {
        notify(executor, tprintf(T("@email: Mail sent to %s (%s)"), ConvertCRLFtoSpace(addy), &inputline[4]));
    }

    mod_email_sock_printf(mailsock, T("QUIT\n"));
    mod_email_sock_close(mailsock);

    free_lbuf(body);
    free_lbuf(addy);
}
Exemple #4
0
/* ---------------------------------------------------------------------------
 * did_it_rlevel: Have player do something to/with thing, watching the
 * attributes. 'what' is actually ignored, the desclist match being used
 * instead.
 */
void did_it_rlevel
(
    dbref player,
    dbref thing,
    int   what,
    const UTF8 *def,
    int   owhat,
    const UTF8 *odef,
    int   awhat,
    int   ctrl_flags,
    const UTF8 *args[],
    int   nargs
)
{
    if (MuxAlarm.bAlarmed)
    {
        return;
    }

    UTF8 *d, *buff, *act, *charges, *bp;
    dbref aowner;
    int num, aflags;
    int i;
    bool found_a_desc;

    reg_ref **preserve = NULL;
    bool need_pres = false;

    // Message to player.
    //
    if (0 < what)
    {
        // Get description list.
        //
        DESC_INFO *desclist = desclist_match(player, thing);
        found_a_desc = false;
        for (i = 0; i < desclist->n; i++)
        {
            // Ok, if it's A_DESC, we need to check against A_IDESC.
            //
            if (  A_IDESC == what
               && A_DESC == desclist->descs[i])
            {
                d = atr_pget(thing, A_IDESC, &aowner, &aflags);
            }
            else
            {
                d = atr_pget(thing, desclist->descs[i], &aowner, &aflags);
            }

            if ('\0' != d[0])
            {
                // No need for the 'def' message.
                //
                found_a_desc = true;
                if (!need_pres)
                {
                    need_pres = true;
                    preserve = PushRegisters(MAX_GLOBAL_REGS);
                    save_global_regs(preserve);
                }
                buff = bp = alloc_lbuf("did_it.1");
                mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                    AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                    args, nargs);
                *bp = '\0';

                if (  A_HTDESC == desclist->descs[i]
                   && Html(player))
                {
                    safe_str(T("\r\n"), buff, &bp);
                    *bp = '\0';
                    notify_html(player, buff);
                }
                else
                {
                    notify(player, buff);
                }
                free_lbuf(buff);
            }
            free_lbuf(d);
        }

        if (!found_a_desc)
        {
            // No desc found... try the default desc (again).
            // A_DESC or A_HTDESC... the worst case we look for it twice.
            //
            d = atr_pget(thing, what, &aowner, &aflags);
            if ('\0' != d[0])
            {
                // No need for the 'def' message
                //
                found_a_desc = true;
                if (!need_pres)
                {
                    need_pres = true;
                    preserve = PushRegisters(MAX_GLOBAL_REGS);
                    save_global_regs(preserve);
                }
                buff = bp = alloc_lbuf("did_it.1");
                mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                    AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                    args, nargs);
                *bp = '\0';

                if (  A_HTDESC == what
                   && Html(player))
                {
                    safe_str(T("\r\n"), buff, &bp);
                    *bp = '\0';
                    notify_html(player, buff);
                }
                else
                {
                    notify(player, buff);
                }
                free_lbuf(buff);
            }
            else if (def)
            {
                notify(player, def);
            }
            free_lbuf(d);
        }
    }
    else if (  what < 0
            && def)
    {
        notify(player, def);
    }

    if (isPlayer(thing))
    {
       d = atr_pget(mudconf.master_room, get_atr(T("ASSET_DESC")), &aowner, &aflags);
       if (*d)
       {
          if (!need_pres)
          {
             need_pres = true;
             preserve = PushRegisters(MAX_GLOBAL_REGS);
             save_global_regs(preserve);
          }
          buff = bp = alloc_lbuf("did_it.1");
          mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
              AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
              args, nargs);
          *bp = '\0';
          notify(player, buff);
          free_lbuf(buff);
       }
       free_lbuf(d);
    }

    // Message to neighbors.
    //
    dbref loc;
    if (  0 < owhat
       && Has_location(player)
       && Good_obj(loc = Location(player)))
    {
        d = atr_pget(thing, owhat, &aowner, &aflags);
        if (*d)
        {
            if (!need_pres)
            {
                need_pres = true;
                preserve = PushRegisters(MAX_GLOBAL_REGS);
                save_global_regs(preserve);
            }
            buff = bp = alloc_lbuf("did_it.2");
            mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                args, nargs);
            *bp = '\0';

            if (*buff)
            {
                if (aflags & AF_NONAME)
                {
                    notify_except2_rlevel2(loc, player, player, thing, buff);
                }
                else
                {
                    notify_except2_rlevel2(loc, player, player, thing,
                        tprintf(T("%s %s"), Name(player), buff));
                }
            }
            free_lbuf(buff);
        }
        else if (odef)
        {
            if (ctrl_flags & VERB_NONAME)
            {
                notify_except2_rlevel2(loc, player, player, thing, odef);
            }
            else
            {
                notify_except2_rlevel2(loc, player, player, thing,
                    tprintf(T("%s %s"), Name(player), odef));
            }
        }
        free_lbuf(d);
    }
    else if (  owhat < 0
            && odef
            && Has_location(player)
            && Good_obj(loc = Location(player)))
    {
        if (ctrl_flags & VERB_NONAME)
        {
            notify_except2_rlevel2(loc, player, player, thing, odef);
        }
        else
        {
            notify_except2_rlevel2(loc, player, player, thing,
                tprintf(T("%s %s"), Name(player), odef));
        }
    }

    // If we preserved the state of the global registers, restore them.
    //
    if (need_pres)
    {
        restore_global_regs(preserve);
        PopRegisters(preserve, MAX_GLOBAL_REGS);
    }

    // Do the action attribute.
    //
    if (  awhat > 0
       && IsReal(thing, player))
    {
        act = atr_pget(thing, awhat, &aowner, &aflags);
        if (*act != '\0')
        {
            charges = atr_pget(thing, A_CHARGES, &aowner, &aflags);
            if (*charges)
            {
                num = mux_atol(charges);
                if (num > 0)
                {
                    buff = alloc_sbuf("did_it.charges");
                    mux_ltoa(num-1, buff);
                    atr_add_raw(thing, A_CHARGES, buff);
                    free_sbuf(buff);
                }
                else
                {
                    buff = atr_pget(thing, A_RUNOUT, &aowner, &aflags);
                    if (*buff != '\0')
                    {
                        free_lbuf(act);
                        act = buff;
                    }
                    else
                    {
                        free_lbuf(act);
                        free_lbuf(buff);
                        free_lbuf(charges);
                        return;
                    }
                }
            }
            free_lbuf(charges);

            CLinearTimeAbsolute lta;
            wait_que(thing, player, player, AttrTrace(aflags, 0), false, lta,
                NOTHING, 0,
                act,
                nargs, args,
                mudstate.global_regs);
        }
        free_lbuf(act);
    }
}
Exemple #5
0
UTF8 *get_rlevel_desc
(
    dbref player,
    dbref thing,
    int  *piDescUsed
)
{
    dbref aowner;
    int aflags;
    UTF8 *buff = alloc_lbuf("get_rlevel_desc.");
    UTF8 *bp = buff;;
    reg_ref **preserve = NULL;
    bool need_pres = false;
    bool bFirst = true;

    // Get description list.
    //
    DESC_INFO *desclist = desclist_match(player, thing);
    bool found_a_desc = false;
    for (int i = 0; i < desclist->n; i++)
    {
        UTF8 *d = atr_pget(thing, desclist->descs[i], &aowner, &aflags);
        if ('\0' != d[0])
        {
            found_a_desc = true;
            if (!need_pres)
            {
                need_pres = true;
                preserve = PushRegisters(MAX_GLOBAL_REGS);
                save_global_regs(preserve);
            }

            mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                NULL, 0);

            if (!bFirst)
            {
                safe_str(T("\r\n"), buff, &bp);
            }
            else
            {
                bFirst = false;
                *piDescUsed = desclist->descs[i];
            }
        }
        free_lbuf(d);
    }

    if (!found_a_desc)
    {
        UTF8 *d = atr_pget(thing, A_DESC, &aowner, &aflags);
        if ('\0' != d[0])
        {
            found_a_desc = true;
            if (!need_pres)
            {
                need_pres = true;
                preserve = PushRegisters(MAX_GLOBAL_REGS);
                save_global_regs(preserve);
            }

            mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                NULL, 0);
            *bp = '\0';

            *piDescUsed = A_DESC;
        }
        free_lbuf(d);
    }

    // If we preserved the state of the global registers, restore them.
    //
    if (need_pres)
    {
        restore_global_regs(preserve);
        PopRegisters(preserve, MAX_GLOBAL_REGS);
    }

    *bp = '\0';
    return buff;
}
Exemple #6
0
static bool ReportTopic(dbref executor, struct help_entry *htab_entry, int iHelpfile,
    UTF8 *result)
{
    UTF8 szTextFilename[SBUF_SIZE+8];
    mux_sprintf(szTextFilename, sizeof(szTextFilename), T("%s.txt"),
        mudstate.aHelpDesc[iHelpfile].pBaseFilename);

    size_t offset = htab_entry->pos;
    FILE *fp;
    if (!mux_fopen(&fp, szTextFilename, T("rb")))
    {
        STARTLOG(LOG_PROBLEMS, "HLP", "OPEN");
        UTF8 *line = alloc_lbuf("ReportTopic.open");
        mux_sprintf(line, LBUF_SIZE, T("Can\xE2\x80\x99t open %s for reading."), szTextFilename);
        log_text(line);
        free_lbuf(line);
        ENDLOG;
        return false;
    }
    DebugTotalFiles++;

    if (fseek(fp, static_cast<long>(offset), 0) < 0L)
    {
        STARTLOG(LOG_PROBLEMS, "HLP", "SEEK");
        UTF8 *line = alloc_lbuf("ReportTopic.seek");
        mux_sprintf(line, LBUF_SIZE, T("Seek error in file %s."), szTextFilename);
        log_text(line);
        free_lbuf(line);
        ENDLOG;
        if (fclose(fp) == 0)
        {
            DebugTotalFiles--;
        }
        return false;
    }
    UTF8 *line = alloc_lbuf("ReportTopic");
    UTF8 *bp = result;
    bool bInTopicAliases = true;
    for (;;)
    {
        if (  fgets((char *)line, LBUF_SIZE - 2, fp) == NULL
           || '\0' == line[0])
        {
            break;
        }

        if ('&' == line[0])
        {
            if (bInTopicAliases)
            {
                continue;
            }
            else
            {
                break;
            }
        }
        bInTopicAliases = false;

        // Transform LF into CRLF to be telnet-friendly.
        //
        size_t len = strlen((char *)line);
        if (  0 < len
           && '\n' == line[len-1]
           && (  1 == len
              || '\r' != line[len-2]))
        {
            line[len-1] = '\r';
            line[len  ] = '\n';
            line[++len] = '\0';
        }

        bool bEval = mudstate.aHelpDesc[iHelpfile].bEval;
        if (bEval)
        {
            dbref executor_for_help = executor;
            if (Good_obj(mudconf.help_executor))
            {
                executor_for_help = mudconf.help_executor;
            }
            mux_exec(line, len, result, &bp, executor_for_help, executor, executor,
                    EV_NO_COMPRESS | EV_FIGNORE | EV_EVAL, NULL, 0);
        }
        else
        {
            safe_str(line, result, &bp);
        }
    }

    // Zap trailing CRLF if present.
    //
    if (  result < bp - 1
       && '\r' == bp[-2]
       && '\n' == bp[-1])
    {
        bp -= 2;
    }
    *bp = '\0';

    if (fclose(fp) == 0)
    {
        DebugTotalFiles--;
    }
    free_lbuf(line);
    return true;
}