Exemple #1
0
Fichier : vote.c Projet : deurk/ktx
void vote_check_elect ()
{
	gedict_t *p;

	if( !get_votes_req( OV_ELECT, true ) ) {

		for( p = world; (p = find_client( p )); )
			if ( p->v.elect_type != etNone )
				break;

		if ( !p ) { // nor admin nor captain found - probably bug
			AbortElect();
			return;
		}

		if( !(p->ct == ctSpec && match_in_progress) )
		if( is_elected(p, etAdmin) ) // s: election was admin election
			BecomeAdmin(p, AF_ADMIN);

		if( !match_in_progress )
		if( is_elected(p, etCaptain) ) // s: election was captain election
			BecomeCaptain(p);

		AbortElect();
		return;
	}
}
Exemple #2
0
DLLFUNC int m_rawto(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	aClient *acptr = NULL;
	if (!IsULine(sptr))
	{
		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
		return -1;
	}
	if (parc < 3)
	{
		sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS),
		    me.name, parv[0], "RAWTO");
		return -1;
	}
	if ((acptr = find_client(parv[1], NULL)))
	{
		if (MyConnect(acptr))
		{
			sendto_one(acptr, "%s", parv[2]);
			return 0;
		}		
		else
		{
			sendto_one(acptr, ":%s %s %s :%s",
				parv[0], IsToken(acptr->from) ? TOK_RAWTO : MSG_RAWTO,
					parv[1], parv[2]);
			return 0;
		}
	}
	return 0;
}
Exemple #3
0
/** Focused
 */
static
void handle_focus_in(xcb_focus_in_event_t *e) {
    struct client_t *c;
    struct workspace_t *ws;

    NIL_LOG("event: focus in win=%d", e->event);
    if (e->mode == XCB_NOTIFY_MODE_GRAB || e->mode == XCB_NOTIFY_MODE_UNGRAB
        || e->detail == XCB_NOTIFY_DETAIL_POINTER) {
        /* ignore event for grap/ungrap or detail is pointer */
        return;
    }
    c = find_client(e->event, &ws);
    if (!c) {
        NIL_ERR("no client %d", e->event);
        return;
    }
    if (c == ws->focus) {
        return;
    }
    if (ws->focus) {
        blur_client(ws->focus);
    }
    focus_client(c);
    ws->focus = c;
    xcb_flush(nil_.con);
}
Exemple #4
0
/** Handler for changing position, size
 */
