/* ....[@@@..[@@@..............[@.................. MUD++ is a written from ....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and ....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++. ....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing ....[@......[@..[@@@@@..[@@@@@.................. development project. All ................................................ contributions are welcome. ....Copyright(C).1995.Melvin.Smith.............. Enjoy. ------------------------------------------------------------------------------ Melvin Smith (aka Fusion) msmith@hom.net MUD++ development mailing list mudpp@van.ml.org ------------------------------------------------------------------------------ utils.cc */ #include "config.h" #include "string.h" #include "llist.h" #include "hash.h" #include "nameable.h" #include "room.h" #include "object.h" #include "npc.h" #include "pc.h" #include "global.h" void wizLog( const String & str, const PC * pc ) { PC *ch; LList<PC> tlist = pcs; Cout << str << endl; for_each( tlist, ch ) { if( !ch->isPlaying() || !ch->authorized( WIZARD ) || !ch->config( PC_WIZNET ) ) continue; if( pc && ( ch->getLevel() <= pc->getLevel() || ch == pc ) ) continue; ch->out( "\n\r[Wiznet]: " ); ch->out( str ); ch->out( "\n\n\r" ); } } void outAllChar( const String & str ) { PC *ch; LList<PC> tlist = pcs; for_each( tlist, ch ) { if( !ch->isPlaying() ) continue; ch->out( str ); } } void outAllCharExcept( const String & str, Char * ch1, Char * ch2 ) { PC *ch; LList<PC> tlist = pcs; for_each( tlist, ch ) { if( !ch->isPlaying() ) continue; else if( ch == ch1 || ch == ch2 ) continue; ch->out( str ); } } // getPCOther returns a PC in the game in any state other than the PC // pointed to by 'skip'. This is called by Nanny for reconnect in case a // char is connected but not playing (logging in or in editor) PC * getPCOther( const String & name, PC * skip ) { PC * other; LList<PC> tlist = pcs; for_each( tlist, other ) { if( other->isName( name ) ) { if( other == skip ) continue; return other; } } tlist = shellpcs; for_each( tlist, other ) { if( other->isName( name ) ) { if( other == skip ) continue; return other; } } return 0; } // getPCWorld returns a PC who is playing, if he is online but // is not playing (editor, etc.) then he is not returned PC * getPCWorld( const String & name ) { PC *ch; LList<PC> tlist = pcs; for_each( tlist, ch ) { if( !ch->isPlaying() ) continue; if( ch->isName( name ) ) break; } return ch; } NPC * getNPCWorld( const String & name ) { NPC * npc; LList<NPC> tlist = npcs; for_each( tlist, npc ) if( npc->isName( name ) ) break; return npc; } Object *getObjWorld( const String & name ) { Object * obj; LList<Object> tlist = objects; for_each( tlist, obj ) if( obj->isName( name ) ) break; return obj; } // Direction functions const char *lookupDirName( int dir ) { static const char *dir_name[] = { "north", "east", "south", "west", "up", "down" }; if( dir < 0 || dir >= MAX_DIR ) return "undefined"; return dir_name[ dir ]; } int getDir( char ch ) { switch( tolower(ch) ) { default : return DIR_UNDEFINED; case 'n': return DIR_NORTH; case 'e': return DIR_EAST; case 's': return DIR_SOUTH; case 'w': return DIR_WEST; case 'u': return DIR_UP; case 'd': return DIR_DOWN; } } int getRevDir( int dir ) { switch( dir ) { default : return DIR_UNDEFINED; case DIR_NORTH: return DIR_SOUTH; case DIR_EAST: return DIR_WEST; case DIR_SOUTH: return DIR_NORTH; case DIR_WEST: return DIR_EAST; case DIR_UP: return DIR_DOWN; case DIR_DOWN: return DIR_UP; } } int getDir( const char * x ) { switch( tolower(*x) ) { default : return DIR_UNDEFINED; case 'n': if( !str_abbrev( "north", x ) ) return DIR_NORTH; return DIR_UNDEFINED; case 'e': if( !str_abbrev( "east", x ) ) return DIR_EAST; return DIR_UNDEFINED; case 's': if( !str_abbrev( "south", x ) ) return DIR_SOUTH; return DIR_UNDEFINED; case 'w': if( !str_abbrev( "west", x ) ) return DIR_WEST; return DIR_UNDEFINED; case 'u': if( !str_abbrev( "up", x ) ) return DIR_UP; return DIR_UNDEFINED; case 'd': if( !str_abbrev( "down", x ) ) return DIR_DOWN; return DIR_UNDEFINED; } }