Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Bing

Members: 0
Guests: 12
Stats
Files
Topics
Posts
Members
Newest Member
481
3,739
19,386
627
MargoThurb
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Smaug Snippets » Finger Snippet
Forum Rules | Mark all | Recent Posts

Finger Snippet
< Newer Topic :: Older Topic > changes to it

Pages:<< prev 1 next >>
Post is unread #1 Aug 25, 2003, 12:14 am
Go to the top of the page
Go to the bottom of the page

Edge

GroupMembers
Posts2
JoinedAug 24, 2003

OK, basically while going through the finger snippet I was not satisfied with the way it was done including of course the goto statement, so I decided to rewrite it in a way the leaves out the goto statement and makes the code much easier to read and handle. I got it working fine on my MUD, but I am unsure if it will work anywhere else, I intend to test it on an unmodified version of SMAUG but haven't had the chance yet, if anyone here wants to try the code or just wants to see it, feel free to e-mail me.
       
Post is unread #2 Aug 25, 2003, 8:25 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

I would certainly be interested in any solution you might have come up with. Feel free to PM me with a link.
       
Post is unread #3 Aug 25, 2003, 11:42 pm
Go to the top of the page
Go to the bottom of the page

Edge

GroupMembers
Posts2
JoinedAug 24, 2003

I tested it out, and it works fine with unmodified SMAUG 1.4a, I e-mailed it to someone who said he will give it to Samson I think for lack of anything else to do, I will post it here (if it fits), just copy the whole thing and save it as finger.c to replace the current one, it should work, any bugs let me know. Oh, and as for parts I changed, do whatever you like with them, I personally couldn't care less what people do with my code, but if you enjoy it or find any ways to change or improve it or any other feedback, please let me know, like any author I enjoy seeing my work used.

There is one small problem with the code which is the title. Chars load up without a space in the title whereas if the title is changed while online a space is added, this is caused by the fact that when it is read from the file the space is ignored. I found that if I changed the part in void fread_char that loads the title (under case 'T') to the same thing I have in fread_finger in this code it solved the problem, you might want to look into that.
-Edge
---------------
/****************************************************************************
* ^ +----- | / ^ ^ | | +- *
* / | | / | /| | | | *
* / +--- |< | / | | | | | *
* /----- | | | v | | | | / *
* / | | | | +-----+ +-/ *
****************************************************************************
* AFKMud Copyright 1997-2002 Alsherok. Contributors: Samson, Dwip, Whir, *
* Cyberfox, Karangi, Rathian, Cam, Raine, and Tarl. *
* *
* Original SMAUG 1.4a written by Thoric (Derek Snider) with Altrag, *
* Blodkai, Haus, Narn, Scryn, Swordbearer, Tricops, Gorog, Rennard, *
* Grishnakh, Fireblade, and Nivek. *
* *
* Original MERC 2.1 code by Hatchet, Furey, and Kahn. *
* *
* Original DikuMUD code by: Hans Staerfeldt, Katja Nyboe, Tom Madsen, *
* Michael Seifert, and Sebastian Hammer. *
****************************************************************************
* Finger and Wizinfo Module *
****************************************************************************/
/******************************************************
Additions and changes by Edge of Acedia
Rewritten fread_finger, load
finger and do_finger to better
handle info of offline players.
E-mail: nevesfirestar2002@yahoo.com
******************************************************/
#include
#include
#include
#include
#include "mud.h"

#if defined(KEY)
#undef KEY
#endif
#define KEY( literal, field, value )
if ( !str_cmp( word, literal ) )
{
field = value;
fMatch = TRUE;
break;
}

/* Begin wizinfo stuff - Samson 6-6-99 */
bool check_parse_name args( ( char *name, bool newchar ) );
WIZINFO_DATA * first_wizinfo;
WIZINFO_DATA * last_wizinfo;

/* Construct wizinfo list from god dir info - Samson 6-6-99 */
void add_to_wizinfo( char *name, WIZINFO_DATA *wiz )
{
WIZINFO_DATA *wiz_prev;
wiz->name = str_dup( name );
if ( !wiz->email )
wiz->email = str_dup( "Not Set" );
for( wiz_prev = first_wizinfo; wiz_prev; wiz_prev = wiz_prev->next )
if( strcasecmp( wiz_prev->name, name ) >= 0 )
break;
if( !wiz_prev )
LINK( wiz, first_wizinfo, last_wizinfo, next, prev );
else
INSERT( wiz, wiz_prev, first_wizinfo, next, prev );
return;
}