static
void handle_configure_notify(xcb_configure_notify_event_t *e) {
    struct client_t *c;

    NIL_LOG("event: configure notify evt=%d win=%d abv=%d @ %d,%d %ux%u",
        e->event, e->window, e->above_sibling, e->x, e->y, e->width, e->height);

    /* only recreate root background picture */
    if (e->window == nil_.scr->root) {
        return;
    }
#if 0
    c = find_client(e->window);
    if (!c) {
        NIL_ERR("no client %d", e->window);
        return;
    }
    /* update client's geometry */
    c->x = e->x;
    c->y = e->y;
    /* invalidate pixmap if resized */
    if (c->w != e->width || c->h != e->height
        || c->border_width != e->border_width) {
    }
    c->w = e->width;
    c->h = e->height;
    c->border_width = e->border_width;
    /* restack */
#else
    (void)c;
#endif
}
Exemple #5
0
static void
mo_chgident(struct Client *client_p, struct Client *source_p,
            int parc, char *parv[])
{
  struct Client *target_p = NULL;

  if (MyClient(source_p) && !IsOperAdmin(source_p))
  {
    sendto_one(source_p, form_str(ERR_NOPRIVS),
               me.name, source_p->name, "CHGIDENT");
    return;
  }

  if (EmptyString(parv[2]))
  {
    parv[2] = parv[1];
    target_p = source_p;

    if (!IsClient(target_p))
      return;
  }
  else {
    target_p = find_client(parv[1]);

    if (target_p == NULL || !IsClient(target_p))
    {
      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
                 me.name, source_p->name, parv[1]);
      return;
    }
  }

  if (strlen(parv[2]) > USERLEN || !*parv[2] || !valid_username(parv[2]))
  {
    sendto_one(source_p, ":%s NOTICE %s :Invalid username",
               me.name, source_p->name);
    return;
  }

  if (IsUserHostIp(target_p))
    delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));

  strlcpy(target_p->username, parv[2], sizeof(target_p->username));

  add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
  SetUserHost(target_p);

  if (MyClient(source_p))
  {
    sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGIDENT %s %s",
                  source_p->name, target_p->name, parv[2]);
    sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
               me.name, source_p->name, target_p->name, target_p->username,
               target_p->host);
  }

  if (MyConnect(target_p) && IsClient(source_p))
    sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s",
               me.name, target_p->name, target_p->username, target_p->host);
}
Exemple #6
0
Fichier : vote.c Projet : deurk/ktx
void vote_clear( int fofs )
{
	gedict_t *p;

	for ( p = world; (p = find_client( p )); )
		*(int*)((byte*)(&p->v)+fofs) = 0;
}
Exemple #7
0
/*
** m_svsguest()
**   parv[0] = sender
**   parv[1] = target nick
**   parv[2] = guest prefix
**   parv[3] = max guest number (9999)
**
*/
int m_svsguest(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  int randnum;
  int maxnum;
  int scount;	/* search count */
  char guestnick[NICKLEN];
  struct Client* acptr;

  /* Check if received from services */
  if(!IsServer(cptr) || !IsService(sptr)) 
    {	
      if (IsServer(cptr))
        { 
	  ts_warn("Got SVSGUEST from non-service: %s", 
	    sptr->name);
	  sendto_one(cptr, ":%s WALLOPS :ignoring SVSGUEST from non-service %s",
	    me.name, sptr->name);
	}
      return 0;
    }

  if( parc < 4 ) /* Check for arguments count */
    {	  
      ts_warn("Invalid SVSGUEST (%s) from %s",
	(parc==2 ) ? parv[1]: "-", parv[0]);
      return 0;
    }
  
  
  
  if ((acptr = find_person(parv[1], NULL)) && MyClient(acptr)) /* person found connected here */
    {
      maxnum = atoi(parv[3]);
      randnum = 1+ (random() % (maxnum+1));
      snprintf(guestnick, NICKLEN, "%s%d", parv[2], randnum);
      scount = 0;
                                                                                
      while((scount++<maxnum+1) && 
        find_client(guestnick, (aClient *)NULL))
        {
          randnum = 1+ (random() % (maxnum+1));
          snprintf(guestnick, NICKLEN, "%s%d", parv[2], randnum);
        }
	
      if(scount<maxnum+1) /* check if we reached max guests count */
        {
           change_nick(acptr, guestnick);
	} 
	else
	  exit_client(acptr, acptr, &me, "Maximum guests count reached!!!");
    }
  else if (acptr) /* nick was found but is not our client */	
    {
      if ( (acptr->from != cptr)) /* this should never happen */
        sendto_one(acptr, 
	  ":%s SVSGUEST %s %s %s", parv[0], parv[1], parv[2], parv[3]);	  
    }
  return 0;
}
Exemple #8
0
int handle_requests()
{
    struct sockaddr_in remote;
    struct pollfd pfds[MAX_CLIENTS];
    int cli_fd, i, n;
    
    size_t len = sizeof(remote);

// akceptujemy przychodzace polaczenia i dodajemy nowych klientow do tablicy
    while ((cli_fd = accept(sock_fd, (struct sockaddr *)&remote, &len))>0)
	if( add_client(cli_fd) < 0) 
	{
	    close(cli_fd);
	    return 0;
	}


// przygotowujemy liste deskryptorow dla poll()-a
    for(n=i=0;i < MAX_CLIENTS;i++)
	if(client_tab[i].fd)
	{    
	    pfds[n].fd = client_tab[i].fd;
	    pfds[n].events = POLLIN | POLLHUP; // reagujemy na przychodzace dane i zerwanie sesji
	    pfds[n].revents = 0;

	    n++;
	}    

    int ret;

// pollujemy klientow    
    if(( ret = poll(pfds, n, 10)) < 0) die("poll error: %s", strerror(errno));

// brak ruchu - koniec pracy funkcji
    if(!ret)  return 0; 

// sprawdzamy, co sie wydarzylo:
    for(i=0; i<n ;i++)
    {
	if(pfds[i].revents & POLLHUP)					// klient zerwal polaczenie?
	{
	    fprintf(stderr, "[lsrv] client %d closed connection.\n", pfds[i].fd);
	    close(pfds[i].fd);
	    remove_client(pfds[i].fd);
	} else if(pfds[i].revents & POLLIN)				// nadeszly dane od klienta?
	{
	    if(handle_client(find_client(pfds[i].fd)) < 0)
	    {
	        close(pfds[i].fd);
		remove_client(pfds[i].fd);
    	    }
	}  	
    }
    
    return 0;    

}
Exemple #9
0
int virtual_stream_disconnect(Channel * c, char * token, char * id) {
    int err = 0;
    StreamClient * client = find_client(id, c);

    if (client == NULL) err = errno;
    if (!err) delete_client(client);

    return err == 0 ? 0 : -1;
}
Exemple #10
0
int
m_quit(user_t *cptr, int parc, char **parv)
{
	user_t *user = find_client(parv[0]);

	if (user)
		del_user(user);
	return 1;
}
Exemple #11
0
/*
** m_pong
**      parv[0] = sender prefix
**      parv[1] = origin
**      parv[2] = destination
*/
int     m_pong(struct Client *cptr,
               struct Client *sptr,
               int parc,
               char *parv[])
{
  struct Client *acptr = NULL;
  char  *origin, *destination;

  if (parc < 2 || *parv[1] == '\0')
    {
      sendto_one(sptr, form_str(ERR_NOORIGIN), me.name, parv[0]);
      return 0;
    }

  origin = parv[1];
  destination = parv[2];

  /* Now attempt to route the PONG, comstud pointed out routable PING
   * is used for SPING.  routable PING should also probably be left in
   *        -Dianora
   * That being the case, we will route, but only for registered clients (a
   * case can be made to allow them only from servers). -Shadowfax
   */
  if (!EmptyString(destination) && irccmp(destination, me.name) != 0
                && IsRegistered(sptr))
    {
      if ((acptr = find_client(destination, NULL)) ||
          (acptr = find_server(destination)))
        sendto_one(acptr,":%s PONG %s %s",
                   parv[0], origin, destination);
      else
        {
          sendto_one(sptr, form_str(ERR_NOSUCHSERVER),
                     me.name, parv[0], destination);
          return 0;
        }
    }
  else
    {
      if (MyConnect(sptr))
      {
        sptr->flags &= ~FLAGS_PINGSENT;
#ifdef NEED_SPLITCODE
#ifdef SPLIT_PONG
        if (IsServer(sptr))
          got_server_pong = 1;
#endif
#endif
      }
#ifdef  DEBUGMODE
      Debug((DEBUG_NOTICE, "PONG: %s %s", origin,
           destination ? destination : "*"));
#endif
    }
  return 0;
}
Exemple #12
0
void
add_linked_server(char *hub, char *leaf, char *comment)
{
	user_t *server, *uplink;

	if ((server = find_client(leaf)))
		del_server(server);

	if (!(uplink = find_client(hub)) && !is_me(leaf))
		return;

	server = add_user_to_list();
	server->nick = leetstrdup(leaf);
	server->realname = leetstrdup(comment);
	server->server = uplink ? uplink : server;
	server->ts = time(NULL);
	server->privs = SERVER;
	me.servers++;
}
Exemple #13
0
/*
 * find_person - find person by (nick)name.
 * inputs	- pointer to name
 * output	- return client pointer
 * side effects -
 */
