]> jfr.im git - irc/gameservirc.git/commitdiff
added a file for rapid development testing via a console (not to be used by all)
authorkainazzzo <redacted>
Thu, 23 Jun 2005 22:19:18 +0000 (22:19 +0000)
committerkainazzzo <redacted>
Thu, 23 Jun 2005 22:19:18 +0000 (22:19 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@341 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/.depend
gameserv/Makefile.in
gameserv/devel.cpp [new file with mode: 0644]
gameserv/tcpclient.cpp

index 631569065deba87fdf96d5b36c5265dacede04a3..cb3083227f687d07a19d4377c11cced621c8565a 100644 (file)
@@ -25,11 +25,11 @@ level.o: level.cpp item.h extern.h player.h level.h list.h listnode.h \
 log.o: log.cpp extern.h player.h level.h list.h listnode.h aClient.h \
   options.h config.h
 # 1 "/home/gameserv/gameserv//"
-pouch.o: pouch.cpp pouch.h item.h
-# 1 "/home/gameserv/gameserv//"
 news.o: news.cpp extern.h player.h level.h list.h listnode.h aClient.h \
   options.h config.h
 # 1 "/home/gameserv/gameserv//"
+pouch.o: pouch.cpp pouch.h item.h
+# 1 "/home/gameserv/gameserv//"
 player.o: player.cpp item.h player.h pouch.h extern.h level.h list.h \
   listnode.h aClient.h options.h config.h flags.h
 # 1 "/home/gameserv/gameserv//"
@@ -38,3 +38,6 @@ sockhelp.o: sockhelp.cpp sockhelp.h extern.h player.h level.h list.h \
 # 1 "/home/gameserv/gameserv//"
 tcpclient.o: tcpclient.cpp sockhelp.h options.h list.h listnode.h \
   aClient.h player.h extern.h level.h config.h flags.h
+# 1 "/home/gameserv/gameserv//"
+devel.o: devel.cpp sockhelp.h options.h list.h listnode.h aClient.h \
+  player.h extern.h level.h config.h flags.h
index cd4ef201756fb17bf27e5da2f964cd5c0e84b8d3..9327e199c5ecbda021cc83c58c69e4d0358d0478 100644 (file)
@@ -18,7 +18,10 @@ LDFLAGS = @LDFLAGS@
 LIBS = @LIBS@
 INSTALL = @INSTALL@
 
-SRCS = aClient.cpp \
+DRIVER = tcpclient.cpp
+CONSOLEDRIVER = devel.cpp
+
+TSRCS =        aClient.cpp \
        config.cpp \
        c_forest.cpp \
        do_attack.cpp \
@@ -30,10 +33,14 @@ SRCS =      aClient.cpp \
        news.cpp \
        pouch.cpp \
        player.cpp \
-       sockhelp.cpp \
-       tcpclient.cpp
+       sockhelp.cpp
+
+CONSOLESRCS = $(TSRCS) $(CONSOLEDRIVER)
+SRCS = $(TSRCS) $(DRIVER)
+ALLSRCS = $(TSRCS) $(DRIVER) $(CONSOLEDRIVER)
 
 OBJS = ${SRCS:.cpp=.o}
+CONSOLEOBJS = $(CONSOLESRCS:.cpp=.o)
 
 all:   gameserv
 
@@ -51,12 +58,16 @@ gameserv: $(OBJS)
        $(CC) $(CFLAGS) -c $<
 
 depend:
-       $(CC) -MM $(CFLAGS) $(SRCS) > .depend
+       $(CC) -MM $(CFLAGS) $(ALLSRCS) > .depend
 
 configscript: configscript.o
        $(CC) -o .config configscript.o
 
+console: $(CONSOLEOBJS)
+       $(CC) -o $@ $(CONSOLEOBJS) $(LIBS)
+
 # Catch any changes in the Makefile, everything depends on it.
 $(OBJS): Makefile
+$(CONSOLEOBJS): Makefile
 
 include .depend
diff --git a/gameserv/devel.cpp b/gameserv/devel.cpp
new file mode 100644 (file)
index 0000000..8c75a20
--- /dev/null
@@ -0,0 +1,388 @@
+#include "options.h"
+#include "list.h"
+#include "aClient.h"
+#include "extern.h"
+#include "flags.h"
+#include "player.h"
+#include "item.h"
+#include "pouch.h"
+
+#include <fstream>
+#include <iostream>
+
+int sock = 2;
+
+using namespace std;
+
+char *PACKAGE = "GameServ";
+char *VERSION = "1.2.6 +devel";
+
+long lastrefresh;
+
+List<aClient> clients[U_TABLE_SIZE];
+
+void save_lastrefresh();
+void load_lastrefresh();
+void prettyIntro();
+void check_idles();
+
+
+int main(int argc, char *argv[])
+{
+    char buffer[1024], buf[1024];
+    memset(buffer, 0, 1024);
+    memset(buf, 0, 1024);
+    int connected;
+
+    char *conf;
+    srand(time(NULL));
+    conf = new char[16];
+    strcpy(conf, "gameserv.conf");
+
+  /*
+   * This needs to be fixed to work for any number of arguments in any
+   * order
+   *
+   */
+  if (argc > 1)
+  {
+       if ( argc > 2 || stricmp(argv[1], "--help") == 0)
+       {
+           cout << "Usage: gameserv [options] [configfile]" << endl;
+           cout << "Options:" << endl;
+           cout << "--help                        Displays this help dialogue" << endl;
+           return 1;
+       }
+       delete []conf;
+       conf = argv[1];
+  }
+
+  prettyIntro();
+
+  if (load_config_file(conf))
+  {
+       cout << "Config file loaded ok...\n"
+             << "Turning into a daemon" << endl;
+  }
+  else
+       exit(2);
+
+    if (argc <= 1)
+       delete []conf;
+
+    // Turn into a daemon
+    /*
+    if (daemon(1,0) < 0)
+    {
+        perror("Could not turn into a daemon");
+        exit(3);
+    }
+    */
+
+  load_gs_dbase();
+  loadNews(newsdata, todaysnews);
+
+  if (load_masters() == false)
+  {
+       log("Error loading masters");
+       goto end;
+  }
+
+  if (load_monsters() == false)
+  {
+       log("Error loading monsters");
+       goto end;
+  }
+
+  if (!load_dragon())
+  {
+       log("Error loading dragon");
+       goto end;
+  }
+
+  if (load_levels() == false)
+  {
+       log("Error loading levels");
+       goto end;
+  }
+
+    shuttingdown = false;
+
+    char ignoreservers[32][256];
+    char *currentserver;
+    currentserver = strtok(ignoreserverslist, " ");
+    for (int server = 0; server < 32 && currentserver != NULL; server++)
+    {
+       strncpy(ignoreservers[server], currentserver, 255);
+       log("Placing %s on the server ignore list", currentserver);
+       currentserver = strtok(NULL, " ");
+    }
+
+ // This loop will retry the connection 3 times
+    connected = 1;
+    load_lastrefresh();
+
+    {    
+      string itemname;
+      item *testitem;
+      
+      cout << "Enter an weapon name: ";
+      cin >> itemname;
+      testitem = new weapon(itemname, 10000);
+      
+      cout << "You entered: " << testitem->getName();
+      
+      delete testitem;
+    }
+
+ end:    
+
+    save_gs_dbase();
+    save_dragon();
+    saveNews(newsdata, todaysnews);
+    
+    delete_monsters();
+    
+#ifdef DEBUGMODE
+    log("<CLOSED>");
+#endif
+    
+    unload_config_file();
+    return 0;
+}
+    
+aClient *find(char *nick)
+{
+  return findbynick(nick);
+}
+
+aClient *find(const char *nick)
+{
+  return findbynick(nick);
+}
+
+#ifdef P10
+
+aClient *findbyrealnick(char *realnick)
+{
+  ListNode <aClient> *newPtr;
+  unsigned long hv = sHASH((unsigned char *) realnick);
+  newPtr = clients[hv].First();
+  
+  aClient *client = NULL;
+  
+  while (newPtr)
+    {
+      client = newPtr->getData();
+      if (stricmp(client->getRealNick(), realnick) == 0)
+       return client;
+      client = NULL;
+      newPtr = newPtr->Next();
+    }
+  return client;    
+}
+
+#else
+
+aClient *findbyrealnick(char *realnick)
+{
+  return findbynick(realnick);
+}
+
+#endif
+
+aClient *findbynick(char *nick)
+{
+  ListNode <aClient> *newPtr;
+#ifdef P10
+  unsigned long hv = sHASH((unsigned char *) nick);
+#else
+  unsigned long hv = iHASH((unsigned char *) nick);
+#endif
+  
+  newPtr = clients[hv].First();
+  
+  aClient *client = NULL;
+  
+  while (newPtr)
+    {
+      client = newPtr->getData();
+#ifdef P10
+      if (strcmp(client->getNick(), nick) == 0)
+#else
+       if (stricmp(client->getNick(), nick) == 0)
+#endif
+         return client;
+      client = NULL;
+      newPtr = newPtr->Next();
+    }
+  return client;    
+}
+
+aClient *findIRCplayer(const char *nick)
+{
+  ListNode <aClient> *newPtr;
+  aClient *p = NULL;
+  
+  p = find(nick);
+  
+  if (!is_playing(p))
+    return NULL;
+  
+  unsigned long hv = iHASH((unsigned char *) p->stats->name.c_str());
+  
+  for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
+    {
+      p = newPtr->getData();
+#ifdef P10
+      if (strcmp(p->getNick(), nick) == 0)
+#else
+       if (stricmp(p->getNick(), nick) == 0)
+#endif
+         return p;
+      p = NULL;
+    }
+  return NULL;
+}
+
+aClient *findplayer(const char *name)
+{
+  ListNode <aClient> *newPtr;
+  Player *p = NULL;
+  unsigned long hv = iHASH((unsigned char *) name);
+  for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
+    {
+      p = newPtr->getData()->stats;
+      if (stricmp(p->name.c_str(), name) == 0)
+       return newPtr->getData();
+      p = NULL;
+    }
+  return NULL;
+}
+
+void check_idles()
+{
+  ListNode <aClient> *newPtr;
+  Player *p = NULL;
+  
+  for (int x = 0; x < U_TABLE_SIZE; x++)
+    {
+      for (newPtr = players[x].First(); newPtr; newPtr = newPtr->Next())
+       {
+         p = newPtr->getData()->stats;
+         switch(p->level)
+           {
+           case 1:
+             if ((time(NULL) - p->lastlogin) / 86400 >= level1expire)
+               {
+                 logout(newPtr->getData());
+                 players[x].remove(newPtr->getData());
+                 return;
+               }
+             break;
+             
+           default:
+             if ((time(NULL) - p->lastlogin) / 86400 >= defaultexpire)
+               {
+                 logout(newPtr->getData());
+                 players[x].remove(newPtr->getData());
+                 return;
+               }
+             break;
+           }
+         if (timedOut(p))
+           {
+             timeOutEvent(p);
+           }
+       }
+    }
+}
+
+aClient *findbynick(const char *nick)
+{
+  ListNode <aClient> *newPtr;
+#ifdef P10
+  unsigned long hv = sHASH((unsigned char *) nick);
+#else
+  unsigned long hv = iHASH((unsigned char *) nick);
+#endif
+  
+  newPtr = clients[hv].First();
+  
+  aClient *client = NULL;
+  
+  while (newPtr)
+    {
+      client = newPtr->getData();
+#ifdef P10
+      if (strcmp(client->getNick(), nick) == 0)
+#else
+       if (stricmp(client->getNick(), nick) == 0)
+#endif
+         return client;
+      client = NULL;
+      newPtr = newPtr->Next();
+    }
+  return client;    
+}
+
+void prettyIntro()
+{
+  cout << endl;
+  cout << "  GGGG     AAA   MM    MM EEEEEEE  SSSSS  EEEEEEE RRRRRR  VV     VV " << endl;
+  cout << " GG  GG   AAAAA  MMM  MMM EE      SS      EE      RR   RR VV     VV " << endl;
+  cout << "GG       AA   AA MM MM MM EEEEE    SSSSS  EEEEE   RRRRRR   VV   VV  " << endl;
+  cout << "GG   GGG AAAAAAA MM    MM EE           SS EE      RR  RR    VV VV   " << endl;
+  cout << "G     G  AA   AA MM    MM EEEEEEE  SSSSS  EEEEEEE RR   RR    VVV" << endl;
+  cout << " GGGGG                                                        V\n\n" << endl;
+  cout << "Version: " << VERSION << endl;
+}
+
+void load_lastrefresh()
+{
+  ifstream infile;
+  infile.open(".gsrefresh");
+  if (infile.fail())
+    {
+#ifdef DEBUGMODE
+      log("Error opening .gsrefresh");
+#endif
+      
+    generate:
+      long mytime = time(NULL);
+#ifdef DEBUGMODE
+      log("Generating new refresh time");
+#endif
+      
+      // Just a safety measure... tho no one should
+      // get anywhere near the time as their refreshperiod
+      if (refreshperiod >= mytime)
+       refreshperiod = 86400;
+      
+      lastrefresh = mytime - (mytime % refreshperiod);
+      refreshall();
+      save_lastrefresh();
+      return;
+    }
+  infile >> lastrefresh;
+  infile.close();
+  if (lastrefresh < 0)
+    goto generate;
+}
+
+void save_lastrefresh()
+{
+  ofstream outfile;
+  
+  outfile.open(".gsrefresh");
+  
+  if (outfile.fail())
+    {
+      log("Error creating new file .gsrefresh");
+      return;
+    }
+  outfile << lastrefresh << endl;
+  
+  outfile.close();
+}
index 2e97580b95c4c4b4e11f1e97026ccb282aa10af6..a873817fe7ae28a01dff297b8e0e7a42e6d1c7aa 100644 (file)
 #include <stdlib.h>
 #include <fcntl.h>
 #include <signal.h>
+
 //#include <sys/types.h>
 //#include <sys/wait.h>
 //#include <errno.h>
 
-using std::ofstream;
-using std::ifstream;
-using std::cerr;
-using std::endl;
+using namespace std;
 
 char *PACKAGE = "GameServ";
 char *VERSION = "1.2.6 +devel";