continues cmd_neonserv_adduser.c
[NeonServV5.git] / cmd_neonserv_adduser.c
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);
 }