-extern ServerConfig* Config;
-
-/* return 0 or 1 depending if users u and u2 share one or more common channels
- * (used by QUIT, NICK etc which arent channel specific notices) */
-
-int common_channels(userrec *u, userrec *u2)
-{
- if ((!u) || (!u2) || (u->registered != 7) || (u2->registered != 7))
- {
- return 0;
- }
- for (std::vector<ucrec*>::const_iterator i = u->chans.begin(); i != u->chans.end(); i++)
- {
- for (std::vector<ucrec*>::const_iterator z = u2->chans.begin(); z != u2->chans.end(); z++)
- {
- if ((((ucrec*)(*i))->channel != NULL) && (((ucrec*)(*z))->channel != NULL))
- {
- if ((((ucrec*)(*i))->channel == ((ucrec*)(*z))->channel))
- {
- if ((c_count(u)) && (c_count(u2)))
- {
- return 1;
- }
- }
- }
- }
- }
- return 0;
-}
-
-void tidystring(char* str)
-{
- // strips out double spaces before a : parameter
-
- char temp[MAXBUF];
- bool go_again = true;
-
- if (!str)
- return;
-
- // pointer voodoo++ --w00t
- while ((*str) && (*str == ' '))
- str++;
-
- while (go_again)
- {
- bool noparse = false;
- int t = 0, a = 0;
- go_again = false;
- const int lenofstr = strlen(str);
-
- /*
- * by caching strlen() of str, we theoretically avoid 3 expensive calls each time this loop
- * rolls around.. should speed things up a nanosecond or two. ;)
- */
-
- while (a < lenofstr)
- {
- if ((a < lenofstr - 1) && (noparse == false))
- {
- if ((str[a] == ' ') && (str[a+1] == ' '))
- {
- log(DEBUG,"Tidied extra space out of string: %s",str);
- go_again = true;
- a++;
- }
- }
-
- if (a < lenofstr - 1)
- {
- if ((str[a] == ' ') && (str[a+1] == ':'))
- {
- noparse = true;
- }
- }
-
- temp[t++] = str[a++];
- }
-
- temp[t] = '\0';
- strlcpy(str,temp,MAXBUF);
- }
-}
-
-/* chop a string down to 512 characters and preserve linefeed (irc max
- * line length) */
-
-void chop(char* str)
-{
- if (!str)
- {
- log(DEBUG,"ERROR! Null string passed to chop()!");
- return;
- }
- if (strlen(str) >= 511)
- {
- str[510] = '\r';
- str[511] = '\n';
- str[512] = '\0';
- log(DEBUG,"Excess line chopped.");
- }
-}
-
-
-void Blocking(int s)
-{
- int flags = fcntl(s, F_GETFL, 0);
- fcntl(s, F_SETFL, flags ^ O_NONBLOCK);
-}
-
-void NonBlocking(int s)
-{
- int flags = fcntl(s, F_GETFL, 0);
- fcntl(s, F_SETFL, flags | O_NONBLOCK);
-}
-
-int CleanAndResolve (char *resolvedHost, const char *unresolvedHost, bool forward)
-{
- bool ok;
- std::string ipaddr;
-
- DNS d(Config->DNSServer);
- if (forward)
- ok = d.ForwardLookup(unresolvedHost, false);
- else
- ok = d.ReverseLookup(unresolvedHost, false);
- if (!ok)
- return 0;
- time_t T = time(NULL)+1;
- while ((!d.HasResult()) && (time(NULL)<T));
- if (forward)
- ipaddr = d.GetResultIP();
- else
- ipaddr = d.GetResult();
- strlcpy(resolvedHost,ipaddr.c_str(),MAXBUF);
- return (ipaddr != "");
-}
-
-int c_count(userrec* u)
-{
- int z = 0;
- for (std::vector<ucrec*>::const_iterator i = u->chans.begin(); i != u->chans.end(); i++)
- if (((ucrec*)(*i))->channel)
- z++;
- return z;
-
-}
-
-void ChangeName(userrec* user, const char* gecos)
-{
- if (user->fd > -1)
- {
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(user,gecos));
- if (MOD_RESULT)
- return;
- FOREACH_MOD(I_OnChangeName,OnChangeName(user,gecos));
- }
- strlcpy(user->fullname,gecos,MAXGECOS+1);
-}
-
-void ChangeDisplayedHost(userrec* user, const char* host)
-{
- if (user->fd > -1)
- {
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(user,host));
- if (MOD_RESULT)
- return;
- FOREACH_MOD(I_OnChangeHost,OnChangeHost(user,host));
- }
- strlcpy(user->dhost,host,63);
- WriteServ(user->fd,"396 %s %s :is now your hidden host",user->nick,user->dhost);
-}