Пример #1
0
int
process_output (DESCRIPTOR_DATA * t)
{
  char i[MAX_STRING_LENGTH + 1];

  if (!t->prompt_mode && !t->connected && t->edit_index == -1)
    if (write_to_descriptor (t, "\r\n") < 0)
      return (-1);

  /* Cycle thru output queue */
  while (get_from_q (&t->output, i))
    {
      if (t->snoop.snoop_by && t->snoop.snoop_by->desc != NULL
	  && !IS_NPC (t->snoop.snoop_by))
	{
	  write_to_q ("% ", &t->snoop.snoop_by->desc->output);
	  write_to_q (i, &t->snoop.snoop_by->desc->output);
	}
      if (write_to_descriptor (t, i))
	return (-1);
    }

  if (!t->connected && !(t->character && !IS_NPC (t->character) &&
			 GET_FLAG (t->character, FLAG_COMPACT)))
    if (IS_SET (t->edit_mode, MODE_DONE_EDITING) && t->edit_index == -1)
      if (write_to_descriptor (t, "\r\n") < 0)
	return (-1);

  return (1);
}
Пример #2
0
void vlog(u32 type, char* fmt, ...){
  va_list args;
  char s[MAX_STRING_LENGTH];
  long ct;
  int bit;
  char *tmstr, buf[MAX_STRING_LENGTH];
  struct connection_data *i;


  va_start(args, fmt);
  vsprintf(s, fmt, args);
  va_end(args);

  ct = time(0);
  tmstr = asctime(localtime(&ct));
  *(tmstr + strlen(tmstr) - 1) = '\0';
  fprintf(stderr, "%s :: %s\n", tmstr, s);

  if (!type) type=LOG_URGENT;
  for (bit=0; ((1<<bit)&type)==0; bit++);

  sprintf(buf,"%c%c %s %c%c\n",
	log_chars[bit][0],log_chars[bit][1],
	s,
	log_chars[bit][2],log_chars[bit][3]);

  for (i = connection_list; i; i = i->next)
    if (IS_CONN(i) && LOG(i->character,type) &&
	!IS_SET(i->character->specials.act,PLR_VEG))
      write_to_q(buf, &i->output,0);
}
Пример #3
0
void logl(int level,char *dl,char *str)
{
  long ct;
  char *tmstr, buf[MAX_STRING_LENGTH];
  struct connection_data *i;


  ct = time(0);
  tmstr = asctime(localtime(&ct));
  *(tmstr + strlen(tmstr) - 1) = '\0';
  fprintf(stderr, "%s :: %s\n", tmstr, str);


  if (str)
     sprintf(buf,"%c* %s *%c\n",dl[0],str,dl[1]);
  for (i = connection_list; i; i = i->next)
    if (IS_CONN(i) && GetMaxLevel(i->character)>=level &&
	!IS_SET(i->character->specials.act,PLR_VEG) &&
	!IS_SET(i->character->specials.act, PLR_NOVIEWLOG))
      write_to_q(buf, &i->output,0);
}
Пример #4
0
void
send_out (DESCRIPTOR_DATA * c, char *out_string)
{
  write_to_q (out_string, &c->output);
}
Пример #5
0
/*
 * Things we want to have when logging events.....
 *
 * BugFile is the filename you want to log to, NULL means stderr
 *
 * File, Func, Line can all be provided by the compiler as
 * __FILE__, __PRETTY_FUNCTION__, and __LINE__
 *
 * Level is the minimum character level which will see the
 * bug if they're logged in.
 *
 * The AreaFile and AreaLine are the file and line number
 * we were reading while booting the world database.
 *
 * Type is the type of error, typically things like
 * LOG_INFO, LOG_ERROR, LOG_FATAL, LOG_BOOT, LOG_AUTH
 *
 * ch is the char_data pointer for the player/mob
 * obj is an obj_data pointer, if you have one
 * room is.... the room_data pointer.
 *
 * Str is, of course, the message, and it gets printed
 * using varargs, so you can have this be a printf type
 * set of macros.
 */
