Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

note.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
00003  *  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
00004  *                                                                         *
00005  *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
00006  *  Chastain, Michael Quan, and Mitchell Tse.                              *
00007  *                                                                         *
00008  *  In order to use any part of this Merc Diku Mud, you must comply with   *
00009  *  both the original Diku license in 'license.doc' as well the Merc       *
00010  *  license in 'license.txt'.  In particular, you may not remove either of *
00011  *  these copyright notices.                                               *
00012  *                                                                         *
00013  *  Much time and thought has gone into this software and you are          *
00014  *  benefitting.  We hope that you share your changes too.  What goes      *
00015  *  around, comes around.                                                  *
00016  ***************************************************************************/
00017  
00018 /***************************************************************************
00019 *   ROM 2.4 is copyright 1993-1998 Russ Taylor             *
00020 *   ROM has been brought to you by the ROM consortium          *
00021 *       Russ Taylor (rtaylor@hypercube.org)                *
00022 *       Gabrielle Taylor (gtaylor@hypercube.org)               *
00023 *       Brian Moore (zump@rom.org)                     *
00024 *   By using this code, you have agreed to follow the terms of the     *
00025 *   ROM license, in the file Rom24/doc/rom.license             *
00026 ***************************************************************************/
00027 
00028 #if defined(macintosh)
00029 #include <types.h>
00030 #else
00031 #include <sys/types.h>
00032 #include <sys/time.h>
00033 #endif
00034 #include <ctype.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <time.h>
00039 #include "merc.h"
00040 #include "recycle.h"
00041 #include "tables.h"
00042 
00043 /* globals from db.c for load_notes */
00044 #if !defined(macintosh)
00045 extern  int     _filbuf         args( (FILE *) );
00046 #endif
00047 extern FILE *                  fpArea;
00048 extern char                    strArea[MAX_INPUT_LENGTH];
00049 
00050 /* local procedures */
00051 void load_thread(char *name, NOTE_DATA **list, int type, time_t free_time);
00052 void parse_note(CHAR_DATA *ch, char *argument, int type);
00053 bool hide_note(CHAR_DATA *ch, NOTE_DATA *pnote);
00054 
00055 NOTE_DATA *note_list;
00056 NOTE_DATA *idea_list;
00057 NOTE_DATA *penalty_list;
00058 NOTE_DATA *news_list;
00059 NOTE_DATA *changes_list;
00060 NOTE_DATA *history_list;
00061 int count_spool(CHAR_DATA *ch, NOTE_DATA *spool)
00062 {
00063     int count = 0;
00064     NOTE_DATA *pnote;
00065 
00066     for (pnote = spool; pnote != NULL; pnote = pnote->next)
00067     if (!hide_note(ch,pnote))
00068         count++;
00069 
00070     return count;
00071 }
00072 
00073 void do_unread(CHAR_DATA *ch)
00074 {
00075     char buf[MAX_STRING_LENGTH];
00076     int count;
00077     bool found = FALSE;
00078 
00079     if (IS_NPC(ch))
00080     return; 
00081 
00082     if ((count = count_spool(ch,news_list)) > 0)
00083     {
00084     found = TRUE;
00085     sprintf(buf,"There %s %d new news article%s waiting.\n\r",
00086         count > 1 ? "are" : "is",count, count > 1 ? "s" : "");
00087     send_to_char(buf,ch);
00088     }
00089     if ((count = count_spool(ch,changes_list)) > 0)
00090     {
00091     found = TRUE;
00092     sprintf(buf,"There %s %d change%s waiting to be read.\n\r",
00093         count > 1 ? "are" : "is", count, count > 1 ? "s" : "");
00094         send_to_char(buf,ch);
00095     }
00096     if ((count = count_spool(ch,note_list)) > 0)
00097     {
00098     found = TRUE;
00099     sprintf(buf,"You have %d new note%s waiting.\n\r",
00100         count, count > 1 ? "s" : "");
00101     send_to_char(buf,ch);
00102     }
00103     if ((count = count_spool(ch,idea_list)) > 0)
00104     {
00105     found = TRUE;
00106     sprintf(buf,"You have %d unread idea%s to peruse.\n\r",
00107         count, count > 1 ? "s" : "");
00108     send_to_char(buf,ch);
00109     }
00110     if (IS_TRUSTED(ch,ANGEL) && (count = count_spool(ch,penalty_list)) > 0)
00111     {
00112     found = TRUE;
00113     sprintf(buf,"%d %s been added.\n\r",
00114         count, count > 1 ? "penalties have" : "penalty has");
00115     send_to_char(buf,ch);
00116     }
00117     if ((count = count_spool(ch, history_list)) > 0)
00118     {
00119         found = TRUE;
00120         sprintf(buf, "The history has been changed %d %s since your last visit",
00121                 count, count > 1 ? "times" : "time");
00122         send_to_char(buf,ch);
00123     }
00124 
00125     if (!found)
00126     send_to_char("You have no unread notes.\n\r",ch);
00127 }
00128 
00129 void do_note(CHAR_DATA *ch,char *argument)
00130 {
00131     parse_note(ch,argument,NOTE_NOTE);
00132 }
00133 
00134 void do_idea(CHAR_DATA *ch,char *argument)
00135 {
00136     parse_note(ch,argument,NOTE_IDEA);
00137 }
00138 
00139 void do_penalty(CHAR_DATA *ch,char *argument)
00140 {
00141     parse_note(ch,argument,NOTE_PENALTY);
00142 }
00143 
00144 void do_news(CHAR_DATA *ch,char *argument)
00145 {
00146     parse_note(ch,argument,NOTE_NEWS);
00147 }
00148 
00149 void do_changes(CHAR_DATA *ch,char *argument)
00150 {
00151     parse_note(ch,argument,NOTE_CHANGES);
00152 }
00153 
00154 void do_history(CHAR_DATA *ch, char *argument)
00155 {
00156     parse_note(ch, argument, NOTE_HISTORY);
00157 }
00158 void save_notes(int type)
00159 {
00160     FILE *fp;
00161     char *name;
00162     NOTE_DATA *pnote;
00163 
00164     switch (type)
00165     {
00166     default:
00167         return;
00168     case NOTE_NOTE:
00169         name = NOTE_FILE;
00170         pnote = note_list;
00171         break;
00172     case NOTE_IDEA:
00173         name = IDEA_FILE;
00174         pnote = idea_list;
00175         break;
00176     case NOTE_PENALTY:
00177         name = PENALTY_FILE;
00178         pnote = penalty_list;
00179         break;
00180     case NOTE_NEWS:
00181         name = NEWS_FILE;
00182         pnote = news_list;
00183         break;
00184     case NOTE_CHANGES:
00185         name = CHANGES_FILE;
00186         pnote = changes_list;
00187         break;
00188     case NOTE_HISTORY:
00189         name = HISTORY_FILE;
00190         pnote = history_list;
00191         break;
00192     }
00193 
00194     fclose( fpReserve );
00195     if ( ( fp = fopen( name, "w" ) ) == NULL )
00196     {
00197     perror( name );
00198     }
00199     else
00200     {
00201     for ( ; pnote != NULL; pnote = pnote->next )
00202     {
00203         fprintf( fp, "Sender  %s~\n", pnote->sender);
00204         fprintf( fp, "Date    %s~\n", pnote->date);
00205         fprintf( fp, "Stamp   %ld\n", pnote->date_stamp);
00206         fprintf( fp, "To      %s~\n", pnote->to_list);
00207         fprintf( fp, "Subject %s~\n", pnote->subject);
00208         fprintf( fp, "Text\n%s~\n",   pnote->text);
00209     }
00210     fclose( fp );
00211     fpReserve = fopen( NULL_FILE, "r" );
00212     return;
00213     }
00214 }
00215 void load_notes(void)
00216 {
00217     load_thread(NOTE_FILE,&note_list, NOTE_NOTE, 28*24*60*60);
00218     load_thread(IDEA_FILE,&idea_list, NOTE_IDEA, 28*24*60*60);
00219     load_thread(PENALTY_FILE,&penalty_list, NOTE_PENALTY, 0);
00220     load_thread(NEWS_FILE,&news_list, NOTE_NEWS, 0);
00221     load_thread(CHANGES_FILE,&changes_list,NOTE_CHANGES, 0);
00222     load_thread(HISTORY_FILE, &history_list, NOTE_HISTORY, 0);
00223 }
00224 
00225 void load_thread(char *name, NOTE_DATA **list, int type, time_t free_time)
00226 {
00227     FILE *fp;
00228     NOTE_DATA *pnotelast;
00229  
00230     if ( ( fp = fopen( name, "r" ) ) == NULL )
00231     return;
00232      
00233     pnotelast = NULL;
00234     for ( ; ; )
00235     {
00236     NOTE_DATA *pnote;
00237     char letter;
00238      
00239     do
00240     {
00241         letter = getc( fp );
00242             if ( feof(fp) )
00243             {
00244                 fclose( fp );
00245                 return;
00246             }
00247         }
00248         while ( isspace(letter) );
00249         ungetc( letter, fp );
00250  
00251         pnote           = alloc_perm( sizeof(*pnote) );
00252  
00253         if ( str_cmp( fread_word( fp ), "sender" ) )
00254             break;
00255         pnote->sender   = fread_string( fp );
00256  
00257         if ( str_cmp( fread_word( fp ), "date" ) )
00258             break;
00259         pnote->date     = fread_string( fp );
00260  
00261         if ( str_cmp( fread_word( fp ), "stamp" ) )
00262             break;
00263         pnote->date_stamp = fread_number(fp);
00264  
00265         if ( str_cmp( fread_word( fp ), "to" ) )
00266             break;
00267         pnote->to_list  = fread_string( fp );
00268  
00269         if ( str_cmp( fread_word( fp ), "subject" ) )
00270             break;
00271         pnote->subject  = fread_string( fp );
00272  
00273         if ( str_cmp( fread_word( fp ), "text" ) )
00274             break;
00275         pnote->text     = fread_string( fp );
00276  
00277         if (free_time && pnote->date_stamp < current_time - free_time)
00278         {
00279         free_note(pnote);
00280             continue;
00281         }
00282 
00283     pnote->type = type;
00284  
00285         if (*list == NULL)
00286             *list           = pnote;
00287         else
00288             pnotelast->next     = pnote;
00289  
00290         pnotelast       = pnote;
00291     }
00292  
00293     strcpy( strArea, NOTE_FILE );
00294     fpArea = fp;
00295     bug( "Load_notes: bad key word.", 0 );
00296     exit( 1 );
00297     return;
00298 }
00299 
00300 void append_note(NOTE_DATA *pnote)
00301 {
00302     FILE *fp;
00303     char *name;
00304     NOTE_DATA **list;
00305     NOTE_DATA *last;
00306 
00307     switch(pnote->type)
00308     {
00309     default:
00310         return;
00311     case NOTE_NOTE:
00312         name = NOTE_FILE;
00313         list = &note_list;
00314         break;
00315     case NOTE_IDEA:
00316         name = IDEA_FILE;
00317         list = &idea_list;
00318         break;
00319     case NOTE_PENALTY:
00320         name = PENALTY_FILE;
00321         list = &penalty_list;
00322         break;
00323     case NOTE_NEWS:
00324          name = NEWS_FILE;
00325          list = &news_list;
00326          break;
00327     case NOTE_CHANGES:
00328          name = CHANGES_FILE;
00329          list = &changes_list;
00330          break;
00331     case NOTE_HISTORY:
00332          name = HISTORY_FILE;
00333          list = &history_list;
00334          break;
00335     }
00336 
00337     if (*list == NULL)
00338     *list = pnote;
00339     else
00340     {
00341     for ( last = *list; last->next != NULL; last = last->next);
00342     last->next = pnote;
00343     }
00344 
00345     fclose(fpReserve);
00346     if ( ( fp = fopen(name, "a" ) ) == NULL )
00347     {
00348         perror(name);
00349     }
00350     else
00351     {
00352         fprintf( fp, "Sender  %s~\n", pnote->sender);
00353         fprintf( fp, "Date    %s~\n", pnote->date);
00354         fprintf( fp, "Stamp   %ld\n", pnote->date_stamp);
00355         fprintf( fp, "To      %s~\n", pnote->to_list);
00356         fprintf( fp, "Subject %s~\n", pnote->subject);
00357         fprintf( fp, "Text\n%s~\n", pnote->text);
00358         fclose( fp );
00359     }
00360     fpReserve = fopen( NULL_FILE, "r" );
00361 }
00362 
00363 bool is_note_to( CHAR_DATA *ch, NOTE_DATA *pnote )
00364 {
00365     if ( !str_cmp( ch->name, pnote->sender ) )
00366     return TRUE;
00367 
00368     if ( is_exact_name( "all", pnote->to_list ) )
00369     return TRUE;
00370 
00371     if ( IS_IMMORTAL(ch) && is_exact_name( "immortal", pnote->to_list ) )
00372     return TRUE;
00373 
00374     if (ch->clan && is_exact_name(clan_table[ch->clan].name,pnote->to_list))
00375     return TRUE;
00376 
00377     if (is_exact_name( ch->name, pnote->to_list ) )
00378     return TRUE;
00379 
00380     return FALSE;
00381 }
00382 
00383 
00384 
00385 void note_attach( CHAR_DATA *ch, int type )
00386 {
00387     NOTE_DATA *pnote;
00388 
00389     if ( ch->pnote != NULL )
00390     return;
00391 
00392     pnote = new_note();
00393 
00394     pnote->next     = NULL;
00395     pnote->sender   = str_dup( ch->name );
00396     pnote->date     = str_dup( "" );
00397     pnote->to_list  = str_dup( "" );
00398     pnote->subject  = str_dup( "" );
00399     pnote->text     = str_dup( "" );
00400     pnote->type     = type;
00401     ch->pnote       = pnote;
00402     return;
00403 }
00404 
00405 
00406 
00407 void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote, bool delete)
00408 {
00409     char to_new[MAX_INPUT_LENGTH];
00410     char to_one[MAX_INPUT_LENGTH];
00411     NOTE_DATA *prev;
00412     NOTE_DATA **list;
00413     char *to_list;
00414 
00415     if (!delete)
00416     {
00417     /* make a new list */
00418         to_new[0]   = '\0';
00419         to_list = pnote->to_list;
00420         while ( *to_list != '\0' )
00421         {
00422             to_list = one_argument( to_list, to_one );
00423             if ( to_one[0] != '\0' && str_cmp( ch->name, to_one ) )
00424         {
00425             strcat( to_new, " " );
00426             strcat( to_new, to_one );
00427         }
00428         }
00429         /* Just a simple recipient removal? */
00430        if ( str_cmp( ch->name, pnote->sender ) && to_new[0] != '\0' )
00431        {
00432        free_string( pnote->to_list );
00433        pnote->to_list = str_dup( to_new + 1 );
00434        return;
00435        }
00436     }
00437     /* nuke the whole note */
00438 
00439     switch(pnote->type)
00440     {
00441     default:
00442         return;
00443     case NOTE_NOTE:
00444         list = &note_list;
00445         break;
00446     case NOTE_IDEA:
00447         list = &idea_list;
00448         break;
00449     case NOTE_PENALTY:
00450         list = &penalty_list;
00451         break;
00452     case NOTE_NEWS:
00453         list = &news_list;
00454         break;
00455     case NOTE_CHANGES:
00456         list = &changes_list;
00457         break;
00458     case NOTE_HISTORY:
00459         list = &history_list;
00460         break;
00461     }
00462 
00463     /*
00464      * Remove note from linked list.
00465      */
00466     if ( pnote == *list )
00467     {
00468     *list = pnote->next;
00469     }
00470     else
00471     {
00472     for ( prev = *list; prev != NULL; prev = prev->next )
00473     {
00474         if ( prev->next == pnote )
00475         break;
00476     }
00477 
00478     if ( prev == NULL )
00479     {
00480         bug( "Note_remove: pnote not found.", 0 );
00481         return;
00482     }
00483 
00484     prev->next = pnote->next;
00485     }
00486 
00487     save_notes(pnote->type);
00488     free_note(pnote);
00489     return;
00490 }
00491 
00492 bool hide_note (CHAR_DATA *ch, NOTE_DATA *pnote)
00493 {
00494     time_t last_read;
00495 
00496     if (IS_NPC(ch))
00497     return TRUE;
00498 
00499     switch (pnote->type)
00500     {
00501     default:
00502         return TRUE;
00503     case NOTE_NOTE:
00504         last_read = ch->pcdata->last_note;
00505         break;
00506     case NOTE_IDEA:
00507         last_read = ch->pcdata->last_idea;
00508         break;
00509     case NOTE_PENALTY:
00510         last_read = ch->pcdata->last_penalty;
00511         break;
00512     case NOTE_NEWS:
00513         last_read = ch->pcdata->last_news;
00514         break;
00515     case NOTE_CHANGES:
00516         last_read = ch->pcdata->last_changes;
00517         break;
00518     case NOTE_HISTORY:
00519         last_read = ch->pcdata->last_history;
00520         break;
00521     }
00522     
00523     if (pnote->date_stamp <= last_read)
00524     return TRUE;
00525 
00526     if (!str_cmp(ch->name,pnote->sender))
00527     return TRUE;
00528 
00529     if (!is_note_to(ch,pnote))
00530     return TRUE;
00531 
00532     return FALSE;
00533 }
00534 
00535 void update_read(CHAR_DATA *ch, NOTE_DATA *pnote)
00536 {
00537     time_t stamp;
00538 
00539     if (IS_NPC(ch))
00540     return;
00541 
00542     stamp = pnote->date_stamp;
00543 
00544     switch (pnote->type)
00545     {
00546         default:
00547             return;
00548         case NOTE_NOTE:
00549         ch->pcdata->last_note = UMAX(ch->pcdata->last_note,stamp);
00550             break;
00551         case NOTE_IDEA:
00552         ch->pcdata->last_idea = UMAX(ch->pcdata->last_idea,stamp);
00553             break;
00554         case NOTE_PENALTY:
00555         ch->pcdata->last_penalty = UMAX(ch->pcdata->last_penalty,stamp);
00556             break;
00557         case NOTE_NEWS:
00558         ch->pcdata->last_news = UMAX(ch->pcdata->last_news,stamp);
00559             break;
00560         case NOTE_CHANGES:
00561         ch->pcdata->last_changes = UMAX(ch->pcdata->last_changes,stamp);
00562             break;
00563     case NOTE_HISTORY:
00564         ch->pcdata->last_history = UMAX(ch->pcdata->last_history, stamp);
00565         break;
00566     }
00567 }
00568 void do_catchup( CHAR_DATA *ch, char *argument)
00569 {
00570     ch->pcdata->last_note = current_time;
00571     ch->pcdata->last_history = current_time;
00572     ch->pcdata->last_penalty = current_time;
00573     ch->pcdata->last_idea = current_time;
00574     ch->pcdata->last_changes = current_time;
00575     ch->pcdata->last_news = current_time;
00576     send_to_char("All note spools have been caught up.\n\r",ch);
00577     return;
00578 }
00579 
00580 void parse_note( CHAR_DATA *ch, char *argument, int type )
00581 {
00582     BUFFER *buffer;
00583     char buf[MAX_STRING_LENGTH];
00584     char arg[MAX_INPUT_LENGTH];
00585     NOTE_DATA *pnote;
00586     NOTE_DATA **list;
00587     char *list_name;
00588     int vnum;
00589     int anum;
00590     char *to_format[MAX_STRING_LENGTH*4];
00591     DESCRIPTOR_DATA *d;
00592     
00593     //if ( IS_NPC(ch))
00594 //  return;
00595 
00596     switch(type)
00597     {
00598     default:
00599         return;
00600         case NOTE_NOTE:
00601             list = &note_list;
00602         list_name = "notes";
00603             break;
00604         case NOTE_IDEA:
00605             list = &idea_list;
00606         list_name = "ideas";
00607             break;
00608         case NOTE_PENALTY:
00609             list = &penalty_list;
00610         list_name = "penalties";
00611             break;
00612         case NOTE_NEWS:
00613             list = &news_list;
00614         list_name = "news";
00615             break;
00616         case NOTE_CHANGES:
00617             list = &changes_list;
00618         list_name = "changes";
00619             break;
00620     case NOTE_HISTORY:
00621         list = &history_list;
00622         list_name = "history";
00623         break;
00624     }
00625 
00626     argument = one_argument( argument, arg );
00627     smash_tilde( argument );
00628 
00629     if ( arg[0] == '\0' || !str_prefix( arg, "read" ) )
00630     {
00631         bool fAll;
00632  
00633         if ( !str_cmp( argument, "all" ) )
00634         {
00635             fAll = TRUE;
00636             anum = 0;
00637         }
00638  
00639         else if ( argument[0] == '\0' || !str_prefix(argument, "next"))
00640         /* read next unread note */
00641         {
00642             vnum = 0;
00643             for ( pnote = *list; pnote != NULL; pnote = pnote->next)
00644             {
00645                 if (!hide_note(ch,pnote))
00646                 {
00647                 /*   sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
00648                         vnum,
00649                         pnote->sender,
00650                         pnote->subject,
00651                         pnote->date,
00652                         pnote->to_list);
00653                     send_to_char( buf, ch );*/
00654          sprintf( buf, "{c--------------------------------------------------------------------------------------{x\n\r");
00655                  send_to_char(buf,ch);
00656                  sprintf( buf, "{R[{c%-3d{R]{x {W%s{c:{x %s\n\r", vnum , pnote->sender, pnote->subject);
00657                  send_to_char(buf,ch);
00658                  sprintf( buf, "%s\n\r", pnote->date);
00659                  send_to_char(buf,ch);
00660                  sprintf(buf, "To: %s\n\r",pnote->to_list);
00661                  send_to_char(buf,ch);
00662                  sprintf( buf, "{c--------------------------------------------------------------------------------------{x\n\r");
00663                                                                                          send_to_char(buf,ch);
00664                                                                                  
00665                     page_to_char( pnote->text, ch );
00666                     update_read(ch,pnote);
00667                     return;
00668                 }
00669                 else if (is_note_to(ch,pnote))
00670                     vnum++;
00671             }
00672         sprintf(buf,"You have no unread %s.\n\r",list_name);
00673         send_to_char(buf,ch);
00674             return;
00675         }
00676  
00677         else if ( is_number( argument ) )
00678         {
00679             fAll = FALSE;
00680             anum = atoi( argument );
00681         }
00682         else
00683         {
00684             send_to_char( "Read which number?\n\r", ch );
00685             return;
00686         }
00687  
00688         vnum = 0;
00689         for ( pnote = *list; pnote != NULL; pnote = pnote->next )
00690         {
00691             if ( is_note_to( ch, pnote ) && ( vnum++ == anum || fAll ) )
00692             {
00693                 sprintf( buf, "{c--------------------------------------------------------------------------------------{x\n\r");
00694         send_to_char(buf,ch);
00695         sprintf( buf, "{R[{c%-3d{R]{x {W%s{c:{x %s\n\r", vnum -1, pnote->sender, pnote->subject);
00696         send_to_char(buf,ch);
00697         sprintf( buf, "%s\n\r", pnote->date);
00698         send_to_char(buf,ch);
00699         sprintf(buf, "To: %s\n\r",pnote->to_list);
00700         send_to_char(buf,ch);
00701         sprintf( buf, "{c--------------------------------------------------------------------------------------{x\n\r");
00702         send_to_char(buf,ch);
00703                  /*   vnum - 1,
00704                     pnote->sender,
00705                     pnote->subject,
00706                     pnote->date,
00707                     pnote->to_list
00708                     );
00709                 send_to_char( buf, ch );*/
00710                 page_to_char( pnote->text, ch );
00711         update_read(ch,pnote);
00712                 return;
00713             }
00714         }
00715  
00716     sprintf(buf,"There aren't that many %s.\n\r",list_name);
00717     send_to_char(buf,ch);
00718         return;
00719     }
00720 
00721     if ( !str_prefix( arg, "list" ) )
00722     {
00723     if (IS_NPC(ch))
00724         return;
00725     vnum = 0;
00726     BUFFER *nbuf;
00727     nbuf = new_buf();
00728     for ( pnote = *list; pnote != NULL; pnote = pnote->next )
00729     {
00730         if ( is_note_to( ch, pnote ) )
00731         {
00732         sprintf( buf, "{R[{c%-3d{W%s{R]{x {W%s{c:{x %s{x\n\r",
00733             vnum, hide_note(ch,pnote) ? " " : "N", 
00734             pnote->sender, pnote->subject );
00735         //send_to_char( buf, ch );
00736         add_buf(nbuf, buf);
00737         vnum++;
00738         }
00739     }
00740     page_to_char(buf_string(nbuf), ch);
00741     free_buf(nbuf);
00742 
00743 
00744     if (!vnum)
00745     {
00746         switch(type)
00747         {
00748         case NOTE_NOTE: 
00749             send_to_char("There are no notes for you.\n\r",ch);
00750             break;
00751         case NOTE_IDEA:
00752             send_to_char("There are no ideas for you.\n\r",ch);
00753             break;
00754         case NOTE_PENALTY:
00755             send_to_char("There are no penalties for you.\n\r",ch);
00756             break;
00757         case NOTE_NEWS:
00758             send_to_char("There is no news for you.\n\r",ch);
00759             break;
00760         case NOTE_CHANGES:
00761             send_to_char("There are no changes for you.\n\r",ch);
00762             break;
00763         case NOTE_HISTORY:
00764             send_to_char("The history has not been changed.\n\r",ch);
00765             break;
00766         }
00767     }
00768     return;
00769     }
00770 
00771     if ( !str_prefix( arg, "remove" ) )
00772     {
00773         if ( !is_number( argument ) )
00774         {
00775             send_to_char( "Note remove which number?\n\r", ch );
00776             return;
00777         }
00778  
00779         anum = atoi( argument );
00780         vnum = 0;
00781         for ( pnote = *list; pnote != NULL; pnote = pnote->next )
00782         {
00783             if ( is_note_to( ch, pnote ) && vnum++ == anum )
00784             {
00785                 note_remove( ch, pnote, FALSE );
00786                 send_to_char( "Ok.\n\r", ch );
00787                 return;
00788             }
00789         }
00790  
00791     sprintf(buf,"There aren't that many %s.",list_name);
00792     send_to_char(buf,ch);
00793         return;
00794     }
00795  
00796     if ( !str_prefix( arg, "delete" ) && get_trust(ch) >= MAX_LEVEL - 1)
00797     {
00798         if ( !is_number( argument ) )
00799         {
00800             send_to_char( "Note delete which number?\n\r", ch );
00801             return;
00802         }
00803  
00804         anum = atoi( argument );
00805         vnum = 0;
00806         for ( pnote = *list; pnote != NULL; pnote = pnote->next )
00807         {
00808             if ( is_note_to( ch, pnote ) && vnum++ == anum )
00809             {
00810                 note_remove( ch, pnote,TRUE );
00811                 send_to_char( "Ok.\n\r", ch );
00812                 return;
00813             }
00814         }
00815 
00816     sprintf(buf,"There aren't that many %s.",list_name);
00817     send_to_char(buf,ch);
00818         return;
00819     }
00820 
00821     if (!str_prefix(arg,"catchup"))
00822     {
00823     switch(type)
00824     {
00825         case NOTE_NOTE: 
00826         ch->pcdata->last_note = current_time;
00827         break;
00828         case NOTE_IDEA:
00829         ch->pcdata->last_idea = current_time;
00830         break;
00831         case NOTE_PENALTY:
00832         ch->pcdata->last_penalty = current_time;
00833         break;
00834         case NOTE_NEWS:
00835         ch->pcdata->last_news = current_time;
00836         break;
00837         case NOTE_CHANGES:
00838         ch->pcdata->last_changes = current_time;
00839         break;
00840         case NOTE_HISTORY:
00841         ch->pcdata->last_history = current_time;
00842         break;
00843     }
00844     return;
00845     }
00846 
00847     /* below this point only certain people can edit notes */
00848     if ((type == NOTE_NEWS && !IS_TRUSTED(ch,ANGEL))
00849     ||  (type == NOTE_CHANGES && !IS_TRUSTED(ch,CREATOR))
00850     ||  (type == NOTE_HISTORY && !IS_TRUSTED(ch, CREATOR)))
00851     {
00852     sprintf(buf,"You aren't high enough level to write %s.",list_name);
00853     send_to_char(buf,ch);
00854     return;
00855     }
00856 
00857     if ( !str_cmp( arg, "+" ) )
00858     {
00859     note_attach( ch,type );
00860     if (ch->pnote->type != type)
00861     {
00862         send_to_char(
00863         "You already have a different note in progress.\n\r",ch);
00864         return;
00865     }
00866 
00867     if (strlen(ch->pnote->text)+strlen(argument) >= 4096)
00868     {
00869         send_to_char( "Note too long.\n\r", ch );
00870         return;
00871     }
00872 
00873     buffer = new_buf();
00874 
00875     add_buf(buffer,ch->pnote->text);
00876     add_buf(buffer,argument);
00877     add_buf(buffer,"\n\r");
00878     free_string( ch->pnote->text );
00879     ch->pnote->text = str_dup( buf_string(buffer) );
00880     free_buf(buffer);
00881     send_to_char( "Ok.\n\r", ch );
00882     return;
00883     }
00884     if ( !str_cmp( arg, "++" ) )
00885         {
00886             note_attach( ch,type );
00887         if (ch->pnote->type != type)
00888             {
00889                 send_to_char(
00890                         "You already have a different note in progress.\n\r",ch);
00891             return;
00892         }
00893 
00894         string_append( ch, &ch->pnote->text );
00895         return;
00896     }
00897     if (!str_cmp( arg, "format"))
00898     {
00899         //char *to_format[MAX_STRING_LENGTH*4];
00900         if (ch->pnote == NULL)
00901         {
00902             send_to_char("You are not currently working on a note.\n\r",ch);
00903             return;
00904         }
00905 
00906         note_attach(ch,type);
00907         if (ch->pnote->type != type)
00908         {
00909             send_to_char("You already have a different note in progress.\n\r",ch);
00910             return;
00911         }
00912         *to_format = str_dup(ch->pnote->text);
00913         ch->pnote->text = format_string(*to_format);
00914         send_to_char("Note formated.\n\r",ch);
00915         return;
00916     }
00917     
00918     
00919     if (!str_cmp(arg,"-"))
00920     {
00921     int len;
00922     bool found = FALSE;
00923 
00924     note_attach(ch,type);
00925         if (ch->pnote->type != type)
00926         {
00927             send_to_char(
00928                 "You already have a different note in progress.\n\r",ch);
00929             return;
00930         }
00931 
00932     if (ch->pnote->text == NULL || ch->pnote->text[0] == '\0')
00933     {
00934         send_to_char("No lines left to remove.\n\r",ch);
00935         return;
00936     }
00937 
00938     strcpy(buf,ch->pnote->text);
00939 
00940     for (len = strlen(buf); len > 0; len--)
00941     {
00942         if (buf[len] == '\r')
00943         {
00944         if (!found)  /* back it up */
00945         {
00946             if (len > 0)
00947             len--;
00948             found = TRUE;
00949         }
00950         else /* found the second one */
00951         {
00952             buf[len + 1] = '\0';
00953             free_string(ch->pnote->text);
00954             ch->pnote->text = str_dup(buf);
00955             return;
00956         }
00957         }
00958     }
00959     buf[0] = '\0';
00960     free_string(ch->pnote->text);
00961     ch->pnote->text = str_dup(buf);
00962     return;
00963     }
00964 
00965     if ( !str_prefix( arg, "subject" ) )
00966     {
00967     note_attach( ch,type );
00968         if (ch->pnote->type != type)
00969         {
00970             send_to_char(
00971                 "You already have a different note in progress.\n\r",ch);
00972             return;
00973         }
00974 
00975     free_string( ch->pnote->subject );
00976     ch->pnote->subject = str_dup( argument );
00977     send_to_char( "Ok.\n\r", ch );
00978     return;
00979     }
00980 
00981     if ( !str_prefix( arg, "to" ) )
00982     {
00983     note_attach( ch,type );
00984         if (ch->pnote->type != type)
00985         {
00986             send_to_char(
00987                 "You already have a different note in progress.\n\r",ch);
00988             return;
00989         }
00990     free_string( ch->pnote->to_list );
00991     ch->pnote->to_list = str_dup( argument );
00992     send_to_char( "Ok.\n\r", ch );
00993     return;
00994     }
00995 
00996     if ( !str_prefix( arg, "clear" ) )
00997     {
00998     if ( ch->pnote != NULL )
00999     {
01000         free_note(ch->pnote);
01001         ch->pnote = NULL;
01002     }
01003 
01004     send_to_char( "Ok.\n\r", ch );
01005     return;
01006     }
01007 
01008     if ( !str_prefix( arg, "show" ) )
01009     {
01010     if ( ch->pnote == NULL )
01011     {
01012         send_to_char( "You have no note in progress.\n\r", ch );
01013         return;
01014     }
01015 
01016     if (ch->pnote->type != type)
01017     {
01018         send_to_char("You aren't working on that kind of note.\n\r",ch);
01019         return;
01020     }
01021 /*
01022     sprintf( buf, "%s: %s\n\rTo: %s\n\r",
01023         ch->pnote->sender,
01024         ch->pnote->subject,
01025         ch->pnote->to_list
01026         );
01027     send_to_char( buf, ch );
01028     send_to_char( ch->pnote->text, ch );*/
01029         sprintf( buf, "{c--------------------------------------------------------------------------------------{x\n\r");
01030         send_to_char(buf,ch);
01031         sprintf( buf, "{W%s{c:{x %s\n\r",  ch->pnote->sender, ch->pnote->subject);
01032         send_to_char(buf,ch);
01033         //sprintf( buf, "%s\n\r", ch->pnote->date);
01034         //send_to_char(buf,ch);
01035         sprintf(buf, "To: %s\n\r",ch->pnote->to_list);
01036         send_to_char(buf,ch);
01037         sprintf( buf, "{c--------------------------------------------------------------------------------------{x\n\r");
01038         send_to_char(buf,ch);
01039     send_to_char( ch->pnote->text, ch);
01040 
01041                                                                                       
01042     return;
01043     }
01044 
01045     if ( !str_prefix( arg, "post" ) || !str_prefix(arg, "send"))
01046     {
01047     char *strtime;
01048 
01049     if ( ch->pnote == NULL )
01050     {
01051         send_to_char( "You have no note in progress.\n\r", ch );
01052         return;
01053     }
01054 
01055         if (ch->pnote->type != type)
01056         {
01057             send_to_char("You aren't working on that kind of note.\n\r",ch);
01058             return;
01059         }
01060 
01061     if (!str_cmp(ch->pnote->to_list,""))
01062     {
01063         send_to_char(
01064         "You need to provide a recipient (name, all, or immortal).\n\r",
01065         ch);
01066         return;
01067     }
01068 
01069     if (!str_cmp(ch->pnote->subject,""))
01070     {
01071         send_to_char("You need to provide a subject.\n\r",ch);
01072         return;
01073     }
01074 
01075     for (d = descriptor_list; d != NULL; d = d->next)
01076     {
01077         if (d->connected == CON_PLAYING)
01078         {
01079             if (is_name(d->character->name, ch->pnote->to_list) ||
01080                     ((is_name("all", ch->pnote->to_list) &&
01081                      d->character->name != ch->name) ||
01082                     (is_name("imm", ch->pnote->to_list) && 
01083                      d->character->level > 51) ||
01084                     (is_name("immortal", ch->pnote->to_list) &&
01085                      d->character->level > 51)))
01086             {
01087                 switch(ch->pnote->type)
01088                 {
01089                     case NOTE_NOTE:
01090                         printf_to_char(d->character, "%s has left you a note.\n\r{*", ch->name);
01091                         break;
01092                     case NOTE_IDEA:
01093                         printf_to_char(d->character, "%s has left an idea.\n\r{*", ch->name);
01094                         break;
01095                     case NOTE_CHANGES:
01096                         printf_to_char(d->character, "%s has done a change, read about it!{*\n\r",
01097                                 ch->name);
01098                         break;
01099                     case NOTE_PENALTY:
01100                         printf_to_char(d->character, "%s has penned someone.{*\n\r", ch->name);
01101                         break;
01102                     case NOTE_NEWS:
01103                         printf_to_char(d->character, "%s has posted some news.{*\n\r",ch->name);
01104                         break;
01105                     case NOTE_HISTORY:
01106                         printf_to_char(d->character, "%s has changed the history around you.{*\n\r",
01107                                 ch->name);
01108                         break;
01109                 }
01110             }
01111         }
01112     }
01113     
01114     
01115             
01116                     
01117 
01118     
01119 
01120     ch->pnote->next         = NULL;
01121     strtime             = ctime( &current_time );
01122     strtime[strlen(strtime)-1]  = '\0';
01123     ch->pnote->date         = str_dup( strtime );
01124     ch->pnote->date_stamp       = current_time;
01125 
01126     append_note(ch->pnote);
01127     ch->pnote = NULL;
01128     send_to_char("Note posted. Thank you.\n\r",ch);
01129     return;
01130     }
01131 
01132     send_to_char( "Note a valid note command.\n\r", ch );
01133     return;
01134 }
01135 

Generated on Thu Jan 13 21:48:13 2005 for Beyond the Shadows by  doxygen 1.4.0