/
roa/
roa/lib/boards/
roa/lib/config/
roa/lib/edits/
roa/lib/help/
roa/lib/misc/
roa/lib/plrobjs/
roa/lib/quests/
roa/lib/socials/
roa/lib/www/
roa/lib/www/LEDSign/
roa/lib/www/LEDSign/fonts/
roa/lib/www/LEDSign/scripts/
roa/src/s_inc/
roa/src/sclient/
roa/src/sclient/binary/
roa/src/sclient/text/
roa/src/util/
/************************************************************************
	Realms of Aurealis 		James Rhone aka Vall of RoA

global.c				Most global variables found around
					are declared here first.  This file
					also deals with online editting of
					some global variables.  Replaces 
					much of the legacy config.c and makes
					it OLCable.

	All variables will be declared with default values in case a config
	file cannot be found or read.

		******** 100% Completely Original Code ********
		*** BE AWARE OF ALL RIGHTS AND RESERVATIONS ***
		******** 100% Completely Original Code ********
		        All rights reserved henceforth. 

    Please note that no guarantees are associated with any code from
Realms of Aurealis.  All code which has been released to the general
public has been done so with an 'as is' pretense.  RoA is based on both
Diku and CircleMUD and ALL licenses from both *MUST* be adhered to as well
as the RoA license.   *** Read, Learn, Understand, Improve ***
*************************************************************************/
#define __ROA_GLOBAL_C__

#include "conf.h"
#include "sysdep.h"

#include "structures.h"
#include "utils.h"
#include "db.h"
#include "comm.h"
#include "handler.h"
#include "plshop.h"
#include "global.h"
#include "weather.h"
#include "htown.h"

// if no port given on command line, what port should the MUD run on?
int DFLT_PORT = 4000;

// whats the default data directory off of circle?
char *DFLT_DIR = "lib";

// how many descriptors (files/connections/etc) does your system allow open
// at one time by a process?
int MAX_DESCRIPTORS_AVAILABLE = 256;

/****************************************************************************/
/****************************************************************************/
// Code from this point forward, manipulation of some of the variables above 
// and others.

// external functions called by this file...
void clear_html_goss(void);
void read_sort_roa_socials(void);
void read_sort_roa_help(void);
void read_sort_roa_wizhelp(void);
void read_sort_wspells(void);
void boot_quests(void);
void boot_plshops(void);

// clear out and default arena data
void clear_arena(void)
{
  arena_info.mortal_initiated = FALSE;
  arena_info.in_progress = FALSE;
  arena_info.locked = TRUE;
  arena_info.minlevel = 1;
  arena_info.maxlevel = 70;
  arena_info.ticks_to_start   = -1;
  arena_info.ticks_since_kill = -1;
  arena_info.official = 0;
}

// clear out the who_list structure
void clear_who_list(void)
{
  int i;

  for (i=0; i<MAX_PLAYERS; i++)
  {
    who_list[i].name[0] = '\0';
    who_list[i].incog = FALSE;
    who_list[i].level = 0;
  }
}

/* reset the time in the game from file */
void    reset_time(void)
{
  long  beginning_of_time = 650336715;
  struct time_info_data mud_time_passed(time_t t2, time_t t1);

  time_info = mud_time_passed(time(0), beginning_of_time);
  time_info.year += 1000;       // sync up with RoA Mythos timeline

}