void clear_wizinfo( bool bootup )
{
WIZINFO_DATA *wiz, *next;
if( !bootup )
{
for ( wiz = first_wizinfo; wiz; wiz = next )
{
next = wiz->next;
UNLINK( wiz, first_wizinfo, last_wizinfo, next, prev );
DISPOSE( wiz->name );
DISPOSE( wiz->email );
DISPOSE( wiz );
}
}
first_wizinfo = NULL;
last_wizinfo = NULL;
return;
}

void fread_info( WIZINFO_DATA *wiz, FILE *fp )
{
char *word;
bool fMatch;
for ( ; ; )
{
word = feof( fp ) ? "End" : fread_word( fp );
fMatch = FALSE;
switch ( UPPER(word[0]) )
{
case '*':
fMatch = TRUE;
fread_to_eol( fp );
break;
case 'E':
KEY( "Email", wiz->email, fread_string_nohash( fp ) );
if ( !str_cmp( word, "End" ) )
return;
break;
case 'I':
KEY( "ICQ", wiz->icq, fread_number( fp ) );
break;
case 'L':
KEY( "Level", wiz->level, fread_number( fp ) );
break;
}
if ( !fMatch )
fread_to_eol( fp );
}
}

void build_wizinfo( bool bootup )
{
DIR *dp;
struct dirent *dentry;
FILE *fp;
WIZINFO_DATA *wiz;
char buf[MSL];
clear_wizinfo( bootup ); /* Clear out the table before rebuilding a new one */
dp = opendir( GOD_DIR );
dentry = readdir( dp );
while ( dentry )
{
/* Added by Tarl 3 Dec 02 because we are now using CVS */
if( !str_cmp( dentry->d_name, "CVS" ) )
{
dentry = readdir( dp );
continue;
}
if ( dentry->d_name[0] != '.' )
{
sprintf( buf, "%s%s", GOD_DIR, dentry->d_name );
fp = fopen( buf, "r" );
if ( fp )
{
CREATE( wiz, WIZINFO_DATA, 1 );
fread_info( wiz, fp );
add_to_wizinfo( dentry->d_name, wiz );
FCLOSE( fp );
}
}
dentry = readdir( dp );
}
closedir( dp );
return;
}

/*
* Wizinfo information.
* Added by Samson on 6-6-99
*/
void do_wizinfo( CHAR_DATA *ch, char *argument )
{
WIZINFO_DATA *wiz;
char buf[MSL];
send_to_pager( "Contact Information for the Immortals:\n\r", ch );
send_to_pager( "Name Email Address ICQ#\n\r", ch );
send_to_pager( "------------+---------------------------------+----------\n\r", ch );
for ( wiz = first_wizinfo; wiz; wiz = wiz->next )
{
sprintf( buf, "%-12s %-33s %10d", wiz->name, wiz->email, wiz->icq );
strcat( buf, "\n\r" );
send_to_pager( buf, ch );
}
return;
}

/* End wizinfo stuff - Samson 6-6-99 */
/* Rewritten by Edge of Acedia */
void fread_finger( CHAR_DATA *victim, FILE *fp )
{
char buf[MAX_STRING_LENGTH];
char *word;
bool fMatch;
for ( ; ; )
{
word = feof( fp ) ? "End" : fread_word( fp );
fMatch = FALSE;
switch ( UPPER(word[0]) )
{
case '*':
fMatch = TRUE;
fread_to_eol( fp );
break;
case 'A':
KEY( "AuthedBy", victim->pcdata->authed_by, fread_string( fp ) );
break;
case 'B':
KEY( "Bio", victim->pcdata->bio, fread_string( fp ) );
break;
case 'C':
KEY( "Class", victim->class, fread_number( fp ) );
break;
case 'E':
if ( !strcmp( word, "End" ) )
return;
KEY( "Email", victim->pcdata->email, fread_string_nohash( fp ) );
break;
case 'F':
KEY( "Flags", victim->pcdata->flags, fread_number( fp ) );
break;
case 'H':
KEY( "Homepage", victim->pcdata->homepage, fread_string_nohash( fp ) );
break;
case 'I':
KEY( "ICQ", victim->pcdata->icq, fread_number( fp ) );
break;
case 'L':
KEY( "Level", victim->level, fread_number( fp ) );
break;
case 'N':
KEY ("Name", victim->name, fread_string( fp ) );
case 'P':
KEY( "Played", victim->played, fread_number( fp ) );
break;
case 'R':
KEY( "Race", victim->race, fread_number( fp ) );
break;
case 'S':
KEY( "Sex", victim->sex, fread_number( fp ) );
if ( !str_cmp( word, "Site" ) )
{
/* I wish there was something better to use, but I think that this was
meant for misc strings -Edge */
victim->dest_buf = STRALLOC( fread_word( fp ) );
fMatch = TRUE;
}
break;
case 'T':
if ( !strcmp( word, "Title" ) )
{
victim->pcdata->title = fread_string( fp );
if ( isalpha(victim->pcdata->title[0]) || isdigit(victim->pcdata->title[0]) )
{
buf[0] = ' ';
strcpy( buf+1, victim->pcdata->title );
}
else
strcpy( buf, victim->pcdata->title );

STRFREE( victim->pcdata->title );
victim->pcdata->title = STRALLOC( buf );
fMatch = TRUE;
}
break;
if ( !fMatch )
{
sprintf( buf, "Fread_char: no match: %s", word );
bug( buf, 0 );
}
}
}
}

