Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Dawn of Time ➜ Administration ➜ Odd SMAUG conversion issues

Odd SMAUG conversion issues

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Meerclar   USA  (733 posts)  Bio
Date Tue 10 Dec 2002 08:04 PM (UTC)

Amended on Wed 11 Dec 2002 03:33 PM (UTC) by Kalahn

Message
K, Ive reached the end of my resourcefulness in solving this one so its time to ask for help. What follows is 2 scan functions for mudwide and pfile wide checks for items with 3 specific flags so that they will only exist in limited numbers. Granted, I expected some insanity as this is originally from SMAUG and any help offered is hugely appreciated.


void scan_equipment( void )
{
  DIR *dp;
   struct dirent *dir_entry;
   char dir_name[100];
   int alpha_loop;

   logf( "Updating rare/unique item counts....." );

   logf( "Checking player files...." );
   
   for ( alpha_loop = 0; alpha_loop <= 25; alpha_loop++ )
   {
      sprintf( dir_name, "%s%c", PLAYER_DIR, 'a' + alpha_loop );
      dp = opendir( dir_name );
      dir_entry = readdir( dp );
      while ( dir_entry )
      {
         if ( dir_entry->d_name[0] != '.' )
         {
			if (scan_players( dir_name, dir_entry->d_name ))
				logf( "Found rare/unique items...." );
         }
         dir_entry = readdir( dp );
      }
      closedir( dp );
   }

   logf( "Checking corpses...." );
   
   sprintf( dir_name, "%s", CORPSES_FILE );
   dp = opendir( dir_name );
   dir_entry = readdir( dp );
   while ( dir_entry )
   {
      if ( dir_entry->d_name[0] != '.' )
      {
         if(scan_corpses( dir_name, dir_entry->d_name ))
			 logf( "Found rare/unique items." );
      }
      dir_entry = readdir( dp );
   }
   closedir( dp );
   
   return;

}

