Global Boards
Posted by Orik
on Mon 15 Jan 2007 11:53 PM
— 26 posts, 94,590 views.
I searched for global boards and most of them came back with Erwins snippet which I don't want to mess with. I want one global board that all will be able to read from anywhere in the mud. I've narrowed it down to these peices of code that I believe to be the culprit to change in order to set it correctly and not have to worry about people being in the room:
BOARD_DATA *get_board( OBJ_DATA * obj )
{
BOARD_DATA *board;
for( board = first_board; board; board = board->next )
if( board->board_obj == obj->pIndexData->vnum )
return board;
return NULL;
}
BOARD_DATA *find_board( CHAR_DATA * ch )
{
OBJ_DATA *obj;
BOARD_DATA *board;
for( obj = ch->in_room->first_content; obj; obj = obj->next_content )
{
if( ( board = get_board( obj ) ) != NULL )
return board;
}
return NULL;
}
I figure I need to change them somehow. I defined OBJ_VNUM_GBOARD as vnum 100 in mud.h
So something along the lines of:
board == OBJ_VNUM_GBOARD
get rid of the ch->in_room somehow to not check to see if they are in room.
Any thoughts or ideas?
Here's what I did:
BOARD_DATA *get_board( OBJ_DATA * obj )
{
BOARD_DATA *board;
for( board = first_board; board; board = board->next )
if( board->board_obj == OBJ_VNUM_GBOARD )
return board;
return NULL;
}
BOARD_DATA *find_board( CHAR_DATA * ch )
{
OBJ_DATA *obj;
BOARD_DATA *board;
board = get_board ( obj );
return board;
}
That works mudwide whereever you are. Now I'll have to figure out how to make it so that you get like a * beside it if the note is new and you hadn't read it yet.
I'll look at that mudmagic snippet real quick.
I wouldn't use the old note system. Probably write your own code. Shouldn't be too hard, just an array for the boards, notes are written to a file, etc.
it would be a lot easier to just use erwins board code, its a pretty good system.
From what I've seen & heard about it, Erwin's is certainly passable, if not pretty nice, once you get past all the bugs and glitches in it. But don't take my word for it, do a search for global boards or gboards on the fuss forums. ;)
Ok, I've put in the code from mudmagic, but I'm getting a warning from it. Here is the warning:
boards.c: In function 'chk_unread':
boards.c:2074: warning: comparison between pointer and integer
make[1]: *** [o/boards.o] Error 1
Make: *** [all] Error 2
Here is the code:
void chk_unread( CHAR_DATA *ch )
{
BOARD_DATA *board;
NOTE_DATA *newnote;
short unread = 0;
char buf[MAX_INPUT_LENGTH];
struct stat fst;
short count = 0;
sprintf( buf, "%s%c/%s", PLAYER_DIR, tolower(ch->name[0]), ch->name );
if ( stat( buf, &fst ) != -1 )
{
sprintf( buf, "You were last on: %s\r", ctime( &fst.st_mtime ) );
send_to_char( buf, ch );
}
else
{
send_to_char( "For some reason, you weren't found in the player database.\n\r", ch );
return;
}
for ( board = first_board; board; board = board->next )
{
if ( board->num_posts == 0
|| board->min_read_level > ch->level
|| board->type != BOARD_NOTE )
continue;
for ( newnote = board->first_note; newnote; newnote = newnote->next )
{
if ( newnote->time > ch->pcdata->last_read )<----offending warning 2074.
unread += 1;
}
if ( unread != 0 )
{
sprintf( buf, "You have %d new note%s.\n\r",
unread, unread == 1 ? "" : "s" );
send_to_char( buf, ch );
unread = 0;
count += 1;
}
}
if ( count == 0 )
send_to_char( "You have no new messages on ANY boards.\n\r", ch );
return;
}
In mud.h I've put at the end:
in the "struct note_data"
Why is the time data member a char*? The warning you're getting is actually significant, because you're trying to compare a string to a number, and the result will be something nonsensical. Where do newnote->time and ch->pcdata->last_read get set?
time is in mud.h struct note_data
last read is:
time_t last_read; in the pc_data struct
I don't think that's the snippet you want. All it does (I believe) is checks if you have any unread notes on any boards. It doesn't allow you to globally post or anything.
That's also unfortunately not the question I asked... I wanted to know where they get assigned a value (i.e. get set), not where they are declared. Seeing where they are set can give hints as to the intention of the snippet.
But, Zeno's comment seems to have a higher priority! :-) "This is not the snippet you're looking for", to paraphrase an old friend.
Well, I have already made my boards global just by making one board and using that one board as OBJ_VNUM_GBOARD. Notes can be checked anywhere in game without having to be in a board room. Note list will check the board. SO that's not the problem. The problem I'm encountering is when I want to show people when they have new notes. So this check unread is doing that. It's just encountering a bug. I don't see any problems in my initial board code right now except the time isn't working correctly.
The newnote->time is not in any other structure I don't think. I don't see where it is set a value. This is the first time it's used. I guess that's the problem eh? heh.
Well, you have to set the time somewhere if you're going to test it against last_read. Somewhere, you need to set some reasonable time for each individual note, as well as making sure it gets loaded and saved to board files. I can't really help much more because I don't know anything about the snippet you're using.
Here's where I got the snippet.
http://www.mudmagic.com/codes/server-snippet/1097
I went through that and it never said to set the time anywhere.
Ok, I figured it out. I used the int vnum from the posts and changed last_read to an int in pc_data.
if (vnum > ch->pcdata->last_read)
I now have global boards and can check everytime I log on to see the new notes I have.
Just curios though, Zeno.
What's wrong with this board.c? Is there memory leaks on it or what? I know you said you didn't like it so you made your own. Could you give me a glimpse of what was wrong so I can fix it? I haven't found anything wrong with it yet.
I don't remember saying anything was wrong with board.c or that I made my own.
ah sorry, I've read too many different posts..hehe. But you did say you wouldn't use the old note sytem? Is that because it's buggy or what?
I wouldn't say bugged, but I personally would just write new code for global boards and not change the current board code.
if (vnum > ch->pcdata->last_read)
That doesn't make any sense to me. Why are we comparing a vnum to a time? (is last_read a time?)
I set last_read as an integer instead of time. So when it's adding up the vnum's for the notes, I'm checking to see if the number stored in the char's pfile is smaller than the new vnums out there.
So if there were 5 notes for that player, but his pfile had 2 stored in last_read then when he logged in, it would say you have 3 notes. Then when he read them it would update in his pfile so after he's done reading note 5, his pfile now says 5 in last_read.
I've pretty much got all the kinks out and it's working quite well. It updates on note read, and note post and also works correctly in chk_unread.
Oh. I think we're not using vnum to refer to the same concept. :) But it's cool that you got your system working.
Yea, they used vnum in note list as an integer so I just set it as that as well. I don't know why they did, I guess I could change it to like nnum for note number or something, but meh...it works..heh. Once I seriously test it all out for any and all bugs, i'll post it if anyone wants it. Basically it's an easy fix for global boards if you don't want to use the smaug board system. I'm thinking about making it to where if they are in a room with a board, they can read that one and post to it, but if they are not in that room it goes to the main global board. We'll see what I come up with.
Hmmm I have trouble installing boards too...
Sad to say, I'm using the windows version, and I don't have a compiler if ever.
Can anyone advise me how to fix the problem, and if possible, through the current limitations I have? I can only edit things via what I have in windows, and I don't have a compiler for C.
If you don't have a compiler you won't be able to put in any code, including the Gboard snippet.
It's not particularly hard to install the free Cygwin compiler, see:
http://www.gammon.com.au/smaug/installingcygwin.htm
Ok I got the cygwin installed. Now...
How to make the changes to add the GBoards? Which file do I have to edit? Which part of the file?
Assume that I'm a newbie (which I partially am) to mud coding in fairness to anyone else who might ask the same question in the future. ^_^
The gboard snippet should come with instructions.