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)
--- /dev/null
+/* 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);
+}
--- /dev/null
+/* 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
#include "cmd_global.h"
#include "cmd_neonserv.h"
#include "cmd_neonspam.h"
+#include "cmd_funcmds.h"
#include "modcmd.h"
void register_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
#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
+ //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
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...
}
}
-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))
#define CMDFLAG_EMPTY_ARGS 0x0400
#define CMDFLAG_REQUIRED 0x0800
#define CMDFLAG_TEMPONARY_BIND 0x1000
+#define CMDFLAG_FUNCMD 0x2000
struct ClientSocket;
struct UserNode;
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