added structure for future fun-commands
authorpk910 <philipp@zoelle1.de>
Tue, 1 Nov 2011 22:54:12 +0000 (23:54 +0100)
committerpk910 <philipp@zoelle1.de>
Tue, 1 Nov 2011 23:03:58 +0000 (00:03 +0100)
Makefile.am
src/cmd_funcmds.c [new file with mode: 0644]
src/cmd_funcmds.h [new file with mode: 0644]
src/commands.c
src/modcmd.c
src/modcmd.h

index 121bb073b2e5ad49f7c6fb839e0b32dfe159a73c..5bea9fd95385fd132ebbb2d74d8f2513768ff25a 100644 (file)
@@ -112,6 +112,7 @@ neonserv_SOURCES = src/version.c \
       src/cmd_neonserv_unvisited.c \
       src/cmd_neonserv_extscript.c \
       src/cmd_neonspam_set.c \
       src/cmd_neonserv_unvisited.c \
       src/cmd_neonserv_extscript.c \
       src/cmd_neonspam_set.c \
+      src/cmd_funcmds.c \
       src/lib/ini.c
 
 neonserv_LDADD = $(MYSQL_LIBS) $(WINSOCK_LIBS)
       src/lib/ini.c
 
 neonserv_LDADD = $(MYSQL_LIBS) $(WINSOCK_LIBS)
diff --git a/src/cmd_funcmds.c b/src/cmd_funcmds.c
new file mode 100644 (file)
index 0000000..1c5d8c2
--- /dev/null
@@ -0,0 +1,83 @@
+/* cmd_funcmds.c - NeonServ v5.2
+ * Copyright (C) 2011  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_funcmds.h"
+#include "modcmd.h"
+#include "mysqlConn.h"
+#include "IRCParser.h"
+#include "ClientSocket.h"
+#include "UserNode.h"
+#include "ChanNode.h"
+
+struct current_funcmd_header {
+    struct ClientSocket *client;
+    struct UserNode *user;
+    struct ChanNode *chan;
+    char send_notice;
+};
+
+static struct current_funcmd_header current_funcmd;
+
+#define FUNCMD_HEADER \
+current_funcmd.client = getTextBot(); \
+current_funcmd.user = user; \
+current_funcmd.chan = chan; \
+{\
+    MYSQL_RES *res; \
+    MYSQL_ROW row; \
+    printf_mysql_query("SELECT `channel_toys` FROM `channels` WHERE `channel_name` = '%s'", escape_string(chan->name)); \
+    res = mysql_use(); \
+    row = mysql_fetch_row(res); \
+    if(!row || !strcmp(row[0], "0")) { \
+        reply(getTextBot(), user, "NS_FUN_DISABLED", chan->name); \
+        return; \
+    } else if(!strcmp(row[0], "1")) \
+        current_funcmd.send_notice = 1; \
+    else \
+        current_funcmd.send_notice = 0; \
+}
+
+
+static void funcmd_reply(const char *text, ...) {
+    char formatBuf[MAXLEN];
+    if(current_funcmd.send_notice)
+        sprintf(formatBuf, "NOTICE %s :%s", current_funcmd.user->nick, text);
+    else
+        sprintf(formatBuf, "PRIVMSG %s :%s", current_funcmd.chan->name, text);
+    va_list arg_list;
+    char sendBuf[MAXLEN];
+    int pos;
+    if (!(current_funcmd.client->flags & SOCKET_FLAG_CONNECTED)) return;
+    sendBuf[0] = '\0';
+    va_start(arg_list, text);
+    pos = vsnprintf(sendBuf, MAXLEN - 2, formatBuf, arg_list);
+    va_end(arg_list);
+    if (pos < 0 || pos > (MAXLEN - 2)) pos = MAXLEN - 2;
+    sendBuf[pos] = '\n';
+    sendBuf[pos+1] = '\0';
+    write_socket(current_funcmd.client, sendBuf, pos+1);
+}
+
+CMD_BIND(funcmd_ping) {
+    FUNCMD_HEADER;
+    funcmd_reply("\002%s\002: Pong!", user->nick);
+}
+
+CMD_BIND(funcmd_pong) {
+    FUNCMD_HEADER;
+    funcmd_reply("\002%s\002: Ping!", user->nick);
+}
diff --git a/src/cmd_funcmds.h b/src/cmd_funcmds.h
new file mode 100644 (file)
index 0000000..e012359
--- /dev/null
@@ -0,0 +1,25 @@
+/* cmd_funcmds.h - NeonServ v5.2
+ * Copyright (C) 2011  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/>. 
+ */
+#ifndef _cmd_funcmds_h
+#define _cmd_funcmds_h
+#include "main.h"
+#include "modcmd.h"
+
+CMD_BIND(funcmd_ping);
+CMD_BIND(funcmd_pong);
+
+#endif
\ No newline at end of file
index 87e7305c609a1267c45f946a95bb0b2fa773ff82..51d4b3fcf416c8bdf46207666fc98668d325b543 100644 (file)
@@ -18,6 +18,7 @@
 #include "cmd_global.h"
 #include "cmd_neonserv.h"
 #include "cmd_neonspam.h"
 #include "cmd_global.h"
 #include "cmd_neonserv.h"
 #include "cmd_neonspam.h"
