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.4 by root, Sun Sep 10 15:59:57 2006 UTC

1
1/* 2/*
2 * static char *rcsid_c_new_c = 3 * static char *rcsid_c_new_c =
3 * "$Id: c_new.C,v 1.3 2006/09/07 10:01:57 pippijn Exp $"; 4 * "$Id: c_new.C,v 1.4 2006/09/10 15:59:57 root Exp $";
4 */ 5 */
5 6
6/* 7/*
7 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
8 9
28 29
29/* This file deals with administrative commands from the client. */ 30/* This file deals with administrative commands from the client. */
30#include <global.h> 31#include <global.h>
31#include <commands.h> 32#include <commands.h>
32#ifndef __CEXTRACT__ 33#ifndef __CEXTRACT__
33#include <sproto.h> 34# include <sproto.h>
34#endif 35#endif
35 36
36#ifndef tolower 37#ifndef tolower
37#define tolower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C)) 38# define tolower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
38#endif 39#endif
39 40
40 41
42static int
41static int compare_A(const void *a, const void *b) 43compare_A (const void *a, const void *b)
42{ 44{
43 return strcmp(((CommArray_s *)a)->name, ((CommArray_s *)b)->name); 45 return strcmp (((CommArray_s *) a)->name, ((CommArray_s *) b)->name);
44} 46}
45 47
48static CommArray_s *
46static CommArray_s *find_command_element(char *cmd, CommArray_s *commarray, 49find_command_element (char *cmd, CommArray_s * commarray, int commsize)
47 int commsize)
48{ 50{
49 CommArray_s *asp, dummy; 51 CommArray_s *asp, dummy;
50 52
51 dummy.name =cmd; 53 dummy.name = cmd;
52 asp =(CommArray_s *)bsearch((void *)&dummy, 54 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; 55 return asp;
56} 56}
57 57
58/* This function is called from the new client/server code. 58/* This function is called from the new client/server code.
59 * pl is the player who is issuing the command, command is the 59 * pl is the player who is issuing the command, command is the
60 * command. 60 * command.
61 */ 61 */
62int
62int execute_newserver_command(object *pl, char *command) 63execute_newserver_command (object *pl, char *command)
63{ 64{
64 CommArray_s *csp; 65 CommArray_s *csp;
65 char *cp; 66 char *cp;
66 67
67 pl->contr->has_hit=0; 68 pl->contr->has_hit = 0;
68 69
69 /* 70 /*
70 * remove trailing spaces from commant 71 * remove trailing spaces from commant
71 */ 72 */
72 cp=command+strlen(command)-1; 73 cp = command + strlen (command) - 1;
73 while ( (cp>=command) && (*cp==' ')){ 74 while ((cp >= command) && (*cp == ' '))
75 {
74 *cp='\0'; 76 *cp = '\0';
75 cp--; 77 cp--;
76 } 78 }
77 cp=strchr(command, ' '); 79 cp = strchr (command, ' ');
78 if (cp) { 80 if (cp)
81 {
79 *(cp++) ='\0'; 82 *(cp++) = '\0';
80 while (*cp==' ') cp++; 83 while (*cp == ' ')
84 cp++;
81 } 85 }
82 86
83 csp = find_plugin_command(command,pl); 87 csp = find_plugin_command (command, pl);
84 88
85 if (!csp) 89 if (!csp)
86 csp = find_command_element(command, NewServerCommands, NewServerCommandSize); 90 csp = find_command_element (command, NewServerCommands, NewServerCommandSize);
87 if (!csp) 91 if (!csp)
88 csp = find_command_element(command, Commands, CommandsSize); 92 csp = find_command_element (command, Commands, CommandsSize);
89 if (!csp) 93 if (!csp)
90 csp = find_command_element(command, CommunicationCommands, CommunicationCommandSize); 94 csp = find_command_element (command, CommunicationCommands, CommunicationCommandSize);
91 if (!csp && QUERY_FLAG(pl, FLAG_WIZ)) 95 if (!csp && QUERY_FLAG (pl, FLAG_WIZ))
92 csp = find_command_element(command, WizCommands, WizCommandsSize); 96 csp = find_command_element (command, WizCommands, WizCommandsSize);
93 97
94 if (csp==NULL) { 98 if (csp == NULL)
95 new_draw_info_format(NDI_UNIQUE, 0,pl, 99 {
96 "'%s' is not a valid command.", command); 100 new_draw_info_format (NDI_UNIQUE, 0, pl, "'%s' is not a valid command.", command);
97 return 0; 101 return 0;
98 } 102 }
99 103
100 pl->speed_left -= csp->time; 104 pl->speed_left -= csp->time;
101 105
102 /* A character time can never exceed his speed (which in many cases, 106 /* 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 107 * 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. 108 * 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 109 * 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 110 * 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, 111 * 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 112 * but greater than -1. This is to improve the performance of the
109 * new client/server. In theory, it shouldn't make much difference. 113 * new client/server. In theory, it shouldn't make much difference.
110 */ 114 */
111 115
112 if (csp->time && pl->speed_left<-2.0) { 116 if (csp->time && pl->speed_left < -2.0)
117 {
113 LOG(llevDebug,"execute_newclient_command: Player issued command that takes more time than he has left.\n"); 118 LOG (llevDebug, "execute_newclient_command: Player issued command that takes more time than he has left.\n");
114 } 119 }
115 return csp->func(pl, cp); 120 return csp->func (pl, cp);
116} 121}
117 122
123int
118int command_run(object *op, char *params) 124command_run (object *op, char *params)
119{ 125{
120 int dir; 126 int dir;
127
121 dir = params?atoi(params):0; 128 dir = params ? atoi (params) : 0;
122 if ( dir<0 || dir>=9 ){ 129 if (dir < 0 || dir >= 9)
130 {
123 new_draw_info(NDI_UNIQUE, 0,op,"Can't run into a non adjacent square."); 131 new_draw_info (NDI_UNIQUE, 0, op, "Can't run into a non adjacent square.");
124 return 0; 132 return 0;
125 } 133 }
126 op->contr->run_on=1; 134 op->contr->run_on = 1;
127 return move_player(op, dir); 135 return move_player (op, dir);
128} 136}
129 137
138int
130int command_run_stop(object *op, char *params) 139command_run_stop (object *op, char *params)
131{ 140{
132 op->contr->run_on=0; 141 op->contr->run_on = 0;
133 return 1; 142 return 1;
134} 143}
135 144
145int
136int command_fire(object *op, char *params) 146command_fire (object *op, char *params)
137{ 147{
138 int dir; 148 int dir;
149
139 dir = params?atoi(params):0; 150 dir = params ? atoi (params) : 0;
140 if ( dir<0 || dir>=9 ){ 151 if (dir < 0 || dir >= 9)
152 {
141 new_draw_info(NDI_UNIQUE, 0,op,"Can't fire to a non adjacent square."); 153 new_draw_info (NDI_UNIQUE, 0, op, "Can't fire to a non adjacent square.");
142 return 0; 154 return 0;
143 }; 155 };
144 op->contr->fire_on=1; 156 op->contr->fire_on = 1;
145 return move_player(op, dir); 157 return move_player (op, dir);
146} 158}
147 159
160int
148int command_fire_stop(object *op, char *params) 161command_fire_stop (object *op, char *params)
149{ 162{
150 op->contr->fire_on=0; 163 op->contr->fire_on = 0;
151 return 1; 164 return 1;
152} 165}
153 166
167int
154int bad_command(object *op, char *params) 168bad_command (object *op, char *params)
155{ 169{
156 new_draw_info(NDI_UNIQUE, 0,op,"bind and unbind are no longer handled on the server"); 170 new_draw_info (NDI_UNIQUE, 0, op, "bind and unbind are no longer handled on the server");
157 return 1; 171 return 1;
158} 172}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines