Exemple #1
0
/* Empty the queues before closing connection */
void
flush_queues (DESCRIPTOR_DATA * d)
{
  char dummy[MAX_STRING_LENGTH];

  while (get_from_q (&d->output, dummy));
  while (get_from_q (&d->input, dummy));
}
Exemple #2
0
int
process_output (DESCRIPTOR_DATA * t)
{
  char i[MAX_STRING_LENGTH + 1];

  if (!t->prompt_mode && !t->connected && t->edit_index == -1)
    if (write_to_descriptor (t, "\r\n") < 0)
      return (-1);

  /* Cycle thru output queue */
  while (get_from_q (&t->output, i))
    {
      if (t->snoop.snoop_by && t->snoop.snoop_by->desc != NULL
	  && !IS_NPC (t->snoop.snoop_by))
	{
	  write_to_q ("% ", &t->snoop.snoop_by->desc->output);
	  write_to_q (i, &t->snoop.snoop_by->desc->output);
	}
      if (write_to_descriptor (t, i))
	return (-1);
    }

  if (!t->connected && !(t->character && !IS_NPC (t->character) &&
			 GET_FLAG (t->character, FLAG_COMPACT)))
    if (IS_SET (t->edit_mode, MODE_DONE_EDITING) && t->edit_index == -1)
      if (write_to_descriptor (t, "\r\n") < 0)
	return (-1);

  return (1);
}
Exemple #3
0
void hangup_on_a_mud(int mud)
{
  char buf[MAX_INPUT_LENGTH];
  
  if (!IS_SET(muds[mud].flags, DD_CONNECTED))
    return;
  
  close(muds[mud].desc);
  while(get_from_q(&muds[mud].input, buf));
  while(get_from_q(&muds[mud].output, buf));
  if (muds[mud].desc == maxdesc)
    --maxdesc;
  
  REMOVE_BIT(muds[mud].flags, DD_CONNECTED|DD_VERIFIED);
  sprintf(buf, "DIMD connection with %s[%s] closed.",
	  muds[mud].formalname, muds[mud].address);
  DIMDLOG(buf);
}
Exemple #4
0
void dimd_loop(void)
{
  int	  i, fromlevel, fromgodlevel;
  fd_set  input_set, output_set, exc_set;
  static char
    buf[MAX_STRING_LENGTH], extra[MAX_STRING_LENGTH],
    fromname[MAX_INPUT_LENGTH], fromkeyname[MAX_INPUT_LENGTH],
    dcommand[MAX_INPUT_LENGTH], toname[MAX_INPUT_LENGTH], *scan;
  struct  char_data *vict;
  char    comm[MAX_INPUT_LENGTH];
  struct  timeval null_time;
  struct  descriptor_data *d;
  
  
  switch (dimd_state) {
    /****************************************************************/
  case DIMD_OPENING:
    if ((dimd_local_mud=getlocalmud())==UNDEFINED)
      {
	DIMDLOG("Couldn't figure out what this mud's name is!  DIMD NOT opened.");
	dimd_state = DIMD_CLOSED;
	dimd_on = FALSE;
	return;
      };
    
    dimd_port = DIMD_PORT;
    dimd_s=init_socket(dimd_port);
    DIMDLOG("DIMD port opened.");
    
    for(i=0; muds[i].address; i++)
      if (IS_SET(muds[i].flags, DD_AUTOTRY))
	call_a_mud(i);
    
    dimd_state = DIMD_OPEN;
    break;
    
    /****************************************************************/
  case DIMD_OPEN:
    
    null_time.tv_sec = 0;
    null_time.tv_usec = 0;
    
    FD_ZERO(&input_set);
    FD_ZERO(&output_set);
    FD_ZERO(&exc_set);
    FD_SET(dimd_s, &input_set);
    for(i=0; muds[i].address; i++)
      if (IS_SET(muds[i].flags, DD_CONNECTED))
	{
	  FD_SET(muds[i].desc, &input_set);
	  FD_SET(muds[i].desc, &exc_set);
	  FD_SET(muds[i].desc, &output_set);
	};
    
    if (select(maxdesc + 1, &input_set, &output_set, &exc_set, &null_time) < 0)
      {
	perror("Tell select poll");
	return;
      };
    
    
    /* Respond to whatever might be happening */
    
    /* New connection? */
    if (FD_ISSET(dimd_s, &input_set))
      if (!answer_a_mud())
	perror("New connection");
    
    for(i=0; muds[i].address; i++)
      if (IS_SET(muds[i].flags, DD_CONNECTED))
	{
	  if (FD_ISSET(muds[i].desc, &exc_set))
	    {
	      FD_CLR(muds[i].desc, &input_set);
	      FD_CLR(muds[i].desc, &output_set);
	      hangup_on_a_mud(i);
	    };
	};
    
    for(i=0; muds[i].address; i++)
      if (IS_SET(muds[i].flags, DD_CONNECTED))
	{
	  if (FD_ISSET(muds[i].desc, &input_set))
	    if (process_dimd_input(i) < 0) 
	      hangup_on_a_mud(i);
	};
    
    for(i=0; muds[i].address; i++)
      if (IS_SET(muds[i].flags, DD_CONNECTED))
	{
	  while(get_from_q(&muds[i].input, comm))
	    {
	      if (!IS_SET(muds[i].flags, DD_VERIFIED))
		{
		  if (str_cmp(comm, DIMD_PASSWORD))
		    {
		      sprintf(buf, "The mud is located at port %d.\n\r",
			      dimd_port-2);
		      write_to_descriptor(muds[i].desc, buf);
		      sprintf(buf, "%s[%s]'s server didn't know our password.",
			      muds[i].formalname, muds[i].host);
		      DIMDLOG(buf);
		      hangup_on_a_mud(i);
		      break;
		    };
		  
		  SET_BIT(muds[i].flags, DD_VERIFIED);
		  break;
		};
	      
	      if (*comm != '^')
		{
		  if (!(vict=get_char(muds[i].pcname)))
		    {
		      sprintf(buf,
			      "DIMD stream for unknown player %s rejected.",
			      muds[i].pcname);
		      DIMDLOG(buf);
		      DIMDLOG(comm);
		    }
		  else
		    msg(comm, vict);
		  
		  continue;
		};
	      
	      scan = comm+1;
	      scan = one_dimd_argument(scan, fromname);
	      scan = one_dimd_argument(scan, fromkeyname);
	      scan = one_dimd_argument(scan, buf);
	      fromlevel = atoi(buf);
	      if (!*fromname || !*fromkeyname || !fromlevel)
		{
		  write_to_descriptor(muds[i].desc, "Your server isn't working properly.");
		  sprintf(buf, "%s[%s] didn't supply PC names or level.",
			  muds[i].formalname, muds[i].host);
		  DIMDLOG(buf);
		  hangup_on_a_mud(i);
		  break;
		};
	      
	      if (fromlevel < muds[i].min_level)
		sprintf(buf, "You must be at least %d level to use DIMD on %s.",
			muds[i].min_level, muds[i].formalname);
	      else {
		fromgodlevel = (fromlevel-muds[i].immort_level)
		  * muds[i].immort_level_mult;
		scan = one_lc_dimd_argument(scan, dcommand);
		switch(*dcommand)
		  {
		  case '#':
		    strcpy(muds[i].pcname, fromkeyname);
		    continue;
		    
		  case 'a':
		    switch(*(dcommand+1))
		      {
		      case 'g':
			sprintf(buf, "%s is now accepting remote gossips.",
				muds[i].formalname);
			REMOVE_BIT(muds[i].flags, DD_NOGOSSIP);
			break;
			
		      case 'm':
			sprintf(buf, "%s is now accepting remote muses.",
				muds[i].formalname);
			REMOVE_BIT(muds[i].flags, DD_NOMUSE);
			break;
			
		      case 't':
			sprintf(buf, "%s is now accepting remote thinks.",
				muds[i].formalname);
			REMOVE_BIT(muds[i].flags, DD_NOTHINK);
			break;
			
		      default:
			sprintf(buf, "Unknown accept command from %s.",
				muds[i].formalname);
		      };
		    DIMDLOG(buf);
		    continue;
		    
		  case 'r':
		    switch(*(dcommand+1))
		      {
		      case 'g':
			sprintf(buf, "%s is now refusing remote gossips.",
				muds[i].formalname);
			SET_BIT(muds[i].flags, DD_NOGOSSIP);
			break;
			
		      case 'm':
			sprintf(buf, "%s is now refusing remote muses.",
				muds[i].formalname);
			SET_BIT(muds[i].flags, DD_NOMUSE);
			break;
			
		      case 't':
			sprintf(buf, "%s is now refusing remote thinks.",
				muds[i].formalname);
			SET_BIT(muds[i].flags, DD_NOTHINK);
			break;
			
		      default:
			sprintf(buf, "Unknown refuse command from %s.",
				muds[i].formalname);
		      };
		    DIMDLOG(buf);
		    continue;
		    
		  case 'w':
		    sprintf(buf, "Who request from %s at %s served.",
			    fromname, muds[i].formalname);
		    DIMDLOG(buf);
/*
		    construct_who_list(buf, 39, NULL, fromgodlevel, scan);
*/		    
		    break;
		    
		  case 't':
	            scan = one_lc_dimd_argument(scan, toname);
		    while(isspace(*scan)) scan++;
		    
	            if (!(vict = get_char(toname))
			|| !dimd_can_see(fromgodlevel, vict))
		      strcpy(buf, "No char by that name.");
	            else
		      {
#if USE_COLOR
			sprintf(buf, "$kW%s $kMfrom $kW%s $kMtells you '%s'.",
				fromname, muds[i].formalname, scan);
#else
			sprintf(buf, "%s from %s tells you '%s'.",
				fromname, muds[i].formalname, scan);
#endif				
			cmsg(buf, vict, CLR_TELL);
			if (IS_SET(vict->pc->comm, COMM_AFK))
#if USE_COLOR
			  sprintf(buf, "$kMYou tell $kW%s$kM (who is AFK), '%s'",
				  PER(vict), scan);
#else
			  sprintf(buf, "You tell %s (who is AFK), '%s'",
				  PER(vict), scan);

#endif				  
			else
#if USE_COLOR
			  sprintf(buf, "$kMYou tell $kW%s$kM, '%s'",
				  PER(vict), scan);
#else
			  sprintf(buf, "You tell %s, '%s'",
				  PER(vict), scan);
#endif				  
		      };
		    break;
		    
		  case 'g':
		    if (!dimd_gossip)
		      {
			write_to_descriptor(muds[i].desc, "^DIMD^DIMD^110^rg\n\r");
			sprintf(buf, "%s is no longer accepting remote gossips.", muds[dimd_local_mud].formalname);
			break;
		      };
		    if (*(dcommand+1)=='g')
#if USE_COLOR
		      sprintf(buf, "$kW%s $kYfrom $kW%s $kYdimension gossips, '%s'",
			      fromname, muds[i].formalname, scan);
#else
		      sprintf(buf, "%s from %s dimension gossips, '%s'",
			      fromname, muds[i].formalname, scan);
#endif			      
		    else
#if USE_COLOR
		      sprintf(buf, "$kW%s $kYfrom $kW%s $kYgossips, '%s'",
			      fromname, muds[i].formalname, scan);
#else
		      sprintf(buf, "%s from %s gossips, '%s'",
			      fromname, muds[i].formalname, scan);
#endif			      
		    
		    for(d = descriptor_list; d; d = d->next)
		      if (!d->connected
			  && !IS_SET(d->character->pc->comm, COMM_NOGOSSIP)
			  && !check_soundproof(d->character))
			cmsg(buf, d->character, CLR_GOSSIP);
		    
#if USE_COLOR
		    sprintf(buf, "$kYYou gossip on $kW%s$kY, '%s'",
			    muds[dimd_local_mud].formalname, scan);
#else
		    sprintf(buf, "You gossip on %s, '%s'",
			    muds[dimd_local_mud].formalname, scan);

#endif			    
		    break;
		    
		  case 'm':
		    if (!dimd_muse)
		      {
			write_to_descriptor(muds[i].desc, "^DIMD^DIMD^110^rm\n\r");
			sprintf(buf, "%s is no longer accepting remote muses.", muds[dimd_local_mud].formalname);
			break;
		      };
		    
		    if (*(dcommand+1)=='g')
#if USE_COLOR
		      sprintf(buf, "$kW%s $kLfrom $kW%s $kLdimension muses, '%s'",
			      fromname, muds[i].formalname, scan);
#else
		      sprintf(buf, "%s from %s dimension muses, '%s'",
			      fromname, muds[i].formalname, scan);
#endif			      
		    else
#if USE_COLOR
		      sprintf(buf, "$kW%s $kLfrom $kW%s $kLmuses, '%s'",
			      fromname, muds[i].formalname, scan);
#else
		      sprintf(buf, "%s from %s muses, '%s'",
			      fromname, muds[i].formalname, scan);
#endif			      
		    for(d = descriptor_list; d; d = d->next)
		      if (!d->connected
			  && GetMaxLevel(d->character) >= LOW_IMMORTAL
			  && !IS_SET(d->character->pc->comm, COMM_NOMUSE))
			cmsg(buf, d->character, CLR_MUSE);
		    
#if USE_COLOR
		    sprintf(buf, "$kLYou muse on $kW%s$kL, '%s'",
			    muds[dimd_local_mud].formalname, scan);
#else
		    sprintf(buf, "You muse on %s, '%s'",
			    muds[dimd_local_mud].formalname, scan);
#endif
		    break;
		    
		  case '*':
		    if (!dimd_think)
		      {
			write_to_descriptor(muds[i].desc, "^DIMD^DIMD^110^rt\n\r");
			sprintf(buf, "%s is no longer accepting remote thinks.", muds[dimd_local_mud].formalname);
			break;
		      };
		    if (*(dcommand+1)=='g')
#if USE_COLOR
		      sprintf(buf, "$kW%s $kLfrom $kW%s $kLdimension thinks, '%s'",
			      fromname, muds[i].formalname, scan);
#else
		      sprintf(buf, "%s from %s dimension thinks, '%s'",
			      fromname, muds[i].formalname, scan);

#endif			      
		    else
#if USE_COLOR
		      sprintf(buf, "$kW%s $kLfrom $kW%s $kLthinks, '%s'",
			      fromname, muds[i].formalname, scan);
#else
		      sprintf(buf, "%s from %s thinks, '%s'",
			      fromname, muds[i].formalname, scan);

#endif			      
		    for(d = descriptor_list; d; d = d->next)
		      if (!d->connected
			  && GetMaxLevel(d->character) >= DEMIGOD
			  && !IS_SET(d->character->pc->comm, COMM_NOMUSE))
			cmsg(buf, d->character, CLR_THINK);
		    
#if USE_COLOR
		    sprintf(buf, "$kLYou think on $kW%s$kL, '%s'",
			    muds[dimd_local_mud].formalname, scan);
#else
		    sprintf(buf, "You think on %s, '%s'",
			    muds[dimd_local_mud].formalname, scan);

#endif			    
		    break;
		    
		  default:
#if USE_COLOR
		    sprintf(buf, "$kW%s $kRfrom $kW%s $kRissued invalid command '%s'.",
			    fromname, muds[i].formalname, dcommand);
#else
		    sprintf(buf, "%s from %s issued invalid command '%s'.",
			    fromname, muds[i].formalname, dcommand);
#endif			    
		    DIMDLOG(buf);
#if USE_COLOR
		    strcpy(buf, "$k+BRYour server isn't functioning properly.");
#else
		    strcpy(buf, "Your server isn't functioning properly.");
#endif		    
		  };
	      };