continues cmd_neonserv_adduser.c
authorpk910 <philipp@zoelle1.de>
Wed, 17 Aug 2011 10:56:03 +0000 (12:56 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 17 Aug 2011 10:56:03 +0000 (12:56 +0200)
bot_NeonServ.c
cmd_neonserv_adduser.c

index f2d1473d9253087181006453c48a2737c1fcbf28..207450148cb7773dffeeceb8b0c0914909b496a1 100644 (file)
@@ -19,6 +19,7 @@ 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."},
     
     {NULL, NULL}
 };
index d79d80450d4d517e18e45fa529b4592b55c72042..54d20792fa7310df89f68a6c4273460db2b92f27 100644 (file)
@@ -22,6 +22,11 @@ static CMD_BIND(neonserv_cmd_adduser) {
     check_mysql();
     //check acccess
     caccess = atoi(argv[1]);
+    if(caccess <= 0 || caccess > 500) {
+        reply(getTextBot(), user, "NS_INVALID_ACCESS", caccess);
+        return;
+    }
+    //check own access
     if(argv[0][0] == '*') {
         //we've got an auth
         argv[0]++;
@@ -99,5 +104,14 @@ static USERAUTH_CALLBACK(neonserv_cmd_adduser_nick_lookup) {
 
 static void neonserv_cmd_adduser_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *nick, char *auth, int caccess) {
     //we've got a valid auth now...
-    putsock(client, "PRIVMSG %s :%s: %s   %d", chan->name, nick, auth, caccess);
+    int userid;
+    printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(auth));
+    res = mysql_use();
+    if ((row = mysql_fetch_row(res)) != NULL) {
+        userid = atoi(res[0]);
+    } else {
+        printf_mysql_query("INSERT INTO `users` (`user_user`) VALUES ('%s')", escape_string(auth));
+        userid = (int) mysql_insert_id(mysql_conn);
+    }
+    putsock(client, "PRIVMSG %s :%s: [%d] %s   %d", chan->name, nick, userid, auth, caccess);
 }