Beispiel #1
0
struct Luser *
			AddClient(char **line)

{
	char *ch;
	struct Luser *tempuser,
				*newptr;

#ifdef BLOCK_ALLOCATION

	tempuser = (struct Luser *) BlockSubAllocate(ClientHeap);
	if (!tempuser) /* shouldn't happen - but I'm paranoid :) */
		return (NULL);

	memset(tempuser, 0, sizeof(struct Luser));

	strlcpy(tempuser->nick, line[1], NICKLEN + 1);
	strlcpy(tempuser->username, line[5], USERLEN + 1);
	strlcpy(tempuser->hostname, line[6], HOSTLEN + 1);
	strlcpy(tempuser->realname, line[8] + 1, REALLEN + 1);

#else

	tempuser = (struct Luser *) MyMalloc(sizeof(struct Luser));
	memset(tempuser, 0, sizeof(struct Luser));

	tempuser->nick = MyStrdup(line[1]);
	tempuser->username = MyStrdup(line[5]);
	tempuser->hostname = MyStrdup(line[6]);
	tempuser->realname = MyStrdup(line[8] + 1);

#endif /* BLOCK_ALLOCATION */

	tempuser->since = atol(line[3]);

#ifdef NICKSERVICES

	tempuser->nick_ts = tempuser->since;

#if defined SVSNICK || defined FORCENICK
	tempuser->flags &= ~(UMODE_NOFORCENICK);
#endif

#endif /* NICKSERVICES */

	if ((tempuser->server = FindServer(line[7])))
{
		tempuser->server->numusers++;

#ifdef STATSERVICES

		if (tempuser->server->numusers > tempuser->server->maxusers)
		{
			tempuser->server->maxusers = tempuser->server->numusers;
			tempuser->server->maxusers_ts = current_ts;
		}
#endif

	}

	ch = &line[4][1];
	while (*ch)
	{
		switch (*ch)
		{
		case 'i':
		case 'I':
			{
				tempuser->umodes |= UMODE_I;
				break;
			}
		case 's':
		case 'S':
			{
				tempuser->umodes |= UMODE_S;
				break;
			}
		case 'w':
		case 'W':
			{
				tempuser->umodes |= UMODE_W;
				break;
			}
		case 'o':
		case 'O':
			{
				tempuser->umodes |= UMODE_O;

				Network->TotalOperators++;

#ifdef STATSERVICES

				if (Network->TotalOperators > Network->MaxOperators)
				{
					Network->MaxOperators = Network->TotalOperators;
					Network->MaxOperators_ts = current_ts;

					if ((Network->MaxOperators % 5) == 0)
					{
						/* inform +y people of new max oper count */
						SendUmode(OPERUMODE_Y,
						          "*** New Max Operator Count: %ld",
						          Network->MaxOperators);
						putlog(LOG2, "New Max Operator Count: %ld",
								Network->MaxOperators);
					}
				}
				if (Network->TotalOperators > Network->MaxOperatorsT)
				{
					Network->MaxOperatorsT = Network->TotalOperators;
					Network->MaxOperatorsT_ts = current_ts;
				}
#endif

				if (tempuser->server)
				{
					tempuser->server->numopers++;

#ifdef STATSERVICES

					if (tempuser->server->numopers > tempuser->server->maxopers)
					{
						tempuser->server->maxopers = tempuser->server->numopers;
						tempuser->server->maxopers_ts = current_ts;
					}
#endif

				}
				break;
			} /* case 'O' */
#ifdef DANCER
		case 'e':
		case 'E':
			{
				struct NickInfo *realptr;
				realptr = FindNick(tempuser->nick);
				if (realptr)
				{
					realptr->flags |= NS_IDENTIFIED;
					tempuser->umodes |= UMODE_E;
					RecordCommand("User %s has +e umode, marking as identified",
					              tempuser->nick);
				}
				else
				{
					/* Is it one of mine? */
					int mine = 0;
					struct aService *sptr;
					for (sptr = ServiceBots; sptr->name; ++sptr)
						if (!irccmp(tempuser->nick, *(sptr->name)))
						{
							mine = 1;
							break;
						}
					if (!mine)
					{
						/* Blech, who is screwing with us? */
						toserv(":%s MODE %s -e\r\n", Me.name, tempuser->nick);
						RecordCommand("User %s has +e umode but is not known to me, setting -e",
						              tempuser->nick);
					}
				}
				break;
			}
#endif /* DANCER */
		default:
			break;
		} /* switch (*ch) */
		ch++;
	}

	tempuser->next = ClientList;
	tempuser->prev = NULL;
	if (tempuser->next)
		tempuser->next->prev = tempuser;
	ClientList = tempuser;

	/* add client to the hash table */
	newptr = HashAddClient(ClientList, 0);

	Network->TotalUsers++;
#ifdef STATSERVICES

	if (Network->TotalUsers > Network->MaxUsers)
	{
		Network->MaxUsers = Network->TotalUsers;
		Network->MaxUsers_ts = current_ts;

		if ((Network->MaxUsers % 10) == 0)
		{
			/* notify +y people of new max user count */
			SendUmode(OPERUMODE_Y,
			          "*** New Max Client Count: %ld",
			          Network->MaxUsers);
			putlog(LOG2, "New Max Client Count: %ld",
					Network->MaxUsers);
		}
	}
	if (Network->TotalUsers > Network->MaxUsersT)
	{
		Network->MaxUsersT = Network->TotalUsers;
		Network->MaxUsersT_ts = current_ts;
	}
#endif /* STATSERVICES */

#ifdef ALLOW_GLINES
	/*
	 * It's possible the client won't exist anymore, because if the user
	 * is a clone and AutoKillClones is enabled, HashAddClient() would
	 * have already killed the user, in which case newptr will be
	 * NULL - CheckGlined() checks for null pointers
	 */
	CheckGlined(newptr); /* Check if new user is glined */
#endif

	return (tempuser);
} /* AddClient() */
struct Channel *
AddChannel(char **line, int nickcnt, char **nicks)

