ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_new.C
(Generate patch)

Comparing deliantra/server/server/c_new.C (file contents):
Revision 1.6 by root, Mon Dec 11 02:54:57 2006 UTC vs.
Revision 1.7 by root, Mon Dec 11 22:56:57 2006 UTC

26#include <commands.h> 26#include <commands.h>
27#ifndef __CEXTRACT__ 27#ifndef __CEXTRACT__
28# include <sproto.h> 28# include <sproto.h>
29#endif 29#endif
30 30
31#ifndef tolower
32# define tolower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
33#endif
34
35
36static int 31static int
37compare_A (const void *a, const void *b) 32compare_A (const void *a, const void *b)
38{ 33{
39 return strcmp (((CommArray_s *) a)->name, ((CommArray_s *) b)->name); 34 return strcmp (((CommArray_s *)a)->name, ((CommArray_s *)b)->name);
40} 35}
41 36
42static CommArray_s * 37static CommArray_s *
43find_command_element (char *cmd, CommArray_s * commarray, int commsize) 38find_command_element (char *cmd, CommArray_s *commarray, int commsize)
44{ 39{
45 CommArray_s *asp, dummy; 40 CommArray_s *asp, dummy;
46 41
47 dummy.name = cmd; 42 dummy.name = cmd;
48 asp = (CommArray_s *) bsearch ((void *) &dummy, (void *) commarray, commsize, sizeof (CommArray_s), compare_A); 43 asp = (CommArray_s *) bsearch ((void *) &dummy, (void *) commarray, commsize, sizeof (CommArray_s), compare_A);
51 46
52/* This function is called from the new client/server code. 47/* This function is called from the new client/server code.
53 * pl is the player who is issuing the command, command is the 48 * pl is the player who is issuing the command, command is the
54 * command. 49 * command.
55 */ 50 */
56int 51void
57execute_newserver_command (object *pl, char *command) 52execute_newserver_command (object *pl, char *command)
58{ 53{
59 CommArray_s *csp; 54 CommArray_s *csp;
60 char *cp; 55 char *cp;
61 56
68 while ((cp >= command) && (*cp == ' ')) 63 while ((cp >= command) && (*cp == ' '))
69 { 64 {
70 *cp = '\0'; 65 *cp = '\0';
71 cp--; 66 cp--;
72 } 67 }
68
73 cp = strchr (command, ' '); 69 cp = strchr (command, ' ');
74 if (cp) 70 if (cp)
75 { 71 {
76 *(cp++) = '\0'; 72 *(cp++) = '\0';
77 while (*cp == ' ') 73 while (*cp == ' ')
78 cp++; 74 cp++;
79 } 75 }
80 76
81 csp = find_plugin_command (command, pl); 77 if (!INVOKE_PLAYER (COMMAND, pl->contr, ARG_STRING (command), ARG_STRING (cp)))
78 {
79 csp = find_command_element (command, NewServerCommands, NewServerCommandSize);
80 if (!csp) csp = find_command_element (command, Commands, CommandsSize);
81 if (!csp) csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize);
82 if (!csp && QUERY_FLAG (pl, FLAG_WIZ))
83 csp = find_command_element (command, WizCommands, WizCommandsSize);
82 84
83 if (!csp) csp = find_command_element (command, NewServerCommands, NewServerCommandSize); 85 if (!csp)
84 if (!csp) csp = find_command_element (command, Commands, CommandsSize); 86 {
85 if (!csp) csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize); 87 new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command);
86 if (!csp && QUERY_FLAG (pl, FLAG_WIZ)) 88 return;
87 csp = find_command_element (command, WizCommands, WizCommandsSize); 89 }
88 90
89 if (csp == NULL) 91 pl->speed_left -= csp->time;
90 { 92
91 new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command); 93 csp->func (pl, cp);
92 return 0;
93 } 94 }
94
95 pl->speed_left -= csp->time;
96 95
97 /* A character time can never exceed his speed (which in many cases, 96 /* 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 97 * 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. 98 * 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 99 * it is only really an issue if time goes below -1
104 * new client/server. In theory, it shouldn't make much difference. 103 * new client/server. In theory, it shouldn't make much difference.
105 */ 104 */
106 105
107 if (csp->time && pl->speed_left < -2.0) 106 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"); 107 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} 108}
112 109
113int 110int
114command_run (object *op, char *params) 111command_run (object *op, char *params)
115{ 112{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines