Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 parse description bug
Yesterday, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Bing

Members: 0
Guests: 7
Stats
Files
Topics
Posts
Members
Newest Member
477
3,706
19,240
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » Lingering connections
Forum Rules | Mark all | Recent Posts

Lingering connections
< Newer Topic :: Older Topic > lingering connections :(

Pages:<< prev 1 next >>
Post is unread #1 Apr 9, 2003, 5:16 am
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,866
JoinedJul 26, 2005

Ok by now everyone probably knows my mud has been crazy for awhile and allowing lingering connections basicaly anyone can connect to the mud and drop link before they are actualy playing and then the connection will stay connected till it desides they aren't connected any longer which is normaly 2 hours later and then its kicked by read_from_descriptor instead of the mud lol. here is the code that might have a problem somewhere if you need more info/code just ask :)
void read_from_buffer(DESCRIPTOR_DATA *d)
{
  AFFECT_DATA af; /* Spamguard abusers beware! Muahahahahah! */
  int i, j, k;

  /* Hold horses if pending command already. */
  if(d->incomm[0] != '\0')
    return;
  /* Look for at least one new line. */
  for(i = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r' && i < MIS; i++)
    if(d->inbuf[i] == '\0')
      return;
  /* Canonical input processing. */
  for(i = 0, k = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r'; i++)
  {
    if(k >= MIL / 2) /* Reasonable enough to allow unless someone floods it with color tags */
    {
      write_to_descriptor(d, "Line too long.\n\r", 0);
      d->inbuf[i] = '\n';
      d->inbuf[i+1] = '\0';
    break;
    }
    if(d->inbuf[i] == '' && k > 0)
      --k;
    /* Note to the future curious: Leave this alone. Extended ascii isn't standardized yet.
       You'd think being the 21st century and all that this wouldn't be the case, but you can
       thank the bastards in Redmond for this. */
    else if(isascii(d->inbuf[i]) && isprint(d->inbuf[i]))
      d->incomm[k++] = d->inbuf[i];
  }
  /* Finish off the line. */
  if(k == 0)
    d->incomm[k++] = ' ';
  d->incomm[k] = '\0';
  /* Deal with bozos with #repeat 1000 ... */
  if(k > 1 || d->incomm[0] == '!')
  {
    if(d->incomm[0] != '!' && strcmp(d->incomm, d->inlast))
      d->repeat = 0;
    else
    {
      /* What this is SUPPOSED to do is make sure the command or alias being used isn't a public channel.
         As we know, code rarely does what we expect, and there could still be problems here.
         The only other solution seen as viable beyond this is to remove the spamguard entirely. */
      CMDTYPE *cmd = NULL;
      ALIAS_DATA *pal = NULL;
      char *arg, arg2[MIL];

      arg = d->incomm;
      arg = one_argument(arg, arg2);
      cmd = find_command(arg2);
      if(!cmd && d->character && (pal = find_alias(d->character, d->incomm)) != NULL)
      {
        char *arg3, arg4[MIL];

        arg3 = pal->cmd;
        arg3 = one_argument(arg3, arg4);
        cmd = find_command(arg4);
      }
      if(cmd && xIS_SET(cmd->flags, CMD_CHANNEL) /* && !str_cmp(d->incomm, d->inlast) */)
        ++d->repeat;
#ifdef I3
      if(!str_prefix("i3", arg2)) /* Keep the pricks from spamming I3 stuff too */
        ++d->repeat;
#endif
      if(d->repeat == 3 && d->character && d->character->level < LEVEL_IMMORTAL)
        send_to_char("}R\n\rYou have repeated the same command 3 times now.\n\r"
          "Repeating it 7 more will result in an autofreeze by the spamguard code.&D\n\r",
          d->character);
      if(d->repeat == 6 && d->character && d->character->level < LEVEL_IMMORTAL)
        send_to_char("}R\n\rYou have repeated the same command 6 times now.\n\r"
          "Repeating it 4 more will result in an autofreeze by the spamguard code.&D\n\r",
          d->character);
      if(d->repeat >= 10 && d->character && d->character->level < LEVEL_IMMORTAL)
      {
        set_char_color(AT_YELL, d->character);
        ++d->character->pcdata->spam;
        sprintf(log_buf, "%s was autofrozen by the spamguard - spamming: %s", d->character->name, d->incomm);
        log_string(log_buf);
        sprintf(log_buf, "%s has spammed %d times this login.", d->character->name, d->character->pcdata->spam);
        log_string(log_buf);
        write_to_descriptor(d, "\n\r*** PUT A LID ON IT!!! ***\n\rYou cannot enter the same command more then 10 consecutive times!\n\r", 0);
        write_to_descriptor(d, "The Spamguard has spoken!\n\r", 0);
        write_to_descriptor(d, "It suddenly becomes very cold, and very QUIET!\n\r", 0);
        strcpy(d->incomm, "spam";);
        af.type = skill_lookup("spamguard";);
        af.duration = 115 * d->character->pcdata->spam; /* One game hour per offense, this can get ugly FAST */
        af.modifier = 0;
        af.location = APPLY_NONE;
        af.bitvector = meb(AFF_SPAMGUARD);
        affect_to_char(d->character, &af);
        SET_PC_FLAG(d->character, PCFLAG_IDLE);
        d->repeat = 0; /* Just so it doesn't get haywire */
      }
    }
  }
  /* Do '!' substitution. */
  if(d->incomm[0] == '!')
    strcpy(d->incomm, d->inlast);
  else
    strcpy(d->inlast, d->incomm);
  /* Shift the input buffer. */
  while(d->inbuf[i] == '\n' || d->inbuf[i] == '\r')
    i++;
  for(j = 0; (d->inbuf[j] = d->inbuf[i+j]) != '\0'; j++);
return;
}

void game_loop()
{
  struct timeval last_time;
  char cmdline[MIL];
  DESCRIPTOR_DATA *d;
  /*  time_t last_check = 0;  */

  signal(SIGPIPE, SIG_IGN);
  signal(SIGALRM, caught_alarm);
  signal(SIGTERM, SigTerm); /* Catch kill signals */
#ifndef FREEBSD
  signal(SIGPWR, SigPower); /* Catch powerfail signals */
#endif
  signal(SIGUSR1, SigUser1); /* Catch user defined signals */
  signal(SIGUSR2, SigUser2);

  /* signal(SIGSEGV, SegVio); */
  gettimeofday(&last_time, NULL);
  current_time = (time_t) last_time.tv_sec;

  /* Main loop */
  while(!mud_down)
  {
    accept_new(control);
    auth_check(&in_set, &out_set, &exc_set);
    /* Kick out descriptors with raised exceptions or have been idle, then check for input. */
    for(d = first_descriptor; d; d = d_next)
    {
      if(d == d->next)
      {
      {
        bug("%s", "descriptor_loop: loop found & fixed";);
        d->next = NULL;
      }
      d_next = d->next;
      d->idle++; /* make it so a descriptor can idle out */
      if(FD_ISSET(d->descriptor, &exc_set))
      {
        FD_CLR(d->descriptor, &in_set);
        FD_CLR(d->descriptor, &out_set);
        if(d->character && (d->connected == CON_PLAYING
        || d->connected == CON_DELETE || d->connected == CON_ROLL_STATS
        || d->connected == CON_EDITING))
          save_char_obj(d->character);
        d->outtop = 0;
        close_socket(d, TRUE);
      continue;
      }
      else
      if((!d->character && d->idle > 480) /* 2 mins */
      || (d->connected != CON_PLAYING && d->idle > 1200) /* 5 mins */
      || d->idle > 28800) /* 2 hrs */
      {
        write_to_descriptor(d, "Idle timeout... disconnecting.\n\r", 0);
        d->outtop = 0;
        close_socket(d, TRUE);
      continue;
      }
      else
      {
        d->fcommand = FALSE;

        if(FD_ISSET(d->descriptor, &in_set))
        {
          d->idle = 0;
          if(d->character)
            d->character->timer = 0;
          if(!read_from_descriptor(d))
          {
            FD_CLR(d->descriptor, &out_set);
            if(d->character && (d->connected == CON_PLAYING
            || d->connected == CON_DELETE || d->connected == CON_ROLL_STATS
            || d->connected == CON_EDITING))
              save_char_obj(d->character);
            d->outtop = 0;
            close_socket(d, FALSE);
          continue;
          }
        }
        /* check for input from the dns */
        if((d->connected == CON_PLAYING || d->character != NULL) && d->ifd != -1 && FD_ISSET(d->ifd, &in_set))
          process_dns(d);
        if(d->character && d->character->wait > 0)
        {
          --d->character->wait;
        continue;
        }
        read_from_buffer(d);
        if(d->incomm[0] != '\0')
        {
          d->fcommand = TRUE;
          if(d->character && !IS_AFFECTED(d->character, AFF_SPAMGUARD))
            stop_idling(d->character);
          strcpy(cmdline, d->incomm);
          d->incomm[0] = '\0';
          if(d->character)
            set_cur_char(d->character);
          if(d->pagepoint)
            set_pager_input(d, cmdline);
          else
            switch(d->connected)
            {
              default:
                nanny(d, cmdline);
              break;
              case CON_PLAYING:
                interpret(d->character, cmdline, FALSE);
              break;
              case CON_EDITING:
                edit_buffer(d->character, cmdline);
              break;
              d->character->cmd_recurse = 0;
            }
        }
      }
      if(d == last_descriptor)
        break;
    }
#ifdef I3
    I3_loop();
#endif
    /* Autonomous game motion */
    update_handler(FALSE);
    /* Output. */
    for(d = first_descriptor; d; d = d_next)
    {
      d_next = d->next;

      if((d->fcommand || d->outtop > 0) && FD_ISSET(d->descriptor, &out_set))
      {
        if(d->pagepoint)
        {
          if(!pager_output(d))
          {
            if(d->character && (d->connected == CON_PLAYING
            || d->connected == CON_DELETE || d->connected == CON_ROLL_STATS
            || d->connected == CON_EDITING))
              save_char_obj(d->character);
            d->outtop = 0;
            close_socket(d, FALSE);
          }
        }
        else if(!flush_buffer(d, TRUE))
        {
          if(d->character && (d->connected == CON_PLAYING || d->connected == CON_DELETE
          || d->connected == CON_ROLL_STATS || d->connected == CON_EDITING))
            save_char_obj(d->character);
          d->outtop = 0;
          close_socket(d, FALSE);
        }
      }
      if(d == last_descriptor)
        break;
    }
    /* Synchronize to a clock.
       Sleep(last_time + 1/PULSE_PER_SECOND - now).
       Careful here of signed versus unsigned arithmetic. */
    {
      struct timeval now_time;
      long secDelta;
      long usecDelta;

      gettimeofday(&now_time, NULL);
      usecDelta = ((int)last_time.tv_usec) - ((int)now_time.tv_usec) + 1000000 / PULSE_PER_SECOND;
      secDelta = ((int)last_time.tv_sec) - ((int)now_time.tv_sec);
      while(usecDelta < 0)
      {
        usecDelta += 1000000;
        secDelta -= 1;
      }
      while(usecDelta >= 1000000)
      {
        usecDelta -= 1000000;
        secDelta += 1;
      }
      if(secDelta > 0 || (secDelta == 0 && usecDelta > 0))
      {
        struct timeval stall_time;

        stall_time.tv_usec = usecDelta;
        stall_time.tv_sec = secDelta;
        if(select(0, NULL, NULL, NULL, &stall_time) < 0 && errno != EINTR)
        {
          perror("game_loop: select: stall";);
        exit(1);
        }
      }
    }
    gettimeofday(&last_time, NULL);
    current_time = (time_t)last_time.tv_sec;
    /* Check every 5 seconds...  (don't need it right now)
    if(last_check + 5 < current_time)
    {
      CHECK_LINKS(first_descriptor, last_descriptor, next, prev, DESCRIPTOR_DATA);
      last_check = current_time;
    }
    */
  }
#ifdef I3
  if(I3_socket > 0)
  I3_shutdown(0);
#endif
  fflush(stderr); /* make sure strerr is flushed */
return;
}




<!--EDIT|Remcon|Apr 9 2003, 07:17 AM-->
       
Pages:<< prev 1 next >>