]> jfr.im git - irc/gameservirc.git/commitdiff
implemented thelizno's custom time idea
authorkainazzzo <redacted>
Sun, 2 Oct 2005 19:45:32 +0000 (19:45 +0000)
committerkainazzzo <redacted>
Sun, 2 Oct 2005 19:45:32 +0000 (19:45 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@380 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/Changes
gameserv/config.cpp
gameserv/extern.h
gameserv/flags.h
gameserv/gameserv.cpp
gameserv/gameserv.example.conf
gameserv/tcpclient.cpp

index 906a417381f9b7b224a1cb1897ee5006d817bffa..7e4439fd543db75f100d915a3c706236d65bc868 100644 (file)
@@ -1,4 +1,10 @@
 Version 1.3.1
+* Added a config file directive ROLLOVERFORESTFIGHTS which will allow you to keep the forest
+    fights from the previous day - kain (Thanks thelizno)
+* Added a config file directive ROLLOVERPERIOD which will allow you to specify a period of time
+    to rollover the forest fights - kain (Thanks thelizno)
+* Added a config file directive MAXFORESTFIGHTS which allows you to specify a maximum amount of
+    forest fights a player can roll over - kain (Thanks thelizno)
 * Fixed a bug causing a crash on /msg GameServ use - kain (Thanks thelizno)
 * Fixed a bug in the masteritems.dat file causing the chain saw to take 1 strength point
     away instead of add 185 - kain (Thanks Tsukasa)
index 4df34843d9d4a61184f1c70f42ba34abcc3692fc..ed1808af7894b86d92cea75ced330874c1037a53 100644 (file)
@@ -37,7 +37,9 @@ int level1expire;             // Days for level 1 players to expire
 int defaultexpire;             // Days for other levels to expire
 int maxitems;                   // Maximum amount of items a player can carry
 long refreshperiod;            // Period for refreshing players
-long configflags;              // Holds the bit representation of some boolean values
+long rolloverperiod;            // Period for rolling over forest fights
+long configflags;              // Holds the binary representation of some boolean values
+long maxforestfights;           // Maximum amount of forest fights to roll over
 
 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
 // to a real ircd.
@@ -113,7 +115,7 @@ int load_config_file(char *config)
 {
     char *buf, *directive, *value;
 
-    #define numdirectives 35
+    #define numdirectives 38
 
     unload_config_file();
 
@@ -174,6 +176,10 @@ int load_config_file(char *config)
     directives[32].desc = "MAXITEMS - Maximum number of items a player can carry";
     directives[33].desc = "STOREITEMDATA - File in which to store the items that are available in the store";
     directives[34].desc = "LOCALHOST - Local hostname or IP to bind to when connecting to the remote server";
+    directives[35].desc = "ROLLOVERFORESTFIGHTS - True/False as to wether or not to roll over forest fights "\
+      "into the next day";
+    directives[36].desc = "MAXFORESTFIGHTS - Maximum amount of forest fights to roll over";
+    directives[37].desc = "ROLLOVERPERIOD - Period (in seconds) to rollover forest fights";
 
     configflags = 0;
 
@@ -450,6 +456,27 @@ int load_config_file(char *config)
            strcpy(localhost, value);
            directives[34].done = true;
          }
+       else if (stricmp(directive, "ROLLOVERFORESTFIGHTS") == 0)
+         {
+           value = strtok(NULL, " ");
+           if (stricmp(value, "TRUE") == 0)
+             {
+               setRolloverForestFights();
+             }
+           directives[35].done = true;
+         }
+       else if (stricmp(directive, "MAXFORESTFIGHTS") == 0)
+         {
+           value = strtok(NULL, "");
+           maxforestfights = stringtoint(value);
+           directives[36].done = true;
+         }
+       else if (stricmp(directive, "ROLLOVERPERIOD") == 0)
+         {
+           value = strtok(NULL, "");
+           rolloverperiod = stringtoint(value);
+           directives[37].done = true;
+         }
        else if (stricmp(directive, "WELCOMEMSG") == 0)
        {
            // This directive is optional
index 7d07bc9c6e3ac93d90cf6dee1e917b8c59230433..30b90e535fcc46c76f0b9332f294412d530ba668 100644 (file)
@@ -35,8 +35,11 @@ E unsigned long iHASH(const unsigned char *name);
 // hash.cpp stuff end
 
 E long lastrefresh;
+E long lastrollover;
 E void save_lastrefresh();
 E void load_lastrefresh();
+E void save_lastrollover();
+E void load_lastrollover();
 
 // The socket
 E int sock;
@@ -80,6 +83,7 @@ E char *ignoreserverslist;
 
 E long configflags;
 E long refreshperiod;
+E long rolloverperiod;
 E int level1expire;
 E int defaultexpire;
 E bool shuttingdown;
@@ -91,6 +95,7 @@ E int maxbfightdistance;
 E int maxidletime;
 E int idlecheckperiod;
 E int maxitems;
+E long maxforestfights;
 
 /* config.cpp end */
 
@@ -179,6 +184,8 @@ E Monster *getNewMonster(Monster *m);
 E void deleteMonster(Monster *m);
 E void refresh(Player *p);
 E void refreshall();
+E void rolloverall();
+E void rollover(Player *p);
 E void updateTS(Player *p);
 E bool timedOut(Player *p);
 E void timeOutEvent(Player *p);
index 42d4217f04c5d6302d94e10416055363beec4b53..83f41409f4d4ace3f9784ab787c496e18ed9670f 100644 (file)
 #define CFLAG_WELCOME                  0x00000008
 #define CFLAG_SAVEDNOTICE              0x00000010
 #define CFLAG_USENICKSERV              0x00000020
+#define CFLAG_ROLLOVERFORESTFIGHTS      0x00000040
+
+#define setRolloverForestFights()       (configflags |= CFLAG_ROLLOVERFORESTFIGHTS)
+#define clearRolloverForestFights()     (configflags &= ~CFLAG_ROLLOVERFORESTFIGHTS)
+#define isRolloverForestFights()        (configflags & CFLAG_ROLLOVERFORESTFIGHTS)
 
 #define setUseNickServ()               (configflags |= CFLAG_USENICKSERV)
 #define clearUseNickServ()             (configflags &= ~CFLAG_USENICKSERV)
index e7a1b2407748633de4d17819d0c06188cb286223..220261d88f7361621b7922a82da3d97b097afff0 100644 (file)
@@ -100,6 +100,9 @@ long int stringtoint(char *number);
 char *spaces(int len, char *seperator);
 void refresh(Player *p);
 void refreshall();
+void rollover(Player *p);
+void rolloverall();
+
 void updateTS(Player *p);
 void reset(Player *p);
 bool load_masters();
@@ -593,6 +596,19 @@ void do_check(char *u)
 
     notice(s_GameServ, u, "Time left to next refresh: %dd %dh %dm %ds", 
           days, hours, minutes, seconds);
+
+    if (isRolloverForestFights())
+      {
+       complete = (lastrollover + rolloverperiod) - time(NULL);
+       
+       days = complete / 86400;
+       hours = (complete % 86400) / 3600;
+       minutes = (complete % 86400) % 3600 / 60;
+       seconds = (complete % 86400) % 3600 % 60;
+       
+       notice(s_GameServ, u, "Time left to next rollover: %dd %dh %dm %ds",
+              days, hours, minutes, seconds);
+      }
 }
 
 void do_list(char *u)
@@ -3208,21 +3224,47 @@ void showBankBalance(const char *u)
 
 }
 
