modified code to use IOHandler functions instead of own ones
[NeonServV5.git] / src / modules / NeonServ.mod / bot_NeonServ.c
index e6ec912caa8f8b61cf42e3e3780cb41b476f6368..050e71c884e7d17e956af0dc397f0e084f2db082 100644 (file)
@@ -1,4 +1,4 @@
-/* bot_NeonServ.c - NeonServ v5.3
+/* bot_NeonServ.c - NeonServ v5.5
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
 #include "../module.h"
+#include "../botid.h"
  
 #include "bot_NeonServ.h"
-#include "modcmd.h"
-#include "IRCEvents.h"
-#include "IRCParser.h"
-#include "UserNode.h"
-#include "ChanNode.h"
-#include "ChanUser.h"
-#include "BanNode.h"
-#include "ModeNode.h"
-#include "ClientSocket.h"
-#include "mysqlConn.h"
-#include "lang.h"
-#include "HandleInfoHandler.h"
-#include "WHOHandler.h"
-#include "DBHelper.h"
-#include "tools.h"
-#include "timeq.h"
-#include "EventLogger.h"
+#include "../../modcmd.h"
+#include "../../IRCEvents.h"
+#include "../../IRCParser.h"
+#include "../../UserNode.h"
+#include "../../ChanNode.h"
+#include "../../ChanUser.h"
+#include "../../BanNode.h"
+#include "../../ModeNode.h"
+#include "../../ClientSocket.h"
+#include "../../mysqlConn.h"
+#include "../../lang.h"
+#include "../../HandleInfoHandler.h"
+#include "../../WHOHandler.h"
+#include "../../DBHelper.h"
+#include "../../tools.h"
+#include "../../timeq.h"
+#include "../../EventLogger.h"
 #include "cmd_neonserv.h"
-#include "ConfigParser.h"
+#include "../../ConfigParser.h"
 
-#define BOTID 1
+#define BOTID NEONSERV_BOTID
 #define BOTALIAS "NeonServ"
 
 static const struct default_language_entry msgtab[] = {
@@ -76,7 +77,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_USERS_HEADER", "%s users from level %d to %d:"}, /* {ARGS: "#TestChan", 1, 500} */
     {"NS_USERS_HEADER_MATCH", "%s users from level %d to %d matching %s:"}, /* {ARGS: "#TestChan", 1, 500, "Test*"} */
     {"NS_USERS_HEADER_ACCESS", "Access"},