bool scan_players( char *dirname, char *filename )
{

   FILE *player_file;
   char file_name[MSL];
   bool found = FALSE;

   sprintf( file_name, "%s/%s", dirname, filename );

   if ( ( player_file = fopen( file_name, "r" ) ) == NULL )
   {
      perror( file_name );
      return found;
   }

   for ( ; ; )
   {
	int vnum, counter = 1;
	char letter;
	char *word;
	OBJ_INDEX_DATA *pObjIndex;

	letter = fread_letter( player_file );
	if ( letter != '#' )
	   continue;

	word = fread_word( player_file );

	if ( !str_cmp( word, "End" ) )
	   break;

	if ( !str_cmp( word, "OBJECT" ) )
	{
	   word = fread_word( player_file );
 
	   if ( !str_cmp( word, "Count" ) )
	   {
		counter = fread_number( player_file );
		word = fread_word( player_file );
	   }

	   if ( !str_cmp( word, "Vnum" ) )
	   {
		vnum = fread_number( player_file );
		if ( ( get_obj_index( vnum ) ) == NULL )
		{
		   bug("Bad obj vnum in limits: %d",vnum );
		}
		else
		{
		   pObjIndex = get_obj_index( vnum );
		   if ( IS_OBJ2_STAT(pObjIndex,OBJEXTRA2_RARE) 
|| IS_OBJ2_STAT(pObjIndex,OBJEXTRA2_UNIQUE) 
|| IS_OBJ2_STAT(pObjIndex,OBJEXTRA2_LIMITED))
		   {
				pObjIndex->count += counter;
				found = TRUE;
		   }
		}
	   }
	}
   }

   fclose( player_file );
   player_file = NULL;
   return found;

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Kalahn   United Kingdom  (138 posts)  Bio
Date Reply #1 on Wed 11 Dec 2002 03:38 PM (UTC)
Message
Instead of trying to convert the smaug code (which is pretty different), you could always just write unique code based on the logic of what you are trying to achieve.

Basically you are scanning the realm for unique objects (including offline players)...

So loop thru all objects in the game like owhere does.
Then loop thru all pfiles in the game, ploading them, scanning their inventory, then punloading them.

ploading has the benefit over the sample smaug code that it will detect objects which have been flagged unique even though their olc template vnum isn't necessarily unique.

I expect pload will take slightly more CPU than the a raw file scan that smaug does, but I think both methods will be intensive. The important thing with pload is that you unload so you don't get a memory leak.

- Kal

Kalahn
Developer of the Dawn of Time codebase
http://www.dawnoftime.org/
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #2 on Wed 11 Dec 2002 07:13 PM (UTC)
Message
Owhere looks like a good basis for the object scan. As for needing to worry about individual objs being flagged without the template being flagged.... I wrote the obj flags specificly to prevent such a thing from happening. Our plan is for unique objs to be the very most powerful objs in the game and as such there's little fear of anyone flagging an existing obj as unique.

What we are having the most difficulty with in regards to players is handling manipulation of the pfile directories for the scan in the first place. Im not sure we want to have the files loaded since these functions are called at startup nad with each zonelife so there's a LOT of concern about increasing processor load too heavily. Won't exactly help us much to get this figured out if the solution makes the mud pause every time a zone resets.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #3 on Sat 19 Jul 2003 12:27 AM (UTC)

Amended on Sat 19 Jul 2003 12:55 AM (UTC) by Meerclar

Message
Ok, after some research I've found that the above snipet almost works without tweaking but since I was trying to compile in MSVC instead of on a *nix based machine it wont ever compile. Why is this you ask? Well, it seems that for some reason the genuises behind the MS C++ complier chose not to support the functions found in dirent.h, and - without that support - crossplatform directory manipulation is patently impossible. Anyway, I am now manipulating that particular code on a BSD machine and have the following compile errors:


rare.cpp: In function `void scan_equipment()':
rare.cpp:38: implicit declaration of function `int scan_players(...)'
rare.cpp:55: implicit declaration of function `int scan_corpses(...)'
rare.cpp: In function `bool scan_players(char *, char *)':
rare.cpp:112: implicit declaration of function `int log(...)'


Now, the way the code is written, I don't understand how it thinks there is an implicit declaration but I'm obviously missing something. Any pointers here would be appreciated.

Many thanks.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #4 on Sat 19 Jul 2003 03:04 AM (UTC)

Amended on Sat 19 Jul 2003 03:05 AM (UTC) by Nick Gammon

Message
I reproduced that dirent stuff in SMAUG, so you can do it in Windows. Here it is ...




// in mud.h or wherever

/* directory scanning stuff */

typedef struct dirent
{
    char *      d_name;
};

typedef struct
{
    HANDLE              hDirectory;
    WIN32_FIND_DATA     Win32FindData;
    struct dirent       dirinfo;
    char                sDirName[MAX_PATH];
} DIR;


DIR *opendir(char * sDirName);
struct dirent *readdir (DIR * dp);
void closedir(DIR * dp);


// in something.c /* directory parsing stuff */ DIR * opendir (char * sDirName) { DIR * dp = malloc (sizeof (DIR)); dp->hDirectory = 0; /* if zero, we must do a FindFirstFile */ strcpy (dp->sDirName, sDirName); /* remember for FindFirstFile */ return dp; } struct dirent * readdir (DIR * dp) { /* either read the first entry, or the next entry */ do { if (dp->hDirectory == 0) { dp->hDirectory = FindFirstFile (dp->sDirName, &dp->Win32FindData); if (dp->hDirectory == INVALID_HANDLE_VALUE) return NULL; } else if (!FindNextFile (dp->hDirectory, &dp->Win32FindData)) return NULL; /* skip directories */ } while (dp->Win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); /* make a copy of the name string */ dp->dirinfo.d_name = dp->Win32FindData.cFileName; /* return a pointer to the DIR structure */ return &dp->dirinfo; } void closedir(DIR * dp) { if (dp->hDirectory) FindClose (dp->hDirectory); free (dp); }


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #5 on Sat 19 Jul 2003 03:10 AM (UTC)
Message
Nice Nick. That will let me keep working locally once those implicit declarations are debugged :) Unfortunately Im still at a loss as to the cause of the implicit declaration errors :(

Thanks much for the dirent info, was having no luck finding it on the web.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


23,084 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.