]> jfr.im git - irc/gameservirc.git/commitdiff
Added boolean.cpp which includes the boolean / is_ functions from gameserv.cpp
authorkainazzzo <redacted>
Sun, 21 Jan 2007 18:12:33 +0000 (18:12 +0000)
committerkainazzzo <redacted>
Sun, 21 Jan 2007 18:12:33 +0000 (18:12 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@470 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/Makefile.in
gameserv/boolean.cpp [new file with mode: 0755]
gameserv/extern.h
gameserv/gameserv.cpp

index 424426bc7f7c7126e6436b253c09d410a7367e09..6405d22bad1384debd6b832be44be51f82d4464d 100644 (file)
@@ -22,6 +22,7 @@ DRIVER = tcpclient.cpp
 CONSOLEDRIVER = devel.cpp
 
 TSRCS =        aClient.cpp \
+       boolean.cpp \
        config.cpp \
        c_forest.cpp \
        do_attack.cpp \
diff --git a/gameserv/boolean.cpp b/gameserv/boolean.cpp
new file mode 100755 (executable)
index 0000000..a6011dd
--- /dev/null
@@ -0,0 +1,188 @@
+#include "extern.h"
+#include "aClient.h"
+#include "player.h"
+#include "flags.h"
+
+bool is_playing(char *u); // True if the given nickname in the clients list is playing.
+bool is_playing(aClient *user);
+
+bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
+bool is_fighting(aClient *user);
+
+bool player_fight(char *u); // True if the player is fighting another player.
+bool player_fight(aClient *user);
+
+bool master_fight(char *u); // True if the player is fighting their master.
+bool master_fight(aClient *user);
+
+bool dragon_fight(char *u); // True if the player is fighting the dragon.
+bool dragon_fight(aClient *user);
+
+bool alphaNumeric(const char *str); // Returns true if all of the characters in str are alphanumeric non-special chars
+/********** GameServ Booleans **********/
+
+
+bool is_playing(char *u)
+{
+  aClient *user;
+  if (!(user = find(u)))
+       return false;
+  else
+       return is_playing(user);
+}
+
+bool is_playing(aClient *user)
+{
+  if (!user)
+    {
+         return false;
+    }
+  else if (!user->stats)
+       {
+         return false;
+       }
+  else if (!FL_is_playing(user))
+    {
+         return false;
+    }
+  else if (user->stats->getClient() != user)
+    {
+         return false;
+    }
+  else
+       return true;
+}
+
+bool is_fighting(char *u)
+{
+  aClient *user;
+  
+  if (!(user = find(u)))
+       return false;
+  else
+       return is_fighting(user);
+}
+
+bool is_fighting(aClient *user)
+{
+  if (!is_playing(user))
+       return false;
+  else
+       return player_fight(user) || master_fight(user) || user->stats->getMonster() != NULL;
+}
+
+bool player_fight(char *u)
+{
+  aClient *user;
+  
+  if (!(user = find(u)))
+       return false;
+  else 
+       return player_fight(user);
+}
+
+bool player_fight(aClient *user)
+{
+  if (!is_playing(user))
+       return false;
+  else if (is_playing(user->stats->getBattle()))
+    {
+         return true;
+    }
+  return false;
+}
+
+bool master_fight(char *u)
+{
+  aClient *user;
+  
+  if (!(user = find(u)))
+       return false;
+  else
+       return master_fight(user);
+}
+
+bool master_fight(aClient *user)
+{
+  if (!is_playing(user))
+       return false;
+  else
+       return user->stats->getMaster() != NULL;
+}
+
+bool dragon_fight(char *u)
+{
+  aClient *user;
+  if (!(user = find(u)))
+       return false;
+  else
+       return dragon_fight(user);
+}
+
+bool dragon_fight(aClient *user)
+{
+  if (!is_playing(user))
+       return false;
+  else
+       return (isDragonFight(user->stats));
+}
+
+bool alphaNumeric(const char *str)
+{
+  int len = strlen(str);
+  for (int x = 0; x < len; x++)
+       {
+         if (!((int(str[x]) >= 65 && int(str[x]) <= 90) || (int(str[x]) >= 97 && int(str[x]) <= 122) || (int(str[x]) >= 48 && int(str[x]) <= 57) || int(str[x]) == 95))
+               return false;
+       }
+  return true;
+}
+
+bool passcmp(const char *encrypted, char *plaintext)
+{
+  char salt[3];
+  char *plaintext2, *plainToencrypt;
+  bool same = false;
+  
+  plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra
+  strcpy(plaintext2, plaintext);
+  
+  salt[0] = encrypted[0];
+  salt[1] = encrypted[1];
+  salt[3] = '\0';
+  
+  plainToencrypt = crypt(plaintext2, salt);
+  
+  same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false);
+  
+  delete []plaintext2;
+  
+  return same;
+}
+
+bool check_password(char *name, char *plaintext)
+{
+  Player *p;
+  
+  if (!(p = findplayer(name)))
+    return false;
+  else
+    {
+      return passcmp(p->getPassword().c_str(), plaintext);
+    }
+}
+
+bool timedOut(Player *p)
+{
+  if (!p)
+       return false;
+  else if (p->lastcommand == 0)
+       return false;
+  else
+    {
+         if ((time(NULL) - p->lastcommand) >= maxidletime)
+           return true;
+         
+         return false;
+    }
+}
index 89216e942f1b1deb8342dae927247809ca7bb0d6..b2c9478babb41899d5905da3136f60eac1e09f42 100644 (file)
@@ -126,6 +126,17 @@ E item *findStoreItemByID(int id);
 E tavernItem *findTavernItemByID(int id);
 /* find.cpp end   */
 
