]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/tcpclient.cpp
implemented thelizno's custom time idea
[irc/gameservirc.git] / gameserv / tcpclient.cpp
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();
+}