int Board_display_msg(int board_type, struct char_data *ch, char *arg, struct obj_data *board) { char number[MAX_INPUT_LENGTH], buffer[MAX_STRING_LENGTH]; int msg, ind; one_argument(arg, number); if (!*number) return (0); if (isname(number, board->name)) /* so "read board" works */ return (Board_show_board(board_type, ch, arg, board)); if (!is_number(number)) /* read 2.mail, look 2.sword */ return (0); if (!(msg = atoi(number))) return (0); if (GET_LEVEL(ch) < READ_LVL(board_type)) { send_to_char(ch, "You try but fail to understand the holy words.\r\n"); return (1); } if (!num_of_msgs[board_type]) { send_to_char(ch, "The board is empty!\r\n"); return (1); } if (msg < 1 || msg > num_of_msgs[board_type]) { send_to_char(ch, "That message exists only in your imagination.\r\n"); return (1); } #if NEWEST_AT_TOP ind = num_of_msgs[board_type] - msg; #else ind = msg - 1; #endif if (MSG_SLOTNUM(board_type, ind) < 0 || MSG_SLOTNUM(board_type, ind) >= INDEX_SIZE) { send_to_char(ch, "Sorry, the board is not working.\r\n"); log("SYSERR: Board is screwed up. (Room #%d)", GET_ROOM_VNUM(IN_ROOM(ch))); return (1); } if (!(MSG_HEADING(board_type, ind))) { send_to_char(ch, "That message appears to be screwed up.\r\n"); return (1); } if (!(msg_storage[MSG_SLOTNUM(board_type, ind)])) { send_to_char(ch, "That message seems to be empty.\r\n"); return (1); } snprintf(buffer, sizeof(buffer), "Message %d : %s\r\n\r\n%s\r\n", msg, MSG_HEADING(board_type, ind), msg_storage[MSG_SLOTNUM(board_type, ind)]); page_string(ch->desc, buffer, TRUE); return (1); }
void Board_load_board(int board_type) { FILE *fl; int i, len1 = 0, len2 = 0; char *tmp1 = 0, *tmp2 = 0; if (!(fl = fopen(FILENAME(board_type), "rb"))) { perror("Error reading board"); return; } fread(&(num_of_msgs[board_type]), sizeof(int), 1, fl); if (num_of_msgs[board_type] < 1 || num_of_msgs[board_type] > MAX_BOARD_MESSAGES) { log("Board file corrupt. Resetting."); Board_reset_board(board_type); return; } for (i = 0; i < num_of_msgs[board_type]; i++) { fread(&(msg_index[board_type][i]),sizeof(struct board_msginfo),1,fl); if (!(len1 = msg_index[board_type][i].heading_len)) { log("Board file corrupt! Resetting."); Board_reset_board(board_type); return; } if (!(tmp1 = (char *)malloc(sizeof(char) * len1))) { log("Error - malloc failed for board header"); exit(1); } fread(tmp1, sizeof(char), len1, fl); MSG_HEADING(board_type, i) = tmp1; if ((len2 = msg_index[board_type][i].message_len)) { if ((MSG_SLOTNUM(board_type, i) = find_slot()) == -1) { log("Out of slots booting board! Resetting.."); Board_reset_board(board_type); return; } if (!(tmp2 = (char *)malloc(sizeof(char) * len2))) { log("Error - malloc failed for board text"); exit(1); } fread(tmp2, sizeof(char), len2, fl); msg_storage[MSG_SLOTNUM(board_type, i)] = tmp2; } } fclose(fl); }
int Board_display_msg(int board_type, struct char_data *ch, char *arg) { char buf[512], number[MAX_STRING_LENGTH], buffer[MAX_STRING_LENGTH]; int msg, ind; one_argument(arg, number); if (!*number || !isdigit(*number)) return 0; if (!(msg = atoi(number))) return 0; if (GET_LEVEL(ch) < READ_LVL(board_type)) { send_to_char("You try but fail to understand the holy words.\n\r", ch); return 1; } if (!num_of_msgs[board_type]) { send_to_char("The board is empty!\n\r", ch); return(1); } if (msg < 1 || msg > num_of_msgs[board_type]) { send_to_char("That message exists only in your imagination..\n\r", ch); return(1); } ind = msg - 1; if (MSG_SLOTNUM(board_type, ind) < 0 || MSG_SLOTNUM(board_type, ind) >= INDEX_SIZE) { send_to_char("Sorry, the board is not working.\n\r", ch); log("Board is screwed up."); return 1; } if (!(MSG_HEADING(board_type, ind))) { send_to_char("That message appears to be screwed up.\n\r", ch); return 1; } if(!(msg_storage[MSG_SLOTNUM(board_type, ind)])) { send_to_char("That message seems to be empty.\n\r", ch); return 1; } sprintf(buffer, "Message %d : %s\n\r\n\r%s\n\r", msg, MSG_HEADING(board_type, ind), msg_storage[MSG_SLOTNUM(board_type, ind)]); page_string(ch->desc, buffer, 1); return 1; }
/* Clear the in-memory structures. */ void Board_clear_board(int board_type) { int i; for (i = 0; i < MAX_BOARD_MESSAGES; i++) { if (MSG_HEADING(board_type, i)) free(MSG_HEADING(board_type, i)); if (msg_storage[MSG_SLOTNUM(board_type, i)]) free(msg_storage[MSG_SLOTNUM(board_type, i)]); msg_storage_taken[MSG_SLOTNUM(board_type, i)] = 0; memset((char *)&(msg_index[board_type][i]),0,sizeof(struct board_msginfo)); msg_index[board_type][i].slot_num = -1; } num_of_msgs[board_type] = 0; }
int Board_display_msg(int board_type, struct char_data * ch, char *arg) { char number[MAX_STRING_LENGTH], buffer[MAX_STRING_LENGTH]; int msg, ind; one_argument(arg, number); if (!*number) return 0; if (isname(number, "board bulletin")) /* so "read board" works */ return (Board_show_board(board_type, ch, arg)); if (!isdigit(*number) || (!(msg = atoi(number)))) return 0; if (READ_LVL(board_type) != 0 && !COM_FLAGGED(ch, READ_LVL(board_type))) { send_to_char("You try but fail to understand the holy words.\r\n", ch); return 1; } if (!num_of_msgs[board_type]) { send_to_char("The board is empty!\r\n", ch); return (1); } if (msg < 1 || msg > num_of_msgs[board_type]) { send_to_char("That message exists only in your imagination.\r\n", ch); return (1); } ind = msg - 1; if (MSG_SLOTNUM(board_type, ind) < 0 || MSG_SLOTNUM(board_type, ind) >= INDEX_SIZE) { send_to_char("Sorry, the board is not working.\r\n", ch); stderr_log("SYSERR: Board is screwed up."); return 1; } if (!(MSG_HEADING(board_type, ind))) { send_to_char("That message appears to be screwed up.\r\n", ch); return 1; } if (!(msg_storage[MSG_SLOTNUM(board_type, ind)])) { send_to_char("That message seems to be empty.\r\n", ch); return 1; } sprintf(buffer, "Message %d : %s\r\n\r\n%s\r\n", msg, MSG_HEADING(board_type, ind), msg_storage[MSG_SLOTNUM(board_type, ind)]); page_string(ch->desc, buffer, 1); return 1; }
void Board_reset_board(int board_type) { int i; char buf[100]; for(i = 0; i < MAX_BOARD_MESSAGES; i++) { if (MSG_HEADING(board_type, i)) free (MSG_HEADING(board_type, i)); if (msg_storage[MSG_SLOTNUM(board_type, i)]) free (msg_storage[MSG_SLOTNUM(board_type, i)]); msg_storage_taken[MSG_SLOTNUM(board_type, i)] = 0; memset(&(msg_index[board_type][i]), '\0', sizeof(struct board_msginfo)); msg_index[board_type][i].slot_num = -1; } num_of_msgs[board_type] = 0; sprintf(buf, "rm -f %s", FILENAME(board_type)); system(buf); }
void board_load_board(int board_type) { FILE *fl; int i, j, len1, len2; char *tmp1, *tmp2; if (!(fl = fopen(FILENAME(board_type), "rb"))) { if (errno != ENOENT) perror("SYSERR: Error reading board"); return; } if (fread(&(num_of_msgs[board_type]), sizeof(int), 1, fl) != 1) return; if (num_of_msgs[board_type] < 1 || num_of_msgs[board_type] > MAX_BOARD_MESSAGES) { log("SYSERR: Board file %d corrupt. Resetting.", board_type); board_reset_board(board_type); return; } for (i = 0; i < num_of_msgs[board_type]; i++) { j = fread(&(msg_index[board_type][i]), sizeof(struct board_msginfo), 1, fl); if ((len1 = msg_index[board_type][i].heading_len) <= 0) { log("SYSERR: Board file %d corrupt! Resetting.", board_type); board_reset_board(board_type); return; } CREATE(tmp1, char, len1); j = fread(tmp1, sizeof(char), len1, fl); MSG_HEADING(board_type, i) = tmp1; if ((MSG_SLOTNUM(board_type, i) = find_slot()) == -1) { log("SYSERR: Out of slots booting board %d! Resetting...", board_type); board_reset_board(board_type); return; } if ((len2 = msg_index[board_type][i].message_len) > 0) { CREATE(tmp2, char, len2); j = fread(tmp2, sizeof(char), len2, fl); msg_storage[MSG_SLOTNUM(board_type, i)] = tmp2; } else msg_storage[MSG_SLOTNUM(board_type, i)] = NULL; } fclose(fl); }
void Board_save_board(int board_type) { FILE *fl; int i; char *tmp1 = 0, *tmp2 = 0, buf[100]; if (!num_of_msgs[board_type]) { sprintf(buf, "rm -f %s", FILENAME(board_type)); system(buf); return; } if (!(fl = fopen(FILENAME(board_type), "wb"))) { perror("Error writing board"); return; } fwrite(&(num_of_msgs[board_type]), sizeof(int), 1, fl); for (i = 0; i < num_of_msgs[board_type]; i++) { if (tmp1 = MSG_HEADING(board_type, i)) msg_index[board_type][i].heading_len = strlen(tmp1) + 1; else msg_index[board_type][i].heading_len = 0; if (MSG_SLOTNUM(board_type, i) < 0 || MSG_SLOTNUM(board_type, i) >= INDEX_SIZE || (!(tmp2 = msg_storage[MSG_SLOTNUM(board_type, i)]))) msg_index[board_type][i].message_len = 0; else msg_index[board_type][i].message_len = strlen(tmp2) + 1; fwrite(&(msg_index[board_type][i]),sizeof(struct board_msginfo),1,fl); if (tmp1) fwrite(tmp1, sizeof(char), msg_index[board_type][i].heading_len, fl); if (tmp2) fwrite(tmp2, sizeof(char), msg_index[board_type][i].message_len, fl); } fclose(fl); }
void board_save_board(int board_type) { FILE *fl; int i, j; char *tmp1, *tmp2 = NULL; if (!num_of_msgs[board_type]) { remove(FILENAME(board_type)); return; } if (!(fl = fopen(FILENAME(board_type), "wb"))) { perror("SYSERR: Error writing board"); return; } j = fwrite(&(num_of_msgs[board_type]), sizeof(int), 1, fl); for (i = 0; i < num_of_msgs[board_type]; i++) { if ((tmp1 = MSG_HEADING(board_type, i)) != NULL) msg_index[board_type][i].heading_len = strlen(tmp1) + 1; else msg_index[board_type][i].heading_len = 0; if (MSG_SLOTNUM(board_type, i) < 0 || MSG_SLOTNUM(board_type, i) >= INDEX_SIZE || (!(tmp2 = msg_storage[MSG_SLOTNUM(board_type, i)]))) msg_index[board_type][i].message_len = 0; else msg_index[board_type][i].message_len = strlen(tmp2) + 1; j = fwrite(&(msg_index[board_type][i]), sizeof(struct board_msginfo), 1, fl); if (tmp1) j = fwrite(tmp1, sizeof(char), msg_index[board_type][i].heading_len, fl); if (tmp2) j = fwrite(tmp2, sizeof(char), msg_index[board_type][i].message_len, fl); } fclose(fl); }
int Board_remove_msg(int board_type, struct char_data *ch, char *arg, struct obj_data *board) { (void)board; int ind, msg, slot_num; char number[MAX_INPUT_LENGTH], buf[MAX_INPUT_LENGTH]; struct descriptor_data *d; one_argument(arg, number); if (!*number || !is_number(number)) return (0); if (!(msg = atoi(number))) return (0); if (!num_of_msgs[board_type]) { send_to_char(ch, "The board is empty!\r\n"); return (1); } if (msg < 1 || msg > num_of_msgs[board_type]) { send_to_char(ch, "That message exists only in your imagination.\r\n"); return (1); } #if NEWEST_AT_TOP ind = num_of_msgs[board_type] - msg; #else ind = msg - 1; #endif if (!MSG_HEADING(board_type, ind)) { send_to_char(ch, "That message appears to be screwed up.\r\n"); return (1); } snprintf(buf, sizeof(buf), "(%s)", GET_NAME(ch)); if (GET_LEVEL(ch) < REMOVE_LVL(board_type) && !(strstr(MSG_HEADING(board_type, ind), buf))) { send_to_char(ch, "You are not holy enough to remove other people's messages.\r\n"); return (1); } if (GET_LEVEL(ch) < MSG_LEVEL(board_type, ind)) { send_to_char(ch, "You can't remove a message holier than yourself.\r\n"); return (1); } slot_num = MSG_SLOTNUM(board_type, ind); if (slot_num < 0 || slot_num >= INDEX_SIZE) { send_to_char(ch, "That message is majorly screwed up.\r\n"); log("SYSERR: The board is seriously screwed up. (Room #%d)", GET_ROOM_VNUM(IN_ROOM(ch))); return (1); } for (d = descriptor_list; d; d = d->next) if (STATE(d) == CON_PLAYING && d->str == &(msg_storage[slot_num])) { send_to_char(ch, "At least wait until the author is finished before removing it!\r\n"); return (1); } if (msg_storage[slot_num]) free(msg_storage[slot_num]); msg_storage[slot_num] = 0; msg_storage_taken[slot_num] = 0; if (MSG_HEADING(board_type, ind)) free(MSG_HEADING(board_type, ind)); for (; ind < num_of_msgs[board_type] - 1; ind++) { MSG_HEADING(board_type, ind) = MSG_HEADING(board_type, ind + 1); MSG_SLOTNUM(board_type, ind) = MSG_SLOTNUM(board_type, ind + 1); MSG_LEVEL(board_type, ind) = MSG_LEVEL(board_type, ind + 1); } MSG_HEADING(board_type, num_of_msgs[board_type] - 1) = NULL; MSG_SLOTNUM(board_type, num_of_msgs[board_type] - 1) = 0; MSG_LEVEL(board_type, num_of_msgs[board_type] - 1) = 0; num_of_msgs[board_type]--; send_to_char(ch, "Message removed.\r\n"); snprintf(buf, sizeof(buf), "$n just removed message %d.", msg); act(buf, FALSE, ch, 0, 0, CommTarget::TO_ROOM); Board_save_board(board_type); return (1); }
int Board_remove_msg(int board_type, struct char_data * ch, char *arg) { int ind, msg, slot_num; char number[MAX_INPUT_LENGTH], buf[MAX_INPUT_LENGTH]; struct descriptor_data *d; one_argument(arg, number); if (!*number || !isdigit(*number)) return 0; if (!(msg = atoi(number))) return (0); if (!num_of_msgs[board_type]) { send_to_char("The board is empty!\r\n", ch); return 1; } if (msg < 1 || msg > num_of_msgs[board_type]) { send_to_char("That message exists only in your imagination.\r\n", ch); return 1; } ind = msg - 1; if (!MSG_HEADING(board_type, ind)) { send_to_char("That message appears to be screwed up.\r\n", ch); return 1; } sprintf(buf, "(%s)", GET_NAME(ch)); if (REMOVE_LVL(board_type) != 0 && !COM_FLAGGED(ch, REMOVE_LVL(board_type)) && !(strstr(MSG_HEADING(board_type, ind), buf))) { send_to_char("You are not holy enough to remove other people's messages.\r\n", ch); return 1; } if (GET_LEVEL(ch) < MSG_LEVEL(board_type, ind)) { send_to_char("You can't remove a message holier than yourself.\r\n", ch); return 1; } slot_num = MSG_SLOTNUM(board_type, ind); if (slot_num < 0 || slot_num >= INDEX_SIZE) { stderr_log("SYSERR: The board is seriously screwed up."); send_to_char("That message is majorly screwed up.\r\n", ch); return 1; } for (d = descriptor_list; d; d = d->next) if (!d->connected && d->str == &(msg_storage[slot_num])) { send_to_char("At least wait until the author is finished before removing it!\r\n", ch); return 1; } sprintf(logbuffer, "%s removed message #%d (%s) from board #%d", GET_NAME(ch), msg, MSG_HEADING(board_type, ind), world[ch->in_room].number); mudlog(logbuffer, 'B', COM_ADMIN, FALSE); if (msg_storage[slot_num]) FREE(msg_storage[slot_num]); msg_storage[slot_num] = 0; msg_storage_taken[slot_num] = 0; if (MSG_HEADING(board_type, ind)) FREE(MSG_HEADING(board_type, ind)); for (; ind < num_of_msgs[board_type] - 1; ind++) { MSG_HEADING(board_type, ind) = MSG_HEADING(board_type, ind + 1); MSG_SLOTNUM(board_type, ind) = MSG_SLOTNUM(board_type, ind + 1); MSG_LEVEL(board_type, ind) = MSG_LEVEL(board_type, ind + 1); } num_of_msgs[board_type]--; send_to_char("Message removed.\r\n", ch); sprintf(buf, "$n just removed message %d.", msg); act(buf, FALSE, ch, 0, 0, TO_ROOM); Board_save_board(board_type); return 1; }