void bug_logger(unsigned int Type, const char *BugFile,
		const char *File, const char *Func, int Line,
		const char *AreaFile, int AreaLine,
		struct char_data *ch, struct char_data *victim,
		unsigned int Level, const char *Str, ...)
{
    va_list                                 arg;
    char                                    Result[MAX_STRING_LENGTH] = "\0\0\0";
    char                                    Temp[MAX_STRING_LENGTH] = "\0\0\0";
    FILE                                   *fp = NULL;
    struct timeb                            right_now;
    struct tm                              *now_part = NULL;

    bzero(Result, MAX_STRING_LENGTH);
    va_start(arg, Str);
    if (Str && *Str) {
	struct descriptor_data                 *i;

	snprintf(Result, MAX_STRING_LENGTH, "%s> ", LogNames[Type]);
	vsnprintf(Temp, MAX_STRING_LENGTH, Str, arg);
	strlcat(Result, Temp, MAX_STRING_LENGTH);
	for (i = descriptor_list; i; i = i->next)
	    if ((!i->connected) && (GetMaxLevel(i->character) >= Level) &&
		(IS_SET(i->character->specials.new_act, NEW_PLR_LOGS)))
		write_to_q(Result, &i->output, 1);
	bzero(Result, MAX_STRING_LENGTH);
    } else
	strlcpy(Temp, "PING!", MAX_STRING_LENGTH);
    va_end(arg);
    ftime(&right_now);
    now_part = localtime((const time_t *)&right_now);
    snprintf(Result, MAX_STRING_LENGTH, "<: %04d%02d%02d.%02d%02d%02d.%03d",
	    now_part->tm_year + 1900, now_part->tm_mon + 1, now_part->tm_mday,
	    now_part->tm_hour, now_part->tm_min, now_part->tm_sec, right_now.millitm);
    scprintf(Result, MAX_STRING_LENGTH, " - %s -", LogNames[Type]);
    if (File || Func || Line) {
	strlcat(Result, " (", MAX_STRING_LENGTH);
	if (File && *File) {
	    strlcat(Result, File, MAX_STRING_LENGTH);
	}
	if (Func && *Func)
	    scprintf(Result, MAX_STRING_LENGTH, ";%s", Func);
	if (Line)
	    scprintf(Result, MAX_STRING_LENGTH, ",%d)", Line);
	else
	    strlcat(Result, ")", MAX_STRING_LENGTH);
    }
    if (ch || victim) {
	if (ch)
	    scprintf(Result, MAX_STRING_LENGTH, " ch \"%s\" [#%d]", NAME(ch), ch->in_room);
	if (victim)
	    scprintf(Result, MAX_STRING_LENGTH, " victim \"%s\" [#%d]",
		    NAME(victim), victim->in_room);
/*
    if (obj)
      scprintf(Result, MAX_STRING_LENGTH, " obj \"%s\" [#%d]",
              SAFE_ONAME(obj), obj->in_room);
    if (room)
      scprintf(Result, MAX_STRING_LENGTH, " room \"%s\" [#%d]",
              room->name?room->name:"", room->number);
*/
	strlcat(Result, "\n", MAX_STRING_LENGTH);
    } else if (File || Func || Line)
	strlcat(Result, "\n", MAX_STRING_LENGTH);

    strlcat(Result, " : ", MAX_STRING_LENGTH);
    strlcat(Result, Temp, MAX_STRING_LENGTH);

    if (BugFile && *BugFile) {
	if (!(fp = fopen(BugFile, "a"))) {
	    perror(BugFile);
	    if (ch)
		cprintf(ch, "Could not open the file!\r\n");
	} else {
	    fprintf(fp, "%s\n", Result);
	    FCLOSE(fp);
	}
    }

    if (stderr) {
	fprintf(stderr, "%s\n", Result);
	fflush(stderr);
    }

    // Here is where we would log to SQL too!

    bug_sql(LogNames[Type], File, Func, Line, NULL, 0,
            ch ? NAME(ch) : NULL, ch ? ch->in_room : 0,
            victim ? NAME(victim) : NULL,  victim ? victim->in_room : 0,
            Temp);
}
Пример #6
0
int
process_input (DESCRIPTOR_DATA * t)
{
  int sofar;
  int thisround;
  int begin;
  int squelch;
  int i;
  int k;
  int flag;
  char tmp[MAX_STRING_LENGTH + 100];
  char buffer[MAX_STRING_LENGTH + 100];

  sofar = 0;
  flag = 0;
  begin = strlen (t->buf);

  /* Read in some stuff */
  do
    {
      if ((thisround = read (t->hSocketFD, t->buf + begin + sofar,
			     MAX_INPUT_LENGTH - (begin + sofar) - 1)) > 0)
	sofar += thisround;
      else if (thisround < 0)
	if (errno != EWOULDBLOCK)
	  {
	    return -1;
	  }
	else
	  break;
      else
	{
	  return -1;
	}
    }
  while (!ISNEWL (*(t->buf + begin + sofar - 1)));

  *(t->buf + begin + sofar) = 0;

  if (!IS_SET (t->edit_mode, MODE_DONE_EDITING))
    {
      ve_process (t, t->buf);	/* Editor subsystem call */
      *t->buf = '\0';		/* This may cause some data to be lost if */
      return (0);		/* chars are typed after @ & before processing */
    }

  /* if no newline is contained in input, return without proc'ing */
  for (i = begin; !ISNEWL (*(t->buf + i)); i++)
    if (!*(t->buf + i))
      return (0);

  /* input contains 1 or more newlines; process the stuff */
  for (i = 0, k = 0; *(t->buf + i);)
    {
      if (!ISNEWL (*(t->buf + i)) && !(flag = (k >= (MAX_INPUT_LENGTH - 2))))
	if (*(t->buf + i) == '\b')	/* backspace */
	  if (k)		/* more than one char ? */
	    {
	      i++;
	    }
	  else
	    i++;		/* no or just one char.. Skip backsp */
	else
	  /* KILLER CDR:  $$ problem here. */
	if (isascii (*(t->buf + i)) && isprint (*(t->buf + i)))
	  {
	    *(tmp + k) = *(t->buf + i);

	    k++;
	    i++;
	  }
	else
	  i++;
      else
	{
	  *(tmp + k) = 0;
	  if (*tmp == '!')
	    strcpy (tmp, t->last_input);
	  else
	    strcpy (t->last_input, tmp);

	  write_to_q (tmp, &t->input);

	  if (t->snoop.snoop_by && t->snoop.snoop_by->desc != NULL
	      && !IS_NPC (t->snoop.snoop_by))
	    {
	      write_to_q ("% ", &t->snoop.snoop_by->desc->output);
	      write_to_q (tmp, &t->snoop.snoop_by->desc->output);
	      write_to_q ("\n\r", &t->snoop.snoop_by->desc->output);
	    }

	  if (flag)
	    {
	      sprintf (buffer, "Line too long. Truncated to:\n\r%s\n\r", tmp);
	      if (write_to_descriptor (t, buffer) < 0)
		return (-1);

	      /* skip the rest of the line */
	      for (; !ISNEWL (*(t->buf + i)); i++);
	    }

	  /* find end of entry */
	  for (; ISNEWL (*(t->buf + i)); i++);

	  /* squelch the entry from the buffer */
	  for (squelch = 0;; squelch++)
	    if ((*(t->buf + squelch) = *(t->buf + i + squelch)) == '\0')
	      break;
	  k = 0;
	  i = 0;
	}
    }

  return (1);
}
Пример #7
0
/*
 * This is my general purpose error handler that spews a time-stamped
 * message to stderr and a logfile.
 * The messages are in this format:
 * <: DATE::(filename,func,line) User[#room]:\n : message\n
 *
 * If File, Func, or Line are NULL they will be ommitted.
 * If BufFile is NULL, stderr will be used alone.
 * If ch is NULL, User will be left blank.
 * If Str is NULL, we are just making a PING!
 *
 * NOTE!  The calling interface is very ugly... it is designed to be very
 * versitle, not pretty... If you want it to be useful in your source code,
 * use a macro like this one:
 * #define log_error(BugFile, ch, Str...) \
 *         bug_logger(__FILE__, __FUNCTION__, __LINE__, BugFile, ch, Str, ## args)
 * which can then be used by simply saying:
 * log_error(BUGLOG, ch, "You died %d times!\n", deaths);
 * producing as an example:
 * <: 950219.195642.037 (ack.c;barf,135) Quixadhal [#3001]:
 *  : You died 27 times!
 * The datestamp is YYMMDD.HHMMSS.MIL format.
 */