+#include "cmd_funcmds.h"
 #include "modcmd.h"
 
 void register_commands() {
 #include "modcmd.h"
 
 void register_commands() {
@@ -47,7 +48,7 @@ void register_commands() {
     #undef OPER_COMMAND
     
     //NeonServ Commands
     #undef OPER_COMMAND
     
     //NeonServ Commands
-    register_bot_alias(1, "NeonServ");
+    register_command_alias(1, "NeonServ");
     
     #define USER_COMMAND(NAME,FUNCTION,PARAMCOUNT,PRIVS,FLAGS) register_command(1, NAME, FUNCTION, PARAMCOUNT, PRIVS, 0, FLAGS)
     //               NAME              FUNCTION        PARAMS     PRIVS                FLAGS
     
     #define USER_COMMAND(NAME,FUNCTION,PARAMCOUNT,PRIVS,FLAGS) register_command(1, NAME, FUNCTION, PARAMCOUNT, PRIVS, 0, FLAGS)
     //               NAME              FUNCTION        PARAMS     PRIVS                FLAGS
@@ -120,12 +121,22 @@ void register_commands() {
     #undef OPER_COMMAND
     
     //NeonSpam Commands
     #undef OPER_COMMAND
     
     //NeonSpam Commands
-    register_bot_alias(2, "NeonSpam");
+    register_command_alias(2, "NeonSpam");
     
     #define USER_COMMAND(NAME,FUNCTION,PARAMCOUNT,PRIVS,FLAGS) register_command(2, NAME, FUNCTION, PARAMCOUNT, PRIVS, 0, FLAGS)
     //               NAME              FUNCTION        PARAMS     PRIVS                FLAGS
     USER_COMMAND("set",          neonspam_cmd_set,       0, "#channel_setters",     CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG);
     #undef USER_COMMAND
     
     
     #define USER_COMMAND(NAME,FUNCTION,PARAMCOUNT,PRIVS,FLAGS) register_command(2, NAME, FUNCTION, PARAMCOUNT, PRIVS, 0, FLAGS)
     //               NAME              FUNCTION        PARAMS     PRIVS                FLAGS
     USER_COMMAND("set",          neonspam_cmd_set,       0, "#channel_setters",     CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG);
     #undef USER_COMMAND
     
+    //Fun Commands
+    register_command_alias(3, "FunCMD");
+    #define USER_COMMAND(NAME,FUNCTION,PARAMCOUNT,FLAGS) register_command(3, NAME, FUNCTION, PARAMCOUNT, NULL, 0, FLAGS)
+    //               NAME              FUNCTION        PARAMS   FLAGS
+    USER_COMMAND("extscript",    neonserv_cmd_extscript, 0,  CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_EMPTY_ARGS | CMDFLAG_CHAN_PARAM | CMDFLAG_FUNCMD);
+    USER_COMMAND("ping",         funcmd_ping,            0,  CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_FUNCMD);
+    USER_COMMAND("pong",         funcmd_pong,            0,  CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_FUNCMD);
+    #undef USER_COMMAND
+    
+    
     
 }
\ No newline at end of file
     
 }
\ No newline at end of file
index bfefb4bdca33f4c82a320dfc029806c3fb32fb54..8b9c72c4573ab60000075d2e6a14e20df36861f9 100644 (file)
@@ -153,6 +153,11 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
     struct cmd_binding *cbind;
     for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
         if(cbind->botid == client->botid && stricmp(cbind->cmd, message) == 0) {
     struct cmd_binding *cbind;
     for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
         if(cbind->botid == client->botid && stricmp(cbind->cmd, message) == 0) {
+            if((cbind->flags & CMDFLAG_FUNCMD)) {
+                if(!sent_chan)
+                    break;
+                chan = sent_chan;
+            }
             //get a text bot
             tmp_text_client = get_prefered_bot(client->botid);
             //parse the arguments...
             //get a text bot
             tmp_text_client = get_prefered_bot(client->botid);
             //parse the arguments...
@@ -768,7 +773,7 @@ void bind_unbound_required_functions(int botid) {
     }
 }
 
     }
 }
 
-void register_bot_alias(int botid, char *alias) {
+void register_command_alias(int botid, char *alias) {
     struct cmd_bot_alias *botalias;
     for(botalias = bot_aliases; botalias; botalias = botalias->next) {
         if(!stricmp(botalias->alias, alias))
     struct cmd_bot_alias *botalias;
     for(botalias = bot_aliases; botalias; botalias = botalias->next) {
         if(!stricmp(botalias->alias, alias))
index 40ad373ea3a403691ec341e43d9fb627e269f9da..4ba89a96a4090ed2df73fc3f135673c589242bf6 100644 (file)
@@ -33,6 +33,7 @@
 #define CMDFLAG_EMPTY_ARGS              0x0400
 #define CMDFLAG_REQUIRED                0x0800
 #define CMDFLAG_TEMPONARY_BIND          0x1000
 #define CMDFLAG_EMPTY_ARGS              0x0400
 #define CMDFLAG_REQUIRED                0x0800
 #define CMDFLAG_TEMPONARY_BIND          0x1000
+#define CMDFLAG_FUNCMD                  0x2000
 
 struct ClientSocket;
 struct UserNode;
 
 struct ClientSocket;
 struct UserNode;
@@ -92,7 +93,7 @@ void bind_set_channel_access(int botid, char *cmd, char *chanaccess);
 struct cmd_binding *find_cmd_binding(int botid, char *cmd);
 void bind_unbound_required_functions(int botid);
 
 struct cmd_binding *find_cmd_binding(int botid, char *cmd);
 void bind_unbound_required_functions(int botid);
 
-void register_bot_alias(int botid, char *alias);
+void register_command_alias(int botid, char *alias);
 struct cmd_binding *getAllBinds(struct cmd_binding *last);
 
 #endif
\ No newline at end of file
 struct cmd_binding *getAllBinds(struct cmd_binding *last);
 
 #endif
\ No newline at end of file