/*
* This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
* Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team
* Copyright (©) 1992 Frank Tore Johansen
*
* Deliantra is free software: you can redistribute it and/or modify it under
* the terms of the Affero GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the Affero GNU General Public License
* and the GNU General Public License along with this program. If not, see
* .
*
* The authors can be reached via e-mail to
*/
/* This file deals with administrative commands from the client. */
#include
#include
#include
static int
compare_A (const void *a, const void *b)
{
return strcmp (((CommArray_s *)a)->name, ((CommArray_s *)b)->name);
}
static CommArray_s *
find_command_element (char *cmd, CommArray_s *commarray, int commsize)
{
CommArray_s *asp, dummy;
dummy.name = cmd;
asp = (CommArray_s *) bsearch ((void *) &dummy, (void *) commarray, commsize, sizeof (CommArray_s), compare_A);
return asp;
}
/* This function is called from the new client/server code.
* pl is the player who is issuing the command, command is the
* command.
*/
void
execute_newserver_command (object *pl, char *command)
{
CommArray_s *csp;
char *cp;
/*
* remove trailing spaces from command
*/
cp = command + strlen (command) - 1;
while ((cp >= command) && (*cp == ' '))
{
*cp = '\0';
cp--;
}
cp = strchr (command, ' ');
if (cp)
{
*(cp++) = '\0';
while (*cp == ' ')
cp++;
}
if (!INVOKE_PLAYER (COMMAND, pl->contr, ARG_STRING (command), ARG_STRING (cp)))
{
csp = find_command_element (command, Commands, CommandsSize);
if (!csp && QUERY_FLAG (pl, FLAG_WIZ))
csp = find_command_element (command, WizCommands, WizCommandsSize);
if (csp)
{
pl->speed_left -= csp->time;
csp->func (pl, cp);
}
else if (!INVOKE_PLAYER (UNKNOWN_COMMAND, pl->contr, ARG_STRING (command), ARG_STRING (cp)))
pl->failmsg (format ("'%s' is not a valid command.", command));
}
}