|
|
1 | |
1 | /* |
2 | /* |
2 | * static char *rcsid_init_c = |
3 | * static char *rcsid_init_c = |
3 | * "$Id: request.C,v 1.6 2006/08/19 03:54:23 root Exp $"; |
4 | * "$Id: request.C,v 1.17 2006/09/12 19:20:09 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 | |
… | |
… | |
64 | #include <commands.h> |
65 | #include <commands.h> |
65 | |
66 | |
66 | /* This block is basically taken from socket.c - I assume if it works there, |
67 | /* This block is basically taken from socket.c - I assume if it works there, |
67 | * it should work here. |
68 | * it should work here. |
68 | */ |
69 | */ |
69 | #ifndef WIN32 /* ---win32 exclude unix headers */ |
70 | #ifndef WIN32 /* ---win32 exclude unix headers */ |
70 | #include <sys/types.h> |
71 | # include <sys/types.h> |
71 | #include <sys/time.h> |
72 | # include <sys/time.h> |
72 | #include <sys/socket.h> |
73 | # include <sys/socket.h> |
73 | #include <netinet/in.h> |
74 | # include <netinet/in.h> |
74 | #include <netdb.h> |
75 | # include <netdb.h> |
75 | #endif /* win32 */ |
76 | #endif /* win32 */ |
76 | |
77 | |
77 | #ifdef HAVE_UNISTD_H |
78 | #ifdef HAVE_UNISTD_H |
78 | #include <unistd.h> |
79 | # include <unistd.h> |
79 | #endif |
80 | #endif |
80 | |
81 | |
81 | #ifdef HAVE_SYS_TIME_H |
82 | #ifdef HAVE_SYS_TIME_H |
82 | #include <sys/time.h> |
83 | # include <sys/time.h> |
83 | #endif |
84 | #endif |
84 | |
85 | |
85 | #include "sounds.h" |
86 | #include "sounds.h" |
86 | |
87 | |
87 | /** |
88 | /** |
88 | * This table translates the attack numbers as used within the |
89 | * This table translates the attack numbers as used within the |
89 | * program to the value we use when sending STATS command to the |
90 | * program to the value we use when sending STATS command to the |
90 | * client. If a value is -1, then we don't send that to the |
91 | * client. If a value is -1, then we don't send that to the |
91 | * client. |
92 | * client. |
92 | */ |
93 | */ |
93 | short atnr_cs_stat[NROFATTACKS] = {CS_STAT_RES_PHYS, |
94 | short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, |
94 | CS_STAT_RES_MAG,CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, |
95 | CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, |
95 | CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, |
96 | CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, |
96 | CS_STAT_RES_DRAIN, -1 /* weaponmagic */, |
97 | CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , |
97 | CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, |
98 | CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, |
98 | CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, |
99 | CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, |
99 | CS_STAT_RES_FEAR, -1 /* Cancellation */, |
100 | CS_STAT_RES_FEAR, -1 /* Cancellation */ , |
100 | CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, |
101 | CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, |
101 | -1 /* Chaos */, -1 /* Counterspell */, |
102 | -1 /* Chaos */ , -1 /* Counterspell */ , |
102 | -1 /* Godpower */, CS_STAT_RES_HOLYWORD, |
103 | -1 /* Godpower */ , CS_STAT_RES_HOLYWORD, |
103 | CS_STAT_RES_BLIND, |
104 | CS_STAT_RES_BLIND, |
104 | -1, /* Internal */ |
105 | -1, /* Internal */ |
105 | -1, /* life stealing */ |
106 | -1, /* life stealing */ |
106 | -1 /* Disease - not fully done yet */ |
107 | -1 /* Disease - not fully done yet */ |
107 | }; |
108 | }; |
108 | |
109 | |
109 | static void |
110 | static void |
110 | socket_map_scroll (NewSocket *ns, int dx, int dy) |
111 | socket_map_scroll (NewSocket * ns, int dx, int dy) |
111 | { |
112 | { |
112 | struct Map newmap; |
113 | struct Map newmap; |
113 | int x,y, mx, my; |
114 | int x, y, mx, my; |
114 | |
115 | |
115 | { |
116 | { |
116 | char buf[MAXSOCKBUF]; |
117 | char buf[MAXSOCKBUF]; |
117 | |
118 | |
118 | sprintf(buf,"map_scroll %d %d", dx, dy); |
119 | sprintf (buf, "map_scroll %d %d", dx, dy); |
119 | Write_String_To_Socket(ns, buf, strlen (buf)); |
120 | Write_String_To_Socket (ns, buf, strlen (buf)); |
120 | } |
121 | } |
121 | |
122 | |
122 | /* If we are using the Map1aCmd, we may in fact send |
123 | /* If we are using the Map1aCmd, we may in fact send |
123 | * head information that is outside the viewable map. |
124 | * head information that is outside the viewable map. |
124 | * So set the mx,my to the max value we want to |
125 | * So set the mx,my to the max value we want to |
125 | * look for. Removed code to do so - it caused extra |
126 | * look for. Removed code to do so - it caused extra |
126 | * complexities for the client, and probably doesn't make |
127 | * complexities for the client, and probably doesn't make |
127 | * that much difference in bandwidth. |
128 | * that much difference in bandwidth. |
128 | */ |
129 | */ |
129 | mx = ns->mapx; |
130 | mx = ns->mapx; |
130 | my = ns->mapy; |
131 | my = ns->mapy; |
131 | |
132 | |
132 | if (ns->mapmode == Map1aCmd) { |
133 | if (ns->mapmode == Map1aCmd) |
|
|
134 | { |
133 | mx += MAX_HEAD_OFFSET; |
135 | mx += MAX_HEAD_OFFSET; |
134 | my += MAX_HEAD_OFFSET; |
136 | my += MAX_HEAD_OFFSET; |
135 | } |
137 | } |
136 | |
138 | |
137 | /* the x and y here are coordinates for the new map, i.e. if we moved |
139 | /* the x and y here are coordinates for the new map, i.e. if we moved |
138 | * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, |
140 | * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, |
139 | * if the destination x or y coordinate is outside the viewable |
141 | * if the destination x or y coordinate is outside the viewable |
140 | * area, we clear the values - otherwise, the old values |
142 | * area, we clear the values - otherwise, the old values |
141 | * are preserved, and the check_head thinks it needs to clear them. |
143 | * are preserved, and the check_head thinks it needs to clear them. |
142 | */ |
144 | */ |
143 | for(x=0; x<mx; x++) { |
145 | for (x = 0; x < mx; x++) |
144 | for(y=0; y<my; y++) { |
146 | { |
|
|
147 | for (y = 0; y < my; y++) |
|
|
148 | { |
145 | if(x >= ns->mapx || y >= ns->mapy) { |
149 | if (x >= ns->mapx || y >= ns->mapy) |
|
|
150 | { |
146 | /* clear cells outside the viewable area */ |
151 | /* clear cells outside the viewable area */ |
147 | memset(&newmap.cells[x][y], 0, sizeof(struct MapCell)); |
152 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
148 | } |
153 | } |
149 | else if ((x+dx) < 0 || (x+dx) >= ns->mapx || (y+dy) < 0 || (y + dy) >= ns->mapy) { |
154 | else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) |
|
|
155 | { |
150 | /* clear newly visible tiles within the viewable area */ |
156 | /* clear newly visible tiles within the viewable area */ |
151 | memset(&(newmap.cells[x][y]), 0, sizeof(struct MapCell)); |
157 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
|
|
158 | } |
|
|
159 | else |
|
|
160 | { |
|
|
161 | memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); |
|
|
162 | } |
|
|
163 | } |
152 | } |
164 | } |
153 | else { |
|
|
154 | memcpy(&(newmap.cells[x][y]), |
|
|
155 | &(ns->lastmap.cells[x+dx][y+dy]),sizeof(struct MapCell)); |
|
|
156 | } |
|
|
157 | } |
|
|
158 | } |
|
|
159 | |
165 | |
160 | memcpy(&(ns->lastmap), &newmap,sizeof(struct Map)); |
166 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
161 | |
167 | |
162 | /* Make sure that the next "map1" command will be sent (even if it is |
168 | /* Make sure that the next "map1" command will be sent (even if it is |
163 | * empty). |
169 | * empty). |
164 | */ |
170 | */ |
165 | ns->sent_scroll = 1; |
171 | ns->sent_scroll = 1; |
|
|
172 | } |
|
|
173 | |
|
|
174 | static void |
|
|
175 | clear_map (player *pl) |
|
|
176 | { |
|
|
177 | NewSocket & socket = pl->socket; |
|
|
178 | |
|
|
179 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
|
|
180 | |
|
|
181 | if (socket.newmapcmd == 1) |
|
|
182 | Write_String_To_Socket (&socket, "newmap", 6); |
|
|
183 | |
|
|
184 | socket.update_look = 1; |
|
|
185 | socket.look_position = 0; |
166 | } |
186 | } |
167 | |
187 | |
168 | /** check for map change and send new map data */ |
188 | /** check for map change and send new map data */ |
169 | static void |
189 | static void |
170 | check_map_change (player *pl) |
190 | check_map_change (player *pl) |
171 | { |
191 | { |
172 | NewSocket &socket = pl->socket; |
192 | NewSocket & socket = pl->socket; |
173 | object *ob = pl->ob; |
193 | object *ob = pl->ob; |
174 | char buf[MAX_BUF]; /* eauugggh */ |
194 | char buf[MAX_BUF]; /* eauugggh */ |
175 | |
195 | |
176 | if (socket.current_map != ob->map) |
196 | if (socket.current_map != ob->map) |
177 | { |
197 | { |
178 | socket.current_map = ob->map; |
198 | socket.current_map = ob->map; |
179 | memset (&socket.lastmap, 0, sizeof(socket.lastmap)); |
|
|
180 | |
199 | |
181 | if (socket.newmapcmd == 1) |
200 | clear_map (pl); |
182 | Write_String_To_Socket (&socket, "newmap", 6); |
|
|
183 | |
|
|
184 | socket.update_look = 1; |
|
|
185 | socket.look_position =0; |
|
|
186 | |
201 | |
187 | if (socket.mapinfocmd) |
202 | if (socket.mapinfocmd) |
188 | { |
203 | { |
189 | if (ob->map && ob->map->path [0]) |
204 | if (ob->map && ob->map->path[0]) |
190 | { |
205 | { |
191 | int flags = 0; |
206 | int flags = 0; |
192 | |
207 | |
193 | if (ob->map->tile_path [0]) flags |= 1; |
208 | if (ob->map->tile_path[0]) |
|
|
209 | flags |= 1; |
194 | if (ob->map->tile_path [1]) flags |= 2; |
210 | if (ob->map->tile_path[1]) |
|
|
211 | flags |= 2; |
195 | if (ob->map->tile_path [2]) flags |= 4; |
212 | if (ob->map->tile_path[2]) |
|
|
213 | flags |= 4; |
196 | if (ob->map->tile_path [3]) flags |= 8; |
214 | if (ob->map->tile_path[3]) |
|
|
215 | flags |= 8; |
197 | |
216 | |
198 | snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s", |
217 | snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s", |
199 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, |
218 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, ob->map->width, ob->map->height, ob->map->path); |
200 | ob->map->width, ob->map->height, ob->map->path); |
|
|
201 | } |
219 | } |
202 | else |
220 | else |
203 | snprintf (buf, MAX_BUF, "mapinfo current"); |
221 | snprintf (buf, MAX_BUF, "mapinfo current"); |
204 | |
222 | |
205 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
223 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
206 | } |
224 | } |
207 | } |
225 | } |
208 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
226 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
209 | { |
227 | { |
|
|
228 | int dx = ob->x - socket.current_x; |
|
|
229 | int dy = ob->y - socket.current_y; |
|
|
230 | |
|
|
231 | if (socket.buggy_mapscroll && (abs (dx) > 8 || abs (dy) > 8)) |
|
|
232 | clear_map (pl); // current (<= 1.9.1) clients have unchecked buffer overflows |
|
|
233 | else |
|
|
234 | { |
210 | socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); |
235 | socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); |
211 | socket.update_look = 1; |
236 | socket.update_look = 1; |
212 | socket.look_position = 0; |
237 | socket.look_position = 0; |
|
|
238 | } |
213 | } |
239 | } |
214 | |
240 | |
215 | socket.current_x = ob->x; |
241 | socket.current_x = ob->x; |
216 | socket.current_y = ob->y; |
242 | socket.current_y = ob->y; |
217 | } |
243 | } |
218 | |
244 | |
|
|
245 | void |
219 | void ExtCmd (char *buf, int len, player *pl) |
246 | ExtCmd (char *buf, int len, player *pl) |
220 | { |
247 | { |
221 | execute_global_event (EVENT_EXTCMD, pl, buf, len); |
248 | INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len)); |
222 | } |
249 | } |
223 | |
250 | |
|
|
251 | void |
224 | void MapInfoCmd (char *buf, int len, player *pl) |
252 | MapInfoCmd (char *buf, int len, player *pl) |
225 | { |
253 | { |
226 | // <mapinfo tag spatial tile-path |
254 | // <mapinfo tag spatial tile-path |
227 | // >mapinfo tag spatial flags x y w h hash |
255 | // >mapinfo tag spatial flags x y w h hash |
228 | |
256 | |
229 | char bigbuf[MAX_BUF], *cp, *token; |
257 | char bigbuf[MAX_BUF], *token; |
230 | |
258 | |
231 | token = buf; |
259 | token = buf; |
232 | // copy token |
260 | // copy token |
233 | if (!(buf = strchr (buf, ' '))) |
261 | if (!(buf = strchr (buf, ' '))) |
234 | return; |
262 | return; |
… | |
… | |
242 | // initial map and its origin |
270 | // initial map and its origin |
243 | mapstruct *map = pl->ob->map; |
271 | mapstruct *map = pl->ob->map; |
244 | sint16 dx, dy; |
272 | sint16 dx, dy; |
245 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
273 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
246 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
274 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
247 | int max_distance = 8; // limit maximum path length to something generous |
275 | int max_distance = 8; // limit maximum path length to something generous |
248 | |
276 | |
249 | while (*buf && map && max_distance) |
277 | while (*buf && map && max_distance) |
250 | { |
278 | { |
251 | int dir = *buf++; |
279 | int dir = *buf++; |
252 | |
280 | |
253 | switch (dir) |
281 | switch (dir) |
254 | { |
282 | { |
255 | case '1': |
283 | case '1': |
|
|
284 | dx = 0; |
|
|
285 | dy = -1; |
256 | dx = 0; dy = -1; map = get_map_from_coord (map, &dx, &dy); |
286 | map = get_map_from_coord (map, &dx, &dy); |
257 | map && (mapy -= map->height); |
287 | map && (mapy -= map->height); |
258 | break; |
288 | break; |
259 | case '2': |
289 | case '2': |
260 | mapx += map->width; |
290 | mapx += map->width; |
|
|
291 | dx = map->width; |
|
|
292 | dy = 0; |
261 | dx = map->width; dy = 0; map = get_map_from_coord (map, &dx, &dy); |
293 | map = get_map_from_coord (map, &dx, &dy); |
262 | break; |
294 | break; |
263 | case '3': |
295 | case '3': |
264 | mapy += map->height; |
296 | mapy += map->height; |
|
|
297 | dx = 0; |
|
|
298 | dy = map->height; |
265 | dx = 0; dy = map->height; map = get_map_from_coord (map, &dx, &dy); |
299 | map = get_map_from_coord (map, &dx, &dy); |
266 | break; |
300 | break; |
267 | case '4': |
301 | case '4': |
|
|
302 | dx = -1; |
|
|
303 | dy = 0; |
268 | dx = -1; dy = 0; map = get_map_from_coord (map, &dx, &dy); |
304 | map = get_map_from_coord (map, &dx, &dy); |
269 | map && (mapx -= map->width); |
305 | map && (mapx -= map->width); |
270 | break; |
306 | break; |
271 | } |
307 | } |
272 | |
308 | |
273 | --max_distance; |
309 | --max_distance; |
274 | } |
310 | } |
275 | |
311 | |
276 | if (!max_distance) |
312 | if (!max_distance) |
277 | snprintf (bigbuf, MAX_BUF, "mapinfo %s error", token); |
313 | snprintf (bigbuf, MAX_BUF, "mapinfo %s error", token); |
278 | else if (map && map->path [0]) |
314 | else if (map && map->path[0]) |
279 | { |
315 | { |
280 | int flags = 0; |
316 | int flags = 0; |
281 | |
317 | |
282 | if (map->tile_path [0]) flags |= 1; |
318 | if (map->tile_path[0]) |
|
|
319 | flags |= 1; |
283 | if (map->tile_path [1]) flags |= 2; |
320 | if (map->tile_path[1]) |
|
|
321 | flags |= 2; |
284 | if (map->tile_path [2]) flags |= 4; |
322 | if (map->tile_path[2]) |
|
|
323 | flags |= 4; |
285 | if (map->tile_path [3]) flags |= 8; |
324 | if (map->tile_path[3]) |
|
|
325 | flags |= 8; |
286 | |
326 | |
287 | snprintf (bigbuf, MAX_BUF, "mapinfo %s spatial %d %d %d %d %d %s", |
327 | snprintf (bigbuf, MAX_BUF, "mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, map->path); |
288 | token, flags, mapx, mapy, |
|
|
289 | map->width, map->height, map->path); |
|
|
290 | } |
328 | } |
291 | else |
329 | else |
292 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
330 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
293 | } |
331 | } |
294 | else |
332 | else |
295 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
333 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
296 | |
334 | |
297 | Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); |
335 | Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); |
298 | } |
336 | } |
299 | |
337 | |
300 | /** This is the Setup cmd - easy first implementation */ |
338 | /** This is the Setup cmd - easy first implementation */ |
|
|
339 | void |
301 | void SetUp(char *buf, int len, NewSocket *ns) |
340 | SetUp (char *buf, int len, NewSocket * ns) |
302 | { |
341 | { |
303 | int s, slen; |
342 | int s, slen; |
304 | char *cmd, *param, cmdback[HUGE_BUF]; |
343 | char *cmd, *param, cmdback[HUGE_BUF]; |
305 | |
344 | |
306 | /* run through the cmds of setup |
345 | /* run through the cmds of setup |
307 | * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
346 | * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
308 | * |
347 | * |
309 | * we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
348 | * we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
310 | * The client then must sort this out |
349 | * The client then must sort this out |
311 | */ |
350 | */ |
312 | |
351 | |
313 | LOG(llevInfo,"Get SetupCmd:: %s\n", buf); |
352 | LOG (llevInfo, "Get SetupCmd:: %s\n", buf); |
314 | strcpy(cmdback,"setup"); |
353 | strcpy (cmdback, "setup"); |
315 | for(s=0;s<len; ) { |
354 | for (s = 0; s < len;) |
|
|
355 | { |
316 | |
356 | |
317 | cmd = &buf[s]; |
357 | cmd = &buf[s]; |
318 | |
358 | |
319 | /* find the next space, and put a null there */ |
359 | /* find the next space, and put a null there */ |
320 | for(;buf[s] && buf[s] != ' ';s++) ; |
360 | for (; buf[s] && buf[s] != ' '; s++); |
321 | buf[s++]=0; |
361 | buf[s++] = 0; |
322 | while (buf[s] == ' ') s++; |
362 | while (buf[s] == ' ') |
|
|
363 | s++; |
323 | |
364 | |
324 | if(s>=len) |
365 | if (s >= len) |
325 | break; |
366 | break; |
326 | |
367 | |
327 | param = &buf[s]; |
368 | param = &buf[s]; |
328 | |
369 | |
329 | for(;buf[s] && buf[s] != ' ';s++) ; |
370 | for (; buf[s] && buf[s] != ' '; s++); |
330 | buf[s++]=0; |
371 | buf[s++] = 0; |
331 | while (buf[s] == ' ') s++; |
372 | while (buf[s] == ' ') |
332 | |
373 | s++; |
|
|
374 | |
333 | slen = strlen(cmdback); |
375 | slen = strlen (cmdback); |
334 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
376 | safe_strcat (cmdback, " ", &slen, HUGE_BUF); |
335 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
377 | safe_strcat (cmdback, cmd, &slen, HUGE_BUF); |
336 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
378 | safe_strcat (cmdback, " ", &slen, HUGE_BUF); |
337 | |
379 | |
338 | if (!strcmp(cmd,"sound")) { |
380 | if (!strcmp (cmd, "sound")) |
|
|
381 | { |
339 | ns->sound = atoi(param); |
382 | ns->sound = atoi (param); |
340 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
383 | safe_strcat (cmdback, param, &slen, HUGE_BUF); |
341 | } |
384 | } |
342 | else if (!strcmp(cmd,"exp64")) { |
385 | else if (!strcmp (cmd, "exp64")) |
|
|
386 | { |
343 | ns->exp64 = atoi(param); |
387 | ns->exp64 = atoi (param); |
344 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
388 | safe_strcat (cmdback, param, &slen, HUGE_BUF); |
|
|
389 | } |
345 | } else if (!strcmp(cmd, "spellmon")) { |
390 | else if (!strcmp (cmd, "spellmon")) |
|
|
391 | { |
346 | ns->monitor_spells = atoi(param); |
392 | ns->monitor_spells = atoi (param); |
347 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
393 | safe_strcat (cmdback, param, &slen, HUGE_BUF); |
|
|
394 | } |
348 | } else if (!strcmp(cmd,"darkness")) { |
395 | else if (!strcmp (cmd, "darkness")) |
|
|
396 | { |
349 | ns->darkness = atoi(param); |
397 | ns->darkness = atoi (param); |
350 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
398 | safe_strcat (cmdback, param, &slen, HUGE_BUF); |
|
|
399 | } |
351 | } else if (!strcmp(cmd,"map1cmd")) { |
400 | else if (!strcmp (cmd, "map1cmd")) |
352 | if (atoi(param)) ns->mapmode = Map1Cmd; |
401 | { |
|
|
402 | if (atoi (param)) |
|
|
403 | ns->mapmode = Map1Cmd; |
353 | /* if beyond this size, need to use map1cmd no matter what */ |
404 | /* if beyond this size, need to use map1cmd no matter what */ |
354 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
405 | if (ns->mapx > 11 || ns->mapy > 11) |
|
|
406 | ns->mapmode = Map1Cmd; |
355 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
407 | safe_strcat (cmdback, ns->mapmode == Map1Cmd ? "1" : "0", &slen, HUGE_BUF); |
|
|
408 | } |
356 | } else if (!strcmp(cmd,"map1acmd")) { |
409 | else if (!strcmp (cmd, "map1acmd")) |
357 | if (atoi(param)) ns->mapmode = Map1aCmd; |
410 | { |
|
|
411 | if (atoi (param)) |
|
|
412 | ns->mapmode = Map1aCmd; |
358 | /* if beyond this size, need to use map1acmd no matter what */ |
413 | /* if beyond this size, need to use map1acmd no matter what */ |
359 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
414 | if (ns->mapx > 11 || ns->mapy > 11) |
|
|
415 | ns->mapmode = Map1aCmd; |
360 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
416 | safe_strcat (cmdback, ns->mapmode == Map1aCmd ? "1" : "0", &slen, HUGE_BUF); |
|
|
417 | } |
361 | } else if (!strcmp(cmd,"newmapcmd")) { |
418 | else if (!strcmp (cmd, "newmapcmd")) |
|
|
419 | { |
362 | ns->newmapcmd= atoi(param); |
420 | ns->newmapcmd = atoi (param); |
363 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
421 | safe_strcat (cmdback, param, &slen, HUGE_BUF); |
364 | // } else if (!strcmp(cmd,"plugincmd")) { |
422 | // } else if (!strcmp(cmd,"plugincmd")) { |
365 | // ns->plugincmd = atoi(param); |
423 | // ns->plugincmd = atoi(param); |
366 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
424 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
|
|
425 | } |
367 | } else if (!strcmp(cmd,"mapinfocmd")) { |
426 | else if (!strcmp (cmd, "mapinfocmd")) |
|
|
427 | { |
368 | ns->mapinfocmd = atoi(param); |
428 | ns->mapinfocmd = atoi (param); |
369 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
429 | safe_strcat (cmdback, "1", &slen, HUGE_BUF); |
|
|
430 | } |
370 | } else if (!strcmp(cmd,"extcmd")) { |
431 | else if (!strcmp (cmd, "extcmd")) |
|
|
432 | { |
371 | ns->extcmd = atoi(param); |
433 | ns->extcmd = atoi (param); |
372 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
434 | safe_strcat (cmdback, "1", &slen, HUGE_BUF); |
|
|
435 | } |
373 | } else if (!strcmp(cmd,"extmap")) { |
436 | else if (!strcmp (cmd, "extmap")) |
|
|
437 | { |
374 | ns->extmap = atoi(param); |
438 | ns->extmap = atoi (param); |
375 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
439 | safe_strcat (cmdback, "1", &slen, HUGE_BUF); |
|
|
440 | } |
376 | } else if (!strcmp(cmd,"facecache")) { |
441 | else if (!strcmp (cmd, "facecache")) |
|
|
442 | { |
377 | ns->facecache = atoi(param); |
443 | ns->facecache = atoi (param); |
378 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
444 | safe_strcat (cmdback, param, &slen, HUGE_BUF); |
|
|
445 | } |
379 | } else if (!strcmp(cmd,"faceset")) { |
446 | else if (!strcmp (cmd, "faceset")) |
|
|
447 | { |
380 | char tmpbuf[20]; |
448 | char tmpbuf[20]; |
381 | int q = atoi(param); |
449 | int q = atoi (param); |
382 | |
450 | |
383 | if (is_valid_faceset(q)) |
451 | if (is_valid_faceset (q)) |
384 | ns->faceset=q; |
452 | ns->faceset = q; |
385 | sprintf(tmpbuf,"%d", ns->faceset); |
453 | sprintf (tmpbuf, "%d", ns->faceset); |
386 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
454 | safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF); |
387 | /* if the client is using faceset, it knows about image2 command */ |
455 | /* if the client is using faceset, it knows about image2 command */ |
388 | ns->image2=1; |
456 | ns->image2 = 1; |
|
|
457 | } |
389 | } else if (!strcmp(cmd,"itemcmd")) { |
458 | else if (!strcmp (cmd, "itemcmd")) |
|
|
459 | { |
390 | /* Version of the item protocol command to use. Currently, |
460 | /* Version of the item protocol command to use. Currently, |
391 | * only supported versions are 1 and 2. Using a numeric |
461 | * only supported versions are 1 and 2. Using a numeric |
392 | * value will make it very easy to extend this in the future. |
462 | * value will make it very easy to extend this in the future. |
393 | */ |
463 | */ |
394 | char tmpbuf[20]; |
464 | char tmpbuf[20]; |
395 | int q = atoi(param); |
465 | int q = atoi (param); |
396 | if (q<1 || q>2) { |
466 | |
397 | strcpy(tmpbuf,"FALSE"); |
467 | if (q < 1 || q > 2) |
398 | } else { |
468 | { |
399 | ns->itemcmd = q; |
469 | strcpy (tmpbuf, "FALSE"); |
|
|
470 | } |
|
|
471 | else |
|
|
472 | { |
|
|
473 | ns->itemcmd = q; |
400 | sprintf(tmpbuf,"%d", ns->itemcmd); |
474 | sprintf (tmpbuf, "%d", ns->itemcmd); |
401 | } |
475 | } |
402 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
476 | safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF); |
|
|
477 | } |
403 | } else if (!strcmp(cmd,"mapsize")) { |
478 | else if (!strcmp (cmd, "mapsize")) |
|
|
479 | { |
404 | int x, y=0; |
480 | int x, y = 0; |
405 | char tmpbuf[MAX_BUF], *cp; |
481 | char tmpbuf[MAX_BUF], *cp; |
406 | |
482 | |
407 | x = atoi(param); |
483 | x = atoi (param); |
408 | for (cp = param; *cp!=0; cp++) |
484 | for (cp = param; *cp != 0; cp++) |
409 | if (*cp == 'x' || *cp == 'X') { |
485 | if (*cp == 'x' || *cp == 'X') |
410 | y = atoi(cp+1); |
486 | { |
411 | break; |
487 | y = atoi (cp + 1); |
412 | } |
488 | break; |
|
|
489 | } |
413 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
490 | if (x < 9 || y < 9 || x > MAP_CLIENT_X || y > MAP_CLIENT_Y) |
|
|
491 | { |
414 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
492 | sprintf (tmpbuf, " %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
415 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
493 | safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF); |
416 | } else { |
494 | } |
417 | ns->mapx = x; |
495 | else |
418 | ns->mapy = y; |
496 | { |
|
|
497 | ns->mapx = x; |
|
|
498 | ns->mapy = y; |
419 | /* better to send back what we are really using and not the |
499 | /* better to send back what we are really using and not the |
420 | * param as given to us in case it gets parsed differently. |
500 | * param as given to us in case it gets parsed differently. |
421 | */ |
501 | */ |
422 | sprintf(tmpbuf,"%dx%d", x,y); |
502 | sprintf (tmpbuf, "%dx%d", x, y); |
423 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
503 | safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF); |
424 | /* If beyond this size and still using orig map command, need to |
504 | /* If beyond this size and still using orig map command, need to |
425 | * go to map1cmd. |
505 | * go to map1cmd. |
426 | */ |
506 | */ |
427 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
507 | if ((x > 11 || y > 11) && ns->mapmode == Map0Cmd) |
428 | } |
508 | ns->mapmode = Map1Cmd; |
|
|
509 | } |
|
|
510 | } |
429 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
511 | else if (!strcmp (cmd, "extendedMapInfos")) |
|
|
512 | { |
430 | /* Added by tchize |
513 | /* Added by tchize |
431 | * prepare to use the mapextended command |
514 | * prepare to use the mapextended command |
432 | */ |
515 | */ |
433 | char tmpbuf[20]; |
516 | char tmpbuf[20]; |
|
|
517 | |
434 | ns->ext_mapinfos = (atoi(param)); |
518 | ns->ext_mapinfos = (atoi (param)); |
435 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
519 | sprintf (tmpbuf, "%d", ns->ext_mapinfos); |
436 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
520 | safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF); |
|
|
521 | } |
437 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
522 | else if (!strcmp (cmd, "extendedTextInfos")) |
|
|
523 | { |
438 | /* Added by tchize |
524 | /* Added by tchize |
439 | * prepare to use the extended text commands |
525 | * prepare to use the extended text commands |
440 | * Client toggle this to non zero to get exttext |
526 | * Client toggle this to non zero to get exttext |
441 | */ |
527 | */ |
442 | char tmpbuf[20]; |
528 | char tmpbuf[20]; |
443 | |
529 | |
444 | ns->has_readable_type = (atoi(param)); |
530 | ns->has_readable_type = (atoi (param)); |
445 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
531 | sprintf (tmpbuf, "%d", ns->has_readable_type); |
446 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
532 | safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF); |
447 | } else { |
533 | } |
|
|
534 | else |
|
|
535 | { |
448 | /* Didn't get a setup command we understood - |
536 | /* Didn't get a setup command we understood - |
449 | * report a failure to the client. |
537 | * report a failure to the client. |
450 | */ |
538 | */ |
451 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
539 | safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF); |
452 | } |
540 | } |
453 | } /* for processing all the setup commands */ |
541 | } /* for processing all the setup commands */ |
454 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
542 | LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback); |
455 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
543 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
456 | } |
544 | } |
457 | |
545 | |
458 | /** |
546 | /** |
459 | * The client has requested to be added to the game. |
547 | * The client has requested to be added to the game. |
460 | * This is what takes care of it. We tell the client how things worked out. |
548 | * This is what takes care of it. We tell the client how things worked out. |
461 | * I am not sure if this file is the best place for this function. however, |
549 | * I am not sure if this file is the best place for this function. however, |
462 | * it either has to be here or init_sockets needs to be exported. |
550 | * it either has to be here or init_sockets needs to be exported. |
463 | */ |
551 | */ |
|
|
552 | void |
464 | void AddMeCmd(char *buf, int len, NewSocket *ns) |
553 | AddMeCmd (char *buf, int len, NewSocket * ns) |
465 | { |
554 | { |
466 | Settings oldsettings; |
555 | Settings oldsettings; |
|
|
556 | |
467 | oldsettings=settings; |
557 | oldsettings = settings; |
468 | if (ns->status != Ns_Add || add_player(ns)) { |
558 | if (ns->status != Ns_Add || add_player (ns)) |
|
|
559 | { |
469 | Write_String_To_Socket(ns, "addme_failed",12); |
560 | Write_String_To_Socket (ns, "addme_failed", 12); |
470 | } else { |
561 | } |
|
|
562 | else |
|
|
563 | { |
471 | /* Basically, the add_player copies the socket structure into |
564 | /* Basically, the add_player copies the socket structure into |
472 | * the player structure, so this one (which is from init_sockets) |
565 | * the player structure, so this one (which is from init_sockets) |
473 | * is not needed anymore. The write below should still work, as the |
566 | * is not needed anymore. The write below should still work, as the |
474 | * stuff in ns is still relevant. |
567 | * stuff in ns is still relevant. |
475 | */ |
568 | */ |
476 | Write_String_To_Socket(ns, "addme_success",13); |
569 | Write_String_To_Socket (ns, "addme_success", 13); |
477 | socket_info.nconns--; |
570 | socket_info.nconns--; |
478 | ns->status = Ns_Avail; |
571 | ns->status = Ns_Avail; |
479 | } |
572 | } |
480 | settings=oldsettings; |
573 | settings = oldsettings; |
481 | } |
574 | } |
482 | |
575 | |
483 | /** Reply to ExtendedInfos command */ |
576 | /** Reply to ExtendedInfos command */ |
|
|
577 | void |
484 | void ToggleExtendedInfos (char *buf, int len, NewSocket *ns){ |
578 | ToggleExtendedInfos (char *buf, int len, NewSocket * ns) |
|
|
579 | { |
485 | char cmdback[MAX_BUF]; |
580 | char cmdback[MAX_BUF]; |
486 | char command[50]; |
581 | char command[50]; |
487 | int info,nextinfo; |
582 | int info, nextinfo; |
|
|
583 | |
488 | cmdback[0]='\0'; |
584 | cmdback[0] = '\0'; |
489 | nextinfo=0; |
585 | nextinfo = 0; |
|
|
586 | |
490 | while (1){ |
587 | while (1) |
|
|
588 | { |
491 | /* 1. Extract an info*/ |
589 | /* 1. Extract an info */ |
492 | info=nextinfo; |
590 | info = nextinfo; |
|
|
591 | |
493 | while ( (info<len) && (buf[info]==' ') ) info++; |
592 | while ((info < len) && (buf[info] == ' ')) |
|
|
593 | info++; |
|
|
594 | |
494 | if (info>=len) |
595 | if (info >= len) |
495 | break; |
596 | break; |
|
|
597 | |
496 | nextinfo=info+1; |
598 | nextinfo = info + 1; |
|
|
599 | |
497 | while ( (nextinfo<len) && (buf[nextinfo]!=' ') ) |
600 | while ((nextinfo < len) && (buf[nextinfo] != ' ')) |
498 | nextinfo++; |
601 | nextinfo++; |
|
|
602 | |
499 | if (nextinfo-info>=49) /*Erroneous info asked*/ |
603 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
500 | continue; |
604 | continue; |
|
|
605 | |
501 | strncpy (command,&(buf[info]),nextinfo-info); |
606 | strncpy (command, &(buf[info]), nextinfo - info); |
502 | command[nextinfo-info]='\0'; |
607 | |
503 | /* 2. Interpret info*/ |
608 | /* 2. Interpret info */ |
504 | if (!strcmp("smooth",command)){ |
609 | if (!strcmp ("smooth", command)) |
505 | /* Toggle smoothing*/ |
610 | /* Toggle smoothing */ |
506 | ns->EMI_smooth=!ns->EMI_smooth; |
611 | ns->EMI_smooth = !ns->EMI_smooth; |
507 | }else{ |
612 | else |
508 | /*bad value*/ |
613 | /*bad value */; |
509 | } |
614 | |
510 | /*3. Next info*/ |
615 | /*3. Next info */ |
511 | } |
616 | } |
|
|
617 | |
512 | strcpy (cmdback,"ExtendedInfoSet"); |
618 | strcpy (cmdback, "ExtendedInfoSet"); |
|
|
619 | |
513 | if (ns->EMI_smooth){ |
620 | if (ns->EMI_smooth) |
|
|
621 | { |
514 | strcat (cmdback," "); |
622 | strcat (cmdback, " "); |
515 | strcat (cmdback,"smoothing"); |
623 | strcat (cmdback, "smoothing"); |
516 | } |
624 | } |
|
|
625 | |
517 | Write_String_To_Socket(ns, cmdback,strlen(cmdback)); |
626 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
518 | } |
627 | } |
|
|
628 | |
519 | /* |
629 | /* |
520 | #define MSG_TYPE_BOOK 1 |
630 | #define MSG_TYPE_BOOK 1 |
521 | #define MSG_TYPE_CARD 2 |
631 | #define MSG_TYPE_CARD 2 |
522 | #define MSG_TYPE_PAPER 3 |
632 | #define MSG_TYPE_PAPER 3 |
523 | #define MSG_TYPE_SIGN 4 |
633 | #define MSG_TYPE_SIGN 4 |
524 | #define MSG_TYPE_MONUMENT 5 |
634 | #define MSG_TYPE_MONUMENT 5 |
525 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
635 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
|
|
636 | |
526 | /** Reply to ExtendedInfos command */ |
637 | /** Reply to ExtendedInfos command */ |
|
|
638 | void |
527 | void ToggleExtendedText (char *buf, int len, NewSocket *ns){ |
639 | ToggleExtendedText (char *buf, int len, NewSocket * ns) |
|
|
640 | { |
528 | char cmdback[MAX_BUF]; |
641 | char cmdback[MAX_BUF]; |
529 | char temp[10]; |
642 | char temp[10]; |
530 | char command[50]; |
643 | char command[50]; |
531 | int info,nextinfo,i,flag; |
644 | int info, nextinfo, i, flag; |
|
|
645 | |
532 | cmdback[0]='\0'; |
646 | cmdback[0] = '\0'; |
|
|
647 | |
533 | nextinfo=0; |
648 | nextinfo = 0; |
534 | while (1){ |
649 | while (1) |
|
|
650 | { |
535 | /* 1. Extract an info*/ |
651 | /* 1. Extract an info */ |
536 | info=nextinfo; |
652 | info = nextinfo; |
|
|
653 | |
537 | while ( (info<len) && (buf[info]==' ') ) info++; |
654 | while ((info < len) && (buf[info] == ' ')) |
|
|
655 | info++; |
|
|
656 | |
538 | if (info>=len) |
657 | if (info >= len) |
539 | break; |
658 | break; |
|
|
659 | |
540 | nextinfo=info+1; |
660 | nextinfo = info + 1; |
|
|
661 | |
541 | while ( (nextinfo<len) && (buf[nextinfo]!=' ') ) |
662 | while ((nextinfo < len) && (buf[nextinfo] != ' ')) |
542 | nextinfo++; |
663 | nextinfo++; |
|
|
664 | |
543 | if (nextinfo-info>=49) /*Erroneous info asked*/ |
665 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
544 | continue; |
666 | continue; |
|
|
667 | |
545 | strncpy (command,&(buf[info]),nextinfo-info); |
668 | strncpy (command, &(buf[info]), nextinfo - info); |
546 | command[nextinfo-info]='\0'; |
669 | command[nextinfo - info] = '\0'; |
547 | /* 2. Interpret info*/ |
670 | /* 2. Interpret info */ |
548 | i = sscanf(command,"%d",&flag); |
671 | i = sscanf (command, "%d", &flag); |
|
|
672 | |
549 | if ( (i==1) && (flag>0) && (flag<=MSG_TYPE_LAST)) |
673 | if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST)) |
550 | ns->supported_readables|=(1<<flag); |
674 | ns->supported_readables |= (1 << flag); |
551 | /*3. Next info*/ |
675 | /*3. Next info */ |
552 | } |
676 | } |
|
|
677 | |
553 | /* Send resulting state */ |
678 | /* Send resulting state */ |
554 | strcpy (cmdback,"ExtendedTextSet"); |
679 | strcpy (cmdback, "ExtendedTextSet"); |
|
|
680 | |
555 | for (i=0;i<=MSG_TYPE_LAST;i++) |
681 | for (i = 0; i <= MSG_TYPE_LAST; i++) |
556 | if (ns->supported_readables &(1<<i)){ |
682 | if (ns->supported_readables & (1 << i)) |
|
|
683 | { |
557 | strcat (cmdback," "); |
684 | strcat (cmdback, " "); |
558 | snprintf(temp,sizeof(temp),"%d",i); |
685 | snprintf (temp, sizeof (temp), "%d", i); |
559 | strcat (cmdback,temp); |
686 | strcat (cmdback, temp); |
560 | } |
687 | } |
|
|
688 | |
561 | Write_String_To_Socket(ns, cmdback,strlen(cmdback)); |
689 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
562 | } |
690 | } |
563 | |
691 | |
564 | /** |
692 | /** |
565 | * A lot like the old AskSmooth (in fact, now called by AskSmooth). |
693 | * A lot like the old AskSmooth (in fact, now called by AskSmooth). |
566 | * Basically, it makes no sense to wait for the client to request a |
694 | * Basically, it makes no sense to wait for the client to request a |
567 | * a piece of data from us that we know the client wants. So |
695 | * a piece of data from us that we know the client wants. So |
568 | * if we know the client wants it, might as well push it to the |
696 | * if we know the client wants it, might as well push it to the |
569 | * client. |
697 | * client. |
570 | */ |
698 | */ |
|
|
699 | static void |
571 | static void SendSmooth(NewSocket *ns, uint16 face) { |
700 | SendSmooth (NewSocket * ns, uint16 face) |
|
|
701 | { |
572 | uint16 smoothface; |
702 | uint16 smoothface; |
573 | unsigned char reply[MAX_BUF]; |
703 | unsigned char reply[MAX_BUF]; |
574 | SockList sl; |
704 | SockList sl; |
575 | |
705 | |
576 | /* If we can't find a face, return and set it so we won't try to send this |
706 | /* If we can't find a face, return and set it so we won't try to send this |
577 | * again. |
707 | * again. |
578 | */ |
708 | */ |
579 | if ((!FindSmooth (face, &smoothface)) && |
709 | if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) |
580 | (!FindSmooth ( smooth_face->number, &smoothface))) { |
710 | { |
581 | |
711 | |
582 | LOG(llevError,"could not findsmooth for %d. Neither default (%s)\n",face,smooth_face->name); |
712 | LOG (llevError, "could not findsmooth for %d. Neither default (%s)\n", face, &smooth_face->name); |
583 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
713 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
584 | return; |
714 | return; |
585 | } |
715 | } |
586 | |
716 | |
587 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
717 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
588 | esrv_send_face(ns, smoothface, 0); |
718 | esrv_send_face (ns, smoothface, 0); |
589 | |
719 | |
590 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
720 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
591 | |
721 | |
592 | sl.buf=reply; |
722 | sl.buf = reply; |
593 | strcpy((char*)sl.buf,"smooth "); |
723 | strcpy ((char *) sl.buf, "smooth "); |
594 | sl.len=strlen((char*)sl.buf); |
724 | sl.len = strlen ((char *) sl.buf); |
595 | SockList_AddShort(&sl, face); |
725 | SockList_AddShort (&sl, face); |
596 | SockList_AddShort(&sl, smoothface); |
726 | SockList_AddShort (&sl, smoothface); |
597 | Send_With_Handling(ns, &sl); |
727 | Send_With_Handling (ns, &sl); |
598 | } |
728 | } |
599 | |
729 | |
600 | /** |
730 | /** |
601 | * Tells client the picture it has to use |
731 | * Tells client the picture it has to use |
602 | * to smooth a picture number given as argument. |
732 | * to smooth a picture number given as argument. |
603 | */ |
733 | */ |
|
|
734 | void |
604 | void AskSmooth (char *buf, int len, NewSocket *ns){ |
735 | AskSmooth (char *buf, int len, NewSocket * ns) |
|
|
736 | { |
605 | uint16 facenbr; |
737 | uint16 facenbr; |
606 | |
738 | |
607 | facenbr=atoi (buf); |
739 | facenbr = atoi (buf); |
608 | SendSmooth(ns, facenbr); |
740 | SendSmooth (ns, facenbr); |
609 | } |
741 | } |
610 | |
742 | |
611 | |
743 | |
612 | |
744 | |
613 | |
745 | |
614 | |
746 | |
615 | /** |
747 | /** |
616 | * This handles the general commands from the client (ie, north, fire, cast, |
748 | * This handles the general commands from the client (ie, north, fire, cast, |
617 | * etc.) |
749 | * etc.) |
618 | */ |
750 | */ |
|
|
751 | void |
619 | void PlayerCmd(char *buf, int len, player *pl) |
752 | PlayerCmd (char *buf, int len, player *pl) |
620 | { |
753 | { |
621 | |
754 | |
622 | /* The following should never happen with a proper or honest client. |
755 | /* The following should never happen with a proper or honest client. |
623 | * Therefore, the error message doesn't have to be too clear - if |
756 | * Therefore, the error message doesn't have to be too clear - if |
624 | * someone is playing with a hacked/non working client, this gives them |
757 | * someone is playing with a hacked/non working client, this gives them |
625 | * an idea of the problem, but they deserve what they get |
758 | * an idea of the problem, but they deserve what they get |
626 | */ |
759 | */ |
627 | if (pl->state!=ST_PLAYING) { |
760 | if (pl->state != ST_PLAYING) |
628 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
|
|
629 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
|
|
630 | return; |
|
|
631 | } |
761 | { |
|
|
762 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
|
|
763 | return; |
|
|
764 | } |
632 | /* Check if there is a count. In theory, a zero count could also be |
765 | /* Check if there is a count. In theory, a zero count could also be |
633 | * sent, so check for that also. |
766 | * sent, so check for that also. |
634 | */ |
767 | */ |
635 | if (atoi(buf) || buf[0]=='0') { |
768 | if (atoi (buf) || buf[0] == '0') |
|
|
769 | { |
636 | pl->count=atoi((char*)buf); |
770 | pl->count = atoi ((char *) buf); |
637 | buf=strchr(buf,' '); /* advance beyond the numbers */ |
771 | buf = strchr (buf, ' '); /* advance beyond the numbers */ |
638 | if (!buf) { |
772 | if (!buf) |
|
|
773 | { |
639 | #ifdef ESRV_DEBUG |
774 | #ifdef ESRV_DEBUG |
640 | LOG(llevDebug,"PlayerCmd: Got count but no command.\n"); |
775 | LOG (llevDebug, "PlayerCmd: Got count but no command.\n"); |
641 | #endif |
776 | #endif |
642 | return; |
777 | return; |
643 | } |
778 | } |
644 | buf++; |
779 | buf++; |
645 | } |
780 | } |
646 | /* This should not happen anymore. */ |
781 | /* This should not happen anymore. */ |
647 | if (pl->ob->speed_left<-1.0) { |
782 | if (pl->ob->speed_left < -1.0) |
|
|
783 | { |
648 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
784 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
649 | } |
785 | } |
650 | /* In c_new.c */ |
786 | /* In c_new.c */ |
651 | execute_newserver_command(pl->ob, (char*)buf); |
787 | execute_newserver_command (pl->ob, (char *) buf); |
652 | /* Perhaps something better should be done with a left over count. |
788 | /* Perhaps something better should be done with a left over count. |
653 | * Cleaning up the input should probably be done first - all actions |
789 | * Cleaning up the input should probably be done first - all actions |
654 | * for the command that issued the count should be done before any other |
790 | * for the command that issued the count should be done before any other |
655 | * commands. |
791 | * commands. |
656 | */ |
792 | */ |
657 | |
793 | |
658 | pl->count=0; |
794 | pl->count = 0; |
659 | |
795 | |
660 | } |
796 | } |
661 | |
797 | |
662 | |
798 | |
663 | /** |
799 | /** |
664 | * This handles the general commands from the client (ie, north, fire, cast, |
800 | * This handles the general commands from the client (ie, north, fire, cast, |
665 | * etc.). It is a lot like PlayerCmd above, but is called with the |
801 | * etc.). It is a lot like PlayerCmd above, but is called with the |
666 | * 'ncom' method which gives more information back to the client so it |
802 | * 'ncom' method which gives more information back to the client so it |
667 | * can throttle. |
803 | * can throttle. |
668 | */ |
804 | */ |
|
|
805 | void |
669 | void NewPlayerCmd(uint8 *buf, int len, player *pl) |
806 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
670 | { |
807 | { |
671 | int time,repeat; |
808 | int time, repeat; |
672 | short packet; |
809 | short packet; |
673 | unsigned char command[MAX_BUF]; |
810 | unsigned char command[MAX_BUF]; |
674 | SockList sl; |
811 | SockList sl; |
675 | |
812 | |
676 | if (len < 7) { |
813 | if (len < 7) |
|
|
814 | { |
677 | LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf); |
815 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
678 | return; |
816 | return; |
679 | } |
817 | } |
680 | |
818 | |
681 | packet = GetShort_String(buf); |
819 | packet = GetShort_String (buf); |
682 | repeat = GetInt_String(buf+2); |
820 | repeat = GetInt_String (buf + 2); |
683 | /* -1 is special - no repeat, but don't update */ |
821 | /* -1 is special - no repeat, but don't update */ |
684 | if (repeat!=-1) { |
822 | if (repeat != -1) |
685 | pl->count=repeat; |
|
|
686 | } |
823 | { |
687 | if ((len-4) >= MAX_BUF) len=MAX_BUF-5; |
824 | pl->count = repeat; |
|
|
825 | } |
|
|
826 | if ((len - 4) >= MAX_BUF) |
|
|
827 | len = MAX_BUF - 5; |
688 | |
828 | |
689 | strncpy((char*)command, (char*)buf+6, len-4); |
829 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
690 | command[len-4]='\0'; |
830 | command[len - 4] = '\0'; |
691 | |
831 | |
692 | /* The following should never happen with a proper or honest client. |
832 | /* The following should never happen with a proper or honest client. |
693 | * Therefore, the error message doesn't have to be too clear - if |
833 | * Therefore, the error message doesn't have to be too clear - if |
694 | * someone is playing with a hacked/non working client, this gives them |
834 | * someone is playing with a hacked/non working client, this gives them |
695 | * an idea of the problem, but they deserve what they get |
835 | * an idea of the problem, but they deserve what they get |
696 | */ |
836 | */ |
697 | if (pl->state!=ST_PLAYING) { |
837 | if (pl->state != ST_PLAYING) |
698 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
|
|
699 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
|
|
700 | return; |
|
|
701 | } |
838 | { |
|
|
839 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
|
|
840 | return; |
|
|
841 | } |
702 | |
842 | |
703 | /* This should not happen anymore. */ |
843 | /* This should not happen anymore. */ |
704 | if (pl->ob->speed_left<-1.0) { |
844 | if (pl->ob->speed_left < -1.0) |
|
|
845 | { |
705 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
846 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
706 | } |
847 | } |
707 | /* In c_new.c */ |
848 | /* In c_new.c */ |
708 | execute_newserver_command(pl->ob, (char*)command); |
849 | execute_newserver_command (pl->ob, (char *) command); |
709 | /* Perhaps something better should be done with a left over count. |
850 | /* Perhaps something better should be done with a left over count. |
710 | * Cleaning up the input should probably be done first - all actions |
851 | * Cleaning up the input should probably be done first - all actions |
711 | * for the command that issued the count should be done before any other |
852 | * for the command that issued the count should be done before any other |
712 | * commands. |
853 | * commands. |
713 | */ |
854 | */ |
714 | pl->count=0; |
855 | pl->count = 0; |
715 | |
856 | |
716 | /* Send confirmation of command execution now */ |
857 | /* Send confirmation of command execution now */ |
717 | sl.buf = command; |
858 | sl.buf = command; |
718 | strcpy((char*)sl.buf,"comc "); |
859 | strcpy ((char *) sl.buf, "comc "); |
719 | sl.len=5; |
860 | sl.len = 5; |
720 | SockList_AddShort(&sl,packet); |
861 | SockList_AddShort (&sl, packet); |
721 | if (FABS(pl->ob->speed) < 0.001) time=MAX_TIME * 100; |
862 | if (FABS (pl->ob->speed) < 0.001) |
|
|
863 | time = MAX_TIME * 100; |
722 | else |
864 | else |
723 | time = ( int )( MAX_TIME/ FABS(pl->ob->speed) ); |
865 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
724 | SockList_AddInt(&sl,time); |
866 | SockList_AddInt (&sl, time); |
725 | Send_With_Handling(&pl->socket, &sl); |
867 | Send_With_Handling (&pl->socket, &sl); |
726 | } |
868 | } |
727 | |
869 | |
728 | |
870 | |
729 | /** This is a reply to a previous query. */ |
871 | /** This is a reply to a previous query. */ |
|
|
872 | void |
730 | void ReplyCmd(char *buf, int len, player *pl) |
873 | ReplyCmd (char *buf, int len, player *pl) |
731 | { |
874 | { |
732 | /* This is to synthesize how the data would be stored if it |
875 | /* This is to synthesize how the data would be stored if it |
733 | * was normally entered. A bit of a hack, and should be cleaned up |
876 | * was normally entered. A bit of a hack, and should be cleaned up |
734 | * once all the X11 code is removed from the server. |
877 | * once all the X11 code is removed from the server. |
735 | * |
878 | * |
736 | * We pass 13 to many of the functions because this way they |
879 | * We pass 13 to many of the functions because this way they |
737 | * think it was the carriage return that was entered, and the |
880 | * think it was the carriage return that was entered, and the |
738 | * function then does not try to do additional input. |
881 | * function then does not try to do additional input. |
739 | */ |
882 | */ |
740 | snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
883 | snprintf (pl->write_buf, sizeof (pl->write_buf), ":%s", buf); |
741 | |
884 | |
742 | /* this avoids any hacking here */ |
885 | /* this avoids any hacking here */ |
743 | |
886 | |
744 | switch (pl->state) { |
887 | switch (pl->state) |
|
|
888 | { |
745 | case ST_PLAYING: |
889 | case ST_PLAYING: |
746 | LOG(llevError,"Got reply message with ST_PLAYING input state\n"); |
890 | LOG (llevError, "Got reply message with ST_PLAYING input state\n"); |
747 | break; |
891 | break; |
748 | |
892 | |
749 | case ST_PLAY_AGAIN: |
893 | case ST_PLAY_AGAIN: |
750 | /* We can check this for return value (2==quit). Maybe we |
894 | /* We can check this for return value (2==quit). Maybe we |
751 | * should, and do something appropriate? |
895 | * should, and do something appropriate? |
752 | */ |
896 | */ |
753 | receive_play_again(pl->ob, buf[0]); |
897 | receive_play_again (pl->ob, buf[0]); |
754 | break; |
898 | break; |
755 | |
899 | |
756 | case ST_ROLL_STAT: |
900 | case ST_ROLL_STAT: |
757 | key_roll_stat(pl->ob,buf[0]); |
901 | key_roll_stat (pl->ob, buf[0]); |
758 | break; |
902 | break; |
759 | |
903 | |
760 | case ST_CHANGE_CLASS: |
904 | case ST_CHANGE_CLASS: |
761 | |
905 | |
762 | key_change_class(pl->ob, buf[0]); |
906 | key_change_class (pl->ob, buf[0]); |
763 | break; |
907 | break; |
764 | |
908 | |
765 | case ST_CONFIRM_QUIT: |
909 | case ST_CONFIRM_QUIT: |
766 | key_confirm_quit(pl->ob, buf[0]); |
910 | key_confirm_quit (pl->ob, buf[0]); |
767 | break; |
911 | break; |
768 | |
912 | |
769 | case ST_CONFIGURE: |
913 | case ST_CONFIGURE: |
770 | LOG(llevError,"In client input handling, but into configure state\n"); |
914 | LOG (llevError, "In client input handling, but into configure state\n"); |
771 | pl->state = ST_PLAYING; |
915 | pl->state = ST_PLAYING; |
772 | break; |
916 | break; |
773 | |
917 | |
774 | case ST_GET_NAME: |
918 | case ST_GET_NAME: |
775 | receive_player_name(pl->ob,13); |
919 | receive_player_name (pl->ob, 13); |
776 | break; |
920 | break; |
777 | |
921 | |
778 | case ST_GET_PASSWORD: |
922 | case ST_GET_PASSWORD: |
779 | case ST_CONFIRM_PASSWORD: |
923 | case ST_CONFIRM_PASSWORD: |
780 | receive_player_password(pl->ob,13); |
924 | receive_player_password (pl->ob, 13); |
781 | break; |
925 | break; |
782 | |
926 | |
783 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
927 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
784 | receive_party_password(pl->ob,13); |
928 | receive_party_password (pl->ob, 13); |
785 | break; |
929 | break; |
786 | |
930 | |
787 | default: |
931 | default: |
788 | LOG(llevError,"Unknown input state: %d\n", pl->state); |
932 | LOG (llevError, "Unknown input state: %d\n", pl->state); |
789 | } |
933 | } |
790 | } |
934 | } |
791 | |
935 | |
792 | /** |
936 | /** |
793 | * Client tells its version. If there is a mismatch, we close the |
937 | * Client tells its version. If there is a mismatch, we close the |
794 | * socket. In real life, all we should care about is the client having |
938 | * socket. In real life, all we should care about is the client having |
795 | * something older than the server. If we assume the client will be |
939 | * something older than the server. If we assume the client will be |
796 | * backwards compatible, having it be a later version should not be a |
940 | * backwards compatible, having it be a later version should not be a |
797 | * problem. |
941 | * problem. |
798 | */ |
942 | */ |
|
|
943 | void |
799 | void VersionCmd(char *buf, int len,NewSocket *ns) |
944 | VersionCmd (char *buf, int len, NewSocket * ns) |
800 | { |
945 | { |
801 | char *cp; |
946 | char *cp; |
802 | char version_warning[256]; |
947 | char version_warning[256]; |
803 | |
948 | |
804 | if (!buf) { |
949 | if (!buf) |
|
|
950 | { |
805 | LOG(llevError, "CS: received corrupted version command\n"); |
951 | LOG (llevError, "CS: received corrupted version command\n"); |
806 | return; |
952 | return; |
807 | } |
953 | } |
808 | |
954 | |
809 | ns->cs_version = atoi(buf); |
955 | ns->cs_version = atoi (buf); |
810 | ns->sc_version = ns->cs_version; |
956 | ns->sc_version = ns->cs_version; |
811 | if (VERSION_CS != ns->cs_version) { |
957 | if (VERSION_CS != ns->cs_version) |
|
|
958 | { |
812 | #ifdef ESRV_DEBUG |
959 | #ifdef ESRV_DEBUG |
813 | LOG(llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS,ns->cs_version); |
960 | LOG (llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS, ns->cs_version); |
814 | #endif |
961 | #endif |
815 | } |
962 | } |
816 | cp = strchr(buf+1,' '); |
963 | cp = strchr (buf + 1, ' '); |
817 | if (!cp) return; |
964 | if (!cp) |
|
|
965 | return; |
818 | ns->sc_version = atoi(cp); |
966 | ns->sc_version = atoi (cp); |
819 | if (VERSION_SC != ns->sc_version) { |
967 | if (VERSION_SC != ns->sc_version) |
|
|
968 | { |
820 | #ifdef ESRV_DEBUG |
969 | #ifdef ESRV_DEBUG |
821 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
970 | LOG (llevDebug, "CS: scversion mismatch (%d,%d)\n", VERSION_SC, ns->sc_version); |
822 | #endif |
971 | #endif |
823 | } |
972 | } |
824 | cp = strchr(cp+1, ' '); |
973 | cp = strchr (cp + 1, ' '); |
825 | if (cp) { |
974 | if (cp) |
|
|
975 | { |
826 | LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
976 | LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
827 | |
977 | |
|
|
978 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
|
|
979 | |
828 | /* This is first implementation - i skip all beta DX clients with it |
980 | /* This is first implementation - i skip all beta DX clients with it |
829 | * Add later stuff here for other clients |
981 | * Add later stuff here for other clients |
830 | */ |
982 | */ |
831 | |
983 | |
832 | /* these are old dxclients */ |
984 | /* these are old dxclients */ |
833 | /* Version 1024 added support for singular + plural name values - |
985 | /* Version 1024 added support for singular + plural name values - |
834 | * requiing this minimal value reduces complexity of that code, and it |
986 | * requiing this minimal value reduces complexity of that code, and it |
835 | * has been around for a long time. |
987 | * has been around for a long time. |
836 | */ |
988 | */ |
837 | if(!strcmp(" CF DX CLIENT", cp) || ns->sc_version < 1024 ) |
989 | if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) |
838 | { |
990 | { |
839 | sprintf(version_warning,"drawinfo %d %s", NDI_RED, "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
991 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
|
|
992 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
840 | Write_String_To_Socket(ns, version_warning, strlen(version_warning)); |
993 | Write_String_To_Socket (ns, version_warning, strlen (version_warning)); |
841 | } |
994 | } |
842 | |
995 | |
843 | } |
996 | } |
844 | } |
997 | } |
845 | |
998 | |
846 | /** sound related functions. */ |
999 | /** sound related functions. */ |
847 | |
1000 | |
|
|
1001 | void |
848 | void SetSound(char *buf, int len, NewSocket *ns) |
1002 | SetSound (char *buf, int len, NewSocket * ns) |
849 | { |
1003 | { |
850 | ns->sound = atoi(buf); |
1004 | ns->sound = atoi (buf); |
851 | } |
1005 | } |
852 | |
1006 | |
853 | /** client wants the map resent */ |
1007 | /** client wants the map resent */ |
854 | |
1008 | |
|
|
1009 | void |
855 | void MapRedrawCmd(char *buf, int len, player *pl) |
1010 | MapRedrawCmd (char *buf, int len, player *pl) |
856 | { |
1011 | { |
|
|
1012 | |
857 | /* This function is currently disabled; just clearing the map state results in |
1013 | /* This function is currently disabled; just clearing the map state results in |
858 | * display errors. It should clear the cache and send a newmap command. |
1014 | * display errors. It should clear the cache and send a newmap command. |
859 | * Unfortunately this solution does not work because some client versions send |
1015 | * Unfortunately this solution does not work because some client versions send |
860 | * a mapredraw command after receiving a newmap command. |
1016 | * a mapredraw command after receiving a newmap command. |
861 | */ |
1017 | */ |
862 | #if 0 |
1018 | #if 0 |
863 | /* Okay, this is MAJOR UGLY. but the only way I know how to |
1019 | /* Okay, this is MAJOR UGLY. but the only way I know how to |
864 | * clear the "cache" |
1020 | * clear the "cache" |
865 | */ |
1021 | */ |
866 | memset(&pl->socket.lastmap, 0, sizeof(struct Map)); |
1022 | memset (&pl->socket.lastmap, 0, sizeof (struct Map)); |
867 | draw_client_map(pl->ob); |
1023 | draw_client_map (pl->ob); |
868 | #endif |
1024 | #endif |
869 | } |
1025 | } |
870 | |
1026 | |
871 | /** |
1027 | /** |
872 | * Moves an object (typically, container to inventory). |
1028 | * Moves an object (typically, container to inventory). |
873 | * syntax is: move (to) (tag) (nrof) |
1029 | * syntax is: move (to) (tag) (nrof) |
874 | */ |
1030 | */ |
|
|
1031 | void |
875 | void MoveCmd(char *buf, int len,player *pl) |
1032 | MoveCmd (char *buf, int len, player *pl) |
876 | { |
1033 | { |
877 | int vals[3], i; |
1034 | int vals[3], i; |
878 | |
1035 | |
879 | /* A little funky here. We only cycle for 2 records, because |
1036 | /* A little funky here. We only cycle for 2 records, because |
880 | * we obviously am not going to find a space after the third |
1037 | * we obviously am not going to find a space after the third |
881 | * record. Perhaps we should just replace this with a |
1038 | * record. Perhaps we should just replace this with a |
882 | * sscanf? |
1039 | * sscanf? |
883 | */ |
1040 | */ |
884 | for (i=0; i<2; i++) { |
1041 | for (i = 0; i < 2; i++) |
|
|
1042 | { |
885 | vals[i]=atoi(buf); |
1043 | vals[i] = atoi (buf); |
886 | if (!(buf = strchr(buf, ' '))) { |
1044 | if (!(buf = strchr (buf, ' '))) |
|
|
1045 | { |
887 | LOG(llevError,"Incomplete move command: %s\n", buf); |
1046 | LOG (llevError, "Incomplete move command: %s\n", buf); |
888 | return; |
1047 | return; |
889 | } |
1048 | } |
890 | buf++; |
1049 | buf++; |
891 | } |
1050 | } |
892 | vals[2]=atoi(buf); |
1051 | vals[2] = atoi (buf); |
893 | |
1052 | |
894 | /* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ |
1053 | /* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ |
895 | esrv_move_object(pl->ob,vals[0], vals[1], vals[2]); |
1054 | esrv_move_object (pl->ob, vals[0], vals[1], vals[2]); |
896 | } |
1055 | } |
897 | |
1056 | |
898 | |
1057 | |
899 | |
1058 | |
900 | /****************************************************************************** |
1059 | /****************************************************************************** |
… | |
… | |
905 | |
1064 | |
906 | /** |
1065 | /** |
907 | * Asks the client to query the user. This way, the client knows |
1066 | * Asks the client to query the user. This way, the client knows |
908 | * it needs to send something back (vs just printing out a message) |
1067 | * it needs to send something back (vs just printing out a message) |
909 | */ |
1068 | */ |
|
|
1069 | void |
910 | void send_query(NewSocket *ns, uint8 flags, char *text) |
1070 | send_query (NewSocket * ns, uint8 flags, char *text) |
911 | { |
1071 | { |
912 | char buf[MAX_BUF]; |
1072 | char buf[MAX_BUF]; |
913 | |
1073 | |
914 | sprintf(buf,"query %d %s", flags, text?text:""); |
1074 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
915 | Write_String_To_Socket(ns, buf, strlen(buf)); |
1075 | Write_String_To_Socket (ns, buf, strlen (buf)); |
916 | } |
1076 | } |
917 | |
1077 | |
918 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1078 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
919 | Old = New; \ |
1079 | Old = New; \ |
920 | SockList_AddChar(&sl, Type); \ |
1080 | SockList_AddChar(&sl, Type); \ |
921 | SockList_AddInt64(&sl, New); \ |
1081 | SockList_AddInt64(&sl, New); \ |
922 | } |
1082 | } |
923 | |
1083 | |
924 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
1084 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
925 | Old = New; \ |
1085 | Old = New; \ |
926 | SockList_AddChar(&sl, Type); \ |
1086 | SockList_AddChar(&sl, Type); \ |
927 | SockList_AddInt(&sl, New); \ |
1087 | SockList_AddInt(&sl, New); \ |
928 | } |
1088 | } |
929 | |
1089 | |
930 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
1090 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
931 | Old = New; \ |
1091 | Old = New; \ |
932 | SockList_AddChar(&sl, Type); \ |
1092 | SockList_AddChar(&sl, Type); \ |
933 | SockList_AddShort(&sl, New); \ |
1093 | SockList_AddShort(&sl, New); \ |
934 | } |
1094 | } |
935 | |
1095 | |
936 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
1096 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
937 | Old = New; \ |
1097 | Old = New; \ |
938 | SockList_AddChar(&sl, Type); \ |
1098 | SockList_AddChar(&sl, Type); \ |
939 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
1099 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
940 | } |
1100 | } |
941 | |
1101 | |
942 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
1102 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
943 | if (Old) free(Old);\ |
1103 | if (Old) free(Old);\ |
944 | Old = strdup_local(New);\ |
1104 | Old = strdup_local(New);\ |
945 | SockList_AddChar(&sl, Type); \ |
1105 | SockList_AddChar(&sl, Type); \ |
946 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
1106 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
947 | strcpy((char*)sl.buf + sl.len, New); \ |
1107 | strcpy((char*)sl.buf + sl.len, New); \ |
948 | sl.len += strlen(New); \ |
1108 | sl.len += strlen(New); \ |
949 | } |
1109 | } |
950 | |
1110 | |
951 | /** |
1111 | /** |
952 | * Sends a statistics update. We look at the old values, |
1112 | * Sends a statistics update. We look at the old values, |
953 | * and only send what has changed. Stat mapping values are in newclient.h |
1113 | * and only send what has changed. Stat mapping values are in newclient.h |
954 | * Since this gets sent a lot, this is actually one of the few binary |
1114 | * Since this gets sent a lot, this is actually one of the few binary |
955 | * commands for now. |
1115 | * commands for now. |
956 | */ |
1116 | */ |
|
|
1117 | void |
957 | void esrv_update_stats(player *pl) |
1118 | esrv_update_stats (player *pl) |
958 | { |
1119 | { |
959 | SockList sl; |
1120 | SockList sl; |
960 | char buf[MAX_BUF]; |
1121 | char buf[MAX_BUF]; |
961 | uint16 flags; |
1122 | uint16 flags; |
962 | |
1123 | |
963 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1124 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
964 | strcpy((char*)sl.buf,"stats "); |
1125 | strcpy ((char *) sl.buf, "stats "); |
965 | sl.len=strlen((char*)sl.buf); |
1126 | sl.len = strlen ((char *) sl.buf); |
966 | |
1127 | |
967 | if(pl->ob != NULL) |
1128 | if (pl->ob != NULL) |
968 | { |
1129 | { |
969 | AddIfShort(pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
1130 | AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
970 | AddIfShort(pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); |
1131 | AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); |
971 | AddIfShort(pl->last_stats.sp, pl->ob->stats.sp, CS_STAT_SP); |
1132 | AddIfShort (pl->last_stats.sp, pl->ob->stats.sp, CS_STAT_SP); |
972 | AddIfShort(pl->last_stats.maxsp, pl->ob->stats.maxsp, CS_STAT_MAXSP); |
1133 | AddIfShort (pl->last_stats.maxsp, pl->ob->stats.maxsp, CS_STAT_MAXSP); |
973 | AddIfShort(pl->last_stats.grace, pl->ob->stats.grace, CS_STAT_GRACE); |
1134 | AddIfShort (pl->last_stats.grace, pl->ob->stats.grace, CS_STAT_GRACE); |
974 | AddIfShort(pl->last_stats.maxgrace, pl->ob->stats.maxgrace, CS_STAT_MAXGRACE); |
1135 | AddIfShort (pl->last_stats.maxgrace, pl->ob->stats.maxgrace, CS_STAT_MAXGRACE); |
975 | AddIfShort(pl->last_stats.Str, pl->ob->stats.Str, CS_STAT_STR); |
1136 | AddIfShort (pl->last_stats.Str, pl->ob->stats.Str, CS_STAT_STR); |
976 | AddIfShort(pl->last_stats.Int, pl->ob->stats.Int, CS_STAT_INT); |
1137 | AddIfShort (pl->last_stats.Int, pl->ob->stats.Int, CS_STAT_INT); |
977 | AddIfShort(pl->last_stats.Pow, pl->ob->stats.Pow, CS_STAT_POW); |
1138 | AddIfShort (pl->last_stats.Pow, pl->ob->stats.Pow, CS_STAT_POW); |
978 | AddIfShort(pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
1139 | AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
979 | AddIfShort(pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1140 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
980 | AddIfShort(pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
1141 | AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
981 | AddIfShort(pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1142 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
982 | } |
|
|
983 | if(pl->socket.exp64) { |
|
|
984 | uint8 s; |
|
|
985 | for(s=0;s<NUM_SKILLS;s++) { |
|
|
986 | if (pl->last_skill_ob[s] && |
|
|
987 | pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) { |
|
|
988 | |
|
|
989 | /* Always send along the level if exp changes. This is only |
|
|
990 | * 1 extra byte, but keeps processing simpler. |
|
|
991 | */ |
|
|
992 | SockList_AddChar(&sl, ( char )( s + CS_STAT_SKILLINFO )); |
|
|
993 | SockList_AddChar(&sl, ( char )pl->last_skill_ob[s]->level); |
|
|
994 | SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
|
|
995 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
|
|
996 | } |
1143 | } |
997 | } |
|
|
998 | } |
|
|
999 | if (pl->socket.exp64) { |
1144 | if (pl->socket.exp64) |
|
|
1145 | { |
|
|
1146 | uint8 s; |
|
|
1147 | |
|
|
1148 | for (s = 0; s < NUM_SKILLS; s++) |
|
|
1149 | { |
|
|
1150 | if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) |
|
|
1151 | { |
|
|
1152 | |
|
|
1153 | /* Always send along the level if exp changes. This is only |
|
|
1154 | * 1 extra byte, but keeps processing simpler. |
|
|
1155 | */ |
|
|
1156 | SockList_AddChar (&sl, (char) (s + CS_STAT_SKILLINFO)); |
|
|
1157 | SockList_AddChar (&sl, (char) pl->last_skill_ob[s]->level); |
|
|
1158 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
|
|
1159 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
|
|
1160 | } |
|
|
1161 | } |
|
|
1162 | } |
|
|
1163 | if (pl->socket.exp64) |
|
|
1164 | { |
1000 | AddIfInt64(pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1165 | AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1001 | } else { |
1166 | } |
|
|
1167 | else |
|
|
1168 | { |
1002 | AddIfInt(pl->last_stats.exp, ( int )pl->ob->stats.exp, CS_STAT_EXP); |
1169 | AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP); |
1003 | } |
1170 | } |
1004 | AddIfShort(pl->last_level, ( char )pl->ob->level, CS_STAT_LEVEL); |
1171 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1005 | AddIfShort(pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1172 | AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1006 | AddIfShort(pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1173 | AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1007 | AddIfShort(pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1174 | AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1008 | AddIfFloat(pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1175 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1009 | AddIfShort(pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
1176 | AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
1010 | AddIfFloat(pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); |
1177 | AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); |
1011 | AddIfInt(pl->last_weight_limit, (sint32)weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); |
1178 | AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); |
1012 | flags=0; |
1179 | flags = 0; |
1013 | if (pl->fire_on) flags |=SF_FIREON; |
1180 | if (pl->fire_on) |
1014 | if (pl->run_on) flags |= SF_RUNON; |
1181 | flags |= SF_FIREON; |
|
|
1182 | if (pl->run_on) |
|
|
1183 | flags |= SF_RUNON; |
1015 | |
1184 | |
1016 | AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
1185 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1017 | if (pl->socket.sc_version<1025) { |
1186 | if (pl->socket.sc_version < 1025) |
|
|
1187 | { |
1018 | AddIfShort(pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1188 | AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1019 | } else { |
1189 | } |
1020 | int i; |
1190 | else |
|
|
1191 | { |
|
|
1192 | int i; |
1021 | |
1193 | |
1022 | for (i=0; i<NROFATTACKS; i++) { |
1194 | for (i = 0; i < NROFATTACKS; i++) |
|
|
1195 | { |
1023 | /* Skip ones we won't send */ |
1196 | /* Skip ones we won't send */ |
1024 | if (atnr_cs_stat[i]==-1) continue; |
1197 | if (atnr_cs_stat[i] == -1) |
|
|
1198 | continue; |
1025 | AddIfShort(pl->last_resist[i], pl->ob->resist[i], ( char )atnr_cs_stat[i]); |
1199 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1026 | } |
1200 | } |
1027 | } |
1201 | } |
1028 | if (pl->socket.monitor_spells) { |
1202 | if (pl->socket.monitor_spells) |
|
|
1203 | { |
1029 | AddIfInt(pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1204 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1030 | AddIfInt(pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1205 | AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1031 | AddIfInt(pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1206 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1032 | } |
1207 | } |
1033 | rangetostring(pl->ob, buf); /* we want use the new fire & run system in new client */ |
1208 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1034 | AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
1209 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1035 | set_title(pl->ob, buf); |
1210 | set_title (pl->ob, buf); |
1036 | AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
1211 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1037 | |
1212 | |
1038 | /* Only send it away if we have some actual data */ |
1213 | /* Only send it away if we have some actual data */ |
1039 | if (sl.len>6) { |
1214 | if (sl.len > 6) |
|
|
1215 | { |
1040 | #ifdef ESRV_DEBUG |
1216 | #ifdef ESRV_DEBUG |
1041 | LOG(llevDebug,"Sending stats command, %d bytes long.\n", sl.len); |
1217 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1042 | #endif |
1218 | #endif |
1043 | Send_With_Handling(&pl->socket, &sl); |
1219 | Send_With_Handling (&pl->socket, &sl); |
1044 | } |
1220 | } |
1045 | free(sl.buf); |
1221 | free (sl.buf); |
1046 | } |
1222 | } |
1047 | |
1223 | |
1048 | |
1224 | |
1049 | /** |
1225 | /** |
1050 | * Tells the client that here is a player it should start using. |
1226 | * Tells the client that here is a player it should start using. |
1051 | */ |
1227 | */ |
|
|
1228 | void |
1052 | void esrv_new_player(player *pl, uint32 weight) |
1229 | esrv_new_player (player *pl, uint32 weight) |
1053 | { |
1230 | { |
1054 | SockList sl; |
1231 | SockList sl; |
1055 | |
1232 | |
1056 | pl->last_weight = weight; |
1233 | pl->last_weight = weight; |
1057 | |
1234 | |
1058 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1235 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1059 | |
1236 | |
1060 | strcpy((char*)sl.buf,"player "); |
1237 | strcpy ((char *) sl.buf, "player "); |
1061 | sl.len=strlen((char*)sl.buf); |
1238 | sl.len = strlen ((char *) sl.buf); |
1062 | SockList_AddInt(&sl, pl->ob->count); |
1239 | SockList_AddInt (&sl, pl->ob->count); |
1063 | SockList_AddInt(&sl, weight); |
1240 | SockList_AddInt (&sl, weight); |
1064 | SockList_AddInt(&sl, pl->ob->face->number); |
1241 | SockList_AddInt (&sl, pl->ob->face->number); |
1065 | |
1242 | |
1066 | SockList_AddChar(&sl, ( char )strlen(pl->ob->name)); |
1243 | SockList_AddChar (&sl, (char) strlen (pl->ob->name)); |
1067 | strcpy((char*)sl.buf+sl.len, pl->ob->name); |
1244 | strcpy ((char *) sl.buf + sl.len, pl->ob->name); |
1068 | sl.len += strlen(pl->ob->name); |
1245 | sl.len += strlen (pl->ob->name); |
1069 | |
1246 | |
1070 | Send_With_Handling(&pl->socket, &sl); |
1247 | Send_With_Handling (&pl->socket, &sl); |
1071 | free(sl.buf); |
1248 | free (sl.buf); |
1072 | SET_FLAG(pl->ob, FLAG_CLIENT_SENT); |
1249 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1073 | } |
1250 | } |
1074 | |
1251 | |
1075 | |
1252 | |
1076 | /** |
1253 | /** |
1077 | * Need to send an animation sequence to the client. |
1254 | * Need to send an animation sequence to the client. |
1078 | * We will send appropriate face commands to the client if we haven't |
1255 | * We will send appropriate face commands to the client if we haven't |
1079 | * sent them the face yet (this can become quite costly in terms of |
1256 | * sent them the face yet (this can become quite costly in terms of |
1080 | * how much we are sending - on the other hand, this should only happen |
1257 | * how much we are sending - on the other hand, this should only happen |
1081 | * when the player logs in and picks stuff up. |
1258 | * when the player logs in and picks stuff up. |
1082 | */ |
1259 | */ |
|
|
1260 | void |
1083 | void esrv_send_animation(NewSocket *ns, short anim_num) |
1261 | esrv_send_animation (NewSocket * ns, short anim_num) |
1084 | { |
1262 | { |
1085 | SockList sl; |
1263 | SockList sl; |
1086 | int i; |
1264 | int i; |
1087 | |
1265 | |
1088 | /* Do some checking on the anim_num we got. Note that the animations |
1266 | /* Do some checking on the anim_num we got. Note that the animations |
1089 | * are added in contigous order, so if the number is in the valid |
1267 | * are added in contigous order, so if the number is in the valid |
1090 | * range, it must be a valid animation. |
1268 | * range, it must be a valid animation. |
1091 | */ |
1269 | */ |
1092 | if (anim_num < 0 || anim_num > num_animations) { |
1270 | if (anim_num < 0 || anim_num > num_animations) |
|
|
1271 | { |
1093 | LOG(llevError,"esrv_send_anim (%d) out of bounds??\n",anim_num); |
1272 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
1094 | return; |
1273 | return; |
1095 | } |
1274 | } |
1096 | |
1275 | |
1097 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
1276 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1098 | strcpy((char*)sl.buf, "anim "); |
1277 | strcpy ((char *) sl.buf, "anim "); |
1099 | sl.len=5; |
1278 | sl.len = 5; |
1100 | SockList_AddShort(&sl, anim_num); |
1279 | SockList_AddShort (&sl, anim_num); |
1101 | SockList_AddShort(&sl, 0); /* flags - not used right now */ |
1280 | SockList_AddShort (&sl, 0); /* flags - not used right now */ |
1102 | /* Build up the list of faces. Also, send any information (ie, the |
1281 | /* Build up the list of faces. Also, send any information (ie, the |
1103 | * the face itself) down to the client. |
1282 | * the face itself) down to the client. |
1104 | */ |
1283 | */ |
1105 | for (i=0; i<animations[anim_num].num_animations; i++) { |
1284 | for (i = 0; i < animations[anim_num].num_animations; i++) |
|
|
1285 | { |
1106 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1286 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1107 | esrv_send_face(ns,animations[anim_num].faces[i],0); |
1287 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1108 | SockList_AddShort(&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1288 | SockList_AddShort (&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1109 | } |
1289 | } |
1110 | Send_With_Handling(ns, &sl); |
1290 | Send_With_Handling (ns, &sl); |
1111 | free(sl.buf); |
1291 | free (sl.buf); |
1112 | ns->anims_sent[anim_num] = 1; |
1292 | ns->anims_sent[anim_num] = 1; |
1113 | } |
1293 | } |
1114 | |
1294 | |
1115 | |
1295 | |
1116 | /****************************************************************************** |
1296 | /****************************************************************************** |
1117 | * |
1297 | * |
… | |
… | |
1121 | |
1301 | |
1122 | /** |
1302 | /** |
1123 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1303 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1124 | * the face yet, we will also send it. |
1304 | * the face yet, we will also send it. |
1125 | */ |
1305 | */ |
1126 | static void esrv_map_setbelow(NewSocket *ns, int x,int y, |
1306 | static void |
1127 | short face_num, struct Map *newmap) |
1307 | esrv_map_setbelow (NewSocket * ns, int x, int y, short face_num, struct Map *newmap) |
1128 | { |
1308 | { |
1129 | if(newmap->cells[x][y].count >= MAP_LAYERS) { |
1309 | if (newmap->cells[x][y].count >= MAP_LAYERS) |
|
|
1310 | { |
1130 | LOG(llevError,"Too many faces in map cell %d %d\n",x,y); |
1311 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1131 | return; |
1312 | return; |
1132 | abort(); |
1313 | abort (); |
1133 | } |
1314 | } |
1134 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1315 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1135 | newmap->cells[x][y].count ++; |
1316 | newmap->cells[x][y].count++; |
1136 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1317 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1137 | esrv_send_face(ns,face_num,0); |
1318 | esrv_send_face (ns, face_num, 0); |
1138 | } |
1319 | } |
1139 | |
1320 | |
1140 | struct LayerCell { |
1321 | struct LayerCell |
|
|
1322 | { |
1141 | uint16 xy; |
1323 | uint16 xy; |
1142 | short face; |
1324 | short face; |
1143 | }; |
1325 | }; |
1144 | |
1326 | |
1145 | struct MapLayer { |
1327 | struct MapLayer |
|
|
1328 | { |
1146 | int count; |
1329 | int count; |
1147 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1330 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1148 | }; |
1331 | }; |
1149 | |
1332 | |
1150 | /** Checkes if map cells have changed */ |
1333 | /** Checkes if map cells have changed */ |
|
|
1334 | static int |
1151 | static int mapcellchanged(NewSocket *ns,int i,int j, struct Map *newmap) |
1335 | mapcellchanged (NewSocket * ns, int i, int j, struct Map *newmap) |
1152 | { |
1336 | { |
1153 | int k; |
1337 | int k; |
1154 | |
1338 | |
1155 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1339 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1156 | return 1; |
1340 | return 1; |
1157 | for(k=0;k<newmap->cells[i][j].count;k++) { |
1341 | for (k = 0; k < newmap->cells[i][j].count; k++) |
1158 | if (ns->lastmap.cells[i][j].faces[k] != |
1342 | { |
1159 | newmap->cells[i][j].faces[k]) { |
1343 | if (ns->lastmap.cells[i][j].faces[k] != newmap->cells[i][j].faces[k]) |
|
|
1344 | { |
1160 | return 1; |
1345 | return 1; |
1161 | } |
1346 | } |
1162 | } |
1347 | } |
1163 | return 0; |
1348 | return 0; |
1164 | } |
1349 | } |
1165 | |
1350 | |
1166 | /** |
1351 | /** |
1167 | * Basically, what this does is pack the data into layers. |
1352 | * Basically, what this does is pack the data into layers. |
1168 | * cnum is the client number, cur is the the buffer we put all of |
1353 | * cnum is the client number, cur is the the buffer we put all of |
1169 | * this data into. we return the end of the data. layers is |
1354 | * this data into. we return the end of the data. layers is |
1170 | * how many layers of data we should back. |
1355 | * how many layers of data we should back. |
1171 | */ |
1356 | */ |
|
|
1357 | static uint8 * |
1172 | static uint8 *compactlayer(NewSocket *ns, unsigned char *cur, int numlayers, |
1358 | compactlayer (NewSocket * ns, unsigned char *cur, int numlayers, struct Map *newmap) |
1173 | struct Map *newmap) |
|
|
1174 | { |
1359 | { |
1175 | int x,y,k; |
1360 | int x, y, k; |
1176 | int face; |
1361 | int face; |
1177 | unsigned char *fcur; |
1362 | unsigned char *fcur; |
1178 | struct MapLayer layers[MAP_LAYERS]; |
1363 | struct MapLayer layers[MAP_LAYERS]; |
1179 | |
1364 | |
1180 | for(k = 0;k<MAP_LAYERS;k++) |
1365 | for (k = 0; k < MAP_LAYERS; k++) |
1181 | layers[k].count = 0; |
1366 | layers[k].count = 0; |
1182 | fcur = cur; |
1367 | fcur = cur; |
1183 | for(x=0;x<ns->mapx;x++) { |
1368 | for (x = 0; x < ns->mapx; x++) |
1184 | for(y=0;y<ns->mapy;y++) { |
1369 | { |
|
|
1370 | for (y = 0; y < ns->mapy; y++) |
|
|
1371 | { |
1185 | if (!mapcellchanged(ns,x,y,newmap)) |
1372 | if (!mapcellchanged (ns, x, y, newmap)) |
1186 | continue; |
1373 | continue; |
1187 | if (newmap->cells[x][y].count == 0) { |
1374 | if (newmap->cells[x][y].count == 0) |
|
|
1375 | { |
1188 | *cur = x*ns->mapy+y; /* mark empty space */ |
1376 | *cur = x * ns->mapy + y; /* mark empty space */ |
1189 | cur++; |
1377 | cur++; |
1190 | continue; |
1378 | continue; |
|
|
1379 | } |
|
|
1380 | for (k = 0; k < newmap->cells[x][y].count; k++) |
|
|
1381 | { |
|
|
1382 | layers[k].lcells[layers[k].count].xy = x * ns->mapy + y; |
|
|
1383 | layers[k].lcells[layers[k].count].face = newmap->cells[x][y].faces[k]; |
|
|
1384 | layers[k].count++; |
|
|
1385 | } |
|
|
1386 | } |
1191 | } |
1387 | } |
1192 | for(k=0;k<newmap->cells[x][y].count;k++) { |
|
|
1193 | layers[k].lcells[layers[k].count].xy = x*ns->mapy+y; |
|
|
1194 | layers[k].lcells[layers[k].count].face = |
|
|
1195 | newmap->cells[x][y].faces[k]; |
|
|
1196 | layers[k].count++; |
|
|
1197 | } |
|
|
1198 | } |
|
|
1199 | } |
|
|
1200 | /* If no data, return now. */ |
1388 | /* If no data, return now. */ |
1201 | if (fcur == cur && layers[0].count == 0) |
1389 | if (fcur == cur && layers[0].count == 0) |
1202 | return cur; |
|
|
1203 | *cur = 255; /* mark end of explicitly cleared cells */ |
|
|
1204 | cur++; |
|
|
1205 | /* First pack by layers. */ |
|
|
1206 | for(k=0;k<numlayers;k++) { |
|
|
1207 | if (layers[k].count == 0) |
|
|
1208 | break; /* once a layer is entirely empty, no layer below it can |
|
|
1209 | have anything in it either */ |
|
|
1210 | /* Pack by entries in thie layer */ |
|
|
1211 | for(x=0;x<layers[k].count;) { |
|
|
1212 | fcur = cur; |
|
|
1213 | *cur = layers[k].lcells[x].face >> 8; |
|
|
1214 | cur++; |
|
|
1215 | *cur = layers[k].lcells[x].face & 0xFF; |
|
|
1216 | cur++; |
|
|
1217 | face = layers[k].lcells[x].face; |
|
|
1218 | /* Now, we back the redundant data into 1 byte xy pairings */ |
|
|
1219 | for(y=x;y<layers[k].count;y++) { |
|
|
1220 | if (layers[k].lcells[y].face == face) { |
|
|
1221 | *cur = ( uint8 )layers[k].lcells[y].xy; |
|
|
1222 | cur++; |
|
|
1223 | layers[k].lcells[y].face = -1; |
|
|
1224 | } |
|
|
1225 | } |
|
|
1226 | *(cur-1) = *(cur-1) | 128; /* mark for end of xy's; 11*11 < 128 */ |
|
|
1227 | /* forward over the now redundant data */ |
|
|
1228 | while(x < layers[k].count && |
|
|
1229 | layers[k].lcells[x].face == -1) |
|
|
1230 | x++; |
|
|
1231 | } |
|
|
1232 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
|
|
1233 | } |
|
|
1234 | return cur; |
1390 | return cur; |
|
|
1391 | *cur = 255; /* mark end of explicitly cleared cells */ |
|
|
1392 | cur++; |
|
|
1393 | /* First pack by layers. */ |
|
|
1394 | for (k = 0; k < numlayers; k++) |
|
|
1395 | { |
|
|
1396 | if (layers[k].count == 0) |
|
|
1397 | break; /* once a layer is entirely empty, no layer below it can |
|
|
1398 | have anything in it either */ |
|
|
1399 | /* Pack by entries in thie layer */ |
|
|
1400 | for (x = 0; x < layers[k].count;) |
|
|
1401 | { |
|
|
1402 | fcur = cur; |
|
|
1403 | *cur = layers[k].lcells[x].face >> 8; |
|
|
1404 | cur++; |
|
|
1405 | *cur = layers[k].lcells[x].face & 0xFF; |
|
|
1406 | cur++; |
|
|
1407 | face = layers[k].lcells[x].face; |
|
|
1408 | /* Now, we back the redundant data into 1 byte xy pairings */ |
|
|
1409 | for (y = x; y < layers[k].count; y++) |
|
|
1410 | { |
|
|
1411 | if (layers[k].lcells[y].face == face) |
|
|
1412 | { |
|
|
1413 | *cur = (uint8) layers[k].lcells[y].xy; |
|
|
1414 | cur++; |
|
|
1415 | layers[k].lcells[y].face = -1; |
|
|
1416 | } |
|
|
1417 | } |
|
|
1418 | *(cur - 1) = *(cur - 1) | 128; /* mark for end of xy's; 11*11 < 128 */ |
|
|
1419 | /* forward over the now redundant data */ |
|
|
1420 | while (x < layers[k].count && layers[k].lcells[x].face == -1) |
|
|
1421 | x++; |
|
|
1422 | } |
|
|
1423 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
|
|
1424 | } |
|
|
1425 | return cur; |
1235 | } |
1426 | } |
1236 | |
1427 | |
|
|
1428 | static void |
1237 | static void esrv_map_doneredraw(NewSocket *ns, struct Map *newmap) |
1429 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1238 | { |
1430 | { |
1239 | static long frames,bytes,tbytes,tframes; |
1431 | static long frames, bytes, tbytes, tframes; |
1240 | char *cur; |
1432 | char *cur; |
1241 | SockList sl; |
1433 | SockList sl; |
1242 | |
1434 | |
1243 | |
1435 | |
1244 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1436 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1245 | strcpy((char*)sl.buf,"map "); |
1437 | strcpy ((char *) sl.buf, "map "); |
1246 | sl.len=strlen((char*)sl.buf); |
1438 | sl.len = strlen ((char *) sl.buf); |
1247 | |
1439 | |
1248 | cur = (char *) compactlayer(ns,(unsigned char*) sl.buf+sl.len,MAP_LAYERS,newmap); |
1440 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
1249 | sl.len=cur-(char*)sl.buf; |
1441 | sl.len = cur - (char *) sl.buf; |
1250 | |
1442 | |
1251 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1443 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1252 | |
1444 | |
1253 | if (sl.len>( int )strlen("map ") || ns->sent_scroll) { |
1445 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
|
|
1446 | { |
1254 | /* All of this is just accounting stuff */ |
1447 | /* All of this is just accounting stuff */ |
1255 | if (tframes>100) { |
1448 | if (tframes > 100) |
|
|
1449 | { |
1256 | tframes = tbytes = 0; |
1450 | tframes = tbytes = 0; |
1257 | } |
1451 | } |
1258 | tframes++; |
1452 | tframes++; |
1259 | frames++; |
1453 | frames++; |
1260 | tbytes += sl.len; |
1454 | tbytes += sl.len; |
1261 | bytes += sl.len; |
1455 | bytes += sl.len; |
1262 | memcpy(&ns->lastmap,newmap,sizeof(struct Map)); |
1456 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1263 | Send_With_Handling(ns, &sl); |
1457 | Send_With_Handling (ns, &sl); |
1264 | ns->sent_scroll = 0; |
1458 | ns->sent_scroll = 0; |
1265 | } |
1459 | } |
1266 | free(sl.buf); |
1460 | free (sl.buf); |
1267 | } |
1461 | } |
1268 | |
1462 | |
1269 | |
1463 | |
1270 | /** Clears a map cell */ |
1464 | /** Clears a map cell */ |
|
|
1465 | static void |
1271 | static void map_clearcell(struct MapCell *cell, int face0, int face1, int face2, int count) |
1466 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1272 | { |
1467 | { |
1273 | cell->faces[0] = face0; |
1468 | cell->faces[0] = face0; |
1274 | cell->faces[1] = face1; |
1469 | cell->faces[1] = face1; |
1275 | cell->faces[2] = face2; |
1470 | cell->faces[2] = face2; |
1276 | cell->count = count; |
1471 | cell->count = count; |
1277 | cell->stat_hp = 0; |
1472 | cell->stat_hp = 0; |
|
|
1473 | cell->player = 0; |
1278 | } |
1474 | } |
1279 | |
1475 | |
1280 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1476 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1281 | #define MAX_LAYERS 3 |
1477 | #define MAX_LAYERS 3 |
1282 | |
1478 | |
… | |
… | |
1285 | * and saves the space of allocating this in the socket object when we only |
1481 | * and saves the space of allocating this in the socket object when we only |
1286 | * need it for this cycle. If the serve is ever threaded, this needs to be |
1482 | * need it for this cycle. If the serve is ever threaded, this needs to be |
1287 | * re-examined. |
1483 | * re-examined. |
1288 | */ |
1484 | */ |
1289 | |
1485 | |
1290 | static object *heads[MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS]; |
1486 | static object *heads[MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS]; |
1291 | |
1487 | |
1292 | /** |
1488 | /** |
1293 | * Returns true if any of the heads for this |
1489 | * Returns true if any of the heads for this |
1294 | * space is set. Returns false if all are blank - this is used |
1490 | * space is set. Returns false if all are blank - this is used |
1295 | * for empty space checking. |
1491 | * for empty space checking. |
1296 | */ |
1492 | */ |
1297 | static inline int have_head(int ax, int ay) { |
1493 | static inline int |
|
|
1494 | have_head (int ax, int ay) |
|
|
1495 | { |
1298 | |
1496 | |
1299 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1497 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1300 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || |
1498 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) |
1301 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) return 1; |
|
|
1302 | return 0; |
1499 | return 1; |
|
|
1500 | return 0; |
1303 | } |
1501 | } |
1304 | |
1502 | |
1305 | /** |
1503 | /** |
1306 | * check_head is a bit simplistic version of update_space below. |
1504 | * check_head is a bit simplistic version of update_space below. |
1307 | * basically, it only checks the that the head on space ax,ay at layer |
1505 | * basically, it only checks the that the head on space ax,ay at layer |
1308 | * needs to get sent - if so, it adds the data, sending the head |
1506 | * needs to get sent - if so, it adds the data, sending the head |
1309 | * if needed, and returning 1. If this no data needs to get |
1507 | * if needed, and returning 1. If this no data needs to get |
1310 | * sent, it returns zero. |
1508 | * sent, it returns zero. |
1311 | */ |
1509 | */ |
|
|
1510 | static int |
1312 | static int check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) |
1511 | check_head (SockList & sl, NewSocket & ns, int ax, int ay, int layer) |
1313 | { |
1512 | { |
1314 | short face_num; |
1513 | short face_num; |
1315 | |
1514 | |
1316 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1515 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1317 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1516 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1318 | else |
1517 | else |
1319 | face_num = 0; |
1518 | face_num = 0; |
1320 | |
1519 | |
1321 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { |
1520 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
|
|
1521 | { |
1322 | SockList_AddShort (&sl, face_num); |
1522 | SockList_AddShort (&sl, face_num); |
1323 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1523 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1324 | esrv_send_face (&ns, face_num, 0); |
1524 | esrv_send_face (&ns, face_num, 0); |
1325 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1525 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1326 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1526 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1327 | return 1; |
1527 | return 1; |
1328 | } |
1528 | } |
1329 | |
1529 | |
1330 | return 0; /* No change */ |
1530 | return 0; /* No change */ |
1331 | } |
1531 | } |
1332 | |
1532 | |
1333 | /** |
1533 | /** |
1334 | * Removes the need to replicate the same code for each layer. |
1534 | * Removes the need to replicate the same code for each layer. |
1335 | * this returns true if this space is now in fact different than |
1535 | * this returns true if this space is now in fact different than |
… | |
… | |
1348 | * the map command, where the faces stack up. Sinces that is no longer |
1548 | * the map command, where the faces stack up. Sinces that is no longer |
1349 | * the case, it seems to make more sense to have these layer values |
1549 | * the case, it seems to make more sense to have these layer values |
1350 | * actually match. |
1550 | * actually match. |
1351 | */ |
1551 | */ |
1352 | |
1552 | |
|
|
1553 | static int |
1353 | static int update_space(SockList *sl, NewSocket *ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1554 | update_space (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1354 | { |
1555 | { |
1355 | object *ob, *head; |
1556 | object *ob, *head; |
1356 | uint16 face_num; |
1557 | uint16 face_num; |
1357 | int bx, by,i; |
1558 | int bx, by, i; |
1358 | |
1559 | |
1359 | /* If there is a multipart object stored away, treat that as more important. |
1560 | /* If there is a multipart object stored away, treat that as more important. |
1360 | * If not, then do the normal processing. |
1561 | * If not, then do the normal processing. |
1361 | */ |
1562 | */ |
1362 | |
1563 | |
1363 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1564 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1364 | |
1565 | |
1365 | /* Check to see if this head is part of the set of objects |
1566 | /* Check to see if this head is part of the set of objects |
1366 | * we would normally send for this space. If so, then |
1567 | * we would normally send for this space. If so, then |
1367 | * don't use the head value. We need to do the check |
1568 | * don't use the head value. We need to do the check |
1368 | * here and not when setting up the heads[] value for two reasons - |
1569 | * here and not when setting up the heads[] value for two reasons - |
1369 | * 1) the heads[] values will get used even if the space is not visible. |
1570 | * 1) the heads[] values will get used even if the space is not visible. |
1370 | * 2) its possible the head is not on the same map as a part, and I'd |
1571 | * 2) its possible the head is not on the same map as a part, and I'd |
1371 | * rather not need to do the map translation overhead. |
1572 | * rather not need to do the map translation overhead. |
1372 | * 3) We need to do some extra checking to make sure that we will |
1573 | * 3) We need to do some extra checking to make sure that we will |
1373 | * otherwise send the image as this layer, eg, either it matches |
1574 | * otherwise send the image as this layer, eg, either it matches |
1374 | * the head value, or is not multipart. |
1575 | * the head value, or is not multipart. |
1375 | */ |
1576 | */ |
1376 | if (head && !head->more) { |
1577 | if (head && !head->more) |
|
|
1578 | { |
1377 | for (i=0; i<MAP_LAYERS; i++) { |
1579 | for (i = 0; i < MAP_LAYERS; i++) |
|
|
1580 | { |
1378 | ob = GET_MAP_FACE_OBJ(mp, mx, my, i); |
1581 | ob = GET_MAP_FACE_OBJ (mp, mx, my, i); |
1379 | if (!ob) continue; |
1582 | if (!ob) |
|
|
1583 | continue; |
1380 | |
1584 | |
1381 | if (ob->head) ob=ob->head; |
1585 | if (ob->head) |
|
|
1586 | ob = ob->head; |
1382 | |
1587 | |
1383 | if (ob == head) { |
1588 | if (ob == head) |
|
|
1589 | { |
1384 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1590 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1385 | head = NULL; |
1591 | head = NULL; |
1386 | break; |
1592 | break; |
|
|
1593 | } |
|
|
1594 | } |
1387 | } |
1595 | } |
1388 | } |
|
|
1389 | } |
|
|
1390 | |
1596 | |
1391 | ob = head; |
1597 | ob = head; |
|
|
1598 | if (!ob) |
1392 | if (!ob) ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1599 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1393 | |
1600 | |
1394 | /* If there is no object for this space, or if the face for the object |
1601 | /* If there is no object for this space, or if the face for the object |
1395 | * is the blank face, set the face number to zero. |
1602 | * is the blank face, set the face number to zero. |
1396 | * else if we have the stored head object for this space, that takes |
1603 | * else if we have the stored head object for this space, that takes |
1397 | * precedence over the other object for this space. |
1604 | * precedence over the other object for this space. |
1398 | * otherwise, we do special head processing |
1605 | * otherwise, we do special head processing |
1399 | */ |
1606 | */ |
1400 | if (!ob || ob->face == blank_face) face_num=0; |
1607 | if (!ob || ob->face == blank_face) |
|
|
1608 | face_num = 0; |
1401 | else if (head){ |
1609 | else if (head) |
|
|
1610 | { |
1402 | /* if this is a head that had previously been stored */ |
1611 | /* if this is a head that had previously been stored */ |
1403 | face_num = ob->face->number; |
1612 | face_num = ob->face->number; |
1404 | } else { |
1613 | } |
|
|
1614 | else |
|
|
1615 | { |
1405 | /* if the faces for the different parts of a multipart object |
1616 | /* if the faces for the different parts of a multipart object |
1406 | * are the same, we only want to send the bottom right most |
1617 | * are the same, we only want to send the bottom right most |
1407 | * portion of the object. That info is in the tail_.. values |
1618 | * portion of the object. That info is in the tail_.. values |
1408 | * of the head. Note that for the head itself, ob->head will |
1619 | * of the head. Note that for the head itself, ob->head will |
1409 | * be null, so we only do this block if we are working on |
1620 | * be null, so we only do this block if we are working on |
1410 | * a tail piece. |
1621 | * a tail piece. |
1411 | */ |
1622 | */ |
1412 | |
1623 | |
1413 | /* tail_x and tail_y will only be set in the head object. If |
1624 | /* tail_x and tail_y will only be set in the head object. If |
1414 | * this is the head object and these are set, we proceed |
1625 | * this is the head object and these are set, we proceed |
1415 | * with logic to only send bottom right. Similarly, if |
1626 | * with logic to only send bottom right. Similarly, if |
1416 | * this is one of the more parts but the head has those values |
1627 | * this is one of the more parts but the head has those values |
1417 | * set, we want to do the processing. There can be cases where |
1628 | * set, we want to do the processing. There can be cases where |
1418 | * the head is not visible but one of its parts is, so we just |
1629 | * the head is not visible but one of its parts is, so we just |
1419 | * can always expect that ob->arch->tail_x will be true for all |
1630 | * can always expect that ob->arch->tail_x will be true for all |
1420 | * object we may want to display. |
1631 | * object we may want to display. |
1421 | */ |
1632 | */ |
1422 | if ((ob->arch->tail_x || ob->arch->tail_y) || |
1633 | if ((ob->arch->tail_x || ob->arch->tail_y) || (ob->head && (ob->head->arch->tail_x || ob->head->arch->tail_y))) |
1423 | (ob->head && (ob->head->arch->tail_x || ob->head->arch->tail_y))) { |
1634 | { |
1424 | |
1635 | |
1425 | if (ob->head) head = ob->head; |
1636 | if (ob->head) |
1426 | else head = ob; |
1637 | head = ob->head; |
|
|
1638 | else |
|
|
1639 | head = ob; |
1427 | |
1640 | |
1428 | /* Basically figure out where the offset is from where we are right |
1641 | /* Basically figure out where the offset is from where we are right |
1429 | * now. the ob->arch->clone.{x,y} values hold the offset that this current |
1642 | * now. the ob->arch->clone.{x,y} values hold the offset that this current |
1430 | * piece is from the head, and the tail is where the tail is from the |
1643 | * piece is from the head, and the tail is where the tail is from the |
1431 | * head. Note that bx and by will equal sx and sy if we are already working |
1644 | * head. Note that bx and by will equal sx and sy if we are already working |
1432 | * on the bottom right corner. If ob is the head, the clone values |
1645 | * on the bottom right corner. If ob is the head, the clone values |
1433 | * will be zero, so the right thing will still happen. |
1646 | * will be zero, so the right thing will still happen. |
1434 | */ |
1647 | */ |
1435 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1648 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1436 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1649 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1437 | |
1650 | |
1438 | /* I don't think this can ever happen, but better to check for it just |
1651 | /* I don't think this can ever happen, but better to check for it just |
1439 | * in case. |
1652 | * in case. |
1440 | */ |
1653 | */ |
1441 | if (bx < sx || by < sy) { |
1654 | if (bx < sx || by < sy) |
|
|
1655 | { |
1442 | LOG(llevError,"update_space: bx (%d) or by (%d) is less than sx (%d) or sy (%d)\n", |
1656 | LOG (llevError, "update_space: bx (%d) or by (%d) is less than sx (%d) or sy (%d)\n", bx, by, sx, sy); |
1443 | bx, by, sx, sy); |
1657 | face_num = 0; |
1444 | face_num = 0; |
1658 | } |
1445 | } |
|
|
1446 | /* single part object, multipart object with non merged faces, |
1659 | /* single part object, multipart object with non merged faces, |
1447 | * of multipart object already at lower right. |
1660 | * of multipart object already at lower right. |
1448 | */ |
1661 | */ |
1449 | else if (bx == sx && by == sy) { |
1662 | else if (bx == sx && by == sy) |
|
|
1663 | { |
1450 | face_num = ob->face->number; |
1664 | face_num = ob->face->number; |
1451 | |
1665 | |
1452 | /* if this face matches one stored away, clear that one away. |
1666 | /* if this face matches one stored away, clear that one away. |
1453 | * this code relies on the fact that the map1 commands |
1667 | * this code relies on the fact that the map1 commands |
1454 | * goes from 2 down to 0. |
1668 | * goes from 2 down to 0. |
1455 | */ |
1669 | */ |
1456 | for (i=0; i<MAP_LAYERS; i++) |
1670 | for (i = 0; i < MAP_LAYERS; i++) |
1457 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1671 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1458 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i]->face->number == face_num) |
1672 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i]->face->number == face_num) |
1459 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1673 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1460 | } |
1674 | } |
1461 | else { |
1675 | else |
|
|
1676 | { |
1462 | /* If this head is stored away, clear it - otherwise, |
1677 | /* If this head is stored away, clear it - otherwise, |
1463 | * there can be cases where a object is on multiple layers - |
1678 | * there can be cases where a object is on multiple layers - |
1464 | * we only want to send it once. |
1679 | * we only want to send it once. |
1465 | */ |
1680 | */ |
1466 | face_num = head->face->number; |
1681 | face_num = head->face->number; |
1467 | for (i=0; i<MAP_LAYERS; i++) |
1682 | for (i = 0; i < MAP_LAYERS; i++) |
1468 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1683 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1469 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i]->face->number == face_num) |
1684 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i]->face->number == face_num) |
1470 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1685 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1471 | |
1686 | |
1472 | /* First, try to put the new head on the same layer. If that is used up, |
1687 | /* First, try to put the new head on the same layer. If that is used up, |
1473 | * then find another layer. |
1688 | * then find another layer. |
1474 | */ |
1689 | */ |
1475 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) { |
1690 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) |
|
|
1691 | { |
1476 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1692 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1477 | } else for (i=0; i<MAX_LAYERS; i++) { |
1693 | } |
|
|
1694 | else |
|
|
1695 | for (i = 0; i < MAX_LAYERS; i++) |
|
|
1696 | { |
1478 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1697 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1479 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) { |
1698 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) |
|
|
1699 | { |
1480 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1700 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1481 | } |
1701 | } |
1482 | } |
1702 | } |
1483 | face_num = 0; /* Don't send this object - we'll send the head later */ |
1703 | face_num = 0; /* Don't send this object - we'll send the head later */ |
1484 | } |
1704 | } |
1485 | } else { |
1705 | } |
|
|
1706 | else |
|
|
1707 | { |
1486 | /* In this case, we are already at the lower right or single part object, |
1708 | /* In this case, we are already at the lower right or single part object, |
1487 | * so nothing special |
1709 | * so nothing special |
1488 | */ |
1710 | */ |
1489 | face_num = ob->face->number; |
1711 | face_num = ob->face->number; |
1490 | |
1712 | |
1491 | /* clear out any head entries that have the same face as this one */ |
1713 | /* clear out any head entries that have the same face as this one */ |
1492 | for (bx=0; bx<layer; bx++) |
1714 | for (bx = 0; bx < layer; bx++) |
1493 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1715 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1494 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx]->face->number == face_num) |
1716 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx]->face->number == face_num) |
1495 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1717 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1496 | } |
1718 | } |
1497 | } /* else not already head object or blank face */ |
1719 | } /* else not already head object or blank face */ |
1498 | |
1720 | |
1499 | /* This is a real hack. Basically, if we have nothing to send for this layer, |
1721 | /* This is a real hack. Basically, if we have nothing to send for this layer, |
1500 | * but there is a head on the next layer, send that instead. |
1722 | * but there is a head on the next layer, send that instead. |
1501 | * Without this, what happens is you can get the case where the player stands |
1723 | * Without this, what happens is you can get the case where the player stands |
1502 | * on the same space as the head. However, if you have overlapping big objects |
1724 | * on the same space as the head. However, if you have overlapping big objects |
1503 | * of the same type, what happens then is it doesn't think it needs to send |
1725 | * of the same type, what happens then is it doesn't think it needs to send |
1504 | * This tends to make stacking also work/look better. |
1726 | * This tends to make stacking also work/look better. |
1505 | */ |
1727 | */ |
1506 | if (!face_num && layer > 0 && heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]) { |
1728 | if (!face_num && layer > 0 && heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer - 1]) |
|
|
1729 | { |
1507 | face_num = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]->face->number; |
1730 | face_num = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer - 1]->face->number; |
1508 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1] = NULL; |
1731 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer - 1] = NULL; |
1509 | } |
1732 | } |
1510 | |
1733 | |
1511 | /* Another hack - because of heads and whatnot, this face may match one |
1734 | /* Another hack - because of heads and whatnot, this face may match one |
1512 | * we already sent for a lower layer. In that case, don't send |
1735 | * we already sent for a lower layer. In that case, don't send |
1513 | * this one. |
1736 | * this one. |
1514 | */ |
1737 | */ |
1515 | if (face_num && layer+1<MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer+1] == face_num) { |
1738 | if (face_num && layer + 1 < MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer + 1] == face_num) |
1516 | face_num = 0; |
|
|
1517 | } |
1739 | { |
|
|
1740 | face_num = 0; |
|
|
1741 | } |
1518 | |
1742 | |
1519 | /* We've gotten what face we want to use for the object. Now see if |
1743 | /* We've gotten what face we want to use for the object. Now see if |
1520 | * if it has changed since we last sent it to the client. |
1744 | * if it has changed since we last sent it to the client. |
1521 | */ |
1745 | */ |
1522 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) { |
1746 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) |
|
|
1747 | { |
1523 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1748 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1524 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1749 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1525 | esrv_send_face(ns, face_num, 0); |
1750 | esrv_send_face (ns, face_num, 0); |
1526 | SockList_AddShort(sl, face_num); |
1751 | SockList_AddShort (sl, face_num); |
1527 | return 1; |
1752 | return 1; |
1528 | } |
1753 | } |
1529 | /* Nothing changed */ |
1754 | /* Nothing changed */ |
1530 | return 0; |
1755 | return 0; |
1531 | } |
1756 | } |
1532 | |
1757 | |
1533 | /** |
1758 | /** |
1534 | * This function is mainly a copy of update_space, |
1759 | * This function is mainly a copy of update_space, |
1535 | * except it handles update of the smoothing updates, |
1760 | * except it handles update of the smoothing updates, |
… | |
… | |
1547 | * layer is the layer to update, with 2 being the floor and 0 the |
1772 | * layer is the layer to update, with 2 being the floor and 0 the |
1548 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1773 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1549 | * take. |
1774 | * take. |
1550 | */ |
1775 | */ |
1551 | |
1776 | |
|
|
1777 | static inline int |
1552 | static inline int update_smooth(SockList *sl, NewSocket *ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1778 | update_smooth (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1553 | { |
1779 | { |
1554 | object *ob; |
1780 | object *ob; |
1555 | int smoothlevel; /* old face_num;*/ |
1781 | int smoothlevel; /* old face_num; */ |
1556 | |
1782 | |
1557 | ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1783 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1558 | |
1784 | |
1559 | /* If there is no object for this space, or if the face for the object |
1785 | /* If there is no object for this space, or if the face for the object |
1560 | * is the blank face, set the smoothlevel to zero. |
1786 | * is the blank face, set the smoothlevel to zero. |
1561 | */ |
1787 | */ |
1562 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH(mp)) smoothlevel=0; |
1788 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) |
|
|
1789 | smoothlevel = 0; |
1563 | else { |
1790 | else |
|
|
1791 | { |
1564 | smoothlevel = ob->smoothlevel; |
1792 | smoothlevel = ob->smoothlevel; |
1565 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1793 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1566 | SendSmooth(ns, ob->face->number); |
1794 | SendSmooth (ns, ob->face->number); |
1567 | } /* else not already head object or blank face */ |
1795 | } /* else not already head object or blank face */ |
1568 | |
1796 | |
1569 | /* We've gotten what face we want to use for the object. Now see if |
1797 | /* We've gotten what face we want to use for the object. Now see if |
1570 | * if it has changed since we last sent it to the client. |
1798 | * if it has changed since we last sent it to the client. |
1571 | */ |
1799 | */ |
1572 | if (smoothlevel>255) |
1800 | if (smoothlevel > 255) |
1573 | smoothlevel=255; |
1801 | smoothlevel = 255; |
1574 | else if (smoothlevel<0) |
1802 | else if (smoothlevel < 0) |
1575 | smoothlevel=0; |
1803 | smoothlevel = 0; |
1576 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) { |
1804 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) |
|
|
1805 | { |
1577 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1806 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1578 | SockList_AddChar(sl, (uint8) (smoothlevel&0xFF)); |
1807 | SockList_AddChar (sl, (uint8) (smoothlevel & 0xFF)); |
1579 | return 1; |
1808 | return 1; |
1580 | } |
1809 | } |
1581 | /* Nothing changed */ |
1810 | /* Nothing changed */ |
1582 | return 0; |
1811 | return 0; |
1583 | } |
1812 | } |
1584 | |
1813 | |
1585 | /** |
1814 | /** |
1586 | * Returns the size of a data for a map square as returned by |
1815 | * Returns the size of a data for a map square as returned by |
1587 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1816 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1588 | * available. |
1817 | * available. |
1589 | */ |
1818 | */ |
|
|
1819 | int |
1590 | int getExtendedMapInfoSize(NewSocket* ns){ |
1820 | getExtendedMapInfoSize (NewSocket * ns) |
|
|
1821 | { |
1591 | int result=0; |
1822 | int result = 0; |
|
|
1823 | |
1592 | if (ns->ext_mapinfos){ |
1824 | if (ns->ext_mapinfos) |
|
|
1825 | { |
1593 | if (ns->EMI_smooth) |
1826 | if (ns->EMI_smooth) |
1594 | result+=1; /*One byte for smoothlevel*/ |
1827 | result += 1; /*One byte for smoothlevel */ |
1595 | } |
1828 | } |
1596 | return result; |
1829 | return result; |
1597 | } |
1830 | } |
|
|
1831 | |
1598 | /** |
1832 | /** |
1599 | * This function uses the new map1 protocol command to send the map |
1833 | * This function uses the new map1 protocol command to send the map |
1600 | * to the client. It is necessary because the old map command supports |
1834 | * to the client. It is necessary because the old map command supports |
1601 | * a maximum map size of 15x15. |
1835 | * a maximum map size of 15x15. |
1602 | * This function is much simpler than the old one. This is because |
1836 | * This function is much simpler than the old one. This is because |
… | |
… | |
1615 | * we use the count value to hold the darkness value. If -1, then this space |
1849 | * we use the count value to hold the darkness value. If -1, then this space |
1616 | * is not viewable. |
1850 | * is not viewable. |
1617 | * we use faces[0] faces[1] faces[2] to hold what the three layers |
1851 | * we use faces[0] faces[1] faces[2] to hold what the three layers |
1618 | * look like. |
1852 | * look like. |
1619 | */ |
1853 | */ |
|
|
1854 | void |
1620 | void draw_client_map1(object *pl) |
1855 | draw_client_map1 (object *pl) |
1621 | { |
1856 | { |
1622 | int x,y,ax, ay, d, startlen, max_x, max_y, oldlen; |
1857 | int x, y, ax, ay, d, startlen, max_x, max_y, oldlen; |
1623 | sint16 nx, ny; |
1858 | sint16 nx, ny; |
1624 | int estartlen, eoldlen; |
1859 | int estartlen, eoldlen; |
1625 | SockList sl; |
1860 | SockList sl; |
1626 | SockList esl; /*For extended Map info*/ |
1861 | SockList esl; /*For extended Map info */ |
1627 | uint16 mask,emask; |
1862 | uint16 mask, emask; |
1628 | uint8 eentrysize; |
1863 | uint8 eentrysize; |
1629 | uint16 ewhatstart,ewhatflag; |
1864 | uint16 ewhatstart, ewhatflag; |
1630 | uint8 extendedinfos; |
1865 | uint8 extendedinfos; |
1631 | mapstruct *m; |
1866 | mapstruct *m; |
|
|
1867 | |
1632 | NewSocket &socket = pl->contr->socket; |
1868 | NewSocket & socket = pl->contr->socket; |
1633 | |
1869 | |
1634 | check_map_change (pl->contr); |
1870 | check_map_change (pl->contr); |
1635 | |
1871 | |
1636 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1872 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1637 | if (socket.mapmode == Map1Cmd) |
1873 | if (socket.mapmode == Map1Cmd) |
1638 | strcpy((char*)sl.buf,"map1 "); |
1874 | strcpy ((char *) sl.buf, "map1 "); |
1639 | else |
1875 | else |
1640 | strcpy((char*)sl.buf,"map1a "); |
1876 | strcpy ((char *) sl.buf, "map1a "); |
1641 | sl.len=strlen((char*)sl.buf); |
1877 | sl.len = strlen ((char *) sl.buf); |
1642 | startlen = sl.len; |
1878 | startlen = sl.len; |
1643 | /*Extendedmapinfo structure initialisation*/ |
1879 | /*Extendedmapinfo structure initialisation */ |
1644 | if (socket.ext_mapinfos){ |
1880 | if (socket.ext_mapinfos) |
|
|
1881 | { |
1645 | esl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1882 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1646 | strcpy((char*)esl.buf,"mapextended "); |
1883 | strcpy ((char *) esl.buf, "mapextended "); |
1647 | esl.len=strlen((char*)esl.buf); |
1884 | esl.len = strlen ((char *) esl.buf); |
1648 | extendedinfos=EMI_NOREDRAW; |
1885 | extendedinfos = EMI_NOREDRAW; |
1649 | if (socket.EMI_smooth) |
1886 | if (socket.EMI_smooth) |
1650 | extendedinfos|=EMI_SMOOTH; |
1887 | extendedinfos |= EMI_SMOOTH; |
1651 | ewhatstart=esl.len; |
1888 | ewhatstart = esl.len; |
1652 | ewhatflag=extendedinfos; /*The EMI_NOREDRAW bit |
1889 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1653 | could need to be taken away*/ |
1890 | could need to be taken away */ |
1654 | SockList_AddChar(&esl, extendedinfos); |
1891 | SockList_AddChar (&esl, extendedinfos); |
1655 | eentrysize=getExtendedMapInfoSize(&socket); |
1892 | eentrysize = getExtendedMapInfoSize (&socket); |
1656 | SockList_AddChar(&esl, eentrysize); |
1893 | SockList_AddChar (&esl, eentrysize); |
1657 | estartlen = esl.len; |
1894 | estartlen = esl.len; |
1658 | } else { |
1895 | } |
|
|
1896 | else |
|
|
1897 | { |
1659 | /* suppress compiler warnings */ |
1898 | /* suppress compiler warnings */ |
1660 | ewhatstart = 0; |
1899 | ewhatstart = 0; |
1661 | ewhatflag = 0; |
1900 | ewhatflag = 0; |
1662 | estartlen = 0; |
1901 | estartlen = 0; |
1663 | } |
1902 | } |
1664 | /* Init data to zero */ |
1903 | /* Init data to zero */ |
1665 | memset(heads, 0, sizeof(object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1904 | memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1666 | |
1905 | |
1667 | /* x,y are the real map locations. ax, ay are viewport relative |
1906 | /* x,y are the real map locations. ax, ay are viewport relative |
1668 | * locations. |
1907 | * locations. |
1669 | */ |
1908 | */ |
1670 | ay=0; |
1909 | ay = 0; |
1671 | |
1910 | |
1672 | /* We could do this logic as conditionals in the if statement, |
1911 | /* We could do this logic as conditionals in the if statement, |
1673 | * but that started to get a bit messy to look at. |
1912 | * but that started to get a bit messy to look at. |
1674 | */ |
1913 | */ |
1675 | max_x = pl->x+(socket.mapx+1)/2; |
1914 | max_x = pl->x + (socket.mapx + 1) / 2; |
1676 | max_y = pl->y+(socket.mapy+1)/2; |
1915 | max_y = pl->y + (socket.mapy + 1) / 2; |
1677 | if (socket.mapmode == Map1aCmd) { |
1916 | if (socket.mapmode == Map1aCmd) |
|
|
1917 | { |
1678 | max_x += MAX_HEAD_OFFSET; |
1918 | max_x += MAX_HEAD_OFFSET; |
1679 | max_y += MAX_HEAD_OFFSET; |
1919 | max_y += MAX_HEAD_OFFSET; |
1680 | } |
1920 | } |
1681 | |
1921 | |
1682 | for(y=pl->y-socket.mapy/2; y<max_y; y++,ay++) { |
1922 | for (y = pl->y - socket.mapy / 2; y < max_y; y++, ay++) |
1683 | ax=0; |
1923 | { |
|
|
1924 | ax = 0; |
1684 | for(x=pl->x-socket.mapx/2;x<max_x;x++,ax++) { |
1925 | for (x = pl->x - socket.mapx / 2; x < max_x; x++, ax++) |
|
|
1926 | { |
1685 | |
1927 | |
1686 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1928 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1687 | |
1929 | |
1688 | /* If this space is out of the normal viewable area, we only check |
1930 | /* If this space is out of the normal viewable area, we only check |
1689 | * the heads value ax or ay will only be greater than what |
1931 | * the heads value ax or ay will only be greater than what |
1690 | * the client wants if using the map1a command - this is because |
1932 | * the client wants if using the map1a command - this is because |
1691 | * if the map1a command is not used, max_x and max_y will be |
1933 | * if the map1a command is not used, max_x and max_y will be |
1692 | * set to lower values. |
1934 | * set to lower values. |
1693 | */ |
1935 | */ |
1694 | if (ax >= socket.mapx || ay >= socket.mapy) { |
1936 | if (ax >= socket.mapx || ay >= socket.mapy) |
1695 | int i, got_one; |
1937 | { |
|
|
1938 | int i, got_one; |
1696 | |
1939 | |
1697 | oldlen = sl.len; |
1940 | oldlen = sl.len; |
1698 | |
1941 | |
1699 | SockList_AddShort(&sl, mask); |
1942 | SockList_AddShort (&sl, mask); |
1700 | |
1943 | |
1701 | if (check_head (sl, socket, ax, ay, 2)) |
1944 | if (check_head (sl, socket, ax, ay, 2)) |
1702 | mask |= 0x4; |
1945 | mask |= 0x4; |
1703 | if (check_head (sl, socket, ax, ay, 1)) |
1946 | if (check_head (sl, socket, ax, ay, 1)) |
1704 | mask |= 0x2; |
1947 | mask |= 0x2; |
1705 | if (check_head (sl, socket, ax, ay, 0)) |
1948 | if (check_head (sl, socket, ax, ay, 0)) |
1706 | mask |= 0x1; |
1949 | mask |= 0x1; |
1707 | |
1950 | |
1708 | /* If all we are doing is sending 0 (blank) faces, we don't |
1951 | /* If all we are doing is sending 0 (blank) faces, we don't |
1709 | * actually need to send that - just the coordinates |
1952 | * actually need to send that - just the coordinates |
1710 | * with no faces tells the client to blank out the |
1953 | * with no faces tells the client to blank out the |
1711 | * space. |
1954 | * space. |
1712 | */ |
1955 | */ |
1713 | got_one=0; |
1956 | got_one = 0; |
1714 | for (i=oldlen+2; i<sl.len; i++) { |
1957 | for (i = oldlen + 2; i < sl.len; i++) |
1715 | if (sl.buf[i]) got_one=1; |
1958 | { |
1716 | } |
1959 | if (sl.buf[i]) |
|
|
1960 | got_one = 1; |
|
|
1961 | } |
1717 | |
1962 | |
1718 | if (got_one && (mask & 0xf)) { |
1963 | if (got_one && (mask & 0xf)) |
|
|
1964 | { |
1719 | sl.buf[oldlen+1] = mask & 0xff; |
1965 | sl.buf[oldlen + 1] = mask & 0xff; |
1720 | } else { /*either all faces blank, either no face at all*/ |
1966 | } |
|
|
1967 | else |
|
|
1968 | { /*either all faces blank, either no face at all */ |
1721 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates*/ |
1969 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1722 | sl.len = oldlen + 2; |
1970 | sl.len = oldlen + 2; |
1723 | else |
1971 | else |
1724 | sl.len = oldlen; |
1972 | sl.len = oldlen; |
1725 | } |
1973 | } |
1726 | /*What concerns extendinfos, nothing to be done for now |
1974 | /*What concerns extendinfos, nothing to be done for now |
1727 | * (perhaps effects layer later) |
1975 | * (perhaps effects layer later) |
1728 | */ |
1976 | */ |
1729 | continue; /* don't do processing below */ |
1977 | continue; /* don't do processing below */ |
1730 | } |
1978 | } |
1731 | |
1979 | |
1732 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1980 | MapCell & lastcell = socket.lastmap.cells[ax][ay]; |
1733 | |
1981 | |
1734 | d = pl->contr->blocked_los[ax][ay]; |
1982 | d = pl->contr->blocked_los[ax][ay]; |
1735 | |
1983 | |
1736 | /* If the coordinates are not valid, or it is too dark to see, |
1984 | /* If the coordinates are not valid, or it is too dark to see, |
1737 | * we tell the client as such |
1985 | * we tell the client as such |
1738 | */ |
1986 | */ |
1739 | nx=x; |
1987 | nx = x; |
1740 | ny=y; |
1988 | ny = y; |
1741 | m = get_map_from_coord(pl->map, &nx, &ny); |
1989 | m = get_map_from_coord (pl->map, &nx, &ny); |
1742 | if (!m) { |
1990 | if (!m) |
|
|
1991 | { |
1743 | /* space is out of map. Update space and clear values |
1992 | /* space is out of map. Update space and clear values |
1744 | * if this hasn't already been done. If the space is out |
1993 | * if this hasn't already been done. If the space is out |
1745 | * of the map, it shouldn't have a head |
1994 | * of the map, it shouldn't have a head |
1746 | */ |
1995 | */ |
1747 | if (lastcell.count != -1) { |
1996 | if (lastcell.count != -1) |
1748 | SockList_AddShort(&sl, mask); |
1997 | { |
1749 | map_clearcell(&lastcell,0,0,0,-1); |
|
|
1750 | } |
|
|
1751 | } else if (d>3) { |
|
|
1752 | int need_send=0, count; |
|
|
1753 | /* This block deals with spaces that are not visible for whatever |
|
|
1754 | * reason. Still may need to send the head for this space. |
|
|
1755 | */ |
|
|
1756 | |
|
|
1757 | oldlen = sl.len; |
|
|
1758 | |
|
|
1759 | SockList_AddShort(&sl, mask); |
1998 | SockList_AddShort (&sl, mask); |
|
|
1999 | map_clearcell (&lastcell, 0, 0, 0, -1); |
|
|
2000 | } |
|
|
2001 | } |
|
|
2002 | else if (d > 3) |
|
|
2003 | { |
|
|
2004 | int need_send = 0, count; |
|
|
2005 | |
|
|
2006 | /* This block deals with spaces that are not visible for whatever |
|
|
2007 | * reason. Still may need to send the head for this space. |
|
|
2008 | */ |
|
|
2009 | |
|
|
2010 | oldlen = sl.len; |
|
|
2011 | |
|
|
2012 | SockList_AddShort (&sl, mask); |
1760 | if (lastcell.count != -1) need_send=1; |
2013 | if (lastcell.count != -1) |
|
|
2014 | need_send = 1; |
1761 | count = -1; |
2015 | count = -1; |
1762 | |
2016 | |
1763 | if (socket.mapmode == Map1aCmd && have_head(ax, ay)) { |
2017 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
|
|
2018 | { |
1764 | /* Now check to see if any heads need to be sent */ |
2019 | /* Now check to see if any heads need to be sent */ |
1765 | |
2020 | |
1766 | if (check_head (sl, socket, ax, ay, 2)) |
2021 | if (check_head (sl, socket, ax, ay, 2)) |
1767 | mask |= 0x4; |
2022 | mask |= 0x4; |
1768 | if (check_head (sl, socket, ax, ay, 1)) |
2023 | if (check_head (sl, socket, ax, ay, 1)) |
1769 | mask |= 0x2; |
2024 | mask |= 0x2; |
1770 | if (check_head (sl, socket, ax, ay, 0)) |
2025 | if (check_head (sl, socket, ax, ay, 0)) |
1771 | mask |= 0x1; |
2026 | mask |= 0x1; |
1772 | |
2027 | |
1773 | lastcell.count = count; |
2028 | lastcell.count = count; |
1774 | |
2029 | |
1775 | } else { |
2030 | } |
|
|
2031 | else |
|
|
2032 | { |
1776 | struct MapCell *cell = &lastcell; |
2033 | struct MapCell *cell = &lastcell; |
|
|
2034 | |
1777 | /* properly clear a previously sent big face */ |
2035 | /* properly clear a previously sent big face */ |
1778 | if(cell->faces[0] != 0 |
2036 | if (cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) |
1779 | || cell->faces[1] != 0 |
2037 | need_send = 1; |
1780 | || cell->faces[2] != 0) |
|
|
1781 | need_send = 1; |
|
|
1782 | map_clearcell(&lastcell, 0, 0, 0, count); |
2038 | map_clearcell (&lastcell, 0, 0, 0, count); |
1783 | } |
2039 | } |
1784 | |
2040 | |
1785 | if ((mask & 0xf) || need_send) { |
2041 | if ((mask & 0xf) || need_send) |
|
|
2042 | { |
1786 | sl.buf[oldlen+1] = mask & 0xff; |
2043 | sl.buf[oldlen + 1] = mask & 0xff; |
1787 | } else { |
2044 | } |
1788 | sl.len = oldlen; |
2045 | else |
1789 | } |
2046 | { |
1790 | } else { |
2047 | sl.len = oldlen; |
|
|
2048 | } |
|
|
2049 | } |
|
|
2050 | else |
|
|
2051 | { |
1791 | /* In this block, the space is visible or there are head objects |
2052 | /* In this block, the space is visible or there are head objects |
1792 | * we need to send. |
2053 | * we need to send. |
1793 | */ |
2054 | */ |
1794 | |
2055 | |
1795 | /* Rather than try to figure out what everything that we might |
2056 | /* Rather than try to figure out what everything that we might |
1796 | * need to send is, then form the packet after that, |
2057 | * need to send is, then form the packet after that, |
1797 | * we presume that we will in fact form a packet, and update |
2058 | * we presume that we will in fact form a packet, and update |
1798 | * the bits by what we do actually send. If we send nothing, |
2059 | * the bits by what we do actually send. If we send nothing, |
1799 | * we just back out sl.len to the old value, and no harm |
2060 | * we just back out sl.len to the old value, and no harm |
1800 | * is done. |
2061 | * is done. |
1801 | * I think this is simpler than doing a bunch of checks to see |
2062 | * I think this is simpler than doing a bunch of checks to see |
1802 | * what if anything we need to send, setting the bits, then |
2063 | * what if anything we need to send, setting the bits, then |
1803 | * doing those checks again to add the real data. |
2064 | * doing those checks again to add the real data. |
1804 | */ |
2065 | */ |
1805 | oldlen = sl.len; |
2066 | oldlen = sl.len; |
1806 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2067 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1807 | eoldlen = esl.len; |
2068 | eoldlen = esl.len; |
1808 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2069 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1809 | SockList_AddShort(&sl, mask); |
2070 | SockList_AddShort (&sl, mask); |
1810 | |
2071 | |
1811 | if (socket.ext_mapinfos) |
2072 | if (socket.ext_mapinfos) |
1812 | SockList_AddShort(&esl, emask); |
2073 | SockList_AddShort (&esl, emask); |
1813 | |
2074 | |
1814 | unsigned char dummy; |
2075 | unsigned char dummy; |
1815 | unsigned char *last_ext = &dummy; |
2076 | unsigned char *last_ext = &dummy; |
1816 | |
2077 | |
1817 | /* Darkness changed */ |
2078 | /* Darkness changed */ |
1818 | if (lastcell.count != d && socket.darkness) { |
2079 | if (lastcell.count != d && socket.darkness) |
1819 | mask |= 0x8; |
2080 | { |
|
|
2081 | mask |= 0x8; |
1820 | |
2082 | |
1821 | if (socket.extmap) |
2083 | if (socket.extmap) |
|
|
2084 | { |
|
|
2085 | *last_ext |= 0x80; |
|
|
2086 | last_ext = sl.buf + sl.len; |
|
|
2087 | SockList_AddChar (&sl, d); |
|
|
2088 | } |
|
|
2089 | else |
|
|
2090 | SockList_AddChar (&sl, 255 - 64 * d); |
|
|
2091 | } |
|
|
2092 | |
|
|
2093 | lastcell.count = d; |
|
|
2094 | |
|
|
2095 | if (socket.extmap) |
|
|
2096 | { |
|
|
2097 | uint8 stat_hp = 0; |
|
|
2098 | uint8 stat_width = 0; |
|
|
2099 | tag_t player = 0; |
|
|
2100 | |
|
|
2101 | // send hp information, if applicable |
|
|
2102 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
|
|
2103 | { |
|
|
2104 | if (op->head || op->invisible) |
|
|
2105 | ; // do not show |
|
|
2106 | else if (op->type == PLAYER |
|
|
2107 | || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)) |
|
|
2108 | { |
|
|
2109 | if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp) |
|
|
2110 | { |
|
|
2111 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
|
|
2112 | stat_width = op->arch->tail_x; |
|
|
2113 | } |
|
|
2114 | } |
|
|
2115 | |
|
|
2116 | if (op->type == PLAYER && op != pl) |
|
|
2117 | player = op->count; |
|
|
2118 | } |
|
|
2119 | |
|
|
2120 | if (lastcell.stat_hp != stat_hp) |
|
|
2121 | { |
|
|
2122 | lastcell.stat_hp = stat_hp; |
|
|
2123 | |
|
|
2124 | mask |= 0x8; |
|
|
2125 | *last_ext |= 0x80; |
|
|
2126 | last_ext = sl.buf + sl.len; |
|
|
2127 | SockList_AddChar (&sl, 5); |
|
|
2128 | SockList_AddChar (&sl, stat_hp); |
|
|
2129 | |
|
|
2130 | if (stat_width > 1) |
|
|
2131 | { |
|
|
2132 | *last_ext |= 0x80; |
|
|
2133 | last_ext = sl.buf + sl.len; |
|
|
2134 | SockList_AddChar (&sl, 6); |
|
|
2135 | SockList_AddChar (&sl, stat_width); |
|
|
2136 | } |
|
|
2137 | } |
|
|
2138 | |
|
|
2139 | if (lastcell.player !=player) |
|
|
2140 | { |
|
|
2141 | lastcell.player = player; |
|
|
2142 | |
|
|
2143 | mask |= 0x8; |
|
|
2144 | *last_ext |= 0x80; |
|
|
2145 | last_ext = sl.buf + sl.len; |
|
|
2146 | SockList_AddChar (&sl, 0x47); |
|
|
2147 | SockList_AddChar (&sl, 4); |
|
|
2148 | SockList_AddInt (&sl, player); |
|
|
2149 | } |
|
|
2150 | } |
|
|
2151 | |
|
|
2152 | /* Floor face */ |
|
|
2153 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
|
|
2154 | mask |= 0x4; |
|
|
2155 | |
|
|
2156 | if (socket.EMI_smooth) |
|
|
2157 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 2)) |
|
|
2158 | emask |= 0x4; |
|
|
2159 | |
|
|
2160 | /* Middle face */ |
|
|
2161 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 1)) |
|
|
2162 | mask |= 0x2; |
|
|
2163 | |
|
|
2164 | if (socket.EMI_smooth) |
|
|
2165 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 1)) |
|
|
2166 | emask |= 0x2; |
|
|
2167 | |
|
|
2168 | if (nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) |
|
|
2169 | { |
|
|
2170 | if (lastcell.faces[0] != pl->face->number) |
|
|
2171 | { |
|
|
2172 | lastcell.faces[0] = pl->face->number; |
|
|
2173 | mask |= 0x1; |
|
|
2174 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
|
|
2175 | esrv_send_face (&socket, pl->face->number, 0); |
|
|
2176 | SockList_AddShort (&sl, pl->face->number); |
|
|
2177 | } |
|
|
2178 | } |
|
|
2179 | /* Top face */ |
|
|
2180 | else |
|
|
2181 | { |
|
|
2182 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
|
|
2183 | mask |= 0x1; |
|
|
2184 | if (socket.EMI_smooth) |
|
|
2185 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
1822 | { |
2186 | { |
1823 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, d); |
2187 | emask |= 0x1; |
1824 | } |
2188 | } |
1825 | else |
|
|
1826 | SockList_AddChar (&sl, 255 - 64 * d); |
|
|
1827 | } |
|
|
1828 | |
|
|
1829 | lastcell.count = d; |
|
|
1830 | |
|
|
1831 | if (socket.extmap) |
|
|
1832 | { |
|
|
1833 | uint8 stat_hp = 0; |
|
|
1834 | uint8 stat_width = 0; |
|
|
1835 | |
|
|
1836 | // send hp information, if applicable |
|
|
1837 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
|
|
1838 | if (!op->head |
|
|
1839 | && op->stats.maxhp > 0 |
|
|
1840 | && (unsigned)op->stats.maxhp > (unsigned)op->stats.hp |
|
|
1841 | && IS_LIVE (op)) |
|
|
1842 | { |
|
|
1843 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
|
|
1844 | stat_width = op->arch->tail_x; |
|
|
1845 | } |
|
|
1846 | |
|
|
1847 | if (lastcell.stat_hp != stat_hp) |
|
|
1848 | { |
|
|
1849 | lastcell.stat_hp = stat_hp; |
|
|
1850 | |
|
|
1851 | mask |= 0x8; |
|
|
1852 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 5); |
|
|
1853 | SockList_AddChar (&sl, stat_hp); |
|
|
1854 | |
|
|
1855 | if (stat_width > 1) |
|
|
1856 | { |
|
|
1857 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 6); |
|
|
1858 | SockList_AddChar (&sl, stat_width); |
|
|
1859 | } |
|
|
1860 | } |
|
|
1861 | } |
2189 | } |
1862 | |
|
|
1863 | /* Floor face */ |
|
|
1864 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 2)) |
|
|
1865 | mask |= 0x4; |
|
|
1866 | |
|
|
1867 | if (socket.EMI_smooth) |
|
|
1868 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 2)) |
|
|
1869 | emask |= 0x4; |
|
|
1870 | |
|
|
1871 | /* Middle face */ |
|
|
1872 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 1)) |
|
|
1873 | mask |= 0x2; |
|
|
1874 | |
|
|
1875 | if (socket.EMI_smooth) |
|
|
1876 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 1)) |
|
|
1877 | emask |= 0x2; |
|
|
1878 | |
|
|
1879 | if(nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
|
|
1880 | if (lastcell.faces[0] != pl->face->number) { |
|
|
1881 | lastcell.faces[0] = pl->face->number; |
|
|
1882 | mask |= 0x1; |
|
|
1883 | if (!(socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) |
|
|
1884 | esrv_send_face(&socket, pl->face->number, 0); |
|
|
1885 | SockList_AddShort(&sl, pl->face->number); |
|
|
1886 | } |
|
|
1887 | } |
|
|
1888 | /* Top face */ |
|
|
1889 | else { |
|
|
1890 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 0)) |
|
|
1891 | mask |= 0x1; |
|
|
1892 | if (socket.EMI_smooth) |
|
|
1893 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 0)){ |
|
|
1894 | emask |= 0x1; |
|
|
1895 | } |
|
|
1896 | } |
|
|
1897 | /* Check to see if we are in fact sending anything for this |
2190 | /* Check to see if we are in fact sending anything for this |
1898 | * space by checking the mask. If so, update the mask. |
2191 | * space by checking the mask. If so, update the mask. |
1899 | * if not, reset the len to that from before adding the mask |
2192 | * if not, reset the len to that from before adding the mask |
1900 | * value, so we don't send those bits. |
2193 | * value, so we don't send those bits. |
1901 | */ |
2194 | */ |
1902 | if (mask & 0xf) { |
2195 | if (mask & 0xf) |
|
|
2196 | { |
1903 | sl.buf[oldlen+1] = mask & 0xff; |
2197 | sl.buf[oldlen + 1] = mask & 0xff; |
1904 | } else { |
2198 | } |
1905 | sl.len = oldlen; |
2199 | else |
1906 | } |
2200 | { |
1907 | if (emask & 0xf) { |
2201 | sl.len = oldlen; |
|
|
2202 | } |
|
|
2203 | if (emask & 0xf) |
|
|
2204 | { |
1908 | esl.buf[eoldlen+1] = emask & 0xff; |
2205 | esl.buf[eoldlen + 1] = emask & 0xff; |
1909 | } else { |
2206 | } |
1910 | esl.len = eoldlen; |
2207 | else |
1911 | } |
2208 | { |
|
|
2209 | esl.len = eoldlen; |
|
|
2210 | } |
1912 | } /* else this is a viewable space */ |
2211 | } /* else this is a viewable space */ |
1913 | } /* for x loop */ |
2212 | } /* for x loop */ |
1914 | } /* for y loop */ |
2213 | } /* for y loop */ |
1915 | |
2214 | |
1916 | /* Verify that we in fact do need to send this */ |
2215 | /* Verify that we in fact do need to send this */ |
1917 | if (socket.ext_mapinfos){ |
2216 | if (socket.ext_mapinfos) |
|
|
2217 | { |
1918 | if (!(sl.len>startlen || socket.sent_scroll)){ |
2218 | if (!(sl.len > startlen || socket.sent_scroll)) |
|
|
2219 | { |
1919 | /* No map data will follow, so don't say the client |
2220 | /* No map data will follow, so don't say the client |
1920 | * it doesn't need draw! |
2221 | * it doesn't need draw! |
1921 | */ |
2222 | */ |
1922 | ewhatflag&=(~EMI_NOREDRAW); |
2223 | ewhatflag &= (~EMI_NOREDRAW); |
1923 | esl.buf[ewhatstart+1] = ewhatflag & 0xff; |
2224 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
1924 | } |
2225 | } |
1925 | if (esl.len>estartlen) { |
2226 | if (esl.len > estartlen) |
|
|
2227 | { |
1926 | Send_With_Handling(&socket, &esl); |
2228 | Send_With_Handling (&socket, &esl); |
1927 | } |
2229 | } |
1928 | free(esl.buf); |
2230 | free (esl.buf); |
1929 | } |
2231 | } |
1930 | if (sl.len>startlen || socket.sent_scroll) { |
2232 | if (sl.len > startlen || socket.sent_scroll) |
|
|
2233 | { |
1931 | Send_With_Handling(&socket, &sl); |
2234 | Send_With_Handling (&socket, &sl); |
1932 | socket.sent_scroll = 0; |
2235 | socket.sent_scroll = 0; |
1933 | } |
2236 | } |
1934 | free(sl.buf); |
2237 | free (sl.buf); |
1935 | } |
2238 | } |
1936 | |
2239 | |
1937 | /** |
2240 | /** |
1938 | * Draws client map. |
2241 | * Draws client map. |
1939 | */ |
2242 | */ |
|
|
2243 | void |
1940 | void draw_client_map(object *pl) |
2244 | draw_client_map (object *pl) |
1941 | { |
2245 | { |
1942 | int i,j; |
2246 | int i, j; |
1943 | sint16 ax, ay, nx, ny;/* ax and ay goes from 0 to max-size of arrays */ |
2247 | sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ |
1944 | New_Face *face,*floor; |
2248 | New_Face *face, *floor; |
1945 | New_Face *floor2; |
2249 | New_Face *floor2; |
1946 | int d, mflags; |
2250 | int d, mflags; |
1947 | struct Map newmap; |
2251 | struct Map newmap; |
1948 | mapstruct *m, *pm; |
2252 | mapstruct *m, *pm; |
1949 | |
2253 | |
1950 | if (pl->type != PLAYER) { |
2254 | if (pl->type != PLAYER) |
|
|
2255 | { |
1951 | LOG(llevError,"draw_client_map called with non player/non eric-server\n"); |
2256 | LOG (llevError, "draw_client_map called with non player/non eric-server\n"); |
1952 | return; |
2257 | return; |
1953 | } |
2258 | } |
1954 | |
2259 | |
1955 | if (pl->contr->transport) { |
|
|
1956 | pm = pl->contr->transport->map; |
|
|
1957 | } |
|
|
1958 | else |
|
|
1959 | pm = pl->map; |
2260 | pm = pl->map; |
1960 | |
2261 | |
1961 | /* If player is just joining the game, he isn't here yet, so the map |
2262 | /* If player is just joining the game, he isn't here yet, so the map |
1962 | * can get swapped out. If so, don't try to send them a map. All will |
2263 | * can get swapped out. If so, don't try to send them a map. All will |
1963 | * be OK once they really log in. |
2264 | * be OK once they really log in. |
1964 | */ |
2265 | */ |
1965 | if (pm==NULL || pm->in_memory!=MAP_IN_MEMORY) return; |
2266 | if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) |
|
|
2267 | return; |
1966 | |
2268 | |
1967 | memset(&newmap, 0, sizeof(struct Map)); |
2269 | memset (&newmap, 0, sizeof (struct Map)); |
1968 | |
2270 | |
1969 | for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { |
2271 | for (j = (pl->y - pl->contr->socket.mapy / 2); j < (pl->y + (pl->contr->socket.mapy + 1) / 2); j++) |
|
|
2272 | { |
1970 | for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) { |
2273 | for (i = (pl->x - pl->contr->socket.mapx / 2); i < (pl->x + (pl->contr->socket.mapx + 1) / 2); i++) |
1971 | ax=i; |
2274 | { |
1972 | ay=j; |
2275 | ax = i; |
|
|
2276 | ay = j; |
1973 | m = pm; |
2277 | m = pm; |
1974 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
2278 | mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); |
1975 | if (mflags & P_OUT_OF_MAP) |
2279 | if (mflags & P_OUT_OF_MAP) |
1976 | continue; |
2280 | continue; |
1977 | if (mflags & P_NEED_UPDATE) |
2281 | if (mflags & P_NEED_UPDATE) |
1978 | update_position(m, ax, ay); |
2282 | update_position (m, ax, ay); |
1979 | /* If a map is visible to the player, we don't want to swap it out |
2283 | /* If a map is visible to the player, we don't want to swap it out |
1980 | * just to reload it. This should really call something like |
2284 | * just to reload it. This should really call something like |
1981 | * swap_map, but this is much more efficient and 'good enough' |
2285 | * swap_map, but this is much more efficient and 'good enough' |
1982 | */ |
2286 | */ |
1983 | if (mflags & P_NEW_MAP) |
2287 | if (mflags & P_NEW_MAP) |
1984 | m->timeout = 50; |
2288 | m->timeout = 50; |
1985 | } |
2289 | } |
1986 | } |
2290 | } |
1987 | /* do LOS after calls to update_position */ |
2291 | /* do LOS after calls to update_position */ |
1988 | if(pl->contr->do_los) { |
2292 | if (pl->contr->do_los) |
|
|
2293 | { |
1989 | update_los(pl); |
2294 | update_los (pl); |
1990 | pl->contr->do_los = 0; |
2295 | pl->contr->do_los = 0; |
1991 | } |
2296 | } |
1992 | |
2297 | |
1993 | if (pl->contr->socket.mapmode == Map1Cmd || pl->contr->socket.mapmode == Map1aCmd) { |
2298 | if (pl->contr->socket.mapmode == Map1Cmd || pl->contr->socket.mapmode == Map1aCmd) |
|
|
2299 | { |
1994 | /* Big maps need a different drawing mechanism to work */ |
2300 | /* Big maps need a different drawing mechanism to work */ |
1995 | draw_client_map1(pl); |
2301 | draw_client_map1 (pl); |
1996 | return; |
2302 | return; |
1997 | } |
|
|
1998 | |
2303 | } |
|
|
2304 | |
1999 | if(pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
2305 | if (pl->invisible & (pl->invisible < 50 ? 4 : 1)) |
2000 | esrv_map_setbelow(&pl->contr->socket,pl->contr->socket.mapx/2, |
|
|
2001 | pl->contr->socket.mapy/2,pl->face->number,&newmap); |
|
|
2002 | } |
2306 | { |
|
|
2307 | esrv_map_setbelow (&pl->contr->socket, pl->contr->socket.mapx / 2, pl->contr->socket.mapy / 2, pl->face->number, &newmap); |
|
|
2308 | } |
2003 | |
2309 | |
2004 | /* j and i are the y and x coordinates of the real map (which is |
2310 | /* j and i are the y and x coordinates of the real map (which is |
2005 | * basically some number of spaces around the player) |
2311 | * basically some number of spaces around the player) |
2006 | * ax and ay are values from within the viewport (ie, 0, 0 is upper |
2312 | * ax and ay are values from within the viewport (ie, 0, 0 is upper |
2007 | * left corner) and are thus disconnected from the map values. |
2313 | * left corner) and are thus disconnected from the map values. |
2008 | * Subtract 1 from the max values so that we properly handle cases where |
2314 | * Subtract 1 from the max values so that we properly handle cases where |
2009 | * player has specified an even map. Otherwise, we try to send them too |
2315 | * player has specified an even map. Otherwise, we try to send them too |
2010 | * much, ie, if mapx is 10, we would try to send from -5 to 5, which is actually |
2316 | * much, ie, if mapx is 10, we would try to send from -5 to 5, which is actually |
2011 | * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is |
2317 | * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is |
2012 | * odd, this still works fine. |
2318 | * odd, this still works fine. |
2013 | */ |
2319 | */ |
2014 | ay=0; |
2320 | ay = 0; |
2015 | for(j=pl->y-pl->contr->socket.mapy/2; j<=pl->y+(pl->contr->socket.mapy-1)/2;j++, ay++) { |
2321 | for (j = pl->y - pl->contr->socket.mapy / 2; j <= pl->y + (pl->contr->socket.mapy - 1) / 2; j++, ay++) |
2016 | ax=0; |
2322 | { |
|
|
2323 | ax = 0; |
2017 | for(i=pl->x-pl->contr->socket.mapx/2;i<=pl->x+(pl->contr->socket.mapx-1)/2;i++, ax++) { |
2324 | for (i = pl->x - pl->contr->socket.mapx / 2; i <= pl->x + (pl->contr->socket.mapx - 1) / 2; i++, ax++) |
|
|
2325 | { |
2018 | |
2326 | |
2019 | d = pl->contr->blocked_los[ax][ay]; |
2327 | d = pl->contr->blocked_los[ax][ay]; |
2020 | /* note the out_of_map and d>3 checks are both within the same |
2328 | /* note the out_of_map and d>3 checks are both within the same |
2021 | * negation check. |
2329 | * negation check. |
2022 | */ |
2330 | */ |
2023 | nx = i; |
2331 | nx = i; |
2024 | ny = j; |
2332 | ny = j; |
2025 | m = get_map_from_coord(pm, &nx, &ny); |
2333 | m = get_map_from_coord (pm, &nx, &ny); |
2026 | if (m && d<4) { |
2334 | if (m && d < 4) |
|
|
2335 | { |
2027 | face = GET_MAP_FACE(m, nx, ny,0); |
2336 | face = GET_MAP_FACE (m, nx, ny, 0); |
2028 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
2337 | floor2 = GET_MAP_FACE (m, nx, ny, 1); |
2029 | floor = GET_MAP_FACE(m, nx, ny,2); |
2338 | floor = GET_MAP_FACE (m, nx, ny, 2); |
2030 | |
2339 | |
2031 | /* If all is blank, send a blank face. */ |
2340 | /* If all is blank, send a blank face. */ |
2032 | if ((!face || face == blank_face) && |
2341 | if ((!face || face == blank_face) && (!floor2 || floor2 == blank_face) && (!floor || floor == blank_face)) |
2033 | (!floor2 || floor2 == blank_face) && |
2342 | { |
2034 | (!floor || floor == blank_face)) { |
2343 | esrv_map_setbelow (&pl->contr->socket, ax, ay, blank_face->number, &newmap); |
2035 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2344 | } |
2036 | blank_face->number,&newmap); |
2345 | else |
2037 | } else { /* actually have something interesting */ |
2346 | { /* actually have something interesting */ |
2038 | /* send the darkness mask, if any. */ |
2347 | /* send the darkness mask, if any. */ |
2039 | if (d && pl->contr->socket.darkness) |
2348 | if (d && pl->contr->socket.darkness) |
2040 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2349 | esrv_map_setbelow (&pl->contr->socket, ax, ay, dark_faces[d - 1]->number, &newmap); |
2041 | dark_faces[d-1]->number,&newmap); |
|
|
2042 | |
2350 | |
2043 | if (face && face != blank_face) |
2351 | if (face && face != blank_face) |
2044 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2352 | esrv_map_setbelow (&pl->contr->socket, ax, ay, face->number, &newmap); |
2045 | face->number,&newmap); |
|
|
2046 | if (floor2 && floor2 != blank_face) |
2353 | if (floor2 && floor2 != blank_face) |
2047 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2354 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor2->number, &newmap); |
2048 | floor2->number,&newmap); |
|
|
2049 | if (floor && floor != blank_face) |
2355 | if (floor && floor != blank_face) |
2050 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2356 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap); |
2051 | floor->number,&newmap); |
2357 | } |
2052 | } |
2358 | } /* Is a valid space */ |
2053 | } /* Is a valid space */ |
2359 | } |
2054 | } |
|
|
2055 | } |
2360 | } |
2056 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
2361 | esrv_map_doneredraw (&pl->contr->socket, &newmap); |
2057 | |
2362 | |
2058 | check_map_change (pl->contr); |
2363 | check_map_change (pl->contr); |
2059 | } |
2364 | } |
2060 | |
2365 | |
2061 | |
2366 | |
2062 | /*****************************************************************************/ |
2367 | /*****************************************************************************/ |
|
|
2368 | |
2063 | /* GROS: The following one is used to allow a plugin to send a generic cmd to*/ |
2369 | /* GROS: The following one is used to allow a plugin to send a generic cmd to*/ |
|
|
2370 | |
2064 | /* a player. Of course, the client need to know the command to be able to */ |
2371 | /* a player. Of course, the client need to know the command to be able to */ |
|
|
2372 | |
2065 | /* manage it ! */ |
2373 | /* manage it ! */ |
|
|
2374 | |
2066 | /*****************************************************************************/ |
2375 | /*****************************************************************************/ |
|
|
2376 | void |
2067 | void send_plugin_custom_message(object *pl, char *buf) |
2377 | send_plugin_custom_message (object *pl, char *buf) |
2068 | { |
2378 | { |
2069 | cs_write_string(&pl->contr->socket,buf,strlen(buf)); |
2379 | cs_write_string (&pl->contr->socket, buf, strlen (buf)); |
2070 | } |
2380 | } |
2071 | |
2381 | |
2072 | /** |
2382 | /** |
2073 | * This sends the skill number to name mapping. We ignore |
2383 | * This sends the skill number to name mapping. We ignore |
2074 | * the params - we always send the same info no matter what. |
2384 | * the params - we always send the same info no matter what. |
2075 | */ |
2385 | */ |
|
|
2386 | void |
2076 | void send_skill_info(NewSocket *ns, char *params) |
2387 | send_skill_info (NewSocket * ns, char *params) |
2077 | { |
2388 | { |
2078 | SockList sl; |
2389 | SockList sl; |
2079 | int i; |
2390 | int i; |
2080 | |
2391 | |
2081 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2392 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2082 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
2393 | strcpy ((char *) sl.buf, "replyinfo skill_info\n"); |
2083 | for (i=1; i< NUM_SKILLS; i++) { |
2394 | for (i = 1; i < NUM_SKILLS; i++) |
|
|
2395 | { |
2084 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2396 | sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2085 | skill_names[i]); |
|
|
2086 | } |
2397 | } |
2087 | sl.len = strlen((char*)sl.buf); |
2398 | sl.len = strlen ((char *) sl.buf); |
2088 | if (sl.len >= MAXSOCKBUF) { |
2399 | if (sl.len >= MAXSOCKBUF) |
|
|
2400 | { |
2089 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2401 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2090 | fatal(0); |
2402 | fatal (0); |
2091 | } |
2403 | } |
2092 | Send_With_Handling(ns, &sl); |
2404 | Send_With_Handling (ns, &sl); |
2093 | free(sl.buf); |
2405 | free (sl.buf); |
2094 | } |
2406 | } |
2095 | |
2407 | |
2096 | /** |
2408 | /** |
2097 | * This sends the spell path to name mapping. We ignore |
2409 | * This sends the spell path to name mapping. We ignore |
2098 | * the params - we always send the same info no matter what. |
2410 | * the params - we always send the same info no matter what. |
2099 | */ |
2411 | */ |
|
|
2412 | void |
2100 | void send_spell_paths (NewSocket *ns, char *params) { |
2413 | send_spell_paths (NewSocket * ns, char *params) |
|
|
2414 | { |
2101 | SockList sl; |
2415 | SockList sl; |
2102 | int i; |
2416 | int i; |
2103 | |
2417 | |
2104 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2418 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2105 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2419 | strcpy ((char *) sl.buf, "replyinfo spell_paths\n"); |
2106 | for(i=0; i<NRSPELLPATHS; i++) |
2420 | for (i = 0; i < NRSPELLPATHS; i++) |
2107 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2421 | sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", 1 << i, spellpathnames[i]); |
2108 | sl.len = strlen((char*)sl.buf); |
2422 | sl.len = strlen ((char *) sl.buf); |
2109 | if (sl.len >= MAXSOCKBUF) { |
2423 | if (sl.len >= MAXSOCKBUF) |
|
|
2424 | { |
2110 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2425 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2111 | fatal(0); |
2426 | fatal (0); |
2112 | } |
2427 | } |
2113 | Send_With_Handling(ns, &sl); |
2428 | Send_With_Handling (ns, &sl); |
2114 | free(sl.buf); |
2429 | free (sl.buf); |
2115 | } |
2430 | } |
2116 | |
2431 | |
2117 | /** |
2432 | /** |
2118 | * This looks for any spells the player may have that have changed their stats. |
2433 | * This looks for any spells the player may have that have changed their stats. |
2119 | * it then sends an updspell packet for each spell that has changed in this way |
2434 | * it then sends an updspell packet for each spell that has changed in this way |
2120 | */ |
2435 | */ |
|
|
2436 | void |
2121 | void esrv_update_spells(player *pl) { |
2437 | esrv_update_spells (player *pl) |
|
|
2438 | { |
2122 | SockList sl; |
2439 | SockList sl; |
2123 | int flags=0; |
2440 | int flags = 0; |
2124 | object *spell; |
2441 | object *spell; |
|
|
2442 | |
2125 | if (!pl->socket.monitor_spells) return; |
2443 | if (!pl->socket.monitor_spells) |
|
|
2444 | return; |
2126 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2445 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
|
|
2446 | { |
2127 | if (spell->type == SPELL) { |
2447 | if (spell->type == SPELL) |
|
|
2448 | { |
2128 | /* check if we need to update it*/ |
2449 | /* check if we need to update it */ |
2129 | if (spell->last_sp != SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA)) { |
2450 | if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) |
|
|
2451 | { |
2130 | spell->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
2452 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2131 | flags |= UPD_SP_MANA; |
2453 | flags |= UPD_SP_MANA; |
2132 | } |
2454 | } |
2133 | if (spell->last_grace != SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE)) { |
2455 | if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) |
|
|
2456 | { |
2134 | spell->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
2457 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2135 | flags |= UPD_SP_GRACE; |
2458 | flags |= UPD_SP_GRACE; |
2136 | } |
2459 | } |
2137 | if (spell->last_eat != spell->stats.dam+SP_level_dam_adjust(pl->ob, spell)) { |
2460 | if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) |
|
|
2461 | { |
2138 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
2462 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2139 | flags |= UPD_SP_DAMAGE; |
2463 | flags |= UPD_SP_DAMAGE; |
|
|
2464 | } |
|
|
2465 | if (flags != 0) |
|
|
2466 | { |
|
|
2467 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
2468 | strcpy ((char *) sl.buf, "updspell "); |
|
|
2469 | sl.len = strlen ((char *) sl.buf); |
|
|
2470 | SockList_AddChar (&sl, flags); |
|
|
2471 | SockList_AddInt (&sl, spell->count); |
|
|
2472 | if (flags & UPD_SP_MANA) |
|
|
2473 | SockList_AddShort (&sl, spell->last_sp); |
|
|
2474 | if (flags & UPD_SP_GRACE) |
|
|
2475 | SockList_AddShort (&sl, spell->last_grace); |
|
|
2476 | if (flags & UPD_SP_DAMAGE) |
|
|
2477 | SockList_AddShort (&sl, spell->last_eat); |
|
|
2478 | flags = 0; |
|
|
2479 | Send_With_Handling (&pl->socket, &sl); |
|
|
2480 | free (sl.buf); |
|
|
2481 | } |
|
|
2482 | } |
2140 | } |
2483 | } |
2141 | if (flags !=0) { |
|
|
2142 | sl.buf =(unsigned char*) malloc(MAXSOCKBUF); |
|
|
2143 | strcpy((char*)sl.buf,"updspell "); |
|
|
2144 | sl.len=strlen((char*)sl.buf); |
|
|
2145 | SockList_AddChar(&sl, flags); |
|
|
2146 | SockList_AddInt(&sl, spell->count); |
|
|
2147 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
|
|
2148 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
|
|
2149 | if (flags & UPD_SP_DAMAGE) SockList_AddShort(&sl, spell->last_eat); |
|
|
2150 | flags = 0; |
|
|
2151 | Send_With_Handling(&pl->socket, &sl); |
|
|
2152 | free(sl.buf); |
|
|
2153 | } |
|
|
2154 | } |
|
|
2155 | } |
|
|
2156 | } |
2484 | } |
2157 | |
2485 | |
|
|
2486 | void |
2158 | void esrv_remove_spell(player *pl, object *spell) { |
2487 | esrv_remove_spell (player *pl, object *spell) |
|
|
2488 | { |
2159 | SockList sl; |
2489 | SockList sl; |
2160 | |
2490 | |
2161 | if (!pl->socket.monitor_spells) return; |
2491 | if (!pl->socket.monitor_spells) |
|
|
2492 | return; |
2162 | if (!pl || !spell || spell->env != pl->ob) { |
2493 | if (!pl || !spell || spell->env != pl->ob) |
|
|
2494 | { |
2163 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2495 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2164 | return; |
2496 | return; |
2165 | } |
2497 | } |
2166 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2498 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2167 | strcpy((char*)sl.buf,"delspell "); |
2499 | strcpy ((char *) sl.buf, "delspell "); |
2168 | sl.len=strlen((char*)sl.buf); |
2500 | sl.len = strlen ((char *) sl.buf); |
2169 | SockList_AddInt(&sl, spell->count); |
2501 | SockList_AddInt (&sl, spell->count); |
2170 | Send_With_Handling(&pl->socket, &sl); |
2502 | Send_With_Handling (&pl->socket, &sl); |
2171 | free(sl.buf); |
2503 | free (sl.buf); |
2172 | } |
2504 | } |
2173 | |
2505 | |
2174 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2506 | /* appends the spell *spell to the Socklist we will send the data to. */ |
|
|
2507 | static void |
2175 | static void append_spell (player *pl, SockList *sl, object *spell) { |
2508 | append_spell (player *pl, SockList * sl, object *spell) |
|
|
2509 | { |
2176 | int len, i, skill=0; |
2510 | int len, i, skill = 0; |
2177 | |
2511 | |
2178 | if (!(spell->name)) { |
2512 | if (!(spell->name)) |
|
|
2513 | { |
2179 | LOG(llevError, "item number %d is a spell with no name.\n", spell->count); |
2514 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
2180 | return; |
2515 | return; |
2181 | } |
2516 | } |
2182 | SockList_AddInt(sl, spell->count); |
2517 | SockList_AddInt (sl, spell->count); |
2183 | SockList_AddShort(sl, spell->level); |
2518 | SockList_AddShort (sl, spell->level); |
2184 | SockList_AddShort(sl, spell->casting_time); |
2519 | SockList_AddShort (sl, spell->casting_time); |
2185 | /* store costs and damage in the object struct, to compare to later */ |
2520 | /* store costs and damage in the object struct, to compare to later */ |
2186 | spell->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
2521 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2187 | spell->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
2522 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2188 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
2523 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2189 | /* send the current values */ |
2524 | /* send the current values */ |
2190 | SockList_AddShort(sl, spell->last_sp); |
2525 | SockList_AddShort (sl, spell->last_sp); |
2191 | SockList_AddShort(sl, spell->last_grace); |
2526 | SockList_AddShort (sl, spell->last_grace); |
2192 | SockList_AddShort(sl, spell->last_eat); |
2527 | SockList_AddShort (sl, spell->last_eat); |
2193 | |
2528 | |
2194 | /* figure out which skill it uses, if it uses one */ |
2529 | /* figure out which skill it uses, if it uses one */ |
2195 | if (spell->skill) { |
2530 | if (spell->skill) |
|
|
2531 | { |
2196 | for (i=1; i< NUM_SKILLS; i++) |
2532 | for (i = 1; i < NUM_SKILLS; i++) |
2197 | if (!strcmp(spell->skill, skill_names[i])) { |
2533 | if (!strcmp (spell->skill, skill_names[i])) |
|
|
2534 | { |
2198 | skill = i+CS_STAT_SKILLINFO; |
2535 | skill = i + CS_STAT_SKILLINFO; |
2199 | break; |
2536 | break; |
|
|
2537 | } |
2200 | } |
2538 | } |
2201 | } |
|
|
2202 | SockList_AddChar(sl, skill); |
2539 | SockList_AddChar (sl, skill); |
2203 | |
2540 | |
2204 | SockList_AddInt(sl, spell->path_attuned); |
2541 | SockList_AddInt (sl, spell->path_attuned); |
2205 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
2542 | SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); |
2206 | |
2543 | |
2207 | len = strlen(spell->name); |
2544 | len = strlen (spell->name); |
2208 | SockList_AddChar(sl, (char)len); |
2545 | SockList_AddChar (sl, (char) len); |
2209 | memcpy(sl->buf+sl->len, spell->name, len); |
2546 | memcpy (sl->buf + sl->len, spell->name, len); |
2210 | sl->len+=len; |
2547 | sl->len += len; |
2211 | |
2548 | |
2212 | if (!spell->msg) { |
2549 | if (!spell->msg) |
|
|
2550 | { |
2213 | SockList_AddShort(sl, 0); |
2551 | SockList_AddShort (sl, 0); |
|
|
2552 | } |
|
|
2553 | else |
2214 | } |
2554 | { |
2215 | else { |
|
|
2216 | len = strlen(spell->msg); |
2555 | len = strlen (spell->msg); |
2217 | SockList_AddShort(sl, len); |
2556 | SockList_AddShort (sl, len); |
2218 | memcpy(sl->buf+sl->len, spell->msg, len); |
2557 | memcpy (sl->buf + sl->len, spell->msg, len); |
2219 | sl->len+=len; |
2558 | sl->len += len; |
2220 | } |
2559 | } |
2221 | } |
2560 | } |
2222 | |
2561 | |
2223 | /** |
2562 | /** |
2224 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2563 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2225 | * all spells in the player's inventory. |
2564 | * all spells in the player's inventory. |
2226 | */ |
2565 | */ |
|
|
2566 | void |
2227 | void esrv_add_spells(player *pl, object *spell) { |
2567 | esrv_add_spells (player *pl, object *spell) |
|
|
2568 | { |
2228 | SockList sl; |
2569 | SockList sl; |
|
|
2570 | |
2229 | if (!pl) { |
2571 | if (!pl) |
|
|
2572 | { |
2230 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2573 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2231 | return; |
2574 | return; |
2232 | } |
2575 | } |
2233 | if (!pl->socket.monitor_spells) return; |
2576 | if (!pl->socket.monitor_spells) |
|
|
2577 | return; |
2234 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2578 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2235 | strcpy((char*)sl.buf,"addspell "); |
2579 | strcpy ((char *) sl.buf, "addspell "); |
2236 | sl.len=strlen((char*)sl.buf); |
2580 | sl.len = strlen ((char *) sl.buf); |
2237 | if (!spell) { |
2581 | if (!spell) |
|
|
2582 | { |
2238 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2583 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
|
|
2584 | { |
2239 | /* were we to simply keep appending data here, we could exceed |
2585 | /* were we to simply keep appending data here, we could exceed |
2240 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2586 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2241 | * append_spells will always append 19 data bytes, plus 4 length |
2587 | * append_spells will always append 19 data bytes, plus 4 length |
2242 | * bytes and 3 strings (because that is the spec) so we need to |
2588 | * bytes and 3 strings (because that is the spec) so we need to |
2243 | * check that the length of those 3 strings, plus the 23 bytes, |
2589 | * check that the length of those 3 strings, plus the 23 bytes, |
2244 | * won't take us over the length limit for the socket, if it does, |
2590 | * won't take us over the length limit for the socket, if it does, |
2245 | * we need to send what we already have, and restart packet formation |
2591 | * we need to send what we already have, and restart packet formation |
2246 | */ |
2592 | */ |
2247 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2593 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2248 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2594 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2249 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2595 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2250 | * like it will fix this |
2596 | * like it will fix this |
2251 | */ |
2597 | */ |
2252 | if (spell->type != SPELL) continue; |
2598 | if (spell->type != SPELL) |
2253 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2599 | continue; |
2254 | (spell->msg?strlen(spell->msg):0)))) { |
2600 | if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
|
|
2601 | { |
2255 | Send_With_Handling(&pl->socket, &sl); |
2602 | Send_With_Handling (&pl->socket, &sl); |
2256 | strcpy((char*)sl.buf,"addspell "); |
2603 | strcpy ((char *) sl.buf, "addspell "); |
2257 | sl.len=strlen((char*)sl.buf); |
2604 | sl.len = strlen ((char *) sl.buf); |
|
|
2605 | } |
|
|
2606 | append_spell (pl, &sl, spell); |
|
|
2607 | } |
2258 | } |
2608 | } |
|
|
2609 | else if (spell->type != SPELL) |
|
|
2610 | { |
|
|
2611 | LOG (llevError, "Asked to send a non-spell object as a spell"); |
|
|
2612 | return; |
|
|
2613 | } |
|
|
2614 | else |
2259 | append_spell(pl, &sl, spell); |
2615 | append_spell (pl, &sl, spell); |
2260 | } |
|
|
2261 | } |
|
|
2262 | else if (spell->type != SPELL) { |
|
|
2263 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
|
|
2264 | return; |
|
|
2265 | } |
|
|
2266 | else append_spell(pl, &sl, spell); |
|
|
2267 | if (sl.len >= MAXSOCKBUF) { |
2616 | if (sl.len >= MAXSOCKBUF) |
|
|
2617 | { |
2268 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2618 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2269 | fatal(0); |
2619 | fatal (0); |
2270 | } |
2620 | } |
2271 | /* finally, we can send the packet */ |
2621 | /* finally, we can send the packet */ |
2272 | Send_With_Handling(&pl->socket, &sl); |
2622 | Send_With_Handling (&pl->socket, &sl); |
2273 | free(sl.buf); |
2623 | free (sl.buf); |
2274 | } |
2624 | } |
2275 | |
|
|