{
  char *names;
  char **anames;
  char *currnick;
  char modes[MAXLINE];
  struct Channel *chname, *cptr;
  struct Channel *tempchan;
  int ii, ncnt, acnt;

  ncnt = 5; /* default position for channel nicks, if no limit/key */
  strcpy(modes, line[4]);
  while (line[ncnt][0] != ':')
    {
      strcat(modes, " ");
      strcat(modes, line[ncnt]);
      ncnt++;
    }

  if (nickcnt > 0)
  {
    acnt = nickcnt;
    anames = nicks;
  }
  else
  {
    names = line[ncnt];
    names++; /* point past the leading : */

    ii = strlen(names);

    /* kill the \n char on the end */
    if (IsSpace(names[ii - 2]))
      names[ii - 2] = '\0';
    else if (IsSpace(names[ii - 1]))
      names[ii - 1] = '\0';

    acnt = SplitBuf(names, &anames);
  }

  if (!(cptr = FindChannel(line[3])))
  {
  #ifdef BLOCK_ALLOCATION

    tempchan = (struct Channel *) BlockSubAllocate(ChannelHeap);
    memset(tempchan, 0, sizeof(struct Channel));
    strncpy(tempchan->name, line[3], CHANNELLEN);

  #else

    tempchan = (struct Channel *) MyMalloc(sizeof(struct Channel));
    memset(tempchan, 0, sizeof(struct Channel));
    tempchan->name = MyStrdup(line[3]);

  #endif /* BLOCK_ALLOCATION */

    tempchan->since = atol(line[2]);
    tempchan->numusers = acnt;

    tempchan->next = ChannelList;
    tempchan->prev = NULL;
    if (tempchan->next)
      tempchan->next->prev = tempchan;

    HashAddChan(tempchan);

    ChannelList = tempchan;
    chname = ChannelList;

    ++Network->TotalChannels;
  #ifdef STATSERVICES
    if (Network->TotalChannels > Network->MaxChannels)
    {
      Network->MaxChannels = Network->TotalChannels;
      Network->MaxChannels_ts = current_ts;

      if ((Network->MaxChannels % 10) == 0)
      {
        /* notify +y people about new max channel count */
        SendUmode(OPERUMODE_Y,
          "*** New Max Channel Count: %ld",
          Network->MaxChannels);
      }
    }
    if (Network->TotalChannels > Network->MaxChannelsT)
    {
      Network->MaxChannelsT = Network->TotalChannels;
      Network->MaxChannelsT_ts = current_ts;
    }
  #endif /* STATSERVICES */
  }
  else /* it's an existing channel, but someone has joined it */
  {
    cptr->numusers += acnt;
    chname = cptr;
  }

  /* Add the channel to each nick's channel list */
  for (ii = 0; ii < acnt; ii++)
  {
    currnick = GetNick(anames[ii]);
    if (!currnick)
      continue;

    if (!IsChannelMember(chname, FindClient(currnick)))
    {
      /*
       * Use anames[ii] instead of currnick here so we get
       * the @/+ flags
       */
      AddToChannel(chname, anames[ii]);
    }
    else
      chname->numusers--;
  }
  
  /* finally, add the modes for the channel */
  UpdateChanModes(0, line[0] + 1, chname, modes);

  /*
   * Only free anames[] if there was no nick list
   * given
   */
  if (!nickcnt)
    MyFree(anames);

  return (chname);
} /* AddChannel() */