void User::UnOper() { if (!this->IsOper()) return; /* * unset their oper type (what IS_OPER checks). * note, order is important - this must come before modes as -o attempts * to call UnOper. -- w00t */ oper = NULL; /* Remove all oper only modes from the user when the deoper - Bug #466*/ Modes::ChangeList changelist; const ModeParser::ModeHandlerMap& usermodes = ServerInstance->Modes->GetModes(MODETYPE_USER); for (ModeParser::ModeHandlerMap::const_iterator i = usermodes.begin(); i != usermodes.end(); ++i) { ModeHandler* mh = i->second; if (mh->NeedsOper()) changelist.push_remove(mh); } ServerInstance->Modes->Process(this, NULL, this, changelist); // Remove the user from the oper list stdalgo::vector::swaperase(ServerInstance->Users->all_opers, this); ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER); this->SetMode(opermh, false); }
void User::UnOper() { if (!IS_OPER(this)) return; /* * unset their oper type (what IS_OPER checks). * note, order is important - this must come before modes as -o attempts * to call UnOper. -- w00t */ oper = NULL; /* Remove all oper only modes from the user when the deoper - Bug #466*/ std::string moderemove("-"); for (unsigned char letter = 'A'; letter <= 'z'; letter++) { ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER); if (mh && mh->NeedsOper()) moderemove += letter; } std::vector<std::string> parameters; parameters.push_back(this->nick); parameters.push_back(moderemove); ServerInstance->Parser->CallHandler("MODE", parameters, this); /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */ ServerInstance->Users->all_opers.remove(this); this->modes[UM_OPERATOR] = 0; }
void User::UnOper() { if (!this->IsOper()) return; /* * unset their oper type (what IS_OPER checks). * note, order is important - this must come before modes as -o attempts * to call UnOper. -- w00t */ oper = NULL; /* Remove all oper only modes from the user when the deoper - Bug #466*/ std::string moderemove("-"); for (unsigned char letter = 'A'; letter <= 'z'; letter++) { ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER); if (mh && mh->NeedsOper()) moderemove += letter; } std::vector<std::string> parameters; parameters.push_back(this->nick); parameters.push_back(moderemove); ServerInstance->Modes->Process(parameters, this); // Remove the user from the oper list stdalgo::vector::swaperase(ServerInstance->Users->all_opers, this); ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER); this->SetMode(opermh, false); }
CmdResult Handle (const std::vector<std::string> ¶meters, User *user) { if (parameters.size() > 1 && parameters[1] != ServerInstance->Config->ServerName.c_str()) return CMD_SUCCESS; User *targuser; Channel *targchan; std::string checkstr; std::string chliststr; checkstr = ":" + ServerInstance->Config->ServerName + " 304 " + user->nick + " :CHECK"; targuser = ServerInstance->FindNick(parameters[0]); targchan = ServerInstance->FindChan(parameters[0]); /* * Syntax of a /check reply: * :server.name 304 target :CHECK START <target> * :server.name 304 target :CHECK <field> <value> * :server.name 304 target :CHECK END */ user->SendText(checkstr + " START " + parameters[0]); if (targuser) { LocalUser* loctarg = IS_LOCAL(targuser); /* /check on a user */ user->SendText(checkstr + " nuh " + targuser->GetFullHost()); user->SendText(checkstr + " realnuh " + targuser->GetFullRealHost()); user->SendText(checkstr + " realname " + targuser->fullname); user->SendText(checkstr + " modes +" + targuser->FormatModes()); user->SendText(checkstr + " snomasks " + GetSnomasks(targuser)); user->SendText(checkstr + " server " + targuser->server->GetName()); user->SendText(checkstr + " uid " + targuser->uuid); user->SendText(checkstr + " signon " + timestring(targuser->signon)); user->SendText(checkstr + " nickts " + timestring(targuser->age)); if (loctarg) user->SendText(checkstr + " lastmsg " + timestring(loctarg->idle_lastmsg)); if (targuser->IsAway()) { /* user is away */ user->SendText(checkstr + " awaytime " + timestring(targuser->awaytime)); user->SendText(checkstr + " awaymsg " + targuser->awaymsg); } if (targuser->IsOper()) { OperInfo* oper = targuser->oper; /* user is an oper of type ____ */ user->SendText(checkstr + " opertype " + oper->name); if (loctarg) { std::string umodes; std::string cmodes; for(char c='A'; c < 'z'; c++) { ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_USER); if (mh && mh->NeedsOper() && loctarg->HasModePermission(c, MODETYPE_USER)) umodes.push_back(c); mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL); if (mh && mh->NeedsOper() && loctarg->HasModePermission(c, MODETYPE_CHANNEL)) cmodes.push_back(c); } user->SendText(checkstr + " modeperms user="******" channel=" + cmodes); std::string opcmds; for(std::set<std::string>::iterator i = oper->AllowedOperCommands.begin(); i != oper->AllowedOperCommands.end(); i++) { opcmds.push_back(' '); opcmds.append(*i); } std::stringstream opcmddump(opcmds); user->SendText(checkstr + " commandperms", opcmddump); std::string privs; for(std::set<std::string>::iterator i = oper->AllowedPrivs.begin(); i != oper->AllowedPrivs.end(); i++) { privs.push_back(' '); privs.append(*i); } std::stringstream privdump(privs); user->SendText(checkstr + " permissions", privdump); } } if (loctarg) { user->SendText(checkstr + " clientaddr " + loctarg->client_sa.str()); user->SendText(checkstr + " serveraddr " + loctarg->server_sa.str()); std::string classname = loctarg->GetClass()->name; if (!classname.empty()) user->SendText(checkstr + " connectclass " + classname); } else user->SendText(checkstr + " onip " + targuser->GetIPString()); for (UCListIter i = targuser->chans.begin(); i != targuser->chans.end(); i++) { Channel* c = (*i)->chan; chliststr.append(c->GetPrefixChar(targuser)).append(c->name).append(" "); } std::stringstream dump(chliststr); user->SendText(checkstr + " onchans", dump); dumpExt(user, checkstr, targuser); } else if (targchan) { /* /check on a channel */ user->SendText(checkstr + " timestamp " + timestring(targchan->age)); if (targchan->topic[0] != 0) { /* there is a topic, assume topic related information exists */ user->SendText(checkstr + " topic " + targchan->topic); user->SendText(checkstr + " topic_setby " + targchan->setby); user->SendText(checkstr + " topic_setat " + timestring(targchan->topicset)); } user->SendText(checkstr + " modes " + targchan->ChanModes(true)); user->SendText(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter())); /* now the ugly bit, spool current members of a channel. :| */ const UserMembList *ulist= targchan->GetUsers(); /* note that unlike /names, we do NOT check +i vs in the channel */ for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++) { /* * Unlike Asuka, I define a clone as coming from the same host. --w00t */ user->SendText("%s member %-3lu %s%s (%s@%s) %s ", checkstr.c_str(), ServerInstance->Users->GlobalCloneCount(i->first), targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(), i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str()); } const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes(); for (ModeParser::ListModeList::const_iterator i = listmodes.begin(); i != listmodes.end(); ++i) dumpListMode(user, checkstr, (*i)->GetList(targchan)); dumpExt(user, checkstr, targchan); } else { /* /check on an IP address, or something that doesn't exist */ long x = 0; /* hostname or other */ for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++) { if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map)) { /* host or vhost matches mask */ user->SendText(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->fullname); } /* IP address */ else if (InspIRCd::MatchCIDR(a->second->GetIPString(), parameters[0])) { /* same IP. */ user->SendText(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->fullname); } } user->SendText(checkstr + " matches " + ConvToStr(x)); } user->SendText(checkstr + " END " + parameters[0]); return CMD_SUCCESS; }
void CommandStats::DoStats(char statschar, User* user, string_list &results) { bool isPublic = ServerInstance->Config->UserStats.find(statschar) != std::string::npos; bool isRemoteOper = IS_REMOTE(user) && (user->IsOper()); bool isLocalOperWithPrivs = IS_LOCAL(user) && user->HasPrivPermission("servers/auspex"); if (!isPublic && !isRemoteOper && !isLocalOperWithPrivs) { ServerInstance->SNO->WriteToSnoMask('t', "%s '%c' denied for %s (%s@%s)", (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->host.c_str()); results.push_back("481 " + user->nick + " :Permission denied - STATS " + statschar + " requires the servers/auspex priv."); return; } ModResult MOD_RESULT; FIRST_MOD_RESULT(OnStats, MOD_RESULT, (statschar, user, results)); if (MOD_RESULT == MOD_RES_DENY) { results.push_back("219 "+user->nick+" "+statschar+" :End of /STATS report"); ServerInstance->SNO->WriteToSnoMask('t',"%s '%c' requested by %s (%s@%s)", (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->host.c_str()); return; } switch (statschar) { /* stats p (show listening ports) */ case 'p': { for (std::vector<ListenSocket*>::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i) { ListenSocket* ls = *i; std::string ip = ls->bind_addr; if (ip.empty()) ip.assign("*"); std::string type = ls->bind_tag->getString("type", "clients"); std::string hook = ls->bind_tag->getString("ssl", "plaintext"); results.push_back("249 "+user->nick+" :"+ ip + ":"+ConvToStr(ls->bind_port)+ " (" + type + ", " + hook + ")"); } } break; /* These stats symbols must be handled by a linking module */ case 'n': case 'c': break; case 'i': { for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) { ConnectClass* c = *i; std::stringstream res; res << "215 " << user->nick << " I " << c->name << ' '; if (c->type == CC_ALLOW) res << '+'; if (c->type == CC_DENY) res << '-'; if (c->type == CC_NAMED) res << '*'; else res << c->host; res << ' ' << c->config->getString("port", "*") << ' '; res << c->GetRecvqMax() << ' ' << c->GetSendqSoftMax() << ' ' << c->GetSendqHardMax() << ' ' << c->GetCommandRate() << ' ' << c->GetPenaltyThreshold(); if (c->fakelag) res << '*'; results.push_back(res.str()); } } break; case 'Y': { int idx = 0; for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) { ConnectClass* c = *i; results.push_back("215 "+user->nick+" i NOMATCH * "+c->GetHost()+" "+ConvToStr(c->limit ? c->limit : SocketEngine::GetMaxFds())+" "+ConvToStr(idx)+" "+ServerInstance->Config->ServerName+" *"); results.push_back("218 "+user->nick+" Y "+ConvToStr(idx)+" "+ConvToStr(c->GetPingTime())+" 0 "+ConvToStr(c->GetSendqHardMax())+" :"+ ConvToStr(c->GetRecvqMax())+" "+ConvToStr(c->GetRegTimeout())); idx++; } } break; case 'P': { unsigned int idx = 0; const UserManager::OperList& opers = ServerInstance->Users->all_opers; for (UserManager::OperList::const_iterator i = opers.begin(); i != opers.end(); ++i) { User* oper = *i; if (!oper->server->IsULine()) { LocalUser* lu = IS_LOCAL(oper); results.push_back("249 " + user->nick + " :" + oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " + (lu ? ConvToStr(ServerInstance->Time() - lu->idle_lastmsg) + " secs" : "unavailable")); idx++; } } results.push_back("249 "+user->nick+" :"+ConvToStr(idx)+" OPER(s)"); } break; case 'k': ServerInstance->XLines->InvokeStats("K",216,user,results); break; case 'g': ServerInstance->XLines->InvokeStats("G",223,user,results); break; case 'q': ServerInstance->XLines->InvokeStats("Q",217,user,results); break; case 'Z': ServerInstance->XLines->InvokeStats("Z",223,user,results); break; case 'e': ServerInstance->XLines->InvokeStats("E",223,user,results); break; case 'E': { const SocketEngine::Statistics& stats = SocketEngine::GetStats(); results.push_back("249 "+user->nick+" :Total events: "+ConvToStr(stats.TotalEvents)); results.push_back("249 "+user->nick+" :Read events: "+ConvToStr(stats.ReadEvents)); results.push_back("249 "+user->nick+" :Write events: "+ConvToStr(stats.WriteEvents)); results.push_back("249 "+user->nick+" :Error events: "+ConvToStr(stats.ErrorEvents)); break; } /* stats m (list number of times each command has been used, plus bytecount) */ case 'm': for (Commandtable::iterator i = ServerInstance->Parser->cmdlist.begin(); i != ServerInstance->Parser->cmdlist.end(); i++) { if (i->second->use_count) { /* RPL_STATSCOMMANDS */ results.push_back("212 "+user->nick+" "+i->second->name+" "+ConvToStr(i->second->use_count)); } } break; /* stats z (debug and memory info) */ case 'z': { results.push_back("249 "+user->nick+" :Users: "+ConvToStr(ServerInstance->Users->GetUsers().size())); results.push_back("249 "+user->nick+" :Channels: "+ConvToStr(ServerInstance->GetChans().size())); results.push_back("249 "+user->nick+" :Commands: "+ConvToStr(ServerInstance->Parser->cmdlist.size())); float kbitpersec_in, kbitpersec_out, kbitpersec_total; char kbitpersec_in_s[30], kbitpersec_out_s[30], kbitpersec_total_s[30]; SocketEngine::GetStats().GetBandwidth(kbitpersec_in, kbitpersec_out, kbitpersec_total); snprintf(kbitpersec_total_s, 30, "%03.5f", kbitpersec_total); snprintf(kbitpersec_out_s, 30, "%03.5f", kbitpersec_out); snprintf(kbitpersec_in_s, 30, "%03.5f", kbitpersec_in); results.push_back("249 "+user->nick+" :Bandwidth total: "+ConvToStr(kbitpersec_total_s)+" kilobits/sec"); results.push_back("249 "+user->nick+" :Bandwidth out: "+ConvToStr(kbitpersec_out_s)+" kilobits/sec"); results.push_back("249 "+user->nick+" :Bandwidth in: "+ConvToStr(kbitpersec_in_s)+" kilobits/sec"); #ifndef _WIN32 /* Moved this down here so all the not-windows stuff (look w00tie, I didn't say win32!) is in one ifndef. * Also cuts out some identical code in both branches of the ifndef. -- Om */ rusage R; /* Not sure why we were doing '0' with a RUSAGE_SELF comment rather than just using RUSAGE_SELF -- Om */ if (!getrusage(RUSAGE_SELF,&R)) /* RUSAGE_SELF */ { results.push_back("249 "+user->nick+" :Total allocation: "+ConvToStr(R.ru_maxrss)+"K"); results.push_back("249 "+user->nick+" :Signals: "+ConvToStr(R.ru_nsignals)); results.push_back("249 "+user->nick+" :Page faults: "+ConvToStr(R.ru_majflt)); results.push_back("249 "+user->nick+" :Swaps: "+ConvToStr(R.ru_nswap)); results.push_back("249 "+user->nick+" :Context Switches: Voluntary; "+ConvToStr(R.ru_nvcsw)+" Involuntary; "+ConvToStr(R.ru_nivcsw)); char percent[30]; float n_elapsed = (ServerInstance->Time() - ServerInstance->stats->LastSampled.tv_sec) * 1000000 + (ServerInstance->Time_ns() - ServerInstance->stats->LastSampled.tv_nsec) / 1000; float n_eaten = ((R.ru_utime.tv_sec - ServerInstance->stats->LastCPU.tv_sec) * 1000000 + R.ru_utime.tv_usec - ServerInstance->stats->LastCPU.tv_usec); float per = (n_eaten / n_elapsed) * 100; snprintf(percent, 30, "%03.5f%%", per); results.push_back("249 "+user->nick+" :CPU Use (now): "+percent); n_elapsed = ServerInstance->Time() - ServerInstance->startup_time; n_eaten = (float)R.ru_utime.tv_sec + R.ru_utime.tv_usec / 100000.0; per = (n_eaten / n_elapsed) * 100; snprintf(percent, 30, "%03.5f%%", per); results.push_back("249 "+user->nick+" :CPU Use (total): "+percent); } #else PROCESS_MEMORY_COUNTERS MemCounters; if (GetProcessMemoryInfo(GetCurrentProcess(), &MemCounters, sizeof(MemCounters))) { results.push_back("249 "+user->nick+" :Total allocation: "+ConvToStr((MemCounters.WorkingSetSize + MemCounters.PagefileUsage) / 1024)+"K"); results.push_back("249 "+user->nick+" :Pagefile usage: "+ConvToStr(MemCounters.PagefileUsage / 1024)+"K"); results.push_back("249 "+user->nick+" :Page faults: "+ConvToStr(MemCounters.PageFaultCount)); } FILETIME CreationTime; FILETIME ExitTime; FILETIME KernelTime; FILETIME UserTime; LARGE_INTEGER ThisSample; if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) && QueryPerformanceCounter(&ThisSample)) { KernelTime.dwHighDateTime += UserTime.dwHighDateTime; KernelTime.dwLowDateTime += UserTime.dwLowDateTime; double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000; double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart; double per = (n_eaten/n_elapsed); char percent[30]; snprintf(percent, 30, "%03.5f%%", per); results.push_back("249 "+user->nick+" :CPU Use (now): "+percent); n_elapsed = ServerInstance->Time() - ServerInstance->startup_time; n_eaten = (double)(( (uint64_t)(KernelTime.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime))/100000; per = (n_eaten / n_elapsed); snprintf(percent, 30, "%03.5f%%", per); results.push_back("249 "+user->nick+" :CPU Use (total): "+percent); } #endif } break; case 'T': { results.push_back("249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats->statsAccept)+" refused "+ConvToStr(ServerInstance->stats->statsRefused)); results.push_back("249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats->statsUnknown)); results.push_back("249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats->statsCollisions)); results.push_back("249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats->statsDnsGood+ServerInstance->stats->statsDnsBad)+" succeeded "+ConvToStr(ServerInstance->stats->statsDnsGood)+" failed "+ConvToStr(ServerInstance->stats->statsDnsBad)); results.push_back("249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats->statsConnects)); results.push_back(InspIRCd::Format("249 %s :bytes sent %5.2fK recv %5.2fK", user->nick.c_str(), ServerInstance->stats->statsSent / 1024.0, ServerInstance->stats->statsRecv / 1024.0)); } break; /* stats o */ case 'o': { ConfigTagList tags = ServerInstance->Config->ConfTags("oper"); for(ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* tag = i->second; results.push_back("243 "+user->nick+" O "+tag->getString("host")+" * "+ tag->getString("name") + " " + tag->getString("type")+" 0"); } } break; case 'O': { for (OperIndex::const_iterator i = ServerInstance->Config->OperTypes.begin(); i != ServerInstance->Config->OperTypes.end(); ++i) { OperInfo* tag = i->second; tag->init(); std::string umodes; std::string cmodes; for(char c='A'; c < 'z'; c++) { ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_USER); if (mh && mh->NeedsOper() && tag->AllowedUserModes[c - 'A']) umodes.push_back(c); mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL); if (mh && mh->NeedsOper() && tag->AllowedChanModes[c - 'A']) cmodes.push_back(c); } results.push_back("243 "+user->nick+" O "+tag->name.c_str() + " " + umodes + " " + cmodes); } } break; /* stats l (show user I/O stats) */ case 'l': results.push_back("211 "+user->nick+" :nick[ident@host] sendq cmds_out bytes_out cmds_in bytes_in time_open"); for (LocalUserList::iterator n = ServerInstance->Users->local_users.begin(); n != ServerInstance->Users->local_users.end(); n++) { LocalUser* i = *n; results.push_back("211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->dhost+"] "+ConvToStr(i->eh.getSendQSize())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(ServerInstance->Time() - i->age)); } break; /* stats L (show user I/O stats with IP addresses) */ case 'L': results.push_back("211 "+user->nick+" :nick[ident@ip] sendq cmds_out bytes_out cmds_in bytes_in time_open"); for (LocalUserList::iterator n = ServerInstance->Users->local_users.begin(); n != ServerInstance->Users->local_users.end(); n++) { LocalUser* i = *n; results.push_back("211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->GetIPString()+"] "+ConvToStr(i->eh.getSendQSize())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(ServerInstance->Time() - i->age)); } break; /* stats u (show server uptime) */ case 'u': { time_t current_time = 0; current_time = ServerInstance->Time(); time_t server_uptime = current_time - ServerInstance->startup_time; struct tm* stime; stime = gmtime(&server_uptime); /* i dont know who the hell would have an ircd running for over a year nonstop, but * Craig suggested this, and it seemed a good idea so in it went */ if (stime->tm_year > 70) { results.push_back(InspIRCd::Format("242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d", user->nick.c_str(), stime->tm_year - 70, stime->tm_yday, stime->tm_hour, stime->tm_min, stime->tm_sec)); } else { results.push_back(InspIRCd::Format("242 %s :Server up %d days, %.2d:%.2d:%.2d", user->nick.c_str(), stime->tm_yday, stime->tm_hour, stime->tm_min, stime->tm_sec)); } } break; default: break; } results.push_back("219 "+user->nick+" "+statschar+" :End of /STATS report"); ServerInstance->SNO->WriteToSnoMask('t',"%s '%c' requested by %s (%s@%s)", (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->host.c_str()); return; }
ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool adding, const unsigned char modechar, std::string ¶meter, bool SkipACL) { ModeType type = chan ? MODETYPE_CHANNEL : MODETYPE_USER; ModeHandler *mh = FindMode(modechar, type); int pcnt = mh->GetNumParams(adding); // crop mode parameter size to 250 characters if (parameter.length() > 250 && adding) parameter = parameter.substr(0, 250); ModResult MOD_RESULT; FIRST_MOD_RESULT(OnRawMode, MOD_RESULT, (user, chan, modechar, parameter, adding, pcnt)); if (IS_LOCAL(user) && (MOD_RESULT == MOD_RES_DENY)) return MODEACTION_DENY; if (chan && !SkipACL && (MOD_RESULT != MOD_RES_ALLOW)) { MOD_RESULT = mh->AccessCheck(user, chan, parameter, adding); if (MOD_RESULT == MOD_RES_DENY) return MODEACTION_DENY; if (MOD_RESULT == MOD_RES_PASSTHRU) { unsigned int neededrank = mh->GetLevelRequired(); /* Compare our rank on the channel against the rank of the required prefix, * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown * in NAMES(X) are not in rank order, we know the most powerful mode is listed * first, so we don't need to iterate, we just look up the first instead. */ unsigned int ourrank = chan->GetPrefixValue(user); if (ourrank < neededrank) { PrefixMode* neededmh = NULL; for(char c='A'; c <= 'z'; c++) { PrefixMode* privmh = FindPrefixMode(c); if (privmh && privmh->GetPrefixRank() >= neededrank) { // this mode is sufficient to allow this action if (!neededmh || privmh->GetPrefixRank() < neededmh->GetPrefixRank()) neededmh = privmh; } } if (neededmh) user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have channel %s access or above to %sset channel mode %c", user->nick.c_str(), chan->name.c_str(), neededmh->name.c_str(), adding ? "" : "un", modechar); else user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You cannot %sset channel mode %c", user->nick.c_str(), chan->name.c_str(), adding ? "" : "un", modechar); return MODEACTION_DENY; } } } // Ask mode watchers whether this mode change is OK std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mh->name); for (ModeWatchIter i = itpair.first; i != itpair.second; ++i) { ModeWatcher* mw = i->second; if (mw->GetModeType() == type) { if (!mw->BeforeMode(user, targetuser, chan, parameter, adding)) return MODEACTION_DENY; // A module whacked the parameter completely, and there was one. Abort. if (pcnt && parameter.empty()) return MODEACTION_DENY; } } if (IS_LOCAL(user) && !user->IsOper()) { char* disabled = (type == MODETYPE_CHANNEL) ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes; if (disabled[modechar - 'A']) { user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - %s mode %c has been locked by the administrator", user->nick.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar); return MODEACTION_DENY; } } if (adding && IS_LOCAL(user) && mh->NeedsOper() && !user->HasModePermission(modechar, type)) { /* It's an oper only mode, and they don't have access to it. */ if (user->IsOper()) { user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper type %s does not have access to set %s mode %c", user->nick.c_str(), user->oper->name.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar); } else { user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Only operators may set %s mode %c", user->nick.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar); } return MODEACTION_DENY; } /* Call the handler for the mode */ ModeAction ma = mh->OnModeChange(user, targetuser, chan, parameter, adding); if (pcnt && parameter.empty()) return MODEACTION_DENY; if (ma != MODEACTION_ALLOW) return ma; if ((!mh->IsListMode()) && (mh->GetNumParams(true)) && (chan)) chan->SetModeParam(mh, (adding ? parameter : "")); itpair = modewatchermap.equal_range(mh->name); for (ModeWatchIter i = itpair.first; i != itpair.second; ++i) { ModeWatcher* mw = i->second; if (mw->GetModeType() == type) mw->AfterMode(user, targetuser, chan, parameter, adding); } return MODEACTION_ALLOW; }