added cmd_help
[NeonServV5.git] / cmd_neonserv_help.c
1
2 /*
3 * argv[0-*]     index
4 */
5
6 static CMD_BIND(neonserv_cmd_help) {
7     char *ident;
8     if(argc)
9         ident = merge_argv(argv, 0, argc);
10     else
11         ident = "0";
12     MYSQL_RES *res;
13     MYSQL_ROW row;
14     printf_mysql_query("SELECT `user_lang` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
15     res = mysql_use();
16     char *lang;
17     if ((row = mysql_fetch_row(res)) != NULL)
18         lang = row[0];
19     else
20         lang = "en";
21     printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = '%s' AND `ident` = '%s'", escape_string(lang), escape_string(ident));
22     res = mysql_use();
23     if ((row = mysql_fetch_row(res)) == NULL) {
24         if(stricmp(lang, "en")) {
25             printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = 'en' AND `ident` = '%s'", escape_string(ident));
26             res = mysql_use();
27         }
28         if ((row = mysql_fetch_row(res)) == NULL) {
29             reply(getTextBot(), user, "NS_HELP_TOPIC");
30             return;
31         }
32     }
33     char sendBuf[MAXLEN];
34     int sendBufPos = 0;
35     int i;
36     for(i = 0; i < strlen(row[0]); i++) {
37         switch(row[0][i]) {
38             case '\n':
39                 if(sendBufPos) {
40                     sendBuf[sendBufPos] = '\0';
41                     reply(getTextBot(), user, "%s", sendBuf);
42                     sendBufPos = 0;
43                 }
44                 break;
45             case '$':
46                 switch(row[0][i+1]) {
47                     case 'b':
48                         sendBuf[sendBufPos++] = '\002';
49                         i++;
50                         break;
51                     case 'k':
52                         sendBuf[sendBufPos++] = '\003';
53                         i++;
54                         break;
55                     case 'u':
56                         sendBuf[sendBufPos++] = '\031';
57                         i++;
58                         break;
59                     case 'C':
60                     case 'S':
61                         sendBufPos += sprintf(sendBuf + sendBufPos, "%s", client->user->nick);
62                         i++;
63                         break;
64                     default:
65                         sendBuf[sendBufPos++] = '$';
66                         break;
67                 }
68                 break;
69             default:
70                 sendBuf[sendBufPos++] = row[0][i];
71                 break;
72         }
73     }
74     if(sendBufPos) {
75         sendBuf[sendBufPos] = '\0';
76         reply(getTextBot(), user, "%s", sendBuf);
77         sendBufPos = 0;
78     }
79 }