add 'beep' and 'nobeep' support

This commit is contained in:
Mike Belopuhov 2013-12-24 18:52:56 +01:00
parent 4d92f03396
commit bf02a602e1
3 changed files with 74 additions and 3 deletions

69
cmd.c
View File

@ -27,9 +27,11 @@
extern int creategroups;
void icb_cmd_beep(struct icb_session *, char *);
void icb_cmd_boot(struct icb_session *, char *);
void icb_cmd_change(struct icb_session *, char *);
void icb_cmd_name(struct icb_session *, char *);
void icb_cmd_nobeep(struct icb_session *, char *);
void icb_cmd_personal(struct icb_session *, char *);
void icb_cmd_pass(struct icb_session *, char *);
void icb_cmd_topic(struct icb_session *, char *);
@ -42,11 +44,13 @@ icb_cmd_lookup(char *cmd)
const char *cmd;
void (*handler)(struct icb_session *, char *);
} cmdtab[] = {
{ "beep", icb_cmd_beep },
{ "boot", icb_cmd_boot },
{ "g", icb_cmd_change },
{ "m", icb_cmd_personal },
{ "msg", icb_cmd_personal },
{ "name", icb_cmd_name },
{ "nobeep", icb_cmd_nobeep },
{ "pass", icb_cmd_pass },
{ "topic", icb_cmd_topic },
{ "w", icb_cmd_who },
@ -60,6 +64,37 @@ icb_cmd_lookup(char *cmd)
return (NULL);
}
void
icb_cmd_beep(struct icb_session *is, char *arg)
{
struct icb_group *ig = is->group;
struct icb_session *s;
if (strlen(arg) == 0) {
icb_error(is, "Invalid user");
return;
}
LIST_FOREACH(s, &ig->sess, entry) {
if (strcmp(s->nick, arg) == 0)
break;
}
if (s == NULL) {
icb_status(is, STATUS_NOTIFY, "%s is not signed on", arg);
return;
}
if (ISSETF(s->flags, ICB_SF_NOBEEP | ICB_SF_NOBEEP2)) {
icb_error(is, "User has nobeep enabled");
if (ISSETF(s->flags, ICB_SF_NOBEEP2))
icb_status(s, STATUS_NOBEEP,
"%s attempted to beep you", is->nick);
return;
}
icb_sendfmt(s, "%c%s", ICB_M_BEEP, is->nick);
}
void
icb_cmd_boot(struct icb_session *is, char *arg)
{
@ -187,6 +222,40 @@ icb_cmd_name(struct icb_session *is, char *arg)
strlcpy(is->nick, arg, sizeof is->nick);
}
void
icb_cmd_nobeep(struct icb_session *is, char *arg)
{
if (strlen(arg) == 0) {
/* fail if we have verbose turned on */
if (ISSETF(is->flags, ICB_SF_NOBEEP2)) {
icb_error(is, "Can't toggle your nobeep status");
return;
}
/* otherwise toggle the status */
if (ISSETF(is->flags, ICB_SF_NOBEEP))
CLRF(is->flags, ICB_SF_NOBEEP);
else
SETF(is->flags, ICB_SF_NOBEEP);
icb_status(is, STATUS_NOBEEP, "No-Beep %s",
ISSETF(is->flags, ICB_SF_NOBEEP) ? "on" : "off");
return;
}
if (strcmp(arg, "on") == 0) {
SETF(is->flags, ICB_SF_NOBEEP);
CLRF(is->flags, ICB_SF_NOBEEP2); /* can't be on and verbose */
icb_status(is, STATUS_NOBEEP, "No-Beep on");
} else if (strcmp(arg, "verbose") == 0) {
SETF(is->flags, ICB_SF_NOBEEP2);
CLRF(is->flags, ICB_SF_NOBEEP); /* can't be on and verbose */
icb_status(is, STATUS_NOBEEP, "No-Beep on (verbose)");
} else if (strcmp(arg, "off") == 0) {
CLRF(is->flags, ICB_SF_NOBEEP | ICB_SF_NOBEEP2);
icb_status(is, STATUS_NOBEEP, "No-Beep off");
} else
icb_error(is, "Invalid nobeep mode");
}
void
icb_cmd_personal(struct icb_session *is, char *arg)
{

3
icb.c
View File

@ -314,6 +314,7 @@ icb_status(struct icb_session *is, int type, const char *fmt, ...)
{ STATUS_BOOT, "Boot" },
{ STATUS_DEPART, "Depart" },
{ STATUS_NAME, "Name" },
{ STATUS_NOBEEP, "No-Beep" },
{ STATUS_NOTIFY, "Notify" },
{ STATUS_SIGNON, "Sign-on" },
{ STATUS_SIGNOFF, "Sign-off" },
@ -451,7 +452,7 @@ icb_who(struct icb_session *is, struct icb_group *ig)
ig = is->group;
LIST_FOREACH(s, &ig->sess, entry) {
(void)snprintf(buf, sizeof buf,
"%c%c%s%c%d%c0%c%d%c%s%c%s%c%s",
"%c%c%s%c%lld%c0%c%lld%c%s%c%s%c%s",
icb_ismoder(ig, s) ? '*' : ' ', ICB_M_SEP,
s->nick, ICB_M_SEP, getmonotime() - s->last,
ICB_M_SEP, ICB_M_SEP, s->login, ICB_M_SEP,

5
icb.h
View File

@ -32,6 +32,7 @@ enum {
STATUS_BOOT,
STATUS_DEPART,
STATUS_NAME,
STATUS_NOBEEP,
STATUS_NOTIFY,
STATUS_SIGNON,
STATUS_SIGNOFF,
@ -77,11 +78,11 @@ struct icb_session {
#define SETF(t, f) ((t) |= (f))
#define CLRF(t, f) ((t) &= ~(f))
#define ISSETF(t, f) ((t) & (f))
#define ICB_SF_UNKNOWN 0x00
#define ICB_SF_PROTOSENT 0x01
#define ICB_SF_LOGGEDIN 0x02
#define ICB_SF_NOGROUP 0x08
#define ICB_SF_MODERATOR 0x10
#define ICB_SF_NOBEEP 0x10
#define ICB_SF_NOBEEP2 0x20
};
struct icb_group {