]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/tcpclient.cpp
Fixed a few things with the version and ping.
[irc/gameservirc.git] / gameserv / tcpclient.cpp
index 17375aee8d38e4a76ed3ccdd254cfbafcfa31adf..12cc359967f282fe8aa481660c41633d2a81af8c 100644 (file)
 #include <unistd.h>
 #include <string.h>
 #include <iostream.h>
+#include <fstream.h>
 #include <iomanip.h>
-#include <time.h>
 #include <stdlib.h>
 
 int sock;
+long timestamp;
+
 List<aClient> clients;
 
+void save_timestamp();
+void load_timestamp();
+
 int main(int argc, char *argv[])
 {
   char buffer[1024], buf[1024];
   int connected = 1;
   char *cmd, *source = NULL;
   srand(time(NULL));
-
-    load_config_file();
+  
+  load_config_file();
 
   if (argc == 1) {
     argc = 3;
@@ -74,6 +79,8 @@ int main(int argc, char *argv[])
   init_monsters();
   init_masters();
   load_gs_dbase();
+  load_timestamp();
+
   while (connected) {
       if (sock_gets(sock,buffer,sizeof(buffer)) == -1) {
         connected = 0;
@@ -118,7 +125,7 @@ int main(int argc, char *argv[])
            if ((quitter = find(source + 1)))
                clients.remove(quitter);
            if ((quitter = findplayer(source + 1)))
-               players.remove(quitter);
+               quitter->setNick("NULL");
 
        } else if (stricmp(cmd, "PRIVMSG") == 0) {
            char *rest, *dest;
@@ -139,6 +146,7 @@ int main(int argc, char *argv[])
        }
   }
   save_gs_dbase();
+  save_timestamp();
   delete_monsters();
   delete_masters();
 
@@ -210,3 +218,46 @@ aClient *findbynick(const char *nick)
     return client;    
 }
 
+void load_timestamp()
+{
+    ifstream infile;
+
+    infile.open(".gstimestamp");
+
+    if (infile.fail())
+    {
+       cerr << "Error opening .gstimestamp" << endl;
+       cerr << "Generating new timestamp" << endl;
+       generate:
+       timestamp = midnight();
+        save_timestamp();
+       return;
+    }
+
+    infile >> timestamp;
+    infile.close();
+    if (timestamp < 1000000)
+       goto generate;
+}
+
+void save_timestamp()
+{
+    ofstream outfile;
+
+    outfile.open(".gstimestamp");
+
+    if (outfile.fail())
+    {
+       cerr << "Error creating new file." << endl;
+       return;
+    }
+
+    outfile << timestamp << endl;
+
+    outfile.close();
+}
+
+long int midnight(long int offset)
+{
+    return (time(NULL) - (time(NULL) % 86400)) + (offset * 3600);
+}