tbamud/src/boards.c
Rumble ebc985f010 jeremyosborne | 2008-04-04 02:36:38 +0200 (Fri, 04 Apr 2008) | 1 line
Minor Bugfix: All game configuration settings now reference the world config 
structure, not the individual config variables found in config.c.
------------------------------------------------------------------------
 rumble | 2008-03-22 13:27:00 +0100 (Sat, 22 Mar 2008) | 1 line

Added lib/world/qst/ directory, index, index.mini, and 0.qst.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-08 03:27:51 +0100 (Sat, 08 Mar 2008) | 3 lines

Bugfix: the include directory (for .h files) is now referenced correctly in the
depend statement.
Deletion: listrent.c removed as a separate utility.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-08 03:08:51 +0100 (Sat, 08 Mar 2008) | 1 line

Enhancement: utils/ Makefile will now use a depends file, and looks for dependen
cies in the ../ directory (shrinks the necessary information to make each utilit
y).
------------------------------------------------------------------------
 Rumble | 2008-03-06 23:39:35 +0100 (Thu, 06 Mar 2008) | 1 line

Made TBA specific changes. do_cheat, removed help level checking, and advance to
level 32.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-06 18:37:12 +0100 (Thu, 06 Mar 2008) | 1 line

Minor Update: Changed header of Makefile.in to read 'tbaMUD' and also added in a
ttribution for the changes. (Thanks seqwith.)
------------------------------------------------------------------------
 jeremyosborne | 2008-03-06 18:31:07 +0100 (Thu, 06 Mar 2008) | 4 lines

Changed Makefile.in to use glob expressions when building the objects. This 
translates into no longer a need to update Makefile.in whenever a new .c file 
is added to the mud code. Other Makefile.* have not yet been changed (and 
need review, anyway).

All CXREF cruft left in Makefile.in has been removed. tbaMUD is now using 
Doxygen. Technically, CXREF provides a bit more auto-documentation than Doxygen
does, however the tbaMUD (and legacy circle code) has never been marked-up with 
the special CXREF codes required to effectively use the program. Since Doxygen 
is easier to use, and provides almost as much functionality as CXREF, CXREF 
support has been dropped.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-06 08:31:02 +0100 (Thu, 06 Mar 2008) | 1 line

Bug Fix: asciiflag_conv* functions now can handle a negative numeric value.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-06 08:16:06 +0100 (Thu, 06 Mar 2008) | 1 line

Bug fix/enhancement: Charmed mobs (specifically charmed mobs with a ->master) 
will no longer attempt to wander off.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-06 08:13:38 +0100 (Thu, 06 Mar 2008) | 6 lines

Based on the compiler warning about mag_materials being an unused function, and
the clone spell being unused.

Bug fix: Clone can now be cast. It is an 'ignore' target spell.

Fix and Modification: Clone, being an effectively unused spell that is only used
by mortal Magic Users at level 30, is now implemented as very simple example of
how to use mag_materials(). The item required by mag_materials is vnum 161, 
which in stock tbaMUD is some sacrificial entrails.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-05 01:43:09 +0100 (Wed, 05 Mar 2008) | 3 lines

Bug Fix for "Did you mean:" including DG commands.
------------------------------------------------------------------------
 jeremyosborne | 2008-03-05 01:29:18 +0100 (Wed, 05 Mar 2008) | 3 lines

Bug Fix: do_simple_move slightly rewritten to handle Leave triggers that purge a
 door.

Documentation: do_simple_move documented.
------------------------------------------------------------------------
 Laoris | 2008-03-01 08:22:12 +0100 (Sat, 01 Mar 2008) | 1 line

Trial run of columnizer function on commands list to see how people like it.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-26 22:36:17 +0100 (Tue, 26 Feb 2008) | 1 line

asciimap, an in game automap, along with a couple of minor bug fixes to do with
the automap, patched in (Thanks Jamdog).
------------------------------------------------------------------------
 jeremyosborne | 2008-02-22 04:08:05 +0100 (Fri, 22 Feb 2008) | 1 line

Minor update: Relocate local variable declaration to the top of ACMD(do_help)
------------------------------------------------------------------------
 jeremyosborne | 2008-02-22 04:04:37 +0100 (Fri, 22 Feb 2008) | 6 lines

