Beispiel #1
0
bool auth_write(AUTH_DATA *a, CHAR_DATA *ch)
{
  char authbuf[32];
  int n;
  
  sprintf(authbuf, "%u , %u\r\n", (unsigned int)ntohs(a->them.sin_port),
          (unsigned int)ntohs(a->us.sin_port));
  n = send(a->afd, authbuf, strlen(authbuf), 0);
  
  if (n != strlen(authbuf))
  {
    if (!--a->times)
    {
      /* This used to be the KILLRET you see below, but too many imms complained
         about log being spammed.. yeah.. like it aint spammed anyways..
         -- Alty */
      STRFREE(a->d->user);
      a->d->user = STRALLOC("(broken pipe)");
      return FALSE;
    }
/*      KILLRET("Auth_write: broken pipe for %s@%s.", "(broken pipe)");*/
    closesocket(a->afd);
    a->state = AS_TOOPEN;
    if (a->times == sysdata.ident_retries-1)
    {
      STRFREE(a->d->user);
      a->d->user = STRALLOC("(pipe breaking)");
    }
    return TRUE; /* Dont kill AUTH_DATA */
  }
  a->state = AS_TOREAD;
  return TRUE;
}
Beispiel #2
0
void do_prompt( CHAR_DATA * ch, const char *argument )
{
   char arg[MAX_INPUT_LENGTH];

   if( IS_NPC( ch ) )
   {
      send_to_char( "NPC's can't change their prompt..\r\n", ch );
      return;
   }
   argument = smash_tilde_static( argument );
   one_argument( argument, arg );
   if( !*arg )
   {
      send_to_char( "Set prompt to what? (try help prompt)\r\n", ch );
      return;
   }
   if( ch->pcdata->prompt )
      STRFREE( ch->pcdata->prompt );

   char prompt[128];
   mudstrlcpy(prompt, argument, 128);

   /*
    * Can add a list of pre-set prompts here if wanted.. perhaps
    * 'prompt 1' brings up a different, pre-set prompt 
    */
   if( !str_cmp( arg, "default" ) )
      ch->pcdata->prompt = STRALLOC( "" );
   else
      ch->pcdata->prompt = STRALLOC( prompt );
   send_to_char( "Ok.\r\n", ch );
   return;
}
Beispiel #3
0
void recv_text_handler( string & str )
{
   mud_channel *channel = nullptr;
   char_data *ch = nullptr;
   string arg1, arg2, arg3, arg4, arg5, chname;
   int ilevel = -1, clevel = -1;
   bool isnpc, isinvis;

   str = one_argument( str, arg1 );
   str = one_argument( str, arg2 );
   str = one_argument( str, arg3 );
   str = one_argument( str, arg4 );
   str = one_argument( str, arg5 );
   str = one_argument( str, chname );
   ilevel = atoi( arg2.c_str(  ) );
   clevel = atoi( arg3.c_str(  ) );
   isnpc = atoi( arg4.c_str(  ) );
   isinvis = atoi( arg5.c_str(  ) );

   if( !( channel = find_channel( arg1 ) ) )
   {
      bug( "%s: channel %s doesn't exist!", __func__, arg1.c_str(  ) );
      return;
   }

   /*
    * Massive punt here 
    */
   ch = new char_data;

   if( !isnpc )
   {
      ch->name = STRALLOC( capitalize( chname.c_str(  ) ) );
      ch->pcdata = new pc_data;
      ch->pcdata->wizinvis = ilevel;
      if( isinvis )
         ch->set_pcflag( PCFLAG_WIZINVIS );
   }
   else
   {
      ch->set_actflag( ACT_IS_NPC );
      ch->short_descr = STRALLOC( capitalize( chname.c_str(  ) ) );
      ch->mobinvis = ilevel;
   }
   ch->level = clevel;
   ch->to_room( get_room_index( ROOM_VNUM_LIMBO ) );
   send_tochannel( ch, channel, str );

   ch->from_room(  );
   deleteptr( ch );
}
Beispiel #4
0
FILE                   *__FileOpen( const char *filename, const char *mode, const char *file,
                                    const char *function, int line )
{
    FILE                   *fp = NULL;
    char                    fbuf[256];

    if ( !filename || filename[0] == '\0' || !mode || mode[0] == '\0' ) {
        log_string( "FileOpen called improperly." );
        return NULL;
    }

    // If writing...first create a temp file, otherwise just open the file -->KeB
    // 10/29/08
    if ( strstr( mode, "w" ) )
        snprintf( fbuf, 256, "%s.temporary", filename );
    else
        snprintf( fbuf, 256, "%s", filename );

    if ( ( fp = fopen( fbuf, mode ) ) == NULL ) {
        bug( "%s: can't open %s for %s. Called from %s:%d", __FUNCTION__, fbuf, mode, file, line );
        perror( fbuf );
        return NULL;
    }
    else {
        // *If you want to be really picky, define this* //
#ifdef DEBUG_FILEDATA
        FILE_DATA              *file_data;

        for ( file_data = file_list; file_data; file_data->next ) {
            if ( file_data->fp == fp ) {
                log_string( "FileOpen: Double opening of a file!" );
            }
        }
#endif

        FILE_DATA              *filedata;

        CREATE( filedata, FILE_DATA, 1 );
        filedata->filename = STRALLOC( fbuf );
        filedata->mode = STRALLOC( mode );
        filedata->file = STRALLOC( file );
        filedata->function = STRALLOC( function );
        filedata->line = line;
        filedata->fp = fp;
        LINK( filedata, first_filedata, last_filedata, next, prev );
        FilesOpen++;
    }

    return fp;
}
Beispiel #5
0
void disintegration( CHAR_DATA * ch, CHAR_DATA * victim, long amount )
{
   BOUNTY_DATA *bounty;
   bool found;
   char buf[MAX_STRING_LENGTH];

   found = FALSE;

   for( bounty = first_disintegration; bounty; bounty = bounty->next )
   {
      if( !str_cmp( bounty->target, victim->name ) )
      {
         found = TRUE;
         break;
      }
   }

   if( !found )
   {
      CREATE( bounty, BOUNTY_DATA, 1 );
      LINK( bounty, first_disintegration, last_disintegration, next, prev );

      bounty->target = STRALLOC( victim->name );
      bounty->amount = 0;
   }

   bounty->amount = bounty->amount + amount;
   save_disintegrations(  );

   sprintf( buf, "Someone has added %ld credits to the bounty on %s.", amount, victim->name );
   echo_to_all( AT_RED, buf, 0 );

}
Beispiel #6
0
/* changed for new indexing - 5/5/02 */
void renumber_news( void )
{
   NEWS_TYPE *type = NULL;
   NEWS *news = NULL;
   int x, y;

   for( y = 0; y < top_news_type; ++y )
      if( news_command_table[y] )
         STRFREE( news_command_table[y] );

   top_news_type = 0;

   for( type = first_news_type; type; type = type->next )
   {
      type->vnum = top_news_type++;
      news_command_table[type->vnum] = STRALLOC( type->cmd_name );

      x = 0;
      for( news = type->first_news; news; news = news->next )
      {
         ++x;
         news->number = x;
         news->type = type->vnum;
      }
   }
   return;
}
Beispiel #7
0
/*
 * make some coinage
 */
