/
teeny/db/
teeny/dbm/
teeny/docs/
teeny/includes/
teeny/misc/
teeny/news/
teeny/text/
/* speech.c */

#include "copyright.h"
#include "config.h"

#include <stdio.h>
#ifdef STRING_H
#include <string.h>
#else
#include <strings.h>
#endif                                  /* STRING_H */
#include <ctype.h>

#include "teeny.h"
#include "match.h"

/*
 * Basic player commands pertaining to communication. 
 */

/* Buffer from cmds.c */

extern char     cmdwork[];


voidfunc 
do_pose(player, arg)
  int             player;
  char           *arg;
{
  char           *name, *p;
  int             count;

  if (get_str_elt(player, NAME, &name) == -1)
    goto posebomb;
  p = cmdwork;
  if (name != NULL)
  {
    for (count = 0; count < BUFFSIZ && !isspace(*name)
	 && *name; count++)
    {
      *p++ = *name++;
    }
  }
  if (arg != NULL)
  {
    if (arg[0] != ',' && arg[0] != '\'' && arg[0] != ' ')
      *p++ = ' ';
    count++;

    for (; count < BUFFSIZ - 3 && *arg; count++)
    {
      *p++ = *arg++;
    }
  }
  *p++ = '\r';
  *p++ = '\n';
  *p = '\0';
  notify_all(player, cmdwork);
  return;
posebomb:
  notify_bad(player);
  return;
}