/* init global structures on bootup -jtrhone */
void init_globals(void)
{
  log("   Auction ptr.");
     auction_ptr = NULL;

  log("   RoAClient PID ptr.");
     cl_pids = NULL;

  log("   Arena Data.");
     clear_arena();

  log("   WWW Gossip.");
    clear_html_goss();

  log("   Who List.");
    clear_who_list();

  log("   Reading & Sorting RoASocials");
    read_sort_roa_socials();

  log("   Reading & Sorting RoAHelp");
    read_sort_roa_help();

  log("   Reading & Sorting RoAWizHelp");
    read_sort_roa_wizhelp();

  log("   Reading & Sorting RoAWarlockSpells");
    read_sort_wspells();

  log("   Booting RoAutomated Quests");
    boot_quests();

  log("   Booting RoA Player Shops");
    boot_plshops();

  // init some runtime globals...
  log("   Runtime Globals");
  if (!load_configuration(TRUE))
  {
    autosave_time = 7;
    level_can_shout = 2;
    holler_move_cost = 20;
    max_npc_corpse_time = 5;
    max_pc_corpse_time = 10;
    immort_start_room = 1204;
    mortal_start_room = DEF_GATEWAY;
    frozen_start_room = 1202;
    newbie_start_room = 1900;
    nameserver_is_slow = YES;
    bin_socials = NO;
    auto_save = YES;
    use_autowiz = YES;
    min_wizlist_lev = LEV_GOD;
    requirelongdesc = YES;
    mailcost = 20;
    maxnewbielevel = 5;
    minforarenawin = 5;
    maxfleeexploss = 200000;
    maxdeathexploss= 500000;
    max_aliases    = 40;
    train_pracs    = 50;
    useglobals     = 0;

    shortmudname  = STR_DUP("RoA");
    longmudname   = STR_DUP("Realms of Aurealis");
    currency_name = STR_DUP("gold");
    currency_name_plural = STR_DUP("gold coins");

    impname       = STR_DUP("Impl  ");
    cimpname      = STR_DUP("Cimpl ");
    aimpname      = STR_DUP("Aimpl ");
    godname       = STR_DUP(" God  ");
    avtrname      = STR_DUP("Avatar");
    trustedname   = STR_DUP("+Avtr+");
    ambassname    = STR_DUP("Ambass");

    spico_path    = STR_DUP("/home/vall/roa/lib/edits/spico");

    www_page         = STR_DUP("roa.com");
    www_mailto       = STR_DUP("vall@roa.mudservices.com");
    www_contact_name = STR_DUP("James Rhone");

    // only if we didn't read it in successfully
    reset_time();
  }

  sprintf(buf, "   Current Gametime: %dH %dD %dM %dY.", time_info.hours, time_info.day,
          time_info.month, time_info.year);
  log(buf);

  // not alterable...
  RoA_version   = STR_DUP("RoA v2.0");
  OLC_version   = STR_DUP("RoAOLC(v2.2)");

  sprintf(buf, 
        "\033[H\033[J"
        "\033[25C\033[30;46m-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\033[0m\n\r"
        "\033[25C\033[30;46m-                            -\033[0m\n\r"
        "\033[25C\033[30;46m-         Welcome to         -\033[0m\n\r"
        "\033[25C\033[30;46m-                            -\033[0m\n\r"
        "\033[36m\033[25C\033[30;46m-     %-18.18s     -\033[0m\n\r"
        "\033[25C\033[30;46m-                            -\033[0m\n\r"
        "\033[25C\033[30;46m-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\033[0m\n\r"
        "\n\n\n\r"
        "\033[36m0\033[0m) Exit from %s.\n\r"
        "\033[36m1\033[0m) \033[1mEnter the game.\033[0m.\n\r"
        "\033[36m2\033[0m) Enter your character description.\n\r"
        "\033[36m3\033[0m) Read the background story.\n\r"
        "\033[36m4\033[0m) Change password.\n\r"
        "\033[36m5\033[0m) View visible players online.\n\r"
        "\033[36m6\033[0m) View current %s statistics.\n\r"
        "\033[31m9\033[0m) Delete this character.\n\r"
        "\n\r"
        "   What is thy bidding? ", longmudname, shortmudname, shortmudname);

  VTMENU = STR_DUP(buf);

  sprintf(buf, "\n\r"
               "Welcome to %s:\n\n\r"
               "0) Exit from %s.\n\r"
               "1) Enter the game.\n\r"
               "2) Enter your character description.\n\r"
               "3) Read the background story.\n\r"
               "4) Change password.\n\r"
               "5) View visible players online.\n\r"
               "6) View current %s statistics.\n\r"
               "9) Delete this character.\n\r"
               "\n\r"
               "   What is thy bidding? ", longmudname, shortmudname, shortmudname);

  MENU   = STR_DUP(buf);

  init_weather();
}

