+ /*
+ * 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;
+ delete []conf;
+ 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);
+ }
+ if (load_items() == 0)
+ {
+ log("Error loading items");
+ goto end;
+ }
+
+ if (load_store() == 0)
+ {
+ log("Error loading store");
+ goto end;
+ }
+ if (load_tavern() == 0)
+ {
+ log("Error loading tavern");
+ goto end;
+ }
+
+ 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
+ for (int retry = 0; retry < 3 && !shuttingdown; retry++)
+ {
+ connected = 1;
+ load_lastrefresh();
+ load_lastrollover();
+
+ long int loadtime = time(NULL);
+ long int currentTime;
+ long int oldTime = loadtime;
+
+ lastidlecheck = loadtime;
+
+#ifdef DEBUGMODE
+ log("Setting primary Idle Check timestamp: %ld", lastidlecheck);
+#endif
+ bool loaded = false;
+
+ ignore_pipe();
+ sock = conn(remoteserver, remoteport, localhost, 0);
+ // sock = make_connection(remoteport, SOCK_STREAM, remoteserver);
+ if (sock == -1)
+ {
+ fprintf(stderr,"make_connection failed.\n");
+ unload_config_file();
+ return -1;
+ }
+ log("%S socket connected.");
+