00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include <global.h>
00035 #include <commands.h>
00036 #ifndef __CEXTRACT__
00037 #include <sproto.h>
00038 #endif
00039
00040 #ifndef tolower
00041
00042 #define tolower(C) (((C) >= 'A' && (C) <= 'Z') ? (C)-'A'+'a' : (C))
00043 #endif
00044
00058 static int compare_A(const void *a, const void *b) {
00059 return strcmp(((const command_array_struct *)a)->name,
00060 ((const command_array_struct *)b)->name);
00061 }
00062
00075 static command_array_struct *find_command_element(const char *cmd, command_array_struct *commarray, int commsize) {
00076 command_array_struct *asp, dummy;
00077
00078 dummy.name = cmd;
00079 asp = (command_array_struct *)bsearch((void *)&dummy,
00080 (void *)commarray, commsize,
00081 sizeof(command_array_struct),
00082 compare_A);
00083 return asp;
00084 }
00085
00098 int execute_newserver_command(object *pl, char *command) {
00099 command_array_struct *csp;
00100 char *cp, *low;
00101
00102 pl->contr->has_hit = 0;
00103
00104
00105
00106
00107 cp = command+strlen(command)-1;
00108 while ((cp >= command) && (*cp == ' ')) {
00109 *cp = '\0';
00110 cp--;
00111 }
00112 cp = strchr(command, ' ');
00113 if (cp) {
00114 *(cp++) = '\0';
00115 while (*cp == ' ')
00116 cp++;
00117 }
00118
00119 for (low = command; *low; low++)
00120 *low = tolower(*low);
00121
00122 csp = find_plugin_command(command, pl);
00123 if (!csp)
00124 csp = find_command_element(command, Commands, CommandsSize);
00125 if (!csp)
00126 csp = find_command_element(command, CommunicationCommands,
00127 CommunicationCommandSize);
00128 if (!csp && QUERY_FLAG(pl, FLAG_WIZ))
00129 csp = find_command_element(command, WizCommands, WizCommandsSize);
00130
00131 if (csp == NULL) {
00132 draw_ext_info_format(NDI_UNIQUE, 0, pl,
00133 MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
00134 "'%s' is not a valid command.",
00135 "'%s' is not a valid command.",
00136 command);
00137 return 0;
00138 }
00139
00140 pl->speed_left -= csp->time;
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 if (csp->time && pl->speed_left < -2.0) {
00153 LOG(llevDebug, "execute_newclient_command: Player issued command that takes more time than he has left.\n");
00154 }
00155 return csp->func(pl, cp);
00156 }
00157
00168 int command_run(object *op, char *params) {
00169 int dir;
00170
00171 dir = params ? atoi(params) : 0;
00172 if (dir < 0 || dir >= 9) {
00173 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
00174 "Can't run into a non adjacent square.", NULL);
00175 return 0;
00176 }
00177 op->contr->run_on = 1;
00178 return move_player(op, dir);
00179 }
00180
00191 int command_run_stop(object *op, char *params) {
00192 op->contr->run_on = 0;
00193 return 1;
00194 }
00195
00206 int command_fire(object *op, char *params) {
00207 int dir;
00208
00209 dir = params ? atoi(params) : 0;
00210 if (dir < 0 || dir >= 9) {
00211 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
00212 "Can't fire to a non adjacent square.", NULL);
00213 return 0;
00214 }
00215 op->contr->fire_on = 1;
00216 return move_player(op, dir);
00217 }
00218
00229 int command_fire_stop(object *op, char *params) {
00230 op->contr->fire_on = 0;
00231 return 1;
00232 }