From: pk910 Date: Wed, 21 Sep 2011 13:51:47 +0000 (+0200) Subject: continued event_join X-Git-Tag: v5.3~381 X-Git-Url: http://git.pk910.de/?a=commitdiff_plain;h=d4f8a26dc937cf699011e837502cb964e7b5827f;p=NeonServV5.git continued event_join continued event_join --- diff --git a/event_neonserv_join.c b/event_neonserv_join.c index 25f6cf6..6397e0b 100644 --- a/event_neonserv_join.c +++ b/event_neonserv_join.c @@ -6,6 +6,7 @@ struct neonserv_event_join_cache { static USERAUTH_CALLBACK(neonserv_event_join_nick_lookup); static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanUser *chanuser); +static TIMEQ_CALLBACK(neonserv_event_join_dynlimit); static void neonserv_event_join(struct ChanUser *chanuser) { struct UserNode *user = chanuser->user; @@ -56,24 +57,33 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU struct ClientSocket *textclient = ((client->flags & SOCKET_FLAG_PREFERRED) ? client : get_prefered_bot(client->botid)); struct ChanNode *chan = chanuser->chan; struct UserNode *user = chanuser->user; + struct ModeBuffer *modeBuf; MYSQL_RES *res; - MYSQL_ROW row, chanuserrow; - printf_mysql_query("SELECT `channel_maxusers`, `channel_greeting`, `channel_usergreeting` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id); + MYSQL_ROW row, chanuserrow, defaultrow = NULL; + printf_mysql_query("SELECT `channel_maxusers`, `channel_greeting`, `channel_usergreeting`, `channel_getop`, `channel_getvoice`, `channel_userinfo`, `channel_dynlimit` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id); res = mysql_use(); if ((row = mysql_fetch_row(res)) == NULL) return; + if(!row[3] || !row[4]) { + printf_mysql_query("SELECT `channel_getop`, `channel_getvoice`, `channel_userinfo` FROM `channels` WHERE `channel_name` = 'defaults'"); + res = mysql_use(); + defaultrow = mysql_fetch_row(res); + } if(chan->usercount > atoi(row[0])) { //update maxusers printf_mysql_query("UPDATE `channels` SET `channel_maxusers` = '%d' WHERE `channel_id` = '%d'", chan->usercount, chan->channel_id); } - printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `chanuser_info` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id); - res = mysql_use(); - chanuserrow = mysql_fetch_row(res); + if((user->flags & USERFLAG_ISAUTHED)) { + printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `chanuser_infoline`, `chanuser_seen`, `chanuser_id` FROM `chanusers` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `chanuser_cid` = '%d' AND `user_user` = '%s'", chan->channel_id, escape_string(user->auth)); + res = mysql_use(); + chanuserrow = mysql_fetch_row(res); + } else + chanuserrow = NULL; int userflags = (chanuserrow ? atoi(chanuserrow[1]) : 0); int uaccess = ((chanuserrow && !(userflags & DB_CHANUSER_SUSPENDED)) ? atoi(chanuserrow[0]) : 0); //GREETING char greeting[MAXLEN]; int greetingPos = 0; - char *a, *b = (chanuserrow && row[2] ? row[2] : row[1]); + char *a, *b = (chanuserrow && *row[2] ? row[2] : row[1]); do { if(!b) break; a = strstr(b, "$"); @@ -110,7 +120,57 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU if(greetingPos) reply(textclient, user, "[%s] %s", chan->name, greeting); //USER RIGHTS - //INFOLINE / SEEN + if(!(userflags & DB_CHANUSER_NOAUTOOP)) { + int getop = atoi((row[3] ? row[3] : defaultrow[0])); + int getvoice = atoi((row[4] ? row[4] : defaultrow[1])); + modeBuf = initModeBuffer(client, chan); + if(uaccess >= getop && uaccess != 0) { //we disallow auto op for all users + modeBufferOp(modeBuf, user->nick); + } else if(uaccess >= getvoice) { + modeBufferVoice(modeBuf, user->nick); + } + freeModeBuffer(modeBuf); + } + //INFOLINE + int userinfoaccess = atoi((row[5] ? row[5] : defaultrow[2])); + if(chanuserrow && strcmp(chanuserrow[2], "") && uaccess > userinfoaccess) { + if(!strcmp(chanuserrow[3], "0") || time(0) - atol(chanuserrow[3]) >= 30) { + putsock(client, "PRIVMSG %s :[%s] %s", chan->name, user->nick, chanuserrow[2]); + } + } + //SEEN + if(chanuserrow) { + printf_mysql_query("UPDATE `chanusers` SET `chanuser_seen` = UNIX_TIMESTAMP() WHERE `chanuser_id` = '%s'", chanuserrow[4]); + } //DYNLIMIT + if(row[6] && strcmp(row[6], "0")) { + char nameBuf[CHANNELLEN + 10]; + sprintf(nameBuf, "dynlimit_%s", chan->name); + if(!timeq_name_exists(nameBuf)) { + //neonserv_event_join_dynlimit + timeq_add_name(nameBuf, 30, neonserv_event_join_dynlimit, strdup(chan->name)); + } + } //AUTOINVITE + if(!strcmp(chanuserrow[3], "0") || time(0) - atol(chanuserrow[3]) >= 30) { + //TODO: autoinvite + } +} + +static TIMEQ_CALLBACK(neonserv_event_join_dynlimit) { + char *chanName = data; + struct ChanNode *chan = getChanByName(chanName); + free(chanName); + struct ClientSocket *client = getBotForChannel(chan); + if(!client) return; + loadChannelSettings(chan); + if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return; + MYSQL_RES *res; + MYSQL_ROW row; + printf_mysql_query("SELECT `channel_dynlimit` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id); + res = mysql_use(); + if ((row = mysql_fetch_row(res)) == NULL) return; + if(row[0] && strcmp(row[0], "0")) { + putsock(client, "MODE %s +l %d", chan->name, chan->usercount + atoi(row[0])); + } } diff --git a/timeq.c b/timeq.c index 2fb46ea..fe919c8 100644 --- a/timeq.c +++ b/timeq.c @@ -88,3 +88,13 @@ int timeq_del_name(char *name) { } return 0; } + +int timeq_name_exists(char *name) { + struct timeq_entry *centry; + for(centry = timeq_events; centry; centry = centry->next) { + if(centry->name && !stricmp(centry->name, name)) { + return 1; + } + } + return 0; +} diff --git a/timeq.h b/timeq.h index 334eb70..0a06948 100644 --- a/timeq.h +++ b/timeq.h @@ -20,5 +20,6 @@ struct timeq_entry* timeq_add(int seconds, timeq_callback_t *callback, void *dat struct timeq_entry* timeq_add_name(char *name, int seconds, timeq_callback_t *callback, void *data); int timeq_del(struct timeq_entry* entry); int timeq_del_name(char *name); +int timeq_name_exists(char *name); #endif \ No newline at end of file