#include <ctype.h>
#include <stdio.h>
#include "command.h"
#include "stringops.h"
#include "com_help.h"
#include "com_stim.h"
#include "com_resp.h"
#include "com_player.h"
#include "com_globals.h"
#include "com_group.h"
#include "com_room.h"
#include "com_exit.h"

static char word [128], output[1024];

int command_force (globals *g, player *p, char *l)
{
	#ifdef FUNCTIONS
	puts ("**command_force");
	#endif

	socket_write (g->socket, l);
}

int command (globals *g, player *p, char *line)
{
	#ifdef FUNCTIONS
	puts ("**command");
	#endif

	if (p->command)
	{
		line = tokenize (word, line);

		if (strlen (word) == 0)
		{
			if (p->verbose)
			{
				sprintf (output, "w %s = commands: quit, \
				player, globals, group, stim, resp, force, \
				help, room, exit, move", p->name);
				socket_write (g->socket, output);
			}
			return 0;
		}

		if (!strcasecmp (word, "quit"))
			return 1;
		if (!strcasecmp (word, "player"))
			command_player (g, p, line);
		if (!strcasecmp (word, "globals"))
			command_global (g, p, line);
		if (!strcasecmp (word, "group"))
			command_group (g, p, line);
		if (!strcasecmp (word, "stim"))
			command_stim (g, p, line);
		if (!strcasecmp (word, "resp"))
			command_resp (g, p, line);
		if (!strcasecmp (word, "force"))
			command_force (g, p, line);
		if (!strcasecmp (word, "help"))
			command_help (g, p, line);
		if (!strcasecmp (word, "room"))
			command_room (g, p, line);
		if (!strcasecmp (word, "exit"))
			command_exit (g, p, line);
		if (!strcasecmp (word, "move"))
			command_move (g, line);
	}
	return 0;
}