X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=5383f4aba2b39bed9cd95514896594a574641b17;hb=b844d1cbbe79585facc69b9247baa8427cff0b62;hp=b6912e24530d09a0b9e0d83151dda182d8697adc;hpb=457362304bba836737f2955f7e871cef431a069e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index b6912e245..5383f4aba 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -1,21 +1,16 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. * This program is free but copyrighted software; see - * the file COPYING for details. + * the file COPYING for details. * * --------------------------------------------------- */ -using namespace std; - #include #include "configreader.h" #include "inspircd.h" @@ -27,7 +22,7 @@ using namespace std; chanrec::chanrec(InspIRCd* Instance) : ServerInstance(Instance) { *name = *topic = *setby = *key = 0; - created = topicset = limit = 0; + maxbans = created = topicset = limit = 0; memset(&modes,0,64); age = ServerInstance->Time(true); } @@ -42,21 +37,12 @@ void chanrec::SetMode(char mode,bool mode_on) void chanrec::SetModeParam(char mode,const char* parameter,bool mode_on) { - ServerInstance->Log(DEBUG,"SetModeParam called"); - CustomModeList::iterator n = custom_mode_params.find(mode); if (mode_on) { if (n == custom_mode_params.end()) - { custom_mode_params[mode] = strdup(parameter); - ServerInstance->Log(DEBUG,"Custom mode parameter %c %s added",mode,parameter); - } - else - { - ServerInstance->Log(DEBUG, "Tried to set custom mode parameter for %c '%s' when it was already '%s'", mode, parameter, n->second); - } } else { @@ -75,22 +61,18 @@ bool chanrec::IsModeSet(char mode) std::string chanrec::GetModeParameter(char mode) { - if (mode == 'k') + switch (mode) { - return this->key; - } - else if (mode == 'l') - { - return ConvToStr(this->limit); - } - else - { - CustomModeList::iterator n = custom_mode_params.find(mode); - if (n != custom_mode_params.end()) - { - return n->second; - } - return ""; + case 'k': + return this->key; + case 'l': + return ConvToStr(this->limit); + default: + CustomModeList::iterator n = custom_mode_params.find(mode); + if (n != custom_mode_params.end()) + return n->second; + return ""; + break; } } @@ -222,7 +204,7 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo /* create a new one */ Ptr = new chanrec(Instance); - Instance->chanlist[cname] = Ptr; + (*(Instance->chanlist))[cname] = Ptr; strlcpy(Ptr->name, cname,CHANMAX); @@ -234,7 +216,6 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo *Ptr->topic = 0; *Ptr->setby = 0; Ptr->topicset = 0; - Instance->Log(DEBUG,"chanrec::JoinUser(): created: %s",cname); new_channel = true; } else @@ -312,10 +293,6 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo } } } - else - { - Instance->Log(DEBUG,"chanrec::JoinUser(): Overridden checks"); - } } /* NOTE: If the user is an oper here, we can extend their user->chans by up to @@ -344,14 +321,13 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo if (new_channel) { - Instance->Log(DEBUG,"BLAMMO, Whacking channel."); /* Things went seriously pear shaped, so take this away. bwahaha. */ - chan_hash::iterator n = Instance->chanlist.find(cname); - if (n != Instance->chanlist.end()) + chan_hash::iterator n = Instance->chanlist->find(cname); + if (n != Instance->chanlist->end()) { Ptr->DelUser(user); DELETE(Ptr); - Instance->chanlist.erase(n); + Instance->chanlist->erase(n); } } @@ -390,13 +366,13 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr, userrec* user, con * must stick to ::find(). */ case '@': - user->chans[Ptr] |= STATUS_OP; + user->chans[Ptr] |= UCMODE_OP; break; case '%': - user->chans[Ptr] |= STATUS_HOP; + user->chans[Ptr] |= UCMODE_HOP; break; case '+': - user->chans[Ptr] |= STATUS_VOICE; + user->chans[Ptr] |= UCMODE_VOICE; break; } } @@ -469,13 +445,12 @@ long chanrec::PartUser(userrec *user, const char* reason) if (!this->DelUser(user)) /* if there are no users left on the channel... */ { - chan_hash::iterator iter = ServerInstance->chanlist.find(this->name); + chan_hash::iterator iter = ServerInstance->chanlist->find(this->name); /* kill the record */ - if (iter != ServerInstance->chanlist.end()) + if (iter != ServerInstance->chanlist->end()) { - ServerInstance->Log(DEBUG,"del_channel: destroyed: %s", this->name); FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this)); - ServerInstance->chanlist.erase(iter); + ServerInstance->chanlist->erase(iter); } return 0; } @@ -512,12 +487,12 @@ long chanrec::ServerKickUser(userrec* user, const char* reason, bool triggereven if (!this->DelUser(user)) { - chan_hash::iterator iter = ServerInstance->chanlist.find(this->name); + chan_hash::iterator iter = ServerInstance->chanlist->find(this->name); /* kill the record */ - if (iter != ServerInstance->chanlist.end()) + if (iter != ServerInstance->chanlist->end()) { FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this)); - ServerInstance->chanlist.erase(iter); + ServerInstance->chanlist->erase(iter); } return 0; } @@ -585,13 +560,13 @@ long chanrec::KickUser(userrec *src, userrec *user, const char* reason) if (!this->DelUser(user)) /* if there are no users left on the channel */ { - chan_hash::iterator iter = ServerInstance->chanlist.find(this->name); + chan_hash::iterator iter = ServerInstance->chanlist->find(this->name); /* kill the record */ - if (iter != ServerInstance->chanlist.end()) + if (iter != ServerInstance->chanlist->end()) { FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this)); - ServerInstance->chanlist.erase(iter); + ServerInstance->chanlist->erase(iter); } return 0; } @@ -617,14 +592,18 @@ void chanrec::WriteChannel(userrec* user, char* text, ...) void chanrec::WriteChannel(userrec* user, const std::string &text) { CUList *ulist = this->GetUsers(); + char tb[MAXBUF]; if (!user) return; + snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str()); + std::string out = tb; + for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { if (IS_LOCAL(i->second)) - user->WriteTo(i->second,text); + i->second->Write(out); } } @@ -646,11 +625,15 @@ void chanrec::WriteChannelWithServ(const char* ServName, const char* text, ...) void chanrec::WriteChannelWithServ(const char* ServName, const std::string &text) { CUList *ulist = this->GetUsers(); + char tb[MAXBUF]; + + snprintf(tb,MAXBUF,":%s %s",ServName ? ServName : ServerInstance->Config->ServerName, text.c_str()); + std::string out = tb; for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { if (IS_LOCAL(i->second)) - i->second->WriteServ(text); + i->second->Write(out); } } @@ -689,6 +672,7 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CUList &except_list, const std::string &text) { CUList *ulist; + char tb[MAXBUF]; switch (status) { @@ -706,6 +690,9 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi break; } + snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str()); + std::string out = tb; + for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { if ((IS_LOCAL(i->second)) && (except_list.find(i->second) == except_list.end())) @@ -713,7 +700,7 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi if (serversource) i->second->WriteServ(text); else - i->second->WriteFrom(user,text); + i->second->Write(out); } } } @@ -747,7 +734,7 @@ char* chanrec::ChanModes(bool showkey) static char scratch[MAXBUF]; static char sparam[MAXBUF]; char* offset = scratch; - std::string extparam = ""; + std::string extparam; *scratch = '\0'; *sparam = '\0'; @@ -806,12 +793,9 @@ void chanrec::UserList(userrec *user) return; FOREACH_RESULT(I_OnUserList,OnUserList(user, this)); - ServerInstance->Log(DEBUG,"MOD_RESULT for UserList = %d",MOD_RESULT); if (MOD_RESULT == 1) return; - ServerInstance->Log(DEBUG,"Using builtin NAMES list generation"); - dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name); int numusers = 0; @@ -867,16 +851,29 @@ void chanrec::UserList(userrec *user) long chanrec::GetMaxBans() { + /* Return the cached value if there is one */ + if (this->maxbans) + return this->maxbans; + + /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */ for (std::map::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++) { if (match(this->name,n->first.c_str())) { + this->maxbans = n->second; return n->second; } } - return 64; + + /* Screw it, just return the default of 64 */ + this->maxbans = 64; + return this->maxbans; } +void chanrec::ResetMaxBans() +{ + this->maxbans = 0; +} /* returns the status character for a given user on a channel, e.g. @ for op, * % for halfop etc. If the user has several modes set, the highest mode @@ -1006,7 +1003,6 @@ void chanrec::SetPrefix(userrec* user, char prefix, unsigned int prefix_value, b n->second.erase(x); } } - ServerInstance->Log(DEBUG,"Added prefix %c to %s for %s, prefixlist size is now %d", prefix, this->name, user->nick, prefixes.size()); } void chanrec::RemoveAllPrefixes(userrec* user) @@ -1014,7 +1010,6 @@ void chanrec::RemoveAllPrefixes(userrec* user) prefixlist::iterator n = prefixes.find(user); if (n != prefixes.end()) { - ServerInstance->Log(DEBUG,"Removed prefixes from %s for %s, prefixlist size is now %d", this->name, user->nick, prefixes.size()); prefixes.erase(n); } }