-    {"NS_USERS_HEADER_ACCOUNT", "Accout"},
+    {"NS_USERS_HEADER_ACCOUNT", "Account"},
     {"NS_USERS_HEADER_SEEN", "Last Seen"},
     {"NS_USERS_HEADER_STATE", "Status"},
     {"NS_USERS_COUNT", "There are $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
@@ -100,7 +101,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_MYACCESS_HEADER_MATCH", "Showing all channel entries for account $b%s$b matching %s:"}, /* {ARGS: "TestAuth", "#Test*"} */
     {"NS_MYACCESS_HEADER_NAME", "Name"},
     {"NS_MYACCESS_HEADER_ACCESS", "Access"},
-    {"NS_MYACCESS_HEADER_FLAGS", "Flags"},
+    {"NS_MYACCESS_HEADER_FLAGS", "Rights"},
     {"NS_MYACCESS_HEADER_INFO", "Info"},
     {"NS_MYACCESS_COUNT", "%s has access in $b%d$b channel(s) and is owner of $b%d$b channel(s)."}, /* {ARGS: "TestUser", 15, 5} */
     {"NS_MYACCESS_COUNT_MATCH", "%s has access in $b%d$b channel(s) and is owner of $b%d$b channel(s) ($b%d$b channels matching your request)."}, /* {ARGS: "TestUser", 15, 5, 7} */
@@ -149,7 +150,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_SET_CANNOT_SET", "That setting is above your current level, so you cannot change it."},
     {"NS_SET_BADLEVEL", "You cannot change any setting to above your level."},
     {"NS_SET_INVALID_OPTION", "$b%d$b is not a valid choice.  Choose one:"}, /* {ARGS: 5} */
-    {"NS_SET_INVALID_BOOLEAN", "$b%s$b is an invalid binary value."}, /* {ARGS: 2} */
+    {"NS_SET_INVALID_BOOLEAN", "$b%s$b is an invalid binary value."}, /* {ARGS: "3"} */
     {"NS_SET_DEFAULTS_OWNER", "You must have access 500 in %s to reset it to the default options."}, /* {ARGS: "#TestChan"} */
     {"NS_SET_DEFAULTS_CODE", "To reset %s's settings to the defaults, you must use 'set defaults %s'."}, /* {ARGS: "#TestChan", "abc123"} */
     {"NS_SET_DEFAULTS_DONE", "All settings for %s have been reset to default values."}, /* {ARGS: "#TestChan"} */
@@ -236,6 +237,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_REGISTER_DONE", "$b%s$b is now registered to $b%s$b."}, /* {ARGS: "#TestChan", "TestUser"} */
     {"NS_REGISTER_DONE_NOAUTH", "$b%s$b is now registered."}, /* {ARGS: "#TestChan"} */
     {"NS_UNREGISTER_NOT_REGISTERED", "$b%s$b is not registered with %s."}, /* {ARGS: "#TestChan", "NeonServ"} */
+    {"NS_UNREGISTER_NODELETE", "$b%s$b is protected from being unregistered (nodelete)."}, /* {ARGS: "#TestChan"} */
     {"NS_UNREGISTER_DONE", "$b%s$b unregistered."}, /* {ARGS: "#TestChan"} */
     {"NS_RECOVER_DONE", "$b%s$b has been recovered."}, /* {ARGS: "#TestChan"} */
     {"NS_RESYNC_DONE", "Synchronized users in $b%s$b with the userlist."}, /* {ARGS: "#TestChan"} */
@@ -267,6 +269,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_UNBANALL_FAIL", "$b%s$b could not find any bans in %s."}, /* {ARGS: "NeonServ", "#TestChan"} */
     {"NS_UNBANME_DONE", "removed $b%d$b masks from the %s ban list."}, /* {ARGS: 5, "#TestChan"} */
     {"NS_UNBANME_FAIL", "$b%s$b could not find any bans matching %s."}, /* {ARGS: "NeonServ", "TestUser!TestIdent@TestUser.user.WebGamesNet"} */
+    {"NS_INVITE_GLOBALLY_BLOCKED", "$b%s$b doesn't want to be invited at all."}, /* {ARGS: "TestUser"} */
     {"NS_INVITE_RESTRICTION", "%s doesn't want to be invited to %s."}, /* {ARGS: "TestUser", "#TestChan"} */
     {"NS_INVITE_TIMEOUT", "%s has already been invited to $b%s$b."}, /* {ARGS: "TestUser", "#TestChan"} */
     {"NS_INVITE_ON_CHAN", "%s is already in $b%s$b."}, /* {ARGS: "TestUser", "#TestChan"} */
@@ -289,6 +292,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_UNBIND_DONE", "Unbound command $b%s$b."}, /* {ARGS: "TestCommand"} */
     {"NS_EVENTS_HEADER", "The following channel events were found:"},
     {"NS_OPLOG_HEADER", "The following oper events were found:"},
+    {"NS_SEARCH_ZOMBIE_SCAN_IN_PROGRESS", "Another Zombie Scan is already in progress."},
     {"NS_SEARCH_HEADER", "The following channels were found:"},
     {"NS_COMMAND_BINDING", "$b%s$b is a binding of %s %s"}, /* {ARGS: "TestCommand", "TestFunction", "TestParameters"} */
     {"NS_COMMAND_ACCESS", "You need at least %d channel access and %d oper access to execute this command."}, /* {ARGS: 500, 100} */
@@ -400,7 +404,6 @@ cmd_neonserv_calc.c
 //EVENTS
 #include "event_neonserv_join.c"
 #include "event_neonserv_part.c"
-#include "event_neonserv_quit.c"
 #include "event_neonserv_kick.c"
 #include "event_neonserv_mode.c"
 #include "event_neonserv_ctcp.c"
@@ -414,12 +417,17 @@ struct ClientSocket *getBotForChannel(struct ChanNode *chan) {
 }
 
 static void neonserv_bot_ready(struct ClientSocket *client) {
+    if(client->botid != BOTID)
+        return;
     MYSQL_RES *res;
     MYSQL_ROW row;
     
-    printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
+    printf_mysql_query("SELECT `automodes`, `oper_user`, `oper_pass` FROM `bots` WHERE `id` = '%d'", client->clientid);
     res = mysql_use();
     if ((row = mysql_fetch_row(res)) != NULL) {
+        if(row[1] && row[2]) {
+            putsock(client, "OPER %s %s", row[1], row[2]);
+        }
         putsock(client, "MODE %s +%s", client->user->nick, row[0]);
     }
     
@@ -464,6 +472,7 @@ static void start_bots(int type) {
             client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
             client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
             client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0);
+            client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP;
             client->botid = BOTID;
             client->clientid = atoi(row[7]);
             connect_socket(client);
@@ -500,7 +509,6 @@ void init_NeonServ(int type) {
     bind_bot_ready(neonserv_bot_ready, module_id);
     bind_join(neonserv_event_join, module_id);
     bind_part(neonserv_event_part, module_id);
-    bind_quit(neonserv_event_quit, module_id);
     bind_chanctcp(neonserv_event_chanctcp, module_id);
     bind_privctcp(general_event_privctcp, module_id);
     bind_channotice(neonserv_event_channotice, module_id);
@@ -514,10 +522,6 @@ void init_NeonServ(int type) {
     register_default_language_table(msgtab);
 }
 
-void loop_NeonServ() {
-    
-}
-
 void free_NeonServ(int type) {
     unbind_allcmd(BOTID);
     if(type == MODSTATE_STARTSTOP) {