struct Client *find_person(char *name)
{
  struct Client       *c2ptr;

  c2ptr = find_client(name);

  if (c2ptr && IsPerson(c2ptr))
    return (c2ptr);
  return (NULL);
}
Exemple #14
0
int get_votes( int fofs )
{
	int votes = 0;
	gedict_t *p;

	for ( p = world; (p = find_client( p )); )
		if ( *(int*)((byte*)(&p->v)+fofs) )
			votes++;

	return votes;
}
Exemple #15
0
int virtual_stream_connect(Channel * c, char * token, char * id) {
    int err = 0;

    if (find_client(id, c) == NULL) {
        VirtualStream * stream = virtual_stream_find(id);
        if (stream == NULL) err = errno;
        else create_client(stream, c);
    }

    return err == 0 ? 0 : -1;
}
Exemple #16
0
int is_admins_vote( int fofs )
{
	int votes = 0;
	gedict_t *p;

	for ( p = world; (p = find_client( p )); )
		if ( *(int*)((byte*)(&p->v)+fofs) && is_adm( p ) )
			votes++;

	return votes;
}
Exemple #17
0
int get_votes_by_value( int fofs, int value )
{
	int votes = 0;
	gedict_t *p;

	for ( p = world; (p = find_client( p )); )
		if ( *((int*)(&(p->v)+fofs)) == value )
			votes++;

	return votes;
}
Exemple #18
0
void register_client(int pos, pid_t pid)
{
    struct chain_socket *cs;
    
    if(!(cs = find_client(&pos, 0)))
        return;
    
    cs->pid = pid;
    
    DEBUG(printf("Client registered [%i] %i\n", cs->sock, pid));
}
Exemple #19
0
client_t *get_focus_client(void)
{
    xcb_get_input_focus_cookie_t c = xcb_get_input_focus(wm_conf.connection);
    xcb_get_input_focus_reply_t *r = xcb_get_input_focus_reply(wm_conf.connection, c, NULL);
    client_t *focus_client = NULL;
    if (r) {
        focus_client = find_client(r->focus);
        free(r);
    }
    return focus_client;
}
Exemple #20
0
/* Examine the client and work out which arch it is for */
static const char *select_arch(
      const char *clientname, cpu_type_t default_cputype,
      const char *default_arch)
{
   uint8_t buf[4096];
   ssize_t bytes;
   int fd = open(find_client(clientname), O_RDONLY);
   if (fd < 0) {
      barf("%s: %s", clientname, strerror(errno));
   }

   bytes = read(fd, buf, sizeof(buf));
   close(fd);
   if (bytes != sizeof(buf)) {
      return NULL;
   }
   
   // If it's thin, return that arch.
   {
      struct mach_header *mh = (struct mach_header *)buf;
      if (mh->magic == MH_MAGIC  ||  mh->magic == MH_MAGIC_64) {
         return name_for_cputype(mh->cputype);
      } else if (mh->magic == MH_CIGAM  ||  mh->magic == MH_CIGAM_64) {
         return name_for_cputype(OSSwapInt32(mh->cputype));
      }
   }

   // If it's fat, look for a good arch.
   {
      struct fat_header *fh = (struct fat_header *)buf;
      if (ntohl(fh->magic) == FAT_MAGIC) {
         uint32_t nfat_arch = ntohl(fh->nfat_arch);
         int i;
         // If only one fat arch, use it.
         if (nfat_arch == 1) {
            struct fat_arch *fa = (struct fat_arch *)(fh+1);
            return name_for_cputype(ntohl(fa->cputype));
         }
         // Scan fat headers for default arch.
         if (fat_has_cputype(fh, default_cputype)) {
            return default_arch;
         }
         
         // Scan fat headers for any supported arch.
         for (i = 0; i < valid_archs_count; i++) {
            if (fat_has_cputype(fh, valid_archs[i].cputype)) {
               return valid_archs[i].valgrind_name;
            }
         }
      }
   }
   
   return NULL;
}
/*
** m_pong
**	parv[0] = sender prefix
**	parv[1] = origin
**	parv[2] = destination
*/
DLLFUNC int m_pong(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	aClient *acptr;
	char *origin, *destination;

#ifdef NOSPOOF
	if (!IsRegistered(cptr))
		return m_nospoof(cptr, sptr, parc, parv);
#endif

	if (parc < 2 || *parv[1] == '\0')
	{
		sendto_one(sptr, err_str(ERR_NOORIGIN), me.name, parv[0]);
		return 0;
	}

	origin = parv[1];
	destination = parv[2];
	cptr->flags &= ~FLAGS_PINGSENT;
	sptr->flags &= ~FLAGS_PINGSENT;

	/* Remote pongs for clients? uhh... */
	if (MyClient(sptr) || !IsRegistered(sptr))
		destination = NULL;

	if (!BadPtr(destination) && mycmp(destination, me.name) != 0)
	{
		if ((acptr = find_client(destination, NULL)) ||
		    (acptr = find_server_quick(destination)))
		{
			if (!IsServer(cptr) && !IsServer(acptr))
			{
				sendto_one(sptr, err_str(ERR_NOSUCHSERVER),
				    me.name, parv[0], destination);
				return 0;
			}
			else
				sendto_one(acptr, ":%s PONG %s %s",
				    parv[0], origin, destination);
		}
		else
		{
			sendto_one(sptr, err_str(ERR_NOSUCHSERVER),
			    me.name, parv[0], destination);
			return 0;
		}
	}
#ifdef	DEBUGMODE
	else
		Debug((DEBUG_NOTICE, "PONG: %s %s", origin,
		    destination ? destination : "*"));
#endif
	return 0;
}
Exemple #22
0
static
void handle_unmap_notify(xcb_unmap_notify_event_t *e) {
    struct client_t *c;

    NIL_LOG("event: unmap notify %d", e->window);
    c = find_client(e->window, 0);
    if (!c) {
        NIL_ERR("no client %d", e->window);
        return;
    }
    NIL_CLEAR_FLAG(c->flags, CLIENT_MAPPED);
}
Exemple #23
0
static int
mo_forcepart(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
	struct Client *target_p;
	struct Channel *chptr;
	struct membership *msptr;

	if(!IsOperAdmin(source_p))
	{
		sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "forcepart");
		return 0;
	}

	if((hunt_server(client_p, source_p, ":%s FORCEPART %s %s", 1, parc, parv)) != HUNTED_ISME)
		return 0;

	/* if target_p == NULL then let the oper know */
	if((target_p = find_client(parv[1])) == NULL)
	{
		sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]);
		return 0;
	}

	if(!IsClient(target_p))
		return 0;


	if((chptr = find_channel(parv[2])) == NULL)
	{
		sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
				   form_str(ERR_NOSUCHCHANNEL), parv[1]);
		return 0;
	}

	if((msptr = find_channel_membership(chptr, target_p)) == NULL)
	{
		sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
			   me.name, source_p->name, parv[1], parv[2]);
		return 0;
	}

	sendto_server(target_p, chptr, NOCAPS, NOCAPS,
		      ":%s PART %s :%s", target_p->name, chptr->chname, target_p->name);

	sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
			     target_p->name, target_p->username,
			     target_p->host, chptr->chname, target_p->name);


	remove_user_from_channel(msptr);

	return 0;
}
Exemple #24
0
/**
 * do_main - The main loop.
 *
 * @fd: Receiver socket's file descriptor.
 *
 * Returns nothing.
 */
