示例#1
0
文件: imc-interp.c 项目: bkero/Smaug
/* send a keepalive request to everyone - shogar */
void imc_request_keepalive(void)
{
  imc_packet out;
/*
  if (imc_active<IA_UP)
    return;
*/

  if(!time_of_last_salive)
  {
	time_of_last_salive=time(NULL);
  }
  else
  {
        time_since_last_salive = time(NULL) - time_of_last_salive;
	time_of_last_salive =time(NULL);
  }
  imc_initdata(&out.data);
  strcpy(out.type, "keepalive-request");
  strcpy(out.from, "*");
  strcpy(out.to, "*@*");
  imc_addkey(&out.data, "versionid", IMC_VERSIONID);
  if (imc_siteinfo.flags[0])
    imc_addkey(&out.data, "flags", imc_siteinfo.flags);

  imc_send(&out);
  imc_freedata(&out.data);
}
示例#2
0
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.";
}
示例#3
0
文件: imc-interp.c 项目: bkero/Smaug
/* send a blank packet with a type of "inforequest" to everyone. The reply is automatic
so we don't need to send any data except who we are. Those with less than version 1.0a will
reply with a reject packet. */
void imc_send_info_request(void)
{
  imc_packet out;

  if (imc_active<IA_UP)
    return;
  global_directnum=-1;
  if(!time_of_last_salive) /* ping istat monitor - shogar */
  {
	time_of_last_salive=time(NULL);
  }
  else
  {
        time_since_last_salive = time(NULL) - time_of_last_salive;
	time_of_last_salive =time(NULL);
  }

  imc_initdata(&out.data);
  strcpy(out.type, "inforequest");
  strcpy(out.from, "*");
  strcpy(out.to, "*@*");

  imc_send(&out);
  imc_freedata(&out.data);
  imc_logstring("Polling for fast hubs.");
}
示例#4
0
文件: imc-mail.c 项目: bhyvex/cosMUD
/* try sending a qnode */
void ev_qnode_send(void *data)
{
  imc_qnode *p=(imc_qnode *)data;
  imc_packet out;

  save_ml();
  save_mq();

  /* send it.. */

  imc_initdata(&out.data);

  sprintf(out.to, "Mail-daemon@%s", p->tomud);
  strcpy(out.from, "Mail-daemon");
  strcpy(out.type, "mail");

  imc_addkey(&out.data, "to", p->data->to);
  imc_addkey(&out.data, "from", p->data->from);
  imc_addkey(&out.data, "subject", p->data->subject);
  imc_addkey(&out.data, "date", p->data->date);
  imc_addkey(&out.data, "text", p->data->text);
  imc_addkey(&out.data, "id", p->data->id);

  imc_send(&out);
  imc_freedata(&out.data);

  /* try resending it in an hour */

  imc_add_event(3600, ev_qnode_send, data, 1);
}
示例#5
0
文件: imc-interp.c 项目: bkero/Smaug
/* send connection info to new hub for optimization */
void imc_send_autoconnect(const char *to)
{
  imc_packet out;
  imc_info *i;
  char no_port[IMC_MNAME_LENGTH];

  int a=0,b=0;

  if (imc_active<IA_UP)
    return;

  i=imc_getinfo(to);
  if(i && i == imc_info_list && i->connection) /* not if primary hub - shogar */
    return;

     /* Send all this info: -- Scion 
	 imc set <mudname> all <host> <port> <clientpw> <serverpw> <rcvstamp> <noforward> <flags>
		*/
  imc_initdata(&out.data);
  strcpy(out.type, "imc-switch");
  strcpy(out.from, "*");
  strcpy(out.to, "*@");
  imc_sncpy(out.to+2, to, IMC_MNAME_LENGTH-2);

  /* Get that pesky port out of the host name */
  for (a=0;a<strlen(imc_siteinfo.host); a++) {
	  if (imc_siteinfo.host[a]==':' 
	  || imc_siteinfo.host[a]==' ') 
	  {
		  break;
	  }
	  no_port[b++]=imc_siteinfo.host[a];
	  no_port[b]='\0';
  }
  imc_addkey(&out.data, "host", no_port);
  imc_addkeyi(&out.data, "port", (int)imc_port);
  
  if(i) /* don't assign new ones, if we have passwords */
  {
  	imc_addkey(&out.data, "clientpw", i->clientpw);
  	imc_addkey(&out.data, "serverpw", i->serverpw);
  }
  else 
  {
  	imc_addkey(&out.data, "clientpw", imc_make_password());/* these are random */
  	imc_addkey(&out.data, "serverpw", imc_make_password());
  }
  imc_addkeyi(&out.data, "rcvstamp", 0);
  imc_addkeyi(&out.data, "noforward", 0);
  imc_addkey(&out.data, "flags", "none");
  imc_addkey(&out.data, "localname", imc_name);

  imc_send(&out);
  imc_freedata(&out.data);
  imc_logstring("Autoconnect sent to %s", to);
}
示例#6
0
void ev_icec_firstrefresh(void *dummy) {
    imc_packet out;
    if(imc_active < IA_UP) {
        return;
    }
    strcpy(out.from, "*");
    strcpy(out.to, "ICE@*");
    strcpy(out.type, "ice-refresh");
    imc_initdata(&out.data);
    imc_addkey(&out.data, "channel", "*");
    imc_send(&out);
    imc_freedata(&out.data);
}
示例#7
0
文件: imc-interp.c 项目: bkero/Smaug
 /* This function was rendered useless when everything was packed into
 rquery, and the rquery info command returned that dumb little #define instead
 of this info. I swapped this with the rquery info function, and now I'm salvaging
 this function to use for something entirely different. 1/5/99 -- Scion
 */
