| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <string.h> |
| 23 |
#include <ctype.h> |
| 24 |
|
| 25 |
#include "commands.h" |
| 26 |
#include "sproto.h" |
| 27 |
|
| 28 |
#ifndef tolower |
| 29 |
|
| 30 |
#define tolower(C) (((C) >= 'A' && (C) <= 'Z') ? (C)-'A'+'a' : (C)) |
| 31 |
#endif |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static int compare_A(const void *a, const void *b) { |
| 47 |
return strcmp(((const command_array_struct *)a)->name, |
| 48 |
((const command_array_struct *)b)->name); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
static command_array_struct *find_command_element(const char *cmd, command_array_struct *commarray, int commsize) { |
| 64 |
command_array_struct *asp, dummy; |
| 65 |
|
| 66 |
dummy.name = cmd; |
| 67 |
asp = (command_array_struct *)bsearch((void *)&dummy, |
| 68 |
(void *)commarray, commsize, |
| 69 |
sizeof(command_array_struct), |
| 70 |
compare_A); |
| 71 |
return asp; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
void execute_newserver_command(object *pl, char *command) { |
| 85 |
command_array_struct *csp, sent; |
| 86 |
char *cp, *low; |
| 87 |
|
| 88 |
pl->contr->has_hit = 0; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
cp = command+strlen(command)-1; |
| 94 |
while ((cp >= command) && (*cp == ' ')) { |
| 95 |
*cp = '\0'; |
| 96 |
cp--; |
| 97 |
} |
| 98 |
cp = strchr(command, ' '); |
| 99 |
if (cp) { |
| 100 |
*(cp++) = '\0'; |
| 101 |
while (*cp == ' ') |
| 102 |
cp++; |
| 103 |
} else { |
| 104 |
cp = strchr(command, '\0'); |
| 105 |
} |
| 106 |
|
| 107 |
for (low = command; *low; low++) |
| 108 |
*low = tolower(*low); |
| 109 |
|
| 110 |
csp = find_plugin_command(command, &sent); |
| 111 |
if (!csp) |
| 112 |
csp = find_command_element(command, Commands, CommandsSize); |
| 113 |
if (!csp) |
| 114 |
csp = find_command_element(command, CommunicationCommands, |
| 115 |
CommunicationCommandSize); |
| 116 |
if (!csp && QUERY_FLAG(pl, FLAG_WIZ)) |
| 117 |
csp = find_command_element(command, WizCommands, WizCommandsSize); |
| 118 |
|
| 119 |
if (csp == NULL) { |
| 120 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, |
| 121 |
MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 122 |
"'%s' is not a valid command.", |
| 123 |
command); |
| 124 |
return; |
| 125 |
} |
| 126 |
|
| 127 |
pl->speed_left -= csp->time; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
if (csp->time && pl->speed_left < -2.0) { |
| 140 |
LOG(llevDebug, "execute_newclient_command: Player issued command that takes more time than he has left.\n"); |
| 141 |
} |
| 142 |
csp->func(pl, cp); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
void command_run(object *op, const char *params) { |
| 154 |
int dir; |
| 155 |
|
| 156 |
dir = atoi(params); |
| 157 |
if (dir < 0 || dir >= 9) { |
| 158 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 159 |
"Can't run into a non adjacent square."); |
| 160 |
return; |
| 161 |
} |
| 162 |
op->contr->run_on = 1; |
| 163 |
move_player(op, dir); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
void command_run_stop(object *op, const char *params) { |
| 177 |
op->contr->run_on = 0; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
void command_fire(object *op, const char *params) { |
| 189 |
int dir; |
| 190 |
|
| 191 |
dir = atoi(params); |
| 192 |
if (dir < 0 || dir >= 9) { |
| 193 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 194 |
"Can't fire to a non adjacent square."); |
| 195 |
return; |
| 196 |
} |
| 197 |
op->contr->fire_on = 1; |
| 198 |
move_player(op, dir); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
void command_fire_stop(object *op, const char *params) { |
| 210 |
op->contr->fire_on = 0; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
void command_face(object *op, const char *params) { |
| 222 |
int dir; |
| 223 |
|
| 224 |
if ( !isdigit(*params) ) { |
| 225 |
if ( strcmp(params,"stay") == 0 || strcmp(params,"down") == 0 ) dir=0; |
| 226 |
else if ( strcmp(params,"north") == 0 || strcmp(params,"n") == 0 ) dir=1; |
| 227 |
else if ( strcmp(params,"northeast") == 0 || strcmp(params,"ne") == 0 ) dir=2; |
| 228 |
else if ( strcmp(params,"east") == 0 || strcmp(params,"e") == 0 ) dir=3; |
| 229 |
else if ( strcmp(params,"southeast") == 0 || strcmp(params,"se") == 0 ) dir=4; |
| 230 |
else if ( strcmp(params,"south") == 0 || strcmp(params,"s") == 0 ) dir=5; |
| 231 |
else if ( strcmp(params,"southwest") == 0 || strcmp(params,"sw") == 0 ) dir=6; |
| 232 |
else if ( strcmp(params,"west") == 0 || strcmp(params,"w") == 0 ) dir=7; |
| 233 |
else if ( strcmp(params,"northwest") == 0 || strcmp(params,"nw") == 0 ) dir=8; |
| 234 |
else { |
| 235 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 236 |
"Unknown direction to face: %s",params); |
| 237 |
return; |
| 238 |
} |
| 239 |
} |
| 240 |
else dir = atoi(params); |
| 241 |
if (dir < 0 || dir >= 9) { |
| 242 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 243 |
"Can't face to a non adjacent square."); |
| 244 |
return; |
| 245 |
} |
| 246 |
face_player(op, dir); |
| 247 |
} |