/* Dismiss a member from the clan/Resign from the clan */ void do_dismiss( struct char_data *ch, struct clan_type *cptr, struct char_data *vict ) { if (vict != ch){ if (vict != NULL && GET_CLAN(vict) == GET_CLAN(ch)) { if (GET_CLAN_RANK(vict) >= GET_CLAN_RANK(ch)) { send_to_char("You may not dismiss those of equal or greater clan status than yourself!\r\n", ch); return; } /* send some sort of mail to player notifying him/her of dismissal */ sprintf(buf, "%s,\r\n\r\n" " You have been dismissed from the clan of %s.\r\n" "If you are unsure of the reason why, please feel\r\n" "free to contact the leader, %s.\r\n", GET_NAME(vict), cptr->name, cptr->leadersname); store_mail(GET_IDNUM(vict), GET_IDNUM(ch), -1, buf); remove_member(cptr, vict); } } else if (GET_CLAN_RANK(vict) == CLAN_LEADER) { GET_CLAN_RANK(vict) = CLAN_MEMBER; send_to_char("You have resigned as leader.\r\n", ch); cptr->leadersname = strdup("NoOne"); save_clans(); return; } GET_CLAN(vict) = CLAN_NONE; GET_CLAN_RANK(vict) = CLAN_NONE; GET_HOME(vict) = 1; remove_member(cptr, vict); save_char(vict, NOWHERE); save_clans(); return; }
/* Accept an applicant into the clan */ void do_caccept( struct char_data *ch, struct clan_type *cptr, struct char_data *vict ) { int i=0; if (vict != NULL && (GET_CLAN(vict) < CLAN_MEMBER)) { GET_CLAN(vict) = GET_CLAN(ch); GET_CLAN_RANK(vict) = CLAN_MEMBER; /* send some sort of mail to player notifying him/her of acceptance */ sprintf(buf, "%s,\r\n\r\n" " Congratulations! You have been accepted into the ranks of\r\n" "%s. The leader of our clan is %s. Good luck.\r\n", GET_NAME(vict), cptr->name, cptr->leadersname); store_mail(GET_IDNUM(vict), GET_IDNUM(ch), -1, buf); /* now that the mail has been sent, let's continue. */ GET_HOME(vict) = GET_HOME(ch); save_char(vict, NOWHERE); /* now remove the player from the petition list */ remove_applicant(cptr, vict); for (i = 0; i < 100; i++) { if (cptr->members[i] == NULL) { cptr->members[i] = strdup(GET_NAME(vict)); break; } if (strcmp(cptr->members[i], GET_NAME(vict)) == 0) break; } save_clans(); } return; }
/* Reject an applicant from a clan/Withdraw an application */ void do_creject( struct char_data *ch, struct clan_type *cptr, struct char_data *vict) { int i=0; long leader; if (vict != ch) { if (vict != NULL) { /* send some sort of mail to player notifying him/her of rejection */ sprintf(buf, "%s,\r\n\r\n" " You have been rejected from the clan of %s.\r\n" "If you are unsure of the reason why, please feel\r\n" "free to contact the leader, %s.\r\n", GET_NAME(vict), cptr->name, cptr->leadersname); store_mail(GET_IDNUM(vict), GET_IDNUM(ch), -1, buf); /* mail's been sent, let's move on */ } } else { for (i=0; i<20; i++) { if (!str_cmp(cptr->applicants[i], GET_NAME(ch))) { send_to_char("You aren't applying to the clan...\r\n", ch); break; } } /* send some sort of mail to leader notifying him/her of withdrawal */ leader = get_id_by_name(cptr->leadersname); sprintf(buf, "%s,\r\n\r\n" " I have withdrawn my application from the clan.\r\n" "\r\n%s\r\n", cptr->leadersname, GET_NAME(ch)); store_mail(leader, GET_IDNUM(ch), -1, buf); /* now that the mail has been sent, let's continue. */ } GET_CLAN(vict) = CLAN_NONE; GET_CLAN_RANK(vict) = 0; save_char(vict, NOWHERE); /* now remove the player from the petition list */ remove_applicant(cptr, vict); save_clans(); return; }
/* Apply to a clan for membership */ void do_apply( struct char_data *ch, struct clan_type *cptr ) { int i; long leader; if (IS_NPC(ch)) return; if (!strcmp(cptr->leadersname, "NoOne") ) { send_to_char("The clan is currently without a leader.\r\n", ch); return; } for (i = 0; i < 20; i++) { if (cptr->applicants[i] == NULL) break; if (!strcmp(cptr->applicants[i], GET_NAME(ch))) { send_to_char("You have already applied to this clan.\r\n", ch); return; } } if ((cptr->applicants[i] == NULL) && (i < 20)) { cptr->applicants[i] = str_dup(GET_NAME(ch)); save_clans(); /* send some sort of mail to leader notifying him/her of application */ leader = get_id_by_name(cptr->leadersname); sprintf(buf, "%s,\r\n\r\n" " Hi there! I'd like to apply to your clan. I have some abilities\r\n" "that I feel will be useful to you. Please feel free to contact me \r\n" "for any information that you might need about me.\r\n" "Hope to hear from you soon!\r\n" "\r\n%s\r\n", cptr->leadersname, GET_NAME(ch)); store_mail(leader, GET_IDNUM(ch), -1, buf); /* now that the mail has been sent, let's continue. */ sprintf(buf, "Your application for admittance to %s has been noted.\r\n" "You will receive notification when you have been accepted.\r\n", cptr->name); send_to_char(buf, ch); } else send_to_char("This clan is already being applied to by 20 other players, try again later.\r\n", ch); save_clans(); return; }
void store_mail(long to, long from, char *message_pointer) { header_block_type header; data_block_type data; long last_address, target_address; char *msg_txt = message_pointer; int bytes_written = 0; int total_length = strlen(message_pointer); int i; if (to == -1) { // "all" - unchanged from mailall.lord.txt for (i = 0; i <= top_of_p_table; i++) store_mail(player_table[i].id, from, message_pointer); return; } assert(sizeof(header_block_type) == sizeof(data_block_type)); assert(sizeof(header_block_type) == BLOCK_SIZE); if (from < 0 || to < 0 || !*message_pointer) { log("SYSERR: Mail system -- non-fatal error #5."); return; } memset((char *) &header, 0, sizeof(header)); /* clear the record */ header.block_type = HEADER_BLOCK; header.header_data.next_block = LAST_BLOCK; header.header_data.from = from; header.header_data.to = to; header.header_data.mail_time = time(0); strncpy(header.txt, msg_txt, HEADER_BLOCK_DATASIZE); header.txt[HEADER_BLOCK_DATASIZE] = '\0'; target_address = pop_free_list(); /* find next free block */ index_mail(to, target_address); /* add it to mail index in memory */ write_to_file(&header, BLOCK_SIZE, target_address); if (strlen(msg_txt) <= HEADER_BLOCK_DATASIZE) return; /* that was the whole message */ bytes_written = HEADER_BLOCK_DATASIZE; msg_txt += HEADER_BLOCK_DATASIZE; /* move pointer to next bit of text */ /* * find the next block address, then rewrite the header to reflect where * the next block is. */ last_address = target_address; target_address = pop_free_list(); header.header_data.next_block = target_address; write_to_file(&header, BLOCK_SIZE, last_address); /* now write the current data block */ memset((char *) &data, 0, sizeof(data)); /* clear the record */ data.block_type = LAST_BLOCK; strncpy(data.txt, msg_txt, DATA_BLOCK_DATASIZE); data.txt[DATA_BLOCK_DATASIZE] = '\0'; write_to_file(&data, BLOCK_SIZE, target_address); bytes_written += strlen(data.txt); msg_txt += strlen(data.txt); /* * if, after 1 header block and 1 data block there is STILL part of the * message left to write to the file, keep writing the new data blocks and * rewriting the old data blocks to reflect where the next block is. Yes, * this is kind of a hack, but if the block size is big enough it won't * matter anyway. Hopefully, MUD players won't pour their life stories out * into the Mud Mail System anyway. * * Note that the block_type data field in data blocks is either a number >=0, * meaning a link to the next block, or LAST_BLOCK flag (-2) meaning the * last block in the current message. This works much like DOS' FAT. */ while (bytes_written < total_length) { last_address = target_address; target_address = pop_free_list(); /* rewrite the previous block to link it to the next */ data.block_type = target_address; write_to_file(&data, BLOCK_SIZE, last_address); /* now write the next block, assuming it's the last. */ data.block_type = LAST_BLOCK; strncpy(data.txt, msg_txt, DATA_BLOCK_DATASIZE); data.txt[DATA_BLOCK_DATASIZE] = '\0'; write_to_file(&data, BLOCK_SIZE, target_address); bytes_written += strlen(data.txt); msg_txt += strlen(data.txt); } } /* store mail */
/** * Loads the emails contained in a path and stores its tokens in a berkeley database. */ void load_directory_mail(char *directory, char *db_path, int type){ filelist *mails_directory=list_files(directory,"eml"); int i=0; DB *dbp=NULL; DB_ENV *bayes_env; map_t tokenbody; char *email; int count=0; //bayes_env=malloc(sizeof(DB_ENV *)); /* If the path is incorrect. */ if(mails_directory==NULL){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Directory not found"); exit(EXIT_FAILURE); } /* If the directory not contains any e-mail.*/ if (count_files_filelist(mails_directory)==0){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Directory empty\n"); exit(EXIT_FAILURE); } /*If the environment can't be created.*/ if(create_env(&bayes_env,BAYES_SPAM_LEARN_ENV_PATH)!=DB_OK){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Could not create environment\n"); exit(EXIT_FAILURE); } /* If the database can't be open.*/ if(create_db_conexion(&dbp, bayes_env, db_path, DB_CREATE)!=DB_OK){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Could not open database\n"); exit(EXIT_FAILURE); } /*If the e-mail is a spam message, its tokens will be stored in the database as spam tokens.*/ if(type==OPT_SPAM) for(;i<count_files_filelist(mails_directory);i++){ wblprintf(LOG_INFO,"LEARN_BAYES","Spam file name: %s\n",get_file_at(mails_directory,i)); email=loademail(get_file_at(mails_directory,i)); if((tokenbody=tokenizebody(email))!=NULL){ count++; store_mail(dbp,tokenbody,OPT_SPAM); free_tokenize(tokenbody); } else{} free(email); }/*If the e-mail is a ham message, its tokens will be stored in the database as ham tokens.*/ else for(;i<count_files_filelist(mails_directory);i++){ wblprintf(LOG_INFO,"LEARN_BAYES","Ham file name: %s\n",get_file_at(mails_directory,i)); email=loademail(get_file_at(mails_directory,i)); if((tokenbody=tokenizebody(email))!=NULL){ count++; store_mail(dbp,tokenbody,OPT_HAM); free_tokenize(tokenbody); } free(email); } free_filelist(mails_directory); close_db_conexion(&dbp, db_path); bayes_env->close(bayes_env,0); //free(bayes_env); freeEMLParser(); printf("Summary %d messages\n",i); printf(" %d messages inserted\n",count); printf(" %d messages wrong\n",i-count); }