Merge remote-tracking branch 'origin/development'
authorpk910 <philipp@zoelle1.de>
Sun, 23 Sep 2012 22:31:21 +0000 (00:31 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 23 Sep 2012 22:31:21 +0000 (00:31 +0200)
Makefile.am
src/modcmd.c
src/modcmd.h
src/modules/NeonServ.mod/cmd_neonserv.c
src/modules/NeonServ.mod/cmd_neonserv.h
src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c [new file with mode: 0644]
src/modules/NeonServ.mod/event_neonserv_join.c
src/modules/global.mod/cmd_global_modcmd.c

index 02a219c4c6a8f20b2ba248377436fb18ad7a7b61..df5f18017770bcfffee2a7ac08a4ab5d122ce124 100644 (file)
@@ -97,6 +97,7 @@ libNeonServ_la_SOURCES = src/modules/NeonServ.mod/bot_NeonServ.c \
       src/modules/NeonServ.mod/cmd_neonserv_help.c \
       src/modules/NeonServ.mod/cmd_neonserv_invite.c \
       src/modules/NeonServ.mod/cmd_neonserv_inviteme.c \
+      src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c \
       src/modules/NeonServ.mod/cmd_neonserv_kick.c \
       src/modules/NeonServ.mod/cmd_neonserv_kickban.c \
       src/modules/NeonServ.mod/cmd_neonserv_mdeluser.c \
index f53a3c22a93bfa88dafc2820c288c7f80599f053..e19d261318cd71f169f894bee1efc2a1ea5259c8 100644 (file)
@@ -179,6 +179,32 @@ static struct cmd_binding *modcmd_linker_command(struct ClientSocket *client, st
     }
 }
 
+static struct cmd_binding *modcmd_sub_linker_command(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct cmd_binding *cbind, int bind_index, char **args_ptr) {
+    //links subcommands
+    char command[MAXLEN];
+    struct cmd_binding *parent_bind = cbind;
+    char *args = *args_ptr;
+    if(args) {
+        char *subcmd = args;
+        args = strchr(args, ' ');
+        if(args) {
+            *args = '\0';
+            args++;
+        }
+        sprintf(command, "%s %s", parent_bind->cmd, subcmd);
+        for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+            if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmp(cbind->cmd, command) == 0)
+                break;
+        }
+        *args_ptr = args;
+        if(cbind && cbind->func->func == modcmd_linker) {
+            return modcmd_linker_command(client, textclient, user, cbind, bind_index, args_ptr);
+        }
+        return (cbind ? cbind : parent_bind);
+    } else
+        return parent_bind;
+}
+
 static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
     struct ChanNode *sent_chan = chan;
     if(message[0] == '#') {
@@ -193,7 +219,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
     }
     message = strdup(message);
     int bind_index = get_binds_index(message[0]);
-    char *args = strstr(message, " ");
+    char *args = strchr(message, ' ');
     char *args_buffer = NULL; //we need this to save a possible pointer to a allocation we need to free
     if(args) {
         *args = '\0';
@@ -209,7 +235,8 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
             if(cbind->func->func == modcmd_linker) {
                 cbind = modcmd_linker_command(client, textclient, user, cbind, bind_index, &args);
                 if(cbind == NULL) break;
-            }
+            } else if(cbind->flags & CMDFLAG_SUB_LINKER)
+                cbind = modcmd_sub_linker_command(client, textclient, user, cbind, bind_index, &args);
             if(statistics_enabled)
                 statistics_commands++;
             total_triggered++;
index 9f39e1fc48046c5014498a5b2b4788e1f0668d48..214a096f2b030a3ae746bb57e5f848ca11d2a053 100644 (file)
 
 #define MAXPARAMETERS 50
 
-#define CMDFLAG_REQUIRE_CHAN            0x0001
-#define CMDFLAG_REQUIRE_AUTH            0x0002
-#define CMDFLAG_REQUIRE_GOD             0x0004
-#define CMDFLAG_CHECK_AUTH              0x0008
-#define CMDFLAG_REGISTERED_CHAN         0x0010
-#define CMDFLAG_OVERRIDE_GLOBAL_ACCESS  0x0020
-#define CMDFLAG_OVERRIDE_CHANNEL_ACCESS 0x0040
-#define CMDFLAG_CHAN_PARAM              0x0080
-#define CMDFLAG_LOG                     0x0100
-#define CMDFLAG_OPLOG                   0x0200
-#define CMDFLAG_EMPTY_ARGS              0x0400
-#define CMDFLAG_REQUIRED                0x0800
-#define CMDFLAG_TEMPONARY_BIND          0x1000
-#define CMDFLAG_FUNCMD                  0x2000
-#define CMDFLAG_ESCAPE_ARGS             0x4000
-#define CMDFLAG_NO_CROSSCHAN            0x8000
+#define CMDFLAG_REQUIRE_CHAN            0x00001
+#define CMDFLAG_REQUIRE_AUTH            0x00002
+#define CMDFLAG_REQUIRE_GOD             0x00004
+#define CMDFLAG_CHECK_AUTH              0x00008
+#define CMDFLAG_REGISTERED_CHAN         0x00010
+#define CMDFLAG_OVERRIDE_GLOBAL_ACCESS  0x00020
+#define CMDFLAG_OVERRIDE_CHANNEL_ACCESS 0x00040
+#define CMDFLAG_CHAN_PARAM              0x00080
+#define CMDFLAG_LOG                     0x00100
+#define CMDFLAG_OPLOG                   0x00200
+#define CMDFLAG_EMPTY_ARGS              0x00400
+#define CMDFLAG_REQUIRED                0x00800
+#define CMDFLAG_TEMPONARY_BIND          0x01000
+#define CMDFLAG_FUNCMD                  0x02000
+#define CMDFLAG_ESCAPE_ARGS             0x04000
+#define CMDFLAG_NO_CROSSCHAN            0x08000
+#define CMDFLAG_SUB_LINKER              0x10000
 
 struct ClientSocket;
 struct UserNode;
