Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_c_new_c = 00003 * "$Id: c_new.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 CrossFire, A Multiplayer game for X-windows 00008 00009 Copyright (C) 2002-2006 Mark Wedel & Crossfire Development Team 00010 Copyright (C) 1992 Frank Tore Johansen 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 00026 The author can be reached via e-mail to crossfire-devel@real-time.com 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 * remove trailing spaces from commant 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 /* A character time can never exceed his speed (which in many cases, 00143 * if wearing armor, is less than one.) Thus, in most cases, if 00144 * the command takes 1.0, the player's speed will be less than zero. 00145 * it is only really an issue if time goes below -1 00146 * Due to various reasons that are too long to go into here, we will 00147 * actually still execute player even if his time is less than 0, 00148 * but greater than -1. This is to improve the performance of the 00149 * new client/server. In theory, it shouldn't make much difference. 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 }