added full half-op support
[NeonServV5.git] / src / event_neonserv_join.c
index f307b42a630de25959bc6c5ce6d7152cfb07ff31..77d5de7519a200df297dbe939b3b691b405e8c03 100644 (file)
@@ -1,5 +1,5 @@
-/* event_neonserv_join.c - NeonServ v5.2
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* event_neonserv_join.c - NeonServ v5.3
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,10 +29,11 @@ static void neonserv_event_join(struct ChanUser *chanuser) {
     struct UserNode *user = chanuser->user;
     struct ClientSocket *client = getBotForChannel(chanuser->chan);
     if(!client) return; //we can't "see" this event
-    if(user->flags & USERFLAG_ISBOT) {
-        putsock(client, "MODE %s +o %s", chanuser->chan->name, chanuser->user->nick);
+    if(chanuser->user == client->user) {
+        requestOp(client->user, chanuser->chan);
         return;
     }
+    if(chanuser->user->flags & USERFLAG_ISBOT) return;
     loadChannelSettings(chanuser->chan);
     if(!(chanuser->chan->flags & CHANFLAG_CHAN_REGISTERED)) return;
     char *ban;
@@ -76,13 +77,14 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU
     struct ChanNode *chan = chanuser->chan;
     struct UserNode *user = chanuser->user;
     struct ModeBuffer *modeBuf;
+    int with_halfops = get_int_field("General.have_halfop");
     MYSQL_RES *res;
     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);
+    printf_mysql_query("SELECT `channel_maxusers`, `channel_greeting`, `channel_usergreeting`, `channel_getop`, `channel_getvoice`, `channel_userinfo`, `channel_dynlimit`, `channel_gethalfop` 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] || !row[5]) {
-        printf_mysql_query("SELECT `channel_getop`, `channel_getvoice`, `channel_userinfo` FROM `channels` WHERE `channel_name` = 'defaults'");
+    if(!row[3] || !row[4] || !row[5] || (!row[7] && with_halfops)) {
+        printf_mysql_query("SELECT `channel_getop`, `channel_getvoice`, `channel_userinfo`, `channel_gethalfop` FROM `channels` WHERE `channel_name` = 'defaults'");
         res = mysql_use();
         defaultrow = mysql_fetch_row(res);
     }
@@ -142,10 +144,13 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU
     //USER RIGHTS
     if(!(userflags & DB_CHANUSER_NOAUTOOP)) {
         int getop = atoi((row[3] ? row[3] : defaultrow[0]));
+        int gethalfop = (with_halfops ? atoi((row[7] ? row[7] : defaultrow[3])) : 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(with_halfops && uaccess >= gethalfop) {
+            modeBufferHalfop(modeBuf, user->nick);
         } else if(uaccess >= getvoice) {
             modeBufferVoice(modeBuf, user->nick);
         }
@@ -172,7 +177,7 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU
         }
     }
     //AUTOINVITE
-    if(!chanuserrow || !strcmp(chanuserrow[3], "0") || time(0) - atol(chanuserrow[3]) >= 30) {
+    if((user->flags & USERFLAG_ISAUTHED) && (!chanuserrow || !strcmp(chanuserrow[3], "0") || time(0) - atol(chanuserrow[3]) >= 30)) {
         //check if it's the first channel, the user is seen by the bot (IMPORTANT: ignore other bot's channel!)
         char first_chan = 1;
         char bot_in_chan;