src/parse.c
changeset 38 c2f62d1b8d76
parent 33 56571d34d754
child 39 0ae006af497e
equal deleted inserted replaced
37:85891f91096c 38:c2f62d1b8d76
    22 
    22 
    23 #ifndef SOURCE_URL
    23 #ifndef SOURCE_URL
    24 #define SOURCE_URL "http://largo.homelinux.org/cgi-bin/gitweb.cgi?p=net/mcbot.git"
    24 #define SOURCE_URL "http://largo.homelinux.org/cgi-bin/gitweb.cgi?p=net/mcbot.git"
    25 #endif
    25 #endif
    26 
    26 
    27 enum {
    27 enum command_map {
    28     HELP, JOIN, LEAVE, ADD, REPLACE, DELETE, LIST, SEARCH, INFO, PING, ON, OFF, DEBUG,
    28     HELP, JOIN, LEAVE, ADD, REPLACE, DELETE, LIST, SEARCH, INFO, PING, ON, OFF, DEBUG,
    29     VACCUUM, LOGOUT, WHO, WHOIS, TIME, TELL, OP, DEOP, KICK, BAN, UNBAN, KICKBAN, HELLO
    29     VACCUUM, LOGOUT, WHO, WHOIS, TIME, TELL, OP, DEOP, KICK, BAN, UNBAN, KICKBAN, HELLO
    30 };
    30 };
    31 
    31 
    32 const
    32 const
    68 
    68 
    69 char *parse (MSG * message)
    69 char *parse (MSG * message)
    70 {
    70 {
    71     static char msg[DEFAULT_BUF_SIZE];
    71     static char msg[DEFAULT_BUF_SIZE];
    72     int cmd = -1;
    72     int cmd = -1;
    73     int i;
    73     enum command_map map;
    74     char *token;
    74     char *token;
    75     char *parameters;
    75     char *parameters;
    76 
    76 
    77     time_t t;
    77     time_t t;
    78     struct tm *timeptr;
    78     struct tm *timeptr;
    93      */
    93      */
    94     if (*message->line != '!') {
    94     if (*message->line != '!') {
    95         return NULL;
    95         return NULL;
    96     }
    96     }
    97 
    97 
    98     i = 0;
    98     map = 0;
    99     token = strtok (message->line, " ");
    99     token = strtok (message->line, " ");
   100     while (Bot_Commands[i]) {
   100     while (Bot_Commands[map]) {
   101         if (!strcmp (token, Bot_Commands[i])) {
   101         if (!strcmp (token, Bot_Commands[map])) {
   102             switch (i) {
   102             switch (map) {
   103             case HELP:
   103             case HELP:
   104                 if ((token = strtok (NULL, "\r\n")))
   104                 if ((token = strtok (NULL, "\r\n")))
   105                     cmd = atoi (token);
   105                     cmd = atoi (token);
   106                 if ((cmd > 0) && (cmd < VISIBLE_ITEMS))
   106                 if ((cmd > 0) && (cmd < VISIBLE_ITEMS))
   107                     snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[cmd]);
   107                     snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[cmd]);
   311                 snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s?\r\n", message->channel, gettext ("What's up"),
   311                 snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s?\r\n", message->channel, gettext ("What's up"),
   312                           message->user);
   312                           message->user);
   313                 return msg;
   313                 return msg;
   314             }
   314             }
   315         }
   315         }
   316         i++;
   316         map++;
   317     }
   317     }
   318 
   318 
   319     return NULL;
   319     return NULL;
   320 }
   320 }