+/* messages.cpp begin */
+E void display_help(char *u, char *file);
+E void display_monster(char *u);
+E void display_players(char *u);
+E void display_players(aClient *user);
+/* messages.cpp end   */
+
+/* boolean.cpp begin */
+E bool check_password(char *name, char *plaintext);
+/* boolean.cpp end   */
+
 /** tcpclient.cpp **/
 E void check_idles();
 E void clearClients();
@@ -193,9 +204,7 @@ E char *strtok(char *str, const char *delim);
 #endif
 
 E char *spaces(int len, char *seperator);
-E void display_monster(char *u);
-E void display_players(char *u);
-E void display_players(aClient *user);
+
 E int stricmp(const char *s1, const char *s2);
 E int strnicmp(const char *s1, const char *s2, size_t len);
 E long int chartoint(char ch);
index 1ddbd545dc207a44db8af09ae4f3765e3a4f6fc4..c91338f2f1110dc8ffaa9cdc1d64aae6ff4c1865 100644 (file)
@@ -33,6 +33,7 @@ Monster dragon;                               // The current dragon
 Level levels[LEVELS];                  // The newest way to store monsters
 list<item*> Items;                      // The master list of items
 list<tavernItem> tavern;                // The list of items available at the tavern
+list<item*> store;                      // List of items available at the store
 
 toplist myToplist;          // List of the top 10 players
 
@@ -54,44 +55,11 @@ int stricmp(const char *s1, const char *s2);
 int strnicmp(const char *s1, const char *s2, size_t len);
 // String Functions
 
