+/* bot_NeonSpam.c - NeonServ v5.1
+ * 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 "bot_NeonSpam.h"
+#include "cmd_neonserv.h"
+
+#define BOTID 2
+
+static const struct default_language_entry msgtab[] = {
+ {NULL, NULL}
+};
+
+//EVENTS
+//#include "event_neonspam_join.c"
+
+static void neonspam_bot_ready(struct ClientSocket *client) {
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+
+ printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) != NULL) {
+ putsock(client, "MODE %s +%s", client->user->nick, row[0]);
+ }
+
+ printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d' AND `suspended` = '0'", client->clientid);
+ res = mysql_use();
+
+ while ((row = mysql_fetch_row(res)) != NULL) {
+ putsock(client, "JOIN %s %s", row[0], row[1]);
+ }
+}
+
+static void neonspam_trigger_callback(struct ChanNode *chan, char *trigger) {
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ loadChannelSettings(chan);
+ printf_mysql_query("SELECT `trigger` FROM `bot_channels` LEFT JOIN `bots` ON `botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chan->channel_id, BOTID);
+ res = mysql_use();
+ row = mysql_fetch_row(res);
+ strcpy(trigger, (strlen(row[0]) ? row[0] : "~"));
+}
+
+static void start_bots() {
+ struct UserNode *user;
+ struct ClientSocket *client;
+ MYSQL_RES *res, *res2;
+ MYSQL_ROW row;
+
+ printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
+ res = mysql_use();
+
+ while ((row = mysql_fetch_row(res)) != NULL) {
+
+ user = addUser(row[0]);
+ strcpy(user->ident, row[1]);
+ strcpy(user->realname, row[2]);
+ user->flags |= USERFLAG_ISBOT;
+ client = create_socket(row[3], atoi(row[4]), row[5], user);
+ client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
+ client->botid = BOTID;
+ client->clientid = atoi(row[7]);
+ connect_socket(client);
+ printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", client->botid);
+ res2 = mysql_use();
+ while ((row = mysql_fetch_row(res2)) != NULL) {
+ if(bind_cmd_to_command(BOTID, row[0], row[1])) {
+ if(row[2] && strcmp(row[2], "")) {
+ bind_set_parameters(BOTID, row[0], row[2]);
+ }
+ if(row[3]) {
+ bind_set_global_access(BOTID, row[0], atoi(row[3]));
+ }
+ if(row[4]) {
+ bind_set_channel_access(BOTID, row[0], row[4]);
+ }
+ }
+ }
+ }
+
+}
+
+void init_NeonSpam() {
+ start_bots();
+
+ //register events
+ bind_bot_ready(neonspam_bot_ready);
+ //bind_join(neonspam_event_join);
+
+ set_trigger_callback(BOTID, neonspam_trigger_callback);
+
+ register_default_language_table(msgtab);
+}
+
+void loop_NeonSpam() {
+
+}
+
+void free_NeonSpam() {
+
+}
+
+#undef BOTID