[ScryMUD] SVN Commit Info r917 - trunk/mud/grrmud/server

scrymud at wanfear.com scrymud at wanfear.com
Tue Mar 6 16:23:31 PST 2007


Author: eroper
Date: 2007-03-06 16:23:30 -0800 (Tue, 06 Mar 2007)
New Revision: 917

Added:
   trunk/mud/grrmud/server/pfile_maint.cc
   trunk/mud/grrmud/server/pfile_maint.h
Modified:
   trunk/mud/grrmud/server/Makefile
   trunk/mud/grrmud/server/ServerConfig.cc
   trunk/mud/grrmud/server/ServerConfig.h
   trunk/mud/grrmud/server/classes.cc
   trunk/mud/grrmud/server/grrmud.cc
Log:
Added a "--resave-pfiles" command line option to gmud. This will cause the
server to load all Pfiles, update them to the current Pfile version and write
them back to disk. It will also perform any sanitization as defined in
pfile_maint.cc (such as resetting bhd). After completing this operation, the
server exits. This will allow us to remove the functionality currently
embedded in login.cc. This should be run whenever a version upgrade occurs,
and should be safe to run even when no upgrade has occured.


Modified: trunk/mud/grrmud/server/Makefile
===================================================================
--- trunk/mud/grrmud/server/Makefile	2007-03-06 04:52:00 UTC (rev 916)
+++ trunk/mud/grrmud/server/Makefile	2007-03-07 00:23:30 UTC (rev 917)
@@ -21,7 +21,9 @@
 ez_skll.o social2.o cr_skll.o ar_skll.o pet_spll.o vehicle.o const.o \
 script.o SkillSpell.o zone.o rm_parse.o rm_cmds.o obj_parse.o \
 obj_cmds.o BuildInfo.o BugEntry.o MudStats.o clients.o ServerConfig.o \
-mapper.o regex.o protocol_handler.o telnet_handler.o hegemon_handler.o
+mapper.o regex.o protocol_handler.o telnet_handler.o hegemon_handler.o \
+pfile_maint.o
+
 grrmud_TARG = grrmud
 
 GEN_SPEC = gen_cmds.spec

Modified: trunk/mud/grrmud/server/ServerConfig.cc
===================================================================
--- trunk/mud/grrmud/server/ServerConfig.cc	2007-03-06 04:52:00 UTC (rev 916)
+++ trunk/mud/grrmud/server/ServerConfig.cc	2007-03-07 00:23:30 UTC (rev 917)
@@ -79,6 +79,8 @@
    mySQLdatabase="gmud";
    mySQLhost="localhost";
    mySQLport=0;
+
+   resave_pfiles = false;
 }//ServerConfig
 
 void ServerConfig::read(char* filename) {

Modified: trunk/mud/grrmud/server/ServerConfig.h
===================================================================
--- trunk/mud/grrmud/server/ServerConfig.h	2007-03-06 04:52:00 UTC (rev 916)
+++ trunk/mud/grrmud/server/ServerConfig.h	2007-03-07 00:23:30 UTC (rev 917)
@@ -107,5 +107,8 @@
       String mySQLdatabase;
       String mySQLhost;
       int mySQLport;
+
+      // Misc
+      bool resave_pfiles;
 };
 #endif

Modified: trunk/mud/grrmud/server/classes.cc
===================================================================
--- trunk/mud/grrmud/server/classes.cc	2007-03-06 04:52:00 UTC (rev 916)
+++ trunk/mud/grrmud/server/classes.cc	2007-03-07 00:23:30 UTC (rev 917)
@@ -60,6 +60,7 @@
          {"version", 0, 0, 0},
          {"summon", 0, 0, 0},
          {"teeport", 0, 0, 0},
+         {"resave-pfiles", 0,0,0},
          {0, 0, 0, 0}
       };
 
@@ -89,6 +90,10 @@
             cout << "Using " << config.port << " for the well known server port.\n";
             break;
 
