/* * channels.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" /* Channel levels: 1: Channel friend 2: Channel voice 3: Channel op 4: Channel master 5. Channel owner */ void setrightmode(struct activechanuser *acu, struct activeuser *u) { int chanlev = 0; if(acu != NULL && acu->channel != NULL && acu->channel->isop == 1 && acu->channel->arm->id != 1) { chanlev = chanuserlevel(acu->user, acu->channel); if (acu->channel->autovoice == 1 && chanlev == CHAN_VOICE && acu->voice == 0) voice(acu->channel->name, acu->user->nick); else if (acu->channel->autoop == 1 && chanlev >= CHAN_OP && acu->op == 0) op(acu->channel->name, acu->user->nick); return; } #ifdef MAIN if(acu == NULL || acu->channel->arm->id == 1) { if (u->auth >= TECHNICIAN && u->auth < BOT_NORMAL && u->auth != IRC_OPERATOR) (acu == NULL) ? op(HOMECHAN, u->nick) : op(acu->channel->name, u->nick); else if (u->auth == QUEUE_WORKER || u->auth == HELPER || u->auth == SERVICE_FRIEND) (acu == NULL) ? voice(HOMECHAN, u->nick) : voice(acu->channel->name, u->nick); } #endif } int c_join (char *channame, struct arm *a) { char query[MAX_QUERY]; char *eschanname; if(a->channels+1 == MAXCHANS) return 0; if((strstr(channame, "'") != NULL) || (strstr(channame, "\\") != NULL) || (strstr(channame, ",") != NULL) || strcasecmp(channame, HOMECHAN) == 0) return 0; if (findchannel(channame) == NULL) { eschanname = escapequery(channame); sprintf(query, "SELECT `id` FROM `channels` WHERE `name` = '%s'", eschanname); Free(eschanname); dbquery(query); if((row = mysql_fetch_row(res))) return 0; EndDbQuery(); adddbchannel(channame, a); // We add the channel to the database loadchannel(channame); // Load that channel joinchannel(findchannel(channame)); // Now we join the channel return 1; } else return 0; // We are already on that channel, stupid } int c_part (char *channame, char *reason) { struct channel *c; c = findchannel(channame); if (c != NULL) { --c->arm->channels; // Decrease global channels counter partchannel(c, reason); // Now we part the channel delallachanusers(c); // We delete all active channel users in memory deldbchannel(channame); // We remove the channel to the database delchannel(c); // Delete the channel from memory return 1; } else return 0; // We are not on that channel, stupid } int c_move (char *from, char *to) { struct channel *c; char reason[512]; char query[MAX_QUERY]; c = findchannel(from); if (c != NULL) { if(findchannel(to) != NULL || strcasecmp(to, HOMECHAN) == 0) return 2; sprintf(query, "UPDATE `channels` SET `name` = '%s' WHERE id = '%i'", to, c->id); dbquery(query); // Update database EndDbQuery(); snprintf(reason, 512, "Moving to: %s", to); delallachanusers(c); // We delete all active channel users in memory --c->arm->channels; // Decrease global channels counter partchannel(c, reason); // Now we part the channel strncpy(c->name, to, CHANNELLEN); // Update memory joinchannel(c); // Join the new channel return 1; } else return 0; // We are not on that channel, stupid } void c_setlev (int uid, char *channame, int level) { char query[MAX_QUERY]; struct channel *c; struct chanuser *cu; c = findchannel(channame); if(c == NULL) return; cu = findchanuser(uid, c); if (cu == NULL) { /* Oki, the user is not in memory (and the hopefully not in database). What do we do now? */ sprintf(query, "INSERT INTO `chanusers` (`cid`, `uid`, `level`, `sid`) VALUES ('%d', '%d', '%d', '%s')", c->id, uid, level, SID); dbquery(query); EndDbQuery(); addchanuser(c, uid, level, ""); } else { sprintf(query, "UPDATE `chanusers` SET `level` = '%d' WHERE uid = '%d' AND cid = '%d'", level, uid, c->id); dbquery(query); EndDbQuery(); cu->level = level; } } void c_setgreet (int uid, char *channame, char *greet) { char query[MAX_QUERY]; struct channel *c; struct chanuser *cu; char *esgreet; c = findchannel(channame); cu = findchanuser(uid, c); if (cu != NULL) { esgreet = escapequery(greet); snprintf(query, MAX_QUERY, "UPDATE `chanusers` SET `greet` = '%s' WHERE uid = '%d' AND cid = '%i'", esgreet, uid, c->id); Free(esgreet); dbquery(query); EndDbQuery(); if(cu->greet != NULL) Free(cu->greet); cu->greet = DupString(greet); } } void PartAllArmChannels(struct arm *a) { /* Part all channels that an arm is on */ struct channel *c, *next; for(c = firstchan; c != NULL; c = next) { next = c->next; if(c->arm == a) c_part(c->name, "ARM Removed"); } }