-/********** Password functions **********/
-
-bool passcmp(const char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one
-
-bool check_password(char *name, char *plaintext); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
-
-/********** Password functions **********/
-
-
-/********** GameServ Booleans **********/
 
 bool shuttingdown;
-bool timedOut(Player *p);
 void updateTS(Player *p);
 void timeOutEvent(Player *p);
 
-bool is_playing(char *u); // True if the given nickname in the clients list is playing.
-bool is_playing(aClient *user);
-
-bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
-bool is_fighting(aClient *user);
-
-bool player_fight(char *u); // True if the player is fighting another player.
-bool player_fight(aClient *user);
-
-bool master_fight(char *u); // True if the player is fighting their master.
-bool master_fight(aClient *user);
-
-bool dragon_fight(char *u); // True if the player is fighting the dragon.
-bool dragon_fight(aClient *user);
-
-bool alphaNumeric(const char *str); // Returns true if all of the characters in str are alphanumeric non-special chars
-/********** GameServ Booleans **********/
-
-void display_help(char *u, char *file = NULL);
-void display_monster(char *u);
-void display_players(char *u);
-void display_players(aClient *user);
 long int chartoint(char ch);
 int isstringnum(char *num);
 long int pow (int x, int y);
@@ -1347,121 +1315,6 @@ void delete_monsters()
 
 
 
-bool is_playing(char *u)
-{
-  aClient *user;
-  if (!(user = find(u)))
-       return false;
-  else
-       return is_playing(user);
-}
-
-bool is_playing(aClient *user)
-{
-  if (!user)
-    {
-         return false;
-    }
-  else if (!user->stats)
-       {
-         return false;
-       }
-  else if (!FL_is_playing(user))
-    {
-         return false;
-    }
-  else if (user->stats->getClient() != user)
-    {
-         return false;
-    }
-  else
-       return true;
-}
-
-bool is_fighting(char *u)
-{
-  aClient *user;
-  
-  if (!(user = find(u)))
-       return false;
-  else
-       return is_fighting(user);
-}
-
-bool is_fighting(aClient *user)
-{
-  if (!is_playing(user))
-       return false;
-  else
-       return player_fight(user) || master_fight(user) || user->stats->getMonster() != NULL;
-}
-
-bool player_fight(char *u)
-{
-  aClient *user;
-  
-  if (!(user = find(u)))
-       return false;
-  else 
-       return player_fight(user);
-}
-
-bool player_fight(aClient *user)
-{
-  if (!is_playing(user))
-       return false;
-  else if (is_playing(user->stats->getBattle()))
-    {
-         return true;
-    }
-  return false;
-}
-
-bool master_fight(char *u)
-{
-  aClient *user;
-  
-  if (!(user = find(u)))
-       return false;
-  else
-       return master_fight(user);
-}
-
-bool master_fight(aClient *user)
-{
-  if (!is_playing(user))
-       return false;
-  else
-       return user->stats->getMaster() != NULL;
-}
-
-bool dragon_fight(char *u)
-{
-  aClient *user;
-  if (!(user = find(u)))
-       return false;
-  else
-       return dragon_fight(user);
-}
-
-bool dragon_fight(aClient *user)
-{
-  if (!is_playing(user))
-       return false;
-  else
-       return (isDragonFight(user->stats));
-}
-
-bool alphaNumeric(const char *str)
-{
-  int len = strlen(str);
-  for (int x = 0; x < len; x++)
-       {
-         if (!((int(str[x]) >= 65 && int(str[x]) <= 90) || (int(str[x]) >= 97 && int(str[x]) <= 122) || (int(str[x]) >= 48 && int(str[x]) <= 57) || int(str[x]) == 95))
-               return false;
-       }
-  return true;
-}
 
 void do_fight(char *u)
 {
@@ -2390,39 +2243,7 @@ int load_gs_dbase()
   return 1;
 }
 
-bool passcmp(const char *encrypted, char *plaintext)
-{
-  char salt[3];
-  char *plaintext2, *plainToencrypt;
-  bool same = false;
-  
-  plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra
-  strcpy(plaintext2, plaintext);
-  
-  salt[0] = encrypted[0];
-  salt[1] = encrypted[1];
-  salt[3] = '\0';
-  
-  plainToencrypt = crypt(plaintext2, salt);
-  
-  same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false);
-  
-  delete []plaintext2;
-  
-  return same;
-}
 
-bool check_password(char *name, char *plaintext)
-{
-  Player *p;
-  
-  if (!(p = findplayer(name)))
-    return false;
-  else
-    {
-      return passcmp(p->getPassword().c_str(), plaintext);
-    }
-}
 
 void do_store(char *u)
 {
@@ -3274,20 +3095,7 @@ void updateTS(Player *p)
   
 }
 
-bool timedOut(Player *p)
-{
-  if (!p)
-       return false;
-  else if (p->lastcommand == 0)
-       return false;
-  else
-    {
-         if ((time(NULL) - p->lastcommand) >= maxidletime)
-           return true;
-         
-         return false;
-    }
-}
+
 
 void timeOutEvent(Player *p)
 {