bulletin.c
./lib/players/hippo/tools/bulletin.c · 9.3 KB
From the archive h7v3.0a.tar.gz
Download the archive « Back to the archive contents
/* Bulletin Board 2 */
/*
This board gives the player greater control over notices. It uses
/obj/editor (a string editor), and /obj/pager (a 'more' for strings).
These are also used by the mailer
*/
// Changed by tuxedo@StarRift
/* added number of notes at short
added marker so you know which notes are new to you
added follow-up command
*/
/* Slightly changed by Hippo@Hvn7
changed writer into tp()->real_name
added linewrap
implemented this version in heaven7 ver 2.08
*/
#include <mudlib.h>
inherit BASE;
#include <ansi.h>
#include <linewrap.h>
#ifndef EDITOR
#define EDITOR "obj/editor"
#endif
#ifndef PAGER
#define PAGER "obj/pager"
#endif
#define NAME (string)capitalize(this_player()->query_name())
#define REAL (string)this_player()->query_name(1)
#define CREAL capitalize(this_player()->query_real_name())
#define HEADER 0
#define AUTHOR 1
#define MESSAGE 2
#define READBY 3
#define TIME ctime(time())[4..9]
#define PASTE "/"+ PASTE_DIR +"/"+ REAL
#define NUMBER_OF_MESSAGE 40
/* bulletins */
mixed *bulletins; /* ({ ({ header, author, message, readby}), }) */
static string save_file;
/* new notice */
static object new_author;
static string new_header;
static int edit_old;
#ifdef NATIVE_MODE
void create() {
#else
void reset(status arg) {
if(arg) return;
#endif /* native */
set_name("bulletin board");
set_alt_name("board");
set_extra_long("There is a bulletin board here.\n");
bulletins = ({});
}
string short(status wiz) {
int i, j, k;
string str ;
if ( (!wiz) && (!query_short())) return ::short(wiz) ;
i = sizeof(bulletins) ;
for (j=0, k=0; j < i ; j++ )
if (member_array(REAL, bulletins[j][READBY]) == -1) k++ ;
str = (k) ? (", " + k + " new]") : "]" ;
return (::short(wiz) + " [" + i + ( i>1 ? " notes" : " note") + str ) ;
}
void long(status wiz) {
int i;
if(query_long()) ::long(wiz);
writelw("You can set up new notes with the command 'note headline'. "+
"Read a note with 'read num', and remove an old note(s) with "+
"'remove num{,num2}'. You can clip a note to your clipboard with "+
"'clip num'. You can edit one of your old notes with 'edit num'. "+
"Also, you can write follow-up with 'follow|Follow #'. "+
"\n");
if(!sizeof(bulletins)) {
write("It is Empty.\n");
}
else if(sizeof(bulletins) == 1) {
write("The Bulletin Board contains 1 note:\n\n");
}
else {
write("The Bulletin Board contains "+ sizeof(bulletins) +" notes:\n\n");
}
say(NAME +" studies the bulletin board.\n");
for(i = 0; i < sizeof(bulletins); i++) {
write((i+1) + ( (i > 8) ? "." : ". " ) );
/* i > 8, message number > 10 */
if (sizeof(bulletins[i])==3) {
write(" (NEW)");
}
else if (member_array(REAL, bulletins[i][READBY]) != -1 )
write("\t ");
else
write(" (NEW)");
write(" " + bulletins[i][HEADER] + "\n");
}
}
void set_save_file(string file) {
save_file = file;
if(save_file) restore_object(save_file);
}
status get() {
write("It is secured to the ground.\n");
return 0;
}
init() {
if(!bulletins) bulletins = ({});
add_action ("new", "note");
add_action ("read", "read");
add_action ("remove", "remove");
add_action ("bo", "bo");
add_action ("read", "clip");
add_action ("edit", "edit");
add_action ("follow", "follow");
add_action ("Follow", "Follow");
}
status bo() {
long(0);
return 1;
}
/*************************************************************************/
void add_message(string arg) { /* quit and save from editor */
if(new_author != this_player()) return;
if(edit_old) { /* was editing old notice */
bulletins = bulletins[0..(edit_old-2)]
+ bulletins[edit_old..(sizeof(bulletins)-1)];
edit_old = 0;
}
bulletins += ({
({
new_header,
REAL,
arg,
({ REAL, }),
})
});
if(save_file) save_object(save_file);
new_author = 0;
new_header = 0;
}
void editor_quit(string arg) { /* quit, no save from editor */
edit_old = 0;
new_author = 0;
new_header = 0;
}
/***********************************************************************/
/* edit old notice */
status edit(string str) {
int i;
string rest;
if(!str || !(sscanf(str, "%d", i) || sscanf(str, "note %d", i))) return 0;
if(i < 1 || i > sizeof(bulletins)) {
write("Not that number of messages.\n");
return 1;
}
i -= 1;
if(!this_player()->id(bulletins[i][AUTHOR])) {
write("Sorry, you can only edit your own notice.\n");
return 1;
}
if(new_author && environment(new_author) == environment()) {
write((string)new_author->query_name() +" is busy writing.\n");
return 1;
}
sscanf(bulletins[i][HEADER],"%s("+ CREAL +", %s",new_header,rest);
new_header += " ("+ CREAL +", "+ TIME +")";
new_author = this_player();
edit_old = i + 1;
clone_object(EDITOR)->edit("add_message",bulletins[i][MESSAGE],1);
return 1;
}
/*************************************************************************/
/* add new notice */
status new(string hd) {
if(!hd) {
notify_fail("You must give a title.\n");
return 0;
}
if(new_author && environment(new_author) == environment()) {
write((string)new_author->query_name() +" is busy writing.\n");
return 1;
}
if(sizeof(bulletins) == NUMBER_OF_MESSAGE) {
write("You have to remove an old message first.\n");
return 1;
}
if(strlen(hd) > 50) {
write("Too long header to fit the paper.\n");
return 1;
}
hd = (string)this_player()->filter_ansi(hd); /* all headers filtered */
new_author = this_player();
new_header = hd +" ("+ CREAL +", "+ TIME +")";
clone_object(EDITOR)->edit("add_message",0,1);
return 1;
}
/**************************************************************************/
/* read notice */
status read(string str) {
int i, k;
object pager_ob;
if(!str || (sscanf(str, "%d", i) && sscanf(str, "note %d", i))) {
if(query_verb() == "clip")
notify_fail("Usage: clip <note number>\n");
return 0;
}
if(i < 1 || i > sizeof(bulletins)) {
write("Not that number of messages.\n");
return 1;
}
i -= 1;
say(NAME +" reads a note titled '"+ bulletins[i][HEADER] +"'.\n");
if(query_verb() == "clip") {
str = bulletins[i][MESSAGE];
}
else if(this_player()->ansi_on()) {
str = bulletins[i][MESSAGE] + OFF;
}
else {
str = (string)this_player()->filter_ansi(bulletins[i][MESSAGE]);
}
if(query_verb() == "clip") {
rm(PASTE);
write("The note is titled '" + bulletins[i][HEADER] +
"' has been copied to your Clipboard.\n");
write_file(PASTE, str);
}
else {
str += "\nYou have finished the note " + (i+1) + ".\n" ;
write("The note is titled '" + bulletins[i][HEADER] + "':\n\n");
#ifdef PAGER
pager_ob = clone_object(PAGER);
#ifdef NATIVE_MODE
pager_ob->move(this_player());
#else
move_object(pager_ob, this_player());
#endif /* NATIVE_MODE */
pager_ob->page(str);
#else
write(str);
#endif
}
if (sizeof(bulletins[i]) == 3) bulletins[i] += ({ ({ }), }) ;
if (member_array(REAL, bulletins[i][READBY]) == -1 ) {
bulletins[i][READBY] += ({ REAL }) ;
if(save_file) save_object(save_file);
}
return 1;
}
status remove(string str) {
int i, j, k;
if(!str || !(sscanf(str, "%d,%d", i, j) || sscanf(str, "note %d", i)
|| sscanf(str, "%d", i))) {
notify_fail("remove <number>\nremove <number1,number2>\n");
return 0;
}
if(i < 1 || i > sizeof(bulletins)) {
notify_fail("Not that number of messages.\n");
return 0;
}
if(j < i) j = i;
if(j > sizeof(bulletins)) j = sizeof(bulletins);
for(i -= 1, j -= 1; j >= i; j--) {
if(!(this_player()->id(bulletins[j][AUTHOR]) ||
this_player()->query_security_level())) {
write("Sorry, you will have to ask a creator to remove the message "+
(j+1) +"for you.\n");
continue;
}
say(NAME +" removed a note titled '"+ bulletins[j][HEADER] +"'.\n");
write("You remove the note "+ bulletins[j][HEADER] +"...\n");
bulletins = bulletins[0..j-1]+bulletins[j+1..sizeof(bulletins)-1];
}
if(save_file) save_object(save_file);
return 1;
}
status follow_up(string str, int flag) {
int i;
string tmp ;
i = to_int(str);
if(!i) {
notify_fail("You must specify make a follow-up to which note.\n");
return 0;
}
if(new_author && environment(new_author) == environment()) {
write((string)new_author->query_name() +" is busy writing.\n");
return 1;
}
if (i> sizeof(bulletins) || i <0) {
notify_fail("No such number of note on this board.\n");
return 0;
}
if(sizeof(bulletins) == NUMBER_OF_MESSAGE) {
write("You have to remove an old message first.\n");
return 1;
}
i--;
sscanf(bulletins[i][HEADER],"%s(" +capitalize(bulletins[i][AUTHOR])+"%s",
new_header, tmp);
if (!new_header)
if (!sscanf(bulletins[i][HEADER],"%s(Someone%s", new_header, tmp))
new_header = "" ;
if (sscanf(new_header,"RE: %s",tmp)) new_header =tmp;
new_author = this_player();
new_header = "RE: " + new_header + "("+ CREAL +", "+ TIME +")";
if (flag) {
tmp = "> " +bulletins[i][MESSAGE] ;
tmp = implode(explode(tmp,"\n"), "\n> ");
}
else tmp = 0 ;
clone_object(EDITOR)->edit("add_message", tmp ,1);
return 1;
}
status follow(string i) {
return follow_up(i, 0) ;
}
status Follow(string i) {
return follow_up(i, 1) ;
}