OBJ_DATA *create_money( int amount )
{
   char buf[MAX_STRING_LENGTH];
   OBJ_DATA *obj;

   if( amount <= 0 )
   {
      bug( "Create_money: zero or negative money %d.", amount );
      amount = 1;
   }

   if( amount == 1 )
   {
      obj = create_object( get_obj_index( OBJ_VNUM_MONEY_ONE ), 0 );
   }
   else
   {
      obj = create_object( get_obj_index( OBJ_VNUM_MONEY_SOME ), 0 );
      snprintf( buf, MAX_STRING_LENGTH, obj->short_descr, amount );
      STRFREE( obj->short_descr );
      obj->short_descr = STRALLOC( buf );
      obj->value[0] = amount;
   }

   return obj;
}
Beispiel #8
0
void note_attach( CHAR_DATA * ch )
{
  NOTE_DATA *pnote = NULL;

  if( ch->pnote )
    return;

  CREATE( pnote, NOTE_DATA, 1 );
  pnote->next = NULL;
  pnote->prev = NULL;
  pnote->sender = QUICKLINK( ch->name );
  pnote->date = STRALLOC( "" );
  pnote->to_list = STRALLOC( "" );
  pnote->subject = STRALLOC( "" );
  pnote->text = STRALLOC( "" );
  ch->pnote = pnote;
}
Beispiel #9
0
void do_prompt( CHAR_DATA * ch, const char *argument )
{
	char arg[MAX_INPUT_LENGTH];

	set_char_color( AT_GREY, ch );

	if ( IS_NPC( ch ) )
	{
		send_to_char( "NPC's can't change their prompt..\r\n", ch );
		return;
	}
	smash_tilde( argument );
	one_argument( argument, arg );
	if ( !*arg || !str_cmp( arg, "display" ) )
	{
		send_to_char( "Your current prompt string:\r\n", ch );
		set_char_color( AT_WHITE, ch );
		ch_printf( ch, "%s\r\n", !str_cmp( ch->pcdata->prompt, "" ) ? "(default prompt)" : ch->pcdata->prompt );
		set_char_color( AT_GREY, ch );
		send_to_char( "Type 'help prompt' for information on changing your prompt.\r\n", ch );
		return;
	}
	send_to_char( "Replacing old prompt of:\r\n", ch );
	set_char_color( AT_WHITE, ch );
	ch_printf( ch, "%s\r\n", !str_cmp( ch->pcdata->prompt, "" ) ? "(default prompt)" : ch->pcdata->prompt );
	if ( ch->pcdata->prompt )
		STRFREE( ch->pcdata->prompt );

	char prompt[128];

	mudstrlcpy( prompt, argument, 128 );

	/*
	 * Can add a list of pre-set prompts here if wanted.. perhaps
	 * 'prompt 1' brings up a different, pre-set prompt 
	 */
	if ( !str_cmp( arg, "default" ) )
		ch->pcdata->prompt = STRALLOC( "" );
	else
		ch->pcdata->prompt = STRALLOC( prompt );
	return;
}
Beispiel #10
0
/*
**  Name: CFReadConf
**
**  Description:
**      Read the configuration file a line at a time and build a list.
**
**  Inputs:
**      path            path of file to read
**      filename        filename of file to read
**
**  Outputs:
**      loc             Location to update with path and filename
**      begin           Starting line of the confiuration
**      end             Last line of the configuration
**
**  Returns:
**      OK      success
**      FAIL    failure
**
** History:
**      11-Feb-2000 (fanra01)
**          Created.
*/
STATUS
CFReadConf( char* path, char* filename, LOCATION* loc, PRL* begin )
{
    STATUS  status;
    char*   locpath;
    FILE*   fptr;
    PRL     newline;
    PRL     end;

    /*
    ** Get the location path
    */
    LOtos( loc, &locpath );
    STRCOPY( path, locpath );
    if ((status = LOfroms( PATH, locpath, loc )) == OK)
    {
        LOfstfile( filename, loc );
        if ((status = SIfopen( loc, "r", SI_TXT, 0, &fptr )) == OK)
        {
            do
            {
                status = SIgetrec( readbuf, SI_MAX_TXT_REC, fptr );
                if (status != ENDFILE)
                {
                    HALLOC( newline, RL, 1, &status );
                    if (newline != NULL)
                    {
                        newline->text = STRALLOC( readbuf );
                        if (*begin == NULL)
                        {
                            *begin = newline;
                            newline->prev = newline;
                        }
                        else
                        {
                            end = (*begin)->prev;
                            end->next = newline;
                            newline->prev = end;
                            (*begin)->prev = newline;
                        }
                    }
                }
            }while (status == OK);
            status = ((status == ENDFILE) || (status == OK)) ? OK : status;
            SIclose( fptr );
        }
        else
        {
            PRINTF( "Error: %d - Unable to open file %s in %s.\n", status,
                filename, path );
        }
    }
    return (status);
}
Beispiel #11
0
/* Create a new class online. -Shaddai */
bool create_new_class( int Class, char *argument )
{
    int                     i;

    if ( Class >= MAX_CLASS || class_table[Class] == NULL || !VLD_STR( argument ) )
        return FALSE;

    if ( class_table[Class]->who_name )
        STRFREE( class_table[Class]->who_name );
    if ( class_table[Class]->filename )
        STRFREE( class_table[Class]->filename );
    if ( argument[0] != '\0' )
        argument[0] = UPPER( argument[0] );
    class_table[Class]->who_name = STRALLOC( argument );
    class_table[Class]->filename = STRALLOC( argument );
    xCLEAR_BITS( class_table[Class]->affected );
    class_table[Class]->attr_prime = 0;
    class_table[Class]->attr_second = 0;
    class_table[Class]->attr_deficient = 0;
    class_table[Class]->race_restriction = 0;
    class_table[Class]->combo_restriction = 0;
    class_table[Class]->resist = 0;
    class_table[Class]->suscept = 0;
    class_table[Class]->skill_adept = 0;
    class_table[Class]->thac0_00 = 0;
    class_table[Class]->thac0_32 = 0;
    class_table[Class]->hp_min = 0;
    class_table[Class]->hp_max = 0;
    class_table[Class]->mana_min = 0;
    class_table[Class]->mana_max = 0;
    class_table[Class]->starting = FALSE;              /* Default to not a starting class 
                                                        */
    class_table[Class]->exp_base = 0;
    class_table[Class]->craft_base = 0;
    for ( i = 0; i < MAX_LEVEL; i++ ) {
        title_table[Class][i][0] = STRALLOC( "Not set." );
        title_table[Class][i][1] = STRALLOC( "Not set." );
    }
    return TRUE;
}
Beispiel #12
0
/* Read in an individual slaytype */
void fread_slay( SLAY_DATA * slay, FILE * fp )
{
   const char *word;
   bool fMatch;

   for( ;; )
   {
      word = feof( fp ) ? "End" : fread_word( fp );
      fMatch = FALSE;

      switch ( UPPER( word[0] ) )
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol( fp );
            break;

         case 'C':
            KEY( "Cmessage", slay->cmsg, fread_string( fp ) );
            KEY( "Color", slay->color, fread_number( fp ) );
            break;

         case 'E':
            if( !str_cmp( word, "End" ) )
            {
               if( !slay->owner )
                  slay->owner = STRALLOC( "Any" );
               return;
            }
            break;

         case 'O':
            KEY( "Owner", slay->owner, fread_string( fp ) );
            break;

         case 'R':
            KEY( "Rmessage", slay->rmsg, fread_string( fp ) );
            break;

         case 'T':
            KEY( "Type", slay->type, fread_string( fp ) );
            break;

         case 'V':
            KEY( "Vmessage", slay->vmsg, fread_string( fp ) );
            break;
      }

      if( !fMatch )
         bug( "Fread_slay: no match: %s", word );
   }
}
Beispiel #13
0
/* Create a slaytype online - Samson 8-3-98 */
void do_makeslay( CHAR_DATA * ch, char *argument )
{
   SLAY_DATA *slay;

   if( IS_NPC( ch ) )
   {
      send_to_char( "Huh?\r\n", ch );
      return;
   }

   if( !argument || argument[0] == '\0' )
   {
      send_to_char( "Usage: makeslay <slaytype>\r\n", ch );
      return;
   }

   smash_tilde( argument );

   /*
    * Glaring oversight just noticed - Samson 7-5-99 
    */
   if( ( slay = get_slay( argument ) ) != NULL )
   {
      send_to_char( "That slay type already exists.\r\n", ch );
      return;
   }

   CREATE( slay, SLAY_DATA, 1 );
   LINK( slay, first_slay, last_slay, next, prev );
   slay->type = STRALLOC( argument );
   slay->owner = STRALLOC( "Any" );
   slay->color = AT_IMMORT;
   slay->cmsg = STRALLOC( "You brutally slay $N!" );
   slay->vmsg = STRALLOC( "$n chops you up into little pieces!" );
   slay->rmsg = STRALLOC( "$n brutally slays $N!" );
   ch_printf( ch, "New slaytype %s added. Set to default values.\r\n", slay->type );
   save_slays(  );
   return;
}
Beispiel #14
0
/* added for new index - 5/5/02 - Nopey */
void fread_news_type( NEWS_TYPE * type, FILE * fp )
{
   const char *word;
   bool fMatch;

   for( ;; )
   {
      word = feof( fp ) ? "End" : fread_word( fp );
      fMatch = FALSE;

      switch ( UPPER( word[0] ) )
      {
         case '*':
            fread_to_eol( fp );
            break;

         case 'C':
            KEY( "Cmd_Name", type->cmd_name, fread_string( fp ) );
            break;

         case 'E':
            if( !str_cmp( word, "END" ) )
            {
               if( !type->name )
                  type->name = STRALLOC( "Unknown" );

               return;
            }
            break;

         case 'H':
            KEY( "Header", type->header, fread_string( fp ) );
            break;

         case 'L':
            KEY( "Level", type->level, fread_number( fp ) );
            break;

         case 'N':
            KEY( "Name", type->name, fread_string( fp ) );
            break;

         case 'V':
            KEY( "Vnum", type->vnum, fread_number( fp ) );
            break;
      }

      if( !fMatch )
         bug( "fread_news_type(): no match: %s", word );
   }
}
Beispiel #15
0
void set_auth(DESCRIPTOR_DATA *d)
{
  CHAR_DATA *ch = (d->original ? d->original : d->character);
  AUTH_DATA *a;
  struct sockaddr_in us, them;
  int ulen = sizeof(us), tlen = sizeof(them);
  
  /* To stop an uninitialized memory read --Shaddai */
  us.sin_port =    0;
  them.sin_port =  0;

  if (sysdata.ident_retries <= 0)
  {
    STRFREE(d->user);
    d->user = STRALLOC("(ident not active)");
    return;
  }
  if (getsockname(d->descriptor, (struct sockaddr *)&us, &ulen) < 0)
  {
    perror("set_auth: getsockname");
    ENDRET("Set_auth: getsockname error for %s@%s.", "(getsockname error)");
  }
  if (getpeername(d->descriptor, (struct sockaddr *)&them, &tlen) < 0)
  {
    perror("set_auth: getpeername");
    ENDRET("Set_auth: getpeername error for %s@%s.", "(getpeername error)");
  }
  CREATE(a, AUTH_DATA, 1);
  a->d = d;
  a->state = AS_TOOPEN;
  a->times = sysdata.ident_retries;
  a->us = us;
  a->them = them;
  LINK(a, first_auth, last_auth, next, prev);
  STRFREE(d->user);
  d->user = STRALLOC("(in progress)");
  return;
}
Beispiel #16
0
void auth_check(fd_set *ins, fd_set *outs, fd_set *excs)
{
  AUTH_DATA *a, *a_next;
  CHAR_DATA *ch;
  bool ferr;

  for (a = first_auth; a; a = a_next)
  {
    a_next = a->next;
    ferr = FALSE;
    ch = (a->d->original ? a->d->original : a->d->character);
    if (a->state == AS_TOOPEN)
    {
      if (!auth_open(a, ch))
        ferr = TRUE;
    }
    else if (FD_ISSET(a->afd, excs))
    {
      FD_CLR(a->afd, ins);
      FD_CLR(a->afd, outs);
      bug("Auth_check: exception found for %s@%s.",
          (ch ? ch->name : "(unknown)"), a->d->host);
      STRFREE(a->d->user);
      a->d->user = STRALLOC("Exception");
      ferr = TRUE;
    }
    else if (FD_ISSET(a->afd, ins) && a->state == AS_TOREAD)
    {
      if (!auth_read(a, ch))
      {
        FD_CLR(a->afd, outs);
        ferr = TRUE;
      }
    }
    else if (FD_ISSET(a->afd, outs) && a->state == AS_TOSEND)
    {
      if (!auth_write(a, ch))
        ferr = TRUE;
    }
    if (ferr)
    {
      if (a->state != AS_TOOPEN)
        closesocket(a->afd);
      UNLINK(a, first_auth, last_auth, next, prev);
      DISPOSE(a);
    }
  }
  return;
}
Beispiel #17
0
void kill_auth(DESCRIPTOR_DATA *d)
{
  AUTH_DATA *a;
  
  for (a = first_auth; a; a = a->next)
    if (a->d == d)
    {
      if (a->state != AS_TOOPEN)
        closesocket(a->afd);
      UNLINK(a, first_auth, last_auth, next, prev);
      DISPOSE(a);
      STRFREE(d->user);
      d->user = STRALLOC("(killed)");
      return;
    }
  return;
}
Beispiel #18
0
void load_disabled(  )
{
   FILE *fp;
   DISABLED_DATA *disabled;
   CMDTYPE *cmd;
   char *word;

   fp = fopen( DISABLE_FILE, "r" );

   if( !fp )
   {
      bug( "Unable to open disabled commands list." );
      return;
   }

   for( ;; )
   {
      word = fread_word( fp );

      if( !str_cmp( word, "End" ) )
         break;

      cmd = find_command( word );
      if( !cmd )
      {
         bug( "Unknown command in disabled list." );
         fread_number( fp );
         fread_word( fp );
         continue;
      }

      CREATE( disabled, DISABLED_DATA, 1 );
      disabled->command = cmd;
      disabled->level = fread_number( fp );
      disabled->who = STRALLOC( fread_word( fp ) );
      disabled->next = first_disabled;
      first_disabled = disabled;
   }

   fclose( fp );
}
Beispiel #19
0
void set_title( CHAR_DATA * ch, const char *title )
{
   char buf[MAX_STRING_LENGTH];

   if( IS_NPC( ch ) )
   {
      bug( "%s: NPC.", __FUNCTION__ );
      return;
   }

   if( isalpha( title[0] ) || isdigit( title[0] ) )
   {
      buf[0] = ' ';
      mudstrlcpy( buf + 1, title, MAX_STRING_LENGTH - 1 );
   }
   else
      mudstrlcpy( buf, title, MAX_STRING_LENGTH );

   STRFREE( ch->pcdata->title );
   ch->pcdata->title = STRALLOC( buf );
}
Beispiel #20
0
bool auth_read(AUTH_DATA *a, CHAR_DATA *ch)
{
  char readbuf[MAX_STRING_LENGTH];
  char system[MAX_INPUT_LENGTH], user[MAX_INPUT_LENGTH];
  char *s = readbuf;
  int n;
  
  n = recv(a->afd, readbuf, sizeof(readbuf)-10, 0);
  if (n < 0)
  {
    perror("auth_read: read");
    KILLRET("Auth_read: Error on read for %s@%s.", "(Error on read)");
  }
  if (!n)
    return TRUE;
/*    KILLRET("Auth_read: EOF on read for %s@%s.", "(EOF on read)");*/
  readbuf[n] = '\0';
  while (isspace(*s))
    ++s;
  if (!*s)
    KILLRET("Auth_read: blank auth for %s@%s.", "(blank auth)");
  /* That 1024 check should actually be against the port the user is
     logged into, but in SMAUG theres like 4 possible, and I don't
     feel like checking every single one.. -- Alty */
/*  bug("ident = '%s'.", s);*/
  if (!atoi(break_arg(&s, ',')) || atoi(break_arg(&s, ':')) < 1024)
    KILLRET("Auth_read: Invalid ident reply for %s@%s.", "(invalid ident)");
  break_arg(&s, ':');
  sprintf(system, "%.*s", (int)sizeof(system)-1, break_arg(&s, ':'));
/*  if (!str_cmp(system, "OTHER"))
    KILLRET("Auth_read: invalid system for %s@%s.", "(invalid system)");*/
  sprintf(user, "%.*s", (int)sizeof(user)-1, break_arg(&s, ' '));
  if (!*user)
    KILLRET("Auth_read: no username for %s@%s.", "(no username)");
  sprintf(log_buf, "Auth reply ok.  Incoming user [%s@%s] for %s.",
          user, a->d->host, (ch ? ch->name : "(unknown)"));
  STRFREE(a->d->user);
  a->d->user = STRALLOC(user);
  return FALSE; /* FALSE actually removes the AUTH_DATA, which is good. */
}
Beispiel #21
0
/*
** Name: CFBuildList
**
** Description:
**      Build a list from an array of character strings.
**
** Inputs:
**      section         pointer to array of character strings.
**
** Outputs:
**      begin           head of the list
**      end             tail of the list
**
** Returns:
**      OK              success
**      FAIL            failure
**
** History:
**      11-Feb-2000 (fanra01)
**          Created.
*/
STATUS
CFBuildList( char* section[], PRL* begin )
{
    STATUS  status = OK;
    PRL     newline;
    PRL     end;
    char**  sectline = section;
    i4      i;

    /*
    ** Assume the section is NULL terminated
    */
    for (i=0; (sectline && sectline[i]); i++)
    {
        /*
        ** Allocate a structure for the new line
        */
        HALLOC( newline, RL, 1, &status );
        if (newline != NULL)
        {
            /*
            ** Duplicate the line and add to end of list
            */
            newline->text = STRALLOC( sectline[i] );
            if (*begin == NULL)
            {
                *begin = newline;
                newline->prev = newline;
            }
            else
            {
                end = (*begin)->prev;
                end->next = newline;
                newline->prev = end;
                (*begin)->prev = newline;
            }
        }
    }
    return (status);
}
Beispiel #22
0
void set_title( CHAR_DATA * ch, const char *title )
{
   char buf[MAX_STRING_LENGTH];

   if( IS_NPC( ch ) )
   {
      bug( "Set_title: NPC.", 0 );
      return;
   }

   if( isalpha( title[0] ) || isdigit( title[0] ) )
   {
      buf[0] = ' ';
      strcpy( buf + 1, title );
   }
   else
      strcpy( buf, title );

   STRFREE( ch->pcdata->title );
   ch->pcdata->title = STRALLOC( buf );
   return;
}
Beispiel #23
0
void load_bounties(  )
{
   FILE *fpList;
   char *target;
   char bountylist[256];
   BOUNTY_DATA *bounty;
   long int amount;

   first_disintegration = NULL;
   last_disintegration = NULL;

   log_string( "Loading disintegrations..." );

   sprintf( bountylist, "%s%s", SYSTEM_DIR, disintegration_LIST );
   if( ( fpList = fopen( bountylist, "r" ) ) == NULL )
   {
      perror( bountylist );
      exit( 1 );
   }

   for( ;; )
   {
      target = feof( fpList ) ? "$" : fread_word( fpList );
      if( target[0] == '$' )
         break;
      CREATE( bounty, BOUNTY_DATA, 1 );
      LINK( bounty, first_disintegration, last_disintegration, next, prev );
      bounty->target = STRALLOC( target );
      amount = fread_number( fpList );
      bounty->amount = amount;
   }
   fclose( fpList );
   log_string( " Done bounties " );

   return;
}
Beispiel #24
0
char                   *align_news( char *argument )
{
    char                    buf[MAX_NEWS_LENGTH];
    char                    arg[MAX_NEWS_LENGTH];
    char                   *return_buf;
    int                     num = 0;
    int                     count = 0;
    int                     date_len = 10;
    int                     spacer = 2;
    int                     total = ( date_len + spacer );

    strcpy( buf, "" );

    if ( argument == NULL || argument[0] == '\0' )
        return ( char * ) "";

    for ( ;; ) {
        int                     i = 0;
        int                     length = 0;
        int                     longlen = 0;

        argument = news_argument( argument, arg );

        // We use the length without the color spaces for wrapping
        length = strlen_color( arg );

        if ( ( total + length ) >= 79 ) {
            int                     index;

            buf[num] = '\n';
            num++;
            buf[num] = '\r';
            num++;
            for ( index = 0; index < ( date_len + spacer ); index++ ) {
                buf[num] = ' ';
                num++;
            }
            total = ( date_len + spacer );
        }

        // We use the length with the color spaces for substitution
        longlen = strlen( arg );

        for ( i = 0; i < longlen; i++ ) {
            if ( arg[count] == '&' || arg[count] == '^' ) {
                if ( arg[count + 1] == '\0' ) {
                    arg[count] = '\0';
                }
                else if ( ( arg[count] == '&' && arg[count + 1] == '&' )
                          || ( arg[count] == '^' && arg[count + 1] == '^' ) ) {
                    buf[num] = arg[count];
                    num++;
                    count++;
                    i++;
                    buf[num] = arg[count];
                    num++;
                    count++;
                    total++;
                }
                else {
                    count += 2;
                    i++;
                }
            }
            else {
                buf[num] = arg[count];
                total++;
                num++;
                count++;
            }
        }

        if ( argument != NULL && argument[0] != '\0' ) {
            buf[num] = ' ';
            num++;
            total++;
            count = 0;
        }
        else {
            buf[num] = '\0';
            break;
        }
    }

    return_buf = STRALLOC( buf );

    return return_buf;
}
Beispiel #25
0
/* Recover from a hotboot - load players */
void hotboot_recover( void )
{
   DESCRIPTOR_DATA *d = NULL;
   FILE *fp;
   char name[100];
   char host[MAX_STRING_LENGTH];
   int desc, room, dport, idle, dcompress, maxp = 0;
   bool fOld;

   fp = fopen( HOTBOOT_FILE, "r" );

   if( !fp )   /* there are some descriptors open which will hang forever then ? */
   {
      perror( "hotboot_recover: fopen" );
      bug( "%s", "Hotboot file not found. Exitting." );
      exit( 1 );
   }

   unlink( HOTBOOT_FILE ); /* In case something crashes - doesn't prevent reading */
   for( ;; )
   {
      d = NULL;

      fscanf( fp, "%d %d %d %d %d %s %s\n", &dcompress, &desc, &room, &dport, &idle, name, host );

      if( desc == -1 || feof( fp ) )
         break;

      if( !str_cmp( name, "maxp" ) || !str_cmp( host, "maxp" ) )
      {
         maxp = idle;
         continue;
      }

      /*
       * Write something, and check if it goes error-free 
       */
      if( !write_to_descriptor_old( desc, "\r\nThe Force swirls around you.\r\n", 0 ) )
      {
         close( desc ); /* nope */
         continue;
      }

      CREATE( d, DESCRIPTOR_DATA, 1 );
      CREATE( d->mccp, MCCP, 1 );
      d->next = NULL;
      d->descriptor = desc;
      d->connected = CON_GET_NAME;
      d->outsize = 2000;
      d->idle = 0;
      d->lines = 0;
      d->scrlen = 24;
      d->newstate = 0;
      d->prevcolor = 0x08;
      d->ifd = -1;
      d->ipid = -1;

      CREATE( d->outbuf, char, d->outsize );

      d->host = STRALLOC( host );
      d->port = dport;
      d->idle = idle;
#ifdef MCCP
      if( dcompress )
         write_to_buffer( d, compress2_on_str_2, 0 );
#endif
      LINK( d, first_descriptor, last_descriptor, next, prev );
      d->connected = CON_COPYOVER_RECOVER;   /* negative so close_socket will cut them off */
//      d->can_compress = dcompress;
//      if( d->can_compress )
//         compressStart( d );

      /*
       * Now, find the pfile 
       */
      fOld = load_char_obj( d, name, FALSE, TRUE );

      if( !fOld ) /* Player file not found?! */
      {
         write_to_descriptor( d, "\r\nSomehow, your character was lost during hotboot. Contact the immortals ASAP.\r\n", 0 );
         close_socket( d, FALSE );
      }
      else  /* ok! */
      {
         write_to_descriptor( d, "Suddenly, you remember nothing as the Force continues into the Galaxy.\r\n", 0 );
         d->character->in_room = get_room_index( room );
         if( !d->character->in_room )
            d->character->in_room = get_room_index( ROOM_VNUM_TEMPLE );

         /*
          * Insert in the char_list 
          */
         LINK( d->character, first_char, last_char, next, prev );

         char_to_room( d->character, d->character->in_room );
         act( AT_MAGIC, "You appear in a swirl of the Force!", d->character, NULL, NULL, TO_CHAR );
         act( AT_MAGIC, "$n appears in a swrrl of the Force!", d->character, NULL, NULL, TO_ROOM );
         d->connected = CON_PLAYING;
         if( ++num_descriptors > sysdata.maxplayers )
            sysdata.maxplayers = num_descriptors;
#ifdef AUTO_AUTH
         check_auth_state( d->character );   /* new auth */
#endif
      }
   }
   FCLOSE( fp );
   if( maxp > sysdata.maxplayers )
      sysdata.maxplayers = maxp;
   log_string( "Hotboot recovery complete." );
   return;
}
Beispiel #26
0
HINT_DATA *read_hint( char *filename, FILE * fp )
{
   HINT_DATA *hintData;
   const char *word;
   bool fMatch;
   char letter;

   do
   {
      letter = getc( fp );
      if( feof( fp ) )
      {
         fclose( fp );
         fp = NULL;
         return NULL;
      }
   }
   while( isspace( letter ) );
   ungetc( letter, fp );

   CREATE( hintData, HINT_DATA, 1 );
   hintData->next = NULL;
   hintData->prev = NULL;
   hintData->text = STRALLOC( "" );
   hintData->low = 0;
   hintData->high = 0;

   for( ;; )
   {
      word = feof( fp ) ? "End" : fread_word( fp );
      fMatch = FALSE;

      switch ( UPPER( word[0] ) )
      {
         case 'T':
            if( !str_cmp( word, "Text" ) )
               STRFREE( hintData->text );
            KEY( "Text", hintData->text, fread_string( fp ) );
            break;

         case 'E':
            if( !str_cmp( word, "End" ) )
            {
               if( !hintData->text )
                  hintData->text = STRALLOC( "" );
               return hintData;
            }
            break;

         case 'H':
            KEY( "High", hintData->high, fread_number( fp ) );
            break;

         case 'L':
            KEY( "Low", hintData->low, fread_number( fp ) );
            break;
      }

      if( !fMatch )
         bug( "%s: no match: %s", __func__, word );
   }
   STRFREE( hintData->text );
   DISPOSE( hintData );
   return NULL;
}
Beispiel #27
0
void do_hintedit( CHAR_DATA* ch, const char* argument)
{
   char arg[MAX_STRING_LENGTH];
   char arg2[MAX_STRING_LENGTH];
   char arg3[MAX_STRING_LENGTH];
   HINT_DATA *hintData;
   int i;
   int no = 0;
   int ano = 0;
   bool found = FALSE;

   if( IS_NPC( ch ) )
      return;

   if( !IS_IMMORTAL( ch ) )
      return;

   set_char_color( AT_LBLUE, ch );
   argument = one_argument( argument, arg );
   argument = one_argument( argument, arg2 );
   argument = one_argument( argument, arg3 );
   if( !str_cmp( arg, "help" ) || arg[0] == '\0' )
   {
      do_help( ch, "imm_hints" );
      return;
   }

   if( !str_cmp( arg, "list" ) )
   {
      if( first_hint )
      {
         pager_printf( ch, "No | Low | High |            Text             \r\n" );
         pager_printf( ch, "---|-----|------|--------------------------------------------------\r\n" );
         i = 0;
         for( hintData = first_hint; hintData; hintData = hintData->next )
         {
            ++i;
            pager_printf( ch, "%2d | %3d | %4d | %-30s\r\n", i, hintData->low, hintData->high, hintData->text );
         }
         pager_printf( ch, "\r\n%d hints in file.\r\n", i );
      }
      else
         send_to_char( "No hints in file.\r\n", ch );
      return;
   }

   else if( !str_cmp( arg, "remove" ) )
   {
      no = 0;
      if( !is_number( arg2 ) )
      {
         send_to_char_color( "Remove which hint?\r\n", ch );
         return;
      }
      ano = atoi( arg2 );
      found = FALSE;
      for( hintData = first_hint; hintData; hintData = hintData->next )
      {
         ++no;
         if( no == ano )
         {
            ch_printf_color( ch, "&CHint Number %d removed\r\n", ano );
            UNLINK( hintData, first_hint, last_hint, next, prev );
            STRFREE( hintData->text );
            DISPOSE( hintData );
            found = TRUE;
            break;
         }
      }
      if( !found )
      {
         send_to_char( "Hint not found\r\n", ch );
         return;
      }
      return;
   }
   else if( !str_cmp( arg, "add" ) )
   {
      if( arg2 == '\0' )
      {
         send_to_char( "What is the minimum level for this hint?\r\n", ch );
         return;
      }
      if( arg3 == '\0' )
      {
         send_to_char( "What is the maximum level for this hint?\r\n", ch );
         return;
      }
      if( atoi( arg2 ) > atoi( arg3 ) )
      {
         send_to_char( "Aborting:  max less than min!\r\n", ch );
         return;
      }
      CREATE( hintData, HINT_DATA, 1 );
      hintData->low = atoi( arg2 );
      hintData->high = atoi( arg3 );
      hintData->text = STRALLOC( argument );
      LINK( hintData, first_hint, last_hint, next, prev );
      send_to_char( "Ok.  Hint created\r\n", ch );
      return;
   }
   else if( !str_cmp( arg, "force" ) )
   {
      ch_printf_color( ch, "&p( &wHINT&p ):  &P%s\r\n", get_hint( LEVEL_AVATAR ) );
      return;
   }
   else if( !str_cmp( arg, "edit" ) )
   {
      no = 0;
      i = 0;

      if( arg2[0] == '\0' )
      {
         send_to_char( "Edit which hint number?\r\n", ch );
         return;
      }
      else
         no = atoi( arg2 );
      if( arg3[0] == '\0' )
      {
         ch_printf( ch, "Edit which field of hint %d (low/high/text)?\r\n", no );
         return;
      }
      if( argument[0] == '\0' )
      {
         ch_printf( ch, "Change hint %d's field %s to what ?\r\n", no, arg3 );
         return;
      }
      for( hintData = first_hint; hintData; hintData = hintData->next )
      {
         ++i;
         if( i == no )
         {
            found = TRUE;
            break;
         }
      }
      if( !found )
      {
         ch_printf( ch, "Hint %d not found.\r\n", no );
         return;
      }
      else
      {
         if( !str_cmp( arg3, "text" ) )
         {
            STRFREE( hintData->text );
            hintData->text = STRALLOC( argument );
            send_to_char( "Hint text changed!\r\n", ch );
            return;
         }
         else if( !str_cmp( arg3, "low" ) )
         {
            if( atoi( argument ) > hintData->high )
            {
               send_to_char( "Aborting:  min higher than max.\r\n", ch );
               return;
            }
            hintData->low = atoi( argument );
            send_to_char( "Minimum level for hint changed.\r\n", ch );
            return;
         }
         else if( !str_cmp( arg3, "high" ) )
         {
            if( atoi( argument ) < hintData->low )
            {
               send_to_char( "Aborting:  max lower than min.\r\n", ch );
               return;
            }
            hintData->high = atoi( argument );
            send_to_char( "Maximum level for hint changed.\r\n", ch );
            return;
         }
         else
         {
            send_to_char( "Valid fields are:  low/high/text\r\n", ch );
            return;
         }
      }
   }
   else if( !str_cmp( arg, "save" ) )
   {
      write_hint(  );
      send_to_char( "Saved.\r\n", ch );
      return;
   }
   else
   {
      send_to_char( "Syntax:  hint (list/add/remove/edit/save/force)\r\n", ch );
      return;
   }
}
Beispiel #28
0
void do_chess( CHAR_DATA * ch, const char *argument )
{
	char arg[MAX_INPUT_LENGTH];

	argument = one_argument( argument, arg );

	if ( IS_NPC( ch ) )
	{
		send_to_char( "NPC's can't be in chess games.\r\n", ch );
		return;
	}

	if ( !str_cmp( arg, "begin" ) )
	{
		GAME_BOARD_DATA *board;

		if ( ch->pcdata->game_board )
		{
			send_to_char( "You are already in a chess match.\r\n", ch );
			return;
		}

		CREATE( board, GAME_BOARD_DATA, 1 );
		init_board( board );
		ch->pcdata->game_board = board;
		ch->pcdata->game_board->player1 = QUICKLINK( ch->name );
		send_to_char( "You have started a game of chess.\r\n", ch );
		return;
	}

	if ( !str_cmp( arg, "join" ) )
	{
		GAME_BOARD_DATA *board = NULL;
		CHAR_DATA *vch;
		char arg2[MAX_INPUT_LENGTH];

		if ( ch->pcdata->game_board )
		{
			send_to_char( "You are already in a game of chess.\r\n", ch );
			return;
		}

		argument = one_argument( argument, arg2 );
		if ( arg2[0] == '\0' )
		{
			send_to_char( "Join whom in a chess match?\r\n", ch );
			return;
		}

#ifdef IMC
		if ( strstr( arg2, "@" ) )
		{
			if ( !str_cmp( imc_mudof( arg2 ), this_imcmud->localname ) )
			{
				send_to_char( "You cannot join IMC chess on the local mud!\r\n", ch );
				return;
			}

			if ( !str_cmp( imc_mudof( arg2 ), "*" ) )
			{
				send_to_char( "* is not a valid mud name.\r\n", ch );
				return;
			}

			if ( !str_cmp( imc_nameof( arg2 ), "*" ) )
			{
				send_to_char( "* is not a valid player name.\r\n", ch );
				return;
			}

			send_to_char( "Attempting to initiate IMC chess game...\r\n", ch );

			CREATE( board, GAME_BOARD_DATA, 1 );
			init_board( board );
			board->type = TYPE_IMC;
			board->player1 = QUICKLINK( ch->name );
			board->player2 = STRALLOC( arg2 );
			board->turn = -1;
			ch->pcdata->game_board = board;
			imc_send_chess( ch->name, arg2, "start" );
			return;
		}
#endif

		if ( !( vch = get_char_world( ch, arg2 ) ) )
		{
			send_to_char( "Cannot find that player.\r\n", ch );
			return;
		}

		if ( IS_NPC( vch ) )
		{
			send_to_char( "That player is an NPC, and cannot play games.\r\n", ch );
			return;
		}

		board = vch->pcdata->game_board;
		if ( !board )
		{
			send_to_char( "That player is not playing a game.\r\n", ch );
			return;
		}

		if ( board->player2 )
		{
			send_to_char( "That game already has two players.\r\n", ch );
			return;
		}

		board->player2 = QUICKLINK( ch->name );
		ch->pcdata->game_board = board;
		send_to_char( "You have joined a game of chess.\r\n", ch );

		vch = get_char_world( ch, board->player1 );
		ch_printf( vch, "%s has joined your game.\r\n", ch->name );
		return;
	}

	if ( !ch->pcdata->game_board )
	{
		send_to_char( "Usage: chess <begin|cease|status|board|move|join>\r\n", ch );
		return;
	}

	if ( !str_cmp( arg, "cease" ) )
	{
		free_game( ch->pcdata->game_board );
		return;
	}

	if ( !str_cmp( arg, "status" ) )
	{
		GAME_BOARD_DATA *board = ch->pcdata->game_board;

		if ( !board->player1 )
			send_to_char( "There is no black player.\r\n", ch );
		else if ( !str_cmp( board->player1, ch->name ) )
			send_to_char( "You are black.\r\n", ch );
		else
			ch_printf( ch, "%s is black.\r\n", board->player1 );

		if ( king_in_checkmate( board, BLACK_KING ) )
			send_to_char( "The black king is in checkmate!\r\n", ch );
		else if ( king_in_check( board, BLACK_KING ) )
			send_to_char( "The black king is in check.\r\n", ch );

		if ( !board->player2 )
			send_to_char( "There is no white player.\r\n", ch );
		else if ( !str_cmp( board->player2, ch->name ) )
			send_to_char( "You are white.\r\n", ch );
		else
			ch_printf( ch, "%s is white.\r\n", board->player2 );

		if ( king_in_checkmate( board, WHITE_KING ) )
			send_to_char( "The white king is in checkmate!\r\n", ch );
		else if ( king_in_check( board, WHITE_KING ) )
			send_to_char( "The white king is in check.\r\n", ch );

		if ( !board->player2 || !board->player1 )
			return;

		ch_printf( ch, "%d turns.\r\n", board->turn );
		if ( board->turn % 2 == 1 && !str_cmp( board->player1, ch->name ) )
		{
			ch_printf( ch, "It is %s's turn.\r\n", board->player2 );
			return;
		}
		else if ( board->turn % 2 == 0 && !str_cmp( board->player2, ch->name ) )
		{
			ch_printf( ch, "It is %s's turn.\r\n", board->player1 );
			return;
		}
		else
		{
			send_to_char( "It is your turn.\r\n", ch );
			return;
		}
		return;
	}

	if ( !str_prefix( arg, "board" ) )
	{
		send_to_char( print_big_board( ch, ch->pcdata->game_board ), ch );
		return;
	}

	if ( !str_prefix( arg, "move" ) )
	{
		CHAR_DATA *opp;
		char opp_name[MAX_INPUT_LENGTH];
		char a, b;
		int x, y, dx, dy, ret;

		if ( !ch->pcdata->game_board->player1 || !ch->pcdata->game_board->player2 )
		{
			send_to_char( "There is only 1 player.\r\n", ch );
			return;
		}

		if ( ch->pcdata->game_board->turn < 0 )
		{
			send_to_char( "The game hasn't started yet.\r\n", ch );
			return;
		}

		if ( king_in_checkmate( ch->pcdata->game_board, BLACK_KING ) )
		{
			send_to_char( "The black king has been checkmated, the game is over.\r\n", ch );
			return;
		}

		if ( king_in_checkmate( ch->pcdata->game_board, WHITE_KING ) )
		{
			send_to_char( "The white king has been checkmated, the game is over.\r\n", ch );
			return;
		}

		if ( !*argument )
		{
			send_to_char( "Usage: chess move [piece to move] [where to move]\r\n", ch );
			return;
		}

		if ( ch->pcdata->game_board->turn % 2 == 1 && !str_cmp( ch->pcdata->game_board->player1, ch->name ) )
		{
			send_to_char( "It is not your turn.\r\n", ch );
			return;
		}

		if ( ch->pcdata->game_board->turn % 2 == 0 && !str_cmp( ch->pcdata->game_board->player2, ch->name ) )
		{
			send_to_char( "It is not your turn.\r\n", ch );
			return;
		}

		if ( sscanf( argument, "%c%d %c%d", &a, &y, &b, &dy ) != 4 )
		{
			send_to_char( "Usage: chess move [dest] [source]\r\n", ch );
			return;
		}

		if ( a < 'a' || a > 'h' || b < 'a' || b > 'h' || y < 1 || y > 8 || dy < 1 || dy > 8 )
		{
			send_to_char( "Invalid move, use a-h, 1-8.\r\n", ch );
			return;
		}

		x = a - 'a';
		dx = b - 'a';
		--y;
		--dy;

		ret = is_valid_move( ch, ch->pcdata->game_board, x, y, dx, dy );
		if ( ret == MOVE_OK || ret == MOVE_TAKEN )
		{
			GAME_BOARD_DATA *board;
			int piece, destpiece;

			board = ch->pcdata->game_board;
			piece = board->board[x][y];
			destpiece = board->board[dx][dy];
			board->board[dx][dy] = piece;
			board->board[x][y] = NO_PIECE;

			if ( king_in_check( board, IS_WHITE( board->board[dx][dy] ) ? WHITE_KING : BLACK_KING ) && ( board->board[dx][dy] != WHITE_KING && board->board[dx][dy] != BLACK_KING ) )
			{
				board->board[dx][dy] = destpiece;
				board->board[x][y] = piece;
				ret = MOVE_INCHECK;
			}
			else
			{
				++board->turn;
#ifdef IMC
				if ( ch->pcdata->game_board->type == TYPE_IMC )
				{
					snprintf( arg, LGST, "move %d%d %d%d", x, y, dx, dy );
					imc_send_chess( ch->pcdata->game_board->player1, ch->pcdata->game_board->player2, arg );
				}
#endif
			}
		}

		if ( !str_cmp( ch->name, ch->pcdata->game_board->player1 ) )
		{
			opp = get_char_world( ch, ch->pcdata->game_board->player2 );
			if ( !opp )
				mudstrlcpy( opp_name, ch->pcdata->game_board->player2, MAX_INPUT_LENGTH );
		}
		else
		{
			opp = get_char_world( ch, ch->pcdata->game_board->player1 );
			if ( !opp )
				mudstrlcpy( opp_name, ch->pcdata->game_board->player1, MAX_INPUT_LENGTH );
		}

#ifdef IMC
#    define SEND_TO_OPP(arg,opp) \
      if( opp ) \
      { \
         if( ch->pcdata->game_board->type == TYPE_LOCAL ) \
            ch_printf( (opp), "%s\r\n", (arg) ); \
      } \
      else \
      { \
         if( ch->pcdata->game_board->type == TYPE_IMC ) \
            imc_send_tell( ch->name, opp_name, (arg), 1 ); \
      }
#else
#    define SEND_TO_OPP(arg,opp) \
      if( opp ) \
      { \
         if( ch->pcdata->game_board->type == TYPE_LOCAL ) \
            ch_printf( (opp), "%s\r\n", (arg) ); \
      }
#endif

		switch ( ret )
		{
			case MOVE_OK:
				send_to_char( "Ok.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has moved.\r\n", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_INVALID:
				send_to_char( "Invalid move.\r\n", ch );
				break;

			case MOVE_BLOCKED:
				send_to_char( "You are blocked in that direction.\r\n", ch );
				break;

			case MOVE_TAKEN:
				send_to_char( "You take the enemy's piece.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has taken one of your pieces!", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_CHECKMATE:
				send_to_char( "That move would result in a checkmate.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has attempted a move that would result in checkmate.", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_OFFBOARD:
				send_to_char( "That move would be off the board.\r\n", ch );
				break;

			case MOVE_SAMECOLOR:
				send_to_char( "Your own piece blocks the way.\r\n", ch );
				break;

			case MOVE_CHECK:
				send_to_char( "That move would result in a check.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has made a move that would result in a check.", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_WRONGCOLOR:
				send_to_char( "That is not your piece.\r\n", ch );
				break;

			case MOVE_INCHECK:
				send_to_char( "You are in check, you must save your king.\r\n", ch );
				break;

			default:
				bug( "%s: Unknown return value", __FUNCTION__ );
				break;
		}
#undef SEND_TO_OPP
		return;
	}
	send_to_char( "Usage: chess <begin|cease|status|board|move|join>\r\n", ch );
}
Beispiel #29
0
void do_comment( CHAR_DATA * ch, char *argument )
{
   char buf[MAX_STRING_LENGTH];
   char arg[MAX_INPUT_LENGTH];
   char arg1[MAX_INPUT_LENGTH];
   NOTE_DATA *pnote;
   CHAR_DATA *victim;
   int vnum;
   int anum;

   if( IS_NPC( ch ) )
   {
      send_to_char( "Mobs can't use the comment command.\r\n", ch );
      return;
   }

   if( !ch->desc )
   {
      bug( "do_comment: no descriptor", 0 );
      return;
   }

   /*
    * Put in to prevent crashing when someone issues a comment command
    * from within the editor. -Narn 
    */
   if( ch->desc->connected == CON_EDITING || ch->desc->connected == CON_NOTE_TO )
   {
      send_to_char( "You can't use the comment command from within the editor.\r\n", ch );
      return;
   }

   switch ( ch->substate )
   {
      default:
         break;
      case SUB_WRITING_NOTE:
         if( !ch->pnote )
         {
            bug( "do_comment: note got lost?", 0 );
            send_to_char( "Your note got lost!\r\n", ch );
            stop_editing( ch );
            return;
         }
         if( ch->dest_buf != ch->pnote )
            bug( "do_comment: sub_writing_note: ch->dest_buf != ch->pnote", 0 );
         STRFREE( ch->pnote->text );
         ch->pnote->text = copy_buffer( ch );
         stop_editing( ch );
         return;
   }

   set_char_color( AT_NOTE, ch );
   argument = one_argument( argument, arg );
   smash_tilde( argument );

   if( !str_cmp( arg, "about" ) )
   {

      victim = get_char_world( ch, argument );
      if( !victim )
      {
         send_to_char( "They're not logged on!\r\n", ch );  /* maybe fix this? */
         return;
      }

      if( IS_NPC( victim ) )
      {
         send_to_char( "No comments about mobs\r\n", ch );
         return;
      }


   }


   if( !str_cmp( arg, "list" ) )
   {
      victim = get_char_world( ch, argument );
      if( !victim )
      {
         send_to_char( "They're not logged on!\r\n", ch );  /* maybe fix this? */
         return;
      }

      if( IS_NPC( victim ) )
      {
         send_to_char( "No comments about mobs\r\n", ch );
         return;
      }

      if( get_trust( victim ) >= get_trust( ch ) )
      {
         send_to_char( "You're not of the right caliber to do this...\r\n", ch );
         return;
      }

      if( !victim->comments )
      {
         send_to_char( "There are no relevant comments.\r\n", ch );
         return;
      }

      vnum = 0;
      for( pnote = victim->comments; pnote; pnote = pnote->next )
      {
         vnum++;
         sprintf( buf, "%2d) %-10s [%s] %s\r\n", vnum, pnote->sender, pnote->date, pnote->subject );
/* Brittany added date to comment list and whois with above change */
         send_to_char( buf, ch );
      }

      /*
       * act( AT_ACTION, "$n glances over the notes.", ch, NULL, NULL, TO_ROOM ); 
       */
      return;
   }

   if( !str_cmp( arg, "read" ) )
   {
      bool fAll;

      argument = one_argument( argument, arg1 );
      victim = get_char_world( ch, arg1 );
      if( !victim )
      {
         send_to_char( "They're not logged on!\r\n", ch );  /* maybe fix this? */
         return;
      }

      if( IS_NPC( victim ) )
      {
         send_to_char( "No comments about mobs\r\n", ch );
         return;
      }

      if( get_trust( victim ) >= get_trust( ch ) )
      {
         send_to_char( "You're not of the right caliber to do this...\r\n", ch );
         return;
      }

      if( !victim->comments )
      {
         send_to_char( "There are no relevant comments.\r\n", ch );
         return;
      }



      if( !str_cmp( argument, "all" ) )
      {
         fAll = TRUE;
         anum = 0;
      }
      else if( is_number( argument ) )
      {
         fAll = FALSE;
         anum = atoi( argument );
      }
      else
      {
         send_to_char( "Note read which number?\r\n", ch );
         return;
      }

      vnum = 0;
      for( pnote = victim->comments; pnote; pnote = pnote->next )
      {
         vnum++;
         if( vnum == anum || fAll )
         {
            sprintf( buf, "[%3d] %s: %s\r\n%s\r\nTo: %s\r\n",
                     vnum, pnote->sender, pnote->subject, pnote->date, pnote->to_list );
            send_to_char( buf, ch );
            send_to_char( pnote->text, ch );
            /*
             * act( AT_ACTION, "$n reads a note.", ch, NULL, NULL, TO_ROOM ); 
             */
            return;
         }
      }

      send_to_char( "No such comment.\r\n", ch );
      return;
   }

   if( !str_cmp( arg, "write" ) )
   {
      note_attach( ch );
      ch->substate = SUB_WRITING_NOTE;
      ch->dest_buf = ch->pnote;
      start_editing( ch, ch->pnote->text );
      return;
   }

   if( !str_cmp( arg, "subject" ) )
   {
      note_attach( ch );
      STRFREE( ch->pnote->subject );
      ch->pnote->subject = STRALLOC( argument );
      send_to_char( "Ok.\r\n", ch );
      return;
   }

   if( !str_cmp( arg, "to" ) )
   {
      note_attach( ch );
      STRFREE( ch->pnote->to_list );
      ch->pnote->to_list = STRALLOC( argument );
      send_to_char( "Ok.\r\n", ch );
      return;
   }

   if( !str_cmp( arg, "clear" ) )
   {
      if( ch->pnote )
      {
         STRFREE( ch->pnote->text );
         STRFREE( ch->pnote->subject );
         STRFREE( ch->pnote->to_list );
         STRFREE( ch->pnote->date );
         STRFREE( ch->pnote->sender );
         DISPOSE( ch->pnote );
      }
      ch->pnote = NULL;

      send_to_char( "Ok.\r\n", ch );
      return;
   }

   if( !str_cmp( arg, "show" ) )
   {
      if( !ch->pnote )
      {
         send_to_char( "You have no comment in progress.\r\n", ch );
         return;
      }

      sprintf( buf, "%s: %s\r\nTo: %s\r\n", ch->pnote->sender, ch->pnote->subject, ch->pnote->to_list );
      send_to_char( buf, ch );
      send_to_char( ch->pnote->text, ch );
      return;
   }

   if( !str_cmp( arg, "post" ) )
   {
      char *strtime;

      if( !ch->pnote )
      {
         send_to_char( "You have no comment in progress.\r\n", ch );
         return;
      }

      argument = one_argument( argument, arg1 );
      victim = get_char_world( ch, arg1 );
      if( !victim )
      {
         send_to_char( "They're not logged on!\r\n", ch );  /* maybe fix this? */
         return;
      }

      if( IS_NPC( victim ) )
      {
         send_to_char( "No comments about mobs\r\n", ch );
         return;
      }

      if( get_trust( victim ) > get_trust( ch ) )
      {
         send_to_char( "You're not of the right caliber to do this...\r\n", ch );
         return;
      }

      /*
       * act( AT_ACTION, "$n posts a note.", ch, NULL, NULL, TO_ROOM ); 
       */

      strtime = ctime( &current_time );
      strtime[strlen( strtime ) - 1] = '\0';
      ch->pnote->date = STRALLOC( strtime );

      pnote = ch->pnote;
      ch->pnote = NULL;


      /*
       * LIFO to make life easier 
       */
      pnote->next = victim->comments;
      if( victim->comments )
         victim->comments->prev = pnote;
      pnote->prev = NULL;
      victim->comments = pnote;

      save_char_obj( victim );


#ifdef NOTDEFD
      fclose( fpReserve );
      sprintf( notefile, "%s/%s", BOARD_DIR, board->note_file );
      if( ( fp = fopen( notefile, "a" ) ) == NULL )
      {
         perror( notefile );
      }
      else
      {
         fprintf( fp, "Sender  %s~\nDate    %s~\nTo      %s~\nSubject %s~\nText\n%s~\n\n",
                  pnote->sender, pnote->date, pnote->to_list, pnote->subject, pnote->text );
         fclose( fp );
      }
      fpReserve = fopen( NULL_FILE, "r" );
#endif

      send_to_char( "Ok.\r\n", ch );
      return;
   }

   if( !str_cmp( arg, "remove" ) )
   {
      argument = one_argument( argument, arg1 );
      victim = get_char_world( ch, arg1 );
      if( !victim )
      {
         send_to_char( "They're not logged on!\r\n", ch );  /* maybe fix this? */
         return;
      }

      if( IS_NPC( victim ) )
      {
         send_to_char( "No comments about mobs\r\n", ch );
         return;
      }

      if( ( get_trust( victim ) >= get_trust( ch ) ) || ( get_trust( ch ) < 58 ) )  /* switch to some LEVEL_ thingie */
      {
         send_to_char( "You're not of the right caliber to do this...\r\n", ch );
         return;
      }

      /*
       * argument = one_argument(argument, arg); 
       */
      if( !is_number( argument ) )
      {
         send_to_char( "Comment remove which number?\r\n", ch );
         return;
      }

      anum = atoi( argument );
      vnum = 0;
      for( pnote = victim->comments; pnote; pnote = pnote->next )
      {
         vnum++;
         if( ( 58 <= get_trust( ch ) ) /* switch to some LEVEL_ thingie */
             && ( vnum == anum ) )
         {
            comment_remove( victim, pnote );
            send_to_char( "Ok.\r\n", ch );
            /*
             * act( AT_ACTION, "$n removes a note.", ch, NULL, NULL, TO_ROOM ); 
             */
            return;
         }
      }

      send_to_char( "No such comment.\r\n", ch );
      return;
   }

   send_to_char( "Type 'help comment' for usage (i hope!).\r\n", ch );
   return;
}
Beispiel #30
0
void do_buy( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    int maxgold;
    bool debit;
    OBJ_DATA *obj;    

    argument = one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Buy what?\n\r", ch );
	return;
    }

    if ( IS_SET(ch->in_room->room_flags, ROOM_PET_SHOP) )
    {
	char buf[MAX_STRING_LENGTH];
	CHAR_DATA *pet;
	ROOM_INDEX_DATA *pRoomIndexNext;
	ROOM_INDEX_DATA *in_room;

   if ( argument[0] == '\0' )
      debit = FALSE;
   else if ( !str_cmp( "atm", argument ) || !str_cmp( "debit", argument ) )
   {
      bool has_card = FALSE;
      
      for ( obj = ch->last_carrying; obj; obj = obj->prev_content )        
      {
          if ( obj->item_type == ITEM_DEBIT_CARD )
            has_card = TRUE;
      }   
      
     if ( has_card == TRUE )
      debit = TRUE;
     else
     {
       send_to_char( "You don't even have your card with you!\n\r", ch );
       return;    
     }    
    }

	if ( IS_NPC(ch) )
	    return;

	pRoomIndexNext = get_room_index( ch->in_room->vnum + 1 );
	if ( !pRoomIndexNext )
	{
	    bug( "Do_buy: bad pet shop at vnum %d.", ch->in_room->vnum );
	    send_to_char( "Sorry, you can't buy that here.\n\r", ch );
	    return;
	}

	in_room     = ch->in_room;
	ch->in_room = pRoomIndexNext;
	pet         = get_char_room( ch, arg );
	ch->in_room = in_room;

	if ( pet == NULL || !IS_NPC( pet ) || !IS_SET(pet->act, ACT_PET) )
	{
	    send_to_char( "Sorry, you can't buy that here.\n\r", ch );
	    return;
	}

	if (( ch->gold < 10 * pet->top_level * pet->top_level ) && debit == FALSE)
	{
	    send_to_char( "You can't afford it.\n\r", ch );
	    return;
	}
	else if ( (ch->pcdata->bank < 10 * pet->top_level * pet->top_level) && debit == TRUE )
	{
	  send_to_char( "You dont have enough money in your bank account for it.\n\r", ch );
          return;    
        } 

	maxgold = 10 * pet->top_level * pet->top_level;
        if ( debit == FALSE )
	  ch->gold	-= maxgold; /* this was already here, btw */
	else
	  ch->pcdata->bank  -= maxgold;

	boost_economy( ch->in_room->area, maxgold );
	pet		= create_mobile( pet->pIndexData );
	SET_BIT(pet->act, ACT_PET);
	SET_BIT(pet->affected_by, AFF_CHARM);

	argument = one_argument( argument, arg );
	if ( arg[0] != '\0' )
	{
	    sprintf( buf, "%s %s", pet->name, arg );
	    STRFREE( pet->name );
	    pet->name = STRALLOC( buf );
	}

	sprintf( buf, "%sA neck tag says 'I belong to %s'.\n\r",
	    pet->description, ch->name );
	STRFREE( pet->description );
	pet->description = STRALLOC( buf );

	char_to_room( pet, ch->in_room );
	add_follower( pet, ch );
	send_to_char( "Enjoy your pet.\n\r", ch );
    	act( AT_ACTION, "$n bought $N as a pet.", ch, NULL, pet, TO_ROOM );
	return;
    }
    else
    {
	CHAR_DATA *keeper;
	int cost;
	int noi = 1;		/* Number of items */
	sh_int mnoi = 20;	/* Max number of items to be bought at once */

	if ( ( keeper = find_keeper( ch ) ) == NULL )
	    return;

	maxgold = keeper->top_level * 10;

	if ( is_number( arg ) )
	{
	    noi = atoi( arg );
	    argument = one_argument( argument, arg );
	    if ( noi > mnoi )
	    {
		act( AT_TELL, "$n tells you 'I don't sell that many items at"
		  " once.'", keeper, NULL, ch, TO_VICT );
		ch->reply = keeper;
		return;
	    }
	}

    if ( argument[0] == '\0' )
      debit = FALSE;
    else if ( !str_cmp( "atm", argument ) || !str_cmp( "debit", argument ) )
    {
      bool has_card = FALSE;
      
      for ( obj = ch->last_carrying; obj; obj = obj->prev_content )        
      {
          if ( obj->item_type == ITEM_DEBIT_CARD )
            has_card = TRUE;
      }   
      
      if ( has_card == TRUE )
       debit = TRUE;
      else
      {
        send_to_char( "You don't even have your card with you!\n\r", ch );
        return;    
      }    
     }  

	obj  = get_obj_carry( keeper, arg );
	
	if ( !obj && arg[0] == '#' )
        {     
              int onum, oref;
              bool ofound = FALSE;
              
              onum =0;
              oref = atoi(arg+1);
              for ( obj = keeper->last_carrying; obj; obj = obj->prev_content )
	      { 
	        if ( obj->wear_loc == WEAR_NONE
	        &&   can_see_obj( ch, obj ) )
	            onum++;
                if ( onum == oref ) 
                {
                    ofound = TRUE;
                    break;
                }
                else if ( onum > oref )
                   break;
	      }
	      if (!ofound)
	         obj = NULL;
        }
	if (keeper->home != NULL && obj->cost > 0)
          cost= obj->cost;
	cost = ( get_cost( ch, keeper, obj, TRUE ) * noi );

	if( !IS_NPC(ch) && ch->pcdata->learned[gsn_bargain] > 0 && ch->pcdata->learned[gsn_bargain] > number_percent())
	 {
	   ch_printf(ch,"You are able to bargain from %d credits to %d credits!\n\r", cost, (cost/3)+(cost/2));
	   cost = (cost/3) + (cost/2);
	   if(number_percent() > 50)
	    learn_from_success(ch, gsn_bargain);
	 }

	if ( cost <= 0 || !can_see_obj( ch, obj ) )
	{
	    act( AT_TELL, "$n tells you 'I don't sell that -- try 'list'.'",
		keeper, NULL, ch, TO_VICT );
	    ch->reply = keeper;
	    return;
	}

	if ( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) && ( noi > 1 ) )
	{
	    interpret( keeper, "laugh" );
	    act( AT_TELL, "$n tells you 'I don't have enough of those in stock"
	     " to sell more than one at a time.'", keeper, NULL, ch, TO_VICT );
	    ch->reply = keeper;
	    return;
	}
	
	if ( ch->gold < cost && debit == FALSE)
	{
	    act( AT_TELL, "$n tells you 'You can't afford to buy $p.'",
		keeper, obj, ch, TO_VICT );
	    ch->reply = keeper;
	    return;
	}
	
        if ( ch->pcdata->bank < cost && debit == TRUE)
	{
	    send_to_char( "You are almost slide your card through, but you remember you don't have enough money!\n\r", ch );
	    return;	    
        }  

	if ( IS_SET(obj->extra_flags, ITEM_PROTOTYPE) 
             && get_trust( ch ) < LEVEL_IMMORTAL )
	{
	    act( AT_TELL, "$n tells you 'This is a only a prototype!  I can't sell you that...'", 
		keeper, NULL, ch, TO_VICT );
      	    ch->reply = keeper;
	    return;
	}

	if ( ch->carry_number + get_obj_number( obj ) > can_carry_n( ch ) )
	{
	    send_to_char( "You can't carry that many items.\n\r", ch );
	    return;
	}

	if ( ch->carry_weight + ( get_obj_weight( obj ) * noi )
		+ (noi > 1 ? 2 : 0) > can_carry_w( ch ) )
	{
	    send_to_char( "You can't carry that much weight.\n\r", ch );
	    return;
	}

	if ( noi == 1 )
	{
	    if ( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) )  
	       separate_obj( obj );
	    act( AT_ACTION, "$n buys $p.", ch, obj, NULL, TO_ROOM );
    	    act( AT_ACTION, "You buy $p.", ch, obj, NULL, TO_CHAR );
	}
        else
	{
	    sprintf( arg, "$n buys %d $p%s.", noi,
		( obj->short_descr[strlen(obj->short_descr)-1] == 's'
		? "" : "s" ) );
	    act( AT_ACTION, arg, ch, obj, NULL, TO_ROOM );
	    sprintf( arg, "You buy %d $p%s.", noi,
		( obj->short_descr[strlen(obj->short_descr)-1] == 's'
		? "" : "s" ) );
	    act( AT_ACTION, arg, ch, obj, NULL, TO_CHAR );
	    act( AT_ACTION, "$N puts them into a bag and hands it to you.",
		ch, NULL, keeper, TO_CHAR );
	}

        if ( debit == FALSE )
	  ch->gold     -= cost; /* this line was already here, btw */
        else if ( debit == TRUE )
          ch->pcdata->bank     -= cost;
	keeper->gold += cost;

	if ( keeper->gold > maxgold )
	{
	    boost_economy( keeper->in_room->area, keeper->gold - maxgold/2 );
	    keeper->gold = maxgold/2;
	    act( AT_ACTION, "$n puts some credits into a large safe.", keeper, NULL, NULL, TO_ROOM );
	}

	if ( IS_OBJ_STAT( obj, ITEM_INVENTORY ) )
	{
	    OBJ_DATA *buy_obj, *bag;

	    buy_obj = create_object( obj->pIndexData, obj->level );

	    /*
	     * Due to grouped objects and carry limitations in SMAUG
	     * The shopkeeper gives you a bag with multiple-buy,
	     * and also, only one object needs be created with a count
	     * set to the number bought.		-Thoric
	     */
	    if ( noi > 1 )
	    {
		bag = create_object( get_obj_index( OBJ_VNUM_SHOPPING_BAG ), 1 );
		/* perfect size bag ;) */
		bag->value[0] = bag->weight + (buy_obj->weight * noi);
		buy_obj->count = noi;
		obj->pIndexData->count += (noi - 1);
		numobjsloaded += (noi - 1);
		obj_to_obj( buy_obj, bag );
		obj_to_char( bag, ch );
	    }
	    else
		obj_to_char( buy_obj, ch );
	}
        else
	{
	    obj_from_char( obj );
	    obj_to_char( obj, ch );
	}

	return;
    }
}