/* Rewritten for offline fingering by Edge of Acedia */
bool load_finger( CHAR_DATA *victim, char *fingload )
{
FILE *fpFinger;
bool found;

found = FALSE;
if ( ( fpFinger = fopen( fingload, "r" ) ) != NULL )
{
found = TRUE;
for ( ; ; )
{
char letter;
char *word;

letter = fread_letter( fpFinger );

if ( letter != '#' )
continue;
word = fread_word( fpFinger );
if ( !str_cmp( word, "End" ) )
break;
if ( !strcmp( word, "PLAYER" ) )
fread_finger ( victim, fpFinger );
else
if ( !str_cmp( word, "END" ) ) /* Done */
break;
}
FCLOSE( fpFinger );
}
return found;
}
/* Finger snippet courtesy of unknown author. Installed by Samson 4-6-98 */
/* File read/write code redone using standard Smaug I/O routines - Samson 9-12-98 */
/* Data gathering now done via the pfiles, eliminated separate finger files - Samson 12-21-98 */
/* Rewritten to improve offline fingering by Edge of Acedia */
void do_finger( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *victim = NULL;
char *laston = NULL;
char buf[MSL];
char fingload[MAX_INPUT_LENGTH];
char ipbuf[MSL];
struct stat fst;
if( IS_NPC(ch) )
{
send_to_char( "Mobs can't use the finger command.\n\r", ch );
return;
}
if ( !argument || argument[0] == '&#65533;' )
{
send_to_char("Finger whom?\n\r", ch );
return;
}
strcpy( buf, "0." );
strcat( buf, argument );

/* If player is online, check for fingerability (yeah, I coined that one) -Edge */
if ( ( victim = get_char_world( ch, buf ) ) != NULL )
{
if ( IS_SET( victim->pcdata->flags, PCFLAG_PRIVACY ) && !IS_IMMORTAL(ch) )
{
ch_printf( ch, "%s has privacy enabled.\n\r", victim->name );
return;
}
if ( IS_IMMORTAL(victim) && !IS_IMMORTAL(ch) )
{
send_to_char( "You cannot finger an immortal.\n\r", ch );
return;
}
}
/* Check for offline players -Edge */
else
{
sprintf( fingload, "%s%c/%s", PLAYER_DIR, tolower(argument[0]), capitalize( argument ) );
/* Bug fix here provided by Senir to stop /dev/null crash */
if ( stat( fingload, &fst ) == -1 || !check_parse_name( capitalize( argument ), FALSE ))
{
ch_printf( ch, "&YNo player named '%s'.\n\r", argument );
return;
}

/* Lets create an imaginary victim and load up all the info we need -Edge */
laston = ctime( &fst.st_mtime );
CREATE( victim, CHAR_DATA, 1 );
CREATE( victim->pcdata, PC_DATA, 1 );
load_finger( victim, fingload );

if ( IS_SET( victim->pcdata->flags, PCFLAG_PRIVACY ) && !IS_IMMORTAL(ch) )
{
ch_printf( ch, "%s has privacy enabled.\n\r", victim->name );
return;
}
if ( IS_IMMORTAL(victim) && !IS_IMMORTAL(ch) )
{
send_to_char( "You cannot finger an immortal.\n\r", ch );
return;
}
}
send_to_char("&w Finger Info\n\r", ch);
send_to_char(" -----------\n\r", ch);
if ( get_char_world( ch, buf) == NULL )
ch_printf( ch, "&wName : &G%-20s\n\r", victim->name );
else
ch_printf( ch, "&wName : &G%-20s &wMUD Age: &G%d\n\r", victim->name, get_age( victim ) );
ch_printf( ch, "&wSex : &G%-20s &w Race: &G%s\n\r",
victim->sex == SEX_MALE ? "Male" :
victim->sex == SEX_FEMALE ? "Female" : "Neutral",
capitalize( get_race(victim) ) );
/* Slight problem here with title bec. I find it loads up without a space altho if changed a space is added */
ch_printf( ch, "&wTitle:&G%s\n\r", victim->pcdata->title );
if ( !victim->pcdata->homepage
|| ( victim->pcdata->homepage && !strcmp( victim->pcdata->homepage, "" ) ) )
ch_printf( ch, "&wHomepage: &GNot specified\n\r" );
else
ch_printf( ch, "&wHomepage: &G%s\n\r", victim->pcdata->homepage );
if ( !victim->pcdata->email
|| ( victim->pcdata->email && !strcmp( victim->pcdata->email, "" ) ) )
ch_printf( ch, "&wEmail: &GNot specified\n\r" );
else
ch_printf( ch, "&wEmail: &G%s\n\r", victim->pcdata->email );
if ( victim->pcdata->icq == 0 || !victim->pcdata->icq )
ch_printf( ch, "&wICQ#: &GNot specified\n\r" );
else
ch_printf( ch, "&wICQ#: &G%d\n\r", victim->pcdata->icq );
if( get_char_world( ch, buf ) == NULL )
ch_printf( ch, "&wLast on: &G%s", laston );
else
ch_printf( ch, "&wLogged on: &G%s", (char *) ctime( &victim->logon ) );
if ( IS_IMMORTAL(ch) )
{
send_to_char( "&wImmortal Information\n\r", ch );
send_to_char( "--------------------\n\r", ch );
if( get_char_world( ch, buf ) == NULL )
{
ch_printf( ch, "&wLast IP : &G%s\n\r", victim->dest_buf );
ch_printf( ch, "&wTime played : &G%d hours\n\r", ( victim->played / 3600 ) );
}
else
{
if ( victim->desc )
sprintf( ipbuf, "%s@%s", victim->desc->user, victim->desc->host );
else
strcpy( ipbuf, "(Link-Dead)" );
ch_printf( ch, "&wIP Info : &G%s\n\r", ipbuf );
ch_printf( ch, "&wTime played : &G%d hours\n\r", GET_TIME_PLAYED( victim ) );
}
ch_printf( ch, "&wAuthorized by : &G%s\n\r",
victim->pcdata->authed_by ? victim->pcdata->authed_by : ( sysdata.WAIT_FOR_AUTH ? "Not Authed" : "The Code" ) );
ch_printf( ch, "&wPrivacy Status: &G%s\n\r", IS_SET( victim->pcdata->flags, PCFLAG_PRIVACY ) ? "Enabled" : "Disabled" );
}
if ( !victim->pcdata->bio
|| ( victim->pcdata->bio && !strcmp( victim->pcdata->bio, "" ) ) )
ch_printf( ch, "&wBio:\n\r&GNot created\n\r" );
else
ch_printf( ch, "&wBio:\n\r&G%s\n\r", victim->pcdata->bio );
/* Lets put the victim back offline where he belongs
(I'm not sure I did this right) -Edge */
if( get_char_world( ch, buf ) == NULL )
DISPOSE( victim );
return;

}

