Пример #1
0
void		send_all_users(t_msg ***msg, t_channel *channel,
			       int id, char *str)
{
  int		j;
  int		pos_dest;

  j = 0;
  while (j != MAX_FD)
    {
      if (g_env.fd_type[j] == FD_CLIENT && channel->id[j]
	  != UNUSED && (pos_dest = find_id_msg(j, *msg)) != UNUSED)
	{
	  (*msg)[pos_dest]->buffer = send_channel((*msg)[pos_dest]->buffer,
						  channel->name, '\0');
	  (*msg)[pos_dest]->buffer = send_user((*msg)[pos_dest]->buffer,
					       g_env.name[id], ' ', E_TRUE);
	  (*msg)[pos_dest]->buffer = add_msg((*msg)[pos_dest]->buffer,
					     str, '\0');
	}
      j = j + 1;
    }
}
Пример #2
0
void	user_receive(t_who *group, t_who *user)
{
	int		response;
	char	str[1024];

	(void)group;
	ft_bzero(str, 1024);
	response = recv(user->fd, str, BUF_SIZE, 0);
	ft_strcat(user->buffer, str);
	if (response && ft_strchr(user->buffer, '\n') != NULL)
	{
		if (user->buffer[0] == '/')
			user_command(group, user);
		else
			send_channel(group, user);
		ft_bzero(user->buffer, sizeof(user->buffer));
	}
	else if (response == 0)
	{
		sprintf(str, MSG_USER_QUIT, user->user.name);
		close_connection(user);
		send_broadcast(group, str);
	}
}
Пример #3
0
void *irc_event_privmsg(irc_conn_t *c, struct irc_message *m)
{
	if (m->suffix[0] == '\001')
		return NULL;
	char buf[128];
	switch (bot_cmds_parse_msg(&boti, c, m)) {
	case -2:
		strcpy(buf, "ERROR not authorized");
		goto error_send;
	case -1:
		strcpy(buf, "ERROR command requires other parameters");
		goto error_send;
	case 0:
		strcpy(buf, "DONE");
error_send:
		if (m->middle[0] != '#') {
			struct bot_message bm = {
					.src = NULL,
					.dst = m->source,
					.msg = buf
			};
			send_user((void*) c, &bm);
		} else {
			struct bot_message bm = {
					.src = NULL,
					.dst = m->middle,
					.msg = buf
			};
			send_channel((void*) c, &bm);
		}
		return NULL;
	default:
		break;
	}
	bot_know_t *bot = boti.know;
	struct bot_message msg = {m->source, m->middle, m->suffix};
	if (m->middle[0] != '#') {
		bot_know_user_msg(bot, &msg, (void *) c);
		return NULL;
	} else {
		if (msg.msg[0] == '!') {
			++msg.msg;
			bot_know_channel_msg(bot, &msg, (void *) c, 1);
		} else {
			bot_know_channel_msg(bot, &msg, (void *) c, 0);
		}
	}

	return NULL;
}

void *send_channel(void *user_data, struct bot_message *m)
{
	if(user_data == NULL) {
		return NULL;
	}
#ifdef IRC
	irc_privmsg((irc_conn_t *) user_data, m->dst, m->msg);
#endif
	return NULL;
}

void *send_user(void *user_data, struct bot_message *m)
{
	irc_privmsg((irc_conn_t *) user_data, m->dst, m->msg);
	return NULL;
}