// attempt to parse config file for config values...
// if first, do not free up existing strings  8/5/98 -jtrhone
int load_configuration(BOOL first)
{
  FILE *fp;

  if (!(fp = fopen(MAIN_CONFIG_FILE, "rt")))
  {
    mudlog("SYSERR: Unable to open MAIN_CONFIG_FILE for reading.",BRF,LEV_IMM,TRUE);
    mudlog("SYSUPD: Using default configuration.",BRF,LEV_IMM,TRUE);
    return FALSE;
  }

  if (fscanf(fp, "year:%d\n", &time_info.year) != 1)
    mudlog("SYSERR: configuration read error, line 1", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "month:%d\n", &time_info.month) != 1)
    mudlog("SYSERR: configuration read error, line 2", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "day:%d\n", &time_info.day) != 1)
    mudlog("SYSERR: configuration read error, line 3", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "autosave_time:%d\n", &autosave_time) != 1)
    mudlog("SYSERR: configuration read error, line 4", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "level_can_shout:%d\n", &level_can_shout) != 1)
    mudlog("SYSERR: configuration read error, line 5", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "holler_move_cost:%d\n", &holler_move_cost) != 1)
    mudlog("SYSERR: configuration read error, line 6", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "max_npc_corpse_time:%d\n", &max_npc_corpse_time) != 1)
    mudlog("SYSERR: configuration read error, line 7", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "max_pc_corpse_time:%d\n", &max_pc_corpse_time) != 1)
    mudlog("SYSERR: configuration read error, line 8", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "immort_start_room:%d\n", &immort_start_room) != 1)
    mudlog("SYSERR: configuration read error, line 9", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "mortal_start_room:%d\n", &mortal_start_room) != 1)
    mudlog("SYSERR: configuration read error, line 10", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "frozen_start_room:%d\n", &frozen_start_room) != 1)
    mudlog("SYSERR: configuration read error, line 11", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "newbie_start_room:%d\n", &newbie_start_room) != 1)
    mudlog("SYSERR: configuration read error, line 12", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "nameserver_is_slow:%d\n", &nameserver_is_slow) != 1)
    mudlog("SYSERR: configuration read error, line 13", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "bin_socials:%d\n", &bin_socials) != 1)
    mudlog("SYSERR: configuration read error, line 14", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "auto_save:%d\n", &auto_save) != 1)
    mudlog("SYSERR: configuration read error, line 15", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "use_autowiz:%d\n", &use_autowiz) != 1)
    mudlog("SYSERR: configuration read error, line 16", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "min_wizlist_lev:%d\n", &min_wizlist_lev) != 1)
    mudlog("SYSERR: configuration read error, line 17", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "requirelongdesc:%d\n", &requirelongdesc) != 1)
    mudlog("SYSERR: configuration read error, line 18", BRF, LEV_IMM, TRUE);

  if (fscanf(fp, "mailcost:%d\n", &mailcost) != 1)
    mudlog("SYSERR: configuration read error, line 19", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "maxnewbielevel:%d\n", &maxnewbielevel) != 1)
    mudlog("SYSERR: configuration read error, line 20", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "minforarenawin:%d\n", &minforarenawin) != 1)
    mudlog("SYSERR: configuration read error, line 21", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "maxfleeexploss:%d\n", &maxfleeexploss) != 1)
    mudlog("SYSERR: configuration read error, line 22", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "maxdeathexploss:%d\n", &maxdeathexploss) != 1)
    mudlog("SYSERR: configuration read error, line 23", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "max_aliases:%d\n", &max_aliases) != 1)
    mudlog("SYSERR: configuration read error, line 24", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "train_pracs:%d\n", &train_pracs) != 1)
    mudlog("SYSERR: configuration read error, line 25", BRF, LEV_IMM, TRUE);
  if (fscanf(fp, "useglobals:%d\n", &useglobals) != 1)
    mudlog("SYSERR: configuration read error, line 26", BRF, LEV_IMM, TRUE);

  // dont do this the first time thru...
  if (!first)
  {
    FREENULL(shortmudname);
    FREENULL(longmudname);
    FREENULL(currency_name);
    FREENULL(currency_name_plural);
    FREENULL(impname);
    FREENULL(cimpname);
    FREENULL(aimpname);
    FREENULL(godname);
    FREENULL(avtrname);
    FREENULL(trustedname);
    FREENULL(ambassname);

    FREENULL(spico_path);

    FREENULL(www_page);
    FREENULL(www_mailto);
    FREENULL(www_contact_name);
  }

  fscanf(fp, "shortmudname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  shortmudname = STR_DUP(buf);

  fscanf(fp, "longmudname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  longmudname = STR_DUP(buf);

  fscanf(fp, "currency_name:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  currency_name = STR_DUP(buf);
 
  fscanf(fp, "currency_name_plural:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  currency_name_plural = STR_DUP(buf);
 
  fscanf(fp, "impname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  impname       = STR_DUP(buf);

  fscanf(fp, "cimpname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  cimpname      = STR_DUP(buf);

  fscanf(fp, "aimpname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  aimpname      = STR_DUP(buf);

  fscanf(fp, "godname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  godname       = STR_DUP(buf);

  fscanf(fp, "avtrname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  avtrname      = STR_DUP(buf);

  fscanf(fp, "trustedname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  trustedname   = STR_DUP(buf);

  fscanf(fp, "ambassname:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  ambassname    = STR_DUP(buf);

  fscanf(fp, "spico_path:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  spico_path    = STR_DUP(buf);

  fscanf(fp, "www_page:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  www_page    = STR_DUP(buf);

  fscanf(fp, "www_mailto:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  www_mailto    = STR_DUP(buf);

  fscanf(fp, "www_contact_name:"); 
  fgets(buf, 80, fp);
  buf[strlen(buf) -1] = '\0';
  www_contact_name    = STR_DUP(buf);

  fclose(fp);

  mudlog("SYSUPD: Main config file loaded successfully.", BUG, LEV_IMM, TRUE);
  return TRUE;
}

int save_configuration(void)
{
  FILE *fp;
  
  if (!(fp = fopen(MAIN_CONFIG_FILE, "wt")))
  {
    mudlog("SYSERR: Unable to open MAIN_CONFIG_FILE for writing.",BRF,LEV_IMM,TRUE);
    return FALSE;
  }

  fprintf(fp, "year:%d\n", time_info.year);
  fprintf(fp, "month:%d\n", time_info.month);
  fprintf(fp, "day:%d\n", time_info.day);
  fprintf(fp, "autosave_time:%d\n", autosave_time);
  fprintf(fp, "level_can_shout:%d\n", level_can_shout);
  fprintf(fp, "holler_move_cost:%d\n", holler_move_cost);
  fprintf(fp, "max_npc_corpse_time:%d\n", max_npc_corpse_time);
  fprintf(fp, "max_pc_corpse_time:%d\n", max_pc_corpse_time);
  fprintf(fp, "immort_start_room:%d\n", immort_start_room);
  fprintf(fp, "mortal_start_room:%d\n", mortal_start_room);
  fprintf(fp, "frozen_start_room:%d\n", frozen_start_room);
  fprintf(fp, "newbie_start_room:%d\n", newbie_start_room);
  fprintf(fp, "nameserver_is_slow:%d\n", nameserver_is_slow);
  fprintf(fp, "bin_socials:%d\n", bin_socials);
  fprintf(fp, "auto_save:%d\n", auto_save);
  fprintf(fp, "use_autowiz:%d\n", use_autowiz);
  fprintf(fp, "min_wizlist_lev:%d\n", min_wizlist_lev);
  fprintf(fp, "requirelongdesc:%d\n", requirelongdesc);

  fprintf(fp, "mailcost:%d\n", mailcost);
  fprintf(fp, "maxnewbielevel:%d\n", maxnewbielevel);
  fprintf(fp, "minforarenawin:%d\n", minforarenawin);
  fprintf(fp, "maxfleeexploss:%d\n", maxfleeexploss);
  fprintf(fp, "maxdeathexploss:%d\n", maxdeathexploss);
  fprintf(fp, "max_aliases:%d\n", max_aliases);
  fprintf(fp, "train_pracs:%d\n", train_pracs);
  fprintf(fp, "useglobals:%d\n", useglobals);

  fprintf(fp, "shortmudname:%s\n", shortmudname);
  fprintf(fp, "longmudname:%s\n", longmudname);
  fprintf(fp, "currency_name:%s\n", currency_name);
  fprintf(fp, "currency_name_plural:%s\n", currency_name_plural);

  fprintf(fp, "impname:%s\n", impname);
  fprintf(fp, "cimpname:%s\n", cimpname);
  fprintf(fp, "aimpname:%s\n", aimpname);
  fprintf(fp, "godname:%s\n", godname);
  fprintf(fp, "avtrname:%s\n", avtrname);
  fprintf(fp, "trustedname:%s\n", trustedname);
  fprintf(fp, "ambassname:%s\n", ambassname);

  fprintf(fp, "spico_path:%s\n", spico_path);

  fprintf(fp, "www_page:%s\n", www_page);
  fprintf(fp, "www_mailto:%s\n", www_mailto);
  fprintf(fp, "www_contact_name:%s\n", www_contact_name);

  fclose(fp);

  mudlog("SYSUPD: config_file saved successfully.", BUG, LEV_IMM, TRUE);
  return TRUE;
}


#undef __ROA_GLOBAL_C__