1 | |
1 | |
2 | /* |
2 | /* |
3 | * static char *rcsid_init_c = |
3 | * static char *rcsid_init_c = |
4 | * "$Id: request.C,v 1.16 2006/09/10 13:43:33 root Exp $"; |
4 | * "$Id: request.C,v 1.18 2006/09/14 19:08:41 root Exp $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
50 | * operations |
50 | * operations |
51 | * |
51 | * |
52 | * esrv_map_doneredraw finishes the map update, and ships across the |
52 | * esrv_map_doneredraw finishes the map update, and ships across the |
53 | * map updates. |
53 | * map updates. |
54 | * |
54 | * |
55 | * esrv_map_scroll tells the client to scroll the map, and does similarily |
|
|
56 | * for the locally cached copy. |
|
|
57 | */ |
55 | */ |
58 | |
56 | |
59 | #include <global.h> |
57 | #include <global.h> |
60 | #include <sproto.h> |
58 | #include <sproto.h> |
61 | |
59 | |
… | |
… | |
581 | char command[50]; |
579 | char command[50]; |
582 | int info, nextinfo; |
580 | int info, nextinfo; |
583 | |
581 | |
584 | cmdback[0] = '\0'; |
582 | cmdback[0] = '\0'; |
585 | nextinfo = 0; |
583 | nextinfo = 0; |
|
|
584 | |
586 | while (1) |
585 | while (1) |
587 | { |
586 | { |
588 | /* 1. Extract an info */ |
587 | /* 1. Extract an info */ |
589 | info = nextinfo; |
588 | info = nextinfo; |
|
|
589 | |
590 | while ((info < len) && (buf[info] == ' ')) |
590 | while ((info < len) && (buf[info] == ' ')) |
591 | info++; |
591 | info++; |
|
|
592 | |
592 | if (info >= len) |
593 | if (info >= len) |
593 | break; |
594 | break; |
|
|
595 | |
594 | nextinfo = info + 1; |
596 | nextinfo = info + 1; |
|
|
597 | |
595 | while ((nextinfo < len) && (buf[nextinfo] != ' ')) |
598 | while ((nextinfo < len) && (buf[nextinfo] != ' ')) |
596 | nextinfo++; |
599 | nextinfo++; |
|
|
600 | |
597 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
601 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
598 | continue; |
602 | continue; |
|
|
603 | |
599 | strncpy (command, &(buf[info]), nextinfo - info); |
604 | strncpy (command, &(buf[info]), nextinfo - info); |
600 | command[nextinfo - info] = '\0'; |
605 | |
601 | /* 2. Interpret info */ |
606 | /* 2. Interpret info */ |
602 | if (!strcmp ("smooth", command)) |
607 | if (!strcmp ("smooth", command)) |
603 | { |
|
|
604 | /* Toggle smoothing */ |
608 | /* Toggle smoothing */ |
605 | ns->EMI_smooth = !ns->EMI_smooth; |
609 | ns->EMI_smooth = !ns->EMI_smooth; |
606 | } |
|
|
607 | else |
610 | else |
608 | { |
|
|
609 | /*bad value */ |
611 | /*bad value */; |
610 | } |
612 | |
611 | /*3. Next info */ |
613 | /*3. Next info */ |
612 | } |
614 | } |
|
|
615 | |
613 | strcpy (cmdback, "ExtendedInfoSet"); |
616 | strcpy (cmdback, "ExtendedInfoSet"); |
|
|
617 | |
614 | if (ns->EMI_smooth) |
618 | if (ns->EMI_smooth) |
615 | { |
619 | { |
616 | strcat (cmdback, " "); |
620 | strcat (cmdback, " "); |
617 | strcat (cmdback, "smoothing"); |
621 | strcat (cmdback, "smoothing"); |
618 | } |
622 | } |
|
|
623 | |
619 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
624 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
620 | } |
625 | } |
621 | |
626 | |
622 | /* |
627 | /* |
623 | #define MSG_TYPE_BOOK 1 |
628 | #define MSG_TYPE_BOOK 1 |
… | |
… | |
635 | char temp[10]; |
640 | char temp[10]; |
636 | char command[50]; |
641 | char command[50]; |
637 | int info, nextinfo, i, flag; |
642 | int info, nextinfo, i, flag; |
638 | |
643 | |
639 | cmdback[0] = '\0'; |
644 | cmdback[0] = '\0'; |
|
|
645 | |
640 | nextinfo = 0; |
646 | nextinfo = 0; |
641 | while (1) |
647 | while (1) |
642 | { |
648 | { |
643 | /* 1. Extract an info */ |
649 | /* 1. Extract an info */ |
644 | info = nextinfo; |
650 | info = nextinfo; |
|
|
651 | |
645 | while ((info < len) && (buf[info] == ' ')) |
652 | while ((info < len) && (buf[info] == ' ')) |
646 | info++; |
653 | info++; |
|
|
654 | |
647 | if (info >= len) |
655 | if (info >= len) |
648 | break; |
656 | break; |
|
|
657 | |
649 | nextinfo = info + 1; |
658 | nextinfo = info + 1; |
|
|
659 | |
650 | while ((nextinfo < len) && (buf[nextinfo] != ' ')) |
660 | while ((nextinfo < len) && (buf[nextinfo] != ' ')) |
651 | nextinfo++; |
661 | nextinfo++; |
|
|
662 | |
652 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
663 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
653 | continue; |
664 | continue; |
|
|
665 | |
654 | strncpy (command, &(buf[info]), nextinfo - info); |
666 | strncpy (command, &(buf[info]), nextinfo - info); |
655 | command[nextinfo - info] = '\0'; |
667 | command[nextinfo - info] = '\0'; |
656 | /* 2. Interpret info */ |
668 | /* 2. Interpret info */ |
657 | i = sscanf (command, "%d", &flag); |
669 | i = sscanf (command, "%d", &flag); |
|
|
670 | |
658 | if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST)) |
671 | if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST)) |
659 | ns->supported_readables |= (1 << flag); |
672 | ns->supported_readables |= (1 << flag); |
660 | /*3. Next info */ |
673 | /*3. Next info */ |
661 | } |
674 | } |
|
|
675 | |
662 | /* Send resulting state */ |
676 | /* Send resulting state */ |
663 | strcpy (cmdback, "ExtendedTextSet"); |
677 | strcpy (cmdback, "ExtendedTextSet"); |
|
|
678 | |
664 | for (i = 0; i <= MSG_TYPE_LAST; i++) |
679 | for (i = 0; i <= MSG_TYPE_LAST; i++) |
665 | if (ns->supported_readables & (1 << i)) |
680 | if (ns->supported_readables & (1 << i)) |
666 | { |
681 | { |
667 | strcat (cmdback, " "); |
682 | strcat (cmdback, " "); |
668 | snprintf (temp, sizeof (temp), "%d", i); |
683 | snprintf (temp, sizeof (temp), "%d", i); |
669 | strcat (cmdback, temp); |
684 | strcat (cmdback, temp); |
670 | } |
685 | } |
|
|
686 | |
671 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
687 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
672 | } |
688 | } |
673 | |
689 | |
674 | /** |
690 | /** |
675 | * A lot like the old AskSmooth (in fact, now called by AskSmooth). |
691 | * A lot like the old AskSmooth (in fact, now called by AskSmooth). |
… | |
… | |
1426 | |
1442 | |
1427 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
1443 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
1428 | { |
1444 | { |
1429 | /* All of this is just accounting stuff */ |
1445 | /* All of this is just accounting stuff */ |
1430 | if (tframes > 100) |
1446 | if (tframes > 100) |
1431 | { |
|
|
1432 | tframes = tbytes = 0; |
1447 | tframes = tbytes = 0; |
1433 | } |
1448 | |
1434 | tframes++; |
1449 | tframes++; |
1435 | frames++; |
1450 | frames++; |
1436 | tbytes += sl.len; |
1451 | tbytes += sl.len; |
1437 | bytes += sl.len; |
1452 | bytes += sl.len; |
1438 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1453 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1439 | Send_With_Handling (ns, &sl); |
1454 | Send_With_Handling (ns, &sl); |
1440 | ns->sent_scroll = 0; |
1455 | ns->sent_scroll = 0; |
1441 | } |
1456 | } |
|
|
1457 | |
1442 | free (sl.buf); |
1458 | free (sl.buf); |
1443 | } |
1459 | } |
1444 | |
1460 | |
1445 | |
1461 | |
1446 | /** Clears a map cell */ |
1462 | /** Clears a map cell */ |
… | |
… | |
2203 | * it doesn't need draw! |
2219 | * it doesn't need draw! |
2204 | */ |
2220 | */ |
2205 | ewhatflag &= (~EMI_NOREDRAW); |
2221 | ewhatflag &= (~EMI_NOREDRAW); |
2206 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2222 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2207 | } |
2223 | } |
|
|
2224 | |
2208 | if (esl.len > estartlen) |
2225 | if (esl.len > estartlen) |
2209 | { |
|
|
2210 | Send_With_Handling (&socket, &esl); |
2226 | Send_With_Handling (&socket, &esl); |
2211 | } |
2227 | |
2212 | free (esl.buf); |
2228 | free (esl.buf); |
2213 | } |
2229 | } |
|
|
2230 | |
2214 | if (sl.len > startlen || socket.sent_scroll) |
2231 | if (sl.len > startlen || socket.sent_scroll) |
2215 | { |
2232 | { |
2216 | Send_With_Handling (&socket, &sl); |
2233 | Send_With_Handling (&socket, &sl); |
2217 | socket.sent_scroll = 0; |
2234 | socket.sent_scroll = 0; |
2218 | } |
2235 | } |
|
|
2236 | |
2219 | free (sl.buf); |
2237 | free (sl.buf); |
2220 | } |
2238 | } |
2221 | |
2239 | |
2222 | /** |
2240 | /** |
2223 | * Draws client map. |
2241 | * Draws client map. |