示例#1
0
void endmotd_handler (ircclient_t *cl, char *nick, char *host, char *args)
{
    chanlist_t *it;

    if (cl->ns_nick && cl->ns_command)
        irc_privmsg (cl, cl->ns_nick, "%s", cl->ns_command);

    for (it = cl->channels; it; it = it->next)
        if (strlen (it->name) && strlen (it->pass))
            irc_join (cl, it->name, it->pass);
        else if (strlen (it->name))
            irc_join (cl, it->name, NULL);

    return;
}
示例#2
0
文件: oper.c 项目: nacx/circus
int main(int argc, char **argv) {
    char* server, *port;

    if (argc != 3) {
        printf("Usage: %s <server> <port>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    server = argv[1];   /* The IRC server */
    port = argv[2];     /* The IRC server port */

    /* Bind message commands to custom functions */
    irc_bind_command("!op", (Callback) give_op);
    irc_bind_command("!deop", (Callback) take_op);
    irc_bind_command("!voice", (Callback) give_voice);
    irc_bind_command("!devoice", (Callback) take_voice);

    /* Connect, login and join the configured channel */
    irc_connect(server, port);
    irc_login(CONF_NICK, "Circus", "Circus IRC bot");
    irc_join(CONF_CHAN);

    /* Start listening to events.
     * This method blocks until a quit signal is received */
    irc_listen();

    /* Send quit message and close connection */
    irc_quit("Bye");
    irc_disconnect();

    return 0;
}
示例#3
0
文件: callback.c 项目: nacx/circus
int main(int argc, char **argv) {
    char* server, *port;

    if (argc != 3) {
        printf("Usage: %s <server> <port>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    server = argv[1];   /* The IRC server */
    port = argv[2];     /* The IRC server port */

    /* Bind IRC event to custom functions.
     * All bindable events are defined in codes.h */
    irc_bind_event(ERR_NICKNAMEINUSE, (Callback) on_nick_in_use);
    irc_bind_event(ERROR, (Callback) on_error);
    irc_bind_event(JOIN, (Callback) on_join);
    irc_bind_event(ALL, (Callback) on_message);

    /* Connect, login and join the configured channel */
    irc_connect(server, port);
    irc_login(CONF_NICK, "Circus", "Circus IRC bot");
    irc_join(CONF_CHAN);

    /* Start listening to events.
     * This method blocks until a quit signal is received */
    irc_listen();

    /* Send quit message and close connection */
    irc_quit("Bye");
    irc_disconnect();

    return 0;
}
示例#4
0
文件: test_irc.c 项目: nacx/circus
void test_irc_join() {
    char msg[READ_BUF];

    irc_join("#circus");
    read_mock(msg);

    mu_assert(s_eq(msg, "JOIN #circus\r\n"), "test_irc_join: msg should be 'JOIN #circus\\r\\n'");
}
示例#5
0
文件: irc_tests.c 项目: meqif/lolbot
static
char *test_irc_join() {
    bstring expected;

    expected = bfromcstr("JOIN #lolbot\r\n");
    irc_join(SOCK, "lolbot");
    mu_assert("Empty message", blength(sent) != 0);
    mu_assert("Message differs from expected", bstrcmp(expected, sent) == 0);
    bdestroy(expected);
    bdestroy(sent);

    return NULL;
}
示例#6
0
文件: prbot.c 项目: rfw/prbot
int
main(int argc, char *argv[])
{
    // Compile some regexes.
    if (regcomp(&new_pr_regex, NEW_PR_PATTERN, REG_EXTENDED)) {
        fprintf(stderr, "Failed to compile regex.\n");
        return 1;
    }

    // Initialize SQLite gunk.
    int retval;

    retval = sqlite3_open(DATABASE_NAME, &db);
    if (retval) {
        fprintf(stderr, "Failed to open database: %s\n", sqlite3_errmsg(db));
        return 1;
    }

    retval = sqlite3_exec(db, INITIALIZE_DB, 0, 0, 0);
    if (retval) {
        fprintf(stderr, "Failed to initialize database: %s\n", sqlite3_errmsg(db));
        return 1;
    }
 
    // Kick off the IRC connection.
	char buf[BUF_LEN];
	struct ircbuf ircbuf;
	ircbuf_init(&ircbuf, buf, BUF_LEN);

	int fd = irc_connect(IRC_HOST, IRC_PORT);
	if (fd < 0) {
		fprintf(stderr, "Failed to open connection.\n");
		return 1;
	}

	irc_nick(fd, IRC_NICK, NULL);
	irc_join(fd, IRC_CHANNEL);

	char *line;
	while ((line = irc_getline(fd, &ircbuf))) {
		printf("%s\n", line);

		struct ircmsg msg;
		irc_parseline(line, &msg);
		if (!dispatch_handler(fd, &msg))
			return 2;
	}

	return 0;
}
示例#7
0
文件: main.c 项目: bajr/bajrc-bot
void init_conf (irc_t * irc, FILE * conf) {
  char *servname = NULL, *servport = NULL, *line = NULL, *tok = NULL, ch = 0;
  int state = 0;

  do {
    line = getln(conf);
    ch = 0;
    tok = NULL;

    if (line != NULL)
      tok = strtok(line, " :");
    if (tok != NULL) {
      if (strcmp(tok, "") == 0)
        tok = NULL;
      if (tok != NULL)
        ch = tok[0];
    }

    if (ch == '{') {
      state = 1;
    }
    else if (ch == '}') {
      state = 0;
    }
    else if (state == 0 && tok != NULL) {
      servname = tok;
      servport = strtok(NULL, " :");
      if ( irc_connect(irc, servname, servport) < 0 ) {
        fprintf(stderr, "Connection to %s:%sfailed.\n", servname, servport);
      }
      else {
        if ( irc_login(irc, BOTNAME) < 0 ) {
          fprintf(stderr, "Couldn't log in.\n");
        }
      }
    }
    else if (state == 1 && ch == '#') {
      char *chan = malloc(strlen(tok)+1);
      strcpy(chan, tok);
      irc_join(irc, chan);
    }

    if (line != NULL) {
      free(line);
    }
  } while (line != NULL);
}
示例#8
0
文件: hash.c 项目: NX-Andro/x3
struct modeNode *
AddChannelUser(struct userNode *user, struct chanNode* channel)
{
	struct modeNode *mNode;
	unsigned int n;

	mNode = GetUserMode(channel, user);
	if (mNode)
            return mNode;

	mNode = malloc(sizeof(*mNode));

	/* set up modeNode */
	mNode->channel = channel;
	mNode->user = user;
	mNode->modes = 0;
        mNode->oplevel = -1;
        mNode->idle_since = now;

	/* Add modeNode to channel and to user.
         * We have to do this before calling join funcs in case the
         * modeNode is manipulated (e.g. chanserv ops the user).
         */
	modeList_append(&channel->members, mNode);
	modeList_append(&user->channels, mNode);

        if (channel->members.used == 1
            && !(channel->modes & MODE_REGISTERED)
            && !(channel->modes & MODE_APASS)) {
            mNode->modes |= MODE_CHANOP;
            log_module(MAIN_LOG, LOG_DEBUG, "setting op");
        }

        if (IsLocal(user)) {
            irc_join(user, channel);
        }

        for (n=0; (n<jf_used) && !user->dead; n++) {
            /* Callbacks return true if they kick or kill the user,
             * and we can continue without removing mNode. */
            if (jf_list[n](mNode, jf_list_extra[n]))
                return NULL;
        }

	return mNode;
}
示例#9
0
文件: hash.c 项目: NX-Andro/x3
/* reintroduces a user after it has been killed. */
void
ReintroduceUser(struct userNode *user)
{
    struct mod_chanmode change;
    unsigned int n;
	
    irc_user(user);
    mod_chanmode_init(&change);
    change.argc = 1;
    for (n = 0; n < user->channels.used; n++) {
        struct modeNode *mn = user->channels.list[n];
	irc_join(user, mn->channel);
        if (mn->modes) {
            change.args[0].mode = mn->modes;
            change.args[0].u.member = mn;
            mod_chanmode_announce(user, mn->channel, &change);
        }
    }
}
示例#10
0
void network_connect(struct network *net)
{
    struct channel *tmp;
    irc_connect(net);
    if (net->close_network)
        return ;

    irc_nick(net);
    network_write_nick(net);
    irc_user(net);
    network_write_realname(net);
    if (net->password)
        irc_pass(net);

    network_foreach_channel(net, tmp)
        irc_join(net, tmp->name);

    network_write_joined(net);
}
示例#11
0
文件: irc.c 项目: Skeen/OSAA_IRC
int irc_join_channel(irc_t *irc, const char* channel)
{
   strncpy(irc->channel, channel, 254);
   irc->channel[254] = '\0';
   return irc_join(irc->s, channel);
}
示例#12
0
文件: irc.c 项目: dharwood/bajrc-bot
int irc_join_channel(irc_t *irc, const char* channel) {
   return irc_join(irc->s, channel);
}