Checked in the following placeholders for do_gen_tog:
#define SCMD_AUTOLOOT   24
#define SCMD_AUTOGOLD   25
#define SCMD_AUTOSPLIT  26
#define SCMD_AUTOSAC    27
#define SCMD_AUTOASSIST 28
------------------------------------------------------------------------
 jeremyosborne | 2008-02-22 03:57:06 +0100 (Fri, 22 Feb 2008) | 1 line

The Autoquest patch, along with a couple of minor bug fixes, has been integrated
into tbaMUD. (Thanks Jamdog, Kenneth Ray and Morgaelin.)
------------------------------------------------------------------------
 jeremyosborne | 2008-02-18 21:46:45 +0100 (Mon, 18 Feb 2008) | 2 lines

Minor Fix:
Casted NOWHERE, NOTHING, NOBODY and NOFLAG as IDXTYPE for the signed short int 
index types.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-18 03:36:16 +0100 (Mon, 18 Feb 2008) | 7 lines

Added a new atoidx() conversion function for dealing with string to IDXTYPE 
conversions (in utils.c, prototype exported through utils.h).
Added IDXTYPE_MIN and IDXTYPE_MAX defines (in structs.h).
Replaced atoi references with atoidx in do_oasis_zedit (in zedit.c).
------------------------------------------------------------------------
 Rumble | 2008-02-18 01:44:13 +0100 (Mon, 18 Feb 2008) | 1 line

Fixed direction mapping to give readable directions instead of sub commands. 
------------------------------------------------------------------------
 jeremyosborne | 2008-02-18 00:26:15 +0100 (Mon, 18 Feb 2008) | 5 lines

Since general olc editing are automatically saved to disk, 'shutdown reboot' has
been changed to not-autosave by default. (Small change made to do_shutdown in 
act.wizard.c).
------------------------------------------------------------------------
 jeremyosborne | 2008-02-18 00:12:12 +0100 (Mon, 18 Feb 2008) | 3 lines

Changed:
struct attack_hit_type moved to fight.h
attack_hit_text exported through fight.h
------------------------------------------------------------------------
 jeremyosborne | 2008-02-17 22:32:51 +0100 (Sun, 17 Feb 2008) | 7 lines

- do_file heads or tails files correctly and has also been enhanced to return 
file info (act.wizard.c)
- defines made for common log files created by autorun, and those used by 
do_file (db.h)
- utility functions added: file_head(), file_tail(), file_sizeof(), and 
file_numlines() (defined utils.c and exported through utils.h)
------------------------------------------------------------------------
 Rumble | 2008-02-16 23:24:05 +0100 (Sat, 16 Feb 2008) | 1 line

Fixed export command. (thanks Kyle)
------------------------------------------------------------------------
 jeremyosborne | 2008-02-16 22:42:46 +0100 (Sat, 16 Feb 2008) | 1 line

Files are now tagged as executable. Should be able to be checked out from subver
sion and executed without running chmod.
------------------------------------------------------------------------
 Rumble | 2008-02-15 17:03:06 +0100 (Fri, 15 Feb 2008) | 1 line

 Fixed strcat() writing out of bounds in cedit.c since strdup() only malloc() 
strlen(str)+1 bytes. (thanks Buggo) and moved attack_hit_text back.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-13 20:41:02 +0100 (Wed, 13 Feb 2008) | 1 line

Event queue function definitions, global variables and defines doxygenated.
------------------------------------------------------------------------
 Rumble | 2008-02-12 00:23:38 +0100 (Tue, 12 Feb 2008) | 1 line

Updated levels command to use an arg/range and added color parsing to greetings.
 (thanks Jamdog)
------------------------------------------------------------------------
 jeremyosborne | 2008-02-11 21:06:10 +0100 (Mon, 11 Feb 2008) | 1 line

Doxygen comments completed for weather.c
------------------------------------------------------------------------
 Rumble | 2008-02-11 03:52:50 +0100 (Mon, 11 Feb 2008) | 1 line

Corrected several 64-bit warnings. (thanks Buggo)
------------------------------------------------------------------------
 Rumble | 2008-02-10 22:56:56 +0100 (Sun, 10 Feb 2008) | 1 line

Added get_flag_by_name allowing for new trigedit variable checks like 
%actor.pref(FLAG)% checks. (thanks Jamdog)
------------------------------------------------------------------------
 jeremyosborne | 2008-02-08 21:22:26 +0100 (Fri, 08 Feb 2008) | 3 lines

