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.3 by pippijn, Thu Sep 7 10:01:57 2006 UTC vs.
Revision 1.6 by root, Mon Dec 11 02:54:57 2006 UTC

1/*
2 * static char *rcsid_c_new_c =
3 * "$Id: c_new.C,v 1.3 2006/09/07 10:01:57 pippijn Exp $";
4 */
5
6/* 1/*
7 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
8 3
9 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
21 16
22 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 20
26 The author can be reached via e-mail to crossfire-devel@real-time.com 21 The author can be reached via e-mail to <crossfire@schmorp.de>
27*/ 22*/
28 23
29/* This file deals with administrative commands from the client. */ 24/* This file deals with administrative commands from the client. */
30#include <global.h> 25#include <global.h>
31#include <commands.h> 26#include <commands.h>
32#ifndef __CEXTRACT__ 27#ifndef __CEXTRACT__
33#include <sproto.h> 28# include <sproto.h>
34#endif 29#endif
35 30
36#ifndef tolower 31#ifndef tolower
37#define tolower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C)) 32# define tolower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
38#endif 33#endif
39 34
40 35
36static int
41static int compare_A(const void *a, const void *b) 37compare_A (const void *a, const void *b)
42{ 38{
43 return strcmp(((CommArray_s *)a)->name, ((CommArray_s *)b)->name); 39 return strcmp (((CommArray_s *) a)->name, ((CommArray_s *) b)->name);
44} 40}
45 41
42static CommArray_s *
46static CommArray_s *find_command_element(char *cmd, CommArray_s *commarray, 43find_command_element (char *cmd, CommArray_s * commarray, int commsize)
47 int commsize)
48{ 44{
49 CommArray_s *asp, dummy; 45 CommArray_s *asp, dummy;
50 46
51 dummy.name =cmd; 47 dummy.name = cmd;
52 asp =(CommArray_s *)bsearch((void *)&dummy, 48 asp = (CommArray_s *) bsearch ((void *) &dummy, (void *) commarray, commsize, sizeof (CommArray_s), compare_A);
53 (void *)commarray, commsize,
54 sizeof(CommArray_s), compare_A);
55 return asp; 49 return asp;
56} 50}
57 51
58/* This function is called from the new client/server code. 52/* This function is called from the new client/server code.
59 * pl is the player who is issuing the command, command is the 53 * pl is the player who is issuing the command, command is the
60 * command. 54 * command.
61 */ 55 */
56int
62int execute_newserver_command(object *pl, char *command) 57execute_newserver_command (object *pl, char *command)
63{ 58{
64 CommArray_s *csp; 59 CommArray_s *csp;
65 char *cp; 60 char *cp;
66 61
67 pl->contr->has_hit=0; 62 pl->contr->has_hit = 0;
68 63
69 /* 64 /*
70 * remove trailing spaces from commant 65 * remove trailing spaces from commant
71 */ 66 */
72 cp=command+strlen(command)-1; 67 cp = command + strlen (command) - 1;
73 while ( (cp>=command) && (*cp==' ')){ 68 while ((cp >= command) && (*cp == ' '))
69 {
74 *cp='\0'; 70 *cp = '\0';
75 cp--; 71 cp--;
76 } 72 }
77 cp=strchr(command, ' '); 73 cp = strchr (command, ' ');
78 if (cp) { 74 if (cp)
75 {
79 *(cp++) ='\0'; 76 *(cp++) = '\0';
80 while (*cp==' ') cp++; 77 while (*cp == ' ')
78 cp++;
81 } 79 }
82 80
83 csp = find_plugin_command(command,pl); 81 csp = find_plugin_command (command, pl);
84 82
85 if (!csp)
86 csp = find_command_element(command, NewServerCommands, NewServerCommandSize); 83 if (!csp) csp = find_command_element (command, NewServerCommands, NewServerCommandSize);
87 if (!csp)
88 csp = find_command_element(command, Commands, CommandsSize); 84 if (!csp) csp = find_command_element (command, Commands, CommandsSize);
89 if (!csp)
90 csp = find_command_element(command, CommunicationCommands, CommunicationCommandSize); 85 if (!csp) csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize);
91 if (!csp && QUERY_FLAG(pl, FLAG_WIZ)) 86 if (!csp && QUERY_FLAG (pl, FLAG_WIZ))
92 csp = find_command_element(command, WizCommands, WizCommandsSize); 87 csp = find_command_element (command, WizCommands, WizCommandsSize);
93 88
94 if (csp==NULL) { 89 if (csp == NULL)
95 new_draw_info_format(NDI_UNIQUE, 0,pl, 90 {
96 "'%s' is not a valid command.", command); 91 new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command);
97 return 0; 92 return 0;
98 } 93 }
99 94
100 pl->speed_left -= csp->time; 95 pl->speed_left -= csp->time;
101 96
102 /* A character time can never exceed his speed (which in many cases, 97 /* A character time can never exceed his speed (which in many cases,
103 * if wearing armor, is less than one.) Thus, in most cases, if 98 * if wearing armor, is less than one.) Thus, in most cases, if
104 * the command takes 1.0, the player's speed will be less than zero. 99 * the command takes 1.0, the player's speed will be less than zero.
105 * it is only really an issue if time goes below -1 100 * it is only really an issue if time goes below -1
106 * Due to various reasons that are too long to go into here, we will 101 * Due to various reasons that are too long to go into here, we will
107 * actually still execute player even if his time is less than 0, 102 * actually still execute player even if his time is less than 0,
108 * but greater than -1. This is to improve the performance of the 103 * but greater than -1. This is to improve the performance of the
109 * new client/server. In theory, it shouldn't make much difference. 104 * new client/server. In theory, it shouldn't make much difference.
110 */ 105 */
111 106
112 if (csp->time && pl->speed_left<-2.0) { 107 if (csp->time && pl->speed_left < -2.0)
113 LOG(llevDebug,"execute_newclient_command: Player issued command that takes more time than he has left.\n"); 108 LOG (llevDebug, "execute_newclient_command: Player issued command that takes more time than he has left.\n");
114 } 109
115 return csp->func(pl, cp); 110 return csp->func (pl, cp);
116} 111}
117 112
113int
118int command_run(object *op, char *params) 114command_run (object *op, char *params)
119{ 115{
120 int dir; 116 int dir;
117
121 dir = params?atoi(params):0; 118 dir = params ? atoi (params) : 0;
122 if ( dir<0 || dir>=9 ){ 119 if (dir < 0 || dir >= 9)
120 {
123 new_draw_info(NDI_UNIQUE, 0,op,"Can't run into a non adjacent square."); 121 new_draw_info (NDI_UNIQUE, 0, op, "Can't run into a non adjacent square.");
124 return 0; 122 return 0;
125 } 123 }
126 op->contr->run_on=1; 124 op->contr->run_on = 1;
127 return move_player(op, dir); 125 return move_player (op, dir);
128} 126}
129 127
128int
130int command_run_stop(object *op, char *params) 129command_run_stop (object *op, char *params)
131{ 130{
132 op->contr->run_on=0; 131 op->contr->run_on = 0;
133 return 1; 132 return 1;
134} 133}
135 134
135int
136int command_fire(object *op, char *params) 136command_fire (object *op, char *params)
137{ 137{
138 int dir; 138 int dir;
139
139 dir = params?atoi(params):0; 140 dir = params ? atoi (params) : 0;
140 if ( dir<0 || dir>=9 ){ 141 if (dir < 0 || dir >= 9)
142 {
141 new_draw_info(NDI_UNIQUE, 0,op,"Can't fire to a non adjacent square."); 143 new_draw_info (NDI_UNIQUE, 0, op, "Can't fire to a non adjacent square.");
142 return 0; 144 return 0;
143 }; 145 };
144 op->contr->fire_on=1; 146 op->contr->fire_on = 1;
145 return move_player(op, dir); 147 return move_player (op, dir);
146} 148}
147 149
150int
148int command_fire_stop(object *op, char *params) 151command_fire_stop (object *op, char *params)
149{ 152{
150 op->contr->fire_on=0; 153 op->contr->fire_on = 0;
151 return 1; 154 return 1;
152} 155}
153 156
157int
154int bad_command(object *op, char *params) 158bad_command (object *op, char *params)
155{ 159{
156 new_draw_info(NDI_UNIQUE, 0,op,"bind and unbind are no longer handled on the server"); 160 new_draw_info (NDI_UNIQUE, 0, op, "bind and unbind are no longer handled on the server");
157 return 1; 161 return 1;
158} 162}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines