Changeset bf02a60 in code


Ignore:
Timestamp:
Dec 24, 2013, 5:52:56 PM (11 years ago)
Author:
Mike Belopuhov <mike@…>
Branches:
master
Children:
9195a6a
Parents:
4d92f03
Message:

add 'beep' and 'nobeep' support

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    r4d92f03 rbf02a60  
    2828extern int creategroups;
    2929
     30void icb_cmd_beep(struct icb_session *, char *);
    3031void icb_cmd_boot(struct icb_session *, char *);
    3132void icb_cmd_change(struct icb_session *, char *);
    3233void icb_cmd_name(struct icb_session *, char *);
     34void icb_cmd_nobeep(struct icb_session *, char *);
    3335void icb_cmd_personal(struct icb_session *, char *);
    3436void icb_cmd_pass(struct icb_session *, char *);
     
    4345                void            (*handler)(struct icb_session *, char *);
    4446        } cmdtab[] = {
     47                { "beep",       icb_cmd_beep },
    4548                { "boot",       icb_cmd_boot },
    4649                { "g",          icb_cmd_change },
     
    4851                { "msg",        icb_cmd_personal },
    4952                { "name",       icb_cmd_name },
     53                { "nobeep",     icb_cmd_nobeep },
    5054                { "pass",       icb_cmd_pass },
    5155                { "topic",      icb_cmd_topic },
     
    5963                        return (cmdtab[i].handler);
    6064        return (NULL);
     65}
     66
     67void
     68icb_cmd_beep(struct icb_session *is, char *arg)
     69{
     70        struct icb_group *ig = is->group;
     71        struct icb_session *s;
     72
     73        if (strlen(arg) == 0) {
     74                icb_error(is, "Invalid user");
     75                return;
     76        }
     77
     78        LIST_FOREACH(s, &ig->sess, entry) {
     79                if (strcmp(s->nick, arg) == 0)
     80                        break;
     81        }
     82        if (s == NULL) {
     83                icb_status(is, STATUS_NOTIFY, "%s is not signed on", arg);
     84                return;
     85        }
     86
     87        if (ISSETF(s->flags, ICB_SF_NOBEEP | ICB_SF_NOBEEP2)) {
     88                icb_error(is, "User has nobeep enabled");
     89                if (ISSETF(s->flags, ICB_SF_NOBEEP2))
     90                        icb_status(s, STATUS_NOBEEP,
     91                            "%s attempted to beep you", is->nick);
     92                return;
     93        }
     94
     95        icb_sendfmt(s, "%c%s", ICB_M_BEEP, is->nick);
    6196}
    6297
     
    186221            "%s changed nickname to %s", is->nick, arg);
    187222        strlcpy(is->nick, arg, sizeof is->nick);
     223}
     224
     225void
     226icb_cmd_nobeep(struct icb_session *is, char *arg)
     227{
     228        if (strlen(arg) == 0) {
     229                /* fail if we have verbose turned on */
     230                if (ISSETF(is->flags, ICB_SF_NOBEEP2)) {
     231                        icb_error(is, "Can't toggle your nobeep status");
     232                        return;
     233                }
     234                /* otherwise toggle the status */
     235                if (ISSETF(is->flags, ICB_SF_NOBEEP))
     236                        CLRF(is->flags, ICB_SF_NOBEEP);
     237                else
     238                        SETF(is->flags, ICB_SF_NOBEEP);
     239                icb_status(is, STATUS_NOBEEP, "No-Beep %s",
     240                    ISSETF(is->flags, ICB_SF_NOBEEP) ? "on" : "off");
     241                return;
     242        }
     243
     244        if (strcmp(arg, "on") == 0) {
     245                SETF(is->flags, ICB_SF_NOBEEP);
     246                CLRF(is->flags, ICB_SF_NOBEEP2); /* can't be on and verbose */
     247                icb_status(is, STATUS_NOBEEP, "No-Beep on");
     248        } else if (strcmp(arg, "verbose") == 0) {
     249                SETF(is->flags, ICB_SF_NOBEEP2);
     250                CLRF(is->flags, ICB_SF_NOBEEP); /* can't be on and verbose */
     251                icb_status(is, STATUS_NOBEEP, "No-Beep on (verbose)");
     252        } else if (strcmp(arg, "off") == 0) {
     253                CLRF(is->flags, ICB_SF_NOBEEP | ICB_SF_NOBEEP2);
     254                icb_status(is, STATUS_NOBEEP, "No-Beep off");
     255        } else
     256                icb_error(is, "Invalid nobeep mode");
    188257}
    189258
  • icb.c

    r4d92f03 rbf02a60  
    315315                { STATUS_DEPART,        "Depart" },
    316316                { STATUS_NAME,          "Name" },
     317                { STATUS_NOBEEP,        "No-Beep" },
    317318                { STATUS_NOTIFY,        "Notify" },
    318319                { STATUS_SIGNON,        "Sign-on" },
     
    452453        LIST_FOREACH(s, &ig->sess, entry) {
    453454                (void)snprintf(buf, sizeof buf,
    454                     "%c%c%s%c%d%c0%c%d%c%s%c%s%c%s",
     455                    "%c%c%s%c%lld%c0%c%lld%c%s%c%s%c%s",
    455456                    icb_ismoder(ig, s) ? '*' : ' ', ICB_M_SEP,
    456457                    s->nick, ICB_M_SEP, getmonotime() - s->last,
  • icb.h

    r4d92f03 rbf02a60  
    3333         STATUS_DEPART,
    3434         STATUS_NAME,
     35         STATUS_NOBEEP,
    3536         STATUS_NOTIFY,
    3637         STATUS_SIGNON,
     
    7879#define CLRF(t, f)               ((t) &= ~(f))
    7980#define ISSETF(t, f)             ((t) & (f))
    80 #define ICB_SF_UNKNOWN           0x00
    8181#define ICB_SF_PROTOSENT         0x01
    8282#define ICB_SF_LOGGEDIN          0x02
    8383#define ICB_SF_NOGROUP           0x08
    84 #define ICB_SF_MODERATOR         0x10
     84#define ICB_SF_NOBEEP            0x10
     85#define ICB_SF_NOBEEP2           0x20
    8586};
    8687
Note: See TracChangeset for help on using the changeset viewer.