fixed last commit
[NeonServV5.git] / bot_NeonServ.c
index 6d7f44c05dfbf32a170c95c3af0a42888411a4a3..a89be7139a1d409ed38da8760a91b975555d93b1 100644 (file)
@@ -2,34 +2,54 @@
 #include "bot_NeonServ.h"
 #include "modcmd.h"
 #include "IRCEvents.h"
+#include "IRCParser.h"
 #include "UserNode.h"
 #include "ChanNode.h"
 #include "ChanUser.h"
 #include "ClientSocket.h"
 #include "mysqlConn.h"
+#include "lang.h"
+#include "HandleInfoHandler.h"
+#include "WHOHandler.h"
+#include "DBHelper.h"
 
 #define BOTID 1
-#define CLASSNAME "NeonServ"
 
-static CMD_BIND(neonserv_cmd_users) {
-    struct ChanUser *chanuser;
-    putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name);
-    for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
-        putsock(client, "PRIVMSG %s :  %s!%s@%s [%s]  rights: %d", chan->name, chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "*"), chanuser->flags);
-    }
-}
+static const struct default_language_entry msgtab[] = {
+    {"NS_USER_UNKNOWN", "User with nick \002%s\002 does not exist."},
+    {"NS_AUTH_UNKNOWN", "Account \002%s\002 has not been registered."},
+    {"NS_USER_NEED_AUTH", "%s must first authenticate with \002AuthServ\002."},
+    {"NS_INVALID_ACCESS", "\002%d\002 is an invalid access level."},
+    {"NS_ADDUSER_ALREADY_ADDED", "%s is already on the \002%s\002 user list (with access %d)."},
+    {"NS_ADDUSER_DONE", "Added %s to the %s user list with access %d."},
+    {"NS_NOT_ON_USERLIST", "%s lacks access to \002%s\002."},
+    {"NS_DELUSER_DONE", "Deleted %s (with access %d) from the %s user list."},
+    {"NS_ACCESS_OUTRANKED", "You cannot give users access greater than or equal to your own."},
+    {"NS_USER_OUTRANKED", "\002%s\002 outranks you (command has no effect)."},
+    {"NS_ACCESS_DENIED", "Access denied."},
+    {"NS_CLVL_DONE", "%s now has access \002%d\002 in %s."},
+    {NULL, NULL}
+};
 
-static CMD_BIND(neonserv_cmd_modes) {
-    char modeBuf[MAXLEN];
-    getModeString(chan, modeBuf);
-    putsock(client, "PRIVMSG %s :Modes: %s", chan->name, modeBuf);
-}
+/*
+INCLUDE ALL CMD's HERE
+*/
+#include "cmd_neonserv_users.c"
+#include "cmd_neonserv_modes.c"
+#include "cmd_neonserv_adduser.c"
+#include "cmd_neonserv_deluser.c"
 
 static void neonserv_bot_ready(struct ClientSocket *client) {
     MYSQL_RES *res;
     MYSQL_ROW row;
     
     check_mysql();
+    printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
+    res = mysql_use();
+    if ((row = mysql_fetch_row(res)) != NULL) {
+        putsock(client, "MODE %s +%s", client->user->nick, row[0]);
+    }
+    
     printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d'", client->clientid);
     res = mysql_use();
     
@@ -48,7 +68,7 @@ static void start_bots() {
     MYSQL_RES *res, *res2;
     MYSQL_ROW row;
     
-    printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `whoisbot`, `id` FROM `bots` WHERE `botclass` = '%s' AND `active` = '1'", escape_string(CLASSNAME));
+    printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `whoisbot`, `id` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
     res = mysql_use();
     
     while ((row = mysql_fetch_row(res)) != NULL) {
@@ -65,7 +85,14 @@ static void start_bots() {
         printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access` FROM `bot_binds` WHERE `botid` = '%d'", client->clientid);
         res2 = mysql_use();
         while ((row = mysql_fetch_row(res2)) != NULL) {
-            
+            if(bind_cmd_to_command(BOTID, row[0], row[1])) {
+                if(row[2] && strcmp(row[2], "")) {
+                    bind_set_parameters(BOTID, row[0], row[2]);
+                }
+                if(atoi(row[3]) > 0) {
+                    bind_set_gaccess(BOTID, row[0], atoi(row[3]));
+                }
+            }
         }
     }
 }
@@ -73,14 +100,17 @@ static void start_bots() {
 void init_NeonServ() {
     check_mysql();
     
-    register_command(BOTID, "users", neonserv_cmd_users);
-    register_command(BOTID, "modes", neonserv_cmd_modes);
+    register_command(BOTID, "users", neonserv_cmd_users, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REQUIRE_AUTH);
+    register_command(BOTID, "modes", neonserv_cmd_modes, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+    
+    register_command(BOTID, "adduser", neonserv_cmd_adduser, 2, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+    register_command(BOTID, "deluser", neonserv_cmd_deluser, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     
     start_bots();
     bind_bot_ready(neonserv_bot_ready);
     set_trigger_callback(BOTID, neonserv_trigger_callback);
-    bind_cmd_to_command(BOTID, "users", "users");
-    bind_cmd_to_command(BOTID, "modes", "modes");
+    
+    register_default_language_table(msgtab);
 }
 
 void free_NeonServ() {
@@ -88,4 +118,3 @@ void free_NeonServ() {
 }
 
 #undef BOTID
-#undef CLASSNAME