]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Remove unneccessary temp value which caused a win32 problem by using uint32_t type.
[user/henk/code/inspircd.git] / src / users.cpp
index ff417a8a3ca1ff13936506a431b4212bdc0732c8..f7b6467548062d75184aa174cd83ee856fd2a4e9 100644 (file)
@@ -82,7 +82,7 @@ std::string User::ProcessNoticeMasks(const char *sm)
                                        }
                                }
                                else
-                                       this->WriteNumeric(501, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
+                                       this->WriteNumeric(ERR_UNKNOWNSNOMASK, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
 
                                oldadding = adding;
                        break;
@@ -933,13 +933,13 @@ void User::FullConnect()
                return;
 
        this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
-       this->WriteNumeric(001, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick.c_str(), ServerInstance->Config->Network, this->nick.c_str(), this->ident.c_str(), this->host.c_str());
-       this->WriteNumeric(002, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
-       this->WriteNumeric(003, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
-       this->WriteNumeric(004, "%s %s InspIRCd-1.2 %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
+       this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick.c_str(), ServerInstance->Config->Network, this->nick.c_str(), this->ident.c_str(), this->host.c_str());
+       this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
+       this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
+       this->WriteNumeric(RPL_SERVERVERSION, "%s %s InspIRCd-1.2 %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
 
        ServerInstance->Config->Send005(this);
-       this->WriteNumeric(42, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
+       this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
 
 
        this->ShowMOTD();
@@ -1103,7 +1103,7 @@ int User::GetProtocolFamily()
 
 const char* User::GetCIDRMask(int range)
 {
-       static char buf[40];
+       static char buf[44];
 
        if (this->ip == NULL)
                return "";
@@ -1162,7 +1162,7 @@ const char* User::GetCIDRMask(int range)
                        /* And finally, zero the extra bits required. */
                        v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
 
-                       sprintf(buf, "%s/%d\n", inet_ntop(AF_INET6, &v6, buffer, 40), range);
+                       snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
                        return buf;
                }
                break;
@@ -1171,7 +1171,6 @@ const char* User::GetCIDRMask(int range)
                {
                        struct in_addr v4;
                        sockaddr_in* sin;
-                       uint32_t temp;
                        char buffer[16];
 
                        if (range > 32)
@@ -1181,12 +1180,15 @@ const char* User::GetCIDRMask(int range)
                        sin = (sockaddr_in*)this->ip;
                        v4.s_addr = sin->sin_addr.s_addr;
 
-                       /* (32 - range) is the number of bits we are *ignoring*. We shift this left and then right to wipe off these bits. */
+                       /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
+                        * to zero. This means the last (32 - range) bits of the address must be set to zero.
+                        * This is done by shifting the value right and then back left by (32 - range) bits.
+                        */
                        if(range > 0)
                        {
-                               temp = ntohl(v4.s_addr);
-                               temp = (temp >> (32 - range)) << (32 - range);
-                               v4.s_addr = htonl(temp);
+                               v4.s_addr = ntohl(v4.s_addr);
+                               v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
+                               v4.s_addr = htonl(v4.s_addr);
                        }
                        else
                        {
@@ -1197,7 +1199,7 @@ const char* User::GetCIDRMask(int range)
                                v4.s_addr = 0;
                        }
 
-                       sprintf(buf, "%s/%d\n", inet_ntop(AF_INET, &v4, buffer, 16), range);
+                       snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
                        return buf;
                }
                break;
@@ -1668,7 +1670,7 @@ bool User::ChangeDisplayedHost(const char* shost)
        }
 
        if (IS_LOCAL(this))
-               this->WriteNumeric(396, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
+               this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
 
        return true;
 }
@@ -1945,31 +1947,31 @@ void User::ShowMOTD()
 {
        if (!ServerInstance->Config->MOTD.size())
        {
-               this->WriteNumeric(422, "%s :Message of the day file is missing.",this->nick.c_str());
+               this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
                return;
        }
-       this->WriteNumeric(375, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
+       this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
 
        for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
-               this->WriteNumeric(372, "%s :- %s",this->nick.c_str(),i->c_str());
+               this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
 
-       this->WriteNumeric(376, "%s :End of message of the day.", this->nick.c_str());
+       this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
 }
 
 void User::ShowRULES()
 {
        if (!ServerInstance->Config->RULES.size())
        {
-               this->WriteNumeric(434, "%s :RULES File is missing",this->nick.c_str());
+               this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
                return;
        }
 
-       this->WriteNumeric(308, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
+       this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
 
        for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
-               this->WriteNumeric(232, "%s :- %s",this->nick.c_str(),i->c_str());
+               this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
 
-       this->WriteNumeric(309, "%s :End of RULES command.",this->nick.c_str());
+       this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
 }
 
 void User::HandleEvent(EventType et, int errornum)