index 79a4119f1b77d45de65873b125f8e9584e0f7c9a..62750a483217c79b460d1aaebfac8860163c78d8 100644 (file)
@@ -75,6 +75,7 @@ void register_commands() {
     USER_COMMAND("unbanme",      neonserv_cmd_unbanme,   0, "#channel_canban",      CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG);
     USER_COMMAND("invite",       neonserv_cmd_invite,    1, "#channel_canop",       CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG);
     USER_COMMAND("inviteme",     neonserv_cmd_inviteme,  0, "#channel_getinvite",   CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG);
+    USER_COMMAND("invitemeall",  neonserv_cmd_invitemeall,0,NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG);
     USER_COMMAND("help",         neonserv_cmd_help,      0, NULL,                   0);
     USER_COMMAND("events",       neonserv_cmd_events,    0, "1",                    CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("info",         neonserv_cmd_info,      0, NULL,                   CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_NO_CROSSCHAN);
index 097a1f2b7b428e2131fd01ff1b77c544823b366d..da09147c1e66a35ad004dac685f6343e3183d2bd 100644 (file)
@@ -78,6 +78,7 @@ CMD_BIND(neonserv_cmd_help);
 CMD_BIND(neonserv_cmd_info);
 CMD_BIND(neonserv_cmd_invite);
 CMD_BIND(neonserv_cmd_inviteme);
+CMD_BIND(neonserv_cmd_invitemeall);
 CMD_BIND(neonserv_cmd_kick);
 CMD_BIND(neonserv_cmd_kickban);
 CMD_BIND(neonserv_cmd_listrank);
diff --git a/src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c b/src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c
new file mode 100644 (file)
index 0000000..9f5b56d
--- /dev/null
@@ -0,0 +1,52 @@
+/* cmd_neonserv_invitemeall.c - NeonServ v5.6
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_neonserv.h"
+
+/*
+* no arguments
+*/
+
+CMD_BIND(neonserv_cmd_invitemeall) {
+    //invite to all channels where autoinvite is enabled
+    MYSQL_RES *res, *res2;
+    MYSQL_ROW chanuserrow, defaultrow = NULL;
+    printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `channel_name`, `channel_getinvite` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `user_user` = '%s' AND `chanuser_flags` >= '%d'", escape_string(user->auth), DB_CHANUSER_AUTOINVITE);
+    res = mysql_use();
+    struct ChanUser *bchanuser;
+    struct ClientSocket *bot;
+    while((chanuserrow = mysql_fetch_row(res)) != NULL) {
+        int userflags = atoi(chanuserrow[1]);
+        if(!(userflags & DB_CHANUSER_AUTOINVITE)) continue;
+        if(!(chan = getChanByName(chanuserrow[2]))) continue; //no bot is in the channel
+        if((bchanuser = getChanUser(client->user, chan)) && (bchanuser->flags & CHANUSERFLAG_OPPED))
+            bot = client;
+        else {
+            bot = getBotForChannel(chan);
+        }
+        if(getChanUser(user, chan)) continue; //user is already in the channel
+        if(chanuserrow[3] == NULL && defaultrow == NULL) {
+            printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'");
+            res2 = mysql_use();
+            defaultrow = mysql_fetch_row(res2);
+        }
+        if(atoi(chanuserrow[0]) >= atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]))) {
+            putsock(bot, "INVITE %s %s", user->nick, chan->name);
+            reply(textclient, user, "NS_INVITEME_DONE", chan->name);
+        }
+    }
+}
index ba12f166e74e4679f40e738d096e4496972fbd95..8903959038ec3b33ab637577be51b76e1963efb3 100644 (file)
@@ -76,7 +76,7 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU
     struct UserNode *user = chanuser->user;
     struct ModeBuffer *modeBuf;
     int with_halfops = get_int_field("General.have_halfop");
-    MYSQL_RES *res;
+    MYSQL_RES *res, *res2;
     MYSQL_ROW row, chanuserrow, defaultrow = NULL;
     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();
@@ -219,8 +219,8 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU
                 }
                 if(chanuserrow[3] == NULL && defaultrow == NULL) {
                     printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'");
-                    res = mysql_use();
-                    defaultrow = mysql_fetch_row(res);
+                    res2 = mysql_use();
+                    defaultrow = mysql_fetch_row(res2);
                 }
                 getinvite = atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]));
                 if(atoi(chanuserrow[0]) >= getinvite) {
index 1aaa040b2a0dbd85a4c14e5376cf9c2f306e8146..c1066ec1c30c74282ec6f81df075699f52e1e4da 100644 (file)
@@ -113,6 +113,7 @@ static const struct {
     {"FUNCMD",              CMDFLAG_FUNCMD},
     {"ESCAPED_ARGS",        CMDFLAG_ESCAPE_ARGS},       //allows arguments to be escaped ("a\ b" = "a b" as one argument)
     {"NO_CROSSCHAN",        CMDFLAG_NO_CROSSCHAN},
+    {"SUB_LINKER",          CMDFLAG_SUB_LINKER},        //adds a "quiet" subcommand linker with the binding function as default
     {NULL, 0}
 };