]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Replaced sprintf's with some char* voodoo
[user/henk/code/inspircd.git] / src / users.cpp
index a36ad96f797b1bddb49807c33f7f98e8b9075470..256b04780a2ae333aa3b61b5a73392a3f64c1478 100644 (file)
@@ -80,6 +80,18 @@ userrec::~userrec()
 {
 }
 
+void userrec::MakeHost(char* nhost)
+{
+       /* This is much faster than snprintf */
+       char* t = nhost;
+       for(char* n = ident; n; n++)
+               *t++ = *n;
+       *t++ = '@';
+       for(char* n = host; n; n++)
+               *t++ = *n;
+       *t = 0;
+}
+
 void userrec::CloseSocket()
 {
        shutdown(this->fd,2);
@@ -89,7 +101,16 @@ void userrec::CloseSocket()
 char* userrec::GetFullHost()
 {
        static char result[MAXBUF];
-       snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
+       char* t = result;
+       for(char* n = nick; n; n++)
+               *t++ = *n;
+       *t++ = '!';
+       for(char* n = ident; n; n++)
+               *t++ = *n;
+       *t++ = '@';
+       for(char* n = dhost; n; n++)
+               *t++ = *n;
+       *t = 0;
        return result;
 }
 
@@ -106,7 +127,16 @@ int userrec::ReadData(void* buffer, size_t size)
 char* userrec::GetFullRealHost()
 {
        static char fresult[MAXBUF];
-       snprintf(fresult,MAXBUF,"%s!%s@%s",nick,ident,host);
+       char* t = fresult;
+       for(char* n = nick; n; n++)
+               *t++ = *n;
+       *t++ = '!';
+       for(char* n = ident; n; n++)
+               *t++ = *n;
+       *t++ = '@';
+       for(char* n = host; n; n++)
+               *t++ = *n;
+       *t = 0;
        return fresult;
 }
 
@@ -284,7 +314,7 @@ void userrec::AddWriteBuf(std::string data)
 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
 void userrec::FlushWriteBuf()
 {
-       if (sendq.length())
+       if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
        {
                char* tb = (char*)this->sendq.c_str();
                int n_sent = write(this->fd,tb,this->sendq.length());
@@ -467,7 +497,8 @@ void AddWhoWas(userrec* u)
         strlcpy(a->dhost,u->dhost,160);
         strlcpy(a->host,u->host,160);
         strlcpy(a->fullname,u->fullname,MAXGECOS);
-        strlcpy(a->server,u->server,256);
+       if (u->server)
+               strlcpy(a->server,u->server,256);
         a->signon = u->signon;
 
         /* MAX_WHOWAS:   max number of /WHOWAS items
@@ -642,16 +673,18 @@ void FullConnectUser(userrec* user, CullList* Goners)
         user->idle_lastmsg = TIME;
         log(DEBUG,"ConnectUser: %s",user->nick);
 
-        if ((strcmp(Passwd(user),"")) && (!user->haspassed))
+       ConnectClass a = GetClass(user);
+       
+       if (a.type == CC_DENY)
+       {
+               Goners->AddItem(user,"Unauthorised connection");
+               return;
+       }
+       if ((*(a.pass.c_str())) && (!user->haspassed))
         {
                Goners->AddItem(user,"Invalid password");
                 return;
         }
-        if (IsDenied(user))
-        {
-               Goners->AddItem(user,"Unauthorised connection");
-                return;
-        }
 
         char match_against[MAXBUF];
         snprintf(match_against,MAXBUF,"%s@%s",user->ident,user->host);
@@ -681,7 +714,7 @@ void FullConnectUser(userrec* user, CullList* Goners)
         WriteServ(user->fd,"001 %s :Welcome to the %s IRC Network %s!%s@%s",user->nick,Config->Network,user->nick,user->ident,user->host);
         WriteServ(user->fd,"002 %s :Your host is %s, running version %s",user->nick,Config->ServerName,VERSION);
         WriteServ(user->fd,"003 %s :This server was created %s %s",user->nick,__TIME__,__DATE__);
-        WriteServ(user->fd,"004 %s %s %s iowghraAsORVSxNCWqBzvdHtGI lvhopsmntikrRcaqOALQbSeKVfHGCuzN",user->nick,Config->ServerName,VERSION);
+        WriteServ(user->fd,"004 %s %s %s iowghrasxRVSCWBG lvhopsmntikrcaqbegIOLQRSKVHGCNT vhobeIaqglk",user->nick,Config->ServerName,VERSION);
         // anfl @ #ratbox, efnet reminded me that according to the RFC this cant contain more than 13 tokens per line...
         // so i'd better split it :)
         std::stringstream out(Config->data005);
@@ -710,17 +743,6 @@ void FullConnectUser(userrec* user, CullList* Goners)
         WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,user->ip);
 }
 
-
-/* shows the message of the day, and any other on-logon stuff */
-//void ConnectUser(userrec *user)
-//{
-        // dns is already done, things are fast. no need to wait for dns to complete just pass them straight on
-        //if ((user->dns_done) && (user->registered >= 3) && (AllModulesReportReady(user)))
-        //{
-        //        FullConnectUser(user, Goners);
-        //}
-//}
-
 /* re-allocates a nick in the user_hash after they change nicknames,
  * returns a pointer to the new user as it may have moved */