static void do_main(const int fd)
{
	static char buf[65536];
	struct sockaddr_in addr;
	while (1) {
		struct pollfd pfd = { fd, POLLIN, 0 };
		socklen_t size = sizeof(addr);
		int i;
		time_t now;
		/* Don't wait forever if checking for timeout. */
		for (i = 0; i < num_clients; i++)
			if (clients[i].avail)
				break;
		/* Flush log file and wait for data. */
		// fflush(log_fp);
		poll(&pfd, 1, i < num_clients ? 1000 : -1);
		now = time(NULL);
		/* Check for timeout. */
		for (i = 0; i < num_clients; i++)
			if (clients[i].avail &&
			    now - clients[i].stamp >= wait_timeout)
				write_logfile(&clients[i], 1);
		/* Don't receive forever in order to check for timeout. */
		while (now == time(NULL)) {
			struct client *ptr;
			char *tmp;
			int len = recvfrom(fd, buf, sizeof(buf), MSG_DONTWAIT,
					   (struct sockaddr *) &addr, &size);
			if (len <= 0 || size != sizeof(addr))
				break;
			ptr = find_client(&addr);
			if (!ptr)
				continue;
			/* Save current time if receiving the first byte. */
			if (!ptr->avail)
				ptr->stamp = now;
			/* Append data to the line. */
			tmp = realloc(ptr->buffer, round_up(ptr->avail + len));
			if (!tmp)
				flush_all_and_abort();
			memmove(tmp + ptr->avail, buf, len);
			ptr->avail += len;
			ptr->buffer = tmp;
			/* Write if at least one line completed. */
			if (memchr(buf, '\n', len))
				write_logfile(ptr, 0);
			/* Write if the line is too long. */
			if (ptr->avail >= wbuf_size)
				write_logfile(ptr, 1);
		}
		drop_memory_usage();
	}
}
Exemple #25
0
/* read client statistics data and update the context
 */
