--- /dev/null
+#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();
+}