void bug_logger(const char *File, const char *Func, int Line,
#ifdef DIKU_CRUD
		unsigned int Level,
#endif
		unsigned int Type, const char *BugFile,
#ifdef DIKU_CRUD
		struct char_data *ch,
#endif
		const char *Str, ...)
{
    va_list                                 arg;
    char                                    Result[MAX_STRING_LENGTH];
    char                                    Temp[MAX_STRING_LENGTH];
    FILE                                   *fp;
    struct timeb                            right_now;
    struct tm                              *now_part;

    bzero(Result, MAX_STRING_LENGTH);
    va_start(arg, Str);
    if (Str && *Str) {
#ifdef DIKU_CRUD
	struct descriptor_data                 *i;

	strcpy(Result, "Notify> ");
#endif
	vsprintf(Temp, Str, arg);
#ifdef DIKU_CRUD
	strcat(Result, Temp);
	for (i = descriptor_list; i; i = i->next)
	    if ((!i->connected) && (GetMaxLevel(i->character) >= Level) &&
		(IS_SET(i->character->specials.act, PLR_LOGS)))
		write_to_q(Result, &i->output);
	bzero(Result, MAX_STRING_LENGTH);
#endif
    } else
	strcpy(Temp, "PING!");
    va_end(arg);
    ftime(&right_now);
    now_part = localtime((const time_t *)&right_now);
    sprintf(Result, "<: %02d%02d%02d.%02d%02d%02d.%03d",
	    now_part->tm_year, now_part->tm_mon + 1, now_part->tm_mday,
	    now_part->tm_hour, now_part->tm_min, now_part->tm_sec, right_now.millitm);
    if (File || Func || Line) {
	strcat(Result, " (");
	if (File && *File) {
	    strcat(Result, File);
	}
	if (Func && *Func)
	    sprintf(Result + strlen(Result), ";%s", Func);
	if (Line)
	    sprintf(Result + strlen(Result), ",%d)", Line);
	else
	    strcat(Result, ")");
    }
#ifdef DIKU_CRUD
    if (ch && !IS_NPC(ch))
	sprintf(Result + strlen(Result), " %s [#%d]\n",
		ch->player.name, ch->in_room ? ch->in_room : 0);
    else
#endif
    if (File || Func || Line)
	strcat(Result, "\n");

    strcat(Result, " : ");
    strcat(Result, Temp);

    if (BugFile && *BugFile) {
	if (!(fp = fopen(BugFile, "a"))) {
	    perror(BugFile);
#ifdef DIKU_CRUD
	    if (ch)
		send_to_char("Could not open the file!\n\r", ch);
#endif
	} else {
	    fprintf(fp, "%s\n", Result);
	    fclose(fp);
	}
    }
    fprintf(stderr, "%s\n", Result);
}