]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
Added functions to check and see if midnight has passed. If midnight has passed,...
[irc/gameservirc.git] / gameserv / gameserv.cpp
index 54d39bac6f520815d4ab495b728c4539e5a12f2f..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,21 +111,29 @@ 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, input[1024];
+    char *cmd;
     cmd = strtok(buf, " ");
 
     source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
     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) {
@@ -164,15 +172,56 @@ void gameserv(char *source, char *buf)
     } else if (stricmp(cmd, "STATS") == 0) {
        do_stats(source);
     } else if (stricmp(cmd, "SHUTDOWN") == 0) {
-       save_gs_dbase();
-       raw("SQUIT %s :leaving", servername);
+       char *pass = strtok(NULL, " ");
+       if (pass != NULL && (stricmp(pass, adminpass) == 0))
+       {
+           save_gs_dbase();
+           raw("SQUIT %s :leaving", servername);
+       }
+       else
+       {
+           notice(s_GameServ, source, "SYNTAX: /msg %S SHUTDOWN <password>");
+       }
     } else if (stricmp(cmd, "SAVE") == 0) {
-       save_gs_dbase();
+        char *pass = strtok(NULL, " ");
+        if (pass != NULL && (stricmp(pass, adminpass) == 0))
+        {
+           save_gs_dbase();
+        }
+        else
+        {
+            notice(s_GameServ, source, "SYNTAX: /msg %S SAVE <password>");
+        }
     } else if (stricmp(cmd, "LOAD") == 0) {
-       load_gs_dbase();
+        char *pass = strtok(NULL, " ");
+        if (pass != NULL && (stricmp(pass, adminpass) == 0))
+        {
+           load_gs_dbase();
+       }
+        else
+        {
+            notice(s_GameServ, source, "SYNTAX: /msg %S LOAD <password>");
+        }
     } else if (stricmp(cmd, "RAW") == 0) {
-       char *rest = strtok(NULL, "");
-       raw(rest);
+        char *pass = strtok(NULL, " ");
+        if (pass != NULL && (stricmp(pass, adminpass) == 0))
+        {
+           char *rest = strtok(NULL, "");
+           raw("%s", rest);
+       }
+        else
+        {
+            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
@@ -408,7 +457,7 @@ void do_register(char *u)
     {
        notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER PASSWORD");
     }
-    else if (user = find(u))
+    else if ((user = find(u)))
     {
         if (!user->stats)
         {
@@ -442,7 +491,7 @@ void do_identify(char *u)
     {
            notice(s_GameServ, u, "Password incorrect");
     }
-    else if (user = find(u))
+    else if ((user = find(u)))
     {
         if (!user->stats)
         {
@@ -1925,7 +1974,7 @@ void do_fight(char *u)
 void do_run(char *u)
 {
     aClient *user;
-    Player *p, *p2;
+    Player *p, *p2 = NULL;
 
     if (!(user = find(u)))
     {
@@ -2366,7 +2415,7 @@ void do_heal(char *u)
 
 int isstringnum(char *num)
 {
-    int x;
+    unsigned int x;
     for (x = 0; x < strlen(num); x++)
     {
         if ((int)num[x] < 48 || (int)num[x] > 57)
@@ -2440,6 +2489,7 @@ int save_gs_dbase()
        ptr = ptr->Next();
     }
 outfile.close();
+return 1;
 }
 
 int load_gs_dbase()
@@ -2502,6 +2552,8 @@ int load_gs_dbase()
        cout << "Deleted" << endl;
     }
 delete [] buf;
+infile.close();
+return 1;
 }
 
 bool passcmp(char *encrypted, char *plaintext)
@@ -2955,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;
+}