X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2Ftools.c;h=0232671c5050767aca56177a5bf5a7731ce0449d;hp=daedcd095ae19d28097f8814c1ef7fc362b7e433;hb=HEAD;hpb=7289d420ddc81d9975ed6d55dfdfd70dff2b2d48 diff --git a/src/tools.c b/src/tools.c index daedcd0..0232671 100644 --- a/src/tools.c +++ b/src/tools.c @@ -20,6 +20,7 @@ #include "lang.h" #include "ClientSocket.h" #include "IPNode.h" +#include "log.h" static const struct default_language_entry msgtab[] = { {"TIME_MASK_2_ITEMS", "%s and %s"}, /* {ARGS: "2 days", "1 hour"} */ @@ -375,10 +376,20 @@ int strToTime(struct UserNode *user, char *str) { return total_time; } +int getCurrentSecondsOfDay() { + time_t now = time(0); + struct tm *timeofday = localtime(&now); + int seconds = 0; + seconds += timeofday->tm_hour * 3600; + seconds += timeofday->tm_min * 60; + seconds += timeofday->tm_sec; + return seconds; +} + struct ModeBuffer* initModeBuffer(struct ClientSocket *client, struct ChanNode *chan) { struct ModeBuffer *modeBuf = malloc(sizeof(*modeBuf)); if(!modeBuf) { - perror("malloc() failed"); + printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); return NULL; } modeBuf->client = client; @@ -576,6 +587,28 @@ unsigned long crc32(const char *text) { return (crc^0xFFFFFFFF); } +int stricmp (const char *s1, const char *s2) { + return stricmplen(s1, s2, -1); +} + +int stricmplen(const char *s1, const char *s2, int len) { + if (s1 == NULL) + return (s2 == NULL ? 0 : -(*s2)); + if (s2 == NULL) + return *s1; + char c1, c2; + int i = 0; + while ((c1 = tolower(*s1)) == (c2 = tolower(*s2))) { + if (*s1 == '\0') + break; + i++; + s1++; + s2++; + if(len != -1 && i == len) break; + } + return c1 - c2; +} + void init_tools() { register_default_language_table(msgtab); crc32_init();