+bool InspIRCd::ULine(const std::string& sserver)
+{
+ if (sserver.empty())
+ return true;
+
+ return (Config->ulines.find(sserver.c_str()) != Config->ulines.end());
+}
+
+bool InspIRCd::SilentULine(const std::string& sserver)
+{
+ std::map<irc::string,bool>::iterator n = Config->ulines.find(sserver.c_str());
+ if (n != Config->ulines.end())
+ return n->second;
+ else
+ return false;
+}
+
+std::string InspIRCd::TimeString(time_t curtime)
+{
+#ifdef _WIN32
+ if (curtime < 0)
+ curtime = 0;
+#endif
+
+ struct tm* timeinfo = localtime(&curtime);
+ if (!timeinfo)
+ {
+ curtime = 0;
+ timeinfo = localtime(&curtime);
+ }
+
+ // If the calculated year exceeds four digits or is less than the year 1000,
+ // the behavior of asctime() is undefined
+ if (timeinfo->tm_year + 1900 > 9999)
+ timeinfo->tm_year = 9999 - 1900;
+ else if (timeinfo->tm_year + 1900 < 1000)
+ timeinfo->tm_year = 0;
+
+ return std::string(asctime(timeinfo),24);
+}
+
+// You should only pass a single character to this.
+void InspIRCd::AddExtBanChar(char c)
+{
+ std::string &tok = Config->data005;
+ std::string::size_type ebpos = tok.find(" EXTBAN=,");
+
+ if (ebpos == std::string::npos)
+ {
+ tok.append(" EXTBAN=,");
+ tok.push_back(c);
+ }
+ else
+ {
+ ebpos += 9;
+ while (isalpha(tok[ebpos]) && tok[ebpos] < c)
+ ebpos++;
+ tok.insert(ebpos, 1, c);
+ }
+}
+
+std::string InspIRCd::GenRandomStr(int length, bool printable)
+{
+ char* buf = new char[length];
+ GenRandom(buf, length);
+ std::string rv;
+ rv.resize(length);
+ for(int i=0; i < length; i++)
+ rv[i] = printable ? 0x3F + (buf[i] & 0x3F) : buf[i];
+ delete[] buf;
+ return rv;
+}
+
+// NOTE: this has a slight bias for lower values if max is not a power of 2.
+// Don't use it if that matters.
+unsigned long InspIRCd::GenRandomInt(unsigned long max)
+{
+ unsigned long rv;
+ GenRandom((char*)&rv, sizeof(rv));
+ return rv % max;
+}
+
+// This is overridden by a higher-quality algorithm when SSL support is loaded
+void GenRandomHandler::Call(char *output, size_t max)
+{
+ for(unsigned int i=0; i < max; i++)
+#ifdef _WIN32
+ {
+ unsigned int uTemp;
+ if(rand_s(&uTemp) != 0)
+ output[i] = rand();
+ else
+ output[i] = uTemp;
+ }
+#else
+ output[i] = random();
+#endif
+}
+
+ModResult OnCheckExemptionHandler::Call(User* user, Channel* chan, const std::string& restriction)
+{
+ unsigned int mypfx = chan->GetPrefixValue(user);
+ char minmode = 0;
+ std::string current;
+
+ irc::spacesepstream defaultstream(ServerInstance->Config->ConfValue("options")->getString("exemptchanops"));
+
+ while (defaultstream.GetToken(current))
+ {
+ std::string::size_type pos = current.find(':');
+ if (pos == std::string::npos)
+ continue;
+ if (current.substr(0,pos) == restriction)
+ minmode = current[pos+1];
+ }
+
+ ModeHandler* mh = ServerInstance->Modes->FindMode(minmode, MODETYPE_CHANNEL);
+ if (mh && mypfx >= mh->GetPrefixRank())
+ return MOD_RES_ALLOW;
+ if (mh || minmode == '*')
+ return MOD_RES_DENY;
+ return MOD_RES_PASSTHRU;
+}