+         case 'r'://resave pfiles
+            config.resave_pfiles = true;
+            break;
+
          case 'l': {
             lvl = atoi(optarg);
             cout << "Setting logging level to: " << lvl << endl;
@@ -124,7 +129,8 @@
                          "-p --port                    Specify server port\n"
                          "-v --version                 Print out build/version information.\n"
                          "-h --help                    Print this message.\n"
-                         "-u --usage                   Print this message.\n\n";
+                         "-u --usage                   Print this message.\n"
+                         "--resave-pfiles              Load & Resave all pfiles, then exit.\n\n";
             do_shutdown = TRUE;
             exit(0);
             break;

Modified: trunk/mud/grrmud/server/grrmud.cc
===================================================================
--- trunk/mud/grrmud/server/grrmud.cc	2007-03-06 04:52:00 UTC (rev 916)
+++ trunk/mud/grrmud/server/grrmud.cc	2007-03-07 00:23:30 UTC (rev 917)
@@ -80,6 +80,7 @@
 
 #include "telnet.h"
 #include "telnet_handler.h"
+#include "pfile_maint.h"
 
 #define MAX_HOSTNAME    256
 
@@ -728,10 +729,17 @@
    init_masks();   //set all the masks for miscelaneous bitfields
 
 
-   mudlog.log(DBG, "Entering game loop.\n");
+   config_spells(); // configure spells
 
+   //command-line argument: --resave-pfiles
+   if ( config.resave_pfiles ) {
+      if ( resave_all_pfiles() != 0 ) {
+          cerr << "Errors encountered while resaving pfiles." << endl;
+      }
+      do_shutdown = true;
+   }
 
-   config_spells(); // configure spells
+   mudlog.log(DBG, "Entering game loop.\n");
    game_loop(s);
 
    close_sockets(s);

Added: trunk/mud/grrmud/server/pfile_maint.cc
===================================================================
--- trunk/mud/grrmud/server/pfile_maint.cc	                        (rev 0)
+++ trunk/mud/grrmud/server/pfile_maint.cc	2007-03-07 00:23:30 UTC (rev 917)
@@ -0,0 +1,105 @@
+// $Id$
+
+//
+//ScryMUD Server Code
+//Copyright (C) 2007  Edward Roper
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//
+// To contact the Author, Edward Roper: edro <- at -> wanfear.net
+//
+
+#include <vector>
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+
+#include "critter.h"
+#include "command2.h"
+
+//loads all pfiles and saves them again. Useful for upgrading pfile versions
+//and making sure sanitization gets applied to everyone.
+int resave_all_pfiles() {
+
+   DIR* d_ptr = opendir("./Pfiles");
+   std::vector<struct dirent> file_v;
+
+   struct dirent *dent_ptr;
+
+   if ( ! d_ptr ) {
+      return -1;
+   }
+
+   errno = 0;
+   while ( ( dent_ptr = readdir(d_ptr) ) ) {
+      if ( dent_ptr->d_type != DT_REG ) continue;//only do regular files.
+      file_v.push_back(*dent_ptr);
+   }
+
+   if ( errno != 0 ) {
+      return -1;
+   }
+
+   std::vector<struct dirent>::iterator dent_iter;
+
+   for ( dent_iter = file_v.begin(); dent_iter < file_v.end(); dent_iter++ ) {
+      string filepath("./Pfiles/");
+      filepath.append(dent_iter->d_name);
+      ifstream pfile(filepath.c_str());
+      if ( !pfile )  {
+         return -1;
+      }
+      cout << "Checking " << filepath << "." << endl;
+      critter* c = new critter;
+      c->fileRead(pfile, TRUE);
+
+      //prior to version 1, stats were saved with eq modifiers in place.
+      if ( c->pc->file_format_version == 0 ) {
+         cout << "Upgrading " << (const char *)(*(c->getName())) << " from version 0." << endl;
+
+         // if it's the old version remove everything so we can force
+         // correct nasties that ran away with us.
+         int i;
+         for(i=0;i<MAX_EQ;i++) {
+            if (c->EQ[i]) {
+               remove_eq_effects(*(c->EQ[i]), *c, FALSE, FALSE, i);
+            }
+         }
+
+      }//if pfile version 0
+
+      //Other sanitizing steps.
+      c->BH_DICE_COUNT = 2;
+      c->BH_DICE_SIDES = 3;
+
+      // re-gain effects from worn gear
+      // save removes them again.
+      {
+         int i;
+         for(i=0;i<MAX_EQ;i++) {
+            if (c->EQ[i]) {
+               wear_eq_effects(*(c->EQ[i]), *c, i, FALSE);
+            }
+         }
+      }
+
+      save(*c);
+      delete c;
+   }
+
+   closedir(d_ptr);
+
+   return 0;
+}//resave_all_pfiles()


Property changes on: trunk/mud/grrmud/server/pfile_maint.cc
___________________________________________________________________
Name: svn:keywords
   + Id Author Date Revision

Added: trunk/mud/grrmud/server/pfile_maint.h
===================================================================
--- trunk/mud/grrmud/server/pfile_maint.h	                        (rev 0)
+++ trunk/mud/grrmud/server/pfile_maint.h	2007-03-07 00:23:30 UTC (rev 917)
@@ -0,0 +1,29 @@
+// $Id: telnet_handler.h 903 2007-03-02 08:04:18Z eroper $
+
+//
+//ScryMUD Server Code
+//Copyright (C) 2007  Edward Roper
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//
+// To contact the Author, Edward Roper: edro <- at -> wanfear.net
+//
+
+#ifndef GRRMUD_PFILE_MAINTENANCE
+#define GRRMUD_PFILE_MAINTENANCE
+
+int resave_all_pfiles();
+
+#endif




More information about the ScryMUD mailing list