X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fhelperfuncs.cpp;h=d96c068ed445e8693c63b45392d7dcaceb284a74;hb=e80337c204adbe3ff4b38eafed777ba2f8bac6fb;hp=07f9228d479323b39726572d2f529b387d605ea6;hpb=b3d269e6ae329f7caaa11139873afd3e216cf9d3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 07f9228d4..d96c068ed 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -2,45 +2,22 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits * - * 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. * * --------------------------------------------------- */ #include -#include "inspircd_config.h" #include "configreader.h" -#include -#include -#include -#include -#include -#include -#include -#ifdef HAS_EXECINFO -#include -#endif -#include "connection.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" #include "wildcard.h" #include "mode.h" #include "xline.h" -#include "commands.h" -#include "inspstring.h" - -#include "hashcomp.h" -#include "typedefs.h" #include "inspircd.h" static char TIMESTR[26]; @@ -52,11 +29,15 @@ static time_t LAST = 0; */ void InspIRCd::Log(int level, const char* text, ...) { + /* Do this check again here so that we save pointless vsnprintf calls */ + if ((level < Config->LogLevel) && !Config->forcedebug) + return; + va_list argsPtr; - char textbuffer[MAXBUF]; + char textbuffer[65536]; va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); + vsnprintf(textbuffer, 65536, text, argsPtr); va_end(argsPtr); this->Log(level, std::string(textbuffer)); @@ -190,7 +171,7 @@ void InspIRCd::WriteMode(const char* modes, int flags, const char* text, ...) int modelen; va_list argsPtr; - if ((!text) || (!modes) || (!flags)) + if (!text || !modes || !flags) { this->Log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter"); return; @@ -201,14 +182,12 @@ void InspIRCd::WriteMode(const char* modes, int flags, const char* text, ...) va_end(argsPtr); modelen = strlen(modes); - for (std::vector::const_iterator i = local_users.begin(); i != local_users.end(); i++) + if (flags == WM_AND) { - userrec* t = (userrec*)(*i); - bool send_to_user = false; - - if (flags == WM_AND) + for (std::vector::const_iterator i = local_users.begin(); i != local_users.end(); i++) { - send_to_user = true; + userrec* t = *i; + bool send_to_user = true; for (int n = 0; n < modelen; n++) { @@ -218,10 +197,17 @@ void InspIRCd::WriteMode(const char* modes, int flags, const char* text, ...) break; } } + if (send_to_user) + t->WriteServ("NOTICE %s :%s",t->nick,textbuffer); } - else if (flags == WM_OR) + } + else + if (flags == WM_OR) + { + for (std::vector::const_iterator i = local_users.begin(); i != local_users.end(); i++) { - send_to_user = false; + userrec* t = *i; + bool send_to_user = false; for (int n = 0; n < modelen; n++) { @@ -231,11 +217,8 @@ void InspIRCd::WriteMode(const char* modes, int flags, const char* text, ...) break; } } - } - - if (send_to_user) - { - t->WriteServ("NOTICE %s :%s",t->nick,textbuffer); + if (send_to_user) + t->WriteServ("NOTICE %s :%s",t->nick,textbuffer); } } } @@ -329,13 +312,7 @@ int InspIRCd::UserCount() int InspIRCd::RegisteredUserCount() { int c = 0; - - for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++) - { - c += (i->second->registered == REG_ALL); - } - - return c; + return this->UnregisteredUserCount() - clientlist.size(); } int InspIRCd::InvisibleUserCount() @@ -428,6 +405,34 @@ bool InspIRCd::IsChannel(const char *chname) return true; } +bool InspIRCd::IsNick(const char* n) +{ + if (!n || !*n) + return false; + + int p = 0; + for (char* i = (char*)n; *i; i++, p++) + { + if ((*i >= 'A') && (*i <= '}')) + { + /* "A"-"}" can occur anywhere in a nickname */ + continue; + } + + if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n)) + { + /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */ + continue; + } + + /* invalid character! abort */ + return false; + } + + /* too long? or not -- pointer arithmetic rocks */ + return (p < NICKMAX - 1); +} + void InspIRCd::OpenLog(char** argv, int argc) { if (!*this->LogFileName) @@ -436,26 +441,17 @@ void InspIRCd::OpenLog(char** argv, int argc) { Config->logpath = ServerConfig::GetFullProgDir(argv,argc) + "/ircd.log"; } + + Config->log_file = fopen(Config->logpath.c_str(),"a+"); } else { Config->log_file = fopen(this->LogFileName,"a+"); - - if (!Config->log_file) - { - printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str()); - Exit(ERROR); - } - - this->Logger = new FileLogger(this, Config->log_file); - return; } - Config->log_file = fopen(Config->logpath.c_str(),"a+"); - if (!Config->log_file) { - printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str()); + printf("ERROR: Could not write to logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno)); Exit(ERROR); } @@ -505,3 +501,25 @@ void InspIRCd::LoadAllModules() this->Log(DEFAULT,"Total loaded modules: %d", this->ModCount+1); } +void InspIRCd::SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text) +{ + std::string copy_text = text; + + int MOD_RESULT = 0; + FOREACH_RESULT_I(this, I_OnWhoisLine, OnWhoisLine(user, dest, numeric, copy_text)); + + if (!MOD_RESULT) + user->WriteServ("%d %s", numeric, copy_text.c_str()); +} + +void InspIRCd::SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...) +{ + char textbuffer[MAXBUF]; + va_list argsPtr; + va_start (argsPtr, format); + vsnprintf(textbuffer, MAXBUF, format, argsPtr); + va_end(argsPtr); + + this->SendWhoisLine(user, dest, numeric, std::string(textbuffer)); +} +