/*
 * ----------------------------------------------------------------
 * Night Light IRC Proxy - Client Notice Functions
 * ----------------------------------------------------------------
 * Copyright (C) 1997-2007 Jonas Kvinge <jonas@night-light.net>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Last modified by:
 * Jonas Kvinge (15.11.2006)
 *
 */

#define CLIENT_C

#define NEED_SYS_TYPES_H 1		/* Extra types */
#define NEED_SYS_PARAM_H 1		/* Some systems need this */
#define NEED_LIMITS_H 0			/* Kernel limits */
#define NEED_STDARG_H 1			/* va_list, etc */
#define NEED_ERRNO_H 1			/* errno */
#define NEED_CTYPE_H 0			/* isdigit(), etc */
#define NEED_NETINET_IN_H 1		/* in_addr, sockaddr_in, etc */
#define NEED_ARPA_INET_H 1		/* inet_ntoa(), inet_aton(), etc */
#define NEED_STDIO_H 1			/* Standard C UNIX functions */
#define NEED_STDLIB_H 1			/* malloc(), exit(), atoi(), etc */
#define NEED_TIME_H 1			/* time(), etc */
#define NEED_SYSCTL_H 0			/* sysctl(), etc */
#define NEED_SYS_STAT_H 0		/* chmod(), mkdir(), etc */
#define NEED_SYS_UIO_H 0		/* iovec, etc */
#define NEED_FCNTL_H 1			/* open(), creat(), fcntl(), etc */
#define NEED_SYS_IOCTL_H 0		/* ioctl(), etc */
#define NEED_SYS_FILIO_H 0		/* Solaris need this for ioctl(), etc */
#define NEED_UNISTD_H 1			/* Unix standard functions */
#define NEED_STRING_H 1			/* C string functions */
#define NEED_SIGNAL_H 0			/* Signal functions */
#define NEED_SYS_SOCKET_H 1		/* Socket functions */
#define NEED_NETDB_H 1			/* Network database functions */
#define NEED_ARPA_NAMESER_H 0		/* Nameserver definitions */
#define NEED_GETUSERPW_HEADERS 0 	/* Functions to retrive system passwords */
#define NEED_ARES 0			/* Functions needed for ares */
#define NEED_SSL 1			/* Needed for SSL support */

#include "includes.h"
#include "irc.h"

#include "listen.h"

#include "client.h"
#include "client_connection.h"

#include "conn.h"

/* VARIABLES - JONAS (31.07.2001) */

extern struct Client_Struct *Client_Head;

/* CLIENT_NOTICE FUNCTION - JONAS (01.07.2000) */

void client_notice(struct Client_Struct *ClientS, const char *const LinePT, ...) {

  char Line[IRCNOTICELEN+1] = "";
  va_list Args = { 0 };

  assert(LinePT != NULL);

  va_start(Args, LinePT);
  vsnprintf(Line, IRCNOTICELEN+1, LinePT, Args);
  va_end(Args);

  if (!Client_IsSentError(ClientS)) { client_addsend(ClientS, ":%s NOTICE %s :%s", IRCP_USER_HOST(ClientS), IRCP_USER_NICK(ClientS), Line); }

}

/* CLIENT_NOTICEALLUSER FUNCTION - JONAS (01.07.2000) */

void client_noticealluser(const char *UserPT, const char *const LinePT, ...) {

  char Line[IRCNOTICELEN+1] = "";
  va_list Args = { 0 };
  struct Client_Struct *ClientS = NULL;

  assert(LinePT != NULL);

  va_start(Args, LinePT);
  vsnprintf(Line, IRCNOTICELEN+1, LinePT, Args);
  va_end(Args);

  DEBUGPRINT(BITMASK_DEBUG_CLIENT, "%s", Line);

  for (ClientS = Client_Head ; ClientS != NULL ; ClientS = ClientS->Next) {
    if ((Client_IsVerified(ClientS)) && (!Client_IsSentError(ClientS)) && (strcmp(ClientS->User, UserPT) == FALSE)) { client_addsend(ClientS, ":%s NOTICE %s :%s", IRCP_USER_HOST(ClientS), IRCP_USER_NICK(ClientS), Line); }
  }

}

/* CLIENT_NOTICEALLBUTONE FUNCTION - JONAS (01.07.2000) */

void client_noticeallbutone(struct Client_Struct *ClientO, const char *const LinePT, ...) {

  char Line[IRCNOTICELEN+1] = "";
  va_list Args = { 0 };
  struct Client_Struct *UserL = NULL;

  assert(LinePT != NULL);

  va_start(Args, LinePT);
  vsnprintf(Line, IRCNOTICELEN+1, LinePT, Args);
  va_end(Args);

  DEBUGPRINT(BITMASK_DEBUG_CLIENT, "%s", Line);

  for (UserL = Client_Head ; UserL != NULL ; UserL = UserL->Next) {
    if ((UserL != ClientO) && (Client_IsVerified(UserL)) && (!Client_IsSentError(UserL)) && (strcmp(UserL->User, ClientO->User) == FALSE)) { client_addsend(UserL, ":%s NOTICE %s :%s", IRCP_USER_HOST(ClientO), IRCP_USER_NICK(ClientO), Line); }
  }

}

/* CLIENT_NOTICEALL FUNCTION - JONAS (01.07.2000) */

void client_noticeall(const char *const LinePT, ...) {

  char Line[IRCNOTICELEN+1] = "";
  va_list Args = { 0 };
  struct Client_Struct *ClientS = NULL;

  assert(LinePT != NULL);

  va_start(Args, LinePT);
  vsnprintf(Line, IRCNOTICELEN+1, LinePT, Args);
  va_end(Args);

  for (ClientS = Client_Head ; ClientS != NULL ; ClientS = ClientS->Next) {
    if ((Client_IsVerified(ClientS)) && (!Client_IsSentError(ClientS))) { client_addsend(ClientS, ":%s NOTICE %s :%s", IRCP_USER_HOST(ClientS), IRCP_USER_NICK(ClientS), Line); }
  }

}


syntax highlighted by Code2HTML, v. 0.9.1