/
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

www.c					RoA WWW page code.  Formats
					some HTML pages with runtime
					data.  Neat stuff.

		******** 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 ***
*************************************************************************/
#include "conf.h"
#include "sysdep.h"

#include "structures.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "mudlimits.h"
#include "screen.h"
#include "lists.h"
#include "www.h"
#include "global.h"
#include "exshell.h"
#include "darkenelf.h"

/* internal functions */
void stats_to_html_buf(char *buf);
int update_stats_html(void);
int update_who_html(void);
void clear_html_goss(void);
void update_last_goss(chdata *ch, char *chan, char *str);
void update_goss_html(void);

// this function now returns #ppl online
// updated slightly 5/28/98 -jtrhone (searching for fprintf bug...)
int update_who_html(void)
{
  FILE *fl;
  dsdata *d;
  char name[MAX_POOFIN_LENGTH];
  int count = 0;

  if (!(fl = fopen(HTML_WHO_FILE, "wt"))) 
  {
    perror ("who_html");
    log("SYSERR: HTML_WHO_FILE unable to open for writing.");
    return 0;
  }

   /* actual page written here. -jtrhone */
   fprintf(fl, "<HTML>\n");
   fprintf(fl, "<META HTTP-EQUIV=""Refresh"" CONTENT=""90; URL=./who.html"">");
   fprintf(fl, "<HEAD>\n");
   fprintf(fl, "<TITLE>%s WHO page</TITLE>\n", longmudname);
   fprintf(fl, "</HEAD>\n");
   fprintf(fl, "<body background=""images/whobak.gif""\n");
   fprintf(fl, "bgcolor=#eeeeee text=#eeeeee link=#eeeeee vlink=#aaaaee>\n");
   fprintf(fl, "<center> <img src=images/whoimage.gif> </center>\n");
   fprintf(fl, "<h2 align=center>The adventurers of %s</h2>\n", shortmudname);
   fprintf(fl, "<hr>\n");
   fprintf(fl, "<h2>The following players are logged into %s:</h2>\n", shortmudname);
   fprintf(fl, "\n<h4>\n");
   fprintf(fl, "<blockquote>\n");

   /* print players to file here */
   Descriptors(d)
    if (D_CHECK(d) && IS_PC(d->character) && (GET_INVIS_LEV(d->character) < LEV_IMM))
     {
       count++;
       strcpy(name, GET_NAME(d->character));
       sprintf(buf, "%s", GET_TITLE(d->character));
       killp(buf);
       fprintf(fl, "<li>%s <em>%s</em>\n",name, buf);
     }

   fprintf(fl, "<br><em>%d visible player%s online.</em>\n",count,(count>1?"s":""));
   fprintf(fl, "</blockquote>\n");
   fprintf(fl, "</h4>\n");
   fprintf(fl, "<h4>Return to the <a href=""http://%s"">%s</a> Home page.</h4>\n", www_page, longmudname);
   fprintf(fl, "<hr>\n");
   fprintf(fl, "<ADDRESS>%s- <a href=""mailto:%s"">%s</a>\n", www_contact_name, www_mailto, www_mailto);
   fprintf(fl, "</ADDRESS>\n");
   fprintf(fl, "</body>\n");
   fprintf(fl, "<HTML>\n");
   fclose(fl);

   sprintf(name, "chmod 664 %s", HTML_WHO_FILE);
   roa_system(name);  /* just use pre allocated name for command */
   return count;      /* for global max online */
}

