+
+static void neonserv_cmd_unvisited_unreg(struct ClientSocket *client, char *channel) {
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ int sync_neonspam_unreg = get_int_field("General.sync_neonspam_unreg");
+ int botid;
+ if(client)
+ botid = client->botid;
+ else
+ botid = NEONSERV_BOTID;
+ printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended`, `channels`.`channel_nodelete` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `channel_name` = '%s' AND `botclass` = '%d'", escape_string(channel), botid);
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) == NULL) {
+ return;
+ }
+ int clientid = atoi(row[0]);
+ struct ClientSocket *bot;
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ if(bot->clientid == clientid)
+ break;
+ }
+ if(!strcmp(row[3], "1")) return;
+ printf_mysql_query("DELETE FROM `bot_channels` WHERE `id` = '%s'", row[1]);
+ if(bot && strcmp(row[2], "1")) {
+ putsock(bot, "PART %s :Channel unregistered.", channel);
+ }
+ if(botid == NEONSERV_BOTID && sync_neonspam_unreg) {
+ botid = NEONSPAM_BOTID;
+ printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `channel_name` = '%s' AND `botclass` = '%d'", escape_string(channel), botid);
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) == NULL) {
+ return;
+ }
+ clientid = atoi(row[0]);
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ if(bot->clientid == clientid)
+ break;
+ }
+ printf_mysql_query("DELETE FROM `bot_channels` WHERE `id` = '%s'", row[1]);
+ if(bot && strcmp(row[2], "1")) {
+ putsock(bot, "PART %s :Channel unregistered.", channel);
+ }
+ }
+ if(botid == NEONSERV_BOTID) {
+ char setting[128];
+ sprintf(setting, "modules.%s.auto_backup_unregister", get_module_name(module_id));
+ if(get_int_field(setting))
+ module_global_cmd_unregister_neonbackup(channel);
+ }
+ char *alertchan = get_string_field("General.alertchan");
+ if(alertchan) {
+ struct ChanNode *alertchan_chan = getChanByName(alertchan);
+ struct ClientSocket *alertclient;
+ if(alertchan_chan && (alertclient = getChannelBot(alertchan_chan, 0)) != NULL) {
+ putsock(alertclient, "PRIVMSG %s :Unregistered %s (unvisited)", alertchan_chan->name, channel);
+ }
+ }
+}