(thanks to the people reading git and excessively exploiting this bug... It was undet...
[NeonServV5.git] / src / bots.c
index 4875b5a5c987e97036c6084b704c2ddb58a58362..7da678c97ffb3b4a185f9b0dea6b74f3c69431ae 100644 (file)
@@ -1,4 +1,4 @@
-/* bots.c - NeonServ v5.5
+/* bots.c - NeonServ v5.6
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -26,6 +26,8 @@
 #include "modcmd.h"
 #include "DBHelper.h"
 #include "IRCEvents.h"
+#include "tools.h"
+#include "log.h"
 
 struct cmd_bot_alias {
     int botid;
@@ -151,8 +153,8 @@ struct ClientSocket *getChannelBot(struct ChanNode *chan, int botid) {
     struct ChanUser *chanuser;
     for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
         if(botid && bot->botid != botid) continue;
-        if((chanuser = getChanUser(bot->user, chan)) != NULL) {
-            if((chanuser->flags & CHANUSERFLAG_OPPED)) {
+        if(!chan || (chanuser = getChanUser(bot->user, chan)) != NULL) {
+            if(chan && (chanuser->flags & CHANUSERFLAG_OPPED)) {
                 use_bot = bot;
                 if(bot->flags & SOCKET_FLAG_PREFERRED) break;
             } else if(bot->flags & SOCKET_FLAG_PREFERRED)
@@ -190,7 +192,7 @@ void requestOp(struct UserNode *user, struct ChanNode *chan) {
 }
 
 void requestInvite(struct UserNode *user, struct ChanNode *chan) {
-    struct ClientSocket *bot, *userbot = NULL;
+    struct ClientSocket *bot;
     struct ChanUser *chanuser = getChanUser(user, chan);
     char invited = 0;
     if(chanuser) return;
@@ -199,9 +201,6 @@ void requestInvite(struct UserNode *user, struct ChanNode *chan) {
             invited = 1;
             putsock(bot, "INVITE %s %s", user->nick, chan->name);
         }
-        if(bot->user == user) {
-            userbot = bot;
-        }
     }
 }
 
@@ -277,7 +276,7 @@ void set_bot_alias(int botid, char *alias) {
     }
     botalias = malloc(sizeof(*botalias));
     if (!botalias) {
-        perror("malloc() failed");
+        printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
         return;
     }
     botalias->botid = botid;