+void rolloverall()
+{
+  ListNode <aClient> *it;
+  Player *p;
+  for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
+    {
+      it = players[x].First();
+      while (it)
+       {
+         p = it->getData()->stats;
+         rollover(p);
+         it = it->Next();
+       }
+    }
+}
 void refreshall()
 {
-    ListNode <aClient> *it;
-    Player *p;
-   for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
-   {
-    it = players[x].First();
-
-    while (it)
+  ListNode <aClient> *it;
+  Player *p;
+  for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
     {
-       p = it->getData()->stats;
-       refresh(p);
-       it = it->Next();
+      it = players[x].First();
+      
+      while (it)
+       {
+         p = it->getData()->stats;
+         refresh(p);
+         it = it->Next();
+       }
     }
-   }
+}
+
+void rollover(Player *p)
+{
+  if (!p)
+    return;
+
+  p->forest_fights += forestfights;
+
+  if (p->forest_fights > maxforestfights)
+    p->forest_fights = maxforestfights;
 }
 
 void refresh(Player *p)
@@ -3232,7 +3274,11 @@ void refresh(Player *p)
 
     if (p->hp < p->maxhp)
        p->hp = p->maxhp;
-    p->forest_fights = forestfights;
+    if (p->forest_fights < forestfights)
+      {
+       p->forest_fights = forestfights;
+      }
+
     p->player_fights = 3;
     setAlive(p);
     clearMaster(p);