/* print stats to a html formatted buf */
void stats_to_html_buf(char *buf)
{
   int	i, j, k, con, freedcount, idlecount, closedcount, zone, zonecount, doncount;
   chdata *vict;
   obdata *obj;
   extern int buf_switches, buf_largecount, buf_overflows;
   extern int socialcount, helpcount;
   extern void uptime_to_buf(char *buf);
   extern void date_to_buf(char *buf);

   i = j = k = con = doncount = freedcount = idlecount = closedcount = zonecount = 0;

   /* use zone as counter */
      for (zone = 0; zone < top_of_world; zone++)
	if (ROOM_FLAGGED2(zone, DONATION))
	  doncount++;

      for (zone = 0; zone < NUM_ZONES; zone++)
	if (REAL_ZONE(zone))
	{
	  zonecount++;
          if (ZONE_FLAGGED(zone, Z_CLOSED))
	    closedcount++;
	  if (ZONE_IDLE(zone))
	    idlecount++;
	  if (ZONE_FREED(zone))
	    freedcount++;
	}
      for (vict = character_list; vict; vict = vict->next) 
      {
	 if (IS_NPC(vict))
	    j++;
	 else if (!GET_INVIS_LEV(vict)) 
         {
	    i++;
	    if (vict->desc)
	       con++;
	 }
      }

      for (obj = object_list; obj; obj = obj->next)
	 k++;
     
      sprintf(buf, "<li>%d player%s in game\n<li>%d connected", i, (con==1?"":"s"), con);
      sprintf(buf, "%s<li>%d mortal%s <em>max</em> this session\n", buf, max_on, (max_on==1?"":"s"));
      sprintf(buf, "%s<li>%d total registered players<p>\n", buf, top_of_p_table + 1);
      sprintf(buf, "%s<li>%d mobiles (%d prototypes)\n", buf, j, top_of_mobt);
      sprintf(buf, "%s<li>%d objects (%d prototypes)\n", buf, k, top_of_objt);
      sprintf(buf, "%s<li>%d rooms\n<li>%d donation room%s\n", 
	  buf, top_of_world, doncount, (doncount==1?"":"s"));
      sprintf(buf, "%s<li>%d total zones  (%d freed, %d idle, %d closed)<p>\n",
	  buf, zonecount, freedcount, idlecount, closedcount);
      sprintf(buf, "%s<li>%d socials\n", buf, socialcount);
      sprintf(buf, "%s<li>%d help files<p>\n", buf, helpcount);
      sprintf(buf, "%s<li>%d large bufs\n", buf, buf_largecount);
      sprintf(buf, "%s<li>%d buf switches (%d overflows)\n", buf, buf_switches, buf_overflows);
      uptime_to_buf(buf2);
      killp(buf2); 
      killr(buf2);
      sprintf(buf, "%s<li>%s\n", buf, buf2);

      date_to_buf(buf2);
      sprintf(buf, "%s\n<li>Last page update: %s\n", buf, buf2);      
}