COMPLETE: tbaMUD code re-org of global and local scope function and variable 
declarations. There may be a few things that I did not catch (some non extern 
keyword declarations of function prototypes within other functions, for 
example).

BUG FIX: Unused functions encrypt_hex() and decrypt_hex() removed from mail.c.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-05 23:31:09 +0100 (Tue, 05 Feb 2008) | 2 lines

Continued clean-up of 'extern' references to functions and variables.
BUG UNCOVERED: set_title() in class.c incorrectly handles the const nature of 
the char * returned from title_female and title_male.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-05 19:38:17 +0100 (Tue, 05 Feb 2008) | 3 lines

More work on mud clean-up.
New file: spec_procs.h
Created this file to house the legacy special procedures (spec_procs.c and 
castle.c) and special feature assignment in general.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-05 00:59:44 +0100 (Tue, 05 Feb 2008) | 3 lines

- Minor Bugfix: Fixed parse error in mobact.c
- Minor Bugfix: act.h is now included in all of the act functions. Forgot to do
that the first time :(
- Additions: ban.h has been added as the external entry point into the ban.c 
globals and functions. Files needing ban.h have been updated.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-04 20:02:11 +0100 (Mon, 04 Feb 2008) | 1 line

All act*.c functions, defines and globals have been prototyped/declared in 
act.h. The file act.h does not contain every ACMD, only those ACMDs and 
utility functions available within the act*.c files.
------------------------------------------------------------------------
 Rumble | 2008-02-04 17:59:47 +0100 (Mon, 04 Feb 2008) | 1 line

Fixed the last few flags missed for the 128 bit conversion.
------------------------------------------------------------------------
 Laoris | 2008-02-04 07:27:56 +0100 (Mon, 04 Feb 2008) | 3 lines

Adding a column formatter for lists.  Accepts printf-like arguments.
Only used by medit right now.

------------------------------------------------------------------------
 jeremyosborne | 2008-02-04 07:09:19 +0100 (Mon, 04 Feb 2008) | 2 lines

- Changed the 'struct queue' to 'struct dg_queue' to avoid namespace conflicts.
- Ongoing cleanup to mud project.
------------------------------------------------------------------------
 Rumble | 2008-02-04 00:07:09 +0100 (Mon, 04 Feb 2008) | 1 line

Fixed run_autowiz which ran twice on advancement.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-03 03:46:22 +0100 (Sun, 03 Feb 2008) | 1 line

act.h created and added. This header will be the external entry point for the 
functions, function subcommands and variables within the act*.c files. It is 
not designed to be the entry point for all ACMD functions.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-03 02:44:29 +0100 (Sun, 03 Feb 2008) | 1 line

Merge of another part of the code cleanup, the dg script stuff.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-02 08:56:03 +0100 (Sat, 02 Feb 2008) | 1 line

Modularizing and organizing files continues. Committing comm.c and comm.h 
because they are hairy, and I don't want to do them over if my hard drive 
crashes.
------------------------------------------------------------------------
 jeremyosborne | 2008-02-02 07:05:08 +0100 (Sat, 02 Feb 2008) | 4 lines

- Marking all file scope functions as 'static'
- Reorganization of the global variables and functions.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-31 10:20:47 +0100 (Thu, 31 Jan 2008) | 1 line

* Protected the conf.h.* system config files from multiple calls.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-31 09:56:18 +0100 (Thu, 31 Jan 2008) | 1 line

* Removed extraneous references to TRUE / FALSE and YES / NO defines.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-31 09:46:20 +0100 (Thu, 31 Jan 2008) | 2 lines

* BUGFIX: NUM_POSITIONS set to 8 (was incorrectly set to 15 before)
* Migrated NUM_* settings from oasis.h to more appropriate locations near where
they are defined. (For Example: NUM_POSITIONS moved to structs.h next to the 
POSITION_* defines.)
------------------------------------------------------------------------
 jeremyosborne | 2008-01-31 03:58:28 +0100 (Thu, 31 Jan 2008) | 1 line

Added Appendix A - Coder Support. Right now, it simply speaks to the fact that 
we have included doxygen config files, are working to document the source code, 
and provides a rudimentary "do this" guide to create the doxygen cross 
references.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-30 07:12:07 +0100 (Wed, 30 Jan 2008) | 2 lines

- All .h files now have doxygen recognized headers, and the format is slightly 
altered to ease editing of headers.
- Protected all .h files from multiple calls. (Standard format is #ifndef _HEADE
R_H_ #define _HEADER_H_ .... #endif)
------------------------------------------------------------------------
 jeremyosborne | 2008-01-29 11:18:14 +0100 (Tue, 29 Jan 2008) | 1 line

constants.h, structs.h and utils.h now protected from multiple includes. This is
 sometimes overkill, but good practice overall.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-29 10:38:18 +0100 (Tue, 29 Jan 2008) | 1 line

Updated documentation for constants.c and constants.h.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-29 10:15:25 +0100 (Tue, 29 Jan 2008) | 3 lines

The standard Doxygen configuration doxyfiles (config files) for tbaMUD. One is 
to be used with the Graphviz DOT (dox_withGraphs), one is designed to be used if
Graphviz is not available.

Now just need a short document describing the usage of doxygen.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-29 10:11:36 +0100 (Tue, 29 Jan 2008) | 1 line

Minor document correction in struct dex_app_tpe.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-28 20:53:51 +0100 (Mon, 28 Jan 2008) | 1 line

*bugfix* do_drink command: When a container is empty, the correct, "It is 
empty." message is now displayed.
------------------------------------------------------------------------
 jeremyosborne | 2008-01-28 07:58:15 +0100 (Mon, 28 Jan 2008) | 3 lines

Merging changes to trunk for:
* utils.h, utils.c and structs.h doxygen comments
* adding file dox_withGraphs.doxyfile
2008-04-12 01:31:58 +00:00

527 lines
16 KiB
C

/**************************************************************************
* File: boards.c Part of tbaMUD *
* Usage: Handling of multiple bulletin boards. *
* *
* All rights reserved. See license for complete information. *
* *
* Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University *
* CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. *
**************************************************************************/
#define __BOARDS_C__
/* FEATURES & INSTALLATION INSTRUCTIONS
* - Arbitrary number of boards handled by one set of generalized routines.
* Adding a new board is as easy as adding another entry to an array.
* - Safe removal of messages while other messages are being written.
*
* TO ADD A NEW BOARD, simply follow our easy 4-step program:
* 1 - Create a new board object in the object files.
* 2 - Increase the NUM_OF_BOARDS constant in boards.h.
* 3 - Add a new line to the board_info array below. The fields are:
* Board's virtual number.
* Min level one must be to look at this board or read messages on it.
* Min level one must be to post a message to the board.
* Min level one must be to remove other people's messages from this
* board (but you can always remove your own message).
* Filename of this board, in quotes.
* Last field must always be 0.
* 4 - In spec_assign.c, find the section which assigns the special procedure
* gen_board to the other bulletin boards, and add your new one in a
* similar fashion. */
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "db.h"
#include "boards.h"
#include "interpreter.h"
#include "handler.h"
#include "improved-edit.h"
#include "modify.h"
/* Board appearance order. */
#define NEWEST_AT_TOP FALSE
/* Format: vnum, read lvl, write lvl, remove lvl, filename, 0 at end. Be sure
* to also change NUM_OF_BOARDS in board.h*/
struct board_info_type board_info[NUM_OF_BOARDS] = {
{3099, 0, 0, LVL_GOD, LIB_ETC "board.mortal", 0},
{3098, LVL_IMMORT, LVL_IMMORT, LVL_GRGOD, LIB_ETC "board.immortal", 0},
{3097, LVL_IMMORT, LVL_GRGOD, LVL_IMPL, LIB_ETC "board.freeze", 0},
{3096, 0, 0, LVL_IMMORT, LIB_ETC "board.social", 0},
{1226, 0, 0, LVL_IMPL, LIB_ETC "board.builder", 0},
{1227, 0, 0, LVL_IMPL, LIB_ETC "board.staff", 0},
{1228, 0, 0, LVL_IMPL, LIB_ETC "board.advertising", 0},
};
/* local (file scope) global variables */
static char *msg_storage[INDEX_SIZE];
static int msg_storage_taken[INDEX_SIZE];
static int num_of_msgs[NUM_OF_BOARDS];
static struct board_msginfo msg_index[NUM_OF_BOARDS][MAX_BOARD_MESSAGES];
/* local static utility functions */
static int find_slot(void);
static int find_board(struct char_data *ch);
static void init_boards(void);
static void board_reset_board(int board_type);
static void board_clear_board(int board_type);
static int find_slot(void)
{
int i;
for (i = 0; i < INDEX_SIZE; i++)
if (!msg_storage_taken[i]) {
msg_storage_taken[i] = 1;
return (i);
}
return (-1);
}
/* search the room ch is standing in to find which board he's looking at */
static int find_board(struct char_data *ch)
{
struct obj_data *obj;
int i;
for (obj = world[IN_ROOM(ch)].contents; obj; obj = obj->next_content)
for (i = 0; i < NUM_OF_BOARDS; i++)
if (BOARD_RNUM(i) == GET_OBJ_RNUM(obj))
return (i);
if (GET_LEVEL(ch) >= LVL_IMMORT)
for (obj = ch->carrying; obj; obj = obj->next_content)
for (i = 0; i < NUM_OF_BOARDS; i++)
if (BOARD_RNUM(i) == GET_OBJ_RNUM(obj))
return (i);
return (-1);
}
static void init_boards(void)
{
int i, j, fatal_error = 0;
for (i = 0; i < INDEX_SIZE; i++) {
msg_storage[i] = 0;
msg_storage_taken[i] = 0;
}
for (i = 0; i < NUM_OF_BOARDS; i++) {
if ((BOARD_RNUM(i) = real_object(BOARD_VNUM(i))) == NOTHING) {
log("SYSERR: Fatal board error: board vnum %d does not exist!",
BOARD_VNUM(i));
fatal_error = 1;
}
num_of_msgs[i] = 0;
for (j = 0; j < MAX_BOARD_MESSAGES; j++) {
memset((char *) &(msg_index[i][j]), 0, sizeof(struct board_msginfo));
msg_index[i][j].slot_num = -1;
}
board_load_board(i);
}
if (fatal_error)
exit(1);
}
SPECIAL(gen_board)
{
int board_type;
static int loaded = 0;
struct obj_data *board = (struct obj_data *)me;
/* These were originally globals for some unknown reason. */
int ACMD_READ, ACMD_LOOK, ACMD_EXAMINE, ACMD_WRITE, ACMD_REMOVE;
if (!loaded) {
init_boards();
loaded = 1;
}
if (!ch->desc)
return (0);
ACMD_READ = find_command("read");
ACMD_WRITE = find_command("write");
ACMD_REMOVE = find_command("remove");
ACMD_LOOK = find_command("look");
ACMD_EXAMINE = find_command("examine");
if (cmd != ACMD_WRITE && cmd != ACMD_LOOK && cmd != ACMD_EXAMINE &&
cmd != ACMD_READ && cmd != ACMD_REMOVE)
return (0);
if ((board_type = find_board(ch)) == -1) {
log("SYSERR: degenerate board! (what the hell...)");
return (0);
}
if (cmd == ACMD_WRITE)
return (board_write_message(board_type, ch, argument, board));
else if (cmd == ACMD_LOOK || cmd == ACMD_EXAMINE)
return (board_show_board(board_type, ch, argument, board));
else if (cmd == ACMD_READ)
return (board_display_msg(board_type, ch, argument, board));
else if (cmd == ACMD_REMOVE)
return (board_remove_msg(board_type, ch, argument, board));
else
return (0);
}
int board_write_message(int board_type, struct char_data *ch, char *arg, struct obj_data *board)
{
time_t ct;
char buf[MAX_INPUT_LENGTH], buf2[MAX_NAME_LENGTH + 3], tmstr[MAX_STRING_LENGTH];
if (GET_LEVEL(ch) < WRITE_LVL(board_type)) {
send_to_char(ch, "You are not holy enough to write on this board.\r\n");
return (1);
}
if (num_of_msgs[board_type] >= MAX_BOARD_MESSAGES) {
send_to_char(ch, "The board is full.\r\n");
return (1);
}
if ((NEW_MSG_INDEX(board_type).slot_num = find_slot()) == -1) {
send_to_char(ch, "The board is malfunctioning - sorry.\r\n");
log("SYSERR: Board: failed to find empty slot on write.");
return (1);
}
/* skip blanks */
skip_spaces(&arg);
delete_doubledollar(arg);
/* JE Truncate headline at 80 chars if it's longer than that. */
arg[80] = '\0';
if (!*arg) {
send_to_char(ch, "We must have a headline!\r\n");
return (1);
}
ct = time(0);
strftime(tmstr, sizeof(tmstr), "%a %b %d %Y", localtime(&ct));
snprintf(buf2, sizeof(buf2), "(%s)", GET_NAME(ch));
snprintf(buf, sizeof(buf), "%s %-12s :: %s", tmstr, buf2, arg);
NEW_MSG_INDEX(board_type).heading = strdup(buf);
NEW_MSG_INDEX(board_type).level = GET_LEVEL(ch);
send_to_char(ch, "Write your message.\r\n");
send_editor_help(ch->desc);
act("$n starts to write a message.", TRUE, ch, 0, 0, TO_ROOM);
string_write(ch->desc, &(msg_storage[NEW_MSG_INDEX(board_type).slot_num]),
MAX_MESSAGE_LENGTH, board_type + BOARD_MAGIC, NULL);
num_of_msgs[board_type]++;
return (1);
}
int board_show_board(int board_type, struct char_data *ch, char *arg, struct obj_data *board)
{
int i;
char tmp[MAX_STRING_LENGTH], buf[MAX_STRING_LENGTH];
if (!ch->desc)
return (0);
one_argument(arg, tmp);
if (!*tmp || !isname(tmp, board->name))
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);
}
act("$n studies the board.", TRUE, ch, 0, 0, TO_ROOM);
if (!num_of_msgs[board_type])
send_to_char(ch, "This is a bulletin board. Usage: READ/REMOVE <messg #>, WRITE <header>.\r\nThe board is empty.\r\n");
else {
size_t len = 0;
int nlen;
len = snprintf(buf, sizeof(buf),
"This is a bulletin board. Usage: READ/REMOVE <messg #>, WRITE <header>.\r\n"
"You will need to look at the board to save your message.\r\n"
"There are %d messages on the board.\r\n",
num_of_msgs[board_type]);
#if NEWEST_AT_TOP
for (i = num_of_msgs[board_type] - 1; i >= 0; i--) {
if (!MSG_HEADING(board_type, i))
goto fubar;
nlen = snprintf(buf + len, sizeof(buf) - len, "%-2d : %s\r\n", num_of_msgs[board_type] - i, MSG_HEADING(board_type, i));
if (len + nlen >= sizeof(buf) || nlen < 0)
break;
len += nlen;
}
#else
for (i = 0; i < num_of_msgs[board_type]; i++) {
if (!MSG_HEADING(board_type, i))
goto fubar;
nlen = snprintf(buf + len, sizeof(buf) - len, "%-2d : %s\r\n", i + 1, MSG_HEADING(board_type, i));
if (len + nlen >= sizeof(buf) || nlen < 0)
break;
len += nlen;
}
#endif
page_string(ch->desc, buf, TRUE);
}
return (1);
fubar:
log("SYSERR: Board %d is fubar'd.", board_type);
send_to_char(ch, "Sorry, the board isn't working.\r\n");
return (1);
}
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);
}
int board_remove_msg(int board_type, struct char_data *ch, char *arg, struct obj_data *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);
}
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, TO_ROOM);
board_save_board(board_type);
return (1);
}
void board_save_board(int board_type)
{
FILE *fl;
int i;
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;
}
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;
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_load_board(int board_type)
{
FILE *fl;
int i, len1, len2;
char *tmp1, *tmp2;
if (!(fl = fopen(FILENAME(board_type), "rb"))) {
if (errno != ENOENT)
perror("SYSERR: 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("SYSERR: Board file %d corrupt. Resetting.", board_type);
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) <= 0) {
log("SYSERR: Board file %d corrupt! Resetting.", board_type);
board_reset_board(board_type);
return;
}
CREATE(tmp1, char, len1);
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);
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);
}
/* When shutting down, clear all boards. */
void board_clear_all(void)
{
int i;
for (i = 0; i < NUM_OF_BOARDS; i++)
board_clear_board(i);
}
/* Clear the in-memory structures. */
void board_clear_board(int board_type)
{
int i;
for (i = 0; i < MAX_BOARD_MESSAGES; i++) {
if (MSG_SLOTNUM(board_type, i) == -1)
continue; /* don't try to free non-existant slots */
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;
}
/* Destroy the on-disk and in-memory board. */
static void board_reset_board(int board_type)
{
board_clear_board(board_type);
remove(FILENAME(board_type));
}