void imc_recv_inforequest(const char *from) {
	/* What we're going to do here is to reply to a type of packet
	labelled as "inforequest". We'll reply with two things: 
	1) Are we a hub or not?
	2) The number of direct connections we have.
	
	  What will happen when the MUD receives this info is that it will compare
	  each of the available hubs and find the one with the least number of direct
	  connections. It will then switch its hub connection to the hub with less
	  connections, hopefully averaging the number of connections per hub. You will
	  be able to prevent this auto-swap by #defining NO_OPTIMIZE in imc-config.h -- Scion */
  imc_packet reply;
  int num_direct=0;
  imc_info *i;
  
  extern imc_info *imc_info_list;

  strcpy(reply.to, from);
  strcpy(reply.from, "*");

  imc_initdata(&reply.data);

  if (imc_isignored(from)) /* Don't reply if they're ignored */
  {
    strcpy(reply.type, "info-unavailable");
    imc_send(&reply);
  }
  strcpy(reply.type, "info-reply");
    
  if (imc_is_router) 
  	/* don't even send a reply if we're not a hub -- Scion */
  {
	  imc_addkey(&reply.data, "hub",    "yes");
	  for (i=imc_info_list; i; i=i->next)
              if(i->connection && i->connection->state & IMC_CONNECTED) /* only the live ones - shogar */
			num_direct++;
	  imc_addkeyi(&reply.data, "direct",    
		imc_siteinfo.maxguests - num_direct);
  
        /*  don't send if num_direct exceeds maxguest - shogar */
        if(num_direct <= imc_siteinfo.maxguests)
        {
  		imc_send(&reply);
  		imc_logstring("Sent info-reply to %s.", from);
	}
  }
  imc_freedata(&reply.data);
}
示例#8
0
文件: imc-interp.c 项目: bkero/Smaug
/* convert back from 'd' to 'p' */
static void setdata(imc_packet *p, const imc_char_data *d)
{
  imc_initdata(&p->data);

  if (!d)
  {
    strcpy(p->from, "*");
    imc_addkeyi(&p->data, "level", -1);
    return;
  }

  strcpy(p->from, d->name);

  if (d->wizi)
    imc_addkeyi(&p->data, "wizi", d->wizi);
  imc_addkeyi(&p->data, "level", d->level);
}
示例#9
0
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;
}
示例#10
0
文件: imc-interp.c 项目: bkero/Smaug
/* send a ping with a given timestamp */
void imc_send_ping(const char *to, int time_s, int time_u)
{
  imc_packet out;

  if (imc_active<IA_UP)
    return;

  imc_initdata(&out.data);
  strcpy(out.type, "ping");
  strcpy(out.from, "*");
  strcpy(out.to, "*@");
  imc_sncpy(out.to+2, to, IMC_MNAME_LENGTH-2);
  imc_addkeyi(&out.data, "time-s", time_s);
  imc_addkeyi(&out.data, "time-us", time_u);

  imc_send(&out);
  imc_freedata(&out.data);
}
示例#11
0
文件: imc-interp.c 项目: bkero/Smaug
/* send a keepalive to everyone */
void imc_send_keepalive(void)
{
  imc_packet out;

  if (imc_active<IA_UP)
    return;

  imc_initdata(&out.data);
  strcpy(out.type, "is-alive");
  strcpy(out.from, "*");
  strcpy(out.to, "*@*");
  imc_addkey(&out.data, "versionid", IMC_VERSIONID);
  if (imc_siteinfo.flags[0])
    imc_addkey(&out.data, "flags", imc_siteinfo.flags);

  imc_send(&out);
  imc_freedata(&out.data);
  imc_add_event(ICED_REFRESH_TIME, ev_iced_refresh, NULL, 1);
}
示例#12
0
文件: imc-interp.c 项目: bkero/Smaug
/* respond with a whois-reply */
void imc_send_whoisreply(const char *to, const char *data)
{
  imc_packet out;

  if (imc_active<IA_UP)
    return;

  if (!strcmp(imc_mudof(to), "*"))
    return; /* don't let them do this */

  imc_initdata(&out.data);

  imc_sncpy(out.to, to, IMC_NAME_LENGTH);
  strcpy(out.type, "whois-reply");
  strcpy(out.from, "*");
  imc_addkey(&out.data, "text", data);

  imc_send(&out);
  imc_freedata(&out.data);
}
示例#13
0
void icec_sendmessage(ice_channel *c, const char *name, const char *text, int emote) {
    imc_packet out;
    strcpy(out.from, name);
    imc_initdata(&out.data);
    imc_addkey(&out.data, "channel", c->name);
    imc_addkey(&out.data, "text", text);
    imc_addkeyi(&out.data, "emote", emote);
    /* send a message out on a channel */
    if(c->policy == ICE_PRIVATE) {
        /* send to the daemon to distribute */
        /* send locally */
        icec_showchannel(c, imc_makename(name, imc_name), text, emote);
        sprintf(out.to, "ICE@%s", ice_mudof(c->name));
        strcpy(out.type, "ice-msg-p");
    } else {
        /* broadcast */
        strcpy(out.type, "ice-msg-b");
        strcpy(out.to, "*@*");
    }
    imc_send(&out);
    imc_freedata(&out.data);
}
示例#14
0
文件: imc.c 项目: bkero/Smaug
/* notify everyone of the closure - shogar */
void imc_close_notify(const char *host)
{
  imc_packet out;
  char shorthost[80];

  if (imc_active<IA_UP)
    return;

  strcpy(shorthost,host);
  if(strchr(shorthost,'['))
    *(strchr(shorthost,'['))=0;

  imc_initdata(&out.data);
  strcpy(out.type, "close-notify");
  strcpy(out.from, "*");
  strcpy(out.to, "*@*");
  imc_addkey(&out.data, "versionid", IMC_VERSIONID);
  if (imc_siteinfo.flags[0])
    imc_addkey(&out.data, "flags", imc_siteinfo.flags);
  imc_addkey(&out.data, "host", shorthost);
  imc_send(&out);
  imc_freedata(&out.data);
}
示例#15
0
文件: imc-interp.c 项目: bkero/Smaug
/* add the mud to our list if we're a hub, and reply with our info. -- Scion*/
void imc_recv_autoconnect(const char *to, const char *rhost, int rport, 
	const char *rclientpw, const char *rserverpw, 
  	int rrcvstamp, int rnoforward, const char *rflags, 
	const char *remotename)
{
  imc_packet out;
  char no_port[IMC_MNAME_LENGTH];

  int a=0,b=0;

  imc_info *i,*o;

   if (imc_active<IA_UP)
    return;


  /* Receive all this info: -- Scion 
	 imc set <mudname> all <host> <port> <clientpw> <serverpw> <rcvstamp> <noforward> <flags>
		*/
#ifdef NO_OPTIMIZE
   imc_logstring("Autoconnect refused because NO_OPTIMIZE is defined.");
   return;
#endif
  
  if (imc_name && !strcasecmp(remotename, imc_name)) {
	  imc_logstring("Autoconnect attempt allegedly from this server! Ignoring.");
      return; /* Hey! That's our name! */
  }
	  
  /* Get that pesky port out of the host name */
  for (a=0;a<strlen(imc_siteinfo.host); a++) {
	  if (imc_siteinfo.host[a]==':'
	  || imc_siteinfo.host[a]==' ') 
 	  {
		  break;
	  }
	  no_port[b++]=imc_siteinfo.host[a];
	  no_port[b]='\0';
  }
  /* Send our information back to the MUD */
  imc_initdata(&out.data);
  strcpy(out.type, "switch-reply");
  strcpy(out.from, "*");
  strcpy(out.to, "*@");
  imc_sncpy(out.to+2, remotename, IMC_MNAME_LENGTH-2);
  
  imc_addkey(&out.data, "confirm", "connection added");
  imc_addkey(&out.data, "host", no_port); /* don't put the port number in from imc_siteinfo.host b/c it's the game port */
  imc_addkeyi(&out.data, "port", (int)imc_port);
  imc_addkey(&out.data, "clientpw", rclientpw);
  imc_addkey(&out.data, "serverpw", rserverpw);
  imc_addkeyi(&out.data, "rcvstamp", 0);
  imc_addkeyi(&out.data, "noforward", 0);
  imc_addkey(&out.data, "flags", "none");
  imc_addkey(&out.data, "localname", imc_name);
  
  imc_send(&out);
  
  imc_freedata(&out.data); 
  
  /* Setup the new connection... */
  if((o=imc_getinfo(remotename))) /* remove old entries - shogar */
  {
  	i=imc_insert_info();
        i->connection=o->connection;
        i->flags=o->flags;
        if (i->connection) i->connection->info=i;
  	imc_cancel_info(o); 
  }
  else
  {
  	i=imc_insert_info();
        i->flags = imc_flagvalue("new", imc_connection_flags); /* Hubs don't need specific flags really */
  }


  i->name       = imc_strdup(remotename);
  i->host       = imc_strdup(rhost);
  i->port       = (unsigned short)rport;
  i->clientpw   = imc_strdup(rclientpw);
  i->serverpw   = imc_strdup(rserverpw);
  i->rcvstamp   = rrcvstamp;
  i->noforward  = rnoforward;
  i->connect_attempts = 0;


  imc_saveconfig();
  /* All done! */
  
  imc_logstring("Autoconnect accepted from %s", to);


}
示例#16
0
文件: imc-mail.c 项目: bhyvex/cosMUD
void imc_recv_mail(const char *from, const char *to, const char *date,
		   const char *subject, const char *id, const char *text)
{
  imc_mailid *mid;
  imc_packet out;
  char *reason;
  char temp[IMC_DATA_LENGTH];

  /* silently drop broadcast mail */
  if (strchr(to, '*'))
    return;

  imc_initdata(&out.data);
  sprintf(out.to, "Mail-daemon@%s", imc_mudof(from));
  strcpy(out.from, "Mail-daemon");

  /* check if we've already seen it */

  mid=find_id(id);

  if (mid)
  {
    strcpy(out.type, "mail-ok");
    imc_addkey(&out.data, "id", id);

    imc_send(&out);
    imc_freedata(&out.data);

    mid->received = imc_now;

    return;
  }

  /* check for rignores */

  if (imc_isignored(from))
  {
    strcpy(out.type, "mail-reject");
    imc_addkey(&out.data, "id", id);
    imc_addkey(&out.data, "reason", "You are being ignored.");

    imc_send(&out);
    imc_freedata(&out.data);
    return;
  }

  /* forward it to the mud */

  addrtomud(to, temp);

  if ((reason=imc_mail_arrived(from, temp, date, subject, text)) == NULL)
  {
    /* it was OK */

    strcpy(out.type, "mail-ok");
    imc_addkey(&out.data, "id", id);

    imc_send(&out);
    imc_freedata(&out.data);

    mid=new_mailid();
    mid->id=imc_strdup(id);
    mid->received=imc_now;

    add_idlist(mid);
    save_idlist();
    return;
  }

  /* mud rejected the mail */

  strcpy(out.type, "mail-reject");
  imc_addkey(&out.data, "id", id);
  imc_addkey(&out.data, "reason", reason);

  imc_send(&out);
  imc_freedata(&out.data);
}