/* Added a clone of homepage to let players input their email addy - Samson 4-18-98 */
void do_email( CHAR_DATA *ch, char *argument )
{
char buf[MSL];
if ( IS_NPC(ch) )
return;
if ( argument[0] == '\0' )
{
if ( !ch->pcdata->email || !strcmp( ch->pcdata->email, "" ) )
{
ch_printf( ch, "You have not set your email address.\n\r" );
ch->pcdata->email = str_dup( "" );
}
else
ch_printf( ch, "Your email address is: %s\n\r", show_tilde( ch->pcdata->email ) );
return;
}
if ( !str_cmp( argument, "clear" ) )
{
if ( ch->pcdata->email )
DISPOSE(ch->pcdata->email);
ch->pcdata->email = str_dup( "" );
if ( IS_IMMORTAL( ch ) );
{
save_char_obj( ch );
build_wizinfo( FALSE );
}
send_to_char( "Email address cleared.\n\r", ch );
return;
}
strcpy( buf, argument );

if ( strlen(buf) > 70 )
buf[70] = '\0';
hide_tilde( buf );
if ( ch->pcdata->email )
DISPOSE(ch->pcdata->email);
ch->pcdata->email = str_dup(buf);
if ( IS_IMMORTAL( ch ) );
{
save_char_obj( ch );
build_wizinfo( FALSE );
}
ch_printf( ch, "Email address set to: %s.\n\r", ch->pcdata->email );
}

