/**************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvements copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefiting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************
* ROM 2.4 is copyright 1993-1998 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@hypercube.org) *
* Gabrielle Taylor (gtaylor@hypercube.org) *
* Brian Moore (zump@rom.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************
* 1stMUD ROM Derivative (c) 2001-2002 by Ryan Jennings *
* http://1stmud.dlmud.com/ <r-jenn@shaw.ca> *
***************************************************************************/
#include <sys/types.h>
#if !defined(WIN32)
#include <sys/time.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "tables.h"
#include "olc.h"
#include "lookup.h"
#include "recycle.h"
#include "interp.h"
#define HEDIT( fun ) bool fun(CHAR_DATA *ch, const char*argument)
extern HELP_AREA *had_list;
HELP_AREA *get_help_area (HELP_DATA * help)
{
HELP_AREA *temp;
HELP_DATA *thelp;
for (temp = had_list; temp; temp = temp->next)
for (thelp = temp->first; thelp; thelp = thelp->next_area)
if (thelp == help)
return temp;
return NULL;
}
HEDIT (hedit_show)
{
HELP_DATA *help;
EDIT_HELP (ch, help);
chprintlnf (ch,
"Keyword : [%s]\n\r" "Level : [%d]\n\r" "Texto :\n\r"
"%s-FIN-", help->keyword, help->level, help->text);
return FALSE;
}
HEDIT (hedit_level)
{
HELP_DATA *help;
int lev;
EDIT_HELP (ch, help);
if (IS_NULLSTR (argument) || !is_number (argument))
{
chprintln (ch, "Sintaxis : nivel [-1..MAX_LEVEL]");
return FALSE;
}
lev = atoi (argument);
if (lev < -1 || lev > MAX_LEVEL)
{
chprintf (ch, "HEdit : niveles entre -1 y %d solamente.\n\r",
MAX_LEVEL);
return FALSE;
}
help->level = lev;
chprintln (ch, "Ok.");
return TRUE;
}
HEDIT (hedit_keyword)
{
HELP_DATA *help;
EDIT_HELP (ch, help);
if (IS_NULLSTR (argument))
{
chprintln (ch, "Sintaxis : keyword [keywords]");
return FALSE;
}
free_string (help->keyword);
help->keyword = str_dup (argument);
chprintln (ch, "Ok.");
return TRUE;
}
HEDIT (hedit_new)
{
char arg[MIL], fullarg[MIL];
HELP_AREA *had;
HELP_DATA *help;
extern HELP_DATA *help_last;
if (IS_NULLSTR (argument))
{
chprintln (ch, "Sintaxis : new [nombre]");
chprintln (ch, " new [area] [nombre]");
return FALSE;
}
strcpy (fullarg, argument);
argument = one_argument (argument, arg);
if (!(had = had_lookup (arg)))
{
had = ch->in_room->area->helps;
argument = fullarg;
}
if (help_lookup (argument))
{
chprintln (ch, "HEdit : help ya existe.");
return FALSE;
}
if (!had) /* el area no tiene helps */
{
had = new_had ();
had->filename = str_dup (ch->in_room->area->file_name);
had->area = ch->in_room->area;
had->first = NULL;
had->last = NULL;
had->changed = TRUE;
had->next = had_list;
had_list = had;
ch->in_room->area->helps = had;
SET_BIT (ch->in_room->area->area_flags, AREA_CHANGED);
}
help = new_help ();
help->level = 0;
help->keyword = str_dup (argument);
help->text = str_dup ("");
if (help_last)
help_last->next = help;
if (help_first == NULL)
help_first = help;
help_last = help;
help->next = NULL;
if (!had->first)
had->first = help;
if (!had->last)
had->last = help;
had->last->next_area = help;
had->last = help;
help->next_area = NULL;
edit_start (ch, help, ED_HELP);
chprintln (ch, "Ok.");
return FALSE;
}
HEDIT (hedit_text)
{
HELP_DATA *help;
EDIT_HELP (ch, help);
if (!IS_NULLSTR (argument))
{
chprintln (ch, "Sintaxis : texto");
return FALSE;
}
string_append (ch, &help->text);
return TRUE;
}
void hedit (CHAR_DATA * ch, char *argument)
{
if (ch->pcdata->security < 9)
{
chprintln (ch, "HEdit: Insufficient security to modify code.");
edit_done (ch);
}
if (!str_cmp (argument, "done"))
{
edit_done (ch);
return;
}
if (emptystring (argument))
{
hedit_show (ch, argument);
return;
}
if (!process_olc_command (ch, argument, help_olc_comm_table))
interpret (ch, argument);
return;
}
CH_CMD (do_hedit)
{
HELP_DATA *pHelp;
if (IS_NPC (ch))
return;
if ((pHelp = help_lookup (argument)) == NULL)
{
chprintln (ch, "HEdit : Help inexistente.");
return;
}
edit_start (ch, pHelp, ED_HELP);
return;
}
HEDIT (hedit_delete)
{
HELP_DATA *pHelp, *temp;
HELP_AREA *had;
DESCRIPTOR_DATA *d;
bool found = FALSE;
EDIT_HELP (ch, pHelp);
for (d = descriptor_list; d; d = d->next)
if (d->editor == ED_HELP && pHelp == (HELP_DATA *) d->pEdit)
edit_done (d->character);
if (help_first == pHelp)
help_first = help_first->next;
else
{
for (temp = help_first; temp; temp = temp->next)
if (temp->next == pHelp)
break;
if (!temp)
{
bugf
("hedit_delete : help %s no encontrado en help_first",
pHelp->keyword);
return FALSE;
}
temp->next = pHelp->next;
}
for (had = had_list; had; had = had->next)
if (pHelp == had->first)
{
found = TRUE;
had->first = had->first->next_area;
}
else
{
for (temp = had->first; temp; temp = temp->next_area)
if (temp->next_area == pHelp)
break;
if (temp)
{
temp->next_area = pHelp->next_area;
found = TRUE;
break;
}
}
if (!found)
{
bugf ("hedit_delete : help %s no encontrado en had_list",
pHelp->keyword);
return FALSE;
}
free_help (pHelp);
chprintln (ch, "Ok.");
return TRUE;
}
HEDIT (hedit_list)
{
char buf[MIL];
int cnt = 0;
HELP_DATA *pHelp;
BUFFER *buffer;
EDIT_HELP (ch, pHelp);
if (!str_cmp (argument, "all"))
{
buffer = new_buf ();
for (pHelp = help_first; pHelp; pHelp = pHelp->next)
{
sprintf (buf, "%3d. %-14.14s%s", cnt, pHelp->keyword,
cnt % 4 == 3 ? "\n\r" : " ");
add_buf (buffer, buf);
cnt++;
}
if (cnt % 4)
add_buf (buffer, "\n\r");
page_to_char (buf_string (buffer), ch);
return FALSE;
}
if (!str_cmp (argument, "area"))
{
if (ch->in_room->area->helps == NULL)
{
chprintln (ch, "No hay helps en esta area.");
return FALSE;
}
buffer = new_buf ();
for (pHelp = ch->in_room->area->helps->first; pHelp;
pHelp = pHelp->next_area)
{
sprintf (buf, "%3d. %-14.14s%s", cnt, pHelp->keyword,
cnt % 4 == 3 ? "\n\r" : " ");
add_buf (buffer, buf);
cnt++;
}
if (cnt % 4)
add_buf (buffer, "\n\r");
page_to_char (buf_string (buffer), ch);
return FALSE;
}
if (IS_NULLSTR (argument))
{
chprintln (ch, "Sintaxis : list all");
chprintln (ch, " list area");
return FALSE;
}
return FALSE;
}