/* Remove a note */ static void do_nremove (CHAR_DATA *ch, char *argument) { NOTE_DATA *p; if (!is_number(argument)) { send_to_char ("Remove which note?\n\r",ch); return; } p = find_note (ch, ch->pcdata->board, atoi(argument)); if (!p) { send_to_char ("No such note.\n\r",ch); return; } if (str_cmp(ch->pcdata->switchname,p->sender) && ch->trust < MAX_LEVEL) { send_to_char ("You are not authorized to remove this note.\n\r",ch); return; } unlink_note (ch->pcdata->board,p); free_note (p); send_to_char ("Note removed!\n\r",ch); save_board(ch->pcdata->board); /* save the board */ }
void handle_con_note_finish (DESCRIPTOR_DATA *d, char * argument) { char buf[MAX_STRING_LENGTH]; CHAR_DATA *ch = d->character; if (!ch->pcdata->in_progress) { d->connected = CON_PLAYING; bug ("nanny: In CON_NOTE_FINISH, but no note in progress",0); return; } switch (tolower(argument[0])) { case 'c': /* keep writing */ write_to_buffer (d,"Continuing note...\n\r",0); d->connected = CON_NOTE_TEXT; break; case 'v': /* view note so far */ if (ch->pcdata->in_progress->text) { write_to_buffer (d,GREEN "Text of your note so far:" NO_COLOR "\n\r",0); write_to_buffer (d, ch->pcdata->in_progress->text, 0); } else write_to_buffer (d,"You haven't written a thing!\n\r\n\r",0); write_to_buffer (d, szFinishPrompt, 0); write_to_buffer (d, "\n\r",0); break; case 'p': /* post note */ if (board_number(ch->pcdata->board) < 4 && is_full_name("all", ch->pcdata->in_progress->to_list)) { xprintf(buf,"A new note has been posted by %s on board %d", ch->name, board_number(ch->pcdata->board)+1); do_info(ch, buf); } finish_note (ch->pcdata->board, ch->pcdata->in_progress); write_to_buffer (d, "Note posted.\n\r",0); d->connected = CON_PLAYING; ch->pcdata->in_progress = NULL; act (BOLD GREEN "$n finishes $s note." NO_COLOR , ch, NULL, NULL, TO_ROOM); break; case 'f': write_to_buffer (d, "Note cancelled!\n\r",0); free_note (ch->pcdata->in_progress); ch->pcdata->in_progress = NULL; d->connected = CON_PLAYING; break; default: /* invalid response */ write_to_buffer (d, "Huh? Valid answers are:\n\r\n\r",0); write_to_buffer (d, szFinishPrompt, 0); write_to_buffer (d, "\n\r",0); } if (d->connected == CON_PLAYING) REMOVE_BIT(ch->extra, EXTRA_AFK); }
void clear_notes(void) { NOTE_DATA *curr, *next; log_string("Cleaning: note_list"); for(curr = note_list; curr; curr = next) { next = curr->next; free_note(curr); } note_list = NULL; log_string("Cleaning: idea_list"); for(curr = idea_list; curr; curr = next) { next = curr->next; free_note(curr); } idea_list = NULL; log_string("Cleaning: penalty_list"); for(curr = penalty_list; curr; curr = next) { next = curr->next; free_note(curr); } penalty_list = NULL; log_string("Cleaning: news_list"); for(curr = news_list; curr; curr = next) { next = curr->next; free_note(curr); } news_list = NULL; log_string("Cleaning: changes_list"); for(curr = changes_list; curr; curr = next) { next = curr->next; free_note(curr); } changes_list = NULL; }
void free_char (CHAR_DATA *ch) { OBJ_DATA *obj; OBJ_DATA *obj_next; AFFECT_DATA *paf; AFFECT_DATA *paf_next; if (!IS_VALID(ch)) return; if (IS_NPC(ch)) mobile_count--; for (obj = ch->carrying; obj != NULL; obj = obj_next) { obj_next = obj->next_content; extract_obj(obj); } for (paf = ch->affected; paf != NULL; paf = paf_next) { paf_next = paf->next; affect_remove(ch,paf); } free_string(ch->name); free_string(ch->short_descr); free_string(ch->long_descr); free_string(ch->description); free_string(ch->prompt); free_string(ch->prefix); free_note (ch->pnote); free_pcdata(ch->pcdata); ch->next = char_free; char_free = ch; INVALIDATE(ch); return; }
void note_remove( BOARD_DATA * board, NOTE_DATA * pnote ) { if( !board ) { bug( "note remove: null board", 0 ); return; } if( !pnote ) { bug( "note remove: null pnote", 0 ); return; } /* * Remove note from linked list. */ UNLINK( pnote, board->first_note, board->last_note, next, prev ); --board->num_posts; free_note( pnote ); write_board( board ); }
int main(int argc, char *argv[]) { int ret = 1, i; dldev_t dev; note_t db; u8 *data; u16 len; /* for data security */ /* umask(S_IRWXG | S_IRWXO); */ while((i = getopt(argc, argv, "hd:u:e:")) != -1){ switch(i){ case 'd': dev_file = optarg; break; case 'u': unused_recs = atoi(optarg); if(unused_recs < 0) unused_recs = 0; break; case 'e': extra_msg_len = atoi(optarg); if(extra_msg_len < 0) extra_msg_len = 0; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; set_note_unused_recs(unused_recs); set_note_extra_len(extra_msg_len); #ifdef USB_USBHID dev.usb.file = dev_file; #endif if(open_dev(&dev)){ ERROR("open_dev"); goto exit; } if(start_session(&dev)){ ERROR("read_app_info"); goto exit; } /******************************************************************************/ #ifdef DEBUG for(i = 0; i < NUM_APPS; i++){ if(!dev.app[i].acd.app_idx) continue; printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i, dev.app[i].acd.app_idx, dev.app[i].acd.code_loc, dev.app[i].acd.db_loc, dev.app[i].acd.code_invalid, dev.app[i].acd.db_modified, dev.app[i].acd.db_invalid, dev.app[i].acd.passwd_req, dev.app[i].acd.mode_name, dev.app[i].acb.app_type, dev.app[i].acb.app_inst, dev.app[i].acb.asd_addr, dev.app[i].acb.add_addr, dev.app[i].acb.state_mgr_addr, dev.app[i].acb.refresh_addr, dev.app[i].acb.banner_addr, dev.app[i].acb.code_addr, dev.app[i].banner ); } #endif /******************************************************************************/ if(read_note_mem(&dev, &db)){ ERROR("read_note_mem"); goto end; } create_note(&db, &data, &len); if(load_add(&dev, find_app(&dev, "NOTE"), data)){ ERROR("load_add"); goto end; } free(data); print_note(&db, stdout); free_note(&db); /******************************************************************************/ end: if(end_session(&dev)){ ERROR("end_session"); goto exit; } ret = 0; exit: close_dev(&dev); exit(ret); }
void parse_note( CHAR_DATA *ch, char *argument, int type ) { BUFFER *buffer; char buf[MAX_STRING_LENGTH], query[MSL]; char arg[MAX_INPUT_LENGTH]; MYSQL_RES *res; MYSQL_ROW row; char *list_name; int vnum; int anum; switch(type) { default: return; case NOTE_NOTE: list_name = "notes"; break; case NOTE_IDEA: list_name = "ideas"; break; case NOTE_PENALTY: list_name = "penalties"; break; case NOTE_NEWS: list_name = "news"; break; case NOTE_CHANGES: list_name = "changes"; break; } argument = one_argument( argument, arg ); smash_tilde( argument ); if ( arg[0] == '\0' || !str_prefix( arg, "read" ) ) { bool fAll; if ( !str_cmp( argument, "all" ) ) { fAll = TRUE; anum = 0; } else if ( argument[0] == '\0' || !str_prefix(argument, "next")) /* read next unread note */ { vnum = 0; sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type); res = one_query_res(query); while((row=mysql_fetch_row(res))) { if (!hide_note(ch,row)) { sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r", vnum, row[1], row[4], row[2], row[3]); send_to_char( buf, ch ); page_to_char( row[5], ch ); update_read(ch,atol(row[6]),atoi(row[0])); mysql_free_result(res); return; } else if(is_note_to(ch,row[1],row[3])) vnum++; } sprintf(buf,"You have no unread %s.\n\r",list_name); send_to_char(buf,ch); mysql_free_result(res); return; } else if ( is_number( argument ) ) { fAll = FALSE; anum = atoi( argument ); } else { send_to_char( "Read which number?\n\r", ch ); return; } vnum = 0; sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type); res = one_query_res(query); while((row=mysql_fetch_row(res))) { if (is_note_to(ch,row[1],row[3]) && (vnum++ == anum)) { sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r", anum, row[1], row[4], row[2], row[3]); send_to_char( buf, ch ); page_to_char( row[5], ch ); update_read(ch,atol(row[6]),atoi(row[0])); mysql_free_result(res); return; } } sprintf(buf,"There aren't that many %s.\n\r",list_name); send_to_char(buf,ch); mysql_free_result(res); return; } if ( !str_prefix( arg, "list" ) ) { vnum = 0; sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type); res = one_query_res(query); while((row=mysql_fetch_row(res))) { if (is_note_to(ch,row[1],row[3])) { sprintf( buf, "[%3d%s] %s: %s\n\r", vnum, hide_note(ch,row) ? " " : "N", row[1], row[4]); send_to_char( buf, ch ); vnum++; } } if (!vnum) { switch(type) { case NOTE_NOTE: send_to_char("There are no notes for you.\n\r",ch); break; case NOTE_IDEA: send_to_char("There are no ideas for you.\n\r",ch); break; case NOTE_PENALTY: send_to_char("There are no penalties for you.\n\r",ch); break; case NOTE_NEWS: send_to_char("There is no news for you.\n\r",ch); break; case NOTE_CHANGES: send_to_char("There are no changes for you.\n\r",ch); break; } } mysql_free_result(res); return; } if ( !str_prefix( arg, "remove" ) ) { if ( !is_number( argument ) ) return send_to_char( "Note remove which number?\n\r", ch ); anum = atoi( argument ); vnum = 0; sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type); res = one_query_res(query); while((row=mysql_fetch_row(res))) { if (!str_cmp(ch->true_name, row[1]) && vnum++ == anum ) { sprintf(query,"DELETE FROM notes WHERE timestamp=%s AND sender=\"%s\"", row[6], row[1]); one_query(query); send_to_char( "Ok.\n\r", ch ); mysql_free_result(res); return; } } send_to_char("You must provide the number of a note you have written to remove.\n\r",ch); mysql_free_result(res); return; } if ( !str_prefix( arg, "delete" ) && get_trust(ch) >= MAX_LEVEL - 2) { if ( !is_number( argument ) ) return send_to_char( "Note delete which number?\n\r", ch ); anum = atoi( argument ); vnum = 0; sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type); res = one_query_res(query); while((row=mysql_fetch_row(res))) { if ( is_note_to( ch,row[1],row[3] ) && vnum++ == anum ) { sprintf(query,"DELETE FROM notes WHERE timestamp=%s AND sender=\"%s\"", row[6], row[1]); one_query(query); send_to_char("Ok.\n\r",ch); mysql_free_result(res); return; } } sprintf(buf,"There aren't that many %s.\n\r",list_name); send_to_char(buf,ch); mysql_free_result(res); return; } /* below this point only certain people can edit notes */ if ((type == NOTE_NEWS && !IS_TRUSTED(ch,ANGEL)) || (type == NOTE_CHANGES && !IS_TRUSTED(ch,CREATOR))) { sprintf(buf,"You aren't high enough level to write %s.",list_name); send_to_char(buf,ch); return; } if ( !str_cmp( arg, "+" ) ) { note_attach( ch,type ); if (ch->pnote->type != type) return send_to_char("You already have a different note in progress.\n\r",ch); if (strlen(ch->pnote->text)+strlen(argument) >= 4096) return send_to_char( "Note too long.\n\r", ch ); buffer = new_buf(); add_buf(buffer,ch->pnote->text); add_buf(buffer,argument); add_buf(buffer,"\n\r"); free_pstring( ch->pnote->text ); ch->pnote->text = palloc_string( buf_string(buffer) ); free_buf(buffer); send_to_char( "Ok.\n\r", ch ); return; } if (!str_cmp(arg,"-")) { int len; bool found = FALSE; note_attach(ch,type); if (ch->pnote->type != type) return send_to_char("You already have a different note in progress.\n\r",ch); if (ch->pnote->text == NULL || ch->pnote->text[0] == '\0') return send_to_char("No lines left to remove.\n\r",ch); strcpy(buf,ch->pnote->text); for (len = strlen(buf); len > 0; len--) { if (buf[len] == '\r') { if (!found) /* back it up */ { if (len > 0) len--; found = TRUE; } else /* found the second one */ { buf[len + 1] = '\0'; free_pstring(ch->pnote->text); ch->pnote->text = palloc_string(buf); return; } } } buf[0] = '\0'; free_pstring(ch->pnote->text); ch->pnote->text = palloc_string(buf); return; } if ( !str_prefix( arg, "subject" ) ) { note_attach( ch,type ); if (ch->pnote->type != type) return send_to_char("You already have a different note in progress.\n\r",ch); free_pstring( ch->pnote->subject ); ch->pnote->subject = palloc_string( argument ); send_to_char( "Ok.\n\r", ch ); return; } if ( !str_prefix( arg, "to" ) ) { note_attach( ch,type ); if (ch->pnote->type != type) return send_to_char("You already have a different note in progress.\n\r",ch); if (is_name("all", argument) && !IS_IMMORTAL(ch) && !IS_HEROIMM(ch) && !(ch->pcdata->induct == CABAL_LEADER)) return send_to_char("Sorry, you can't do that!\n\r",ch); if (is_number(argument) && !IS_IMMORTAL(ch)) return send_to_char("You can't do that.\n\r",ch); free_pstring( ch->pnote->to_list ); ch->pnote->to_list = palloc_string( argument ); send_to_char( "Ok.\n\r", ch ); return; } if ( !str_prefix( arg, "clear" ) ) { if ( ch->pnote != NULL ) { free_note(ch->pnote); ch->pnote = NULL; } send_to_char( "Ok.\n\r", ch ); return; } if ( !str_prefix( arg, "show" ) ) { if ( ch->pnote == NULL ) return send_to_char( "You have no note in progress.\n\r", ch ); if (ch->pnote->type != type) return send_to_char("You aren't working on that kind of note.\n\r",ch); sprintf( buf, "%s: %s\n\rTo: %s\n\r", ch->pnote->sender, ch->pnote->subject, ch->pnote->to_list ); send_to_char( buf, ch ); send_to_char( ch->pnote->text, ch ); return; } if ( !str_prefix( arg, "post" ) || !str_prefix(arg, "send")) { char *strtime; if ( ch->pnote == NULL ) return send_to_char( "You have no note in progress.\n\r", ch ); if (ch->pnote->type != type) return send_to_char("You aren't working on that kind of note.\n\r",ch); if (!str_cmp(ch->pnote->to_list,"")) return send_to_char("You need to provide a recipient (name, all, or immortal).\n\r", ch); if (!str_cmp(ch->pnote->subject,"")) return send_to_char("You need to provide a subject.\n\r",ch); if (is_affected_prof(ch, "note_written") && !IS_IMMORTAL(ch)) return send_to_char("You have written a note too recently.\n\r",ch); ch->pnote->next = NULL; strtime = ctime( ¤t_time ); strtime[strlen(strtime)-1] = '\0'; ch->pnote->date = palloc_string( strtime ); ch->pnote->date_stamp = current_time; append_note(ch->pnote); ch->pnote = NULL; send_to_char("Note sent.\n\r",ch); add_prof_affect(ch, "note_written", 4, TRUE); return; } send_to_char( "You can't do that.\n\r", ch ); return; }
void load_thread(char *name, NOTE_DATA **list, int type, time_t free_time) { FILE *fp; NOTE_DATA *pnotelast; if ( ( fp = fopen( name, "r" ) ) == NULL ) return; pnotelast = NULL; for ( ; ; ) { NOTE_DATA *pnote; char letter; do { letter = getc( fp ); if ( feof(fp) ) { fclose( fp ); return; } } while ( isspace(letter) ); ungetc( letter, fp ); CREATE( pnote, NOTE_DATA, 1 ); if ( str_cmp( fread_word( fp ), "sender" ) ) break; pnote->sender = fread_string( fp ); if ( str_cmp( fread_word( fp ), "date" ) ) break; pnote->date = fread_string( fp ); if ( str_cmp( fread_word( fp ), "stamp" ) ) break; pnote->date_stamp = fread_number(fp); if ( str_cmp( fread_word( fp ), "to" ) ) break; pnote->to_list = fread_string( fp ); if ( str_cmp( fread_word( fp ), "subject" ) ) break; pnote->subject = fread_string( fp ); if ( str_cmp( fread_word( fp ), "text" ) ) break; pnote->text = fread_string( fp ); if (free_time && pnote->date_stamp < current_time - free_time) { free_note(pnote); continue; } pnote->type = type; if (*list == NULL) *list = pnote; else pnotelast->next = pnote; pnotelast = pnote; } strcpy( strArea, NOTE_FILE ); fpArea = fp; bug( "Load_notes: bad key word.", 0 ); exit( 1 ); return; }
/* * Snarf a board. */ void load_board( BOARD_DATA *board ) { FILE *fp; FILE *fpArch; NOTE_DATA *pnotelast; char strsave [ MAX_INPUT_LENGTH ]; sprintf( strsave, "%s%s", NOTE_DIR, board->short_name ); if ( !( fp = fopen( strsave, "r" ) ) ) return; pnotelast = NULL; for ( ; ; ) { NOTE_DATA *pnote; int letter; int stat; do { letter = getc( fp ); if ( feof( fp ) ) { fclose( fp ); return; } } while ( isspace( letter ) ); ungetc( letter, fp ); pnote = (NOTE_DATA *) alloc_mem( sizeof( *pnote ) ); if ( str_cmp( fread_word( fp, &stat ), "sender" ) ) break; pnote->sender = fread_string( fp, &stat ); if ( str_cmp( fread_word( fp, &stat ), "date" ) ) break; pnote->date = fread_string( fp, &stat ); if ( str_cmp( fread_word( fp, &stat ), "stamp" ) ) break; pnote->date_stamp = fread_number( fp, &stat ); if ( str_cmp( fread_word( fp, &stat ), "expire" ) ) break; pnote->expire = fread_number( fp, &stat ); if ( str_cmp( fread_word( fp, &stat ), "to" ) ) break; pnote->to_list = fread_string( fp, &stat ); if ( str_cmp( fread_word( fp, &stat ), "subject" ) ) break; pnote->subject = fread_string( fp, &stat ); if ( str_cmp( fread_word( fp, &stat ), "text" ) ) break; pnote->text = fread_string( fp, &stat ); pnote->next = NULL; /* * Should this note be archived right now? */ if ( pnote->expire < current_time ) { sprintf( strsave, "%s%s.old", NOTE_DIR, board->short_name ); if ( !( fpArch = fopen( strsave, "a" ) ) ) bug( "Load_board: couldn't open arch boards for writing.", 0 ); else { append_note( fpArch, pnote ); fclose( fpArch ); } free_note( pnote ); board->changed = TRUE; continue; } if ( !board->note_first ) board->note_first = pnote; else pnotelast->next = pnote; pnotelast = pnote; } strcpy( strArea, board->short_name ); fpArea = fp; bug( "Load_board: bad key word.", 0 ); return; }
/* Start writing a note */ static void do_nwrite (CHAR_DATA *ch, char *argument) { char *strtime; char buf[200]; if (IS_NPC(ch)) /* NPC cannot post notes */ return; //if ((get_age(ch) - 17) < 2) //{ // send_to_char("Newbies cannot write notes.\n\r",ch); // return; // } if (has_timer(ch)) return; if (IS_SET(ch->act, PLR_SILENCE) ) { send_to_char("You are not allowed to write notes.\n\r",ch); return; } if (ch->pcdata->board == NULL) { send_to_char("You're not on a board.\n\r", ch ); return;} if (get_trust(ch) < ch->pcdata->board->write_level) { send_to_char ("You cannot post notes on this board.\n\r",ch); return; } if (ch->position != POS_STANDING) { send_to_char("You can only write notes while standing.\n\r", ch); return; } /* continue previous note, if any text was written*/ if (ch->pcdata->in_progress && (!ch->pcdata->in_progress->text)) { send_to_char ("Note in progress cancelled because you did not manage to write any text \n\r" "before losing link.\n\r\n\r",ch); free_note (ch->pcdata->in_progress); ch->pcdata->in_progress = NULL; } if (!ch->pcdata->in_progress) { ch->pcdata->in_progress = new_note(); ch->pcdata->in_progress->sender = str_dup (ch->pcdata->switchname); /* convert to ascii. ctime returns a string which last character is \n, so remove that */ strtime = ctime (¤t_time); strtime[strlen(strtime)-1] = '\0'; ch->pcdata->in_progress->date = str_dup (strtime); } SET_BIT(ch->extra, EXTRA_AFK); if (ch->master) stop_follower(ch, FALSE); act (BOLD GREEN "$n starts writing a note." NO_COLOR , ch, NULL, NULL, TO_ROOM); /* Begin writing the note ! */ xprintf (buf, "You are now %s a new note on the " BOLD "%s" NO_COLOR " board.\n\r" "If you are using tintin, type #verbose to turn off alias expansion!\n\r\n\r", ch->pcdata->in_progress->text ? "continuing" : "posting", ch->pcdata->board->short_name); send_to_char (buf,ch); xprintf (buf, BOLD YELLOW "From" NO_COLOR ": %s\n\r\n\r", ch->pcdata->switchname); send_to_char (buf,ch); if (!ch->pcdata->in_progress->text) /* Are we continuing an old note or not? */ { switch (ch->pcdata->board->force_type) { case DEF_NORMAL: xprintf (buf, "If you press Return, default recipient \"" BOLD "%s" NO_COLOR "\" will be chosen.\n\r", ch->pcdata->board->names); break; case DEF_INCLUDE: xprintf (buf, "The recipient list MUST include \"" BOLD "%s" NO_COLOR "\". If not, it will be added automatically.\n\r", ch->pcdata->board->names); break; case DEF_EXCLUDE: xprintf (buf, "The recipient of this note must NOT include: \"" BOLD "%s" NO_COLOR "\".", ch->pcdata->board->names); break; } send_to_char (buf,ch); send_to_char ("\n\r" BOLD YELLOW "To" NO_COLOR ": ",ch); ch->desc->connected = CON_NOTE_TO; /* nanny takes over from here */ } else /* we are continuing, print out all the fields and the note so far*/ { xprintf (buf, BOLD YELLOW "To" NO_COLOR ": %s\n\r" BOLD YELLOW "Expires" NO_COLOR ": %s\n\r" BOLD YELLOW "Subject" NO_COLOR ": %s\n\r", ch->pcdata->in_progress->to_list, ctime(&ch->pcdata->in_progress->expire), ch->pcdata->in_progress->subject); send_to_char (buf,ch); send_to_char (BOLD GREEN "Your note so far:\n\r" NO_COLOR,ch); if (ch->pcdata->in_progress != NULL) send_to_char (ch->pcdata->in_progress->text,ch); send_to_char ("\n\rEnter text. Type " BOLD "~" NO_COLOR " or " BOLD "END" NO_COLOR " on an empty line to end note.\n\r" "=======================================================\n\r",ch); ch->desc->connected = CON_NOTE_TEXT; } }
/* Load a single board */ static void load_board (BOARD_DATA *board) { FILE *fp, *fp_archive; NOTE_DATA *last_note; char filename[200]; xprintf (filename, "%s%s", NOTE_DIR, board->short_name); fp = fopen (filename, "r"); /* Silently return */ if (!fp) return; /* Start note fetching. copy of db.c:load_notes() */ last_note = NULL; for ( ; ; ) { NOTE_DATA *pnote; char letter; do { letter = getc( fp ); if ( feof(fp) ) { fclose( fp ); return; } } while ( isspace(letter) ); ungetc( letter, fp ); pnote = alloc_perm( sizeof(*pnote) ); if ( str_cmp( fread_word( fp ), "sender" ) ) break; pnote->sender = fread_string( fp ); if ( str_cmp( fread_word( fp ), "date" ) ) break; pnote->date = fread_string( fp ); if ( str_cmp( fread_word( fp ), "stamp" ) ) break; pnote->date_stamp = fread_number( fp ); if ( str_cmp( fread_word( fp ), "expire" ) ) break; pnote->expire = fread_number( fp ); if ( str_cmp( fread_word( fp ), "to" ) ) break; pnote->to_list = fread_string( fp ); if ( str_cmp( fread_word( fp ), "subject" ) ) break; pnote->subject = fread_string( fp ); if ( str_cmp( fread_word( fp ), "text" ) ) break; pnote->text = fread_string( fp ); pnote->next = NULL; /* jic */ /* Should this note be archived right now ? */ if (pnote->expire < current_time) { char archive_name[200]; xprintf (archive_name, "%s%s.old", NOTE_DIR, board->short_name); fp_archive = fopen (archive_name, "a"); if (!fp_archive) bug ("Could not open archive boards for writing",0); else { append_note (fp_archive, pnote); fclose (fp_archive); /* it might be more efficient to close this later */ } free_note (pnote); board->changed = TRUE; continue; } if ( board->note_first == NULL ) board->note_first = pnote; else last_note->next = pnote; last_note = pnote; } bug( "Load_notes: bad key word.", 0 ); return; /* just return */ }
void handle_con_note_text (DESCRIPTOR_DATA *d, char * argument) { CHAR_DATA *ch = d->character; char buf[MAX_STRING_LENGTH]; char letter[4*MAX_STRING_LENGTH]; if (!ch->pcdata->in_progress) { d->connected = CON_PLAYING; bug ("nanny: In CON_NOTE_TEXT, but no note in progress",0); return; } /* First, check for EndOfNote marker */ strcpy (buf, argument); if ((!str_cmp(buf, "~")) || (!str_cmp(buf, "END"))) { write_to_buffer (d, "\n\r\n\r",0); write_to_buffer (d, szFinishPrompt, 0); write_to_buffer (d, "\n\r", 0); d->connected = CON_NOTE_FINISH; return; } else if (!str_cmp(buf, "~delete")) { delete_last_line_in_note(ch); return; } smash_tilde (buf); /* smash it now */ /* Check for too long lines. Do not allow lines longer than 80 chars */ if (strlen(buf) > MAX_LINE_LENGTH) { write_to_buffer (d, "Too long line rejected. Do NOT go over 80 characters!\n\r",0); return; } /* Not end of note. Copy current text into temp buffer, add new line, and copy back */ /* How would the system react to strcpy( , NULL) ? */ if (ch->pcdata->in_progress->text != NULL) { strcpy (letter, ch->pcdata->in_progress->text); free_string (ch->pcdata->in_progress->text); ch->pcdata->in_progress->text = NULL; /* be sure we don't free it twice */ } else strcpy (letter, ""); /* Check for overflow */ if ((strlen2(letter) + strlen2(buf)) > MAX_NOTE_TEXT) { /* Note too long, take appropriate steps */ write_to_buffer (d, "Note too long!\n\r", 0); free_note (ch->pcdata->in_progress); ch->pcdata->in_progress = NULL; /* important */ d->connected = CON_PLAYING; return; } /* Add new line to the buffer */ strcat (letter, buf); strcat (letter, "\r\n"); /* new line. \r first to make note files better readable */ /* allocate dynamically */ ch->pcdata->in_progress->text = str_dup (letter); }
void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote, bool idelete) { char to_new[MAX_INPUT_LENGTH]; char to_one[MAX_INPUT_LENGTH]; NOTE_DATA *prev; NOTE_DATA **list; char *to_list; if (!idelete) { /* make a new list */ to_new[0] = '\0'; to_list = pnote->to_list; while ( *to_list != '\0' ) { to_list = one_argument( to_list, to_one ); if ( to_one[0] != '\0' && str_cmp( ch->name, to_one ) ) { strcat( to_new, " " ); strcat( to_new, to_one ); } } /* Just a simple recipient removal? */ if ( str_cmp( ch->name, pnote->sender ) && to_new[0] != '\0' ) { PURGE_DATA( pnote->to_list ); pnote->to_list = str_dup( to_new + 1 ); return; } } /* nuke the whole note */ switch(pnote->type) { default: return; case NOTE_NOTE: list = ¬e_list; break; case NOTE_IDEA: list = &idea_list; break; case NOTE_PENALTY: list = &penalty_list; break; case NOTE_NEWS: list = &news_list; break; case NOTE_CHANGES: list = &changes_list; break; } /* * Remove note from linked list. */ if ( pnote == *list ) { *list = pnote->next; } else { for ( prev = *list; prev != NULL; prev = prev->next ) { if ( prev->next == pnote ) break; } if ( prev == NULL ) { bug( "Note_remove: pnote not found.", 0 ); return; } prev->next = pnote->next; } save_notes(pnote->type); free_note(pnote); return; }
void do_project( CHAR_DATA *ch, char *argument ) { char arg[MAX_INPUT_LENGTH]; char arg1[MAX_INPUT_LENGTH]; char arg2[MAX_INPUT_LENGTH]; char buf[MSL]; int pcount; int pnum; PROJECT_DATA *pproject; if( IS_NPC( ch ) ) return; if( !ch->desc ) { bug( "do_project: no descriptor", 0 ); return; } argument = one_argument( argument, arg ); smash_tilde( argument ); if( !str_cmp( arg, "save" ) ) { write_projects(); send_to_char ("Projects saved.\n\r",ch); return; } if ( !str_cmp( arg, "code" ) ) { pcount = 0; send_to_char( " ## | Owner | Project |\n\r",ch); send_to_char( "---|-------------|----------------------|--------------------------|-----------\n\r",ch); for( pproject = first_project; pproject; pproject = pproject->next ) { pcount++; if ( (pproject->status && str_cmp(pproject->status, "approved")) || pproject->coder != NULL) continue; xprintf(buf, "%2d | %-11s | %-20s |\n\r", pcount, pproject->owner ? pproject->owner : "(None)", pproject->name); send_to_char(buf, ch); } return; } if ( !str_cmp( arg, "more" ) || !str_cmp( arg, "mine" ) ) { NOTE_DATA *log; bool MINE = FALSE; int num_logs=0; pcount = 0; if ( !str_cmp( arg, "mine" ) ) MINE = TRUE; send_to_char("\n\r",ch); send_to_char( " ## | Owner | Project | Coder | Status | # of Logs\n\r",ch); send_to_char( "---|-------------|----------------------|---------------|------------|----------\n\r", ch); for( pproject = first_project; pproject; pproject = pproject->next ) { pcount++; if ( MINE &&(!pproject->owner||str_cmp( ch->name,pproject->owner)) && (!pproject->coder || str_cmp( ch->name, pproject->coder)) ) continue; else if (!MINE && pproject->status && !str_cmp("Done", pproject->status ) ) continue; num_logs = 0; for ( log = pproject->first_log; log; log=log->next ) num_logs++; xprintf(buf, "%2d | %-11s | %-20s | %-13s | %-10s | %3d\n\r", pcount, pproject->owner ? pproject->owner : "(None)", pproject->name, pproject->coder ? pproject->coder : "(None)", pproject->status ? pproject->status : "(None)", num_logs); send_to_char(buf, ch); } return; } if( arg[0] == '\0' || !str_cmp( arg, "list" ) ) { bool aflag, projects_available; aflag = FALSE; projects_available = FALSE; if( !str_cmp( argument, "available" ) ) aflag = TRUE; send_to_char("\n\r",ch); if( !aflag ) { send_to_char( " ## | Owner | Project | Date | Status\n\r",ch); send_to_char( "---|-------------|----------------------|--------------------------|-----------\n\r",ch); } else { send_to_char(" ## | Project | Date\n\r",ch); send_to_char( "---|----------------------|--------------------------\n\r",ch); } pcount = 0; for( pproject = first_project; pproject; pproject = pproject->next ) { pcount++; if (pproject->status && !str_cmp("Done", pproject->status ) ) continue; if(!aflag) xprintf(buf, "%2d | %-11s | %-20s | %-24s | %-10s\n\r", pcount, pproject->owner ? pproject->owner : "(None)", pproject->name, pproject->date, pproject->status ? pproject->status : "(None)"); else if( !pproject->taken ) { if( !projects_available ) projects_available = TRUE; xprintf(buf, "%2d | %-20s | %s\n\r", pcount, pproject->name, pproject->date); } send_to_char(buf, ch); } if(pcount == 0) send_to_char("No projects exist.\n\r",ch); else if( aflag && !projects_available ) send_to_char("No projects available.\n\r",ch); return; } if( !str_cmp( arg, "add" ) ) { char *strtime; PROJECT_DATA *new_project; /* Just to be safe */ if( get_trust(ch) < LEVEL_JUDGE) { send_to_char("You are not powerfull enough to add a new project.\n\r",ch); return; } new_project = alloc_mem( sizeof( PROJECT_DATA)); LINK( new_project, first_project, last_project, next, prev ); new_project->name = str_dup(argument); new_project->coder = NULL; new_project->taken = FALSE; new_project->owner = NULL; new_project->status = NULL; new_project->description = str_dup( "" ); new_project->first_log = NULL; new_project->last_log = NULL; strtime = ctime( ¤t_time ); strtime[strlen(strtime)-1] = '\0'; new_project->date = str_dup( strtime ); write_projects(); send_to_char("Ok.\n\r",ch ); return; } if( !is_number( arg ) ) { send_to_char("Invalid project.\n\r",ch); return; } pnum = atoi( arg ); pproject = get_project_by_number( pnum ); if(!pproject) { send_to_char("No such project.\n\r",ch); return; } argument = one_argument( argument, arg1 ); if( !str_cmp( arg1, "desc" ) ) { if ( pproject->description == NULL ) pproject->description = str_dup(""); string_append( ch, &pproject->description ); return; } if( !str_cmp( arg1, "delete" ) ) { NOTE_DATA *log, *tlog; if( get_trust(ch) < LEVEL_HIGHJUDGE) { send_to_char("You are not high enough level to delete a project.\n\r", ch ); return; } tlog = NULL; for( log = pproject->first_log; log; tlog = log, log = log->next ) { if ( tlog == NULL ) pproject->first_log = log->next; else tlog->next = log->next; free_note( log ); } pproject->last_log = NULL; UNLINK( pproject, first_project, last_project, next, prev ); free_string( pproject->name ); if ( pproject->coder ) free_string( pproject->coder ); if( pproject->owner ) free_string( pproject->owner ); if( pproject->description ) free_string( pproject->description ); if ( pproject->date ) free_string( pproject->date ); if ( pproject->status ) free_string( pproject->status ); free_mem( pproject, sizeof( *pproject) ); write_projects(); send_to_char("Ok.\n\r",ch ); return; } if( !str_cmp( arg1, "take" ) ) { if( pproject->taken && pproject->owner && !str_cmp(pproject->owner, ch->name ) ) { pproject->taken = FALSE; free_string( pproject->owner ); pproject->owner = NULL; send_to_char("You removed yourself as the owner.\n\r", ch ); write_projects(); return; } else if ( pproject->taken ) { send_to_char("This project is already taken.\n\r" ,ch); return; } if( pproject->owner ) free_string( pproject->owner ); pproject->owner = str_dup( ch->name ); pproject->taken = TRUE; write_projects(); send_to_char("Ok.\n\r" ,ch); return; } if( !str_cmp( arg1, "coder" ) ) { if ( pproject->coder && !str_cmp(ch->name, pproject->coder)) { free_string( pproject->coder ); pproject->coder = NULL; send_to_char("You removed yourself as the coder.\n\r", ch ); write_projects(); return; } else if ( pproject->coder ) { send_to_char("This project already has a coder.\n\r",ch ); return; } pproject->coder = str_dup( ch->name ); write_projects(); send_to_char("Ok.\n\r" ,ch); return; } if( !str_cmp( arg1, "status" ) ) { if( pproject->owner && str_cmp( pproject->owner, ch->name ) && get_trust(ch) < LEVEL_JUDGE && pproject->coder && str_cmp(pproject->coder, ch->name) ) { send_to_char("This is not your project!\n\r",ch ); return; } if(pproject->status) free_string(pproject->status); pproject->status = str_dup(argument); write_projects(); send_to_char("Done.\n\r", ch ); return; } if( !str_cmp( arg1, "show" ) ) { if ( pproject->description ) send_to_char ( pproject->description, ch ); else send_to_char ("That project does not have a description.\n\r",ch); return; } if( !str_cmp( arg1, "log" ) ) { NOTE_DATA *plog,*tlog; if( !str_cmp( argument, "write" ) ) { string_append( ch, &ch->pnote->text); return; } argument = one_argument( argument, arg2 ); if( !str_cmp( arg2, "subject" ) ) { note_attach(ch); free_string(ch->pnote->subject); ch->pnote->subject = str_dup( argument ); send_to_char("Ok.\n\r",ch); return; } if( !str_cmp( arg2, "post" ) ) { char *strtime; if( pproject->owner && str_cmp(ch->name, pproject->owner) && pproject->coder && str_cmp(ch->name, pproject->coder) && get_trust(ch) < LEVEL_JUDGE ) { send_to_char("This is not your project!\n\r",ch ); return; } if ( !ch->pnote ) { send_to_char("You have no log in progress.\n\r" ,ch); return; } if ( !ch->pnote->subject ) { send_to_char( "Your log has no subject.\n\r",ch ); return; } strtime = ctime( ¤t_time ); strtime[strlen(strtime)-1] = '\0'; ch->pnote->date = str_dup( strtime ); ch->pnote->sender = ch->name; plog = ch->pnote; ch->pnote = NULL; if( !pproject->first_log ) pproject->first_log = plog; else { for( tlog = pproject->first_log; tlog->next; tlog = tlog->next ) ; tlog->next = plog; } plog->next = NULL; pproject->last_log = plog; write_projects(); send_to_char("Ok.\n\r",ch); return; } if( !str_cmp( arg2, "list" ) ) { if( pproject->owner && pproject->coder && str_cmp(ch->name, pproject->owner) && get_trust(ch) < LEVEL_BUILDER && str_cmp(ch->name, pproject->coder) ) { send_to_char("This is not your project!\n\r",ch ); return; } pcount = 0; xprintf(buf, "Project: %-12s: %s\n\r", pproject->owner ? pproject->owner : "(None)", pproject->name); send_to_char(buf,ch); for( plog = pproject->first_log; plog; plog = plog->next ) { pcount++; xprintf( buf, "%2d) %-12s: %s\n\r", pcount, plog->sender, plog->subject ); send_to_char(buf,ch); } if( pcount == 0 ) send_to_char("No logs available.\n\r",ch ); return; } if( !is_number( arg2 )) { send_to_char("Invalid log.\n\r",ch ); return; } pnum = atoi( arg2 ); plog = get_log_by_number( pproject, pnum ); if( !plog ) { send_to_char("Invalid log.\n\r",ch ); return; } if( !str_cmp( argument, "delete" ) ) { if( pproject->owner && str_cmp(ch->name, pproject->owner) && get_trust(ch) < LEVEL_JUDGE && pproject->coder && str_cmp(ch->name, pproject->coder ) ) { send_to_char("This is not your project!\n\r",ch ); return; } for( tlog = pproject->first_log; tlog->next; tlog = tlog->next ) if( tlog->next == plog ) break; tlog->next = plog->next; free_note( plog ); write_projects(); send_to_char("Ok.\n\r",ch ); return; } if( !str_cmp( argument, "read" ) ) { if( pproject->owner && pproject->coder && str_cmp(ch->name, pproject->owner) && get_trust(ch) < LEVEL_BUILDER && str_cmp(ch->name, pproject->coder ) ) { send_to_char("This is not your project!\n\r" ,ch); return; } xprintf( buf, "[%3d] %s: %s\n\r%s\n\r%s", pnum, plog->sender, plog->subject, plog->date, plog->text ); send_to_char(buf,ch); return; } } send_to_char("Unknown syntax see help 'PROJECT'.\n\r", ch ); return; }
void parse_sign( CHAR_DATA *ch, char *argument, int type ) { BUFFER *buffer; char buf[MAX_STRING_LENGTH]; char arg[MAX_INPUT_LENGTH]; OBJ_INDEX_DATA *pObjIndex; OBJ_DATA *obj; if ( IS_NPC(ch) ) return; argument = one_argument( argument, arg ); smash_tilde( argument ); if ( arg[0] == '\0' ) { return; } if ( !str_cmp( arg, "+" ) ) { sign_attach( ch,type ); if (ch->pnote->type != type) { send_to_char( "You already have a different note in progress.\n\r",ch); return; } if (strlen(ch->pnote->text)+strlen(argument) >= 4096) { send_to_char( "Sign too long.\n\r", ch ); return; } buffer = new_buf(); add_buf(buffer,ch->pnote->text); add_buf(buffer,argument); add_buf(buffer,"\n\r"); free_string( ch->pnote->text ); ch->pnote->text = str_dup( buf_string(buffer) ); free_buf(buffer); send_to_char( "Ok.\n\r", ch ); return; } if (!str_cmp(arg,"-")) { int len; bool found = FALSE; sign_attach(ch,type); if (ch->pnote->type != type) { send_to_char( "You already have a different note in progress.\n\r",ch); return; } if (ch->pnote->text == NULL || ch->pnote->text[0] == '\0') { send_to_char("No lines left to remove.\n\r",ch); return; } strcpy(buf,ch->pnote->text); for (len = strlen(buf); len > 0; len--) { if (buf[len] == '\r') { if (!found) /* back it up */ { if (len > 0) len--; found = TRUE; } else /* found the second one */ { buf[len + 1] = '\0'; free_string(ch->pnote->text); ch->pnote->text = str_dup(buf); return; } } } buf[0] = '\0'; free_string(ch->pnote->text); ch->pnote->text = str_dup(buf); return; } if ( !str_prefix( arg, "make" ) ) { sign_attach( ch,type ); if (ch->pnote->type != type) { send_to_char( "You already have a different note in progress.\n\r",ch); return; } free_string( ch->pnote->to_list ); free_string( ch->pnote->subject ); send_to_char( "Ok.\n\r", ch ); return; } if ( !str_prefix( arg, "clear" ) ) { if ( ch->pnote != NULL ) { free_note(ch->pnote); ch->pnote = NULL; } send_to_char( "Ok.\n\r", ch ); return; } if ( !str_prefix( arg, "show" ) ) { if ( ch->pnote == NULL ) { send_to_char( "You have no sign in progress.\n\r", ch ); return; } if (ch->pnote->type != type) { send_to_char("You aren't working on that kind of note.\n\r",ch); return; } send_to_char( ch->pnote->text, ch ); return; } if ( !str_prefix( arg, "post" ) || !str_prefix(arg, "send") || !str_prefix(arg, "save")) { EXTRA_DESCR_DATA *ed; if ( ch->pnote == NULL ) { send_to_char( "You have no sign in progress.\n\r", ch ); return; } if (ch->pnote->type != type) { send_to_char("You aren't working on that kind of note.\n\r",ch); return; } pObjIndex = get_obj_index(OBJ_VNUM_QUEST_SIGN); obj = create_object( pObjIndex, ch->level ); obj_to_room( obj, ch->in_room ); ed = new_extra_descr(); ed->keyword = str_dup( "sign" ); buffer = new_buf(); add_buf(buffer,ch->pnote->text); ed->description = str_dup(buf_string(buffer)); ed->next = NULL; obj->extra_descr = ed; ch->pnote = NULL; send_to_char( "A sign now floats before you.\n\r", ch ); return; } send_to_char( "You can't do that.\n\r", ch ); return; }