bulletin.c

bulletin.c · 8.7 KB

From the archive bulletin.tar.gz

Download the archive   « Back to the archive contents

/*
 *                     DIRT 3.0  (Aber 4)
 *
 * File: bulletin.c
 *
 * Bulletin board code for dirt3 muds.
 * Written by Vitastjern (anna@ludd.luth.se), September 1993 for
 * Northern Lights.
 *
 */


#include <unistd.h>
#include <stdlib.h>

#include <stdio.h>
#include <strings.h>
#include <stdarg.h>

#include "protos.h"

#include "kernel.h"
#include "writer.h"
#include "sendsys.h"
#include "mudmacros.h"
#include "timing.h"
#include "utils.h"
#include "objects.h"
#include "log.h"
#include "parse.h"
#include "bprintf.h"
#include "exec.h"

/* Defines needed for the bulletin */

#define START_RECORD   "BeginRecord"
#define END_OF_SUBJECT "EndSubject"

/* Help function to postcom() (writes the body of the text) */
static void bulletin_writer(void *w, void *ad, int adlen)
{
  char b[100];
  char a[adlen];
  FILE *f;

  strcpy(b, BULLETIN_DIR "/");
  strcpy(a, (char *)ad);
  strcat(b, a);  

  if ((f = fopen(b,"a+")) == NULL)
    {
      mudlog("Failed opening file %s (bulletin_writer)", b);
      bprintf("Sorry, can't open the bulletin. Try again later.\n");
      progerror(b);
      terminate_writer(w);
      return;
    }

  while (wgets(b,sizeof(b),w) != NULL)
    {
      fputs(b, f);
    }
  
  fclose(f);
}

/* Are we in a room with a bboard in it, and can we use that bboard? */
char *locate_bboard(void)
{
  
  if (ploc(mynum) == oloc(OBJ_HAVEN_MBULLETIN))
    {
      /* We are at the mortal bboard */
      return MBULLETIN;
    }
  else
    if (ploc(mynum) == oloc(OBJ_HAVEN_WBULLETIN))
      {
	if (plev(mynum) >= LVL_WIZARD)
	  /* We are at the wizard bboard */
	  return WBULLETIN;
	else
	  {
	    /* A mortal trying to use the wiz bboard... */
	    bprintf("You can't use the wizard bulletin board.\n");
	    return NULL;
	  }
      }
    else
      if (ploc(mynum) == oloc(OBJ_HAVEN_ABULLETIN))
	{
	  if (plev(mynum) >= LVL_ARCHWIZARD)
	    /* We are at the powers bboard */
	    return ABULLETIN;
	  else
	    {
	      bprintf("You can't use the power bulletin board.\n");
	      /* We are at the powers bboard, but can't use it...
		 (not awiz+) */
	      return NULL;
	    }
	}
      else
	{
	  /* We are at a location where there are no bboard at all */
	  bprintf("I can't see any bulletin board here!\n");
	  return NULL;
	}
}

/* Post something to the bulletin board. You can use commands while
   posting.
 */

void postcom(void)

{
  FILE *f;
  char bulletin[50];
  char *tmp;
  char c[1000];
  char b[100];

  getreinput(c);
  
  tmp = locate_bboard();

  if (tmp == NULL)
    return;
  
  strcpy(bulletin, tmp);

  if (cur_player->aliased || cur_player->polymorphed != -1)
    {
      bprintf("Not while aliased.\n");
      return;
    }

  if (EMPTY(txt1))
    {
      bprintf("Usage: POST subject\n");
      error();
      return;
    }


  strcpy(b, BULLETIN_DIR "/");
  strcat(b, bulletin);
  if ((f = fopen(b,"a+")) == NULL)
    {
      mudlog("Failed opening file %s (bulletin_writer)", b);
      bprintf("Sorry, can't open the bulletin. Try again later.\n");
      return;
    }
  fprintf(f, "%s\n", START_RECORD);
  fprintf(f, "Author:  %-20s %s\n", pname(mynum), time2ascii(TIME_CURRENT));
  fprintf(f, "Subject: %s\n", c);
  fprintf(f, "%s\n", END_OF_SUBJECT);
  fclose(f);
  
  start_writer("End the message with ** on the beginning "
	       "of a new line.\n"
	       "Type *HELP POST for help.",
	       "BULLETIN>",
	       bulletin,
	       strlen(bulletin)+1,
	       bulletin_writer,
	       WR_CMD|'*',
	       200);
  return;

}



/* Scan the bulletin board for titles and authors of messages.
 */

