/* 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
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*
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() {
; 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
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
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. */
; 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
fi
done
-
trap '' 1 2 15
cat > confcache <<\EOF
# This file is a shell script that caches the results of configure
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.
dnl Checks for library functions.
AC_CHECK_FUNCS(socket strcspn strspn strtol strtok)
-
AC_OUTPUT(Makefile)
#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;
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);
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();
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;
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) {
{
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
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;
+}
#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;
init_monsters();
init_masters();
load_gs_dbase();
+ load_timestamp();
+
while (connected) {
if (sock_gets(sock,buffer,sizeof(buffer)) == -1) {
connected = 0;
}
}
save_gs_dbase();
+ save_timestamp();
delete_monsters();
delete_masters();
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);
+}