]> jfr.im git - irc/gameservirc.git/commitdiff
Added functions to check and see if midnight has passed. If midnight has passed,...
authorkainazzzo <redacted>
Mon, 27 Oct 2003 22:13:21 +0000 (22:13 +0000)
committerkainazzzo <redacted>
Mon, 27 Oct 2003 22:13:21 +0000 (22:13 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@38 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/config.h.in
gameserv/configure
gameserv/configure.in
gameserv/extern.h
gameserv/gameserv.cpp
gameserv/tcpclient.cpp

index df91fef76e31bc7052d1fde843149d4b909fbff8..38e3c8474b5e171f53ebca8b08f8d9e2d1cac2ef 100644 (file)
@@ -9,6 +9,9 @@
 /* Define if you have the ANSI C header files.  */
 #undef STDC_HEADERS
 
+/* Define if you can safely include both <sys/time.h> and <time.h>.  */
+#undef TIME_WITH_SYS_TIME
+
 /* Define if you have the socket function.  */
 #undef HAVE_SOCKET
 
index eb9a56cbed0b810fc1c6c990f496618a7bda9d5d..7b0989f7d7975dea6074891756a69f116f66ac64 100755 (executable)
@@ -900,21 +900,56 @@ EOF
 
 fi
 
+echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6
+echo "configure:905: checking whether time.h and sys/time.h may both be included" >&5
+if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 910 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+int main() {
+struct tm *tp;
+; return 0; }
+EOF
+if { (eval echo configure:919: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  ac_cv_header_time=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  ac_cv_header_time=no
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$ac_cv_header_time" 1>&6
+if test $ac_cv_header_time = yes; then
+  cat >> confdefs.h <<\EOF
+#define TIME_WITH_SYS_TIME 1
+EOF
+
+fi
+
 for ac_hdr in limits.h unistd.h crypt.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:908: checking for $ac_hdr" >&5
+echo "configure:943: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 913 "configure"
+#line 948 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:918: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:953: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -942,12 +977,12 @@ done
 
 
 echo $ac_n "checking for working const""... $ac_c" 1>&6
-echo "configure:946: checking for working const" >&5
+echo "configure:981: checking for working const" >&5
 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 951 "configure"
+#line 986 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -996,7 +1031,7 @@ ccp = (char const *const *) p;
 
 ; return 0; }
 EOF
-if { (eval echo configure:1000: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1035: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_const=yes
 else
@@ -1017,12 +1052,12 @@ EOF
 fi
 
 echo $ac_n "checking for size_t""... $ac_c" 1>&6
-echo "configure:1021: checking for size_t" >&5
+echo "configure:1056: checking for size_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1026 "configure"
+#line 1061 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -1053,12 +1088,12 @@ fi
 for ac_func in socket strcspn strspn strtol strtok
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1057: checking for $ac_func" >&5
+echo "configure:1092: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1062 "configure"
+#line 1097 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -1081,7 +1116,7 @@ $ac_func();
 
 ; return 0; }
 EOF
-if { (eval echo configure:1085: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1120: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -1105,7 +1140,6 @@ else
 fi
 done
 
-
 trap '' 1 2 15
 cat > confcache <<\EOF
 # This file is a shell script that caches the results of configure
index 44233d5b7a0e09404fe58e37945e77f22240bbf8..48762b38d44b114d49d50a56a7143eb894df4930 100644 (file)
@@ -13,6 +13,7 @@ AC_CHECK_LIB(crypt, crypt)
 
 dnl Checks for header files.
 AC_HEADER_STDC
+AC_HEADER_TIME
 AC_CHECK_HEADERS(limits.h unistd.h crypt.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
@@ -21,5 +22,4 @@ AC_TYPE_SIZE_T
 
 dnl Checks for library functions.
 AC_CHECK_FUNCS(socket strcspn strspn strtol strtok)
-
 AC_OUTPUT(Makefile)
index 242a28317cc5eb4d0433c3f2e46bb2fb34a32598..7e80946c7572ca6427a9afbada19ddb2cda2935a 100644 (file)
@@ -9,6 +9,25 @@
 #include <stdarg.h>
 #include "player.h"
 #include "list.h"
+#include "config.h"
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+
+// The timestamp from load time to be compared against the current midnight time.
+E long timestamp;
+E void save_timestamp();
+E void load_timestamp();
+E long int midnight(long int offset = 8);
 
 // The socket
 E int sock;
@@ -80,7 +99,7 @@ E void delete_monsters();
 E void delete_masters();
 E Monster *getNewMonster(Monster *m);
 E void deleteMonster(Monster *m);
-E void refresh(aClient *ni);
+E void refresh(Player *p);
 E void refreshall();
 E void reset(aClient *ni);
 
index b60ed0d9e914541a9ea62233db5fe461ba83890a..225c1bff5f87cfc7103ac35dfb055697431fda71 100644 (file)
@@ -64,7 +64,7 @@ long int pow (int x, int y);
 long int stringtoint(char *number);
 
 char *spaces(int len, char *seperator);
-void refresh(aClient *ni);
+void refresh(Player *p);
 void refreshall();
 void reset(aClient *ni);
 void init_masters();
@@ -111,7 +111,6 @@ int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550};
 int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200};
 int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150};
 
-
 void gameserv(char *source, char *buf)
 {
     char *cmd;
@@ -121,11 +120,20 @@ void gameserv(char *source, char *buf)
     cmd++;    // Get rid of that : at the beginning of the :text  (command)
 
     cout << "Source: " << source << "\ncmd: " << cmd << endl;
+    long int mn = midnight();
+
+    if (mn > timestamp)
+    {
+        refreshall();
+        timestamp = mn;
+       save_timestamp();
+    }
+
     if (strnicmp(cmd, ":\1PING", 6) == 0)
     {
-       char *timestamp;
-       timestamp = strtok(NULL, "\1");
-        notice(s_GameServ, source, "\1PING %s\1", timestamp);
+       char *ts;
+       ts = strtok(NULL, "\1");
+        notice(s_GameServ, source, "\1PING %s\1", ts);
     } else if (stricmp(cmd, ":\1VERSION\1") == 0) {
        notice(s_GameServ, source, "\1VERSION GameServ v1.0b\1");
     } else if (stricmp(cmd, "SEARCH") == 0) {
@@ -205,6 +213,15 @@ void gameserv(char *source, char *buf)
         {
             notice(s_GameServ, source, "SYNTAX: /msg %S RAW <password> <raw>");
         }
+    } else if (stricmp(cmd, "TESTSTAMP") == 0) {
+       char *pass = strtok(NULL, " ");
+       if (pass != NULL && (stricmp(pass, adminpass) == 0))
+       {
+           mn = time(NULL);
+           notice(s_GameServ, source, "Resetting timestamp");
+       }
+       else
+           notice(s_GameServ, source, "SYNTAX: /msg %S TESTSTAMP <password>");
     }
 
    source--;  // Bring the : back so we don't leak memory
@@ -2990,3 +3007,29 @@ void showBankBalance(const char *u)
     notice(s_GameServ, u, "Account Balance: %ld     Gold On hand: %ld", p->bank, p->gold);
 
 }
+
+void refreshall()
+{
+    ListNode <aClient> *it;
+    Player *p;
+
+    it = players.First();
+
+    while (it)
+    {
+       p = it->getData()->stats;
+       refresh(p);
+       it = it->Next();
+    }
+}
+
+void refresh(Player *p)
+{
+    if (!p)
+       return;
+
+    p->hp = p->maxhp;
+    p->forest_fights = 100;
+    p->player_fights = 3;
+    p->alive = true;
+}
index 17375aee8d38e4a76ed3ccdd254cfbafcfa31adf..bcc98fad81fddfa582824b600bc6e8028341aaba 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;
@@ -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);
+}