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.5 by root, Thu Sep 14 22:34:03 2006 UTC vs.
Revision 1.8 by root, Tue Dec 12 16:59:35 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) 85 if (!csp)
84 csp = find_command_element (command, NewServerCommands, NewServerCommandSize); 86 {
85 if (!csp) 87 new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command);
86 csp = find_command_element (command, Commands, CommandsSize); 88 return;
87 if (!csp) 89 }
88 csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize);
89 if (!csp && QUERY_FLAG (pl, FLAG_WIZ))
90 csp = find_command_element (command, WizCommands, WizCommandsSize);
91 90
92 if (csp == NULL) 91 pl->speed_left -= csp->time;
93 { 92
94 new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command); 93 csp->func (pl, cp);
95 return 0;
96 } 94 }
97
98 pl->speed_left -= csp->time;
99
100 /* A character time can never exceed his speed (which in many cases,
101 * if wearing armor, is less than one.) Thus, in most cases, if
102 * the command takes 1.0, the player's speed will be less than zero.
103 * it is only really an issue if time goes below -1
104 * Due to various reasons that are too long to go into here, we will
105 * actually still execute player even if his time is less than 0,
106 * but greater than -1. This is to improve the performance of the
107 * new client/server. In theory, it shouldn't make much difference.
108 */
109
110 if (csp->time && pl->speed_left < -2.0)
111 {
112 LOG (llevDebug, "execute_newclient_command: Player issued command that takes more time than he has left.\n");
113 }
114 return csp->func (pl, cp);
115} 95}
116 96
117int 97int
118command_run (object *op, char *params) 98command_run (object *op, char *params)
119{ 99{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines