const char *icec_command(const char *from, const char *arg) { char cmd[IMC_NAME_LENGTH]; char chan[IMC_NAME_LENGTH]; char data[IMC_DATA_LENGTH]; const char *p; imc_packet out; ice_channel *c; p = imc_getarg(arg, cmd, IMC_NAME_LENGTH); p = imc_getarg(p, chan, IMC_NAME_LENGTH); strcpy(data, p); if(!cmd[0] || !chan[0]) { return "Syntax: icommand <command> <node:channel> [<data..>]"; } p = strchr(chan, ':'); if(!p) { c = icec_findlchannel(chan); if(c) { strcpy(chan, c->name); } } sprintf(out.to, "ICE@%s", ice_mudof(chan)); strcpy(out.type, "ice-cmd"); strcpy(out.from, from); imc_initdata(&out.data); imc_addkey(&out.data, "channel", chan); imc_addkey(&out.data, "command", cmd); imc_addkey(&out.data, "data", data); imc_send(&out); imc_freedata(&out.data); return "Command sent."; }
/* send an emote out on a channel */ void imc_send_emote(const imc_char_data *from, int channel, const char *argument, const char *to) { imc_packet out; char tobuf[IMC_MNAME_LENGTH]; if (imc_active<IA_UP) return; setdata(&out, from); strcpy(out.type, "emote"); imc_addkeyi(&out.data, "channel", channel); imc_addkey(&out.data, "text", argument); to=imc_getarg(to, tobuf, IMC_MNAME_LENGTH); while (tobuf[0]) { if (!strcmp(tobuf, "*") || !strcasecmp(tobuf, imc_name) || imc_find_reminfo(tobuf, 0)) { strcpy(out.to, "*@"); strcat(out.to, tobuf); imc_send(&out); } to=imc_getarg(to, tobuf, IMC_MNAME_LENGTH); } imc_freedata(&out.data); }
/* handle a password response from a server */ static void serverpassword(imc_connect *c, const char *argument) { char arg1[3], name[IMC_MNAME_LENGTH], pw[IMC_PW_LENGTH], version[20]; imc_info *i; argument=imc_getarg(argument, arg1, 4); /* has to be PW */ argument=imc_getarg(argument, name, IMC_MNAME_LENGTH); argument=imc_getarg(argument, pw, IMC_PW_LENGTH); argument=imc_getarg(argument, version, 20); if (strcasecmp(arg1, "PW")) { imc_logstring("%s: non-PW password packet", imc_getconnectname(c)); do_close(c); return; } i=imc_getinfo(name); if (!i || strcmp(i->serverpw, pw) || i != c->info) { if ((!i || !(i->flags & IMC_QUIET)) && !(c->info->flags & IMC_QUIET)) imc_logstring("%s: password failure for %s", imc_getconnectname(c), name); do_close(c); return; } if (i->connection) /* kill old connections */ do_close(i->connection); i->connection = c; c->state = IMC_CONNECTED; c->spamcounter1 = 0; c->spamcounter2 = 0; /* check for a version string (assume version 0 if not present) */ if (sscanf(version, "version=%hu", &c->version)!=1) c->version=0; /* check for generator/interpreter */ if (!imc_vinfo[c->version].generate || !imc_vinfo[c->version].interpret) { if (!(i->flags & IMC_QUIET)) imc_logstring("%s: unsupported version %d", imc_getconnectname(c), c->version); do_close(c); return; } if (!(i->flags & IMC_QUIET)) imc_logstring("%s: connected (version %d)", imc_getconnectname(c), c->version); c->info->timer_duration=IMC_MIN_RECONNECT_TIME; c->info->last_connected=imc_now; imc_cancel_event(ev_login_timeout, c); imc_cancel_event(ev_reconnect, c->info); }
static imc_packet *interpret2(const char *argument) { char seq[20]; static imc_packet out; imc_initdata(&out.data); argument = imc_getarg(argument, out.i.from, IMC_NAME_LENGTH); argument = imc_getarg(argument, seq, 20); argument = imc_getarg(argument, out.i.path, IMC_PATH_LENGTH); argument = imc_getarg(argument, out.type, IMC_TYPE_LENGTH); argument = imc_getarg(argument, out.i.to, IMC_NAME_LENGTH); if(!out.i.from[0] || !seq[0] || !out.i.path[0] || !out.type[0] || !out.i.to[0]) { imc_logerror("interpret2: bad packet received, discarding"); return NULL; } parsekeys(argument, &out.data); out.i.sequence = strtoul(seq, NULL, 10); return &out; }
static void addrtomud(const char *list, char *output) { char arg[IMC_NAME_LENGTH]; output[0]=0; list=imc_getarg(list, arg, IMC_NAME_LENGTH); while (*arg) { if (!strcasecmp(imc_name, imc_mudof(arg))) sprintf(output + strlen(output), "%s ", imc_nameof(arg)); else sprintf(output + strlen(output), "%s ", arg); list=imc_getarg(list, arg, IMC_NAME_LENGTH); } }
static void mudtoaddr(const char *list, char *output) { char arg[IMC_NAME_LENGTH]; output[0]=0; list=imc_getarg(list, arg, IMC_NAME_LENGTH); while (*arg) { if (strchr(arg, '@') == NULL) sprintf(output + strlen(output), "%s@%s ", arg, imc_name); else sprintf(output + strlen(output), "%s ", arg); list=imc_getarg(list, arg, IMC_NAME_LENGTH); } /* chop final space */ if (arg[0] && arg[strlen(arg) - 1] == ' ') arg[strlen(arg) - 1] = 0; }
/* check for icec channels, return TRUE to stop command processing, FALSE otherwise */ bool icec_command_hook(CHAR_DATA *ch, const char *command, const char *argument) { ice_channel *c; char arg[MAX_STRING_LENGTH]; const char *word2; int emote=0; if (IS_NPC(ch)) return FALSE; #ifdef CIRCLE skip_spaces(&argument); #endif c=icec_findlchannel(command); if (!c || !c->local) return FALSE; if (c->local->level > get_trust(ch)) return FALSE; if (!imc_hasname(ch->pcdata->ice_listen, c->local->name)) return FALSE; if (!ice_audible(c, imc_makename(ch->name, imc_name))) { send_to_char("You cannot use that channel.\n\r", ch); return TRUE; } word2=imc_getarg(argument, arg, MAX_STRING_LENGTH); if (!arg[0]) { send_to_char("Use ichan to toggle the channel - or provide some text.\n\r", ch); return TRUE; } if (!str_cmp(arg, ",") || !str_cmp(arg, "emote")) { emote=1; argument=word2; } icec_sendmessage(c, ch->name, color_mtoi(argument), emote); return TRUE; }
/* handle a password from a client */ static void clientpassword(imc_connect *c, const char *argument) { char arg1[3], name[IMC_MNAME_LENGTH], pw[IMC_PW_LENGTH], version[20]; imc_info *i; char response[IMC_PACKET_LENGTH]; argument=imc_getarg(argument, arg1, 4); /* packet type (has to be PW) */ argument=imc_getarg(argument, name, IMC_MNAME_LENGTH); /* remote mud name */ argument=imc_getarg(argument, pw, IMC_PW_LENGTH); /* password */ argument=imc_getarg(argument, version, 20); /* optional version=n string */ if (strcasecmp(arg1, "PW")) { imc_logstring("%s: non-PW password packet", imc_getconnectname(c)); do_close(c); return; } /* do we know them, and do they have the right password? */ i=imc_getinfo(name); if (!i || strcmp(i->clientpw, pw)) { if (!i || !(i->flags & IMC_QUIET)) imc_logstring("%s: password failure for %s", imc_getconnectname(c), name); do_close(c); return; } /* deny access if deny flag is set (good for eg. muds that start crashing * on rwho) */ if (i->flags & IMC_DENY) { if (!(i->flags & IMC_QUIET)) imc_logstring("%s: denying connection", name); do_close(c); return; } if (i->connection) /* kill old connections */ do_close(i->connection); /* register them */ i->connection = c; c->state = IMC_CONNECTED; c->info = i; c->spamcounter1 = 0; c->spamcounter2 = 0; /* check for a version string (assume version 0 if not present) */ if (sscanf(version, "version=%hu", &c->version)!=1) c->version=0; /* check for generator/interpreter */ if (!imc_vinfo[c->version].generate || !imc_vinfo[c->version].interpret) { if (!(i->flags & IMC_QUIET)) imc_logstring("%s: unsupported version %d", imc_getconnectname(c), c->version); do_close(c); return; } /* send our response */ sprintf(response, "PW %s %s version=%d", imc_name, i->serverpw, IMC_VERSION); do_send(c, response); if (!(i->flags & IMC_QUIET)) imc_logstring("%s: connected (version %d)", imc_getconnectname(c), c->version); c->info->timer_duration=IMC_MIN_RECONNECT_TIME; c->info->last_connected=imc_now; imc_cancel_event(ev_login_timeout, c); imc_cancel_event(ev_reconnect, c->info); }
/* imc_send_mail: called by the mud to add a piece of mail to the queue */ void imc_send_mail(const char *from, const char *to, const char *date, const char *subject, const char *text) { char temp[IMC_DATA_LENGTH]; imc_mail *m; imc_qnode *qroot, *q; char arg[IMC_NAME_LENGTH]; const char *mud; int when=10; /* set up the entry for the mail list */ m=new_mail(); mudtoaddr(to, temp); /* qualify local addresses */ m->to = imc_strdup(temp); sprintf(temp, "%s@%s", from, imc_name); /* qualify sender */ m->from = imc_strdup(temp); m->date = imc_strdup(date); m->subject = imc_strdup(subject); m->id = imc_strdup(generate_mailid()); m->text = imc_strdup(text); m->received = imc_now; qroot=NULL; /* initialise the local list */ to=imc_getarg(to, arg, IMC_NAME_LENGTH); while (*arg) { /* get a mudname and check if we've already added a queue entry for that * mud. If not, add it */ if (strchr(arg, '@') != NULL && (mud = imc_mudof(arg))[0] != 0 && strcasecmp(mud, imc_name)) { if (!strcmp(mud, "*")) q=NULL; /* catch the @* case - not yet implemented */ else for (q=qroot; q; q=q->next) if (!strcasecmp(q->tomud, mud)) break; if (!q) /* not seen yet */ { /* add to the top of our mini-queue */ q=new_qnode(); q->tomud=imc_strdup(mud); q->data=m; q->next=qroot; m->usage++; qroot=q; imc_add_event(when, ev_qnode_send, q, 1); when += rand()%30+30; } } /* get the next address */ to=imc_getarg(to, arg, IMC_NAME_LENGTH); } if (!qroot) /* boggle, no foreign addresses?? */ { free_mail(m); return; } /* add mail to mail list, add mini-queue to mail queue */ add_ml(m); add_mq(qroot); save_ml(); save_mq(); }