void scancom()
{

  char buff[BUFSIZ];
  char bulletin[50];
  char b[100];
  int  nr;
  FILE *f;
  char *tmp;  

  /* check if we are at a bboard and that we can use it... */
  tmp = locate_bboard();

  /* Must quit scan if we aren't at a bboard or can't use it... */
  if (tmp == NULL)
    return;

  strcpy(bulletin, tmp);

  if (cur_player->aliased || cur_player->polymorphed != -1)
    {
      bprintf("Not while aliased.\n");
      return;
    }

  strcpy(b, BULLETIN_DIR "/");
  strcat(b, bulletin);
  
  if ((f = fopen(b, "r")) == NULL)
    {
      bprintf("There are no posts on this bulletin board.\n");
      return;
    }

  if (f == NULL)
    {
      bprintf("Bailing out...\n");
      return;
    }

  nr = 0;
  
  while (fgets(buff, BUFSIZ, f) != NULL)
    {
      if (strcmp(buff, START_RECORD "\n") == 0)
	while (fgets(buff, BUFSIZ, f) != NULL)
	  {
	    if (strcmp(buff, END_OF_SUBJECT "\n") == 0)
	      break;
	    else
	      {
		nr++;
		bprintf("%-3d  %s", nr, buff);
		fgets(buff, BUFSIZ, f);
		bprintf("     %s", buff);
	      }
	  }
      else
	continue;
    }
  fclose(f);
  
}

/* Read a posted message
 */

void perusecom()
{

  int nr;
  char buff[BUFSIZ];
  char b[100];
  char c[1000];
  char bulletin[50];
  FILE *f;
  Boolean hitpost;
  char *tmp;
  
  /* check if we are at a bboard and that we can use it... */
  tmp = locate_bboard();
  
  /* Must quit peruse if we aren't at a bboard or can't use it... */
  if (tmp == NULL)
    return;

  strcpy(bulletin, tmp);

  if (cur_player->aliased || cur_player->polymorphed != -1)
    {
      bprintf("Not while aliased.\n");
      return;
    }

  strcpy(b, BULLETIN_DIR "/");
  strcat(b, bulletin);
  
  if ((f = fopen(b, "r")) == NULL)
    {
      bprintf("There are no posts on this bulletin board.\n");
      return;
    }

  if (f == NULL)
    {
      bprintf("Bailing out...\n");
      return;
    }

  if (EMPTY(txt1))
    {
      bprintf("Usage: PERUSE nr\n");
      error();
      return;
    }

  getreinput(c);

  hitpost = False;
  nr = 0;  
  
/* search through file for the pvoid postcom(void);
void unpostcom(void);
void scancom(void);
void perusecom(void);
MailncoXLNewsdPÆbinpZo.nnŒ.elm ÃmiscEAD´Õ.iscreen»Èµ
lost+foundÇÜ.xinitrcèì.rhosts
.Xdefaultsa
.twmrc.olds$.loginh4!¢logsarsH/„libidents.c\.login~x	rand_mazecŒ.aliases.cœnovice¬.cshrc¼.emaREADME   644   2146     52        5734  5615364312   5027 Step 1.  In the haven zone (xlimbo.zone) add the following objects:
(make sure to put the locations to where you want them)


Name	  = mbulletin
Pname	  = bulletin
AltName	  = board
Location  = IN_ROOM:haven
Oflags	  {NoGet}
Desc[0]	  = "A bulletin board is hanging on the north wall."
Examine	  = "
There is a little space left on the bulletin board, between notes of
people looking for rooms and announcements of things that happened last year.

You can leave messages here for other players to read.
Use POST and UNPOST to write and remove your messages.
Use SCAN and PERUSE to read the messages already posted."
End 	  = mbulletin

Name	  = wbulletin
Pname     = bulletin
AltName   = board
Location  = IN_ROOM:play@home
Oflags    {NoGet}
Desc[0]   = "A bulletin board for wizards has been constructed here."
Examine   = "
There is a little space left on the bulletin board, between notes of
wizards wanting to learn new spells, and invitations to parties that
took place last year.

Wizards can leave messages here for other wizards to read.
Use POST and UNPOST to write and remove your messages.
Use SCAN and PERUSE to read the messages already posted."
End	  = wbulletin

Name	  = abulletin
Pname     = bulletin
AltName   = board
Location  = IN_ROOM:rob38@robots
Oflags    {Magical NoGet}
Desc[0]   = "The bulletin board for this mud's powers is floating in the air."
Examine   = "
This bulletin board was created by the Goddess for the powers of this
mud to post small notes and encouragements to each other. Unfortunately,
they are the only ones that can use it...

Use POST and UNPOST to write and remove your messages.
Use SCAN and PERUSE to read the messages already posted."
End	  = abulletin


-----------------------

Step 2.

Create the directory "BB" in ../data

----------------------

Step 3:

Add the following lines to ../include/files.h:

#define BULLETIN_DIR    "BB"            /* Where to find bboard files */
#define MBULLETIN       "mortalbb"      /* General bulletin file */
#define WBULLETIN       "wizardbb"      /* Wizard bulletin file */
#define ABULLETIN       "awizbb"        /* The power bulletin file */

-----------------------

Step 4:

Add post, unpost, scan and peruse in ../data/verbs.src
and the corresponding calls to postcom, 

Site Stats

Snippets: 1791
Codebases: 571