void do_icq_number( CHAR_DATA *ch, char *argument )
{
int icq;
if ( IS_NPC( ch ) )
return;
if ( argument[0] == '\0' )
{
if ( !ch->pcdata->icq || ch->pcdata->icq == '0' )
ch_printf( ch, "You have not set your ICQ#.\n\r" );
else
ch_printf( ch, "Your ICQ# is: %d\n\r", ch->pcdata->icq );
return;
}
if ( !str_cmp( argument, "clear" ) )
{
ch->pcdata->icq = 0;
if ( IS_IMMORTAL( ch ) );
{
save_char_obj( ch );
build_wizinfo( FALSE );
}
send_to_char( "ICQ# cleared.\n\r", ch );
return;
}
if ( !is_number( argument ) )
{
send_to_char( "You must enter numeric data.\n\r", ch );
return;
}
icq = atoi( argument );
if ( icq pcdata->icq = icq;
if ( IS_IMMORTAL( ch ) );
{
save_char_obj( ch );
build_wizinfo( FALSE );
}
ch_printf( ch, "ICQ# set to: %d.\n\r", ch->pcdata->icq );
return;
}
void do_homepage( CHAR_DATA *ch, char *argument )
{
char buf[MSL];
if ( IS_NPC(ch) )
return;
if ( !argument || argument[0] == '&#65533;' )
{
if ( !ch->pcdata->homepage || !strcmp( ch->pcdata->homepage, "" ) )
{
ch_printf( ch, "You have not set your homepage.\n\r" );
ch->pcdata->homepage = str_dup( "" );
}
else
ch_printf( ch, "Your homepage is: %s\n\r", show_tilde( ch->pcdata->homepage ) );
return;
}
if ( !str_cmp( argument, "clear" ) )
{
if ( ch->pcdata->homepage )
DISPOSE(ch->pcdata->homepage);
ch->pcdata->homepage = str_dup( "" );
send_to_char( "Homepage cleared.\n\r", ch );
return;
}
if ( strstr( argument, "://" ) )
strcpy( buf, argument );
else
sprintf( buf, "http://%s", argument );
if ( strlen(buf) > 70 )
buf[70] = '&#65533;';
hide_tilde( buf );
if ( ch->pcdata->homepage )
DISPOSE(ch->pcdata->homepage);
ch->pcdata->homepage = str_dup( buf );
ch_printf( ch, "Homepage set to: %s.\n\r", ch->pcdata->homepage );
}
void do_privacy( CHAR_DATA *ch, char *argument )
{
if ( IS_NPC( ch ) )
{
send_to_char( "Mobs can't use the privacy toggle.\n\r", ch );
return;
}
TOGGLE_BIT( ch->pcdata->flags, PCFLAG_PRIVACY );
if ( IS_SET( ch->pcdata->flags, PCFLAG_PRIVACY ) )
{
send_to_char( "Privacy flag enabled.\n\r", ch );
return;
}
else
{
send_to_char( "Privacy flag disabled.\n\r", ch );
return;
}
}
       
Post is unread #4 Aug 27, 2003, 8:04 am
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

Went and took a look at this, after tweaking for the things our code needed, I fired it up and was inundated with tons of log spam about unmatched keywords. But since I REALLY wanted that goto hack gone, I just went balls out and did a full pload on any offline people. Bit extreme, but hey. It works now, no goto hack, and the world can rejoice

I'll be updating some of my snippets in the coming days, and this will be on the list.
       
Pages:<< prev 1 next >>