int update_stats_html(void)
{
  FILE *fl;
  char filename[80];
  char name[MAX_INPUT_LENGTH];

  sprintf(filename,"%s", HTML_STATS_FILE);

   if (!(fl = fopen(filename, "w"))) {
      perror ("stats_html");
      log("SYSERR:  STATS HTML unable to open for writing.");
      return FALSE;
   }

   /* actual page written here. James Rhone*/
   fprintf(fl, "<HTML>\n");
   fprintf(fl, "<META HTTP-EQUIV=""Refresh"" CONTENT=""90; URL=./roastats.html"">");
   fprintf(fl, "<HEAD>\n");
   fprintf(fl, "<TITLE>%s STATS page</TITLE>\n", longmudname);
   fprintf(fl, "</HEAD>\n");
   fprintf(fl, "<body background=""images/roastatsbak.gif""\n");
   fprintf(fl, "bgcolor=#eeeeee text=#eeeeee link=#eeeeee vlink=#aaaaee>\n");
   fprintf(fl, "<center> <img src=images/roastatsimage.gif> </center>\n");
   fprintf(fl, "<h1 align=center>%s</h1>\n", longmudname);
   fprintf(fl, "<h2 align=center>Statistic Page</h2>\n");
   fprintf(fl, "<hr>\n");
   fprintf(fl, "<h1 align=center>\n");
   fprintf(fl, "<applet codebase=""./LEDSign/LED"" code=""LED.class"" width=377 height=45>\n");
   fprintf(fl, "   <param name=""script"" value=""./LEDSign/scripts/ROA.led"">\n");
   fprintf(fl, "   <param name=""font"" value=""./LEDSign/fonts/charter.font"">\n");
   fprintf(fl, "   <param name=""border"" value=""3"">\n");
   fprintf(fl, "   <param name=""bordercolor"" value=""0,0,100"">\n");
   fprintf(fl, "   <param name=""spacewidth"" value=""3"">\n");
   fprintf(fl, "   <param name=""wth"" value=""120"">\n");
   fprintf(fl, "   <param name=""ht"" value=""9"">\n");
   fprintf(fl, "   <param name=""ledsize"" value=""2"">\n");
   fprintf(fl, "</applet></h1>\n");
 
   fprintf(fl, "<h2>The latest statistics of %s:</h2>\n", shortmudname);
   fprintf(fl, "\n<h4>\n");
   fprintf(fl, "<blockquote>\n");

   /* dont send a character for auto update */
   stats_to_html_buf(buf1);

   /* print info to file here */
   fprintf(fl, "%s<p>\n", buf1);

   fprintf(fl, "</blockquote>\n");
   fprintf(fl, "</h4>\n");
   fprintf(fl, "<h4>Return to the <a href=""http://%s"">%s</a> Home page.</h4>\n", www_page, longmudname);
   fprintf(fl, "<hr>\n");
   fprintf(fl, "<ADDRESS>%s- <a href=""mailto:%s"">%s</a>\n", www_contact_name, www_mailto, www_mailto);
   fprintf(fl, "</ADDRESS>\n");
   fprintf(fl, "</body>\n");
   fprintf(fl, "<HTML>\n");

   fclose(fl);

   // ug+rw,o+r on file
   sprintf(name, "chmod 664 %s", HTML_STATS_FILE);
   roa_system(name);  /* just use pre allocated name for command */

   return TRUE;
}

void clear_html_goss(void)
{
  int i;
  
  for (i=0;i<GOSSIP_PAGE_LENGTH;i++)
  {
    strcpy(latest_gossip[i].name, "");
    strcpy(latest_gossip[i].said, "");
  }
}

// no longer JUST gossip, now every channel, include channel... 4/10/98 -jtrhone
void update_last_goss(chdata *ch, char *chan, char *str)
{
  int i;
  extern void update_allclient_chan(void);

  if (strlen(str) > MAX_INPUT_LENGTH || !str || IS_NPC(ch))
    return;

  for (i=GOSSIP_PAGE_LENGTH-1 ; i > 0; i--)
  {
    strcpy(latest_gossip[i].name, latest_gossip[i-1].name);
    strcpy(latest_gossip[i].said, latest_gossip[i-1].said);
  } 

  strcpy(latest_gossip[0].name, GET_NAME(ch));
 
  sprintf(buf2, "%s, '", chan);
  strcpy(latest_gossip[0].said, buf2);

  // no longer send color codes to web page... 2/12/98 -jtrhone
  strcpy(buf2, str);
  killp(buf2);

  strcat(buf2, "'");
  strcat(latest_gossip[0].said, buf2);

  // now update clients who like to have their chans updated  6/18/98 -jtrhone
  update_allclient_chan();
}

void update_goss_led(void)
{
  FILE *fl;
  char filename[80];
  char name[MAX_INPUT_LENGTH];
  int i;

  sprintf(filename,"%s", HTML_GOSS_LED_FILE);

   if (!(fl = fopen(filename, "w"))) {
      perror ("goss_led_file");
      log("SYSERR:  GOSS LED FILE unable to open for writing.");
      return;
   }

   /* actual page written here. James Rhone*/
   fprintf(fl, "!! %s GOSS LED script\n", shortmudname);
   fprintf(fl, "Do\n");

   fprintf(fl, " ScrollDown delay=30 center=true text=\\g%s\n", longmudname);
   fprintf(fl, " Sleep delay=2000\n");
   
   // add one line for each gossip here... -roa
   for (i=GOSSIP_PAGE_LENGTH-1; i >= 0; i--)
     if (latest_gossip[i].name[0])
     {
       fprintf(fl, " ScrollLeft delay=10 startspace=40 endspace=40 text=\\w");

       sprintf(buf, "%s: \\b%s",latest_gossip[i].name,latest_gossip[i].said);
       fprintf(fl, "%s\n", buf);
     }

   fprintf(fl, "!! repeat infinitely\n");
   fprintf(fl, "Repeat times=-1\n");
   fclose(fl);

   sprintf(name, "chmod 664 %s", HTML_GOSS_LED_FILE);
   roa_system(name);
}

