1stMUD/corefiles/
1stMUD/gods/
1stMUD/player/
1stMUD/win32/
1stMUD/win32/ROM/
/**************************************************************************
*  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>                   *
***************************************************************************/

/* Online Social Editting Module, 
 * (c) 1996,97 Erwin S. Andreasen <erwin@andreasen.org>
 * See the file "License" for important licensing information
 */

/* This version contains minor modifications to support ROM 2.4b4. */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "db.h"
#include "olc.h"

#define SEDIT( fun )		bool fun( CHAR_DATA *ch, const char *argument )

/* Find a social based on name */
int social_lookup(const char *name)
{
	int i;

	for (i = 0; i < maxSocial; i++)
		if (!str_cmp(name, social_table[i].name))
			return i;

	return -1;
}

/*
 * Social editting command
 */

SOCIAL_DATA *get_social_data(const char *name)
{
	int i;

	for (i = 0; i < maxSocial; i++)
		if (!str_cmp(name, social_table[i].name))
			return &social_table[i];
	return NULL;
}

SEDIT(sedit_show)
{
	SOCIAL_DATA *pSocial;

	if (IS_NULLSTR(argument))
		EDIT_SOCIAL(ch, pSocial);
	else
		pSocial = get_social_data(argument);

	if (pSocial == NULL)
	{
		chprintln(ch, "That social does not exist.");
		return FALSE;
	}

	chprintf(ch, "%s\n\r",
			 stringf(0, ALIGN_CENTER, "-",
					 FORMATF("[ %s: %s ]", olc_ed_name(ch), olc_ed_vnum(ch))));

	chprintf(ch, "Name    : %s\n\r"
			 "(cnoarg): %s\n\r" "(onoarg): %s\n\r"
			 "(cfound): %s\n\r" "(ofound): %s\n\r"
			 "(vfound): %s\n\r" "(cself) : %s\n\r"
			 "(oself) : %s\n\r",
			 IS_STRSET(pSocial->name),
			 IS_STRSET(pSocial->char_no_arg),
			 IS_STRSET(pSocial->others_no_arg),
			 IS_STRSET(pSocial->char_found),
			 IS_STRSET(pSocial->others_found),
			 IS_STRSET(pSocial->vict_found),
			 IS_STRSET(pSocial->char_auto), IS_STRSET(pSocial->others_auto));

	chprintln(ch, draw_line(NULL, 0));
	return TRUE;
}

SEDIT(sedit_delete)
{
	int i, j;
	SOCIAL_DATA *pSocial;
	struct social_type *new_table;

	new_table = (struct social_type *) calloc(sizeof(*new_table), maxSocial);

	if (!new_table)
	{
		chprintln(ch, "Memory allocation failed. Brace for impact...");
		return FALSE;
	}

	if (IS_NULLSTR(argument))
		EDIT_SOCIAL(ch, pSocial);
	else
		pSocial = get_social_data(argument);

	if (pSocial == NULL)
	{
		chprintln(ch, "No such social exists.");
		return FALSE;
	}

	for (i = 0, j = 0; i < maxSocial + 1; i++)
	{
		if (&social_table[i] != pSocial)
		{
			new_table[j] = social_table[i];
			j++;
		}
	}
	free(social_table);
	social_table = new_table;
	maxSocial--;
	edit_done(ch);
	chprintln(ch, "Social deleted.");
	return TRUE;
}

SEDIT(sedit_create)
{
	int iSocial;
	SOCIAL_DATA *pSocial;
	char arg[MAX_INPUT_LENGTH];
	struct social_type *new_table;

	argument = one_argument(argument, arg);

	if (IS_NULLSTR(arg))
	{
		chprintln(ch, "Syntax: sedit create [social]");
		return FALSE;
	}
	if ((iSocial = social_lookup(arg)) != -1)
	{
		chprintln(ch, "A social with that name already exists.");
		return FALSE;
	}
	maxSocial++;
	new_table =
		(struct social_type *) realloc(social_table,
									   sizeof(struct
											  social_type) * (maxSocial + 1));

	if (!new_table)
	{
		chprintln(ch, "Memory allocation failed. Brace for impact...");
		return FALSE;
	}
	social_table = new_table;
	replace_string(social_table[maxSocial - 1].name, arg);
	replace_string(social_table[maxSocial - 1].char_no_arg, "");
	replace_string(social_table[maxSocial - 1].others_no_arg, "");
	replace_string(social_table[maxSocial - 1].char_found, "");
	replace_string(social_table[maxSocial - 1].others_found, "");
	replace_string(social_table[maxSocial - 1].vict_found, "");
	replace_string(social_table[maxSocial - 1].char_auto, "");
	replace_string(social_table[maxSocial - 1].others_auto, "");
	replace_string(social_table[maxSocial].name, "");

	pSocial = get_social_data(arg);
	edit_start(ch, pSocial, ED_SOCIAL);
	chprintln(ch, "Social created.");
	return TRUE;
}

void sedit(CHAR_DATA * ch, char *argument)
{
	if (ch->pcdata->security < 5)
	{
		chprintln(ch, "SEdit: Insufficient security to modify socials.");
		edit_done(ch);
	}

	if (!str_cmp(argument, "done"))
	{
		edit_done(ch);
		return;
	}

	if (emptystring(argument))
	{
		sedit_show(ch, "");
		return;
	}

	if (!process_olc_command(ch, argument, social_olc_comm_table))
		interpret(ch, argument);
	return;
}

CH_CMD(do_sedit)
{
	SOCIAL_DATA *pSocial;
	char arg1[MAX_INPUT_LENGTH];

	argument = one_argument(argument, arg1);

	if (IS_NPC(ch))
		return;

	if (ch->pcdata->security < 5)
	{
		chprintln(ch, "Insuficient security to edit socials.");
		return;
	}

	if (!str_cmp(arg1, "show"))
	{
		if (IS_NULLSTR(argument))
		{
			chprintln(ch, "Syntax: sedit show [social]");
			return;
		}
		sedit_show(ch, "");
		return;
	}
	if (!str_cmp(arg1, "create"))
	{
		if (IS_NULLSTR(argument))
		{
			chprintln(ch, "Syntax: sedit create [social]");
			return;
		}
		if (sedit_create(ch, argument))
		{
			ch->desc->editor = ED_SOCIAL;
			act("$n has entered the social editor.", ch, NULL, NULL, TO_ROOM);
		}
		return;
	}
	if (!str_cmp(arg1, "delete"))
	{
		if (IS_NULLSTR(argument))
		{
			chprintln(ch, "Syntax: sedit delete [social]");
			return;
		}
		if (sedit_delete(ch, argument))
		{
			return;
		}
	}

	if ((pSocial = get_social_data(arg1)) != NULL)
	{
		edit_start(ch, pSocial, ED_SOCIAL);
		return;
	}
	if (pSocial == NULL && !IS_NULLSTR(arg1))
	{
		chprintln(ch, "That social does not exist.");
		return;
	}

	chprintln(ch, "SEdit: There is no default social to edit.");
	return;
}