/* * CrossFire, A Multiplayer game for X-windows * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team * Copyright (C) 2002 Mark Wedel & Crossfire Development Team * Copyright (C) 1992 Frank Tore Johansen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 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 GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * The author 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; pl->contr->has_hit = 0; /* * remove trailing spaces from commant */ 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, NewServerCommands, NewServerCommandSize); if (!csp) csp = find_command_element (command, Commands, CommandsSize); if (!csp) csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize); if (!csp && QUERY_FLAG (pl, FLAG_WIZ)) csp = find_command_element (command, WizCommands, WizCommandsSize); if (!csp) { new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command); return; } pl->speed_left -= csp->time; csp->func (pl, cp); } } int command_run (object *op, char *params) { int dir; dir = params ? atoi (params) : 0; if (dir < 0 || dir >= 9) { new_draw_info (NDI_UNIQUE, 0, op, "Can't run into a non adjacent square."); return 0; } op->contr->run_on = 1; return move_player (op, dir); } int command_run_stop (object *op, char *params) { op->contr->run_on = 0; return 1; } int command_fire (object *op, char *params) { int dir; dir = params ? atoi (params) : 0; if (dir < 0 || dir >= 9) { new_draw_info (NDI_UNIQUE, 0, op, "Can't fire to a non adjacent square."); return 0; }; op->contr->fire_on = 1; return move_player (op, dir); } int command_fire_stop (object *op, char *params) { op->contr->fire_on = 0; return 1; } int bad_command (object *op, char *params) { new_draw_info (NDI_UNIQUE, 0, op, "bind and unbind are no longer handled on the server"); return 1; }