From: Ari Johnson Date: Fri, 13 Apr 2007 03:59:43 +0000 (+0000) Subject: Added crecall() X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=e8ffc73afb430beecfe6e0d202702c6083131287;p=cobramush.git Added crecall() (cherry picked from commit f7a124bb66073b43c3923dbe24342c10cd45c115) --- diff --git a/game/txt/changes/0.73 b/game/txt/changes/0.73 index 7c50af5..1f42c29 100644 --- a/game/txt/changes/0.73 +++ b/game/txt/changes/0.73 @@ -195,4 +195,5 @@ CobraMUSH Version 0.73 * FIXED flag restriction on 'home' is now entirely in restrict.cnf [AEJ] * @chan/list works better for people who increase CHAN_NAME_LEN [AEJ] * locate() can take multiple types and prefer all of them [AEJ] + * crecall() [AEJ] diff --git a/game/txt/hlp/cobra_chat.hlp b/game/txt/hlp/cobra_chat.hlp index fbd6491..2297965 100644 --- a/game/txt/hlp/cobra_chat.hlp +++ b/game/txt/hlp/cobra_chat.hlp @@ -323,6 +323,15 @@ specific indirect lock instead of the default one: @clock. See also: @clock +& CRECALL() + crecall([, [, [, [, ]]]]) + + This function is the functional form of @chan/recall, and returns a + string containing the recalled lines from the channel, separated by + . If is a true value, the recalled lines will + include their timestamps; otherwise, they will not. + + See also: @channel3 & Channel functions Channel functions work with the channel system. diff --git a/src/extchat.c b/src/extchat.c index 53d2ffd..fc5a1ad 100644 --- a/src/extchat.c +++ b/src/extchat.c @@ -3220,6 +3220,117 @@ FUNCTION(fun_cemit) do_cemit(executor, args[0], args[1], flags); } +/* ARGSUSED */ +FUNCTION(fun_crecall) +{ + CHAN *chan; + CHANUSER *u; + int start = -1, num_lines = 10; + char *p = NULL, *buf, *name; + time_t timestamp; + char *stamp; + dbref speaker; + int type; + int first = 1; + char sep; + int showstamp = 0; + + name = args[0]; + if (!name || !*name) { + safe_str(T("#-1 NO SUCH CHANNEL"), buff, bp); + return; + } + + if (!args[1] || !*args[1]) { + /* nothing */ + } else if (is_integer(args[1])) { + num_lines = parse_integer(args[1]); + if (num_lines == 0) + num_lines = INT_MAX; + } else { + safe_str(T(e_int), buff, bp); + return; + } + if (!args[2] || !*args[2]) { + /* nothing */ + } else if (is_integer(args[2])) { + start = parse_integer(args[2]) - 1; + } else { + safe_str(T(e_int), buff, bp); + return; + } + + if (!delim_check(buff, bp, nargs, args, 4, &sep)) + return; + + if (nargs > 4 && args[4] && *args[4]) + showstamp = parse_boolean(args[4]); + + if (num_lines < 0) { + safe_str(T(e_uint), buff, bp); + return; + } + + test_channel(executor, name, chan); + if (!Chan_Can_See(chan, executor)) { + if (onchannel(executor, chan)) + safe_str(T(e_perm), buff, bp); + else + safe_str(T("#-1 NO SUCH CHANNEL"), buff, bp); + return; + } + + u = onchannel(executor, chan); + if (!u &&!Chan_Can_Access(chan, executor)) { + safe_str(T(e_perm), buff, bp); + return; + } + + if (!ChanBufferQ(chan)) { + safe_str(T("#-1 NO RECALL BUFFER"), buff, bp); + return; + } + + if (start < 0) + start = BufferQNum(ChanBufferQ(chan)) - num_lines; + if (isempty_bufferq(ChanBufferQ(chan)) + || BufferQNum(ChanBufferQ(chan)) <= start) { + safe_str(T(e_range), buff, bp); + return; + } + + while (start > 0) { + buf = iter_bufferq(ChanBufferQ(chan), &p, &speaker, &type, ×tamp); + start--; + } + while ((buf = iter_bufferq(ChanBufferQ(chan), &p, &speaker, &type, + ×tamp)) && num_lines > 0) { + if (first) + first = 0; + else + safe_chr(sep, buff, bp); + if (Nospoof(executor) && GoodObject(speaker)) { + char *nsmsg = ns_esnotify(speaker, na_one, &executor, + Paranoid(executor) ? 1 : 0); + if (!showstamp) + safe_format(buff, bp, T("%s %s"), nsmsg, buf); + else { + stamp = show_time(timestamp, 0); + safe_format(buff, bp, T("[%s] %s %s"), stamp, nsmsg, buf); + } + mush_free(nsmsg, "string"); + } else { + if (!showstamp) + safe_str(buf, buff, bp); + else { + stamp = show_time(timestamp, 0); + safe_format(buff, bp, T("[%s] %s"), stamp, buf); + } + } + num_lines--; + } +} + COMMAND (cmd_cemit) { int spflags = !strcmp(cmd->name, "@NSCEMIT") ? PEMIT_SPOOF : 0; SPOOF(player, cause, sw); diff --git a/src/function.c b/src/function.c index 32d7652..c7b41e4 100644 --- a/src/function.c +++ b/src/function.c @@ -315,6 +315,7 @@ FUNTAB flist[] = { {"CLOCK", fun_clock, 1, 2, FN_REG}, {"CMSGS", fun_cinfo, 1, 1, FN_REG}, {"COWNER", fun_cowner, 1, 1, FN_REG}, + {"CRECALL", fun_crecall, 3, 5, FN_REG}, {"CSTATUS", fun_cinfo, 1, 1, FN_REG}, {"CTITLE", fun_ctitle, 2, 2, FN_REG}, {"CUSERS", fun_cinfo, 1, 1, FN_REG}, diff --git a/win32/funs.h b/win32/funs.h index 8f2cfb3..5eefb07 100644 --- a/win32/funs.h +++ b/win32/funs.h @@ -61,6 +61,7 @@ FUNCTION_PROTO(fun_cor); FUNCTION_PROTO(fun_cos); FUNCTION_PROTO(fun_cowner); FUNCTION_PROTO(fun_create); +FUNCTION_PROTO(fun_crecall); FUNCTION_PROTO(fun_crplog); FUNCTION_PROTO(fun_cstatus); FUNCTION_PROTO(fun_ctime);