Example #1
0
File: chat.c Project: wyat/kbs
int chat_cmd(chatcontext * pthis, char *buf)
{
    int i, j;

    if (*buf++ != '/')
        return 0;
    for (i = 0; chat_cmdtbl[i].cmdname; i++) {
        if (chat_cmd_match
                (buf, chat_cmdtbl[i].cmdname, chat_cmdtbl[i].nCmdLenth))
            break;
    }
    if (!chat_cmdtbl[i].cmdname)
        return 0;
    for (j = 0; buf[j]; j++) {
        if (buf[j] == '\t' || buf[j] == '\r' || buf[j] == '\n') {
            buf[j] = ' ';
        }
    }
    while (*buf && *buf != ' ')
        buf++;
    while (*buf && *buf == ' ')
        buf++;                  /* chop head */
    /* chop tail */
    j = strlen(buf) - 1;
    while (j > 0 && buf[j] == ' ')
        j--;
    buf[j + 1] = 0;
    chat_cmdtbl[i].cmdfunc(pthis, buf);
    return 1;
}
Example #2
0
chat_process_local( char *cbuf, char *chatid )
{
  /* 
     See if the typed line should be handled locally. If not, return -1.
     If so, return 1 if we should exit, 0 if we keep going.
  */
  if (!strncmp(cbuf, "Goodbye!", 8)) {
    chat_exit("/e\n");
    return 1;
  }

  if (chat_cmd_match(cbuf, "clear")) 
    return (chat_resetscreen(chatid));
  else if (chat_cmd_match(cbuf, "exit"))
    return (chat_exit(cbuf));
  else if (chat_cmd_match(cbuf, "help"))
    return (chat_help(CHAT_HELP_FILE));
  else if (chat_cmd_match(cbuf, "long"))
    return (chat_list_users(cbuf, 1));
  else if (chat_cmd_match(cbuf, "query"))
    return (chat_query_user(cbuf));
  else if (chat_cmd_match(cbuf, "users"))
    return (chat_list_users(cbuf, 0));
  else if (chat_cmd_match(cbuf, "xhelp"))
    return (chat_help(CHAT_XTRA_HELP_FILE));

  return -1;
}