Browse Source

Improve command handler to support leading whitespace

master
Emil 8 months ago
parent
commit
0a0a7bbaa9
No known key found for this signature in database GPG Key ID: 5432DB986FDBCF8A
1 changed files with 10 additions and 8 deletions
  1. +10
    -8
      src/irc.c

+ 10
- 8
src/irc.c View File

@@ -122,7 +122,8 @@ event_connect(irc_session_t * lsession,
#ifdef INITIAL_ASSIGNMENT_MESSAGE
if(is_no_assignment(creds.channel))
{
ircmsg(creds.channel, IRC_RED "No assignment for this channel. Finding a new..." IRC_STOP);
ircmsg(creds.channel,
IRC_RED "No assignment for this channel. Finding a new..." IRC_STOP);
random_assign(creds.channel);
}
ircmsg(creds.channel, remind(creds.channel));
@@ -187,34 +188,34 @@ parse_command(char const * cmd)
size_t i = 0;
char * msgswp = NULL;
/* size_t len = strlen(cmd); */
printf("Handling '%s'\n", cmd);
if (!(i = has_arg(cmd)))
{
printf("NARG Handling '%s'\n", cmd);
/* NO ARGUMENTS */
if (strcmp(cmd, "remind") == 0)
if (strncmp(cmd, "remind", 6) == 0)
{
msgswp = remind(current_username);
ircmsg(creds.channel, "%s: %s", current_username, msgswp);
}
else if (strcmp(cmd, "help") == 0)
else if (strncmp(cmd, "help", 4) == 0)
{ ircmsg(creds.channel, help_msg); }
else if (strcmp(cmd, "magic") == 0)
else if (strncmp(cmd, "magic", 5) == 0)
{ ircmsg(creds.channel, "%s: " IRC_YELLOW "%d" IRC_STOP, current_username, (rand() % 100) + 1); }
#ifndef NO_VULN_COMMANDS
else if (strcmp(cmd, "dump") == 0)
else if (strncmp(cmd, "dump", 4) == 0)
{
ircmsg(creds.channel, "%s: All projects:", current_username);
msgswp = dump();
ircmsg(creds.channel, msgswp);
}
#endif /* !NO_VULN_COMMANDS */
else if (strcmp(cmd, "reroll") == 0)
else if (strncmp(cmd, "reroll", 6) == 0)
{
purge_assignments(current_username);
random_assign(current_username);
ircmsg(creds.channel, "%s: %s", current_username, remind(current_username));
}
else if (strcmp(cmd, "stop") == 0)
else if (strncmp(cmd, "stop", 4) == 0)
{
if (vote_count)
{
@@ -225,6 +226,7 @@ parse_command(char const * cmd)
}
else /* HAS ARGUMENTS */
{
printf("ARG Handling '%s'\n", cmd);
static int yes, no;
char const * const arg = cmd + i;
/* fprintf(stderr, "argoff: %p; i: %ld; arg: %sEOA\n", cmd + i + 1, i, arg); */