… | |
… | |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* This file deals with administrative commands from the client. */ |
24 | /* This file deals with administrative commands from the client. */ |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <commands.h> |
26 | #include <commands.h> |
27 | #ifndef __CEXTRACT__ |
|
|
28 | # include <sproto.h> |
27 | #include <sproto.h> |
29 | #endif |
|
|
30 | |
|
|
31 | #ifndef tolower |
|
|
32 | # define tolower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C)) |
|
|
33 | #endif |
|
|
34 | |
|
|
35 | |
28 | |
36 | static int |
29 | static int |
37 | compare_A (const void *a, const void *b) |
30 | compare_A (const void *a, const void *b) |
38 | { |
31 | { |
39 | return strcmp (((CommArray_s *) a)->name, ((CommArray_s *) b)->name); |
32 | return strcmp (((CommArray_s *)a)->name, ((CommArray_s *)b)->name); |
40 | } |
33 | } |
41 | |
34 | |
42 | static CommArray_s * |
35 | static CommArray_s * |
43 | find_command_element (char *cmd, CommArray_s * commarray, int commsize) |
36 | find_command_element (char *cmd, CommArray_s *commarray, int commsize) |
44 | { |
37 | { |
45 | CommArray_s *asp, dummy; |
38 | CommArray_s *asp, dummy; |
46 | |
39 | |
47 | dummy.name = cmd; |
40 | dummy.name = cmd; |
48 | asp = (CommArray_s *) bsearch ((void *) &dummy, (void *) commarray, commsize, sizeof (CommArray_s), compare_A); |
41 | asp = (CommArray_s *) bsearch ((void *) &dummy, (void *) commarray, commsize, sizeof (CommArray_s), compare_A); |
… | |
… | |
51 | |
44 | |
52 | /* This function is called from the new client/server code. |
45 | /* This function is called from the new client/server code. |
53 | * pl is the player who is issuing the command, command is the |
46 | * pl is the player who is issuing the command, command is the |
54 | * command. |
47 | * command. |
55 | */ |
48 | */ |
56 | int |
49 | void |
57 | execute_newserver_command (object *pl, char *command) |
50 | execute_newserver_command (object *pl, char *command) |
58 | { |
51 | { |
59 | CommArray_s *csp; |
52 | CommArray_s *csp; |
60 | char *cp; |
53 | char *cp; |
61 | |
54 | |
… | |
… | |
68 | while ((cp >= command) && (*cp == ' ')) |
61 | while ((cp >= command) && (*cp == ' ')) |
69 | { |
62 | { |
70 | *cp = '\0'; |
63 | *cp = '\0'; |
71 | cp--; |
64 | cp--; |
72 | } |
65 | } |
|
|
66 | |
73 | cp = strchr (command, ' '); |
67 | cp = strchr (command, ' '); |
74 | if (cp) |
68 | if (cp) |
75 | { |
69 | { |
76 | *(cp++) = '\0'; |
70 | *(cp++) = '\0'; |
77 | while (*cp == ' ') |
71 | while (*cp == ' ') |
78 | cp++; |
72 | cp++; |
79 | } |
73 | } |
80 | |
74 | |
81 | csp = find_plugin_command (command, pl); |
75 | if (!INVOKE_PLAYER (COMMAND, pl->contr, ARG_STRING (command), ARG_STRING (cp))) |
|
|
76 | { |
|
|
77 | csp = find_command_element (command, NewServerCommands, NewServerCommandSize); |
|
|
78 | if (!csp) csp = find_command_element (command, Commands, CommandsSize); |
|
|
79 | if (!csp) csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize); |
|
|
80 | if (!csp && QUERY_FLAG (pl, FLAG_WIZ)) |
|
|
81 | csp = find_command_element (command, WizCommands, WizCommandsSize); |
82 | |
82 | |
83 | if (!csp) csp = find_command_element (command, NewServerCommands, NewServerCommandSize); |
83 | if (!csp) |
84 | if (!csp) csp = find_command_element (command, Commands, CommandsSize); |
84 | { |
85 | if (!csp) csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize); |
85 | new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command); |
86 | if (!csp && QUERY_FLAG (pl, FLAG_WIZ)) |
86 | return; |
87 | csp = find_command_element (command, WizCommands, WizCommandsSize); |
87 | } |
88 | |
88 | |
89 | if (csp == NULL) |
89 | pl->speed_left -= csp->time; |
90 | { |
90 | |
91 | new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command); |
91 | csp->func (pl, cp); |
92 | return 0; |
|
|
93 | } |
92 | } |
94 | |
|
|
95 | pl->speed_left -= csp->time; |
|
|
96 | |
|
|
97 | /* A character time can never exceed his speed (which in many cases, |
|
|
98 | * if wearing armor, is less than one.) Thus, in most cases, if |
|
|
99 | * the command takes 1.0, the player's speed will be less than zero. |
|
|
100 | * it is only really an issue if time goes below -1 |
|
|
101 | * Due to various reasons that are too long to go into here, we will |
|
|
102 | * actually still execute player even if his time is less than 0, |
|
|
103 | * but greater than -1. This is to improve the performance of the |
|
|
104 | * new client/server. In theory, it shouldn't make much difference. |
|
|
105 | */ |
|
|
106 | |
|
|
107 | if (csp->time && pl->speed_left < -2.0) |
|
|
108 | LOG (llevDebug, "execute_newclient_command: Player issued command that takes more time than he has left.\n"); |
|
|
109 | |
|
|
110 | return csp->func (pl, cp); |
|
|
111 | } |
93 | } |
112 | |
94 | |
113 | int |
95 | int |
114 | command_run (object *op, char *params) |
96 | command_run (object *op, char *params) |
115 | { |
97 | { |