2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * dispatch.c: Actually execute the command given
29 * Known contributors to this file:
32 * Markus Armbruster, 2007-2011
47 #include "prototypes.h"
51 * Execute command named by player->argp[0].
52 * BUF is the raw UTF-8 command line. It should have been passed to
53 * parse() to set up player->argp.
54 * If REDIR is not null, it's the command's redirection, in UTF-8.
55 * Return -1 if the command is not unique or doesn't exist, else 0.
58 dispatch(char *buf, char *redir)
61 struct cmndstr *command;
64 cmd = comtch(player->argp[0], player_coms, player->nstat);
66 if (cmd == M_NOTUNIQUE)
67 pr("Command \"%s\" is ambiguous -- ", player->argp[0]);
68 else if (cmd == M_IGNORE)
71 pr("\"%s\" is not a legal command\n", player->argp[0]);
74 command = &player_coms[cmd];
75 np = getnatp(player->cnum);
76 if (np->nat_btu < command->c_cost && command->c_cost > 0) {
77 if (player->god || opt_BLITZ)
78 np->nat_btu = max_btus;
80 pr("You don't have the BTU's, bozo\n");
84 if (!command->c_addr) {
85 pr("Command not implemented\n");
88 player->may_sleep = command->c_flags & C_MOD
89 ? PLAYER_SLEEP_ON_INPUT : PLAYER_SLEEP_FREELY;
90 player->command = command;
91 empth_rwlock_rdlock(play_lock);
97 journal_command(command->c_form);
98 switch (command->c_addr()) {
100 player->btused += command->c_cost;
103 pr("command failed\n");
104 player->btused += command->c_cost;
107 pr("Usage: %s\n", command->c_form);
113 empth_rwlock_unlock(play_lock);
114 player->command = NULL;
115 player->may_sleep = PLAYER_SLEEP_FREELY;