3 * argv[0] - nick / *auth
5 static USERAUTH_CALLBACK(neonserv_cmd_invite_nick_lookup);
6 static void neonserv_cmd_invite_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nick, char *auth);
7 static TIMEQ_CALLBACK(neonserv_cmd_invite_timeout_timeout);
8 static struct neonserv_cmd_invite_timeout* neonserv_cmd_invite_add_timeout(char *nick, char *chan);
9 static int neonserv_cmd_invite_is_timeout(char *nick, char *chan);
10 static void neonserv_cmd_invite_del_timeout(struct neonserv_cmd_invite_timeout *timeout);
13 struct neonserv_cmd_invite_cache {
14 struct ClientSocket *client, *textclient;
15 struct UserNode *user;
16 struct ChanNode *chan;
21 struct neonserv_cmd_invite_timeout {
25 struct neonserv_cmd_invite_timeout *next;
28 static struct neonserv_cmd_invite_timeout *first_timeout = NULL, *last_timeout = NULL;
30 static CMD_BIND(neonserv_cmd_invite) {
31 if(neonserv_cmd_invite_is_timeout(argv[0], chan->name)) {
32 reply(getTextBot(), user, "NS_INVITE_TIMEOUT", argv[0], chan->name);
35 struct UserNode *cuser = getUserByNick(argv[0]);
37 cuser = createTempUser(argv[0]);
38 cuser->flags |= USERFLAG_ISTMPUSER;
39 } else if(getChanUser(cuser, chan)) {
40 reply(getTextBot(), user, "NS_INVITE_ON_CHAN", cuser->nick, chan->name);
42 This check does not work if the user is invisible (CHMODE +D/+d)
43 to fix this we'd need to request the full userlist...
44 this is really senseless to invite a simple user so we simply mark this bug as unsolvable.
48 if(cuser->flags & USERFLAG_ISAUTHED) {
49 neonserv_cmd_invite_async1(client, getTextBot(), user, chan, event, argv[0], cuser->auth);
51 struct neonserv_cmd_invite_cache *cache = malloc(sizeof(*cache));
53 perror("malloc() failed");
56 cache->client = client;
57 cache->textclient = getTextBot();
61 cache->nick = strdup(argv[0]);
62 get_userauth(cuser, neonserv_cmd_invite_nick_lookup, cache);
66 static USERAUTH_CALLBACK(neonserv_cmd_invite_nick_lookup) {
67 struct neonserv_cmd_invite_cache *cache = data;
70 reply(cache->textclient, cache->user, "NS_USER_UNKNOWN", cache->nick);
72 neonserv_cmd_invite_async1(cache->client, cache->textclient, cache->user, cache->chan, cache->event, user->nick, ((user->flags & USERFLAG_ISAUTHED) ? user->auth : NULL));
77 static void neonserv_cmd_invite_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nick, char *auth) {
81 printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(auth));
83 if ((row = mysql_fetch_row(res)) != NULL) {
84 //check if the user has set noinvite
85 printf_mysql_query("SELECT `id` FROM `noinvite` WHERE `uid` = '%s' AND `cid` = '%d'", row[0], chan->channel_id);
87 if ((row = mysql_fetch_row(res)) != NULL) {
88 reply(textclient, user, "NS_INVITE_RESTRICTION", nick, chan->name);
93 struct neonserv_cmd_invite_timeout *timeout = neonserv_cmd_invite_add_timeout(nick, chan->name);
94 timeq_add(INVITE_TIMEOUT, neonserv_cmd_invite_timeout_timeout, timeout);
95 putsock(client, "INVITE %s %s", nick, chan->name);
96 struct UserNode *tmpu = getUserByNick(nick);
98 tmpu = createTempUser(nick);
99 tmpu->flags |= USERFLAG_ISTMPUSER | (auth ? USERFLAG_ISAUTHED : 0);
101 strcpy(tmpu->auth, auth);
103 reply(textclient, tmpu, "NS_INVITE_DONE_USER", chan->name, user->nick, client->user->nick);
104 reply(textclient, user, "NS_INVITE_DONE", nick, chan->name);
107 static TIMEQ_CALLBACK(neonserv_cmd_invite_timeout_timeout) {
108 struct neonserv_cmd_invite_timeout *entry = data;
109 neonserv_cmd_invite_del_timeout(entry);
112 static struct neonserv_cmd_invite_timeout* neonserv_cmd_invite_add_timeout(char *nick, char *chan) {
113 struct neonserv_cmd_invite_timeout *entry = malloc(sizeof(*entry));
115 perror("malloc() failed");
119 entry->nick = strdup(nick);
120 entry->chan = strdup(chan);
122 last_timeout->next = entry;
123 last_timeout = entry;
125 last_timeout = entry;
126 first_timeout = entry;
131 static int neonserv_cmd_invite_is_timeout(char *nick, char *chan) {
132 if(!first_timeout) return 0;
133 struct neonserv_cmd_invite_timeout *entry;
134 for(entry = first_timeout; entry; entry = entry->next) {
135 if(!stricmp(entry->nick, nick) && !stricmp(entry->chan, chan))
141 static void neonserv_cmd_invite_del_timeout(struct neonserv_cmd_invite_timeout *timeout) {
142 struct neonserv_cmd_invite_timeout *entry, *prev = NULL;
143 for(entry = first_timeout; entry; entry = entry->next) {
144 if(entry == timeout) {
146 prev->next = entry->next;
148 first_timeout = entry->next;
153 if(last_timeout == timeout)