MSDP Exit Display

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
2 years 6 months ago - 2 years 6 months ago #5466 by Krell
Krell created the topic: MSDP Exit Display
I'm playing around with the MSDP settings trying to get exits to display on my MSDP prompt bar on tintin. I've made the following entry in comm.c but I don't know how to complete it so it works. Any help would be appreciated.
MSDPSetString( d, eMSDP_ROOM_EXITS, 
Last Edit: 2 years 6 months ago by Krell. Reason: just so it's clear I'm asking about exits

Please Log in or Create an account to join the conversation.

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
2 years 5 months ago - 2 years 5 months ago #5509 by Krell
Krell replied the topic: MSDP Exit Display
I've made the following alterations to comm.c. I think this should work but I'm getting some strange looking characters in my client when I try to access the values. Either the code doesn't work the way I think it does or the script in my client isn't parsing the values properly. Maybe both.

My function prototype.
const char *find_exits(struct char_data *);  /* MSDP_ROOM_EXITS? */

My function.
/* Trying to make MSDP_ROOM_EXITS work. */
const char *find_exits(struct char_data *ch)
{
      int door, len = 0;
      char *msdp_exits;

      msdp_exits = calloc(DIR_COUNT, sizeof(char));

      for (door = 0; door < DIR_COUNT; door++) {
	      if (!EXIT(ch, door) || EXIT(ch, door)->to_room == NOWHERE)
		      continue;
	      if (EXIT_FLAGGED(EXIT(ch, door), EX_CLOSED) && !CONFIG_DISP_CLOSED_DOORS)
		      continue;
	      if (EXIT_FLAGGED(EXIT(ch, door), EX_HIDDEN) && !PRF_FLAGGED(ch, PRF_HOLYLIGHT))
		      continue;

	      msdp_exits[len] = dirs[door];

	      len++;

	      msdp_exits[len] = GET_ROOM_VNUM(EXIT(ch, door)->to_room);

	      len++;
      }

      return (msdp_exits);
}

My ROOM_EXITS entry in msdp_update().
      MSDPSetTable( d, eMSDP_ROOM_EXITS, find_exits(ch) );

Thoughts, pointers?

Addendum:

Just realized I'm being an idiot again. "msdp_exits[LEN] = DIRS[door]" won't work because I'm trying to copy an array as an element of a array. I'll need to rewrite that function to fix it.
Last Edit: 2 years 5 months ago by Krell. Reason: Addendum

Please Log in or Create an account to join the conversation.

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
2 years 5 months ago - 2 years 5 months ago #5510 by Krell
Krell replied the topic: MSDP Exit Display
At the risk of sounding crazy for chattering to myself, here is my working albeit not final solution. Things finally clicked when I found KaViR's explanation for MSDPTableSet in protocols.h, I can't believe I has missed it so often! I will probably alter the following code in the future.
/* 
 * Find all the exits in the room and display them and the VNUMS of the connecting
 * rooms through the MSDP_ROOM_EXITS interface.
 * Pre: a valid pointer to the MUD PC.
 */
const char *find_exits(struct char_data *ch)
{
      int door, elen = 150; /* elen a bit larger than the number of chars needed for all exits and VNUMS. */
      char *msdp_exits, *buf;

      msdp_exits = calloc(DIR_COUNT * 2, sizeof(char*)); /* Must be free'd by msdp_update(). */
      buf        = calloc(DIR_COUNT * 2, sizeof(char*));


      for (door = 0; door < DIR_COUNT; door++) {
	      if (!EXIT(ch, door) || EXIT(ch, door)->to_room == NOWHERE)
		      continue;
	      if (EXIT_FLAGGED(EXIT(ch, door), EX_CLOSED) && !CONFIG_DISP_CLOSED_DOORS)
		      continue;
	      if (EXIT_FLAGGED(EXIT(ch, door), EX_HIDDEN) && !PRF_FLAGGED(ch, PRF_HOLYLIGHT))
		      continue;

	      sprintf(buf, "%c%s%c%d", (char)MSDP_VAR, dirs[door], (char)MSDP_VAL, GET_ROOM_VNUM(EXIT(ch, door)->to_room));

	      /* *BSD specific, not exactly the most portable. */
	      (void)strlcat(msdp_exits, buf, elen);
      }
      free(buf);
      return (msdp_exits);
}

In msdp_update().
     char buf[MAX_STRING_LENGTH], *buf2;
.
.
.
      buf2 = find_exits(ch);
      MSDPSetTable( d, eMSDP_ROOM_EXITS, buf2 );
.
.
.
      MSDPUpdate( d );
    }

    free(buf2);

Again, pointers and comments welcome.

Addendum:

free in msdp_updates() is in the wrong spot. Causes undefined behavior when an uninitialized pointer is free'd. Might cause a crash on login if not some other point. Place free immediately after the MSDPSetTable or, better yet, use tba's STRFREE macro immediately after.

Addendum 2:

According to the MSDP spec, exit directions are supposed to be abbreviated. Changed dirs[door] to autoexits[door].

tintin.sourceforge.net/msdp/
Last Edit: 2 years 5 months ago by Krell.

Please Log in or Create an account to join the conversation.

Time to create page: 1.088 seconds