void update_goss_html(void)
{
  FILE *fl;
  char filename[80];
  char name[MAX_INPUT_LENGTH];
  int i;

  update_goss_led();

  sprintf(filename,"%s", HTML_GOSS_FILE);

   if (!(fl = fopen(filename, "w"))) {
      perror ("goss_html");
      log("SYSERR:  GOSS HTML unable to open for writing.");
      return;
   }

   /* actual page written here. James Rhone*/
   fprintf(fl, "<HTML>\n");
   fprintf(fl, "<META HTTP-EQUIV=""Refresh"" CONTENT=""90; URL=./goss.html"">");
   fprintf(fl, "<HEAD>\n");
   fprintf(fl, "<TITLE>%s communication page</TITLE>\n", longmudname);
   fprintf(fl, "</HEAD>\n");
   fprintf(fl, "<body background=""images/gossbak.gif""\n");
   fprintf(fl, "bgcolor=#eeeeee text=#eeeeee link=#eeeeee vlink=#aaaaee>\n");
   fprintf(fl, "<center> <img src=images/gossimage.gif> </center>\n");
   fprintf(fl, "<h1 align=center>%s</h1>\n", longmudname);
   fprintf(fl, "<hr>\n");
   fprintf(fl, "<h2>The most recent <em>global communication</em> on %s:</h2>\n", shortmudname);
   fprintf(fl, "\n<h4>\n");
   fprintf(fl, "<h1 align=center>\n");
   fprintf(fl, "<applet codebase=""./LEDSign/LED"" code=""LED.class"" width=377 height=45>\n");
   fprintf(fl, "   <param name=""script"" value=""./LEDSign/scripts/goss.led"">\n");
   fprintf(fl, "   <param name=""font"" value=""./LEDSign/fonts/charter.font"">\n");
   fprintf(fl, "   <param name=""border"" value=""3"">\n");
   fprintf(fl, "   <param name=""bordercolor"" value=""0,0,100"">\n");
   fprintf(fl, "   <param name=""spacewidth"" value=""3"">\n");
   fprintf(fl, "   <param name=""wth"" value=""120"">\n");
   fprintf(fl, "   <param name=""ht"" value=""9"">\n");
   fprintf(fl, "   <param name=""ledsize"" value=""2"">\n");
   fprintf(fl, "</applet></h1>\n");
   fprintf(fl, "<blockquote>\n");

   /* print gossip array to file here */
   for (i=GOSSIP_PAGE_LENGTH-1; i >= 0; i--)
   {
     if (latest_gossip[i].name[0])
       fprintf(fl, "%s %s<br>\n", latest_gossip[i].name, latest_gossip[i].said);  
   }

   fprintf(fl, "</blockquote>\n");
   fprintf(fl, "</h4>\n");
   fprintf(fl, "<h4>Return to the <a href=""http://%s"">%s</a> Home page.</h4>\n", www_page, longmudname);
   fprintf(fl, "<hr>\n");
   fprintf(fl, "<ADDRESS>%s- <a href=""mailto:%s"">%s</a>\n", www_contact_name, www_mailto, www_mailto);
   fprintf(fl, "</ADDRESS>\n");
   fprintf(fl, "</body>\n");
   fprintf(fl, "<HTML>\n");

   fclose(fl);

   sprintf(name, "chmod 664 %s", HTML_GOSS_FILE);
   roa_system(name);
}