voidfunc 
do_page(player, argone, argtwo)
  int             player;
  char           *argone, *argtwo;
{
  int             pagee;
  char           *name;
  char           *p;
  int             location;

  if (issticky(player))
  {
    notify_player(player, "You're not allowed to send pages while your S flag is set.\r\n");
    return;
  }
  if (argone == NULL)
  {
    notify_player(player, "Page whom?\r\n");
    return;
  }
  pagee = match_active_player(argone);
  if (pagee == -1)
  {
    pagee = match_player(argone);
    if (pagee == -1)
    {
      notify_player(player, "No such player.\r\n");
      return;
    } else
    {
      notify_player(player, "That player is not connected.\r\n");
      return;
    }
  }
  if (pagee == -2)
  {
    notify_player(player, "I don't know which player you mean.\r\n");
    return;
  }
  if (issticky(pagee))
  {
    notify_player(player,
		  "That player can't be disturbed at the moment.\r\n");
    return;
  }
  /* OK. Send the message. */

  if (argtwo == NULL)
  {
    notify_player(pagee, "You sense that ");
    if (get_str_elt(player, NAME, &name) == -1)
      goto pagebomb;

    if (name != NULL)
    {
      for (p = cmdwork; *name && !isspace(*name);)
      {
	*p++ = *name++;
      }
      *p++ = '\0';
    }
    notify_player(pagee, cmdwork);
    notify_player(pagee, " is looking for you in ");

    if (get_int_elt(player, LOC, &location) == -1)
      goto pagebomb;
    if (get_str_elt(location, NAME, &name) == -1)
      goto pagebomb;
    if (name != NULL)
    {
      notify_player(pagee, name);
    }
    notify_player(pagee, ".\r\n");
    if (get_str_elt(pagee, NAME, &name) == -1)
      goto pagebomb;

    if (name != NULL)
    {
      for (p = cmdwork; *name && !isspace(*name);)
      {
	*p++ = *name++;
      }
      *p++ = '\0';
    }
    notify_player(player, cmdwork);
    notify_player(player, " has been paged.\r\n"); 
  } else			/* message page */
  {
    if (get_str_elt(player, NAME, &name) == -1)
      goto pagebomb;
    if (name != NULL)
    {
      for (p = cmdwork; *name && !isspace(*name);)
      {
	*p++ = *name++;
      }
      *p++ = '\0';
    }
    notify_player(pagee, cmdwork);
    notify_player(pagee, " pages: ");
    notify_player(pagee, argtwo);
    notify_player(pagee, "\r\n");
    notify_player(player, "You paged ");
    if (get_str_elt(pagee, NAME, &name) == -1)
      goto pagebomb;
    if (name != NULL)
    {
      for (p = cmdwork; *name && !isspace(*name);)
      {
	*p++ = *name++;
      }
      *p++ = '\0';
    }
    notify_player(player, cmdwork);
    notify_player(player, ": ");
    notify_player(player, argtwo);
    notify_player(player, "\r\n");
  }
  return;
pagebomb:
  notify_bad(player);
  return;
}
voidfunc 
do_say(player, arg)
  int             player;
  char           *arg;
{
  char           *name, *p, *q;
  int             count;

  if (get_str_elt(player, NAME, &name) == -1)
    goto saybomb;

  /* Build the thing we're gonna say to everyone else */

  p = cmdwork;
  if (name != NULL)
  {
    for (count = 0; !isspace(*name) && *name
	 && count < BUFFSIZ - 9; count++)
    {
      *p++ = *name++;
    }
  }
  strcpy(p, " says, \"");
  count += 8;
  p += 8;

  if (arg == NULL)
  {
    *p++ = '\"';
    *p++ = '\r';
    *p++ = '\n';
    *p = '\0';
  } else
  {
    for (q = arg; *q && count < BUFFSIZ - 4; count++)
    {
      *p++ = *q++;
    }
    *p++ = '\"';
    *p++ = '\r';
    *p++ = '\n';
    *p = '\0';
  }

  /* Tell everyone else this */

  notify_oall(player, cmdwork);

  /* Now build what we want to tell the player itself */

  notify_player(player, "You say, \"");
  if (arg != NULL)
    notify_player(player, arg);
  notify_player(player, "\"\r\n");
  return;
saybomb:
  notify_bad(player);
  return;
}
voidfunc 
do_whisper(player, argone, argtwo)
  int             player;
  char           *argone, *argtwo;
{
  int             whisperee, here;
  char           *name;
  char           *q, ch;

  if (get_int_elt(player, LOC, &here) == -1)
    goto whisperbomb;

  if (argone == NULL || (!iswiz(player) &&
	 (whisperee = match_here(player, here, argone, MAT_PLAYERS)) == -1))
  {
    notify_player(player, "Whisper to whom?\r\n");
    return;
  }
  if (iswiz(player))
  {				/* wizard whisper */
    if (argone == NULL ||
	(whisperee = resolve_player(player, argone, 1)) == -1)
    {
      notify_player(player, "Whisper to whom?\r\n");
      return;
    }
  }
  if (whisperee == -2)
  {
    notify_player(player, "I don't know which player you mean.\r\n");
    return;
  }
  if (!isalive(whisperee))
  {
    notify_player(player, "That player is not connected.\r\n");
    return;
  }
  /* OK. Tell the players */

  if (get_str_elt(whisperee, NAME, &name) == -1)
    goto whisperbomb;

  /* Temporarily terminate the name. */

  if (name != NULL)
  {
    for (q = name; *q && !isspace(*q);)
      q++;
    ch = *q;
    *q = '\0';
  }
  notify_player(player, "You whisper, \"");
  if (argtwo != NULL)
    notify_player(player, argtwo);

  notify_player(player, "\" to ");
  if (name != NULL)
  {
    notify_player(player, name);
    *q = ch;
  }
  notify_player(player, ".\r\n");


  if (get_str_elt(player, NAME, &name) == -1)
    goto whisperbomb;

  /* Temporarily terminate the name. */

  if (name != NULL)
  {
    for (q = name; *q && !isspace(*q);)
      q++;
    ch = *q;
    *q = '\0';
    notify_player(whisperee, name);
    *q = ch;
  }
  notify_player(whisperee, " whispers, \"");
  if (argtwo != NULL)
  {
    notify_player(whisperee, argtwo);
  }
  notify_player(whisperee, "\"\r\n");
  return;
whisperbomb:
  notify_bad(player);
  return;
}