1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * static char *rcsid_init_c = |
3 | * "$Id: request.C,v 1.11 2006/08/29 07:34:01 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 |
… | |
… | |
329 | |
329 | |
330 | LOG(llevInfo,"Get SetupCmd:: %s\n", buf); |
330 | LOG(llevInfo,"Get SetupCmd:: %s\n", buf); |
331 | strcpy(cmdback,"setup"); |
331 | strcpy(cmdback,"setup"); |
332 | for(s=0;s<len; ) { |
332 | for(s=0;s<len; ) { |
333 | |
333 | |
334 | cmd = &buf[s]; |
334 | cmd = &buf[s]; |
335 | |
335 | |
336 | /* find the next space, and put a null there */ |
336 | /* find the next space, and put a null there */ |
337 | for(;buf[s] && buf[s] != ' ';s++) ; |
337 | for(;buf[s] && buf[s] != ' ';s++) ; |
338 | buf[s++]=0; |
338 | buf[s++]=0; |
339 | while (buf[s] == ' ') s++; |
339 | while (buf[s] == ' ') s++; |
340 | |
340 | |
341 | if(s>=len) |
341 | if(s>=len) |
342 | break; |
342 | break; |
343 | |
343 | |
344 | param = &buf[s]; |
344 | param = &buf[s]; |
345 | |
345 | |
346 | for(;buf[s] && buf[s] != ' ';s++) ; |
346 | for(;buf[s] && buf[s] != ' ';s++) ; |
347 | buf[s++]=0; |
347 | buf[s++]=0; |
348 | while (buf[s] == ' ') s++; |
348 | while (buf[s] == ' ') s++; |
349 | |
349 | |
350 | slen = strlen(cmdback); |
350 | slen = strlen(cmdback); |
351 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
351 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
352 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
352 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
353 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
353 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
354 | |
354 | |
355 | if (!strcmp(cmd,"sound")) { |
355 | if (!strcmp(cmd,"sound")) { |
356 | ns->sound = atoi(param); |
356 | ns->sound = atoi(param); |
357 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
357 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
358 | } |
358 | } |
359 | else if (!strcmp(cmd,"exp64")) { |
359 | else if (!strcmp(cmd,"exp64")) { |
360 | ns->exp64 = atoi(param); |
360 | ns->exp64 = atoi(param); |
361 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
361 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
362 | } else if (!strcmp(cmd, "spellmon")) { |
362 | } else if (!strcmp(cmd, "spellmon")) { |
363 | ns->monitor_spells = atoi(param); |
363 | ns->monitor_spells = atoi(param); |
364 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
364 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
365 | } else if (!strcmp(cmd,"darkness")) { |
365 | } else if (!strcmp(cmd,"darkness")) { |
366 | ns->darkness = atoi(param); |
366 | ns->darkness = atoi(param); |
367 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
367 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
368 | } else if (!strcmp(cmd,"map1cmd")) { |
368 | } else if (!strcmp(cmd,"map1cmd")) { |
369 | if (atoi(param)) ns->mapmode = Map1Cmd; |
369 | if (atoi(param)) ns->mapmode = Map1Cmd; |
370 | /* if beyond this size, need to use map1cmd no matter what */ |
370 | /* if beyond this size, need to use map1cmd no matter what */ |
371 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
371 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
372 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
372 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
373 | } else if (!strcmp(cmd,"map1acmd")) { |
373 | } else if (!strcmp(cmd,"map1acmd")) { |
374 | if (atoi(param)) ns->mapmode = Map1aCmd; |
374 | if (atoi(param)) ns->mapmode = Map1aCmd; |
375 | /* if beyond this size, need to use map1acmd no matter what */ |
375 | /* if beyond this size, need to use map1acmd no matter what */ |
376 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
376 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
377 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
377 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
378 | } else if (!strcmp(cmd,"newmapcmd")) { |
378 | } else if (!strcmp(cmd,"newmapcmd")) { |
379 | ns->newmapcmd= atoi(param); |
379 | ns->newmapcmd= atoi(param); |
380 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
380 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
381 | // } else if (!strcmp(cmd,"plugincmd")) { |
381 | // } else if (!strcmp(cmd,"plugincmd")) { |
382 | // ns->plugincmd = atoi(param); |
382 | // ns->plugincmd = atoi(param); |
383 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
383 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
384 | } else if (!strcmp(cmd,"mapinfocmd")) { |
384 | } else if (!strcmp(cmd,"mapinfocmd")) { |
385 | ns->mapinfocmd = atoi(param); |
385 | ns->mapinfocmd = atoi(param); |
386 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
386 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
387 | } else if (!strcmp(cmd,"extcmd")) { |
387 | } else if (!strcmp(cmd,"extcmd")) { |
388 | ns->extcmd = atoi(param); |
388 | ns->extcmd = atoi(param); |
389 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
389 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
390 | } else if (!strcmp(cmd,"extmap")) { |
390 | } else if (!strcmp(cmd,"extmap")) { |
391 | ns->extmap = atoi(param); |
391 | ns->extmap = atoi(param); |
392 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
392 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
393 | } else if (!strcmp(cmd,"facecache")) { |
393 | } else if (!strcmp(cmd,"facecache")) { |
394 | ns->facecache = atoi(param); |
394 | ns->facecache = atoi(param); |
395 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
395 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
396 | } else if (!strcmp(cmd,"faceset")) { |
396 | } else if (!strcmp(cmd,"faceset")) { |
397 | char tmpbuf[20]; |
397 | char tmpbuf[20]; |
398 | int q = atoi(param); |
398 | int q = atoi(param); |
399 | |
399 | |
400 | if (is_valid_faceset(q)) |
400 | if (is_valid_faceset(q)) |
401 | ns->faceset=q; |
401 | ns->faceset=q; |
402 | sprintf(tmpbuf,"%d", ns->faceset); |
402 | sprintf(tmpbuf,"%d", ns->faceset); |
403 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
403 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
404 | /* if the client is using faceset, it knows about image2 command */ |
404 | /* if the client is using faceset, it knows about image2 command */ |
405 | ns->image2=1; |
405 | ns->image2=1; |
406 | } else if (!strcmp(cmd,"itemcmd")) { |
406 | } else if (!strcmp(cmd,"itemcmd")) { |
407 | /* Version of the item protocol command to use. Currently, |
407 | /* Version of the item protocol command to use. Currently, |
408 | * only supported versions are 1 and 2. Using a numeric |
408 | * only supported versions are 1 and 2. Using a numeric |
409 | * 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. |
410 | */ |
410 | */ |
411 | char tmpbuf[20]; |
411 | char tmpbuf[20]; |
412 | int q = atoi(param); |
412 | int q = atoi(param); |
413 | if (q<1 || q>2) { |
413 | if (q<1 || q>2) { |
414 | strcpy(tmpbuf,"FALSE"); |
414 | strcpy(tmpbuf,"FALSE"); |
415 | } else { |
415 | } else { |
416 | ns->itemcmd = q; |
416 | ns->itemcmd = q; |
417 | sprintf(tmpbuf,"%d", ns->itemcmd); |
417 | sprintf(tmpbuf,"%d", ns->itemcmd); |
418 | } |
418 | } |
419 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
419 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
420 | } else if (!strcmp(cmd,"mapsize")) { |
420 | } else if (!strcmp(cmd,"mapsize")) { |
421 | int x, y=0; |
421 | int x, y=0; |
422 | char tmpbuf[MAX_BUF], *cp; |
422 | char tmpbuf[MAX_BUF], *cp; |
423 | |
423 | |
424 | x = atoi(param); |
424 | x = atoi(param); |
425 | for (cp = param; *cp!=0; cp++) |
425 | for (cp = param; *cp!=0; cp++) |
426 | if (*cp == 'x' || *cp == 'X') { |
426 | if (*cp == 'x' || *cp == 'X') { |
427 | y = atoi(cp+1); |
427 | y = atoi(cp+1); |
428 | break; |
428 | break; |
429 | } |
429 | } |
430 | 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) { |
431 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
431 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
432 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
432 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
433 | } else { |
433 | } else { |
434 | ns->mapx = x; |
434 | ns->mapx = x; |
435 | ns->mapy = y; |
435 | ns->mapy = y; |
436 | /* 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 |
437 | * param as given to us in case it gets parsed differently. |
437 | * param as given to us in case it gets parsed differently. |
438 | */ |
438 | */ |
439 | sprintf(tmpbuf,"%dx%d", x,y); |
439 | sprintf(tmpbuf,"%dx%d", x,y); |
440 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
440 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
441 | /* 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 |
442 | * go to map1cmd. |
442 | * go to map1cmd. |
443 | */ |
443 | */ |
444 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
444 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
445 | } |
445 | } |
446 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
446 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
447 | /* Added by tchize |
447 | /* Added by tchize |
448 | * prepare to use the mapextended command |
448 | * prepare to use the mapextended command |
449 | */ |
449 | */ |
450 | char tmpbuf[20]; |
450 | char tmpbuf[20]; |
451 | ns->ext_mapinfos = (atoi(param)); |
451 | ns->ext_mapinfos = (atoi(param)); |
452 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
452 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
453 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
453 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
454 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
454 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
455 | /* Added by tchize |
455 | /* Added by tchize |
456 | * prepare to use the extended text commands |
456 | * prepare to use the extended text commands |
457 | * Client toggle this to non zero to get exttext |
457 | * Client toggle this to non zero to get exttext |
458 | */ |
458 | */ |
459 | char tmpbuf[20]; |
459 | char tmpbuf[20]; |
460 | |
460 | |
461 | ns->has_readable_type = (atoi(param)); |
461 | ns->has_readable_type = (atoi(param)); |
462 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
462 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
463 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
463 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
464 | } else { |
464 | } else { |
465 | /* Didn't get a setup command we understood - |
465 | /* Didn't get a setup command we understood - |
466 | * report a failure to the client. |
466 | * report a failure to the client. |
467 | */ |
467 | */ |
468 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
468 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
469 | } |
469 | } |
470 | } /* for processing all the setup commands */ |
470 | } /* for processing all the setup commands */ |
471 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
471 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
472 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
472 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
473 | } |
473 | } |
474 | |
474 | |
… | |
… | |
481 | void AddMeCmd(char *buf, int len, NewSocket *ns) |
481 | void AddMeCmd(char *buf, int len, NewSocket *ns) |
482 | { |
482 | { |
483 | Settings oldsettings; |
483 | Settings oldsettings; |
484 | oldsettings=settings; |
484 | oldsettings=settings; |
485 | if (ns->status != Ns_Add || add_player(ns)) { |
485 | if (ns->status != Ns_Add || add_player(ns)) { |
486 | Write_String_To_Socket(ns, "addme_failed",12); |
486 | Write_String_To_Socket(ns, "addme_failed",12); |
487 | } else { |
487 | } else { |
488 | /* Basically, the add_player copies the socket structure into |
488 | /* Basically, the add_player copies the socket structure into |
489 | * the player structure, so this one (which is from init_sockets) |
489 | * the player structure, so this one (which is from init_sockets) |
490 | * 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 |
491 | * stuff in ns is still relevant. |
491 | * stuff in ns is still relevant. |
492 | */ |
492 | */ |
493 | Write_String_To_Socket(ns, "addme_success",13); |
493 | Write_String_To_Socket(ns, "addme_success",13); |
494 | socket_info.nconns--; |
494 | socket_info.nconns--; |
495 | ns->status = Ns_Avail; |
495 | ns->status = Ns_Avail; |
496 | } |
496 | } |
497 | settings=oldsettings; |
497 | settings=oldsettings; |
498 | } |
498 | } |
499 | |
499 | |
500 | /** Reply to ExtendedInfos command */ |
500 | /** Reply to ExtendedInfos command */ |
… | |
… | |
595 | */ |
595 | */ |
596 | if ((!FindSmooth (face, &smoothface)) && |
596 | if ((!FindSmooth (face, &smoothface)) && |
597 | (!FindSmooth ( smooth_face->number, &smoothface))) { |
597 | (!FindSmooth ( smooth_face->number, &smoothface))) { |
598 | |
598 | |
599 | 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); |
600 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
600 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
601 | return; |
601 | return; |
602 | } |
602 | } |
603 | |
603 | |
604 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
604 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
605 | esrv_send_face(ns, smoothface, 0); |
605 | esrv_send_face(ns, smoothface, 0); |
606 | |
606 | |
607 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
607 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
608 | |
608 | |
609 | sl.buf=reply; |
609 | sl.buf=reply; |
610 | strcpy((char*)sl.buf,"smooth "); |
610 | strcpy((char*)sl.buf,"smooth "); |
… | |
… | |
640 | * 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 |
641 | * 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 |
642 | * an idea of the problem, but they deserve what they get |
642 | * an idea of the problem, but they deserve what they get |
643 | */ |
643 | */ |
644 | if (pl->state!=ST_PLAYING) { |
644 | if (pl->state!=ST_PLAYING) { |
645 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
645 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
646 | "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); |
647 | return; |
647 | return; |
648 | } |
648 | } |
649 | /* 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 |
650 | * sent, so check for that also. |
650 | * sent, so check for that also. |
651 | */ |
651 | */ |
652 | if (atoi(buf) || buf[0]=='0') { |
652 | if (atoi(buf) || buf[0]=='0') { |
653 | pl->count=atoi((char*)buf); |
653 | pl->count=atoi((char*)buf); |
654 | buf=strchr(buf,' '); /* advance beyond the numbers */ |
654 | buf=strchr(buf,' '); /* advance beyond the numbers */ |
655 | if (!buf) { |
655 | if (!buf) { |
656 | #ifdef ESRV_DEBUG |
656 | #ifdef ESRV_DEBUG |
657 | LOG(llevDebug,"PlayerCmd: Got count but no command.\n"); |
657 | LOG(llevDebug,"PlayerCmd: Got count but no command.\n"); |
658 | #endif |
658 | #endif |
659 | return; |
659 | return; |
660 | } |
660 | } |
661 | buf++; |
661 | buf++; |
662 | } |
662 | } |
663 | /* This should not happen anymore. */ |
663 | /* This should not happen anymore. */ |
664 | if (pl->ob->speed_left<-1.0) { |
664 | if (pl->ob->speed_left<-1.0) { |
665 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
665 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
666 | } |
666 | } |
667 | /* In c_new.c */ |
667 | /* In c_new.c */ |
668 | execute_newserver_command(pl->ob, (char*)buf); |
668 | execute_newserver_command(pl->ob, (char*)buf); |
669 | /* Perhaps something better should be done with a left over count. |
669 | /* Perhaps something better should be done with a left over count. |
670 | * Cleaning up the input should probably be done first - all actions |
670 | * Cleaning up the input should probably be done first - all actions |
… | |
… | |
689 | short packet; |
689 | short packet; |
690 | unsigned char command[MAX_BUF]; |
690 | unsigned char command[MAX_BUF]; |
691 | SockList sl; |
691 | SockList sl; |
692 | |
692 | |
693 | if (len < 7) { |
693 | if (len < 7) { |
694 | 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); |
695 | return; |
695 | return; |
696 | } |
696 | } |
697 | |
697 | |
698 | packet = GetShort_String(buf); |
698 | packet = GetShort_String(buf); |
699 | repeat = GetInt_String(buf+2); |
699 | repeat = GetInt_String(buf+2); |
700 | /* -1 is special - no repeat, but don't update */ |
700 | /* -1 is special - no repeat, but don't update */ |
701 | if (repeat!=-1) { |
701 | if (repeat!=-1) { |
702 | pl->count=repeat; |
702 | pl->count=repeat; |
703 | } |
703 | } |
704 | if ((len-4) >= MAX_BUF) len=MAX_BUF-5; |
704 | if ((len-4) >= MAX_BUF) len=MAX_BUF-5; |
705 | |
705 | |
706 | strncpy((char*)command, (char*)buf+6, len-4); |
706 | strncpy((char*)command, (char*)buf+6, len-4); |
707 | command[len-4]='\0'; |
707 | command[len-4]='\0'; |
… | |
… | |
710 | * 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 |
711 | * 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 |
712 | * an idea of the problem, but they deserve what they get |
712 | * an idea of the problem, but they deserve what they get |
713 | */ |
713 | */ |
714 | if (pl->state!=ST_PLAYING) { |
714 | if (pl->state!=ST_PLAYING) { |
715 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
715 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
716 | "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); |
717 | return; |
717 | return; |
718 | } |
718 | } |
719 | |
719 | |
720 | /* This should not happen anymore. */ |
720 | /* This should not happen anymore. */ |
721 | if (pl->ob->speed_left<-1.0) { |
721 | if (pl->ob->speed_left<-1.0) { |
722 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
722 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
723 | } |
723 | } |
724 | /* In c_new.c */ |
724 | /* In c_new.c */ |
725 | execute_newserver_command(pl->ob, (char*)command); |
725 | execute_newserver_command(pl->ob, (char*)command); |
726 | /* Perhaps something better should be done with a left over count. |
726 | /* Perhaps something better should be done with a left over count. |
727 | * Cleaning up the input should probably be done first - all actions |
727 | * Cleaning up the input should probably be done first - all actions |
… | |
… | |
735 | strcpy((char*)sl.buf,"comc "); |
735 | strcpy((char*)sl.buf,"comc "); |
736 | sl.len=5; |
736 | sl.len=5; |
737 | SockList_AddShort(&sl,packet); |
737 | SockList_AddShort(&sl,packet); |
738 | if (FABS(pl->ob->speed) < 0.001) time=MAX_TIME * 100; |
738 | if (FABS(pl->ob->speed) < 0.001) time=MAX_TIME * 100; |
739 | else |
739 | else |
740 | time = ( int )( MAX_TIME/ FABS(pl->ob->speed) ); |
740 | time = ( int )( MAX_TIME/ FABS(pl->ob->speed) ); |
741 | SockList_AddInt(&sl,time); |
741 | SockList_AddInt(&sl,time); |
742 | Send_With_Handling(&pl->socket, &sl); |
742 | Send_With_Handling(&pl->socket, &sl); |
743 | } |
743 | } |
744 | |
744 | |
745 | |
745 | |
… | |
… | |
757 | snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
757 | snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
758 | |
758 | |
759 | /* this avoids any hacking here */ |
759 | /* this avoids any hacking here */ |
760 | |
760 | |
761 | switch (pl->state) { |
761 | switch (pl->state) { |
762 | case ST_PLAYING: |
762 | case ST_PLAYING: |
763 | LOG(llevError,"Got reply message with ST_PLAYING input state\n"); |
763 | LOG(llevError,"Got reply message with ST_PLAYING input state\n"); |
764 | break; |
764 | break; |
765 | |
765 | |
766 | case ST_PLAY_AGAIN: |
766 | case ST_PLAY_AGAIN: |
767 | /* We can check this for return value (2==quit). Maybe we |
767 | /* We can check this for return value (2==quit). Maybe we |
768 | * should, and do something appropriate? |
768 | * should, and do something appropriate? |
769 | */ |
769 | */ |
770 | receive_play_again(pl->ob, buf[0]); |
770 | receive_play_again(pl->ob, buf[0]); |
771 | break; |
771 | break; |
772 | |
772 | |
773 | case ST_ROLL_STAT: |
773 | case ST_ROLL_STAT: |
774 | key_roll_stat(pl->ob,buf[0]); |
774 | key_roll_stat(pl->ob,buf[0]); |
775 | break; |
775 | break; |
776 | |
776 | |
777 | case ST_CHANGE_CLASS: |
777 | case ST_CHANGE_CLASS: |
778 | |
778 | |
779 | key_change_class(pl->ob, buf[0]); |
779 | key_change_class(pl->ob, buf[0]); |
780 | break; |
780 | break; |
781 | |
781 | |
782 | case ST_CONFIRM_QUIT: |
782 | case ST_CONFIRM_QUIT: |
783 | key_confirm_quit(pl->ob, buf[0]); |
783 | key_confirm_quit(pl->ob, buf[0]); |
784 | break; |
784 | break; |
785 | |
785 | |
786 | case ST_CONFIGURE: |
786 | case ST_CONFIGURE: |
787 | LOG(llevError,"In client input handling, but into configure state\n"); |
787 | LOG(llevError,"In client input handling, but into configure state\n"); |
788 | pl->state = ST_PLAYING; |
788 | pl->state = ST_PLAYING; |
789 | break; |
789 | break; |
790 | |
790 | |
791 | case ST_GET_NAME: |
791 | case ST_GET_NAME: |
792 | receive_player_name(pl->ob,13); |
792 | receive_player_name(pl->ob,13); |
793 | break; |
793 | break; |
794 | |
794 | |
795 | case ST_GET_PASSWORD: |
795 | case ST_GET_PASSWORD: |
796 | case ST_CONFIRM_PASSWORD: |
796 | case ST_CONFIRM_PASSWORD: |
797 | receive_player_password(pl->ob,13); |
797 | receive_player_password(pl->ob,13); |
798 | break; |
798 | break; |
799 | |
799 | |
800 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
800 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
801 | receive_party_password(pl->ob,13); |
801 | receive_party_password(pl->ob,13); |
802 | break; |
802 | break; |
803 | |
803 | |
804 | default: |
804 | default: |
805 | LOG(llevError,"Unknown input state: %d\n", pl->state); |
805 | LOG(llevError,"Unknown input state: %d\n", pl->state); |
806 | } |
806 | } |
807 | } |
807 | } |
808 | |
808 | |
809 | /** |
809 | /** |
810 | * 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 |
… | |
… | |
815 | */ |
815 | */ |
816 | void VersionCmd(char *buf, int len,NewSocket *ns) |
816 | void VersionCmd(char *buf, int len,NewSocket *ns) |
817 | { |
817 | { |
818 | char *cp; |
818 | char *cp; |
819 | char version_warning[256]; |
819 | char version_warning[256]; |
820 | |
820 | |
821 | if (!buf) { |
821 | if (!buf) { |
822 | LOG(llevError, "CS: received corrupted version command\n"); |
822 | LOG(llevError, "CS: received corrupted version command\n"); |
823 | return; |
823 | return; |
824 | } |
824 | } |
825 | |
825 | |
826 | ns->cs_version = atoi(buf); |
826 | ns->cs_version = atoi(buf); |
827 | ns->sc_version = ns->cs_version; |
827 | ns->sc_version = ns->cs_version; |
828 | if (VERSION_CS != ns->cs_version) { |
828 | if (VERSION_CS != ns->cs_version) { |
829 | #ifdef ESRV_DEBUG |
829 | #ifdef ESRV_DEBUG |
830 | 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); |
831 | #endif |
831 | #endif |
832 | } |
832 | } |
833 | cp = strchr(buf+1,' '); |
833 | cp = strchr(buf+1,' '); |
834 | if (!cp) return; |
834 | if (!cp) return; |
835 | ns->sc_version = atoi(cp); |
835 | ns->sc_version = atoi(cp); |
836 | if (VERSION_SC != ns->sc_version) { |
836 | if (VERSION_SC != ns->sc_version) { |
837 | #ifdef ESRV_DEBUG |
837 | #ifdef ESRV_DEBUG |
838 | 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); |
839 | #endif |
839 | #endif |
840 | } |
840 | } |
841 | cp = strchr(cp+1, ' '); |
841 | cp = strchr(cp+1, ' '); |
842 | if (cp) { |
842 | if (cp) { |
843 | 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); |
844 | |
844 | |
845 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
845 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
846 | |
846 | |
847 | /* 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 |
848 | * Add later stuff here for other clients |
848 | * Add later stuff here for other clients |
849 | */ |
849 | */ |
850 | |
850 | |
851 | /* these are old dxclients */ |
851 | /* these are old dxclients */ |
852 | /* Version 1024 added support for singular + plural name values - |
852 | /* Version 1024 added support for singular + plural name values - |
853 | * requiing this minimal value reduces complexity of that code, and it |
853 | * requiing this minimal value reduces complexity of that code, and it |
854 | * has been around for a long time. |
854 | * has been around for a long time. |
855 | */ |
855 | */ |
856 | if(!strcmp(" CF DX CLIENT", cp) || ns->sc_version < 1024 ) |
856 | if(!strcmp(" CF DX CLIENT", cp) || ns->sc_version < 1024 ) |
857 | { |
857 | { |
858 | 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!! ****"); |
859 | Write_String_To_Socket(ns, version_warning, strlen(version_warning)); |
859 | Write_String_To_Socket(ns, version_warning, strlen(version_warning)); |
860 | } |
860 | } |
861 | |
861 | |
862 | } |
862 | } |
863 | } |
863 | } |
864 | |
864 | |
865 | /** sound related functions. */ |
865 | /** sound related functions. */ |
… | |
… | |
899 | * 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 |
900 | * record. Perhaps we should just replace this with a |
900 | * record. Perhaps we should just replace this with a |
901 | * sscanf? |
901 | * sscanf? |
902 | */ |
902 | */ |
903 | for (i=0; i<2; i++) { |
903 | for (i=0; i<2; i++) { |
904 | vals[i]=atoi(buf); |
904 | vals[i]=atoi(buf); |
905 | if (!(buf = strchr(buf, ' '))) { |
905 | if (!(buf = strchr(buf, ' '))) { |
906 | LOG(llevError,"Incomplete move command: %s\n", buf); |
906 | LOG(llevError,"Incomplete move command: %s\n", buf); |
907 | return; |
907 | return; |
908 | } |
908 | } |
909 | buf++; |
909 | buf++; |
910 | } |
910 | } |
911 | vals[2]=atoi(buf); |
911 | vals[2]=atoi(buf); |
912 | |
912 | |
913 | /* 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]);*/ |
914 | esrv_move_object(pl->ob,vals[0], vals[1], vals[2]); |
914 | esrv_move_object(pl->ob,vals[0], vals[1], vals[2]); |
… | |
… | |
933 | sprintf(buf,"query %d %s", flags, text?text:""); |
933 | sprintf(buf,"query %d %s", flags, text?text:""); |
934 | Write_String_To_Socket(ns, buf, strlen(buf)); |
934 | Write_String_To_Socket(ns, buf, strlen(buf)); |
935 | } |
935 | } |
936 | |
936 | |
937 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
937 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
938 | Old = New; \ |
938 | Old = New; \ |
939 | SockList_AddChar(&sl, Type); \ |
939 | SockList_AddChar(&sl, Type); \ |
940 | SockList_AddInt64(&sl, New); \ |
940 | SockList_AddInt64(&sl, New); \ |
941 | } |
941 | } |
942 | |
942 | |
943 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
943 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
944 | Old = New; \ |
944 | Old = New; \ |
945 | SockList_AddChar(&sl, Type); \ |
945 | SockList_AddChar(&sl, Type); \ |
946 | SockList_AddInt(&sl, New); \ |
946 | SockList_AddInt(&sl, New); \ |
947 | } |
947 | } |
948 | |
948 | |
949 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
949 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
950 | Old = New; \ |
950 | Old = New; \ |
951 | SockList_AddChar(&sl, Type); \ |
951 | SockList_AddChar(&sl, Type); \ |
952 | SockList_AddShort(&sl, New); \ |
952 | SockList_AddShort(&sl, New); \ |
953 | } |
953 | } |
954 | |
954 | |
955 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
955 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
956 | Old = New; \ |
956 | Old = New; \ |
957 | SockList_AddChar(&sl, Type); \ |
957 | SockList_AddChar(&sl, Type); \ |
958 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
958 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
959 | } |
959 | } |
960 | |
960 | |
961 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
961 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
962 | if (Old) free(Old);\ |
962 | if (Old) free(Old);\ |
963 | Old = strdup_local(New);\ |
963 | Old = strdup_local(New);\ |
964 | SockList_AddChar(&sl, Type); \ |
964 | SockList_AddChar(&sl, Type); \ |
965 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
965 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
966 | strcpy((char*)sl.buf + sl.len, New); \ |
966 | strcpy((char*)sl.buf + sl.len, New); \ |
967 | sl.len += strlen(New); \ |
967 | sl.len += strlen(New); \ |
968 | } |
968 | } |
969 | |
969 | |
970 | /** |
970 | /** |
971 | * Sends a statistics update. We look at the old values, |
971 | * Sends a statistics update. We look at the old values, |
972 | * 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 |
973 | * 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 |
… | |
… | |
998 | 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); |
999 | 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); |
1000 | 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); |
1001 | } |
1001 | } |
1002 | if(pl->socket.exp64) { |
1002 | if(pl->socket.exp64) { |
1003 | uint8 s; |
1003 | uint8 s; |
1004 | for(s=0;s<NUM_SKILLS;s++) { |
1004 | for(s=0;s<NUM_SKILLS;s++) { |
1005 | if (pl->last_skill_ob[s] && |
1005 | if (pl->last_skill_ob[s] && |
1006 | 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) { |
1007 | |
1007 | |
1008 | /* Always send along the level if exp changes. This is only |
1008 | /* Always send along the level if exp changes. This is only |
1009 | * 1 extra byte, but keeps processing simpler. |
1009 | * 1 extra byte, but keeps processing simpler. |
1010 | */ |
1010 | */ |
1011 | SockList_AddChar(&sl, ( char )( s + CS_STAT_SKILLINFO )); |
1011 | SockList_AddChar(&sl, ( char )( s + CS_STAT_SKILLINFO )); |
1012 | SockList_AddChar(&sl, ( char )pl->last_skill_ob[s]->level); |
1012 | SockList_AddChar(&sl, ( char )pl->last_skill_ob[s]->level); |
1013 | SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
1013 | SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
1014 | 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; |
1015 | } |
1015 | } |
1016 | } |
1016 | } |
1017 | } |
1017 | } |
1018 | if (pl->socket.exp64) { |
1018 | if (pl->socket.exp64) { |
1019 | 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); |
1020 | } else { |
1020 | } else { |
1021 | 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); |
1022 | } |
1022 | } |
1023 | AddIfShort(pl->last_level, ( char )pl->ob->level, CS_STAT_LEVEL); |
1023 | AddIfShort(pl->last_level, ( char )pl->ob->level, CS_STAT_LEVEL); |
1024 | 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); |
1025 | 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); |
1026 | 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); |
… | |
… | |
1032 | if (pl->fire_on) flags |=SF_FIREON; |
1032 | if (pl->fire_on) flags |=SF_FIREON; |
1033 | if (pl->run_on) flags |= SF_RUNON; |
1033 | if (pl->run_on) flags |= SF_RUNON; |
1034 | |
1034 | |
1035 | AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
1035 | AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
1036 | if (pl->socket.sc_version<1025) { |
1036 | if (pl->socket.sc_version<1025) { |
1037 | 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); |
1038 | } else { |
1038 | } else { |
1039 | int i; |
1039 | int i; |
1040 | |
1040 | |
1041 | for (i=0; i<NROFATTACKS; i++) { |
1041 | for (i=0; i<NROFATTACKS; i++) { |
1042 | /* Skip ones we won't send */ |
1042 | /* Skip ones we won't send */ |
1043 | if (atnr_cs_stat[i]==-1) continue; |
1043 | if (atnr_cs_stat[i]==-1) continue; |
1044 | 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]); |
1045 | } |
1045 | } |
1046 | } |
1046 | } |
1047 | if (pl->socket.monitor_spells) { |
1047 | if (pl->socket.monitor_spells) { |
1048 | 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); |
1049 | 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); |
1050 | 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); |
1051 | } |
1051 | } |
1052 | 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 */ |
1053 | AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
1053 | AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
1054 | set_title(pl->ob, buf); |
1054 | set_title(pl->ob, buf); |
1055 | AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
1055 | AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
1056 | |
1056 | |
1057 | /* Only send it away if we have some actual data */ |
1057 | /* Only send it away if we have some actual data */ |
1058 | if (sl.len>6) { |
1058 | if (sl.len>6) { |
1059 | #ifdef ESRV_DEBUG |
1059 | #ifdef ESRV_DEBUG |
1060 | LOG(llevDebug,"Sending stats command, %d bytes long.\n", sl.len); |
1060 | LOG(llevDebug,"Sending stats command, %d bytes long.\n", sl.len); |
1061 | #endif |
1061 | #endif |
1062 | Send_With_Handling(&pl->socket, &sl); |
1062 | Send_With_Handling(&pl->socket, &sl); |
1063 | } |
1063 | } |
1064 | free(sl.buf); |
1064 | free(sl.buf); |
1065 | } |
1065 | } |
1066 | |
1066 | |
1067 | |
1067 | |
… | |
… | |
1107 | /* 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 |
1108 | * 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 |
1109 | * range, it must be a valid animation. |
1109 | * range, it must be a valid animation. |
1110 | */ |
1110 | */ |
1111 | if (anim_num < 0 || anim_num > num_animations) { |
1111 | if (anim_num < 0 || anim_num > num_animations) { |
1112 | 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); |
1113 | return; |
1113 | return; |
1114 | } |
1114 | } |
1115 | |
1115 | |
1116 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
1116 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
1117 | strcpy((char*)sl.buf, "anim "); |
1117 | strcpy((char*)sl.buf, "anim "); |
1118 | sl.len=5; |
1118 | sl.len=5; |
… | |
… | |
1120 | SockList_AddShort(&sl, 0); /* flags - not used right now */ |
1120 | SockList_AddShort(&sl, 0); /* flags - not used right now */ |
1121 | /* 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 |
1122 | * the face itself) down to the client. |
1122 | * the face itself) down to the client. |
1123 | */ |
1123 | */ |
1124 | for (i=0; i<animations[anim_num].num_animations; i++) { |
1124 | for (i=0; i<animations[anim_num].num_animations; i++) { |
1125 | 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)) |
1126 | esrv_send_face(ns,animations[anim_num].faces[i],0); |
1126 | esrv_send_face(ns,animations[anim_num].faces[i],0); |
1127 | 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 */ |
1128 | } |
1128 | } |
1129 | Send_With_Handling(ns, &sl); |
1129 | Send_With_Handling(ns, &sl); |
1130 | free(sl.buf); |
1130 | free(sl.buf); |
1131 | ns->anims_sent[anim_num] = 1; |
1131 | ns->anims_sent[anim_num] = 1; |
1132 | } |
1132 | } |
… | |
… | |
1141 | /** |
1141 | /** |
1142 | * 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 |
1143 | * the face yet, we will also send it. |
1143 | * the face yet, we will also send it. |
1144 | */ |
1144 | */ |
1145 | static void esrv_map_setbelow(NewSocket *ns, int x,int y, |
1145 | static void esrv_map_setbelow(NewSocket *ns, int x,int y, |
1146 | short face_num, struct Map *newmap) |
1146 | short face_num, struct Map *newmap) |
1147 | { |
1147 | { |
1148 | if(newmap->cells[x][y].count >= MAP_LAYERS) { |
1148 | if(newmap->cells[x][y].count >= MAP_LAYERS) { |
1149 | 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); |
1150 | return; |
1150 | return; |
1151 | abort(); |
1151 | abort(); |
1152 | } |
1152 | } |
1153 | 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; |
1154 | newmap->cells[x][y].count ++; |
1154 | newmap->cells[x][y].count ++; |
1155 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1155 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1156 | esrv_send_face(ns,face_num,0); |
1156 | esrv_send_face(ns,face_num,0); |
1157 | } |
1157 | } |
1158 | |
1158 | |
1159 | struct LayerCell { |
1159 | struct LayerCell { |
1160 | uint16 xy; |
1160 | uint16 xy; |
1161 | short face; |
1161 | short face; |
… | |
… | |
1173 | |
1173 | |
1174 | 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) |
1175 | return 1; |
1175 | return 1; |
1176 | for(k=0;k<newmap->cells[i][j].count;k++) { |
1176 | for(k=0;k<newmap->cells[i][j].count;k++) { |
1177 | if (ns->lastmap.cells[i][j].faces[k] != |
1177 | if (ns->lastmap.cells[i][j].faces[k] != |
1178 | newmap->cells[i][j].faces[k]) { |
1178 | newmap->cells[i][j].faces[k]) { |
1179 | return 1; |
1179 | return 1; |
1180 | } |
1180 | } |
1181 | } |
1181 | } |
1182 | return 0; |
1182 | return 0; |
1183 | } |
1183 | } |
… | |
… | |
1187 | * 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 |
1188 | * 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 |
1189 | * how many layers of data we should back. |
1189 | * how many layers of data we should back. |
1190 | */ |
1190 | */ |
1191 | static uint8 *compactlayer(NewSocket *ns, unsigned char *cur, int numlayers, |
1191 | static uint8 *compactlayer(NewSocket *ns, unsigned char *cur, int numlayers, |
1192 | struct Map *newmap) |
1192 | struct Map *newmap) |
1193 | { |
1193 | { |
1194 | int x,y,k; |
1194 | int x,y,k; |
1195 | int face; |
1195 | int face; |
1196 | unsigned char *fcur; |
1196 | unsigned char *fcur; |
1197 | struct MapLayer layers[MAP_LAYERS]; |
1197 | struct MapLayer layers[MAP_LAYERS]; |
1198 | |
1198 | |
1199 | for(k = 0;k<MAP_LAYERS;k++) |
1199 | for(k = 0;k<MAP_LAYERS;k++) |
1200 | layers[k].count = 0; |
1200 | layers[k].count = 0; |
1201 | fcur = cur; |
1201 | fcur = cur; |
1202 | for(x=0;x<ns->mapx;x++) { |
1202 | for(x=0;x<ns->mapx;x++) { |
1203 | for(y=0;y<ns->mapy;y++) { |
1203 | for(y=0;y<ns->mapy;y++) { |
1204 | if (!mapcellchanged(ns,x,y,newmap)) |
1204 | if (!mapcellchanged(ns,x,y,newmap)) |
1205 | continue; |
1205 | continue; |
1206 | if (newmap->cells[x][y].count == 0) { |
1206 | if (newmap->cells[x][y].count == 0) { |
1207 | *cur = x*ns->mapy+y; /* mark empty space */ |
1207 | *cur = x*ns->mapy+y; /* mark empty space */ |
1208 | cur++; |
1208 | cur++; |
1209 | continue; |
1209 | continue; |
1210 | } |
1210 | } |
1211 | for(k=0;k<newmap->cells[x][y].count;k++) { |
1211 | for(k=0;k<newmap->cells[x][y].count;k++) { |
1212 | layers[k].lcells[layers[k].count].xy = x*ns->mapy+y; |
1212 | layers[k].lcells[layers[k].count].xy = x*ns->mapy+y; |
1213 | layers[k].lcells[layers[k].count].face = |
1213 | layers[k].lcells[layers[k].count].face = |
1214 | newmap->cells[x][y].faces[k]; |
1214 | newmap->cells[x][y].faces[k]; |
1215 | layers[k].count++; |
1215 | layers[k].count++; |
1216 | } |
1216 | } |
1217 | } |
1217 | } |
1218 | } |
1218 | } |
1219 | /* If no data, return now. */ |
1219 | /* If no data, return now. */ |
1220 | if (fcur == cur && layers[0].count == 0) |
1220 | if (fcur == cur && layers[0].count == 0) |
1221 | return cur; |
1221 | return cur; |
1222 | *cur = 255; /* mark end of explicitly cleared cells */ |
1222 | *cur = 255; /* mark end of explicitly cleared cells */ |
1223 | cur++; |
1223 | cur++; |
1224 | /* First pack by layers. */ |
1224 | /* First pack by layers. */ |
1225 | for(k=0;k<numlayers;k++) { |
1225 | for(k=0;k<numlayers;k++) { |
1226 | if (layers[k].count == 0) |
1226 | if (layers[k].count == 0) |
1227 | 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 |
1228 | have anything in it either */ |
1228 | have anything in it either */ |
1229 | /* Pack by entries in thie layer */ |
1229 | /* Pack by entries in thie layer */ |
1230 | for(x=0;x<layers[k].count;) { |
1230 | for(x=0;x<layers[k].count;) { |
1231 | fcur = cur; |
1231 | fcur = cur; |
1232 | *cur = layers[k].lcells[x].face >> 8; |
1232 | *cur = layers[k].lcells[x].face >> 8; |
1233 | cur++; |
1233 | cur++; |
1234 | *cur = layers[k].lcells[x].face & 0xFF; |
1234 | *cur = layers[k].lcells[x].face & 0xFF; |
1235 | cur++; |
1235 | cur++; |
1236 | face = layers[k].lcells[x].face; |
1236 | face = layers[k].lcells[x].face; |
1237 | /* Now, we back the redundant data into 1 byte xy pairings */ |
1237 | /* Now, we back the redundant data into 1 byte xy pairings */ |
1238 | for(y=x;y<layers[k].count;y++) { |
1238 | for(y=x;y<layers[k].count;y++) { |
1239 | if (layers[k].lcells[y].face == face) { |
1239 | if (layers[k].lcells[y].face == face) { |
1240 | *cur = ( uint8 )layers[k].lcells[y].xy; |
1240 | *cur = ( uint8 )layers[k].lcells[y].xy; |
1241 | cur++; |
1241 | cur++; |
1242 | layers[k].lcells[y].face = -1; |
1242 | layers[k].lcells[y].face = -1; |
1243 | } |
1243 | } |
1244 | } |
1244 | } |
1245 | *(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 */ |
1246 | /* forward over the now redundant data */ |
1246 | /* forward over the now redundant data */ |
1247 | while(x < layers[k].count && |
1247 | while(x < layers[k].count && |
1248 | layers[k].lcells[x].face == -1) |
1248 | layers[k].lcells[x].face == -1) |
1249 | x++; |
1249 | x++; |
1250 | } |
1250 | } |
1251 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1251 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1252 | } |
1252 | } |
1253 | return cur; |
1253 | return cur; |
1254 | } |
1254 | } |
1255 | |
1255 | |
1256 | static void esrv_map_doneredraw(NewSocket *ns, struct Map *newmap) |
1256 | static void esrv_map_doneredraw(NewSocket *ns, struct Map *newmap) |
… | |
… | |
1268 | sl.len=cur-(char*)sl.buf; |
1268 | sl.len=cur-(char*)sl.buf; |
1269 | |
1269 | |
1270 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1270 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1271 | |
1271 | |
1272 | if (sl.len>( int )strlen("map ") || ns->sent_scroll) { |
1272 | if (sl.len>( int )strlen("map ") || ns->sent_scroll) { |
1273 | /* All of this is just accounting stuff */ |
1273 | /* All of this is just accounting stuff */ |
1274 | if (tframes>100) { |
1274 | if (tframes>100) { |
1275 | tframes = tbytes = 0; |
1275 | tframes = tbytes = 0; |
1276 | } |
1276 | } |
1277 | tframes++; |
1277 | tframes++; |
1278 | frames++; |
1278 | frames++; |
1279 | tbytes += sl.len; |
1279 | tbytes += sl.len; |
1280 | bytes += sl.len; |
1280 | bytes += sl.len; |
1281 | memcpy(&ns->lastmap,newmap,sizeof(struct Map)); |
1281 | memcpy(&ns->lastmap,newmap,sizeof(struct Map)); |
1282 | Send_With_Handling(ns, &sl); |
1282 | Send_With_Handling(ns, &sl); |
1283 | ns->sent_scroll = 0; |
1283 | ns->sent_scroll = 0; |
1284 | } |
1284 | } |
1285 | free(sl.buf); |
1285 | free(sl.buf); |
1286 | } |
1286 | } |
1287 | |
1287 | |
1288 | |
1288 | |
… | |
… | |
1315 | * for empty space checking. |
1315 | * for empty space checking. |
1316 | */ |
1316 | */ |
1317 | static inline int have_head(int ax, int ay) { |
1317 | static inline int have_head(int ax, int ay) { |
1318 | |
1318 | |
1319 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1319 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1320 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || |
1320 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || |
1321 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) return 1; |
1321 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) return 1; |
1322 | return 0; |
1322 | return 0; |
1323 | } |
1323 | } |
1324 | |
1324 | |
1325 | /** |
1325 | /** |
1326 | * check_head is a bit simplistic version of update_space below. |
1326 | * check_head is a bit simplistic version of update_space below. |
… | |
… | |
1332 | static 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) |
1333 | { |
1333 | { |
1334 | short face_num; |
1334 | short face_num; |
1335 | |
1335 | |
1336 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1336 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1337 | 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; |
1338 | else |
1338 | else |
1339 | face_num = 0; |
1339 | face_num = 0; |
1340 | |
1340 | |
1341 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { |
1341 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { |
1342 | SockList_AddShort (&sl, face_num); |
1342 | SockList_AddShort (&sl, face_num); |
1343 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1343 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1344 | esrv_send_face (&ns, face_num, 0); |
1344 | esrv_send_face (&ns, face_num, 0); |
1345 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1345 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1346 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1346 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1347 | return 1; |
1347 | return 1; |
1348 | } |
1348 | } |
1349 | |
1349 | |
1350 | return 0; /* No change */ |
1350 | return 0; /* No change */ |
1351 | } |
1351 | } |
1352 | |
1352 | |
… | |
… | |
1392 | * 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 |
1393 | * otherwise send the image as this layer, eg, either it matches |
1393 | * otherwise send the image as this layer, eg, either it matches |
1394 | * the head value, or is not multipart. |
1394 | * the head value, or is not multipart. |
1395 | */ |
1395 | */ |
1396 | if (head && !head->more) { |
1396 | if (head && !head->more) { |
1397 | for (i=0; i<MAP_LAYERS; i++) { |
1397 | for (i=0; i<MAP_LAYERS; i++) { |
1398 | ob = GET_MAP_FACE_OBJ(mp, mx, my, i); |
1398 | ob = GET_MAP_FACE_OBJ(mp, mx, my, i); |
1399 | if (!ob) continue; |
1399 | if (!ob) continue; |
1400 | |
1400 | |
1401 | if (ob->head) ob=ob->head; |
1401 | if (ob->head) ob=ob->head; |
1402 | |
1402 | |
1403 | if (ob == head) { |
1403 | if (ob == head) { |
1404 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1404 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1405 | head = NULL; |
1405 | head = NULL; |
1406 | break; |
1406 | break; |
1407 | } |
1407 | } |
1408 | } |
1408 | } |
1409 | } |
1409 | } |
1410 | |
1410 | |
1411 | ob = head; |
1411 | ob = head; |
1412 | if (!ob) ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1412 | if (!ob) ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1413 | |
1413 | |
… | |
… | |
1417 | * precedence over the other object for this space. |
1417 | * precedence over the other object for this space. |
1418 | * otherwise, we do special head processing |
1418 | * otherwise, we do special head processing |
1419 | */ |
1419 | */ |
1420 | if (!ob || ob->face == blank_face) face_num=0; |
1420 | if (!ob || ob->face == blank_face) face_num=0; |
1421 | else if (head){ |
1421 | else if (head){ |
1422 | /* if this is a head that had previously been stored */ |
1422 | /* if this is a head that had previously been stored */ |
1423 | face_num = ob->face->number; |
1423 | face_num = ob->face->number; |
1424 | } else { |
1424 | } else { |
1425 | /* if the faces for the different parts of a multipart object |
1425 | /* if the faces for the different parts of a multipart object |
1426 | * 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 |
1427 | * portion of the object. That info is in the tail_.. values |
1427 | * portion of the object. That info is in the tail_.. values |
1428 | * 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 |
1429 | * 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 |
1430 | * a tail piece. |
1430 | * a tail piece. |
1431 | */ |
1431 | */ |
1432 | |
1432 | |
1433 | /* 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 |
1434 | * this is the head object and these are set, we proceed |
1434 | * this is the head object and these are set, we proceed |
1435 | * with logic to only send bottom right. Similarly, if |
1435 | * with logic to only send bottom right. Similarly, if |
1436 | * 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 |
1437 | * 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 |
1438 | * 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 |
1439 | * 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 |
1440 | * object we may want to display. |
1440 | * object we may want to display. |
1441 | */ |
1441 | */ |
1442 | if ((ob->arch->tail_x || ob->arch->tail_y) || |
1442 | if ((ob->arch->tail_x || ob->arch->tail_y) || |
1443 | (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))) { |
1444 | |
1444 | |
1445 | if (ob->head) head = ob->head; |
1445 | if (ob->head) head = ob->head; |
1446 | else head = ob; |
1446 | else head = ob; |
1447 | |
1447 | |
1448 | /* 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 |
1449 | * 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 |
1450 | * 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 |
1451 | * 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 |
1452 | * 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 |
1453 | * will be zero, so the right thing will still happen. |
1453 | * will be zero, so the right thing will still happen. |
1454 | */ |
1454 | */ |
1455 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1455 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1456 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1456 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1457 | |
1457 | |
1458 | /* 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 |
1459 | * in case. |
1459 | * in case. |
1460 | */ |
1460 | */ |
1461 | if (bx < sx || by < sy) { |
1461 | if (bx < sx || by < sy) { |
1462 | 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", |
1463 | bx, by, sx, sy); |
1463 | bx, by, sx, sy); |
1464 | face_num = 0; |
1464 | face_num = 0; |
1465 | } |
1465 | } |
1466 | /* single part object, multipart object with non merged faces, |
1466 | /* single part object, multipart object with non merged faces, |
1467 | * of multipart object already at lower right. |
1467 | * of multipart object already at lower right. |
1468 | */ |
1468 | */ |
1469 | else if (bx == sx && by == sy) { |
1469 | else if (bx == sx && by == sy) { |
1470 | face_num = ob->face->number; |
1470 | face_num = ob->face->number; |
1471 | |
1471 | |
1472 | /* if this face matches one stored away, clear that one away. |
1472 | /* if this face matches one stored away, clear that one away. |
1473 | * this code relies on the fact that the map1 commands |
1473 | * this code relies on the fact that the map1 commands |
1474 | * goes from 2 down to 0. |
1474 | * goes from 2 down to 0. |
1475 | */ |
1475 | */ |
1476 | for (i=0; i<MAP_LAYERS; i++) |
1476 | for (i=0; i<MAP_LAYERS; i++) |
1477 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1477 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1478 | 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) |
1479 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1479 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1480 | } |
1480 | } |
1481 | else { |
1481 | else { |
1482 | /* If this head is stored away, clear it - otherwise, |
1482 | /* If this head is stored away, clear it - otherwise, |
1483 | * there can be cases where a object is on multiple layers - |
1483 | * there can be cases where a object is on multiple layers - |
1484 | * we only want to send it once. |
1484 | * we only want to send it once. |
1485 | */ |
1485 | */ |
1486 | face_num = head->face->number; |
1486 | face_num = head->face->number; |
1487 | for (i=0; i<MAP_LAYERS; i++) |
1487 | for (i=0; i<MAP_LAYERS; i++) |
1488 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1488 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1489 | 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) |
1490 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1490 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1491 | |
1491 | |
1492 | /* 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, |
1493 | * then find another layer. |
1493 | * then find another layer. |
1494 | */ |
1494 | */ |
1495 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) { |
1495 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) { |
1496 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1496 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1497 | } else for (i=0; i<MAX_LAYERS; i++) { |
1497 | } else for (i=0; i<MAX_LAYERS; i++) { |
1498 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1498 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1499 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) { |
1499 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) { |
1500 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1500 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1501 | } |
1501 | } |
1502 | } |
1502 | } |
1503 | 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 */ |
1504 | } |
1504 | } |
1505 | } else { |
1505 | } else { |
1506 | /* 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, |
1507 | * so nothing special |
1507 | * so nothing special |
1508 | */ |
1508 | */ |
1509 | face_num = ob->face->number; |
1509 | face_num = ob->face->number; |
1510 | |
1510 | |
1511 | /* 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 */ |
1512 | for (bx=0; bx<layer; bx++) |
1512 | for (bx=0; bx<layer; bx++) |
1513 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1513 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1514 | 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) |
1515 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1515 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1516 | } |
1516 | } |
1517 | } /* else not already head object or blank face */ |
1517 | } /* else not already head object or blank face */ |
1518 | |
1518 | |
1519 | /* 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, |
1520 | * 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. |
1521 | * 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 |
1522 | * 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 |
1523 | * 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 |
1524 | * This tends to make stacking also work/look better. |
1524 | * This tends to make stacking also work/look better. |
1525 | */ |
1525 | */ |
1526 | 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]) { |
1527 | 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; |
1528 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1] = NULL; |
1528 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1] = NULL; |
1529 | } |
1529 | } |
1530 | |
1530 | |
1531 | /* 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 |
1532 | * 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 |
1533 | * this one. |
1533 | * this one. |
1534 | */ |
1534 | */ |
1535 | 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) { |
1536 | face_num = 0; |
1536 | face_num = 0; |
1537 | } |
1537 | } |
1538 | |
1538 | |
1539 | /* 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 |
1540 | * 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. |
1541 | */ |
1541 | */ |
1542 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) { |
1542 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) { |
1543 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1543 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1544 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1544 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1545 | esrv_send_face(ns, face_num, 0); |
1545 | esrv_send_face(ns, face_num, 0); |
1546 | SockList_AddShort(sl, face_num); |
1546 | SockList_AddShort(sl, face_num); |
1547 | return 1; |
1547 | return 1; |
1548 | } |
1548 | } |
1549 | /* Nothing changed */ |
1549 | /* Nothing changed */ |
1550 | return 0; |
1550 | return 0; |
1551 | } |
1551 | } |
1552 | |
1552 | |
… | |
… | |
1579 | /* 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 |
1580 | * is the blank face, set the smoothlevel to zero. |
1580 | * is the blank face, set the smoothlevel to zero. |
1581 | */ |
1581 | */ |
1582 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH(mp)) smoothlevel=0; |
1582 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH(mp)) smoothlevel=0; |
1583 | else { |
1583 | else { |
1584 | smoothlevel = ob->smoothlevel; |
1584 | smoothlevel = ob->smoothlevel; |
1585 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1585 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1586 | SendSmooth(ns, ob->face->number); |
1586 | SendSmooth(ns, ob->face->number); |
1587 | } /* else not already head object or blank face */ |
1587 | } /* else not already head object or blank face */ |
1588 | |
1588 | |
1589 | /* 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 |
1590 | * 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. |
1591 | */ |
1591 | */ |
1592 | if (smoothlevel>255) |
1592 | if (smoothlevel>255) |
1593 | smoothlevel=255; |
1593 | smoothlevel=255; |
1594 | else if (smoothlevel<0) |
1594 | else if (smoothlevel<0) |
1595 | smoothlevel=0; |
1595 | smoothlevel=0; |
1596 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) { |
1596 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) { |
1597 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1597 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1598 | SockList_AddChar(sl, (uint8) (smoothlevel&0xFF)); |
1598 | SockList_AddChar(sl, (uint8) (smoothlevel&0xFF)); |
1599 | return 1; |
1599 | return 1; |
1600 | } |
1600 | } |
1601 | /* Nothing changed */ |
1601 | /* Nothing changed */ |
1602 | return 0; |
1602 | return 0; |
1603 | } |
1603 | } |
1604 | |
1604 | |
… | |
… | |
1653 | |
1653 | |
1654 | check_map_change (pl->contr); |
1654 | check_map_change (pl->contr); |
1655 | |
1655 | |
1656 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1656 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1657 | if (socket.mapmode == Map1Cmd) |
1657 | if (socket.mapmode == Map1Cmd) |
1658 | strcpy((char*)sl.buf,"map1 "); |
1658 | strcpy((char*)sl.buf,"map1 "); |
1659 | else |
1659 | else |
1660 | strcpy((char*)sl.buf,"map1a "); |
1660 | strcpy((char*)sl.buf,"map1a "); |
1661 | sl.len=strlen((char*)sl.buf); |
1661 | sl.len=strlen((char*)sl.buf); |
1662 | startlen = sl.len; |
1662 | startlen = sl.len; |
1663 | /*Extendedmapinfo structure initialisation*/ |
1663 | /*Extendedmapinfo structure initialisation*/ |
1664 | if (socket.ext_mapinfos){ |
1664 | if (socket.ext_mapinfos){ |
1665 | esl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1665 | esl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
… | |
… | |
1693 | * but that started to get a bit messy to look at. |
1693 | * but that started to get a bit messy to look at. |
1694 | */ |
1694 | */ |
1695 | max_x = pl->x+(socket.mapx+1)/2; |
1695 | max_x = pl->x+(socket.mapx+1)/2; |
1696 | max_y = pl->y+(socket.mapy+1)/2; |
1696 | max_y = pl->y+(socket.mapy+1)/2; |
1697 | if (socket.mapmode == Map1aCmd) { |
1697 | if (socket.mapmode == Map1aCmd) { |
1698 | max_x += MAX_HEAD_OFFSET; |
1698 | max_x += MAX_HEAD_OFFSET; |
1699 | max_y += MAX_HEAD_OFFSET; |
1699 | max_y += MAX_HEAD_OFFSET; |
1700 | } |
1700 | } |
1701 | |
1701 | |
1702 | for(y=pl->y-socket.mapy/2; y<max_y; y++,ay++) { |
1702 | for(y=pl->y-socket.mapy/2; y<max_y; y++,ay++) { |
1703 | ax=0; |
1703 | ax=0; |
1704 | for(x=pl->x-socket.mapx/2;x<max_x;x++,ax++) { |
1704 | for(x=pl->x-socket.mapx/2;x<max_x;x++,ax++) { |
1705 | |
1705 | |
1706 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1706 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1707 | |
1707 | |
1708 | /* 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 |
1709 | * 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 |
1710 | * the client wants if using the map1a command - this is because |
1710 | * the client wants if using the map1a command - this is because |
1711 | * 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 |
1712 | * set to lower values. |
1712 | * set to lower values. |
1713 | */ |
1713 | */ |
1714 | if (ax >= socket.mapx || ay >= socket.mapy) { |
1714 | if (ax >= socket.mapx || ay >= socket.mapy) { |
1715 | int i, got_one; |
1715 | int i, got_one; |
1716 | |
1716 | |
1717 | oldlen = sl.len; |
1717 | oldlen = sl.len; |
1718 | |
1718 | |
1719 | SockList_AddShort(&sl, mask); |
1719 | SockList_AddShort(&sl, mask); |
1720 | |
1720 | |
1721 | if (check_head (sl, socket, ax, ay, 2)) |
1721 | if (check_head (sl, socket, ax, ay, 2)) |
1722 | mask |= 0x4; |
1722 | mask |= 0x4; |
1723 | if (check_head (sl, socket, ax, ay, 1)) |
1723 | if (check_head (sl, socket, ax, ay, 1)) |
1724 | mask |= 0x2; |
1724 | mask |= 0x2; |
1725 | if (check_head (sl, socket, ax, ay, 0)) |
1725 | if (check_head (sl, socket, ax, ay, 0)) |
1726 | mask |= 0x1; |
1726 | mask |= 0x1; |
1727 | |
1727 | |
1728 | /* 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 |
1729 | * actually need to send that - just the coordinates |
1729 | * actually need to send that - just the coordinates |
1730 | * with no faces tells the client to blank out the |
1730 | * with no faces tells the client to blank out the |
1731 | * space. |
1731 | * space. |
1732 | */ |
1732 | */ |
1733 | got_one=0; |
1733 | got_one=0; |
1734 | for (i=oldlen+2; i<sl.len; i++) { |
1734 | for (i=oldlen+2; i<sl.len; i++) { |
1735 | if (sl.buf[i]) got_one=1; |
1735 | if (sl.buf[i]) got_one=1; |
1736 | } |
1736 | } |
1737 | |
1737 | |
1738 | if (got_one && (mask & 0xf)) { |
1738 | if (got_one && (mask & 0xf)) { |
1739 | sl.buf[oldlen+1] = mask & 0xff; |
1739 | sl.buf[oldlen+1] = mask & 0xff; |
1740 | } else { /*either all faces blank, either no face at all*/ |
1740 | } else { /*either all faces blank, either no face at all*/ |
1741 | 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*/ |
1742 | sl.len = oldlen + 2; |
1742 | sl.len = oldlen + 2; |
1743 | else |
1743 | else |
1744 | sl.len = oldlen; |
1744 | sl.len = oldlen; |
1745 | } |
1745 | } |
1746 | /*What concerns extendinfos, nothing to be done for now |
1746 | /*What concerns extendinfos, nothing to be done for now |
1747 | * (perhaps effects layer later) |
1747 | * (perhaps effects layer later) |
1748 | */ |
1748 | */ |
1749 | continue; /* don't do processing below */ |
1749 | continue; /* don't do processing below */ |
1750 | } |
1750 | } |
1751 | |
1751 | |
1752 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1752 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1753 | |
1753 | |
1754 | d = pl->contr->blocked_los[ax][ay]; |
1754 | d = pl->contr->blocked_los[ax][ay]; |
1755 | |
1755 | |
1756 | /* If the coordinates are not valid, or it is too dark to see, |
1756 | /* If the coordinates are not valid, or it is too dark to see, |
1757 | * we tell the client as such |
1757 | * we tell the client as such |
1758 | */ |
1758 | */ |
1759 | nx=x; |
1759 | nx=x; |
1760 | ny=y; |
1760 | ny=y; |
1761 | m = get_map_from_coord(pl->map, &nx, &ny); |
1761 | m = get_map_from_coord(pl->map, &nx, &ny); |
1762 | if (!m) { |
1762 | if (!m) { |
1763 | /* space is out of map. Update space and clear values |
1763 | /* space is out of map. Update space and clear values |
1764 | * if this hasn't already been done. If the space is out |
1764 | * if this hasn't already been done. If the space is out |
1765 | * of the map, it shouldn't have a head |
1765 | * of the map, it shouldn't have a head |
1766 | */ |
1766 | */ |
1767 | if (lastcell.count != -1) { |
1767 | if (lastcell.count != -1) { |
1768 | SockList_AddShort(&sl, mask); |
1768 | SockList_AddShort(&sl, mask); |
1769 | map_clearcell(&lastcell,0,0,0,-1); |
1769 | map_clearcell(&lastcell,0,0,0,-1); |
1770 | } |
1770 | } |
1771 | } else if (d>3) { |
1771 | } else if (d>3) { |
1772 | int need_send=0, count; |
1772 | int need_send=0, count; |
1773 | /* This block deals with spaces that are not visible for whatever |
1773 | /* This block deals with spaces that are not visible for whatever |
1774 | * reason. Still may need to send the head for this space. |
1774 | * reason. Still may need to send the head for this space. |
1775 | */ |
1775 | */ |
1776 | |
1776 | |
1777 | oldlen = sl.len; |
1777 | oldlen = sl.len; |
1778 | |
1778 | |
1779 | SockList_AddShort(&sl, mask); |
1779 | SockList_AddShort(&sl, mask); |
1780 | if (lastcell.count != -1) need_send=1; |
1780 | if (lastcell.count != -1) need_send=1; |
1781 | count = -1; |
1781 | count = -1; |
1782 | |
1782 | |
1783 | if (socket.mapmode == Map1aCmd && have_head(ax, ay)) { |
1783 | if (socket.mapmode == Map1aCmd && have_head(ax, ay)) { |
1784 | /* Now check to see if any heads need to be sent */ |
1784 | /* Now check to see if any heads need to be sent */ |
1785 | |
1785 | |
1786 | if (check_head (sl, socket, ax, ay, 2)) |
1786 | if (check_head (sl, socket, ax, ay, 2)) |
1787 | mask |= 0x4; |
1787 | mask |= 0x4; |
1788 | if (check_head (sl, socket, ax, ay, 1)) |
1788 | if (check_head (sl, socket, ax, ay, 1)) |
1789 | mask |= 0x2; |
1789 | mask |= 0x2; |
1790 | if (check_head (sl, socket, ax, ay, 0)) |
1790 | if (check_head (sl, socket, ax, ay, 0)) |
1791 | mask |= 0x1; |
1791 | mask |= 0x1; |
1792 | |
1792 | |
1793 | lastcell.count = count; |
1793 | lastcell.count = count; |
1794 | |
1794 | |
1795 | } else { |
1795 | } else { |
1796 | struct MapCell *cell = &lastcell; |
1796 | struct MapCell *cell = &lastcell; |
1797 | /* properly clear a previously sent big face */ |
1797 | /* properly clear a previously sent big face */ |
1798 | if(cell->faces[0] != 0 |
1798 | if(cell->faces[0] != 0 |
1799 | || cell->faces[1] != 0 |
1799 | || cell->faces[1] != 0 |
1800 | || cell->faces[2] != 0) |
1800 | || cell->faces[2] != 0) |
1801 | need_send = 1; |
1801 | need_send = 1; |
1802 | map_clearcell(&lastcell, 0, 0, 0, count); |
1802 | map_clearcell(&lastcell, 0, 0, 0, count); |
1803 | } |
1803 | } |
1804 | |
1804 | |
1805 | if ((mask & 0xf) || need_send) { |
1805 | if ((mask & 0xf) || need_send) { |
1806 | sl.buf[oldlen+1] = mask & 0xff; |
1806 | sl.buf[oldlen+1] = mask & 0xff; |
1807 | } else { |
1807 | } else { |
1808 | sl.len = oldlen; |
1808 | sl.len = oldlen; |
1809 | } |
1809 | } |
1810 | } else { |
1810 | } else { |
1811 | /* 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 |
1812 | * we need to send. |
1812 | * we need to send. |
1813 | */ |
1813 | */ |
1814 | |
1814 | |
1815 | /* Rather than try to figure out what everything that we might |
1815 | /* Rather than try to figure out what everything that we might |
1816 | * need to send is, then form the packet after that, |
1816 | * need to send is, then form the packet after that, |
1817 | * 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 |
1818 | * 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, |
1819 | * 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 |
1820 | * is done. |
1820 | * is done. |
1821 | * 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 |
1822 | * what if anything we need to send, setting the bits, then |
1822 | * what if anything we need to send, setting the bits, then |
1823 | * doing those checks again to add the real data. |
1823 | * doing those checks again to add the real data. |
1824 | */ |
1824 | */ |
1825 | oldlen = sl.len; |
1825 | oldlen = sl.len; |
1826 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1826 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1827 | eoldlen = esl.len; |
1827 | eoldlen = esl.len; |
1828 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1828 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1829 | SockList_AddShort(&sl, mask); |
|
|
1830 | |
|
|
1831 | if (socket.ext_mapinfos) |
|
|
1832 | SockList_AddShort(&esl, emask); |
1829 | SockList_AddShort(&sl, mask); |
|
|
1830 | |
|
|
1831 | if (socket.ext_mapinfos) |
|
|
1832 | SockList_AddShort(&esl, emask); |
1833 | |
1833 | |
1834 | unsigned char dummy; |
1834 | unsigned char dummy; |
1835 | unsigned char *last_ext = &dummy; |
1835 | unsigned char *last_ext = &dummy; |
1836 | |
1836 | |
1837 | /* Darkness changed */ |
1837 | /* Darkness changed */ |
1838 | if (lastcell.count != d && socket.darkness) { |
1838 | if (lastcell.count != d && socket.darkness) { |
1839 | mask |= 0x8; |
1839 | mask |= 0x8; |
1840 | |
1840 | |
1841 | if (socket.extmap) |
1841 | if (socket.extmap) |
1842 | { |
1842 | { |
1843 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, d); |
1843 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, d); |
1844 | } |
1844 | } |
1845 | else |
1845 | else |
1846 | SockList_AddChar (&sl, 255 - 64 * d); |
1846 | SockList_AddChar (&sl, 255 - 64 * d); |
1847 | } |
1847 | } |
1848 | |
1848 | |
1849 | lastcell.count = d; |
1849 | lastcell.count = d; |
1850 | |
1850 | |
1851 | if (socket.extmap) |
1851 | if (socket.extmap) |
1852 | { |
1852 | { |
1853 | uint8 stat_hp = 0; |
1853 | uint8 stat_hp = 0; |
1854 | uint8 stat_width = 0; |
1854 | uint8 stat_width = 0; |
… | |
… | |
1899 | SockList_AddChar (&sl, 4); |
1899 | SockList_AddChar (&sl, 4); |
1900 | SockList_AddInt (&sl, player); |
1900 | SockList_AddInt (&sl, player); |
1901 | } |
1901 | } |
1902 | } |
1902 | } |
1903 | |
1903 | |
1904 | /* Floor face */ |
1904 | /* Floor face */ |
1905 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 2)) |
1905 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 2)) |
1906 | mask |= 0x4; |
1906 | mask |= 0x4; |
1907 | |
1907 | |
1908 | if (socket.EMI_smooth) |
1908 | if (socket.EMI_smooth) |
1909 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 2)) |
1909 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 2)) |
1910 | emask |= 0x4; |
1910 | emask |= 0x4; |
1911 | |
1911 | |
1912 | /* Middle face */ |
1912 | /* Middle face */ |
1913 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 1)) |
1913 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 1)) |
1914 | mask |= 0x2; |
1914 | mask |= 0x2; |
1915 | |
1915 | |
1916 | if (socket.EMI_smooth) |
1916 | if (socket.EMI_smooth) |
1917 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 1)) |
1917 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 1)) |
1918 | emask |= 0x2; |
1918 | emask |= 0x2; |
1919 | |
1919 | |
1920 | 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)) { |
1921 | if (lastcell.faces[0] != pl->face->number) { |
1921 | if (lastcell.faces[0] != pl->face->number) { |
1922 | lastcell.faces[0] = pl->face->number; |
1922 | lastcell.faces[0] = pl->face->number; |
1923 | mask |= 0x1; |
1923 | mask |= 0x1; |
1924 | if (!(socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) |
1924 | if (!(socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) |
1925 | esrv_send_face(&socket, pl->face->number, 0); |
1925 | esrv_send_face(&socket, pl->face->number, 0); |
1926 | SockList_AddShort(&sl, pl->face->number); |
1926 | SockList_AddShort(&sl, pl->face->number); |
1927 | } |
1927 | } |
1928 | } |
1928 | } |
1929 | /* Top face */ |
1929 | /* Top face */ |
1930 | else { |
1930 | else { |
1931 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 0)) |
1931 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 0)) |
1932 | mask |= 0x1; |
1932 | mask |= 0x1; |
1933 | if (socket.EMI_smooth) |
1933 | if (socket.EMI_smooth) |
1934 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 0)){ |
1934 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 0)){ |
1935 | emask |= 0x1; |
1935 | emask |= 0x1; |
1936 | } |
1936 | } |
1937 | } |
1937 | } |
1938 | /* 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 |
1939 | * space by checking the mask. If so, update the mask. |
1939 | * space by checking the mask. If so, update the mask. |
1940 | * 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 |
1941 | * value, so we don't send those bits. |
1941 | * value, so we don't send those bits. |
1942 | */ |
1942 | */ |
1943 | if (mask & 0xf) { |
1943 | if (mask & 0xf) { |
1944 | sl.buf[oldlen+1] = mask & 0xff; |
1944 | sl.buf[oldlen+1] = mask & 0xff; |
1945 | } else { |
1945 | } else { |
1946 | sl.len = oldlen; |
1946 | sl.len = oldlen; |
1947 | } |
1947 | } |
1948 | if (emask & 0xf) { |
1948 | if (emask & 0xf) { |
1949 | esl.buf[eoldlen+1] = emask & 0xff; |
1949 | esl.buf[eoldlen+1] = emask & 0xff; |
1950 | } else { |
1950 | } else { |
1951 | esl.len = eoldlen; |
1951 | esl.len = eoldlen; |
1952 | } |
1952 | } |
1953 | } /* else this is a viewable space */ |
1953 | } /* else this is a viewable space */ |
1954 | } /* for x loop */ |
1954 | } /* for x loop */ |
1955 | } /* for y loop */ |
1955 | } /* for y loop */ |
1956 | |
1956 | |
1957 | /* Verify that we in fact do need to send this */ |
1957 | /* Verify that we in fact do need to send this */ |
1958 | if (socket.ext_mapinfos){ |
1958 | if (socket.ext_mapinfos){ |
1959 | if (!(sl.len>startlen || socket.sent_scroll)){ |
1959 | if (!(sl.len>startlen || socket.sent_scroll)){ |
… | |
… | |
1967 | Send_With_Handling(&socket, &esl); |
1967 | Send_With_Handling(&socket, &esl); |
1968 | } |
1968 | } |
1969 | free(esl.buf); |
1969 | free(esl.buf); |
1970 | } |
1970 | } |
1971 | if (sl.len>startlen || socket.sent_scroll) { |
1971 | if (sl.len>startlen || socket.sent_scroll) { |
1972 | Send_With_Handling(&socket, &sl); |
1972 | Send_With_Handling(&socket, &sl); |
1973 | socket.sent_scroll = 0; |
1973 | socket.sent_scroll = 0; |
1974 | } |
1974 | } |
1975 | free(sl.buf); |
1975 | free(sl.buf); |
1976 | } |
1976 | } |
1977 | |
1977 | |
1978 | /** |
1978 | /** |
… | |
… | |
1987 | int d, mflags; |
1987 | int d, mflags; |
1988 | struct Map newmap; |
1988 | struct Map newmap; |
1989 | mapstruct *m, *pm; |
1989 | mapstruct *m, *pm; |
1990 | |
1990 | |
1991 | if (pl->type != PLAYER) { |
1991 | if (pl->type != PLAYER) { |
1992 | 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"); |
1993 | return; |
1993 | return; |
1994 | } |
1994 | } |
1995 | |
1995 | |
1996 | pm = pl->map; |
1996 | pm = pl->map; |
1997 | |
1997 | |
1998 | /* 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 |
… | |
… | |
2003 | |
2003 | |
2004 | memset(&newmap, 0, sizeof(struct Map)); |
2004 | memset(&newmap, 0, sizeof(struct Map)); |
2005 | |
2005 | |
2006 | 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++) { |
2007 | 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++) { |
2008 | ax=i; |
2008 | ax=i; |
2009 | ay=j; |
2009 | ay=j; |
2010 | m = pm; |
2010 | m = pm; |
2011 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
2011 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
2012 | if (mflags & P_OUT_OF_MAP) |
2012 | if (mflags & P_OUT_OF_MAP) |
2013 | continue; |
2013 | continue; |
2014 | if (mflags & P_NEED_UPDATE) |
2014 | if (mflags & P_NEED_UPDATE) |
2015 | update_position(m, ax, ay); |
2015 | update_position(m, ax, ay); |
2016 | /* 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 |
2017 | * just to reload it. This should really call something like |
2017 | * just to reload it. This should really call something like |
2018 | * swap_map, but this is much more efficient and 'good enough' |
2018 | * swap_map, but this is much more efficient and 'good enough' |
2019 | */ |
2019 | */ |
2020 | if (mflags & P_NEW_MAP) |
2020 | if (mflags & P_NEW_MAP) |
2021 | m->timeout = 50; |
2021 | m->timeout = 50; |
2022 | } |
2022 | } |
2023 | } |
2023 | } |
2024 | /* do LOS after calls to update_position */ |
2024 | /* do LOS after calls to update_position */ |
2025 | if(pl->contr->do_los) { |
2025 | if(pl->contr->do_los) { |
2026 | update_los(pl); |
2026 | update_los(pl); |
2027 | pl->contr->do_los = 0; |
2027 | pl->contr->do_los = 0; |
… | |
… | |
2032 | draw_client_map1(pl); |
2032 | draw_client_map1(pl); |
2033 | return; |
2033 | return; |
2034 | } |
2034 | } |
2035 | |
2035 | |
2036 | if(pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
2036 | if(pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
2037 | esrv_map_setbelow(&pl->contr->socket,pl->contr->socket.mapx/2, |
2037 | esrv_map_setbelow(&pl->contr->socket,pl->contr->socket.mapx/2, |
2038 | pl->contr->socket.mapy/2,pl->face->number,&newmap); |
2038 | pl->contr->socket.mapy/2,pl->face->number,&newmap); |
2039 | } |
2039 | } |
2040 | |
2040 | |
2041 | /* 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 |
2042 | * basically some number of spaces around the player) |
2042 | * basically some number of spaces around the player) |
2043 | * 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 |
… | |
… | |
2048 | * 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 |
2049 | * odd, this still works fine. |
2049 | * odd, this still works fine. |
2050 | */ |
2050 | */ |
2051 | ay=0; |
2051 | ay=0; |
2052 | 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++) { |
2053 | ax=0; |
2053 | ax=0; |
2054 | 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++) { |
2055 | |
2055 | |
2056 | d = pl->contr->blocked_los[ax][ay]; |
2056 | d = pl->contr->blocked_los[ax][ay]; |
2057 | /* 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 |
2058 | * negation check. |
2058 | * negation check. |
2059 | */ |
2059 | */ |
2060 | nx = i; |
2060 | nx = i; |
2061 | ny = j; |
2061 | ny = j; |
2062 | m = get_map_from_coord(pm, &nx, &ny); |
2062 | m = get_map_from_coord(pm, &nx, &ny); |
2063 | if (m && d<4) { |
2063 | if (m && d<4) { |
2064 | face = GET_MAP_FACE(m, nx, ny,0); |
2064 | face = GET_MAP_FACE(m, nx, ny,0); |
2065 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
2065 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
2066 | floor = GET_MAP_FACE(m, nx, ny,2); |
2066 | floor = GET_MAP_FACE(m, nx, ny,2); |
2067 | |
2067 | |
2068 | /* If all is blank, send a blank face. */ |
2068 | /* If all is blank, send a blank face. */ |
2069 | if ((!face || face == blank_face) && |
2069 | if ((!face || face == blank_face) && |
2070 | (!floor2 || floor2 == blank_face) && |
2070 | (!floor2 || floor2 == blank_face) && |
2071 | (!floor || floor == blank_face)) { |
2071 | (!floor || floor == blank_face)) { |
2072 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2072 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2073 | blank_face->number,&newmap); |
2073 | blank_face->number,&newmap); |
2074 | } else { /* actually have something interesting */ |
2074 | } else { /* actually have something interesting */ |
2075 | /* send the darkness mask, if any. */ |
2075 | /* send the darkness mask, if any. */ |
2076 | if (d && pl->contr->socket.darkness) |
2076 | if (d && pl->contr->socket.darkness) |
2077 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2077 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2078 | dark_faces[d-1]->number,&newmap); |
2078 | dark_faces[d-1]->number,&newmap); |
2079 | |
2079 | |
2080 | if (face && face != blank_face) |
2080 | if (face && face != blank_face) |
2081 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2081 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2082 | face->number,&newmap); |
2082 | face->number,&newmap); |
2083 | if (floor2 && floor2 != blank_face) |
2083 | if (floor2 && floor2 != blank_face) |
2084 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2084 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2085 | floor2->number,&newmap); |
2085 | floor2->number,&newmap); |
2086 | if (floor && floor != blank_face) |
2086 | if (floor && floor != blank_face) |
2087 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2087 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2088 | floor->number,&newmap); |
2088 | floor->number,&newmap); |
2089 | } |
2089 | } |
2090 | } /* Is a valid space */ |
2090 | } /* Is a valid space */ |
2091 | } |
2091 | } |
2092 | } |
2092 | } |
2093 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
2093 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
2094 | |
2094 | |
2095 | check_map_change (pl->contr); |
2095 | check_map_change (pl->contr); |
2096 | } |
2096 | } |
… | |
… | |
2116 | int i; |
2116 | int i; |
2117 | |
2117 | |
2118 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2118 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2119 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
2119 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
2120 | for (i=1; i< NUM_SKILLS; i++) { |
2120 | for (i=1; i< NUM_SKILLS; i++) { |
2121 | 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, |
2122 | skill_names[i]); |
2122 | skill_names[i]); |
2123 | } |
2123 | } |
2124 | sl.len = strlen((char*)sl.buf); |
2124 | sl.len = strlen((char*)sl.buf); |
2125 | if (sl.len >= MAXSOCKBUF) { |
2125 | if (sl.len >= MAXSOCKBUF) { |
2126 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2126 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2127 | fatal(0); |
2127 | fatal(0); |
2128 | } |
2128 | } |
2129 | Send_With_Handling(ns, &sl); |
2129 | Send_With_Handling(ns, &sl); |
2130 | free(sl.buf); |
2130 | free(sl.buf); |
2131 | } |
2131 | } |
2132 | |
2132 | |
… | |
… | |
2139 | int i; |
2139 | int i; |
2140 | |
2140 | |
2141 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2141 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2142 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2142 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2143 | for(i=0; i<NRSPELLPATHS; i++) |
2143 | for(i=0; i<NRSPELLPATHS; i++) |
2144 | 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]); |
2145 | sl.len = strlen((char*)sl.buf); |
2145 | sl.len = strlen((char*)sl.buf); |
2146 | if (sl.len >= MAXSOCKBUF) { |
2146 | if (sl.len >= MAXSOCKBUF) { |
2147 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2147 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2148 | fatal(0); |
2148 | fatal(0); |
2149 | } |
2149 | } |
2150 | Send_With_Handling(ns, &sl); |
2150 | Send_With_Handling(ns, &sl); |
2151 | free(sl.buf); |
2151 | free(sl.buf); |
2152 | } |
2152 | } |
2153 | |
2153 | |
… | |
… | |
2159 | SockList sl; |
2159 | SockList sl; |
2160 | int flags=0; |
2160 | int flags=0; |
2161 | object *spell; |
2161 | object *spell; |
2162 | if (!pl->socket.monitor_spells) return; |
2162 | if (!pl->socket.monitor_spells) return; |
2163 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2163 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2164 | if (spell->type == SPELL) { |
2164 | if (spell->type == SPELL) { |
2165 | /* check if we need to update it*/ |
2165 | /* check if we need to update it*/ |
2166 | 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)) { |
2167 | 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); |
2168 | flags |= UPD_SP_MANA; |
2168 | flags |= UPD_SP_MANA; |
2169 | } |
2169 | } |
2170 | 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)) { |
2171 | 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); |
2172 | flags |= UPD_SP_GRACE; |
2172 | flags |= UPD_SP_GRACE; |
2173 | } |
2173 | } |
2174 | 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)) { |
2175 | 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); |
2176 | flags |= UPD_SP_DAMAGE; |
2176 | flags |= UPD_SP_DAMAGE; |
2177 | } |
2177 | } |
2178 | if (flags !=0) { |
2178 | if (flags !=0) { |
2179 | sl.buf =(unsigned char*) malloc(MAXSOCKBUF); |
2179 | sl.buf =(unsigned char*) malloc(MAXSOCKBUF); |
2180 | strcpy((char*)sl.buf,"updspell "); |
2180 | strcpy((char*)sl.buf,"updspell "); |
2181 | sl.len=strlen((char*)sl.buf); |
2181 | sl.len=strlen((char*)sl.buf); |
2182 | SockList_AddChar(&sl, flags); |
2182 | SockList_AddChar(&sl, flags); |
2183 | SockList_AddInt(&sl, spell->count); |
2183 | SockList_AddInt(&sl, spell->count); |
2184 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
2184 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
2185 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
2185 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
2186 | if (flags & UPD_SP_DAMAGE) SockList_AddShort(&sl, spell->last_eat); |
2186 | if (flags & UPD_SP_DAMAGE) SockList_AddShort(&sl, spell->last_eat); |
2187 | flags = 0; |
2187 | flags = 0; |
2188 | Send_With_Handling(&pl->socket, &sl); |
2188 | Send_With_Handling(&pl->socket, &sl); |
2189 | free(sl.buf); |
2189 | free(sl.buf); |
2190 | } |
2190 | } |
2191 | } |
2191 | } |
2192 | } |
2192 | } |
2193 | } |
2193 | } |
2194 | |
2194 | |
2195 | void esrv_remove_spell(player *pl, object *spell) { |
2195 | void esrv_remove_spell(player *pl, object *spell) { |
2196 | SockList sl; |
2196 | SockList sl; |
2197 | |
2197 | |
2198 | if (!pl->socket.monitor_spells) return; |
2198 | if (!pl->socket.monitor_spells) return; |
2199 | if (!pl || !spell || spell->env != pl->ob) { |
2199 | if (!pl || !spell || spell->env != pl->ob) { |
2200 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2200 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2201 | return; |
2201 | return; |
2202 | } |
2202 | } |
2203 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2203 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2204 | strcpy((char*)sl.buf,"delspell "); |
2204 | strcpy((char*)sl.buf,"delspell "); |
2205 | sl.len=strlen((char*)sl.buf); |
2205 | sl.len=strlen((char*)sl.buf); |
2206 | SockList_AddInt(&sl, spell->count); |
2206 | SockList_AddInt(&sl, spell->count); |
… | |
… | |
2228 | SockList_AddShort(sl, spell->last_grace); |
2228 | SockList_AddShort(sl, spell->last_grace); |
2229 | SockList_AddShort(sl, spell->last_eat); |
2229 | SockList_AddShort(sl, spell->last_eat); |
2230 | |
2230 | |
2231 | /* figure out which skill it uses, if it uses one */ |
2231 | /* figure out which skill it uses, if it uses one */ |
2232 | if (spell->skill) { |
2232 | if (spell->skill) { |
2233 | for (i=1; i< NUM_SKILLS; i++) |
2233 | for (i=1; i< NUM_SKILLS; i++) |
2234 | if (!strcmp(spell->skill, skill_names[i])) { |
2234 | if (!strcmp(spell->skill, skill_names[i])) { |
2235 | skill = i+CS_STAT_SKILLINFO; |
2235 | skill = i+CS_STAT_SKILLINFO; |
2236 | break; |
2236 | break; |
2237 | } |
2237 | } |
2238 | } |
2238 | } |
2239 | SockList_AddChar(sl, skill); |
2239 | SockList_AddChar(sl, skill); |
2240 | |
2240 | |
2241 | SockList_AddInt(sl, spell->path_attuned); |
2241 | SockList_AddInt(sl, spell->path_attuned); |
2242 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
2242 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
… | |
… | |
2245 | SockList_AddChar(sl, (char)len); |
2245 | SockList_AddChar(sl, (char)len); |
2246 | memcpy(sl->buf+sl->len, spell->name, len); |
2246 | memcpy(sl->buf+sl->len, spell->name, len); |
2247 | sl->len+=len; |
2247 | sl->len+=len; |
2248 | |
2248 | |
2249 | if (!spell->msg) { |
2249 | if (!spell->msg) { |
2250 | SockList_AddShort(sl, 0); |
2250 | SockList_AddShort(sl, 0); |
2251 | } |
2251 | } |
2252 | else { |
2252 | else { |
2253 | len = strlen(spell->msg); |
2253 | len = strlen(spell->msg); |
2254 | SockList_AddShort(sl, len); |
2254 | SockList_AddShort(sl, len); |
2255 | memcpy(sl->buf+sl->len, spell->msg, len); |
2255 | memcpy(sl->buf+sl->len, spell->msg, len); |
2256 | sl->len+=len; |
2256 | sl->len+=len; |
2257 | } |
2257 | } |
2258 | } |
2258 | } |
2259 | |
2259 | |
2260 | /** |
2260 | /** |
2261 | * 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 |
2262 | * all spells in the player's inventory. |
2262 | * all spells in the player's inventory. |
2263 | */ |
2263 | */ |
2264 | void esrv_add_spells(player *pl, object *spell) { |
2264 | void esrv_add_spells(player *pl, object *spell) { |
2265 | SockList sl; |
2265 | SockList sl; |
2266 | if (!pl) { |
2266 | if (!pl) { |
2267 | 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"); |
2268 | return; |
2268 | return; |
2269 | } |
2269 | } |
2270 | if (!pl->socket.monitor_spells) return; |
2270 | if (!pl->socket.monitor_spells) return; |
2271 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2271 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2272 | strcpy((char*)sl.buf,"addspell "); |
2272 | strcpy((char*)sl.buf,"addspell "); |
2273 | sl.len=strlen((char*)sl.buf); |
2273 | sl.len=strlen((char*)sl.buf); |
2274 | if (!spell) { |
2274 | if (!spell) { |
2275 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2275 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2276 | /* were we to simply keep appending data here, we could exceed |
2276 | /* were we to simply keep appending data here, we could exceed |
2277 | * 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 |
2278 | * append_spells will always append 19 data bytes, plus 4 length |
2278 | * append_spells will always append 19 data bytes, plus 4 length |
2279 | * 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 |
2280 | * 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, |
2281 | * 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, |
2282 | * 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 |
2283 | */ |
2283 | */ |
2284 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2284 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2285 | * 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 |
2286 | * 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 |
2287 | * like it will fix this |
2287 | * like it will fix this |
2288 | */ |
2288 | */ |
2289 | if (spell->type != SPELL) continue; |
2289 | if (spell->type != SPELL) continue; |
2290 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2290 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2291 | (spell->msg?strlen(spell->msg):0)))) { |
2291 | (spell->msg?strlen(spell->msg):0)))) { |
2292 | Send_With_Handling(&pl->socket, &sl); |
2292 | Send_With_Handling(&pl->socket, &sl); |
2293 | strcpy((char*)sl.buf,"addspell "); |
2293 | strcpy((char*)sl.buf,"addspell "); |
2294 | sl.len=strlen((char*)sl.buf); |
2294 | sl.len=strlen((char*)sl.buf); |
2295 | } |
2295 | } |
2296 | append_spell(pl, &sl, spell); |
2296 | append_spell(pl, &sl, spell); |
2297 | } |
2297 | } |
2298 | } |
2298 | } |
2299 | else if (spell->type != SPELL) { |
2299 | else if (spell->type != SPELL) { |
2300 | 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"); |
2301 | return; |
2301 | return; |
2302 | } |
2302 | } |
2303 | else append_spell(pl, &sl, spell); |
2303 | else append_spell(pl, &sl, spell); |
2304 | if (sl.len >= MAXSOCKBUF) { |
2304 | if (sl.len >= MAXSOCKBUF) { |
2305 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2305 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2306 | fatal(0); |
2306 | fatal(0); |
2307 | } |
2307 | } |
2308 | /* finally, we can send the packet */ |
2308 | /* finally, we can send the packet */ |
2309 | Send_With_Handling(&pl->socket, &sl); |
2309 | Send_With_Handling(&pl->socket, &sl); |
2310 | free(sl.buf); |
2310 | free(sl.buf); |
2311 | } |
2311 | } |