/* -- Commented so syntax coloring doesn't screw it up.
The code within this file is free for use on any MUD.  Credit would be nice,
but it's not required so long as you don't claim it as your own original work.
Feel free to send questions, comments, flames, and tasty encrypted pies to me
at sparklydemonlord@hotmail.com where I'll likely never see them!

merc.h:
	Somewhere in struct pc_data, add:

	sh_int			chatmode;

save.c:
	Along with the other pcdata values in fwrite_char, add this:

		if (ch->pcdata->chatmode != 0)
			fprintf (fp, "Chatmode %d", ch->pcdata->chatmode);

	In the 'C' case in fread_char, add this line:

                KEY ("Chatmode", ch->pcdata->chatmode, fread_number (fp));

interp.h:
	Wherever you'd like to place it amongst the other command declarations,
	add a new declaration for do_chatmode.

interp.c:
	Add an entry for do_chatmode to the command table.

	Find this in interpret():

	REMOVE_BIT (ch->affected_by, AFF_HIDE);

	And add this below it:

	// IRC mode hack.
	if (!IS_NPC (ch) && ch->pcdata->chatmode != 0)
	{
		if (argument[0] != '/')
		{
			chatmode_interp (ch, ch->pcdata->chatmode, argument);
			return;
		}
		else
			argument++;
	}

Finally, paste the rest of the code in this file into interp.c.  I have it all
just above interpret(), as chatmode_interp() is called there.
*/

/*
 * To add a new chat mode, increase the size of this array, and add a new
 * entry with the syntax to select the mode first, and the command to
 * execute in that mode second.  Make sure the NULL entry is always last.
 */
const char * chatmode_table[12][2] =
{
	{"off",			""},
	{"say",			"say"},
	{"emote",		"emote"},
	{"gossip",		"gossip"},
	{"question",	"question"},
	{"grats",		"grats"},
	{"quote",		"quote"},
	{"music",		"music"},
	{"auction",		"auction"},
	{"clantalk",	"clantalk"},
	{"immtalk",		"immtalk"},
	{NULL,			NULL}
};

// Get a chat mode by name.
int chatmode_lookup (char * argument)
{
	int i;

	/*
	 * If you add more chat modes, do NOT forget to increase the conditional
	 * for this loop!  You may wish to use a #define'd value for the maximum
	 * 
	 */
	for (i = 0; chatmode_table[i][0] != NULL && chatmode_table[i][1]; i++)
		if (   chatmode_table[i][0][0] == argument[0]
			&& !str_prefix (argument, chatmode_table[i][0]))
			return i;

	return -1;
}

/*
 * Player command to select a chat mode.  A sample helpfile is included:
 *
0 CHATMODE~
With chat mode enabled, all text you input that does not begin with a slash (/)
will be sent to the channel you select for your chat mode.  To turn chat mode
on, simply give the channel name as an argument (eg; chatmode gossip).  To turn
chat mode off, use '/chatmode off'.
~
 */
void do_chatmode (CHAR_DATA * ch, char * argument)
{
	int mode;

	if (IS_NPC (ch))
	{
		send_to_char ("NPCs cannot use chat mode.\n\r", ch);
		return;
	}

	if (argument[0] == '\0')
	{
		send_to_char ("Set your chat mode to which channel?\n\r", ch);
		return;
	}

	mode = chatmode_lookup (argument);

	if (mode == -1)
		send_to_char ("No such chat mode.\n\r", ch);
	else
	{
		if (mode == 0)
			send_to_char ("Chat mode disabled.\n\r", ch);
		// Dirty hack to prevent mortals from using immtalk mode.
		else if (mode == chatmode_lookup ("immtalk") && !IS_IMMORTAL (ch))
		{
			send_to_char ("No such chat mode.\n\r", ch);
			return;
		}
		else
			send_to_char ("Chat mode selected.\n\r", ch);

		ch->pcdata->chatmode = mode;
		return;
	}
}

/*
 * This is a very simple function, and I've added no real error checking.
 * It shouldn't be necessary, and if it becomes necessary you're probably
 * an idiot.
 */ 
void chatmode_interp (CHAR_DATA * ch, int mode, char * argument)
{
	char cmdbuf[MAX_INPUT_LENGTH];

	if (IS_NPC (ch))
		return;

	/*
	 * The easiest (though probably not the most efficient) method here is
	 * to spoof the syntax to communicate on the desired medium with sprintf
	 * and interpret() that as a command.  It's done like this because I'm
	 * lazy and didn't want to create a new struct for the chat mode table.
	 */
	sprintf (cmdbuf, "/%s %s", chatmode_table[mode][1], argument);
	interpret (ch, cmdbuf);
}