1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * static char *rcsid_init_c = |
3 | * "$Id: request.C,v 1.2 2006/08/17 20:23:32 root Exp $"; |
3 | * "$Id: request.C,v 1.12 2006/08/29 08:01:38 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
128 | */ |
128 | */ |
129 | mx = ns->mapx; |
129 | mx = ns->mapx; |
130 | my = ns->mapy; |
130 | my = ns->mapy; |
131 | |
131 | |
132 | if (ns->mapmode == Map1aCmd) { |
132 | if (ns->mapmode == Map1aCmd) { |
133 | mx += MAX_HEAD_OFFSET; |
133 | mx += MAX_HEAD_OFFSET; |
134 | my += MAX_HEAD_OFFSET; |
134 | my += MAX_HEAD_OFFSET; |
135 | } |
135 | } |
136 | |
136 | |
137 | /* the x and y here are coordinates for the new map, i.e. if we moved |
137 | /* 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, |
138 | * (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 |
139 | * if the destination x or y coordinate is outside the viewable |
140 | * area, we clear the values - otherwise, the old values |
140 | * area, we clear the values - otherwise, the old values |
141 | * are preserved, and the check_head thinks it needs to clear them. |
141 | * are preserved, and the check_head thinks it needs to clear them. |
142 | */ |
142 | */ |
143 | for(x=0; x<mx; x++) { |
143 | for(x=0; x<mx; x++) { |
144 | for(y=0; y<my; y++) { |
144 | for(y=0; y<my; y++) { |
145 | if(x >= ns->mapx || y >= ns->mapy) { |
145 | if(x >= ns->mapx || y >= ns->mapy) { |
146 | /* clear cells outside the viewable area */ |
146 | /* clear cells outside the viewable area */ |
147 | memset(&newmap.cells[x][y], 0, sizeof(struct MapCell)); |
147 | memset(&newmap.cells[x][y], 0, sizeof(struct MapCell)); |
148 | } |
148 | } |
149 | else if ((x+dx) < 0 || (x+dx) >= ns->mapx || (y+dy) < 0 || (y + dy) >= ns->mapy) { |
149 | else if ((x+dx) < 0 || (x+dx) >= ns->mapx || (y+dy) < 0 || (y + dy) >= ns->mapy) { |
150 | /* clear newly visible tiles within the viewable area */ |
150 | /* clear newly visible tiles within the viewable area */ |
151 | memset(&(newmap.cells[x][y]), 0, sizeof(struct MapCell)); |
151 | memset(&(newmap.cells[x][y]), 0, sizeof(struct MapCell)); |
152 | } |
152 | } |
153 | else { |
153 | else { |
154 | memcpy(&(newmap.cells[x][y]), |
154 | memcpy(&(newmap.cells[x][y]), |
155 | &(ns->lastmap.cells[x+dx][y+dy]),sizeof(struct MapCell)); |
155 | &(ns->lastmap.cells[x+dx][y+dy]),sizeof(struct MapCell)); |
156 | } |
156 | } |
157 | } |
157 | } |
158 | } |
158 | } |
159 | |
159 | |
160 | memcpy(&(ns->lastmap), &newmap,sizeof(struct Map)); |
160 | memcpy(&(ns->lastmap), &newmap,sizeof(struct Map)); |
161 | |
161 | |
162 | /* Make sure that the next "map1" command will be sent (even if it is |
162 | /* Make sure that the next "map1" command will be sent (even if it is |
163 | * empty). |
163 | * empty). |
164 | */ |
164 | */ |
165 | ns->sent_scroll = 1; |
165 | ns->sent_scroll = 1; |
|
|
166 | } |
|
|
167 | |
|
|
168 | static void |
|
|
169 | clear_map (player *pl) |
|
|
170 | { |
|
|
171 | NewSocket &socket = pl->socket; |
|
|
172 | |
|
|
173 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
|
|
174 | |
|
|
175 | if (socket.newmapcmd == 1) |
|
|
176 | Write_String_To_Socket (&socket, "newmap", 6); |
|
|
177 | |
|
|
178 | socket.update_look = 1; |
|
|
179 | socket.look_position = 0; |
166 | } |
180 | } |
167 | |
181 | |
168 | /** check for map change and send new map data */ |
182 | /** check for map change and send new map data */ |
169 | static void |
183 | static void |
170 | check_map_change (player *pl) |
184 | check_map_change (player *pl) |
… | |
… | |
174 | char buf[MAX_BUF]; /* eauugggh */ |
188 | char buf[MAX_BUF]; /* eauugggh */ |
175 | |
189 | |
176 | if (socket.current_map != ob->map) |
190 | if (socket.current_map != ob->map) |
177 | { |
191 | { |
178 | socket.current_map = ob->map; |
192 | socket.current_map = ob->map; |
179 | memset (&socket.lastmap, 0, sizeof(socket.lastmap)); |
|
|
180 | |
193 | |
181 | if (socket.newmapcmd == 1) |
194 | clear_map (pl); |
182 | Write_String_To_Socket (&socket, "newmap", 6); |
|
|
183 | |
|
|
184 | socket.update_look = 1; |
|
|
185 | socket.look_position =0; |
|
|
186 | |
195 | |
187 | if (socket.mapinfocmd) |
196 | if (socket.mapinfocmd) |
188 | { |
197 | { |
189 | if (ob->map && ob->map->path [0]) |
198 | if (ob->map && ob->map->path [0]) |
190 | { |
199 | { |
… | |
… | |
205 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
214 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
206 | } |
215 | } |
207 | } |
216 | } |
208 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
217 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
209 | { |
218 | { |
|
|
219 | int dx = ob->x - socket.current_x; |
|
|
220 | int dy = ob->y - socket.current_y; |
|
|
221 | |
|
|
222 | if (socket.buggy_mapscroll && (abs (dx) > 8 || abs (dy) > 8)) |
|
|
223 | clear_map (pl); // current (<= 1.9.1) clients have unchecked buffer overflows |
|
|
224 | else |
|
|
225 | { |
210 | socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); |
226 | socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); |
211 | socket.update_look = 1; |
227 | socket.update_look = 1; |
212 | socket.look_position = 0; |
228 | socket.look_position = 0; |
|
|
229 | } |
213 | } |
230 | } |
214 | |
231 | |
215 | socket.current_x = ob->x; |
232 | socket.current_x = ob->x; |
216 | socket.current_y = ob->y; |
233 | socket.current_y = ob->y; |
217 | } |
234 | } |
218 | |
235 | |
219 | void ExtCmd (char *buf, int len, player *pl) |
236 | void ExtCmd (char *buf, int len, player *pl) |
220 | { |
237 | { |
221 | execute_global_event (EVENT_EXTCMD, pl, buf, len); |
238 | INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len)); |
222 | } |
239 | } |
223 | |
240 | |
224 | void MapInfoCmd (char *buf, int len, player *pl) |
241 | void MapInfoCmd (char *buf, int len, player *pl) |
225 | { |
242 | { |
226 | // <mapinfo tag spatial tile-path |
243 | // <mapinfo tag spatial tile-path |
… | |
… | |
312 | |
329 | |
313 | LOG(llevInfo,"Get SetupCmd:: %s\n", buf); |
330 | LOG(llevInfo,"Get SetupCmd:: %s\n", buf); |
314 | strcpy(cmdback,"setup"); |
331 | strcpy(cmdback,"setup"); |
315 | for(s=0;s<len; ) { |
332 | for(s=0;s<len; ) { |
316 | |
333 | |
317 | cmd = &buf[s]; |
334 | cmd = &buf[s]; |
318 | |
335 | |
319 | /* find the next space, and put a null there */ |
336 | /* find the next space, and put a null there */ |
320 | for(;buf[s] && buf[s] != ' ';s++) ; |
337 | for(;buf[s] && buf[s] != ' ';s++) ; |
321 | buf[s++]=0; |
338 | buf[s++]=0; |
322 | while (buf[s] == ' ') s++; |
339 | while (buf[s] == ' ') s++; |
323 | |
340 | |
324 | if(s>=len) |
341 | if(s>=len) |
325 | break; |
342 | break; |
326 | |
343 | |
327 | param = &buf[s]; |
344 | param = &buf[s]; |
328 | |
345 | |
329 | for(;buf[s] && buf[s] != ' ';s++) ; |
346 | for(;buf[s] && buf[s] != ' ';s++) ; |
330 | buf[s++]=0; |
347 | buf[s++]=0; |
331 | while (buf[s] == ' ') s++; |
348 | while (buf[s] == ' ') s++; |
332 | |
349 | |
333 | slen = strlen(cmdback); |
350 | slen = strlen(cmdback); |
334 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
351 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
335 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
352 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
336 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
353 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
337 | |
354 | |
338 | if (!strcmp(cmd,"sound")) { |
355 | if (!strcmp(cmd,"sound")) { |
339 | ns->sound = atoi(param); |
356 | ns->sound = atoi(param); |
340 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
357 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
341 | } |
358 | } |
342 | else if (!strcmp(cmd,"exp64")) { |
359 | else if (!strcmp(cmd,"exp64")) { |
343 | ns->exp64 = atoi(param); |
360 | ns->exp64 = atoi(param); |
344 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
361 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
345 | } else if (!strcmp(cmd, "spellmon")) { |
362 | } else if (!strcmp(cmd, "spellmon")) { |
346 | ns->monitor_spells = atoi(param); |
363 | ns->monitor_spells = atoi(param); |
347 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
364 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
348 | } else if (!strcmp(cmd,"darkness")) { |
365 | } else if (!strcmp(cmd,"darkness")) { |
349 | ns->darkness = atoi(param); |
366 | ns->darkness = atoi(param); |
350 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
367 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
351 | } else if (!strcmp(cmd,"map1cmd")) { |
368 | } else if (!strcmp(cmd,"map1cmd")) { |
352 | if (atoi(param)) ns->mapmode = Map1Cmd; |
369 | if (atoi(param)) ns->mapmode = Map1Cmd; |
353 | /* if beyond this size, need to use map1cmd no matter what */ |
370 | /* if beyond this size, need to use map1cmd no matter what */ |
354 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
371 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
355 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
372 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
356 | } else if (!strcmp(cmd,"map1acmd")) { |
373 | } else if (!strcmp(cmd,"map1acmd")) { |
357 | if (atoi(param)) ns->mapmode = Map1aCmd; |
374 | if (atoi(param)) ns->mapmode = Map1aCmd; |
358 | /* if beyond this size, need to use map1acmd no matter what */ |
375 | /* if beyond this size, need to use map1acmd no matter what */ |
359 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
376 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
360 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
377 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
361 | } else if (!strcmp(cmd,"newmapcmd")) { |
378 | } else if (!strcmp(cmd,"newmapcmd")) { |
362 | ns->newmapcmd= atoi(param); |
379 | ns->newmapcmd= atoi(param); |
363 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
380 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
364 | // } else if (!strcmp(cmd,"plugincmd")) { |
381 | // } else if (!strcmp(cmd,"plugincmd")) { |
365 | // ns->plugincmd = atoi(param); |
382 | // ns->plugincmd = atoi(param); |
366 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
383 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
367 | } else if (!strcmp(cmd,"mapinfocmd")) { |
384 | } else if (!strcmp(cmd,"mapinfocmd")) { |
368 | ns->mapinfocmd = atoi(param); |
385 | ns->mapinfocmd = atoi(param); |
369 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
386 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
370 | } else if (!strcmp(cmd,"extcmd")) { |
387 | } else if (!strcmp(cmd,"extcmd")) { |
371 | ns->extcmd = atoi(param); |
388 | ns->extcmd = atoi(param); |
372 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
389 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
|
|
390 | } else if (!strcmp(cmd,"extmap")) { |
|
|
391 | ns->extmap = atoi(param); |
|
|
392 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
373 | } else if (!strcmp(cmd,"facecache")) { |
393 | } else if (!strcmp(cmd,"facecache")) { |
374 | ns->facecache = atoi(param); |
394 | ns->facecache = atoi(param); |
375 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
395 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
376 | } else if (!strcmp(cmd,"faceset")) { |
396 | } else if (!strcmp(cmd,"faceset")) { |
377 | char tmpbuf[20]; |
397 | char tmpbuf[20]; |
378 | int q = atoi(param); |
398 | int q = atoi(param); |
379 | |
399 | |
380 | if (is_valid_faceset(q)) |
400 | if (is_valid_faceset(q)) |
381 | ns->faceset=q; |
401 | ns->faceset=q; |
382 | sprintf(tmpbuf,"%d", ns->faceset); |
402 | sprintf(tmpbuf,"%d", ns->faceset); |
383 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
403 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
384 | /* if the client is using faceset, it knows about image2 command */ |
404 | /* if the client is using faceset, it knows about image2 command */ |
385 | ns->image2=1; |
405 | ns->image2=1; |
386 | } else if (!strcmp(cmd,"itemcmd")) { |
406 | } else if (!strcmp(cmd,"itemcmd")) { |
387 | /* Version of the item protocol command to use. Currently, |
407 | /* Version of the item protocol command to use. Currently, |
388 | * only supported versions are 1 and 2. Using a numeric |
408 | * only supported versions are 1 and 2. Using a numeric |
389 | * value will make it very easy to extend this in the future. |
409 | * value will make it very easy to extend this in the future. |
390 | */ |
410 | */ |
391 | char tmpbuf[20]; |
411 | char tmpbuf[20]; |
392 | int q = atoi(param); |
412 | int q = atoi(param); |
393 | if (q<1 || q>2) { |
413 | if (q<1 || q>2) { |
394 | strcpy(tmpbuf,"FALSE"); |
414 | strcpy(tmpbuf,"FALSE"); |
395 | } else { |
415 | } else { |
396 | ns->itemcmd = q; |
416 | ns->itemcmd = q; |
397 | sprintf(tmpbuf,"%d", ns->itemcmd); |
417 | sprintf(tmpbuf,"%d", ns->itemcmd); |
398 | } |
418 | } |
399 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
419 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
400 | } else if (!strcmp(cmd,"mapsize")) { |
420 | } else if (!strcmp(cmd,"mapsize")) { |
401 | int x, y=0; |
421 | int x, y=0; |
402 | char tmpbuf[MAX_BUF], *cp; |
422 | char tmpbuf[MAX_BUF], *cp; |
403 | |
423 | |
404 | x = atoi(param); |
424 | x = atoi(param); |
405 | for (cp = param; *cp!=0; cp++) |
425 | for (cp = param; *cp!=0; cp++) |
406 | if (*cp == 'x' || *cp == 'X') { |
426 | if (*cp == 'x' || *cp == 'X') { |
407 | y = atoi(cp+1); |
427 | y = atoi(cp+1); |
408 | break; |
428 | break; |
409 | } |
429 | } |
410 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
430 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
411 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
431 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
412 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
432 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
413 | } else { |
433 | } else { |
414 | ns->mapx = x; |
434 | ns->mapx = x; |
415 | ns->mapy = y; |
435 | ns->mapy = y; |
416 | /* better to send back what we are really using and not the |
436 | /* better to send back what we are really using and not the |
417 | * param as given to us in case it gets parsed differently. |
437 | * param as given to us in case it gets parsed differently. |
418 | */ |
438 | */ |
419 | sprintf(tmpbuf,"%dx%d", x,y); |
439 | sprintf(tmpbuf,"%dx%d", x,y); |
420 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
440 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
421 | /* If beyond this size and still using orig map command, need to |
441 | /* If beyond this size and still using orig map command, need to |
422 | * go to map1cmd. |
442 | * go to map1cmd. |
423 | */ |
443 | */ |
424 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
444 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
425 | } |
445 | } |
426 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
446 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
427 | /* Added by tchize |
447 | /* Added by tchize |
428 | * prepare to use the mapextended command |
448 | * prepare to use the mapextended command |
429 | */ |
449 | */ |
430 | char tmpbuf[20]; |
450 | char tmpbuf[20]; |
431 | ns->ext_mapinfos = (atoi(param)); |
451 | ns->ext_mapinfos = (atoi(param)); |
432 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
452 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
433 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
453 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
434 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
454 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
435 | /* Added by tchize |
455 | /* Added by tchize |
436 | * prepare to use the extended text commands |
456 | * prepare to use the extended text commands |
437 | * Client toggle this to non zero to get exttext |
457 | * Client toggle this to non zero to get exttext |
438 | */ |
458 | */ |
439 | char tmpbuf[20]; |
459 | char tmpbuf[20]; |
440 | |
460 | |
441 | ns->has_readable_type = (atoi(param)); |
461 | ns->has_readable_type = (atoi(param)); |
442 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
462 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
443 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
463 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
444 | } else { |
464 | } else { |
445 | /* Didn't get a setup command we understood - |
465 | /* Didn't get a setup command we understood - |
446 | * report a failure to the client. |
466 | * report a failure to the client. |
447 | */ |
467 | */ |
448 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
468 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
449 | } |
469 | } |
450 | } /* for processing all the setup commands */ |
470 | } /* for processing all the setup commands */ |
451 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
471 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
452 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
472 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
453 | } |
473 | } |
454 | |
474 | |
… | |
… | |
461 | void AddMeCmd(char *buf, int len, NewSocket *ns) |
481 | void AddMeCmd(char *buf, int len, NewSocket *ns) |
462 | { |
482 | { |
463 | Settings oldsettings; |
483 | Settings oldsettings; |
464 | oldsettings=settings; |
484 | oldsettings=settings; |
465 | if (ns->status != Ns_Add || add_player(ns)) { |
485 | if (ns->status != Ns_Add || add_player(ns)) { |
466 | Write_String_To_Socket(ns, "addme_failed",12); |
486 | Write_String_To_Socket(ns, "addme_failed",12); |
467 | } else { |
487 | } else { |
468 | /* Basically, the add_player copies the socket structure into |
488 | /* Basically, the add_player copies the socket structure into |
469 | * the player structure, so this one (which is from init_sockets) |
489 | * the player structure, so this one (which is from init_sockets) |
470 | * is not needed anymore. The write below should still work, as the |
490 | * is not needed anymore. The write below should still work, as the |
471 | * stuff in ns is still relevant. |
491 | * stuff in ns is still relevant. |
472 | */ |
492 | */ |
473 | Write_String_To_Socket(ns, "addme_success",13); |
493 | Write_String_To_Socket(ns, "addme_success",13); |
474 | socket_info.nconns--; |
494 | socket_info.nconns--; |
475 | ns->status = Ns_Avail; |
495 | ns->status = Ns_Avail; |
476 | } |
496 | } |
477 | settings=oldsettings; |
497 | settings=oldsettings; |
478 | } |
498 | } |
479 | |
499 | |
480 | /** Reply to ExtendedInfos command */ |
500 | /** Reply to ExtendedInfos command */ |
… | |
… | |
575 | */ |
595 | */ |
576 | if ((!FindSmooth (face, &smoothface)) && |
596 | if ((!FindSmooth (face, &smoothface)) && |
577 | (!FindSmooth ( smooth_face->number, &smoothface))) { |
597 | (!FindSmooth ( smooth_face->number, &smoothface))) { |
578 | |
598 | |
579 | LOG(llevError,"could not findsmooth for %d. Neither default (%s)\n",face,smooth_face->name); |
599 | LOG(llevError,"could not findsmooth for %d. Neither default (%s)\n",face,smooth_face->name); |
580 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
600 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
581 | return; |
601 | return; |
582 | } |
602 | } |
583 | |
603 | |
584 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
604 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
585 | esrv_send_face(ns, smoothface, 0); |
605 | esrv_send_face(ns, smoothface, 0); |
586 | |
606 | |
587 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
607 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
588 | |
608 | |
589 | sl.buf=reply; |
609 | sl.buf=reply; |
590 | strcpy((char*)sl.buf,"smooth "); |
610 | strcpy((char*)sl.buf,"smooth "); |
… | |
… | |
620 | * Therefore, the error message doesn't have to be too clear - if |
640 | * Therefore, the error message doesn't have to be too clear - if |
621 | * someone is playing with a hacked/non working client, this gives them |
641 | * someone is playing with a hacked/non working client, this gives them |
622 | * an idea of the problem, but they deserve what they get |
642 | * an idea of the problem, but they deserve what they get |
623 | */ |
643 | */ |
624 | if (pl->state!=ST_PLAYING) { |
644 | if (pl->state!=ST_PLAYING) { |
625 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
645 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
626 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
646 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
627 | return; |
647 | return; |
628 | } |
648 | } |
629 | /* Check if there is a count. In theory, a zero count could also be |
649 | /* Check if there is a count. In theory, a zero count could also be |
630 | * sent, so check for that also. |
650 | * sent, so check for that also. |
631 | */ |
651 | */ |
632 | if (atoi(buf) || buf[0]=='0') { |
652 | if (atoi(buf) || buf[0]=='0') { |
633 | pl->count=atoi((char*)buf); |
653 | pl->count=atoi((char*)buf); |
634 | buf=strchr(buf,' '); /* advance beyond the numbers */ |
654 | buf=strchr(buf,' '); /* advance beyond the numbers */ |
635 | if (!buf) { |
655 | if (!buf) { |
636 | #ifdef ESRV_DEBUG |
656 | #ifdef ESRV_DEBUG |
637 | LOG(llevDebug,"PlayerCmd: Got count but no command.\n"); |
657 | LOG(llevDebug,"PlayerCmd: Got count but no command.\n"); |
638 | #endif |
658 | #endif |
639 | return; |
659 | return; |
640 | } |
660 | } |
641 | buf++; |
661 | buf++; |
642 | } |
662 | } |
643 | /* This should not happen anymore. */ |
663 | /* This should not happen anymore. */ |
644 | if (pl->ob->speed_left<-1.0) { |
664 | if (pl->ob->speed_left<-1.0) { |
645 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
665 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
646 | } |
666 | } |
647 | /* In c_new.c */ |
667 | /* In c_new.c */ |
648 | execute_newserver_command(pl->ob, (char*)buf); |
668 | execute_newserver_command(pl->ob, (char*)buf); |
649 | /* Perhaps something better should be done with a left over count. |
669 | /* Perhaps something better should be done with a left over count. |
650 | * Cleaning up the input should probably be done first - all actions |
670 | * Cleaning up the input should probably be done first - all actions |
… | |
… | |
669 | short packet; |
689 | short packet; |
670 | unsigned char command[MAX_BUF]; |
690 | unsigned char command[MAX_BUF]; |
671 | SockList sl; |
691 | SockList sl; |
672 | |
692 | |
673 | if (len < 7) { |
693 | if (len < 7) { |
674 | LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf); |
694 | LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf); |
675 | return; |
695 | return; |
676 | } |
696 | } |
677 | |
697 | |
678 | packet = GetShort_String(buf); |
698 | packet = GetShort_String(buf); |
679 | repeat = GetInt_String(buf+2); |
699 | repeat = GetInt_String(buf+2); |
680 | /* -1 is special - no repeat, but don't update */ |
700 | /* -1 is special - no repeat, but don't update */ |
681 | if (repeat!=-1) { |
701 | if (repeat!=-1) { |
682 | pl->count=repeat; |
702 | pl->count=repeat; |
683 | } |
703 | } |
684 | if ((len-4) >= MAX_BUF) len=MAX_BUF-5; |
704 | if ((len-4) >= MAX_BUF) len=MAX_BUF-5; |
685 | |
705 | |
686 | strncpy((char*)command, (char*)buf+6, len-4); |
706 | strncpy((char*)command, (char*)buf+6, len-4); |
687 | command[len-4]='\0'; |
707 | command[len-4]='\0'; |
… | |
… | |
690 | * Therefore, the error message doesn't have to be too clear - if |
710 | * Therefore, the error message doesn't have to be too clear - if |
691 | * someone is playing with a hacked/non working client, this gives them |
711 | * someone is playing with a hacked/non working client, this gives them |
692 | * an idea of the problem, but they deserve what they get |
712 | * an idea of the problem, but they deserve what they get |
693 | */ |
713 | */ |
694 | if (pl->state!=ST_PLAYING) { |
714 | if (pl->state!=ST_PLAYING) { |
695 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
715 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
696 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
716 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
697 | return; |
717 | return; |
698 | } |
718 | } |
699 | |
719 | |
700 | /* This should not happen anymore. */ |
720 | /* This should not happen anymore. */ |
701 | if (pl->ob->speed_left<-1.0) { |
721 | if (pl->ob->speed_left<-1.0) { |
702 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
722 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
703 | } |
723 | } |
704 | /* In c_new.c */ |
724 | /* In c_new.c */ |
705 | execute_newserver_command(pl->ob, (char*)command); |
725 | execute_newserver_command(pl->ob, (char*)command); |
706 | /* Perhaps something better should be done with a left over count. |
726 | /* Perhaps something better should be done with a left over count. |
707 | * Cleaning up the input should probably be done first - all actions |
727 | * Cleaning up the input should probably be done first - all actions |
… | |
… | |
715 | strcpy((char*)sl.buf,"comc "); |
735 | strcpy((char*)sl.buf,"comc "); |
716 | sl.len=5; |
736 | sl.len=5; |
717 | SockList_AddShort(&sl,packet); |
737 | SockList_AddShort(&sl,packet); |
718 | if (FABS(pl->ob->speed) < 0.001) time=MAX_TIME * 100; |
738 | if (FABS(pl->ob->speed) < 0.001) time=MAX_TIME * 100; |
719 | else |
739 | else |
720 | time = ( int )( MAX_TIME/ FABS(pl->ob->speed) ); |
740 | time = ( int )( MAX_TIME/ FABS(pl->ob->speed) ); |
721 | SockList_AddInt(&sl,time); |
741 | SockList_AddInt(&sl,time); |
722 | Send_With_Handling(&pl->socket, &sl); |
742 | Send_With_Handling(&pl->socket, &sl); |
723 | } |
743 | } |
724 | |
744 | |
725 | |
745 | |
… | |
… | |
737 | snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
757 | snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
738 | |
758 | |
739 | /* this avoids any hacking here */ |
759 | /* this avoids any hacking here */ |
740 | |
760 | |
741 | switch (pl->state) { |
761 | switch (pl->state) { |
742 | case ST_PLAYING: |
762 | case ST_PLAYING: |
743 | LOG(llevError,"Got reply message with ST_PLAYING input state\n"); |
763 | LOG(llevError,"Got reply message with ST_PLAYING input state\n"); |
744 | break; |
764 | break; |
745 | |
765 | |
746 | case ST_PLAY_AGAIN: |
766 | case ST_PLAY_AGAIN: |
747 | /* We can check this for return value (2==quit). Maybe we |
767 | /* We can check this for return value (2==quit). Maybe we |
748 | * should, and do something appropriate? |
768 | * should, and do something appropriate? |
749 | */ |
769 | */ |
750 | receive_play_again(pl->ob, buf[0]); |
770 | receive_play_again(pl->ob, buf[0]); |
751 | break; |
771 | break; |
752 | |
772 | |
753 | case ST_ROLL_STAT: |
773 | case ST_ROLL_STAT: |
754 | key_roll_stat(pl->ob,buf[0]); |
774 | key_roll_stat(pl->ob,buf[0]); |
755 | break; |
775 | break; |
756 | |
776 | |
757 | case ST_CHANGE_CLASS: |
777 | case ST_CHANGE_CLASS: |
758 | |
778 | |
759 | key_change_class(pl->ob, buf[0]); |
779 | key_change_class(pl->ob, buf[0]); |
760 | break; |
780 | break; |
761 | |
781 | |
762 | case ST_CONFIRM_QUIT: |
782 | case ST_CONFIRM_QUIT: |
763 | key_confirm_quit(pl->ob, buf[0]); |
783 | key_confirm_quit(pl->ob, buf[0]); |
764 | break; |
784 | break; |
765 | |
785 | |
766 | case ST_CONFIGURE: |
786 | case ST_CONFIGURE: |
767 | LOG(llevError,"In client input handling, but into configure state\n"); |
787 | LOG(llevError,"In client input handling, but into configure state\n"); |
768 | pl->state = ST_PLAYING; |
788 | pl->state = ST_PLAYING; |
769 | break; |
789 | break; |
770 | |
790 | |
771 | case ST_GET_NAME: |
791 | case ST_GET_NAME: |
772 | receive_player_name(pl->ob,13); |
792 | receive_player_name(pl->ob,13); |
773 | break; |
793 | break; |
774 | |
794 | |
775 | case ST_GET_PASSWORD: |
795 | case ST_GET_PASSWORD: |
776 | case ST_CONFIRM_PASSWORD: |
796 | case ST_CONFIRM_PASSWORD: |
777 | receive_player_password(pl->ob,13); |
797 | receive_player_password(pl->ob,13); |
778 | break; |
798 | break; |
779 | |
799 | |
780 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
800 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
781 | receive_party_password(pl->ob,13); |
801 | receive_party_password(pl->ob,13); |
782 | break; |
802 | break; |
783 | |
803 | |
784 | default: |
804 | default: |
785 | LOG(llevError,"Unknown input state: %d\n", pl->state); |
805 | LOG(llevError,"Unknown input state: %d\n", pl->state); |
786 | } |
806 | } |
787 | } |
807 | } |
788 | |
808 | |
789 | /** |
809 | /** |
790 | * Client tells its version. If there is a mismatch, we close the |
810 | * Client tells its version. If there is a mismatch, we close the |
… | |
… | |
795 | */ |
815 | */ |
796 | void VersionCmd(char *buf, int len,NewSocket *ns) |
816 | void VersionCmd(char *buf, int len,NewSocket *ns) |
797 | { |
817 | { |
798 | char *cp; |
818 | char *cp; |
799 | char version_warning[256]; |
819 | char version_warning[256]; |
800 | |
820 | |
801 | if (!buf) { |
821 | if (!buf) { |
802 | LOG(llevError, "CS: received corrupted version command\n"); |
822 | LOG(llevError, "CS: received corrupted version command\n"); |
803 | return; |
823 | return; |
804 | } |
824 | } |
805 | |
825 | |
806 | ns->cs_version = atoi(buf); |
826 | ns->cs_version = atoi(buf); |
807 | ns->sc_version = ns->cs_version; |
827 | ns->sc_version = ns->cs_version; |
808 | if (VERSION_CS != ns->cs_version) { |
828 | if (VERSION_CS != ns->cs_version) { |
809 | #ifdef ESRV_DEBUG |
829 | #ifdef ESRV_DEBUG |
810 | LOG(llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS,ns->cs_version); |
830 | LOG(llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS,ns->cs_version); |
811 | #endif |
831 | #endif |
812 | } |
832 | } |
813 | cp = strchr(buf+1,' '); |
833 | cp = strchr(buf+1,' '); |
814 | if (!cp) return; |
834 | if (!cp) return; |
815 | ns->sc_version = atoi(cp); |
835 | ns->sc_version = atoi(cp); |
816 | if (VERSION_SC != ns->sc_version) { |
836 | if (VERSION_SC != ns->sc_version) { |
817 | #ifdef ESRV_DEBUG |
837 | #ifdef ESRV_DEBUG |
818 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
838 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
819 | #endif |
839 | #endif |
820 | } |
840 | } |
821 | cp = strchr(cp+1, ' '); |
841 | cp = strchr(cp+1, ' '); |
822 | if (cp) { |
842 | if (cp) { |
823 | LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
843 | LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
824 | |
844 | |
|
|
845 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
|
|
846 | |
825 | /* This is first implementation - i skip all beta DX clients with it |
847 | /* This is first implementation - i skip all beta DX clients with it |
826 | * Add later stuff here for other clients |
848 | * Add later stuff here for other clients |
827 | */ |
849 | */ |
828 | |
850 | |
829 | /* these are old dxclients */ |
851 | /* these are old dxclients */ |
830 | /* Version 1024 added support for singular + plural name values - |
852 | /* Version 1024 added support for singular + plural name values - |
831 | * requiing this minimal value reduces complexity of that code, and it |
853 | * requiing this minimal value reduces complexity of that code, and it |
832 | * has been around for a long time. |
854 | * has been around for a long time. |
833 | */ |
855 | */ |
834 | if(!strcmp(" CF DX CLIENT", cp) || ns->sc_version < 1024 ) |
856 | if(!strcmp(" CF DX CLIENT", cp) || ns->sc_version < 1024 ) |
835 | { |
857 | { |
836 | sprintf(version_warning,"drawinfo %d %s", NDI_RED, "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
858 | sprintf(version_warning,"drawinfo %d %s", NDI_RED, "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
837 | Write_String_To_Socket(ns, version_warning, strlen(version_warning)); |
859 | Write_String_To_Socket(ns, version_warning, strlen(version_warning)); |
838 | } |
860 | } |
839 | |
861 | |
840 | } |
862 | } |
841 | } |
863 | } |
842 | |
864 | |
843 | /** sound related functions. */ |
865 | /** sound related functions. */ |
… | |
… | |
877 | * we obviously am not going to find a space after the third |
899 | * we obviously am not going to find a space after the third |
878 | * record. Perhaps we should just replace this with a |
900 | * record. Perhaps we should just replace this with a |
879 | * sscanf? |
901 | * sscanf? |
880 | */ |
902 | */ |
881 | for (i=0; i<2; i++) { |
903 | for (i=0; i<2; i++) { |
882 | vals[i]=atoi(buf); |
904 | vals[i]=atoi(buf); |
883 | if (!(buf = strchr(buf, ' '))) { |
905 | if (!(buf = strchr(buf, ' '))) { |
884 | LOG(llevError,"Incomplete move command: %s\n", buf); |
906 | LOG(llevError,"Incomplete move command: %s\n", buf); |
885 | return; |
907 | return; |
886 | } |
908 | } |
887 | buf++; |
909 | buf++; |
888 | } |
910 | } |
889 | vals[2]=atoi(buf); |
911 | vals[2]=atoi(buf); |
890 | |
912 | |
891 | /* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ |
913 | /* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ |
892 | esrv_move_object(pl->ob,vals[0], vals[1], vals[2]); |
914 | esrv_move_object(pl->ob,vals[0], vals[1], vals[2]); |
… | |
… | |
911 | sprintf(buf,"query %d %s", flags, text?text:""); |
933 | sprintf(buf,"query %d %s", flags, text?text:""); |
912 | Write_String_To_Socket(ns, buf, strlen(buf)); |
934 | Write_String_To_Socket(ns, buf, strlen(buf)); |
913 | } |
935 | } |
914 | |
936 | |
915 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
937 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
916 | Old = New; \ |
938 | Old = New; \ |
917 | SockList_AddChar(&sl, Type); \ |
939 | SockList_AddChar(&sl, Type); \ |
918 | SockList_AddInt64(&sl, New); \ |
940 | SockList_AddInt64(&sl, New); \ |
919 | } |
941 | } |
920 | |
942 | |
921 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
943 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
922 | Old = New; \ |
944 | Old = New; \ |
923 | SockList_AddChar(&sl, Type); \ |
945 | SockList_AddChar(&sl, Type); \ |
924 | SockList_AddInt(&sl, New); \ |
946 | SockList_AddInt(&sl, New); \ |
925 | } |
947 | } |
926 | |
948 | |
927 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
949 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
928 | Old = New; \ |
950 | Old = New; \ |
929 | SockList_AddChar(&sl, Type); \ |
951 | SockList_AddChar(&sl, Type); \ |
930 | SockList_AddShort(&sl, New); \ |
952 | SockList_AddShort(&sl, New); \ |
931 | } |
953 | } |
932 | |
954 | |
933 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
955 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
934 | Old = New; \ |
956 | Old = New; \ |
935 | SockList_AddChar(&sl, Type); \ |
957 | SockList_AddChar(&sl, Type); \ |
936 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
958 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
937 | } |
959 | } |
938 | |
960 | |
939 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
961 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
940 | if (Old) free(Old);\ |
962 | if (Old) free(Old);\ |
941 | Old = strdup_local(New);\ |
963 | Old = strdup_local(New);\ |
942 | SockList_AddChar(&sl, Type); \ |
964 | SockList_AddChar(&sl, Type); \ |
943 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
965 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
944 | strcpy((char*)sl.buf + sl.len, New); \ |
966 | strcpy((char*)sl.buf + sl.len, New); \ |
945 | sl.len += strlen(New); \ |
967 | sl.len += strlen(New); \ |
946 | } |
968 | } |
947 | |
969 | |
948 | /** |
970 | /** |
949 | * Sends a statistics update. We look at the old values, |
971 | * Sends a statistics update. We look at the old values, |
950 | * and only send what has changed. Stat mapping values are in newclient.h |
972 | * and only send what has changed. Stat mapping values are in newclient.h |
951 | * Since this gets sent a lot, this is actually one of the few binary |
973 | * Since this gets sent a lot, this is actually one of the few binary |
… | |
… | |
976 | AddIfShort(pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
998 | AddIfShort(pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
977 | AddIfShort(pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
999 | AddIfShort(pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
978 | AddIfShort(pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1000 | AddIfShort(pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
979 | } |
1001 | } |
980 | if(pl->socket.exp64) { |
1002 | if(pl->socket.exp64) { |
981 | uint8 s; |
1003 | uint8 s; |
982 | for(s=0;s<NUM_SKILLS;s++) { |
1004 | for(s=0;s<NUM_SKILLS;s++) { |
983 | if (pl->last_skill_ob[s] && |
1005 | if (pl->last_skill_ob[s] && |
984 | pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) { |
1006 | pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) { |
985 | |
1007 | |
986 | /* Always send along the level if exp changes. This is only |
1008 | /* Always send along the level if exp changes. This is only |
987 | * 1 extra byte, but keeps processing simpler. |
1009 | * 1 extra byte, but keeps processing simpler. |
988 | */ |
1010 | */ |
989 | SockList_AddChar(&sl, ( char )( s + CS_STAT_SKILLINFO )); |
1011 | SockList_AddChar(&sl, ( char )( s + CS_STAT_SKILLINFO )); |
990 | SockList_AddChar(&sl, ( char )pl->last_skill_ob[s]->level); |
1012 | SockList_AddChar(&sl, ( char )pl->last_skill_ob[s]->level); |
991 | SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
1013 | SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
992 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1014 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
993 | } |
1015 | } |
994 | } |
1016 | } |
995 | } |
1017 | } |
996 | if (pl->socket.exp64) { |
1018 | if (pl->socket.exp64) { |
997 | AddIfInt64(pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1019 | AddIfInt64(pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
998 | } else { |
1020 | } else { |
999 | AddIfInt(pl->last_stats.exp, ( int )pl->ob->stats.exp, CS_STAT_EXP); |
1021 | AddIfInt(pl->last_stats.exp, ( int )pl->ob->stats.exp, CS_STAT_EXP); |
1000 | } |
1022 | } |
1001 | AddIfShort(pl->last_level, ( char )pl->ob->level, CS_STAT_LEVEL); |
1023 | AddIfShort(pl->last_level, ( char )pl->ob->level, CS_STAT_LEVEL); |
1002 | AddIfShort(pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1024 | AddIfShort(pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1003 | AddIfShort(pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1025 | AddIfShort(pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1004 | AddIfShort(pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1026 | AddIfShort(pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
… | |
… | |
1010 | if (pl->fire_on) flags |=SF_FIREON; |
1032 | if (pl->fire_on) flags |=SF_FIREON; |
1011 | if (pl->run_on) flags |= SF_RUNON; |
1033 | if (pl->run_on) flags |= SF_RUNON; |
1012 | |
1034 | |
1013 | AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
1035 | AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
1014 | if (pl->socket.sc_version<1025) { |
1036 | if (pl->socket.sc_version<1025) { |
1015 | AddIfShort(pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1037 | AddIfShort(pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1016 | } else { |
1038 | } else { |
1017 | int i; |
1039 | int i; |
1018 | |
1040 | |
1019 | for (i=0; i<NROFATTACKS; i++) { |
1041 | for (i=0; i<NROFATTACKS; i++) { |
1020 | /* Skip ones we won't send */ |
1042 | /* Skip ones we won't send */ |
1021 | if (atnr_cs_stat[i]==-1) continue; |
1043 | if (atnr_cs_stat[i]==-1) continue; |
1022 | AddIfShort(pl->last_resist[i], pl->ob->resist[i], ( char )atnr_cs_stat[i]); |
1044 | AddIfShort(pl->last_resist[i], pl->ob->resist[i], ( char )atnr_cs_stat[i]); |
1023 | } |
1045 | } |
1024 | } |
1046 | } |
1025 | if (pl->socket.monitor_spells) { |
1047 | if (pl->socket.monitor_spells) { |
1026 | AddIfInt(pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1048 | AddIfInt(pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1027 | AddIfInt(pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1049 | AddIfInt(pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1028 | AddIfInt(pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1050 | AddIfInt(pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1029 | } |
1051 | } |
1030 | rangetostring(pl->ob, buf); /* we want use the new fire & run system in new client */ |
1052 | rangetostring(pl->ob, buf); /* we want use the new fire & run system in new client */ |
1031 | AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
1053 | AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
1032 | set_title(pl->ob, buf); |
1054 | set_title(pl->ob, buf); |
1033 | AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
1055 | AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
1034 | |
1056 | |
1035 | /* Only send it away if we have some actual data */ |
1057 | /* Only send it away if we have some actual data */ |
1036 | if (sl.len>6) { |
1058 | if (sl.len>6) { |
1037 | #ifdef ESRV_DEBUG |
1059 | #ifdef ESRV_DEBUG |
1038 | LOG(llevDebug,"Sending stats command, %d bytes long.\n", sl.len); |
1060 | LOG(llevDebug,"Sending stats command, %d bytes long.\n", sl.len); |
1039 | #endif |
1061 | #endif |
1040 | Send_With_Handling(&pl->socket, &sl); |
1062 | Send_With_Handling(&pl->socket, &sl); |
1041 | } |
1063 | } |
1042 | free(sl.buf); |
1064 | free(sl.buf); |
1043 | } |
1065 | } |
1044 | |
1066 | |
1045 | |
1067 | |
… | |
… | |
1085 | /* Do some checking on the anim_num we got. Note that the animations |
1107 | /* Do some checking on the anim_num we got. Note that the animations |
1086 | * are added in contigous order, so if the number is in the valid |
1108 | * are added in contigous order, so if the number is in the valid |
1087 | * range, it must be a valid animation. |
1109 | * range, it must be a valid animation. |
1088 | */ |
1110 | */ |
1089 | if (anim_num < 0 || anim_num > num_animations) { |
1111 | if (anim_num < 0 || anim_num > num_animations) { |
1090 | LOG(llevError,"esrv_send_anim (%d) out of bounds??\n",anim_num); |
1112 | LOG(llevError,"esrv_send_anim (%d) out of bounds??\n",anim_num); |
1091 | return; |
1113 | return; |
1092 | } |
1114 | } |
1093 | |
1115 | |
1094 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
1116 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
1095 | strcpy((char*)sl.buf, "anim "); |
1117 | strcpy((char*)sl.buf, "anim "); |
1096 | sl.len=5; |
1118 | sl.len=5; |
… | |
… | |
1098 | SockList_AddShort(&sl, 0); /* flags - not used right now */ |
1120 | SockList_AddShort(&sl, 0); /* flags - not used right now */ |
1099 | /* Build up the list of faces. Also, send any information (ie, the |
1121 | /* Build up the list of faces. Also, send any information (ie, the |
1100 | * the face itself) down to the client. |
1122 | * the face itself) down to the client. |
1101 | */ |
1123 | */ |
1102 | for (i=0; i<animations[anim_num].num_animations; i++) { |
1124 | for (i=0; i<animations[anim_num].num_animations; i++) { |
1103 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1125 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1104 | esrv_send_face(ns,animations[anim_num].faces[i],0); |
1126 | esrv_send_face(ns,animations[anim_num].faces[i],0); |
1105 | SockList_AddShort(&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1127 | SockList_AddShort(&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1106 | } |
1128 | } |
1107 | Send_With_Handling(ns, &sl); |
1129 | Send_With_Handling(ns, &sl); |
1108 | free(sl.buf); |
1130 | free(sl.buf); |
1109 | ns->anims_sent[anim_num] = 1; |
1131 | ns->anims_sent[anim_num] = 1; |
1110 | } |
1132 | } |
… | |
… | |
1119 | /** |
1141 | /** |
1120 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1142 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1121 | * the face yet, we will also send it. |
1143 | * the face yet, we will also send it. |
1122 | */ |
1144 | */ |
1123 | static void esrv_map_setbelow(NewSocket *ns, int x,int y, |
1145 | static void esrv_map_setbelow(NewSocket *ns, int x,int y, |
1124 | short face_num, struct Map *newmap) |
1146 | short face_num, struct Map *newmap) |
1125 | { |
1147 | { |
1126 | if(newmap->cells[x][y].count >= MAP_LAYERS) { |
1148 | if(newmap->cells[x][y].count >= MAP_LAYERS) { |
1127 | LOG(llevError,"Too many faces in map cell %d %d\n",x,y); |
1149 | LOG(llevError,"Too many faces in map cell %d %d\n",x,y); |
1128 | return; |
1150 | return; |
1129 | abort(); |
1151 | abort(); |
1130 | } |
1152 | } |
1131 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1153 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1132 | newmap->cells[x][y].count ++; |
1154 | newmap->cells[x][y].count ++; |
1133 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1155 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1134 | esrv_send_face(ns,face_num,0); |
1156 | esrv_send_face(ns,face_num,0); |
1135 | } |
1157 | } |
1136 | |
1158 | |
1137 | struct LayerCell { |
1159 | struct LayerCell { |
1138 | uint16 xy; |
1160 | uint16 xy; |
1139 | short face; |
1161 | short face; |
… | |
… | |
1151 | |
1173 | |
1152 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1174 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1153 | return 1; |
1175 | return 1; |
1154 | for(k=0;k<newmap->cells[i][j].count;k++) { |
1176 | for(k=0;k<newmap->cells[i][j].count;k++) { |
1155 | if (ns->lastmap.cells[i][j].faces[k] != |
1177 | if (ns->lastmap.cells[i][j].faces[k] != |
1156 | newmap->cells[i][j].faces[k]) { |
1178 | newmap->cells[i][j].faces[k]) { |
1157 | return 1; |
1179 | return 1; |
1158 | } |
1180 | } |
1159 | } |
1181 | } |
1160 | return 0; |
1182 | return 0; |
1161 | } |
1183 | } |
… | |
… | |
1165 | * cnum is the client number, cur is the the buffer we put all of |
1187 | * cnum is the client number, cur is the the buffer we put all of |
1166 | * this data into. we return the end of the data. layers is |
1188 | * this data into. we return the end of the data. layers is |
1167 | * how many layers of data we should back. |
1189 | * how many layers of data we should back. |
1168 | */ |
1190 | */ |
1169 | static uint8 *compactlayer(NewSocket *ns, unsigned char *cur, int numlayers, |
1191 | static uint8 *compactlayer(NewSocket *ns, unsigned char *cur, int numlayers, |
1170 | struct Map *newmap) |
1192 | struct Map *newmap) |
1171 | { |
1193 | { |
1172 | int x,y,k; |
1194 | int x,y,k; |
1173 | int face; |
1195 | int face; |
1174 | unsigned char *fcur; |
1196 | unsigned char *fcur; |
1175 | struct MapLayer layers[MAP_LAYERS]; |
1197 | struct MapLayer layers[MAP_LAYERS]; |
1176 | |
1198 | |
1177 | for(k = 0;k<MAP_LAYERS;k++) |
1199 | for(k = 0;k<MAP_LAYERS;k++) |
1178 | layers[k].count = 0; |
1200 | layers[k].count = 0; |
1179 | fcur = cur; |
1201 | fcur = cur; |
1180 | for(x=0;x<ns->mapx;x++) { |
1202 | for(x=0;x<ns->mapx;x++) { |
1181 | for(y=0;y<ns->mapy;y++) { |
1203 | for(y=0;y<ns->mapy;y++) { |
1182 | if (!mapcellchanged(ns,x,y,newmap)) |
1204 | if (!mapcellchanged(ns,x,y,newmap)) |
1183 | continue; |
1205 | continue; |
1184 | if (newmap->cells[x][y].count == 0) { |
1206 | if (newmap->cells[x][y].count == 0) { |
1185 | *cur = x*ns->mapy+y; /* mark empty space */ |
1207 | *cur = x*ns->mapy+y; /* mark empty space */ |
1186 | cur++; |
1208 | cur++; |
1187 | continue; |
1209 | continue; |
1188 | } |
1210 | } |
1189 | for(k=0;k<newmap->cells[x][y].count;k++) { |
1211 | for(k=0;k<newmap->cells[x][y].count;k++) { |
1190 | layers[k].lcells[layers[k].count].xy = x*ns->mapy+y; |
1212 | layers[k].lcells[layers[k].count].xy = x*ns->mapy+y; |
1191 | layers[k].lcells[layers[k].count].face = |
1213 | layers[k].lcells[layers[k].count].face = |
1192 | newmap->cells[x][y].faces[k]; |
1214 | newmap->cells[x][y].faces[k]; |
1193 | layers[k].count++; |
1215 | layers[k].count++; |
1194 | } |
1216 | } |
1195 | } |
1217 | } |
1196 | } |
1218 | } |
1197 | /* If no data, return now. */ |
1219 | /* If no data, return now. */ |
1198 | if (fcur == cur && layers[0].count == 0) |
1220 | if (fcur == cur && layers[0].count == 0) |
1199 | return cur; |
1221 | return cur; |
1200 | *cur = 255; /* mark end of explicitly cleared cells */ |
1222 | *cur = 255; /* mark end of explicitly cleared cells */ |
1201 | cur++; |
1223 | cur++; |
1202 | /* First pack by layers. */ |
1224 | /* First pack by layers. */ |
1203 | for(k=0;k<numlayers;k++) { |
1225 | for(k=0;k<numlayers;k++) { |
1204 | if (layers[k].count == 0) |
1226 | if (layers[k].count == 0) |
1205 | break; /* once a layer is entirely empty, no layer below it can |
1227 | break; /* once a layer is entirely empty, no layer below it can |
1206 | have anything in it either */ |
1228 | have anything in it either */ |
1207 | /* Pack by entries in thie layer */ |
1229 | /* Pack by entries in thie layer */ |
1208 | for(x=0;x<layers[k].count;) { |
1230 | for(x=0;x<layers[k].count;) { |
1209 | fcur = cur; |
1231 | fcur = cur; |
1210 | *cur = layers[k].lcells[x].face >> 8; |
1232 | *cur = layers[k].lcells[x].face >> 8; |
1211 | cur++; |
1233 | cur++; |
1212 | *cur = layers[k].lcells[x].face & 0xFF; |
1234 | *cur = layers[k].lcells[x].face & 0xFF; |
1213 | cur++; |
1235 | cur++; |
1214 | face = layers[k].lcells[x].face; |
1236 | face = layers[k].lcells[x].face; |
1215 | /* Now, we back the redundant data into 1 byte xy pairings */ |
1237 | /* Now, we back the redundant data into 1 byte xy pairings */ |
1216 | for(y=x;y<layers[k].count;y++) { |
1238 | for(y=x;y<layers[k].count;y++) { |
1217 | if (layers[k].lcells[y].face == face) { |
1239 | if (layers[k].lcells[y].face == face) { |
1218 | *cur = ( uint8 )layers[k].lcells[y].xy; |
1240 | *cur = ( uint8 )layers[k].lcells[y].xy; |
1219 | cur++; |
1241 | cur++; |
1220 | layers[k].lcells[y].face = -1; |
1242 | layers[k].lcells[y].face = -1; |
1221 | } |
1243 | } |
1222 | } |
1244 | } |
1223 | *(cur-1) = *(cur-1) | 128; /* mark for end of xy's; 11*11 < 128 */ |
1245 | *(cur-1) = *(cur-1) | 128; /* mark for end of xy's; 11*11 < 128 */ |
1224 | /* forward over the now redundant data */ |
1246 | /* forward over the now redundant data */ |
1225 | while(x < layers[k].count && |
1247 | while(x < layers[k].count && |
1226 | layers[k].lcells[x].face == -1) |
1248 | layers[k].lcells[x].face == -1) |
1227 | x++; |
1249 | x++; |
1228 | } |
1250 | } |
1229 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1251 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1230 | } |
1252 | } |
1231 | return cur; |
1253 | return cur; |
1232 | } |
1254 | } |
1233 | |
1255 | |
1234 | static void esrv_map_doneredraw(NewSocket *ns, struct Map *newmap) |
1256 | static void esrv_map_doneredraw(NewSocket *ns, struct Map *newmap) |
… | |
… | |
1246 | sl.len=cur-(char*)sl.buf; |
1268 | sl.len=cur-(char*)sl.buf; |
1247 | |
1269 | |
1248 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1270 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1249 | |
1271 | |
1250 | if (sl.len>( int )strlen("map ") || ns->sent_scroll) { |
1272 | if (sl.len>( int )strlen("map ") || ns->sent_scroll) { |
1251 | /* All of this is just accounting stuff */ |
1273 | /* All of this is just accounting stuff */ |
1252 | if (tframes>100) { |
1274 | if (tframes>100) { |
1253 | tframes = tbytes = 0; |
1275 | tframes = tbytes = 0; |
1254 | } |
1276 | } |
1255 | tframes++; |
1277 | tframes++; |
1256 | frames++; |
1278 | frames++; |
1257 | tbytes += sl.len; |
1279 | tbytes += sl.len; |
1258 | bytes += sl.len; |
1280 | bytes += sl.len; |
1259 | memcpy(&ns->lastmap,newmap,sizeof(struct Map)); |
1281 | memcpy(&ns->lastmap,newmap,sizeof(struct Map)); |
1260 | Send_With_Handling(ns, &sl); |
1282 | Send_With_Handling(ns, &sl); |
1261 | ns->sent_scroll = 0; |
1283 | ns->sent_scroll = 0; |
1262 | } |
1284 | } |
1263 | free(sl.buf); |
1285 | free(sl.buf); |
1264 | } |
1286 | } |
1265 | |
1287 | |
1266 | |
1288 | |
1267 | /** Clears a map cell */ |
1289 | /** Clears a map cell */ |
1268 | static void map_clearcell(struct MapCell *cell, int face0, int face1, int face2, int count) |
1290 | static void map_clearcell(struct MapCell *cell, int face0, int face1, int face2, int count) |
1269 | { |
1291 | { |
1270 | cell->count=count; |
|
|
1271 | cell->faces[0] = face0; |
1292 | cell->faces[0] = face0; |
1272 | cell->faces[1] = face1; |
1293 | cell->faces[1] = face1; |
1273 | cell->faces[2] = face2; |
1294 | cell->faces[2] = face2; |
|
|
1295 | cell->count = count; |
|
|
1296 | cell->stat_hp = 0; |
|
|
1297 | cell->player = 0; |
1274 | } |
1298 | } |
1275 | |
1299 | |
1276 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1300 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1277 | #define MAX_LAYERS 3 |
1301 | #define MAX_LAYERS 3 |
1278 | |
1302 | |
… | |
… | |
1291 | * for empty space checking. |
1315 | * for empty space checking. |
1292 | */ |
1316 | */ |
1293 | static inline int have_head(int ax, int ay) { |
1317 | static inline int have_head(int ax, int ay) { |
1294 | |
1318 | |
1295 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1319 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1296 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || |
1320 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || |
1297 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) return 1; |
1321 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) return 1; |
1298 | return 0; |
1322 | return 0; |
1299 | } |
1323 | } |
1300 | |
1324 | |
1301 | /** |
1325 | /** |
1302 | * check_head is a bit simplistic version of update_space below. |
1326 | * check_head is a bit simplistic version of update_space below. |
1303 | * basically, it only checks the that the head on space ax,ay at layer |
1327 | * basically, it only checks the that the head on space ax,ay at layer |
1304 | * needs to get sent - if so, it adds the data, sending the head |
1328 | * needs to get sent - if so, it adds the data, sending the head |
1305 | * if needed, and returning 1. If this no data needs to get |
1329 | * if needed, and returning 1. If this no data needs to get |
1306 | * sent, it returns zero. |
1330 | * sent, it returns zero. |
1307 | */ |
1331 | */ |
1308 | static inline int check_head(SockList *sl, NewSocket *ns, int ax, int ay, int layer) |
1332 | static int check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) |
1309 | { |
1333 | { |
1310 | short face_num; |
1334 | short face_num; |
1311 | |
1335 | |
1312 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1336 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1313 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1337 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1314 | else |
1338 | else |
1315 | face_num = 0; |
1339 | face_num = 0; |
1316 | |
1340 | |
1317 | if (face_num != ns->lastmap.cells[ax][ay].faces[layer]) { |
1341 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { |
1318 | SockList_AddShort(sl, face_num); |
1342 | SockList_AddShort (&sl, face_num); |
1319 | if (face_num && !(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1343 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1320 | esrv_send_face(ns, face_num, 0); |
1344 | esrv_send_face (&ns, face_num, 0); |
1321 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1345 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1322 | ns->lastmap.cells[ax][ay].faces[layer] = face_num; |
1346 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1323 | return 1; |
1347 | return 1; |
1324 | } |
1348 | } |
1325 | |
1349 | |
1326 | return 0; /* No change */ |
1350 | return 0; /* No change */ |
1327 | } |
1351 | } |
1328 | |
1352 | |
… | |
… | |
1344 | * the map command, where the faces stack up. Sinces that is no longer |
1368 | * the map command, where the faces stack up. Sinces that is no longer |
1345 | * the case, it seems to make more sense to have these layer values |
1369 | * the case, it seems to make more sense to have these layer values |
1346 | * actually match. |
1370 | * actually match. |
1347 | */ |
1371 | */ |
1348 | |
1372 | |
1349 | static inline int update_space(SockList *sl, NewSocket *ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1373 | static int update_space(SockList *sl, NewSocket *ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1350 | { |
1374 | { |
1351 | object *ob, *head; |
1375 | object *ob, *head; |
1352 | uint16 face_num; |
1376 | uint16 face_num; |
1353 | int bx, by,i; |
1377 | int bx, by,i; |
1354 | |
1378 | |
… | |
… | |
1368 | * 3) We need to do some extra checking to make sure that we will |
1392 | * 3) We need to do some extra checking to make sure that we will |
1369 | * otherwise send the image as this layer, eg, either it matches |
1393 | * otherwise send the image as this layer, eg, either it matches |
1370 | * the head value, or is not multipart. |
1394 | * the head value, or is not multipart. |
1371 | */ |
1395 | */ |
1372 | if (head && !head->more) { |
1396 | if (head && !head->more) { |
1373 | for (i=0; i<MAP_LAYERS; i++) { |
1397 | for (i=0; i<MAP_LAYERS; i++) { |
1374 | ob = GET_MAP_FACE_OBJ(mp, mx, my, i); |
1398 | ob = GET_MAP_FACE_OBJ(mp, mx, my, i); |
1375 | if (!ob) continue; |
1399 | if (!ob) continue; |
1376 | |
1400 | |
1377 | if (ob->head) ob=ob->head; |
1401 | if (ob->head) ob=ob->head; |
1378 | |
1402 | |
1379 | if (ob == head) { |
1403 | if (ob == head) { |
1380 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1404 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1381 | head = NULL; |
1405 | head = NULL; |
1382 | break; |
1406 | break; |
1383 | } |
1407 | } |
1384 | } |
1408 | } |
1385 | } |
1409 | } |
1386 | |
1410 | |
1387 | ob = head; |
1411 | ob = head; |
1388 | if (!ob) ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1412 | if (!ob) ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1389 | |
1413 | |
… | |
… | |
1393 | * precedence over the other object for this space. |
1417 | * precedence over the other object for this space. |
1394 | * otherwise, we do special head processing |
1418 | * otherwise, we do special head processing |
1395 | */ |
1419 | */ |
1396 | if (!ob || ob->face == blank_face) face_num=0; |
1420 | if (!ob || ob->face == blank_face) face_num=0; |
1397 | else if (head){ |
1421 | else if (head){ |
1398 | /* if this is a head that had previously been stored */ |
1422 | /* if this is a head that had previously been stored */ |
1399 | face_num = ob->face->number; |
1423 | face_num = ob->face->number; |
1400 | } else { |
1424 | } else { |
1401 | /* if the faces for the different parts of a multipart object |
1425 | /* if the faces for the different parts of a multipart object |
1402 | * are the same, we only want to send the bottom right most |
1426 | * are the same, we only want to send the bottom right most |
1403 | * portion of the object. That info is in the tail_.. values |
1427 | * portion of the object. That info is in the tail_.. values |
1404 | * of the head. Note that for the head itself, ob->head will |
1428 | * of the head. Note that for the head itself, ob->head will |
1405 | * be null, so we only do this block if we are working on |
1429 | * be null, so we only do this block if we are working on |
1406 | * a tail piece. |
1430 | * a tail piece. |
1407 | */ |
1431 | */ |
1408 | |
1432 | |
1409 | /* tail_x and tail_y will only be set in the head object. If |
1433 | /* tail_x and tail_y will only be set in the head object. If |
1410 | * this is the head object and these are set, we proceed |
1434 | * this is the head object and these are set, we proceed |
1411 | * with logic to only send bottom right. Similarly, if |
1435 | * with logic to only send bottom right. Similarly, if |
1412 | * this is one of the more parts but the head has those values |
1436 | * this is one of the more parts but the head has those values |
1413 | * set, we want to do the processing. There can be cases where |
1437 | * set, we want to do the processing. There can be cases where |
1414 | * the head is not visible but one of its parts is, so we just |
1438 | * the head is not visible but one of its parts is, so we just |
1415 | * can always expect that ob->arch->tail_x will be true for all |
1439 | * can always expect that ob->arch->tail_x will be true for all |
1416 | * object we may want to display. |
1440 | * object we may want to display. |
1417 | */ |
1441 | */ |
1418 | if ((ob->arch->tail_x || ob->arch->tail_y) || |
1442 | if ((ob->arch->tail_x || ob->arch->tail_y) || |
1419 | (ob->head && (ob->head->arch->tail_x || ob->head->arch->tail_y))) { |
1443 | (ob->head && (ob->head->arch->tail_x || ob->head->arch->tail_y))) { |
1420 | |
1444 | |
1421 | if (ob->head) head = ob->head; |
1445 | if (ob->head) head = ob->head; |
1422 | else head = ob; |
1446 | else head = ob; |
1423 | |
1447 | |
1424 | /* Basically figure out where the offset is from where we are right |
1448 | /* Basically figure out where the offset is from where we are right |
1425 | * now. the ob->arch->clone.{x,y} values hold the offset that this current |
1449 | * now. the ob->arch->clone.{x,y} values hold the offset that this current |
1426 | * piece is from the head, and the tail is where the tail is from the |
1450 | * piece is from the head, and the tail is where the tail is from the |
1427 | * head. Note that bx and by will equal sx and sy if we are already working |
1451 | * head. Note that bx and by will equal sx and sy if we are already working |
1428 | * on the bottom right corner. If ob is the head, the clone values |
1452 | * on the bottom right corner. If ob is the head, the clone values |
1429 | * will be zero, so the right thing will still happen. |
1453 | * will be zero, so the right thing will still happen. |
1430 | */ |
1454 | */ |
1431 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1455 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1432 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1456 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1433 | |
1457 | |
1434 | /* I don't think this can ever happen, but better to check for it just |
1458 | /* I don't think this can ever happen, but better to check for it just |
1435 | * in case. |
1459 | * in case. |
1436 | */ |
1460 | */ |
1437 | if (bx < sx || by < sy) { |
1461 | if (bx < sx || by < sy) { |
1438 | LOG(llevError,"update_space: bx (%d) or by (%d) is less than sx (%d) or sy (%d)\n", |
1462 | LOG(llevError,"update_space: bx (%d) or by (%d) is less than sx (%d) or sy (%d)\n", |
1439 | bx, by, sx, sy); |
1463 | bx, by, sx, sy); |
1440 | face_num = 0; |
1464 | face_num = 0; |
1441 | } |
1465 | } |
1442 | /* single part object, multipart object with non merged faces, |
1466 | /* single part object, multipart object with non merged faces, |
1443 | * of multipart object already at lower right. |
1467 | * of multipart object already at lower right. |
1444 | */ |
1468 | */ |
1445 | else if (bx == sx && by == sy) { |
1469 | else if (bx == sx && by == sy) { |
1446 | face_num = ob->face->number; |
1470 | face_num = ob->face->number; |
1447 | |
1471 | |
1448 | /* if this face matches one stored away, clear that one away. |
1472 | /* if this face matches one stored away, clear that one away. |
1449 | * this code relies on the fact that the map1 commands |
1473 | * this code relies on the fact that the map1 commands |
1450 | * goes from 2 down to 0. |
1474 | * goes from 2 down to 0. |
1451 | */ |
1475 | */ |
1452 | for (i=0; i<MAP_LAYERS; i++) |
1476 | for (i=0; i<MAP_LAYERS; i++) |
1453 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1477 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1454 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i]->face->number == face_num) |
1478 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i]->face->number == face_num) |
1455 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1479 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1456 | } |
1480 | } |
1457 | else { |
1481 | else { |
1458 | /* If this head is stored away, clear it - otherwise, |
1482 | /* If this head is stored away, clear it - otherwise, |
1459 | * there can be cases where a object is on multiple layers - |
1483 | * there can be cases where a object is on multiple layers - |
1460 | * we only want to send it once. |
1484 | * we only want to send it once. |
1461 | */ |
1485 | */ |
1462 | face_num = head->face->number; |
1486 | face_num = head->face->number; |
1463 | for (i=0; i<MAP_LAYERS; i++) |
1487 | for (i=0; i<MAP_LAYERS; i++) |
1464 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1488 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1465 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i]->face->number == face_num) |
1489 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i]->face->number == face_num) |
1466 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1490 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1467 | |
1491 | |
1468 | /* First, try to put the new head on the same layer. If that is used up, |
1492 | /* First, try to put the new head on the same layer. If that is used up, |
1469 | * then find another layer. |
1493 | * then find another layer. |
1470 | */ |
1494 | */ |
1471 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) { |
1495 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) { |
1472 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1496 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1473 | } else for (i=0; i<MAX_LAYERS; i++) { |
1497 | } else for (i=0; i<MAX_LAYERS; i++) { |
1474 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1498 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1475 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) { |
1499 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) { |
1476 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1500 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1477 | } |
1501 | } |
1478 | } |
1502 | } |
1479 | face_num = 0; /* Don't send this object - we'll send the head later */ |
1503 | face_num = 0; /* Don't send this object - we'll send the head later */ |
1480 | } |
1504 | } |
1481 | } else { |
1505 | } else { |
1482 | /* In this case, we are already at the lower right or single part object, |
1506 | /* In this case, we are already at the lower right or single part object, |
1483 | * so nothing special |
1507 | * so nothing special |
1484 | */ |
1508 | */ |
1485 | face_num = ob->face->number; |
1509 | face_num = ob->face->number; |
1486 | |
1510 | |
1487 | /* clear out any head entries that have the same face as this one */ |
1511 | /* clear out any head entries that have the same face as this one */ |
1488 | for (bx=0; bx<layer; bx++) |
1512 | for (bx=0; bx<layer; bx++) |
1489 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1513 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1490 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx]->face->number == face_num) |
1514 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx]->face->number == face_num) |
1491 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1515 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1492 | } |
1516 | } |
1493 | } /* else not already head object or blank face */ |
1517 | } /* else not already head object or blank face */ |
1494 | |
1518 | |
1495 | /* This is a real hack. Basically, if we have nothing to send for this layer, |
1519 | /* This is a real hack. Basically, if we have nothing to send for this layer, |
1496 | * but there is a head on the next layer, send that instead. |
1520 | * but there is a head on the next layer, send that instead. |
1497 | * Without this, what happens is you can get the case where the player stands |
1521 | * Without this, what happens is you can get the case where the player stands |
1498 | * on the same space as the head. However, if you have overlapping big objects |
1522 | * on the same space as the head. However, if you have overlapping big objects |
1499 | * of the same type, what happens then is it doesn't think it needs to send |
1523 | * of the same type, what happens then is it doesn't think it needs to send |
1500 | * This tends to make stacking also work/look better. |
1524 | * This tends to make stacking also work/look better. |
1501 | */ |
1525 | */ |
1502 | if (!face_num && layer > 0 && heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]) { |
1526 | if (!face_num && layer > 0 && heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]) { |
1503 | face_num = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]->face->number; |
1527 | face_num = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]->face->number; |
1504 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1] = NULL; |
1528 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1] = NULL; |
1505 | } |
1529 | } |
1506 | |
1530 | |
1507 | /* Another hack - because of heads and whatnot, this face may match one |
1531 | /* Another hack - because of heads and whatnot, this face may match one |
1508 | * we already sent for a lower layer. In that case, don't send |
1532 | * we already sent for a lower layer. In that case, don't send |
1509 | * this one. |
1533 | * this one. |
1510 | */ |
1534 | */ |
1511 | if (face_num && layer+1<MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer+1] == face_num) { |
1535 | if (face_num && layer+1<MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer+1] == face_num) { |
1512 | face_num = 0; |
1536 | face_num = 0; |
1513 | } |
1537 | } |
1514 | |
1538 | |
1515 | /* We've gotten what face we want to use for the object. Now see if |
1539 | /* We've gotten what face we want to use for the object. Now see if |
1516 | * if it has changed since we last sent it to the client. |
1540 | * if it has changed since we last sent it to the client. |
1517 | */ |
1541 | */ |
1518 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) { |
1542 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) { |
1519 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1543 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1520 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1544 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1521 | esrv_send_face(ns, face_num, 0); |
1545 | esrv_send_face(ns, face_num, 0); |
1522 | SockList_AddShort(sl, face_num); |
1546 | SockList_AddShort(sl, face_num); |
1523 | return 1; |
1547 | return 1; |
1524 | } |
1548 | } |
1525 | /* Nothing changed */ |
1549 | /* Nothing changed */ |
1526 | return 0; |
1550 | return 0; |
1527 | } |
1551 | } |
1528 | |
1552 | |
… | |
… | |
1555 | /* If there is no object for this space, or if the face for the object |
1579 | /* If there is no object for this space, or if the face for the object |
1556 | * is the blank face, set the smoothlevel to zero. |
1580 | * is the blank face, set the smoothlevel to zero. |
1557 | */ |
1581 | */ |
1558 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH(mp)) smoothlevel=0; |
1582 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH(mp)) smoothlevel=0; |
1559 | else { |
1583 | else { |
1560 | smoothlevel = ob->smoothlevel; |
1584 | smoothlevel = ob->smoothlevel; |
1561 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1585 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1562 | SendSmooth(ns, ob->face->number); |
1586 | SendSmooth(ns, ob->face->number); |
1563 | } /* else not already head object or blank face */ |
1587 | } /* else not already head object or blank face */ |
1564 | |
1588 | |
1565 | /* We've gotten what face we want to use for the object. Now see if |
1589 | /* We've gotten what face we want to use for the object. Now see if |
1566 | * if it has changed since we last sent it to the client. |
1590 | * if it has changed since we last sent it to the client. |
1567 | */ |
1591 | */ |
1568 | if (smoothlevel>255) |
1592 | if (smoothlevel>255) |
1569 | smoothlevel=255; |
1593 | smoothlevel=255; |
1570 | else if (smoothlevel<0) |
1594 | else if (smoothlevel<0) |
1571 | smoothlevel=0; |
1595 | smoothlevel=0; |
1572 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) { |
1596 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) { |
1573 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1597 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1574 | SockList_AddChar(sl, (uint8) (smoothlevel&0xFF)); |
1598 | SockList_AddChar(sl, (uint8) (smoothlevel&0xFF)); |
1575 | return 1; |
1599 | return 1; |
1576 | } |
1600 | } |
1577 | /* Nothing changed */ |
1601 | /* Nothing changed */ |
1578 | return 0; |
1602 | return 0; |
1579 | } |
1603 | } |
1580 | |
1604 | |
… | |
… | |
1623 | uint16 mask,emask; |
1647 | uint16 mask,emask; |
1624 | uint8 eentrysize; |
1648 | uint8 eentrysize; |
1625 | uint16 ewhatstart,ewhatflag; |
1649 | uint16 ewhatstart,ewhatflag; |
1626 | uint8 extendedinfos; |
1650 | uint8 extendedinfos; |
1627 | mapstruct *m; |
1651 | mapstruct *m; |
|
|
1652 | NewSocket &socket = pl->contr->socket; |
1628 | |
1653 | |
1629 | check_map_change (pl->contr); |
1654 | check_map_change (pl->contr); |
1630 | |
1655 | |
1631 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1656 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1632 | if (pl->contr->socket.mapmode == Map1Cmd) |
1657 | if (socket.mapmode == Map1Cmd) |
1633 | strcpy((char*)sl.buf,"map1 "); |
1658 | strcpy((char*)sl.buf,"map1 "); |
1634 | else |
1659 | else |
1635 | strcpy((char*)sl.buf,"map1a "); |
1660 | strcpy((char*)sl.buf,"map1a "); |
1636 | sl.len=strlen((char*)sl.buf); |
1661 | sl.len=strlen((char*)sl.buf); |
1637 | startlen = sl.len; |
1662 | startlen = sl.len; |
1638 | /*Extendedmapinfo structure initialisation*/ |
1663 | /*Extendedmapinfo structure initialisation*/ |
1639 | if (pl->contr->socket.ext_mapinfos){ |
1664 | if (socket.ext_mapinfos){ |
1640 | esl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1665 | esl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1641 | strcpy((char*)esl.buf,"mapextended "); |
1666 | strcpy((char*)esl.buf,"mapextended "); |
1642 | esl.len=strlen((char*)esl.buf); |
1667 | esl.len=strlen((char*)esl.buf); |
1643 | extendedinfos=EMI_NOREDRAW; |
1668 | extendedinfos=EMI_NOREDRAW; |
1644 | if (pl->contr->socket.EMI_smooth) |
1669 | if (socket.EMI_smooth) |
1645 | extendedinfos|=EMI_SMOOTH; |
1670 | extendedinfos|=EMI_SMOOTH; |
1646 | ewhatstart=esl.len; |
1671 | ewhatstart=esl.len; |
1647 | ewhatflag=extendedinfos; /*The EMI_NOREDRAW bit |
1672 | ewhatflag=extendedinfos; /*The EMI_NOREDRAW bit |
1648 | could need to be taken away*/ |
1673 | could need to be taken away*/ |
1649 | SockList_AddChar(&esl, extendedinfos); |
1674 | SockList_AddChar(&esl, extendedinfos); |
1650 | eentrysize=getExtendedMapInfoSize(&(pl->contr->socket)); |
1675 | eentrysize=getExtendedMapInfoSize(&socket); |
1651 | SockList_AddChar(&esl, eentrysize); |
1676 | SockList_AddChar(&esl, eentrysize); |
1652 | estartlen = esl.len; |
1677 | estartlen = esl.len; |
1653 | } else { |
1678 | } else { |
1654 | /* suppress compiler warnings */ |
1679 | /* suppress compiler warnings */ |
1655 | ewhatstart = 0; |
1680 | ewhatstart = 0; |
… | |
… | |
1665 | ay=0; |
1690 | ay=0; |
1666 | |
1691 | |
1667 | /* We could do this logic as conditionals in the if statement, |
1692 | /* We could do this logic as conditionals in the if statement, |
1668 | * but that started to get a bit messy to look at. |
1693 | * but that started to get a bit messy to look at. |
1669 | */ |
1694 | */ |
1670 | max_x = pl->x+(pl->contr->socket.mapx+1)/2; |
1695 | max_x = pl->x+(socket.mapx+1)/2; |
1671 | max_y = pl->y+(pl->contr->socket.mapy+1)/2; |
1696 | max_y = pl->y+(socket.mapy+1)/2; |
1672 | if (pl->contr->socket.mapmode == Map1aCmd) { |
1697 | if (socket.mapmode == Map1aCmd) { |
1673 | max_x += MAX_HEAD_OFFSET; |
1698 | max_x += MAX_HEAD_OFFSET; |
1674 | max_y += MAX_HEAD_OFFSET; |
1699 | max_y += MAX_HEAD_OFFSET; |
1675 | } |
1700 | } |
1676 | |
1701 | |
1677 | for(y=pl->y-pl->contr->socket.mapy/2; y<max_y; y++,ay++) { |
1702 | for(y=pl->y-socket.mapy/2; y<max_y; y++,ay++) { |
1678 | ax=0; |
1703 | ax=0; |
1679 | for(x=pl->x-pl->contr->socket.mapx/2;x<max_x;x++,ax++) { |
1704 | for(x=pl->x-socket.mapx/2;x<max_x;x++,ax++) { |
1680 | |
1705 | |
1681 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1706 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1682 | |
1707 | |
1683 | /* If this space is out of the normal viewable area, we only check |
1708 | /* If this space is out of the normal viewable area, we only check |
1684 | * the heads value ax or ay will only be greater than what |
1709 | * the heads value ax or ay will only be greater than what |
1685 | * the client wants if using the map1a command - this is because |
1710 | * the client wants if using the map1a command - this is because |
1686 | * if the map1a command is not used, max_x and max_y will be |
1711 | * if the map1a command is not used, max_x and max_y will be |
1687 | * set to lower values. |
1712 | * set to lower values. |
1688 | */ |
1713 | */ |
1689 | if (ax >= pl->contr->socket.mapx || ay >= pl->contr->socket.mapy) { |
1714 | if (ax >= socket.mapx || ay >= socket.mapy) { |
1690 | int i, got_one; |
1715 | int i, got_one; |
1691 | |
1716 | |
1692 | oldlen = sl.len; |
1717 | oldlen = sl.len; |
1693 | |
1718 | |
1694 | |
|
|
1695 | SockList_AddShort(&sl, mask); |
1719 | SockList_AddShort(&sl, mask); |
1696 | |
1720 | |
1697 | if (check_head(&sl, &pl->contr->socket, ax, ay, 2)) |
1721 | if (check_head (sl, socket, ax, ay, 2)) |
1698 | mask |= 0x4; |
1722 | mask |= 0x4; |
1699 | if (check_head(&sl, &pl->contr->socket, ax, ay, 1)) |
1723 | if (check_head (sl, socket, ax, ay, 1)) |
1700 | mask |= 0x2; |
1724 | mask |= 0x2; |
1701 | if (check_head(&sl, &pl->contr->socket, ax, ay, 0)) |
1725 | if (check_head (sl, socket, ax, ay, 0)) |
1702 | mask |= 0x1; |
1726 | mask |= 0x1; |
1703 | |
1727 | |
1704 | /* If all we are doing is sending 0 (blank) faces, we don't |
1728 | /* If all we are doing is sending 0 (blank) faces, we don't |
1705 | * actually need to send that - just the coordinates |
1729 | * actually need to send that - just the coordinates |
1706 | * with no faces tells the client to blank out the |
1730 | * with no faces tells the client to blank out the |
1707 | * space. |
1731 | * space. |
1708 | */ |
1732 | */ |
1709 | got_one=0; |
1733 | got_one=0; |
1710 | for (i=oldlen+2; i<sl.len; i++) { |
1734 | for (i=oldlen+2; i<sl.len; i++) { |
1711 | if (sl.buf[i]) got_one=1; |
1735 | if (sl.buf[i]) got_one=1; |
1712 | } |
1736 | } |
1713 | |
1737 | |
1714 | if (got_one && (mask & 0xf)) { |
1738 | if (got_one && (mask & 0xf)) { |
1715 | sl.buf[oldlen+1] = mask & 0xff; |
1739 | sl.buf[oldlen+1] = mask & 0xff; |
1716 | } else { /*either all faces blank, either no face at all*/ |
1740 | } else { /*either all faces blank, either no face at all*/ |
1717 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates*/ |
1741 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates*/ |
1718 | sl.len = oldlen + 2; |
1742 | sl.len = oldlen + 2; |
1719 | else |
1743 | else |
|
|
1744 | sl.len = oldlen; |
|
|
1745 | } |
|
|
1746 | /*What concerns extendinfos, nothing to be done for now |
|
|
1747 | * (perhaps effects layer later) |
|
|
1748 | */ |
|
|
1749 | continue; /* don't do processing below */ |
|
|
1750 | } |
|
|
1751 | |
|
|
1752 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
|
|
1753 | |
|
|
1754 | d = pl->contr->blocked_los[ax][ay]; |
|
|
1755 | |
|
|
1756 | /* If the coordinates are not valid, or it is too dark to see, |
|
|
1757 | * we tell the client as such |
|
|
1758 | */ |
|
|
1759 | nx=x; |
|
|
1760 | ny=y; |
|
|
1761 | m = get_map_from_coord(pl->map, &nx, &ny); |
|
|
1762 | if (!m) { |
|
|
1763 | /* space is out of map. Update space and clear values |
|
|
1764 | * if this hasn't already been done. If the space is out |
|
|
1765 | * of the map, it shouldn't have a head |
|
|
1766 | */ |
|
|
1767 | if (lastcell.count != -1) { |
|
|
1768 | SockList_AddShort(&sl, mask); |
|
|
1769 | map_clearcell(&lastcell,0,0,0,-1); |
|
|
1770 | } |
|
|
1771 | } else if (d>3) { |
|
|
1772 | int need_send=0, count; |
|
|
1773 | /* This block deals with spaces that are not visible for whatever |
|
|
1774 | * reason. Still may need to send the head for this space. |
|
|
1775 | */ |
|
|
1776 | |
|
|
1777 | oldlen = sl.len; |
|
|
1778 | |
|
|
1779 | SockList_AddShort(&sl, mask); |
|
|
1780 | if (lastcell.count != -1) need_send=1; |
|
|
1781 | count = -1; |
|
|
1782 | |
|
|
1783 | if (socket.mapmode == Map1aCmd && have_head(ax, ay)) { |
|
|
1784 | /* Now check to see if any heads need to be sent */ |
|
|
1785 | |
|
|
1786 | if (check_head (sl, socket, ax, ay, 2)) |
|
|
1787 | mask |= 0x4; |
|
|
1788 | if (check_head (sl, socket, ax, ay, 1)) |
|
|
1789 | mask |= 0x2; |
|
|
1790 | if (check_head (sl, socket, ax, ay, 0)) |
|
|
1791 | mask |= 0x1; |
|
|
1792 | |
|
|
1793 | lastcell.count = count; |
|
|
1794 | |
|
|
1795 | } else { |
|
|
1796 | struct MapCell *cell = &lastcell; |
|
|
1797 | /* properly clear a previously sent big face */ |
|
|
1798 | if(cell->faces[0] != 0 |
|
|
1799 | || cell->faces[1] != 0 |
|
|
1800 | || cell->faces[2] != 0) |
|
|
1801 | need_send = 1; |
|
|
1802 | map_clearcell(&lastcell, 0, 0, 0, count); |
|
|
1803 | } |
|
|
1804 | |
|
|
1805 | if ((mask & 0xf) || need_send) { |
|
|
1806 | sl.buf[oldlen+1] = mask & 0xff; |
|
|
1807 | } else { |
1720 | sl.len = oldlen; |
1808 | sl.len = oldlen; |
1721 | } |
1809 | } |
1722 | /*What concerns extendinfos, nothing to be done for now |
1810 | } else { |
1723 | * (perhaps effects layer later) |
|
|
1724 | */ |
|
|
1725 | continue; /* don't do processing below */ |
|
|
1726 | } |
|
|
1727 | |
|
|
1728 | d = pl->contr->blocked_los[ax][ay]; |
|
|
1729 | |
|
|
1730 | /* If the coordinates are not valid, or it is too dark to see, |
|
|
1731 | * we tell the client as such |
|
|
1732 | */ |
|
|
1733 | nx=x; |
|
|
1734 | ny=y; |
|
|
1735 | m = get_map_from_coord(pl->map, &nx, &ny); |
|
|
1736 | if (!m) { |
|
|
1737 | /* space is out of map. Update space and clear values |
|
|
1738 | * if this hasn't already been done. If the space is out |
|
|
1739 | * of the map, it shouldn't have a head |
|
|
1740 | */ |
|
|
1741 | if (pl->contr->socket.lastmap.cells[ax][ay].count != -1) { |
|
|
1742 | SockList_AddShort(&sl, mask); |
|
|
1743 | map_clearcell(&pl->contr->socket.lastmap.cells[ax][ay],0,0,0,-1); |
|
|
1744 | } |
|
|
1745 | } else if (d>3) { |
|
|
1746 | int need_send=0, count; |
|
|
1747 | /* This block deals with spaces that are not visible for whatever |
|
|
1748 | * reason. Still may need to send the head for this space. |
|
|
1749 | */ |
|
|
1750 | |
|
|
1751 | oldlen = sl.len; |
|
|
1752 | #if 0 |
|
|
1753 | /* First thing we do is blank out this space (clear it) |
|
|
1754 | * if not already done. If the client is using darkness, and |
|
|
1755 | * this space is at the edge, we also include the darkness. |
|
|
1756 | */ |
|
|
1757 | if (d==4) { |
|
|
1758 | if (pl->contr->socket.darkness && pl->contr->socket.lastmap.cells[ax][ay].count != d) { |
|
|
1759 | mask |= 8; |
|
|
1760 | SockList_AddShort(&sl, mask); |
|
|
1761 | SockList_AddChar(&sl, 0); |
|
|
1762 | } |
|
|
1763 | count = d; |
|
|
1764 | } else |
|
|
1765 | #endif |
|
|
1766 | { |
|
|
1767 | SockList_AddShort(&sl, mask); |
|
|
1768 | if (pl->contr->socket.lastmap.cells[ax][ay].count != -1) need_send=1; |
|
|
1769 | count = -1; |
|
|
1770 | } |
|
|
1771 | |
|
|
1772 | if (pl->contr->socket.mapmode == Map1aCmd && have_head(ax, ay)) { |
|
|
1773 | /* Now check to see if any heads need to be sent */ |
|
|
1774 | |
|
|
1775 | if (check_head(&sl, &pl->contr->socket, ax, ay, 2)) |
|
|
1776 | mask |= 0x4; |
|
|
1777 | if (check_head(&sl, &pl->contr->socket, ax, ay, 1)) |
|
|
1778 | mask |= 0x2; |
|
|
1779 | if (check_head(&sl, &pl->contr->socket, ax, ay, 0)) |
|
|
1780 | mask |= 0x1; |
|
|
1781 | pl->contr->socket.lastmap.cells[ax][ay].count = count; |
|
|
1782 | |
|
|
1783 | } else { |
|
|
1784 | struct MapCell *cell = &pl->contr->socket.lastmap.cells[ax][ay]; |
|
|
1785 | /* properly clear a previously sent big face */ |
|
|
1786 | if(cell->faces[0] != 0 |
|
|
1787 | || cell->faces[1] != 0 |
|
|
1788 | || cell->faces[2] != 0) |
|
|
1789 | need_send = 1; |
|
|
1790 | map_clearcell(&pl->contr->socket.lastmap.cells[ax][ay], 0, 0, 0, count); |
|
|
1791 | } |
|
|
1792 | |
|
|
1793 | if ((mask & 0xf) || need_send) { |
|
|
1794 | sl.buf[oldlen+1] = mask & 0xff; |
|
|
1795 | } else { |
|
|
1796 | sl.len = oldlen; |
|
|
1797 | } |
|
|
1798 | } else { |
|
|
1799 | /* In this block, the space is visible or there are head objects |
1811 | /* In this block, the space is visible or there are head objects |
1800 | * we need to send. |
1812 | * we need to send. |
1801 | */ |
1813 | */ |
1802 | |
1814 | |
1803 | /* Rather than try to figure out what everything that we might |
1815 | /* Rather than try to figure out what everything that we might |
1804 | * need to send is, then form the packet after that, |
1816 | * need to send is, then form the packet after that, |
1805 | * we presume that we will in fact form a packet, and update |
1817 | * we presume that we will in fact form a packet, and update |
1806 | * the bits by what we do actually send. If we send nothing, |
1818 | * the bits by what we do actually send. If we send nothing, |
1807 | * we just back out sl.len to the old value, and no harm |
1819 | * we just back out sl.len to the old value, and no harm |
1808 | * is done. |
1820 | * is done. |
1809 | * I think this is simpler than doing a bunch of checks to see |
1821 | * I think this is simpler than doing a bunch of checks to see |
1810 | * what if anything we need to send, setting the bits, then |
1822 | * what if anything we need to send, setting the bits, then |
1811 | * doing those checks again to add the real data. |
1823 | * doing those checks again to add the real data. |
1812 | */ |
1824 | */ |
1813 | oldlen = sl.len; |
1825 | oldlen = sl.len; |
1814 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1826 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1815 | eoldlen = esl.len; |
1827 | eoldlen = esl.len; |
1816 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1828 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1817 | SockList_AddShort(&sl, mask); |
|
|
1818 | |
|
|
1819 | if (pl->contr->socket.ext_mapinfos) |
|
|
1820 | SockList_AddShort(&esl, emask); |
1829 | SockList_AddShort(&sl, mask); |
1821 | |
1830 | |
1822 | /* Darkness changed */ |
1831 | if (socket.ext_mapinfos) |
1823 | if (pl->contr->socket.lastmap.cells[ax][ay].count != d && pl->contr->socket.darkness) { |
1832 | SockList_AddShort(&esl, emask); |
1824 | pl->contr->socket.lastmap.cells[ax][ay].count = d; |
|
|
1825 | mask |= 0x8; /* darkness bit */ |
|
|
1826 | |
1833 | |
1827 | /* Protocol defines 255 full bright, 0 full dark. |
1834 | unsigned char dummy; |
1828 | * We currently don't have that many darkness ranges, |
1835 | unsigned char *last_ext = &dummy; |
1829 | * so we current what limited values we do have. |
|
|
1830 | */ |
|
|
1831 | if (d==0) SockList_AddChar(&sl, 255); |
|
|
1832 | else if (d==1) SockList_AddChar(&sl, 191); |
|
|
1833 | else if (d==2) SockList_AddChar(&sl, 127); |
|
|
1834 | else if (d==3) SockList_AddChar(&sl, 63); |
|
|
1835 | } |
|
|
1836 | else { |
|
|
1837 | /* need to reset from -1 so that if it does become blocked again, |
|
|
1838 | * the code that deals with that can detect that it needs to tell |
|
|
1839 | * the client that this space is now blocked. |
|
|
1840 | */ |
|
|
1841 | pl->contr->socket.lastmap.cells[ax][ay].count = d; |
|
|
1842 | } |
|
|
1843 | |
1836 | |
1844 | /* Floor face */ |
1837 | /* Darkness changed */ |
|
|
1838 | if (lastcell.count != d && socket.darkness) { |
|
|
1839 | mask |= 0x8; |
|
|
1840 | |
|
|
1841 | if (socket.extmap) |
|
|
1842 | { |
|
|
1843 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, d); |
|
|
1844 | } |
|
|
1845 | else |
|
|
1846 | SockList_AddChar (&sl, 255 - 64 * d); |
|
|
1847 | } |
|
|
1848 | |
|
|
1849 | lastcell.count = d; |
|
|
1850 | |
|
|
1851 | if (socket.extmap) |
|
|
1852 | { |
|
|
1853 | uint8 stat_hp = 0; |
|
|
1854 | uint8 stat_width = 0; |
|
|
1855 | tag_t player = 0; |
|
|
1856 | |
|
|
1857 | // send hp information, if applicable |
|
|
1858 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
|
|
1859 | { |
|
|
1860 | if (op->head || op->invisible) |
|
|
1861 | ; // do not show |
|
|
1862 | else if (op->type == PLAYER |
|
|
1863 | || QUERY_FLAG (op, FLAG_MONSTER) |
|
|
1864 | || QUERY_FLAG (op, FLAG_ALIVE) |
|
|
1865 | || QUERY_FLAG (op, FLAG_GENERATOR)) |
|
|
1866 | { |
|
|
1867 | if (op->stats.maxhp > 0 |
|
|
1868 | && (unsigned)op->stats.maxhp > (unsigned)op->stats.hp) |
|
|
1869 | { |
|
|
1870 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
|
|
1871 | stat_width = op->arch->tail_x; |
|
|
1872 | } |
|
|
1873 | } |
|
|
1874 | |
|
|
1875 | if (op->type == PLAYER && op != pl) |
|
|
1876 | player = op->count; |
|
|
1877 | } |
|
|
1878 | |
|
|
1879 | if (lastcell.stat_hp != stat_hp && 0) |
|
|
1880 | { |
|
|
1881 | lastcell.stat_hp = stat_hp; |
|
|
1882 | |
|
|
1883 | mask |= 0x8; |
|
|
1884 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 5); |
|
|
1885 | SockList_AddChar (&sl, stat_hp); |
|
|
1886 | |
|
|
1887 | if (stat_width > 1) |
|
|
1888 | { |
|
|
1889 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 6); |
|
|
1890 | SockList_AddChar (&sl, stat_width); |
|
|
1891 | } |
|
|
1892 | } |
|
|
1893 | |
|
|
1894 | if (lastcell.player != player && 0) |
|
|
1895 | { |
|
|
1896 | lastcell.player = player; |
|
|
1897 | mask |= 0x8; |
|
|
1898 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 0x47); |
|
|
1899 | SockList_AddChar (&sl, 4); |
|
|
1900 | SockList_AddInt (&sl, player); |
|
|
1901 | } |
|
|
1902 | } |
|
|
1903 | |
|
|
1904 | /* Floor face */ |
1845 | if (update_space(&sl, &pl->contr->socket, m, nx, ny, ax, ay, 2)) |
1905 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 2)) |
1846 | mask |= 0x4; |
1906 | mask |= 0x4; |
1847 | |
1907 | |
1848 | if (pl->contr->socket.EMI_smooth) |
1908 | if (socket.EMI_smooth) |
1849 | if (update_smooth(&esl, &pl->contr->socket, m, nx, ny, ax, ay, 2)){ |
1909 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 2)) |
1850 | emask |= 0x4; |
1910 | emask |= 0x4; |
1851 | } |
|
|
1852 | |
1911 | |
1853 | /* Middle face */ |
1912 | /* Middle face */ |
1854 | if (update_space(&sl, &pl->contr->socket, m, nx, ny, ax, ay, 1)) |
1913 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 1)) |
1855 | mask |= 0x2; |
1914 | mask |= 0x2; |
1856 | |
1915 | |
1857 | if (pl->contr->socket.EMI_smooth) |
1916 | if (socket.EMI_smooth) |
1858 | if (update_smooth(&esl, &pl->contr->socket, m, nx, ny, ax, ay, 1)){ |
1917 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 1)) |
1859 | emask |= 0x2; |
1918 | emask |= 0x2; |
1860 | } |
|
|
1861 | |
1919 | |
1862 | |
|
|
1863 | if(nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
1920 | if(nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
1864 | if (pl->contr->socket.lastmap.cells[ax][ay].faces[0] != pl->face->number) { |
1921 | if (lastcell.faces[0] != pl->face->number) { |
1865 | pl->contr->socket.lastmap.cells[ax][ay].faces[0] = pl->face->number; |
1922 | lastcell.faces[0] = pl->face->number; |
1866 | mask |= 0x1; |
1923 | mask |= 0x1; |
1867 | if (!(pl->contr->socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) |
1924 | if (!(socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) |
1868 | esrv_send_face(&pl->contr->socket, pl->face->number, 0); |
1925 | esrv_send_face(&socket, pl->face->number, 0); |
1869 | SockList_AddShort(&sl, pl->face->number); |
1926 | SockList_AddShort(&sl, pl->face->number); |
1870 | } |
1927 | } |
1871 | } |
1928 | } |
1872 | /* Top face */ |
1929 | /* Top face */ |
1873 | else { |
1930 | else { |
1874 | if (update_space(&sl, &pl->contr->socket, m, nx, ny, ax, ay, 0)) |
1931 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 0)) |
1875 | mask |= 0x1; |
1932 | mask |= 0x1; |
1876 | if (pl->contr->socket.EMI_smooth) |
1933 | if (socket.EMI_smooth) |
1877 | if (update_smooth(&esl, &pl->contr->socket, m, nx, ny, ax, ay, 0)){ |
1934 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 0)){ |
1878 | emask |= 0x1; |
1935 | emask |= 0x1; |
1879 | } |
1936 | } |
1880 | } |
1937 | } |
1881 | /* Check to see if we are in fact sending anything for this |
1938 | /* Check to see if we are in fact sending anything for this |
1882 | * space by checking the mask. If so, update the mask. |
1939 | * space by checking the mask. If so, update the mask. |
1883 | * if not, reset the len to that from before adding the mask |
1940 | * if not, reset the len to that from before adding the mask |
1884 | * value, so we don't send those bits. |
1941 | * value, so we don't send those bits. |
1885 | */ |
1942 | */ |
1886 | if (mask & 0xf) { |
1943 | if (mask & 0xf) { |
1887 | sl.buf[oldlen+1] = mask & 0xff; |
1944 | sl.buf[oldlen+1] = mask & 0xff; |
1888 | } else { |
1945 | } else { |
1889 | sl.len = oldlen; |
1946 | sl.len = oldlen; |
1890 | } |
1947 | } |
1891 | if (emask & 0xf) { |
1948 | if (emask & 0xf) { |
1892 | esl.buf[eoldlen+1] = emask & 0xff; |
1949 | esl.buf[eoldlen+1] = emask & 0xff; |
1893 | } else { |
1950 | } else { |
1894 | esl.len = eoldlen; |
1951 | esl.len = eoldlen; |
1895 | } |
1952 | } |
1896 | } /* else this is a viewable space */ |
1953 | } /* else this is a viewable space */ |
1897 | } /* for x loop */ |
1954 | } /* for x loop */ |
1898 | } /* for y loop */ |
1955 | } /* for y loop */ |
1899 | |
1956 | |
1900 | /* Verify that we in fact do need to send this */ |
1957 | /* Verify that we in fact do need to send this */ |
1901 | if (pl->contr->socket.ext_mapinfos){ |
1958 | if (socket.ext_mapinfos){ |
1902 | if (!(sl.len>startlen || pl->contr->socket.sent_scroll)){ |
1959 | if (!(sl.len>startlen || socket.sent_scroll)){ |
1903 | /* No map data will follow, so don't say the client |
1960 | /* No map data will follow, so don't say the client |
1904 | * it doesn't need draw! |
1961 | * it doesn't need draw! |
1905 | */ |
1962 | */ |
1906 | ewhatflag&=(~EMI_NOREDRAW); |
1963 | ewhatflag&=(~EMI_NOREDRAW); |
1907 | esl.buf[ewhatstart+1] = ewhatflag & 0xff; |
1964 | esl.buf[ewhatstart+1] = ewhatflag & 0xff; |
1908 | } |
1965 | } |
1909 | if (esl.len>estartlen) { |
1966 | if (esl.len>estartlen) { |
1910 | Send_With_Handling(&pl->contr->socket, &esl); |
1967 | Send_With_Handling(&socket, &esl); |
1911 | } |
1968 | } |
1912 | free(esl.buf); |
1969 | free(esl.buf); |
1913 | } |
1970 | } |
1914 | if (sl.len>startlen || pl->contr->socket.sent_scroll) { |
1971 | if (sl.len>startlen || socket.sent_scroll) { |
1915 | Send_With_Handling(&pl->contr->socket, &sl); |
1972 | Send_With_Handling(&socket, &sl); |
1916 | pl->contr->socket.sent_scroll = 0; |
1973 | socket.sent_scroll = 0; |
1917 | } |
1974 | } |
1918 | free(sl.buf); |
1975 | free(sl.buf); |
1919 | } |
1976 | } |
1920 | |
1977 | |
1921 | /** |
1978 | /** |
… | |
… | |
1930 | int d, mflags; |
1987 | int d, mflags; |
1931 | struct Map newmap; |
1988 | struct Map newmap; |
1932 | mapstruct *m, *pm; |
1989 | mapstruct *m, *pm; |
1933 | |
1990 | |
1934 | if (pl->type != PLAYER) { |
1991 | if (pl->type != PLAYER) { |
1935 | LOG(llevError,"draw_client_map called with non player/non eric-server\n"); |
1992 | LOG(llevError,"draw_client_map called with non player/non eric-server\n"); |
1936 | return; |
1993 | return; |
1937 | } |
1994 | } |
1938 | |
1995 | |
1939 | if (pl->contr->transport) { |
|
|
1940 | pm = pl->contr->transport->map; |
|
|
1941 | } |
|
|
1942 | else |
|
|
1943 | pm = pl->map; |
1996 | pm = pl->map; |
1944 | |
1997 | |
1945 | /* If player is just joining the game, he isn't here yet, so the map |
1998 | /* If player is just joining the game, he isn't here yet, so the map |
1946 | * can get swapped out. If so, don't try to send them a map. All will |
1999 | * can get swapped out. If so, don't try to send them a map. All will |
1947 | * be OK once they really log in. |
2000 | * be OK once they really log in. |
1948 | */ |
2001 | */ |
… | |
… | |
1950 | |
2003 | |
1951 | memset(&newmap, 0, sizeof(struct Map)); |
2004 | memset(&newmap, 0, sizeof(struct Map)); |
1952 | |
2005 | |
1953 | for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { |
2006 | for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { |
1954 | for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) { |
2007 | for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) { |
1955 | ax=i; |
2008 | ax=i; |
1956 | ay=j; |
2009 | ay=j; |
1957 | m = pm; |
2010 | m = pm; |
1958 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
2011 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
1959 | if (mflags & P_OUT_OF_MAP) |
2012 | if (mflags & P_OUT_OF_MAP) |
1960 | continue; |
2013 | continue; |
1961 | if (mflags & P_NEED_UPDATE) |
2014 | if (mflags & P_NEED_UPDATE) |
1962 | update_position(m, ax, ay); |
2015 | update_position(m, ax, ay); |
1963 | /* If a map is visible to the player, we don't want to swap it out |
2016 | /* If a map is visible to the player, we don't want to swap it out |
1964 | * just to reload it. This should really call something like |
2017 | * just to reload it. This should really call something like |
1965 | * swap_map, but this is much more efficient and 'good enough' |
2018 | * swap_map, but this is much more efficient and 'good enough' |
1966 | */ |
2019 | */ |
1967 | if (mflags & P_NEW_MAP) |
2020 | if (mflags & P_NEW_MAP) |
1968 | m->timeout = 50; |
2021 | m->timeout = 50; |
1969 | } |
2022 | } |
1970 | } |
2023 | } |
1971 | /* do LOS after calls to update_position */ |
2024 | /* do LOS after calls to update_position */ |
1972 | if(pl->contr->do_los) { |
2025 | if(pl->contr->do_los) { |
1973 | update_los(pl); |
2026 | update_los(pl); |
1974 | pl->contr->do_los = 0; |
2027 | pl->contr->do_los = 0; |
… | |
… | |
1979 | draw_client_map1(pl); |
2032 | draw_client_map1(pl); |
1980 | return; |
2033 | return; |
1981 | } |
2034 | } |
1982 | |
2035 | |
1983 | if(pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
2036 | if(pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
1984 | esrv_map_setbelow(&pl->contr->socket,pl->contr->socket.mapx/2, |
2037 | esrv_map_setbelow(&pl->contr->socket,pl->contr->socket.mapx/2, |
1985 | pl->contr->socket.mapy/2,pl->face->number,&newmap); |
2038 | pl->contr->socket.mapy/2,pl->face->number,&newmap); |
1986 | } |
2039 | } |
1987 | |
2040 | |
1988 | /* j and i are the y and x coordinates of the real map (which is |
2041 | /* j and i are the y and x coordinates of the real map (which is |
1989 | * basically some number of spaces around the player) |
2042 | * basically some number of spaces around the player) |
1990 | * ax and ay are values from within the viewport (ie, 0, 0 is upper |
2043 | * ax and ay are values from within the viewport (ie, 0, 0 is upper |
… | |
… | |
1995 | * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is |
2048 | * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is |
1996 | * odd, this still works fine. |
2049 | * odd, this still works fine. |
1997 | */ |
2050 | */ |
1998 | ay=0; |
2051 | ay=0; |
1999 | for(j=pl->y-pl->contr->socket.mapy/2; j<=pl->y+(pl->contr->socket.mapy-1)/2;j++, ay++) { |
2052 | for(j=pl->y-pl->contr->socket.mapy/2; j<=pl->y+(pl->contr->socket.mapy-1)/2;j++, ay++) { |
2000 | ax=0; |
2053 | ax=0; |
2001 | for(i=pl->x-pl->contr->socket.mapx/2;i<=pl->x+(pl->contr->socket.mapx-1)/2;i++, ax++) { |
2054 | for(i=pl->x-pl->contr->socket.mapx/2;i<=pl->x+(pl->contr->socket.mapx-1)/2;i++, ax++) { |
2002 | |
2055 | |
2003 | d = pl->contr->blocked_los[ax][ay]; |
2056 | d = pl->contr->blocked_los[ax][ay]; |
2004 | /* note the out_of_map and d>3 checks are both within the same |
2057 | /* note the out_of_map and d>3 checks are both within the same |
2005 | * negation check. |
2058 | * negation check. |
2006 | */ |
2059 | */ |
2007 | nx = i; |
2060 | nx = i; |
2008 | ny = j; |
2061 | ny = j; |
2009 | m = get_map_from_coord(pm, &nx, &ny); |
2062 | m = get_map_from_coord(pm, &nx, &ny); |
2010 | if (m && d<4) { |
2063 | if (m && d<4) { |
2011 | face = GET_MAP_FACE(m, nx, ny,0); |
2064 | face = GET_MAP_FACE(m, nx, ny,0); |
2012 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
2065 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
2013 | floor = GET_MAP_FACE(m, nx, ny,2); |
2066 | floor = GET_MAP_FACE(m, nx, ny,2); |
2014 | |
2067 | |
2015 | /* If all is blank, send a blank face. */ |
2068 | /* If all is blank, send a blank face. */ |
2016 | if ((!face || face == blank_face) && |
2069 | if ((!face || face == blank_face) && |
2017 | (!floor2 || floor2 == blank_face) && |
2070 | (!floor2 || floor2 == blank_face) && |
2018 | (!floor || floor == blank_face)) { |
2071 | (!floor || floor == blank_face)) { |
2019 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2072 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2020 | blank_face->number,&newmap); |
2073 | blank_face->number,&newmap); |
2021 | } else { /* actually have something interesting */ |
2074 | } else { /* actually have something interesting */ |
2022 | /* send the darkness mask, if any. */ |
2075 | /* send the darkness mask, if any. */ |
2023 | if (d && pl->contr->socket.darkness) |
2076 | if (d && pl->contr->socket.darkness) |
2024 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2077 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2025 | dark_faces[d-1]->number,&newmap); |
2078 | dark_faces[d-1]->number,&newmap); |
2026 | |
2079 | |
2027 | if (face && face != blank_face) |
2080 | if (face && face != blank_face) |
2028 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2081 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2029 | face->number,&newmap); |
2082 | face->number,&newmap); |
2030 | if (floor2 && floor2 != blank_face) |
2083 | if (floor2 && floor2 != blank_face) |
2031 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2084 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2032 | floor2->number,&newmap); |
2085 | floor2->number,&newmap); |
2033 | if (floor && floor != blank_face) |
2086 | if (floor && floor != blank_face) |
2034 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2087 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2035 | floor->number,&newmap); |
2088 | floor->number,&newmap); |
2036 | } |
2089 | } |
2037 | } /* Is a valid space */ |
2090 | } /* Is a valid space */ |
2038 | } |
2091 | } |
2039 | } |
2092 | } |
2040 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
2093 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
2041 | |
2094 | |
2042 | check_map_change (pl->contr); |
2095 | check_map_change (pl->contr); |
2043 | } |
2096 | } |
… | |
… | |
2063 | int i; |
2116 | int i; |
2064 | |
2117 | |
2065 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2118 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2066 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
2119 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
2067 | for (i=1; i< NUM_SKILLS; i++) { |
2120 | for (i=1; i< NUM_SKILLS; i++) { |
2068 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2121 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2069 | skill_names[i]); |
2122 | skill_names[i]); |
2070 | } |
2123 | } |
2071 | sl.len = strlen((char*)sl.buf); |
2124 | sl.len = strlen((char*)sl.buf); |
2072 | if (sl.len >= MAXSOCKBUF) { |
2125 | if (sl.len >= MAXSOCKBUF) { |
2073 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2126 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2074 | fatal(0); |
2127 | fatal(0); |
2075 | } |
2128 | } |
2076 | Send_With_Handling(ns, &sl); |
2129 | Send_With_Handling(ns, &sl); |
2077 | free(sl.buf); |
2130 | free(sl.buf); |
2078 | } |
2131 | } |
2079 | |
2132 | |
… | |
… | |
2086 | int i; |
2139 | int i; |
2087 | |
2140 | |
2088 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2141 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2089 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2142 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2090 | for(i=0; i<NRSPELLPATHS; i++) |
2143 | for(i=0; i<NRSPELLPATHS; i++) |
2091 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2144 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2092 | sl.len = strlen((char*)sl.buf); |
2145 | sl.len = strlen((char*)sl.buf); |
2093 | if (sl.len >= MAXSOCKBUF) { |
2146 | if (sl.len >= MAXSOCKBUF) { |
2094 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2147 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2095 | fatal(0); |
2148 | fatal(0); |
2096 | } |
2149 | } |
2097 | Send_With_Handling(ns, &sl); |
2150 | Send_With_Handling(ns, &sl); |
2098 | free(sl.buf); |
2151 | free(sl.buf); |
2099 | } |
2152 | } |
2100 | |
2153 | |
… | |
… | |
2106 | SockList sl; |
2159 | SockList sl; |
2107 | int flags=0; |
2160 | int flags=0; |
2108 | object *spell; |
2161 | object *spell; |
2109 | if (!pl->socket.monitor_spells) return; |
2162 | if (!pl->socket.monitor_spells) return; |
2110 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2163 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2111 | if (spell->type == SPELL) { |
2164 | if (spell->type == SPELL) { |
2112 | /* check if we need to update it*/ |
2165 | /* check if we need to update it*/ |
2113 | if (spell->last_sp != SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA)) { |
2166 | if (spell->last_sp != SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA)) { |
2114 | spell->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
2167 | spell->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
2115 | flags |= UPD_SP_MANA; |
2168 | flags |= UPD_SP_MANA; |
2116 | } |
2169 | } |
2117 | if (spell->last_grace != SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE)) { |
2170 | if (spell->last_grace != SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE)) { |
2118 | spell->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
2171 | spell->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
2119 | flags |= UPD_SP_GRACE; |
2172 | flags |= UPD_SP_GRACE; |
2120 | } |
2173 | } |
2121 | if (spell->last_eat != spell->stats.dam+SP_level_dam_adjust(pl->ob, spell)) { |
2174 | if (spell->last_eat != spell->stats.dam+SP_level_dam_adjust(pl->ob, spell)) { |
2122 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
2175 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
2123 | flags |= UPD_SP_DAMAGE; |
2176 | flags |= UPD_SP_DAMAGE; |
2124 | } |
2177 | } |
2125 | if (flags !=0) { |
2178 | if (flags !=0) { |
2126 | sl.buf =(unsigned char*) malloc(MAXSOCKBUF); |
2179 | sl.buf =(unsigned char*) malloc(MAXSOCKBUF); |
2127 | strcpy((char*)sl.buf,"updspell "); |
2180 | strcpy((char*)sl.buf,"updspell "); |
2128 | sl.len=strlen((char*)sl.buf); |
2181 | sl.len=strlen((char*)sl.buf); |
2129 | SockList_AddChar(&sl, flags); |
2182 | SockList_AddChar(&sl, flags); |
2130 | SockList_AddInt(&sl, spell->count); |
2183 | SockList_AddInt(&sl, spell->count); |
2131 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
2184 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
2132 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
2185 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
2133 | if (flags & UPD_SP_DAMAGE) SockList_AddShort(&sl, spell->last_eat); |
2186 | if (flags & UPD_SP_DAMAGE) SockList_AddShort(&sl, spell->last_eat); |
2134 | flags = 0; |
2187 | flags = 0; |
2135 | Send_With_Handling(&pl->socket, &sl); |
2188 | Send_With_Handling(&pl->socket, &sl); |
2136 | free(sl.buf); |
2189 | free(sl.buf); |
2137 | } |
2190 | } |
2138 | } |
2191 | } |
2139 | } |
2192 | } |
2140 | } |
2193 | } |
2141 | |
2194 | |
2142 | void esrv_remove_spell(player *pl, object *spell) { |
2195 | void esrv_remove_spell(player *pl, object *spell) { |
2143 | SockList sl; |
2196 | SockList sl; |
2144 | |
2197 | |
2145 | if (!pl->socket.monitor_spells) return; |
2198 | if (!pl->socket.monitor_spells) return; |
2146 | if (!pl || !spell || spell->env != pl->ob) { |
2199 | if (!pl || !spell || spell->env != pl->ob) { |
2147 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2200 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2148 | return; |
2201 | return; |
2149 | } |
2202 | } |
2150 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2203 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2151 | strcpy((char*)sl.buf,"delspell "); |
2204 | strcpy((char*)sl.buf,"delspell "); |
2152 | sl.len=strlen((char*)sl.buf); |
2205 | sl.len=strlen((char*)sl.buf); |
2153 | SockList_AddInt(&sl, spell->count); |
2206 | SockList_AddInt(&sl, spell->count); |
… | |
… | |
2175 | SockList_AddShort(sl, spell->last_grace); |
2228 | SockList_AddShort(sl, spell->last_grace); |
2176 | SockList_AddShort(sl, spell->last_eat); |
2229 | SockList_AddShort(sl, spell->last_eat); |
2177 | |
2230 | |
2178 | /* figure out which skill it uses, if it uses one */ |
2231 | /* figure out which skill it uses, if it uses one */ |
2179 | if (spell->skill) { |
2232 | if (spell->skill) { |
2180 | for (i=1; i< NUM_SKILLS; i++) |
2233 | for (i=1; i< NUM_SKILLS; i++) |
2181 | if (!strcmp(spell->skill, skill_names[i])) { |
2234 | if (!strcmp(spell->skill, skill_names[i])) { |
2182 | skill = i+CS_STAT_SKILLINFO; |
2235 | skill = i+CS_STAT_SKILLINFO; |
2183 | break; |
2236 | break; |
2184 | } |
2237 | } |
2185 | } |
2238 | } |
2186 | SockList_AddChar(sl, skill); |
2239 | SockList_AddChar(sl, skill); |
2187 | |
2240 | |
2188 | SockList_AddInt(sl, spell->path_attuned); |
2241 | SockList_AddInt(sl, spell->path_attuned); |
2189 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
2242 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
… | |
… | |
2192 | SockList_AddChar(sl, (char)len); |
2245 | SockList_AddChar(sl, (char)len); |
2193 | memcpy(sl->buf+sl->len, spell->name, len); |
2246 | memcpy(sl->buf+sl->len, spell->name, len); |
2194 | sl->len+=len; |
2247 | sl->len+=len; |
2195 | |
2248 | |
2196 | if (!spell->msg) { |
2249 | if (!spell->msg) { |
2197 | SockList_AddShort(sl, 0); |
2250 | SockList_AddShort(sl, 0); |
2198 | } |
2251 | } |
2199 | else { |
2252 | else { |
2200 | len = strlen(spell->msg); |
2253 | len = strlen(spell->msg); |
2201 | SockList_AddShort(sl, len); |
2254 | SockList_AddShort(sl, len); |
2202 | memcpy(sl->buf+sl->len, spell->msg, len); |
2255 | memcpy(sl->buf+sl->len, spell->msg, len); |
2203 | sl->len+=len; |
2256 | sl->len+=len; |
2204 | } |
2257 | } |
2205 | } |
2258 | } |
2206 | |
2259 | |
2207 | /** |
2260 | /** |
2208 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2261 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2209 | * all spells in the player's inventory. |
2262 | * all spells in the player's inventory. |
2210 | */ |
2263 | */ |
2211 | void esrv_add_spells(player *pl, object *spell) { |
2264 | void esrv_add_spells(player *pl, object *spell) { |
2212 | SockList sl; |
2265 | SockList sl; |
2213 | if (!pl) { |
2266 | if (!pl) { |
2214 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2267 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2215 | return; |
2268 | return; |
2216 | } |
2269 | } |
2217 | if (!pl->socket.monitor_spells) return; |
2270 | if (!pl->socket.monitor_spells) return; |
2218 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2271 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2219 | strcpy((char*)sl.buf,"addspell "); |
2272 | strcpy((char*)sl.buf,"addspell "); |
2220 | sl.len=strlen((char*)sl.buf); |
2273 | sl.len=strlen((char*)sl.buf); |
2221 | if (!spell) { |
2274 | if (!spell) { |
2222 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2275 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2223 | /* were we to simply keep appending data here, we could exceed |
2276 | /* were we to simply keep appending data here, we could exceed |
2224 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2277 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2225 | * append_spells will always append 19 data bytes, plus 4 length |
2278 | * append_spells will always append 19 data bytes, plus 4 length |
2226 | * bytes and 3 strings (because that is the spec) so we need to |
2279 | * bytes and 3 strings (because that is the spec) so we need to |
2227 | * check that the length of those 3 strings, plus the 23 bytes, |
2280 | * check that the length of those 3 strings, plus the 23 bytes, |
2228 | * won't take us over the length limit for the socket, if it does, |
2281 | * won't take us over the length limit for the socket, if it does, |
2229 | * we need to send what we already have, and restart packet formation |
2282 | * we need to send what we already have, and restart packet formation |
2230 | */ |
2283 | */ |
2231 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2284 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2232 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2285 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2233 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2286 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2234 | * like it will fix this |
2287 | * like it will fix this |
2235 | */ |
2288 | */ |
2236 | if (spell->type != SPELL) continue; |
2289 | if (spell->type != SPELL) continue; |
2237 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2290 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2238 | (spell->msg?strlen(spell->msg):0)))) { |
2291 | (spell->msg?strlen(spell->msg):0)))) { |
2239 | Send_With_Handling(&pl->socket, &sl); |
2292 | Send_With_Handling(&pl->socket, &sl); |
2240 | strcpy((char*)sl.buf,"addspell "); |
2293 | strcpy((char*)sl.buf,"addspell "); |
2241 | sl.len=strlen((char*)sl.buf); |
2294 | sl.len=strlen((char*)sl.buf); |
2242 | } |
2295 | } |
2243 | append_spell(pl, &sl, spell); |
2296 | append_spell(pl, &sl, spell); |
2244 | } |
2297 | } |
2245 | } |
2298 | } |
2246 | else if (spell->type != SPELL) { |
2299 | else if (spell->type != SPELL) { |
2247 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2300 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2248 | return; |
2301 | return; |
2249 | } |
2302 | } |
2250 | else append_spell(pl, &sl, spell); |
2303 | else append_spell(pl, &sl, spell); |
2251 | if (sl.len >= MAXSOCKBUF) { |
2304 | if (sl.len >= MAXSOCKBUF) { |
2252 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2305 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2253 | fatal(0); |
2306 | fatal(0); |
2254 | } |
2307 | } |
2255 | /* finally, we can send the packet */ |
2308 | /* finally, we can send the packet */ |
2256 | Send_With_Handling(&pl->socket, &sl); |
2309 | Send_With_Handling(&pl->socket, &sl); |
2257 | free(sl.buf); |
2310 | free(sl.buf); |
2258 | } |
2311 | } |