/* * suspends.c * (C) Peter Salanki 2002 * This program is copyright, and covered by the Gnu Public License. * The Natasha bot. * sorcer@linux.se */ #include #include #include #include #include #include #include #include #include #include "globals.h" int SuspendChannel (struct channel *c, char *reason, int finalduration, int setby) { /* Suspend a channel */ char query[MAX_QUERY], subject[512], email[1024]; char *esreason; struct tm *tmstruct; time_t finaldurtime = (time_t) finalduration; char tmstr[100]; if(c->suspended == 1) return 0; /* Channel already suspended */ /* Make expire date */ tmstruct = localtime(&finaldurtime); strftime(tmstr, 100, "%F %H:%M", tmstruct); c->suspended = 1; /* Part from channel */ snprintf(query, MAX_QUERY, "Channel suspended: %c%s%c", BOLD, reason, BOLD); partchannel(c, query); OutOfChannel(c); /* Add to suspends table */ esreason = escapequery(reason); sprintf(query, "INSERT INTO `suspends` (`cid`,`setby`,`reason`,`time`, `expire`) VALUES ('%i', '%i', '%s', UNIX_TIMESTAMP(), '%i')", c->id, setby, esreason, finalduration); Free(esreason); dbquery(query); EndDbQuery(); /* Update channels table */ dbchanmode(c->id, "suspended", "1"); snprintf(subject, 512, "Your channel (%s) has been suspended", c->name); snprintf(email, 1024, "Dear channel owner,\n\nSeconds ago, your channel %s was suspended with reason: %s.\nYou will need to talk to a member of the botservice staff before %s GMT+1. If your channel has not been unsupended before that date, it will automatically be removed.\n\nThank you for your cooperation,\nThe BotService staff", c->name, reason, tmstr); MailChannelOwners(c, subject, email); return 1; } int UnsuspendChannel (struct channel *c) { /* Remove regex from badchan */ char query[MAX_QUERY]; if(c->suspended == 0) return 0; /* Channel is not suspended */ c->suspended = 0; rejoinchannel(c->name, c->arm); /* Update suspends table */ sprintf(query, "UPDATE `suspends` SET `active` = 0 WHERE `cid` = '%i' AND `active` = '1'", c->id); dbquery(query); EndDbQuery(); /* Update channels table */ dbchanmode(c->id, "suspended", "0"); return 1; } void CleanUpOldSuspends (void) { /* Remove old supends from database and part the channel */ struct channel *c; char subject[512], email[1024], *eschannel; for(c = firstchan; c != NULL; c = c->next) { if(c->suspended == 1) { snprintf(subject, 512, "SELECT `id` FROM `suspends` WHERE `expire` < UNIX_TIMESTAMP() AND `active` = '1' AND `cid` = %i", c->id); dbquery(subject); if((row = mysql_fetch_row(res))) { EndDbQuery(); snprintf(subject, 512, "Suspend has expired: %s", c->name); snprintf(email, 1024, "Dear channel owner,\n\nSome time ago, your channel %s was suspended. This suspend has now expired and your channel has been automatically parted.\n\nThank you for your cooperation,\nThe BotService staff", c->name); MailChannelOwners(c, subject, email); /* Part reason */ eschannel = escapequery(c->name); /* Escape channel */ snprintf(subject, 512, "INSERT INTO `parts` (`channel`, `parter`, `reason`, `time`) VALUES ('%s', 'System', 'Suspend expired (%i)', NOW())", eschannel, atoi(row[0])); dbquery(subject); EndDbQuery(); free(eschannel); c_part(c->name, "Suspend expired"); } else EndDbQuery(); } } /* Remove these suspends */ dbquery("UPDATE `suspends` SET `active` = 0 WHERE `expire` < UNIX_TIMESTAMP() AND `active` = '1'"); EndDbQuery(); } int MailChannelOwners(struct channel *c, char *subject, char *message) { /* Send an E-Mail to all channel owners who have E-Mail set */ struct chanuser *cu; char email[512]; cu = firstchanuser; while (cu != NULL) { if(cu->channel == c && GetUserEmail(cu->uid, email)) { SendEmail(email, subject, message); /* Send E-Mail */ } cu = cu->next; } return 1; }