]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Fix configure system loading cache file too late.
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 4605092a1e6f01b777d24435adaefd4752d07d91..3efa58bba44150c111d2e109ab5f14d6cb6f39e6 100644 (file)
 
 /* $Core */
 
+#ifdef _WIN32
+#define _CRT_RAND_S
+#include <stdlib.h>
+#endif
+
 #include "inspircd.h"
 #include "xline.h"
 #include "exitcodes.h"
+#include <iostream>
 
 std::string InspIRCd::GetServerDescription(const std::string& servername)
 {
@@ -190,6 +196,33 @@ bool InspIRCd::IsValidMask(const std::string &mask)
        return true;
 }
 
+void InspIRCd::StripColor(std::string &sentence)
+{
+       /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
+       int seq = 0;
+
+       for (std::string::iterator i = sentence.begin(); i != sentence.end();)
+       {
+               if (*i == 3)
+                       seq = 1;
+               else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) ))
+               {
+                       seq++;
+                       if ( (seq <= 4) && (*i == ',') )
+                               seq = 1;
+                       else if (seq > 3)
+                               seq = 0;
+               }
+               else
+                       seq = 0;
+
+               if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
+                       i = sentence.erase(i);
+               else
+                       ++i;
+       }
+}
+
 /* true for valid channel name, false else */
 bool IsChannelHandler::Call(const char *chname, size_t max)
 {
@@ -311,12 +344,14 @@ bool InspIRCd::OpenLog(char**, int)
 
 void InspIRCd::CheckRoot()
 {
+#ifndef _WIN32
        if (geteuid() == 0)
        {
-               printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
-               this->Logs->Log("STARTUP",DEFAULT,"Cant start as root");
+               std::cout << "ERROR: You are running an irc server as root! DO NOT DO THIS!" << std::endl << std::endl;
+               this->Logs->Log("STARTUP",DEFAULT,"Can't start as root");
                Exit(EXIT_STATUS_ROOT);
        }
+#endif
 }
 
 void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const std::string &text)
@@ -451,7 +486,17 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max)
 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)