index 24b7f0627a21fc638ae536d87c6d3a4ac14e556f..09e805a2043255bd8b6b79b7b75c877aa807c70f 100644 (file)
@@ -130,6 +130,12 @@ updateperiod 180
 # 3600 Seconds in an hour
 refreshperiod 86400
 
+# How often (in seconds) ro rollover forest fights
+# 86400 Seconds in a day
+# 43200 Seconds in 12 hours
+# 3600 Seconds in an hour
+rolloverperiod 43200
+
 # How many days until unused accounts at level 1 are deleted
 level1expire 14
 
@@ -142,6 +148,13 @@ maxitems 100
 # How many forest fights per day should everyone get
 forestfights 100
 
+# True or False - Should GameServ roll over forest fights into the next day
+rolloverforestfights true
+
+# Maximum number of forest fights to roll over total. Forest fights per player will never
+# Roll over to be above this number
+maxforestfights 300
+
 # This is the filename for the gameserv process ID
 # This should be different between .conf files so you have different pid
 # files saved for each process (if you want)
index 1ba1ea34fa5621b45ac6353880b8edcaf26cc167..86a0b8446d05bdd8223acbafbfb1bab958556547 100644 (file)
@@ -37,11 +37,14 @@ char *VERSION = "1.3.0 +devel";
 
 int sock;
 long lastrefresh;
+long lastrollover;
 
 List<aClient> clients[U_TABLE_SIZE];
 
 void save_lastrefresh();
 void load_lastrefresh();
+void load_lastrollover();
+void save_lastrollover();
 void prettyIntro();
 void check_idles();
 
@@ -162,7 +165,7 @@ int main(int argc, char *argv[])
  {
     connected = 1;
     load_lastrefresh();
-
+    load_lastrollover();
 
     long int loadtime = time(NULL);
     long int currentTime;
@@ -295,6 +298,18 @@ int main(int argc, char *argv[])
 
        // Refresh players and clear news if the time is up
        currentTime = time(NULL);
+
+       if (isRolloverForestFights())
+         {
+           if (currentTime - lastrollover >= rolloverperiod)
+             {
+               rolloverall();
+               lastrollover = currentTime;
+               save_lastrollover();
+               notice(s_GameServ, c_Forest, "Adding %d forest fights to all players!", forestfights);
+             }
+         }
+
        if (currentTime - lastrefresh >= refreshperiod)
        {
            refreshall();
@@ -307,7 +322,6 @@ int main(int argc, char *argv[])
        }
 
        // Save the player data every updateperiod seconds
-       currentTime = time(NULL);
        if (currentTime - oldTime >= updateperiod)
        {
            oldTime = currentTime;
@@ -888,21 +902,51 @@ void load_lastrefresh()
        #endif
 
        // Just a safety measure... tho no one should
-       // get anywhere near the time as their refreshperiod
+       // get anywhere near the actual time as their refreshperiod
        if (refreshperiod >= mytime)
+         {
+           log("Refresh period is greater than or equal to the actual time... setting it to 86400");
            refreshperiod = 86400;
-
+         }
+       
        lastrefresh = mytime - (mytime % refreshperiod);
+
        refreshall();
        save_lastrefresh();
        return;
     }
     infile >> lastrefresh;
+
     infile.close();
     if (lastrefresh < 0)
        goto generate;
 }
 
+void load_lastrollover()
+{
+  ifstream infile;
+  infile.open(".gsrollover");
+  if (infile.fail())
+    {
+#ifdef DEBUGMODE
+      log("Error opening .gsrollover");
+#endif
+      
+    generate:
+      long mytime = time(NULL);
+#ifdef DEBUGMODE
+      log("Generating new rollover time");
+#endif
+      lastrollover = mytime;
+      return;
+    }
+  infile >> lastrollover;
+  
+  infile.close();
+  if (lastrollover < 0)
+    goto generate;
+}
+
 void save_lastrefresh()
 {
     ofstream outfile;
@@ -914,7 +958,22 @@ void save_lastrefresh()
        log("Error creating new file .gsrefresh");
        return;
     }
-    outfile << lastrefresh << endl;
+    outfile << lastrefresh << endl << lastrollover;
 
     outfile.close();
 }
+
+void save_lastrollover()
+{
+    ofstream outfile;
+
+    outfile.open(".gsrollover");
+
+    if (outfile.fail())
+    {
+       log("Error creating new file .gsrollover");
+       return;
+    }
+    outfile << lastrollover << endl;
+    outfile.close();
+}