Welcome to the Builder Academy

Question MSDP Exit Display

More
28 Jul 2015 03:29 - 31 Jul 2015 18:15 #5466 by krell
MSDP Exit Display was created by krell
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.
Code:
MSDPSetString( d, eMSDP_ROOM_EXITS,
Last edit: 31 Jul 2015 18:15 by krell. Reason: just so it's clear I'm asking about exits

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

More
25 Aug 2015 19:08 - 26 Aug 2015 12:03 #5509 by krell
Replied by krell on 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.
Code:
const char *find_exits(struct char_data *); /* MSDP_ROOM_EXITS? */

My function.
Code:
/* 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().
Code:
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: 26 Aug 2015 12:03 by krell. Reason: Addendum

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

More
27 Aug 2015 04:06 - 06 Sep 2015 02:44 #5510 by krell
Replied by krell on 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.
Code:
/* * 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().
Code:
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: 06 Sep 2015 02:44 by krell.

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

Time to create page: 0.201 seconds