NICKNAME.C
LIB3/GLOBAL/NICKNAME.C · 2.3 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
/*
** Optimesed by Newstyle, 93/12/09
*/
mapping map_nicknames;
string *query_nicknames()
{
return map_nicknames + ({ });
}
void nickname_commands()
{
add_action( "delete_nickname", "dn*ickname" );
add_action( "nickname", "ni*ckname" );
if( !map_nicknames )
map_nicknames = ([ ]);
}
int add_nickname( string s1, string s2 )
{
if( !map_nicknames[ s1 ] )
write( s1 + " is now nicknamed as " + s2 + ".\n" );
else
write( "Nickname " + s1 + " changed from " + map_nicknames[ s1 ] + " to " + s2 + ".\n" );
map_nicknames[ s1 ] = s2;
return 1;
}
string expand_nickname( string str )
{
string *array;
int i;
if( !str )
return "";
array = explode( lower_case( str ), " " );
for( i = 0; i < sizeof( array ); i++ )
if( map_nicknames[ array[ i ] ] )
array[ i ] = map_nicknames[ array[ i ] ];
return implode( array, " " );
}
int delete_nickname( string str )
{
if( !map_nicknames[ str ] )
{
notify_fail( "That nickname does not exist.\n" );
return 0;
}
map_nicknames = m_delete( map_nicknames, str );
write( "Deleted nickname : " + str + "\n" );
return 1;
}
int print_nicknames()
{
int i, cols;
string str, str1, str2, *tmp;
str1 = str2 = "";
if( !sizeof( map_nicknames ) )
{
write( "You have no nicknames defined.\n" );
return 1;
}
tmp = m_indices( map_nicknames );
cols = (int)this_player()->query_cols();
for( i = 0; i < sizeof( tmp ); i++ )
{
/* Not sure what the point of all this is .... NS, 8/12/93 */
str = tmp[ i ] + ": " + map_nicknames[ tmp[ i ] ] + " ";
if( strlen( str ) > 39 )
printf( tmp[ i ] + ": %-=*s\n", cols - strlen( tmp[ i ] ), map_nicknames[ tmp[ i ] ] );
else
if( strlen( str ) > 19 )
str1 += str + "\n";
else
str2 += str + "\n";
}
if( strlen( str1 ) )
printf( "%-#*s\n", cols, str1 );
if( strlen( str2 ) )
printf( "%-#*s\n", cols, str2 );
return 1;
}
int nickname( string str )
{
string s1, s2;
if( !str )
return print_nicknames();
if( sscanf( str, "%s %s", s1, s2 ) != 2 )
{
if( !map_nicknames[ s1 ] )
{
notify_fail( "That nickname does not exist.\n" );
return 0;
}
write( str + " is nicknamed as " + map_nicknames[ str ] + ".\n" );
return 1;
}
return add_nickname( s1, s2 );
}