int
tpstat_read( struct server_ctx* ctx )
{
    int cindex = -1;
    int readfd = -1;
    ssize_t nread = 0;
    struct tput_stat ts;
    struct client_ctx* client = NULL;

    assert( ctx );

    readfd = ctx->cpipe[0];
    assert( readfd > 0 );

    (void)memset( &ts, 0, sizeof(ts) );

    nread = read( readfd, &ts, sizeof(ts) );
    if( nread <= 0 ) {
        if( (EINTR != errno) && (EAGAIN != errno) ) {
            mperror( g_flog, errno, "%s: read", __func__ );
            return ERR_INTERNAL;
        }
        /* if it's an interrupt or no data available - ignore */
        TRACE( (void)tmfprintf( g_flog, "%s - read error [%s] - ingored\n",
                        __func__, strerror(errno)) );
        return 0;
    }
    if( sizeof(ts) != (size_t)nread ) {
        (void)tmfprintf( g_flog, "%s - read [%d] bytes from pipe, expected [%u]\n",
                __func__, nread, (int)sizeof(ts) );
        return ERR_INTERNAL;
    }

    TRACE( (void)tmfprintf( g_flog,
            "Received TSTAT={ sender=[%ld], bytes=[%f], seconds=[%f] }\n",
            (long)ts.sender_id, ts.nbytes, ts.nsec) );

    cindex = find_client( ctx, (pid_t)ts.sender_id );
    if( -1 == cindex ) {
        (void)tmfprintf( g_flog, "%s - cannot find client [%ld]\n",
                __func__, (long)ts.sender_id );
        /* ignore invalid client id's */
        return 0;
    }

    client = &(ctx->cl[ cindex ]);
    client->tstat = ts;

    TRACE( (void)tmfprintf( g_flog, "Updated context for pid=[%d]; "
                "[%.1f] Kb/sec\n", client->pid, (ts.nbytes / 1024) / ts.nsec  ) );
    return 0;
}
Exemple #26
0
void hide_client(int pos, pid_t pid, int priority, int hide)
{
    struct chain_socket *cs;
    
    if(!(cs = find_client(&pos, pid)))
        return;
    
    cs->priority = priority;
    cs->hide = hide;
    
    DEBUG(printf("Client set %s (%i) [%i] %i\n",
        hide ? "invisible" : "visible", priority, cs->sock, cs->pid));
}
Exemple #27
0
int
m_kill(user_t *cptr, int parc, char **parv)
{
	user_t *user = find_client(parv[1]);

	if (user)
		del_user(user);
	if (is_services_client(parv[1]) > 0) {
		me.opers--;
		intro_nicks(is_services_client(parv[1]));
	}
	return 1;
}
Exemple #28
0
int
m_squit(user_t *cptr, int parc, char **parv)
{
	user_t *sptr = find_client(strnull(parv[1]));
	if (sptr)
	switch (me.servtype) {
		case SERV_IRCNN:
			return del_server(sptr);
		case SERV_HYBRD:
			return del_server(sptr);
	}
	return 1;
}
Exemple #29
0
static void
mo_chgname(struct Client *client_p, struct Client *source_p,
          int parc, char *parv[])
{
  struct Client *target_p = NULL;

  if (MyClient(source_p) && !IsOperAdmin(source_p))
  {
    sendto_one(source_p, form_str(ERR_NOPRIVS),
               me.name, source_p->name, "CHGNAME");
    return;
  }

  if (EmptyString(parv[2]))
  {
    parv[2] = parv[1];
    target_p = source_p;
  }
  else if ((target_p = find_client(parv[1])) == NULL)
  {
    sendto_one(source_p, form_str(ERR_NOSUCHNICK),
               me.name, source_p->name, parv[1]);
    return;
  }

  if (strlen(parv[2]) > REALLEN || !*parv[2])
  {
    sendto_one(source_p, ":%s NOTICE %s :Invalid realname",
               me.name, source_p->name);
    return;
  }

  if (parc > 3 && MyClient(source_p))
    sendto_one(source_p, ":%s NOTICE %s :Warning -- too many parameters "
               "for CHGNAME. You are probably missing a : before the new "
               "IRC name.", me.name, source_p->name);

  strlcpy(target_p->info, parv[2], sizeof(target_p->info));

  if (MyClient(source_p))
  {
    sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGNAME %s :%s",
                  source_p->name, target_p->name, parv[2]);
    sendto_one(source_p, ":%s NOTICE %s :%s realname changed to [%s]",
               me.name, source_p->name, target_p->name, target_p->info);
  }

  if (MyClient(target_p) && IsClient(source_p))
    sendto_one(target_p, ":%s NOTICE %s :Your realname is now [%s]",
               me.name, target_p->name, target_p->info);
}
Exemple #30
0
static void ms_pong(struct Client *client_p,
                   struct Client *source_p,
                   int parc,
                   char *parv[])
{
  struct Client *target_p;
  char  *origin, *destination;

  cluster_prefix(client_p, parc, parv, 0, 0, 0);
  if (parc > 0 && parv[1] && !strchr(parv[1], '.'))
  	cluster_prefix(client_p, parc, parv, 1, 0, 0);
  if (parc > 1 && parv[2] && !strchr(parv[2], '.'))
  	cluster_prefix(client_p, parc, parv, 2, 0, 0);

  if (parc < 2 || *parv[1] == '\0')
    {
      sendto_one(source_p, form_str(source_p,ERR_NOORIGIN), me.name, parv[0]);
      return;
    }

  origin = parv[1];
  destination = parv[2];
  source_p->flags &= ~FLAGS_PINGSENT;

  /* Now attempt to route the PONG, comstud pointed out routable PING
   * is used for SPING.  routable PING should also probably be left in
   *        -Dianora
   * That being the case, we will route, but only for registered clients (a
   * case can be made to allow them only from servers). -Shadowfax
   */
  if (!EmptyString(destination) && !match(destination, me.name))
    {
      if ((target_p = find_client(destination)) ||
          (target_p = find_server(destination)))
        sendto_one(target_p,":%s PONG %s %s",
                   parv[0], origin, destination);
      else
        {
          sendto_one(source_p, form_str(source_p,ERR_NOSUCHSERVER),
                     me.name, parv[0], destination);
          return;
        }
    }

#ifdef  DEBUGMODE
  else
    Debug((DEBUG_NOTICE, "PONG: %s %s", origin,
           destination ? destination : "*"));
#endif
  return;
}