ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/request.C
(Generate patch)

Comparing deliantra/server/socket/request.C (file contents):
Revision 1.16 by root, Sun Sep 10 13:43:33 2006 UTC vs.
Revision 1.26 by pippijn, Mon Dec 11 19:46:47 2006 UTC

1
2/*
3 * static char *rcsid_init_c =
4 * "$Id: request.C,v 1.16 2006/09/10 13:43:33 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001 Mark Wedel 4 Copyright (C) 2001 Mark Wedel
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The author can be reached via e-mail to crossfire-devel@real-time.com 21 The author can be reached via e-mail to <crossfire@schmorp.de>
28*/ 22*/
29 23
30/** 24/**
31 * \file 25 * \file
32 * Client handling. 26 * Client handling.
50 * operations 44 * operations
51 * 45 *
52 * esrv_map_doneredraw finishes the map update, and ships across the 46 * esrv_map_doneredraw finishes the map update, and ships across the
53 * map updates. 47 * map updates.
54 * 48 *
55 * esrv_map_scroll tells the client to scroll the map, and does similarily
56 * for the locally cached copy.
57 */ 49 */
58 50
59#include <global.h> 51#include <global.h>
60#include <sproto.h> 52#include <sproto.h>
61 53
65#include <commands.h> 57#include <commands.h>
66 58
67/* This block is basically taken from socket.c - I assume if it works there, 59/* This block is basically taken from socket.c - I assume if it works there,
68 * it should work here. 60 * it should work here.
69 */ 61 */
70#ifndef WIN32 /* ---win32 exclude unix headers */
71# include <sys/types.h> 62#include <sys/types.h>
72# include <sys/time.h> 63#include <sys/time.h>
73# include <sys/socket.h> 64#include <sys/socket.h>
74# include <netinet/in.h> 65#include <netinet/in.h>
75# include <netdb.h> 66#include <netdb.h>
76#endif /* win32 */
77 67
78#ifdef HAVE_UNISTD_H 68#ifdef HAVE_UNISTD_H
79# include <unistd.h> 69# include <unistd.h>
80#endif 70#endif
81 71
145 for (x = 0; x < mx; x++) 135 for (x = 0; x < mx; x++)
146 { 136 {
147 for (y = 0; y < my; y++) 137 for (y = 0; y < my; y++)
148 { 138 {
149 if (x >= ns->mapx || y >= ns->mapy) 139 if (x >= ns->mapx || y >= ns->mapy)
150 {
151 /* clear cells outside the viewable area */ 140 /* clear cells outside the viewable area */
152 memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); 141 memset (&newmap.cells[x][y], 0, sizeof (struct MapCell));
153 }
154 else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) 142 else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy)
155 {
156 /* clear newly visible tiles within the viewable area */ 143 /* clear newly visible tiles within the viewable area */
157 memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); 144 memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell));
158 }
159 else 145 else
160 {
161 memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); 146 memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell));
162 }
163 } 147 }
164 } 148 }
165 149
166 memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); 150 memcpy (&(ns->lastmap), &newmap, sizeof (struct Map));
167 151
266 if (!strncmp (buf, "spatial ", 8)) 250 if (!strncmp (buf, "spatial ", 8))
267 { 251 {
268 buf += 8; 252 buf += 8;
269 253
270 // initial map and its origin 254 // initial map and its origin
271 mapstruct *map = pl->ob->map; 255 maptile *map = pl->ob->map;
272 sint16 dx, dy; 256 sint16 dx, dy;
273 int mapx = pl->socket.mapx / 2 - pl->ob->x; 257 int mapx = pl->socket.mapx / 2 - pl->ob->x;
274 int mapy = pl->socket.mapy / 2 - pl->ob->y; 258 int mapy = pl->socket.mapy / 2 - pl->ob->y;
275 int max_distance = 8; // limit maximum path length to something generous 259 int max_distance = 8; // limit maximum path length to something generous
276 260
581 char command[50]; 565 char command[50];
582 int info, nextinfo; 566 int info, nextinfo;
583 567
584 cmdback[0] = '\0'; 568 cmdback[0] = '\0';
585 nextinfo = 0; 569 nextinfo = 0;
570
586 while (1) 571 while (1)
587 { 572 {
588 /* 1. Extract an info */ 573 /* 1. Extract an info */
589 info = nextinfo; 574 info = nextinfo;
575
590 while ((info < len) && (buf[info] == ' ')) 576 while ((info < len) && (buf[info] == ' '))
591 info++; 577 info++;
578
592 if (info >= len) 579 if (info >= len)
593 break; 580 break;
581
594 nextinfo = info + 1; 582 nextinfo = info + 1;
583
595 while ((nextinfo < len) && (buf[nextinfo] != ' ')) 584 while ((nextinfo < len) && (buf[nextinfo] != ' '))
596 nextinfo++; 585 nextinfo++;
586
597 if (nextinfo - info >= 49) /*Erroneous info asked */ 587 if (nextinfo - info >= 49) /*Erroneous info asked */
598 continue; 588 continue;
589
599 strncpy (command, &(buf[info]), nextinfo - info); 590 strncpy (command, &(buf[info]), nextinfo - info);
600 command[nextinfo - info] = '\0'; 591
601 /* 2. Interpret info */ 592 /* 2. Interpret info */
602 if (!strcmp ("smooth", command)) 593 if (!strcmp ("smooth", command))
603 {
604 /* Toggle smoothing */ 594 /* Toggle smoothing */
605 ns->EMI_smooth = !ns->EMI_smooth; 595 ns->EMI_smooth = !ns->EMI_smooth;
606 }
607 else 596 else
608 {
609 /*bad value */ 597 /*bad value */;
610 } 598
611 /*3. Next info */ 599 /*3. Next info */
612 } 600 }
601
613 strcpy (cmdback, "ExtendedInfoSet"); 602 strcpy (cmdback, "ExtendedInfoSet");
603
614 if (ns->EMI_smooth) 604 if (ns->EMI_smooth)
615 { 605 {
616 strcat (cmdback, " "); 606 strcat (cmdback, " ");
617 strcat (cmdback, "smoothing"); 607 strcat (cmdback, "smoothing");
618 } 608 }
609
619 Write_String_To_Socket (ns, cmdback, strlen (cmdback)); 610 Write_String_To_Socket (ns, cmdback, strlen (cmdback));
620} 611}
621 612
622/* 613/*
623#define MSG_TYPE_BOOK 1 614#define MSG_TYPE_BOOK 1
635 char temp[10]; 626 char temp[10];
636 char command[50]; 627 char command[50];
637 int info, nextinfo, i, flag; 628 int info, nextinfo, i, flag;
638 629
639 cmdback[0] = '\0'; 630 cmdback[0] = '\0';
631
640 nextinfo = 0; 632 nextinfo = 0;
641 while (1) 633 while (1)
642 { 634 {
643 /* 1. Extract an info */ 635 /* 1. Extract an info */
644 info = nextinfo; 636 info = nextinfo;
637
645 while ((info < len) && (buf[info] == ' ')) 638 while ((info < len) && (buf[info] == ' '))
646 info++; 639 info++;
640
647 if (info >= len) 641 if (info >= len)
648 break; 642 break;
643
649 nextinfo = info + 1; 644 nextinfo = info + 1;
645
650 while ((nextinfo < len) && (buf[nextinfo] != ' ')) 646 while ((nextinfo < len) && (buf[nextinfo] != ' '))
651 nextinfo++; 647 nextinfo++;
648
652 if (nextinfo - info >= 49) /*Erroneous info asked */ 649 if (nextinfo - info >= 49) /*Erroneous info asked */
653 continue; 650 continue;
651
654 strncpy (command, &(buf[info]), nextinfo - info); 652 strncpy (command, &(buf[info]), nextinfo - info);
655 command[nextinfo - info] = '\0'; 653 command[nextinfo - info] = '\0';
656 /* 2. Interpret info */ 654 /* 2. Interpret info */
657 i = sscanf (command, "%d", &flag); 655 i = sscanf (command, "%d", &flag);
656
658 if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST)) 657 if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST))
659 ns->supported_readables |= (1 << flag); 658 ns->supported_readables |= (1 << flag);
660 /*3. Next info */ 659 /*3. Next info */
661 } 660 }
661
662 /* Send resulting state */ 662 /* Send resulting state */
663 strcpy (cmdback, "ExtendedTextSet"); 663 strcpy (cmdback, "ExtendedTextSet");
664
664 for (i = 0; i <= MSG_TYPE_LAST; i++) 665 for (i = 0; i <= MSG_TYPE_LAST; i++)
665 if (ns->supported_readables & (1 << i)) 666 if (ns->supported_readables & (1 << i))
666 { 667 {
667 strcat (cmdback, " "); 668 strcat (cmdback, " ");
668 snprintf (temp, sizeof (temp), "%d", i); 669 snprintf (temp, sizeof (temp), "%d", i);
669 strcat (cmdback, temp); 670 strcat (cmdback, temp);
670 } 671 }
672
671 Write_String_To_Socket (ns, cmdback, strlen (cmdback)); 673 Write_String_To_Socket (ns, cmdback, strlen (cmdback));
672} 674}
673 675
674/** 676/**
675 * A lot like the old AskSmooth (in fact, now called by AskSmooth). 677 * A lot like the old AskSmooth (in fact, now called by AskSmooth).
1121 AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); 1123 AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS);
1122 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); 1124 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX);
1123 AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); 1125 AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON);
1124 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); 1126 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA);
1125 } 1127 }
1128
1126 if (pl->socket.exp64) 1129 if (pl->socket.exp64)
1127 { 1130 {
1128 uint8 s; 1131 uint8 s;
1129 1132
1130 for (s = 0; s < NUM_SKILLS; s++) 1133 for (s = 0; s < NUM_SKILLS; s++)
1140 SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); 1143 SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp);
1141 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; 1144 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp;
1142 } 1145 }
1143 } 1146 }
1144 } 1147 }
1148
1145 if (pl->socket.exp64) 1149 if (pl->socket.exp64)
1146 {
1147 AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); 1150 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) }
1148 }
1149 else 1151 else
1150 {
1151 AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP); 1152 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) }
1152 } 1153
1153 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); 1154 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL);
1154 AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); 1155 AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC);
1155 AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); 1156 AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC);
1156 AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); 1157 AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM);
1157 AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); 1158 AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED);
1158 AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); 1159 AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD);
1159 AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); 1160 AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP);
1160 AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); 1161 AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM);
1161 flags = 0; 1162 flags = 0;
1163
1162 if (pl->fire_on) 1164 if (pl->fire_on)
1163 flags |= SF_FIREON; 1165 flags |= SF_FIREON;
1166
1164 if (pl->run_on) 1167 if (pl->run_on)
1165 flags |= SF_RUNON; 1168 flags |= SF_RUNON;
1166 1169
1167 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); 1170 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS);
1171
1168 if (pl->socket.sc_version < 1025) 1172 if (pl->socket.sc_version < 1025)
1169 {
1170 AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); 1173 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) }
1171 }
1172 else 1174 else
1173 { 1175 {
1174 int i; 1176 int i;
1175 1177
1176 for (i = 0; i < NROFATTACKS; i++) 1178 for (i = 0; i < NROFATTACKS; i++)
1177 { 1179 {
1178 /* Skip ones we won't send */ 1180 /* Skip ones we won't send */
1179 if (atnr_cs_stat[i] == -1) 1181 if (atnr_cs_stat[i] == -1)
1180 continue; 1182 continue;
1183
1181 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); 1184 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]);
1182 } 1185 }
1183 } 1186 }
1187
1184 if (pl->socket.monitor_spells) 1188 if (pl->socket.monitor_spells)
1185 { 1189 {
1186 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); 1190 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE);
1187 AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); 1191 AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL);
1188 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); 1192 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY);
1189 } 1193 }
1194
1190 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ 1195 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */
1191 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); 1196 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE);
1192 set_title (pl->ob, buf); 1197 set_title (pl->ob, buf);
1193 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1198 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE);
1194 1199
1198#ifdef ESRV_DEBUG 1203#ifdef ESRV_DEBUG
1199 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); 1204 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len);
1200#endif 1205#endif
1201 Send_With_Handling (&pl->socket, &sl); 1206 Send_With_Handling (&pl->socket, &sl);
1202 } 1207 }
1208
1203 free (sl.buf); 1209 free (sl.buf);
1204} 1210}
1205
1206 1211
1207/** 1212/**
1208 * Tells the client that here is a player it should start using. 1213 * Tells the client that here is a player it should start using.
1209 */ 1214 */
1210void 1215void
1228 1233
1229 Send_With_Handling (&pl->socket, &sl); 1234 Send_With_Handling (&pl->socket, &sl);
1230 free (sl.buf); 1235 free (sl.buf);
1231 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1236 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1232} 1237}
1233
1234 1238
1235/** 1239/**
1236 * Need to send an animation sequence to the client. 1240 * Need to send an animation sequence to the client.
1237 * We will send appropriate face commands to the client if we haven't 1241 * We will send appropriate face commands to the client if we haven't
1238 * sent them the face yet (this can become quite costly in terms of 1242 * sent them the face yet (this can become quite costly in terms of
1426 1430
1427 if (sl.len > (int) strlen ("map ") || ns->sent_scroll) 1431 if (sl.len > (int) strlen ("map ") || ns->sent_scroll)
1428 { 1432 {
1429 /* All of this is just accounting stuff */ 1433 /* All of this is just accounting stuff */
1430 if (tframes > 100) 1434 if (tframes > 100)
1431 {
1432 tframes = tbytes = 0; 1435 tframes = tbytes = 0;
1433 } 1436
1434 tframes++; 1437 tframes++;
1435 frames++; 1438 frames++;
1436 tbytes += sl.len; 1439 tbytes += sl.len;
1437 bytes += sl.len; 1440 bytes += sl.len;
1438 memcpy (&ns->lastmap, newmap, sizeof (struct Map)); 1441 memcpy (&ns->lastmap, newmap, sizeof (struct Map));
1439 Send_With_Handling (ns, &sl); 1442 Send_With_Handling (ns, &sl);
1440 ns->sent_scroll = 0; 1443 ns->sent_scroll = 0;
1441 } 1444 }
1445
1442 free (sl.buf); 1446 free (sl.buf);
1443} 1447}
1444 1448
1445 1449
1446/** Clears a map cell */ 1450/** Clears a map cell */
1448map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) 1452map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count)
1449{ 1453{
1450 cell->faces[0] = face0; 1454 cell->faces[0] = face0;
1451 cell->faces[1] = face1; 1455 cell->faces[1] = face1;
1452 cell->faces[2] = face2; 1456 cell->faces[2] = face2;
1453 cell->count = count; 1457 cell->count = count;
1454 cell->stat_hp = 0; 1458 cell->stat_hp = 0;
1459 cell->flags = 0;
1455 cell->player = 0; 1460 cell->player = 0;
1456} 1461}
1457 1462
1458#define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) 1463#define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y)
1459#define MAX_LAYERS 3 1464#define MAX_LAYERS 3
1460 1465
1531 * the case, it seems to make more sense to have these layer values 1536 * the case, it seems to make more sense to have these layer values
1532 * actually match. 1537 * actually match.
1533 */ 1538 */
1534 1539
1535static int 1540static int
1536update_space (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) 1541update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1537{ 1542{
1538 object *ob, *head; 1543 object *ob, *head;
1539 uint16 face_num; 1544 uint16 face_num;
1540 int bx, by, i; 1545 int bx, by, i;
1541 1546
1755 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1760 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1756 * take. 1761 * take.
1757 */ 1762 */
1758 1763
1759static inline int 1764static inline int
1760update_smooth (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) 1765update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1761{ 1766{
1762 object *ob; 1767 object *ob;
1763 int smoothlevel; /* old face_num; */ 1768 int smoothlevel; /* old face_num; */
1764 1769
1765 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1770 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1843 SockList esl; /*For extended Map info */ 1848 SockList esl; /*For extended Map info */
1844 uint16 mask, emask; 1849 uint16 mask, emask;
1845 uint8 eentrysize; 1850 uint8 eentrysize;
1846 uint16 ewhatstart, ewhatflag; 1851 uint16 ewhatstart, ewhatflag;
1847 uint8 extendedinfos; 1852 uint8 extendedinfos;
1848 mapstruct *m; 1853 maptile *m;
1849 1854
1850 NewSocket & socket = pl->contr->socket; 1855 NewSocket & socket = pl->contr->socket;
1851 1856
1852 check_map_change (pl->contr); 1857 check_map_change (pl->contr);
1853 1858
1856 strcpy ((char *) sl.buf, "map1 "); 1861 strcpy ((char *) sl.buf, "map1 ");
1857 else 1862 else
1858 strcpy ((char *) sl.buf, "map1a "); 1863 strcpy ((char *) sl.buf, "map1a ");
1859 sl.len = strlen ((char *) sl.buf); 1864 sl.len = strlen ((char *) sl.buf);
1860 startlen = sl.len; 1865 startlen = sl.len;
1866
1861 /*Extendedmapinfo structure initialisation */ 1867 /*Extendedmapinfo structure initialisation */
1862 if (socket.ext_mapinfos) 1868 if (socket.ext_mapinfos)
1863 { 1869 {
1864 esl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1870 esl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1865 strcpy ((char *) esl.buf, "mapextended "); 1871 strcpy ((char *) esl.buf, "mapextended ");
1866 esl.len = strlen ((char *) esl.buf); 1872 esl.len = strlen ((char *) esl.buf);
1867 extendedinfos = EMI_NOREDRAW; 1873 extendedinfos = EMI_NOREDRAW;
1874
1868 if (socket.EMI_smooth) 1875 if (socket.EMI_smooth)
1869 extendedinfos |= EMI_SMOOTH; 1876 extendedinfos |= EMI_SMOOTH;
1877
1870 ewhatstart = esl.len; 1878 ewhatstart = esl.len;
1871 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit 1879 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1872 could need to be taken away */ 1880 could need to be taken away */
1873 SockList_AddChar (&esl, extendedinfos); 1881 SockList_AddChar (&esl, extendedinfos);
1874 eentrysize = getExtendedMapInfoSize (&socket); 1882 eentrysize = getExtendedMapInfoSize (&socket);
1880 /* suppress compiler warnings */ 1888 /* suppress compiler warnings */
1881 ewhatstart = 0; 1889 ewhatstart = 0;
1882 ewhatflag = 0; 1890 ewhatflag = 0;
1883 estartlen = 0; 1891 estartlen = 0;
1884 } 1892 }
1893
1885 /* Init data to zero */ 1894 /* Init data to zero */
1886 memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); 1895 memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS);
1887 1896
1888 /* x,y are the real map locations. ax, ay are viewport relative 1897 /* x,y are the real map locations. ax, ay are viewport relative
1889 * locations. 1898 * locations.
1893 /* We could do this logic as conditionals in the if statement, 1902 /* We could do this logic as conditionals in the if statement,
1894 * but that started to get a bit messy to look at. 1903 * but that started to get a bit messy to look at.
1895 */ 1904 */
1896 max_x = pl->x + (socket.mapx + 1) / 2; 1905 max_x = pl->x + (socket.mapx + 1) / 2;
1897 max_y = pl->y + (socket.mapy + 1) / 2; 1906 max_y = pl->y + (socket.mapy + 1) / 2;
1907
1898 if (socket.mapmode == Map1aCmd) 1908 if (socket.mapmode == Map1aCmd)
1899 { 1909 {
1900 max_x += MAX_HEAD_OFFSET; 1910 max_x += MAX_HEAD_OFFSET;
1901 max_y += MAX_HEAD_OFFSET; 1911 max_y += MAX_HEAD_OFFSET;
1902 } 1912 }
1935 * with no faces tells the client to blank out the 1945 * with no faces tells the client to blank out the
1936 * space. 1946 * space.
1937 */ 1947 */
1938 got_one = 0; 1948 got_one = 0;
1939 for (i = oldlen + 2; i < sl.len; i++) 1949 for (i = oldlen + 2; i < sl.len; i++)
1940 {
1941 if (sl.buf[i]) 1950 if (sl.buf[i])
1942 got_one = 1; 1951 got_one = 1;
1943 }
1944 1952
1945 if (got_one && (mask & 0xf)) 1953 if (got_one && (mask & 0xf))
1946 {
1947 sl.buf[oldlen + 1] = mask & 0xff; 1954 sl.buf[oldlen + 1] = mask & 0xff;
1948 }
1949 else 1955 else
1950 { /*either all faces blank, either no face at all */ 1956 { /*either all faces blank, either no face at all */
1951 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ 1957 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1952 sl.len = oldlen + 2; 1958 sl.len = oldlen + 2;
1953 else 1959 else
1954 sl.len = oldlen; 1960 sl.len = oldlen;
1955 } 1961 }
1962
1956 /*What concerns extendinfos, nothing to be done for now 1963 /*What concerns extendinfos, nothing to be done for now
1957 * (perhaps effects layer later) 1964 * (perhaps effects layer later)
1958 */ 1965 */
1959 continue; /* don't do processing below */ 1966 continue; /* don't do processing below */
1960 } 1967 }
1961 1968
1962 MapCell & lastcell = socket.lastmap.cells[ax][ay]; 1969 MapCell &lastcell = socket.lastmap.cells[ax][ay];
1963 1970
1964 d = pl->contr->blocked_los[ax][ay]; 1971 d = pl->contr->blocked_los[ax][ay];
1965 1972
1966 /* If the coordinates are not valid, or it is too dark to see, 1973 /* If the coordinates are not valid, or it is too dark to see,
1967 * we tell the client as such 1974 * we tell the client as such
1968 */ 1975 */
1969 nx = x; 1976 nx = x;
1970 ny = y; 1977 ny = y;
1971 m = get_map_from_coord (pl->map, &nx, &ny); 1978 m = get_map_from_coord (pl->map, &nx, &ny);
1979
1972 if (!m) 1980 if (!m)
1973 { 1981 {
1974 /* space is out of map. Update space and clear values 1982 /* space is out of map. Update space and clear values
1975 * if this hasn't already been done. If the space is out 1983 * if this hasn't already been done. If the space is out
1976 * of the map, it shouldn't have a head 1984 * of the map, it shouldn't have a head
1990 */ 1998 */
1991 1999
1992 oldlen = sl.len; 2000 oldlen = sl.len;
1993 2001
1994 SockList_AddShort (&sl, mask); 2002 SockList_AddShort (&sl, mask);
2003
1995 if (lastcell.count != -1) 2004 if (lastcell.count != -1)
1996 need_send = 1; 2005 need_send = 1;
2006
1997 count = -1; 2007 count = -1;
1998 2008
1999 if (socket.mapmode == Map1aCmd && have_head (ax, ay)) 2009 if (socket.mapmode == Map1aCmd && have_head (ax, ay))
2000 { 2010 {
2001 /* Now check to see if any heads need to be sent */ 2011 /* Now check to see if any heads need to be sent */
2006 mask |= 0x2; 2016 mask |= 0x2;
2007 if (check_head (sl, socket, ax, ay, 0)) 2017 if (check_head (sl, socket, ax, ay, 0))
2008 mask |= 0x1; 2018 mask |= 0x1;
2009 2019
2010 lastcell.count = count; 2020 lastcell.count = count;
2011
2012 } 2021 }
2013 else 2022 else
2014 { 2023 {
2015 struct MapCell *cell = &lastcell;
2016
2017 /* properly clear a previously sent big face */ 2024 /* properly clear a previously sent big face */
2018 if (cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) 2025 if (lastcell.faces[0] != 0 || lastcell.faces[1] != 0 || lastcell.faces[2] != 0
2026 || lastcell.stat_hp || lastcell.flags || lastcell.player)
2019 need_send = 1; 2027 need_send = 1;
2028
2020 map_clearcell (&lastcell, 0, 0, 0, count); 2029 map_clearcell (&lastcell, 0, 0, 0, count);
2021 } 2030 }
2022 2031
2023 if ((mask & 0xf) || need_send) 2032 if ((mask & 0xf) || need_send)
2024 {
2025 sl.buf[oldlen + 1] = mask & 0xff; 2033 sl.buf[oldlen + 1] = mask & 0xff;
2026 }
2027 else 2034 else
2028 {
2029 sl.len = oldlen; 2035 sl.len = oldlen;
2030 }
2031 } 2036 }
2032 else 2037 else
2033 { 2038 {
2034 /* In this block, the space is visible or there are head objects 2039 /* In this block, the space is visible or there are head objects
2035 * we need to send. 2040 * we need to send.
2076 2081
2077 if (socket.extmap) 2082 if (socket.extmap)
2078 { 2083 {
2079 uint8 stat_hp = 0; 2084 uint8 stat_hp = 0;
2080 uint8 stat_width = 0; 2085 uint8 stat_width = 0;
2086 uint8 flags = 0;
2081 tag_t player = 0; 2087 tag_t player = 0;
2082 2088
2083 // send hp information, if applicable 2089 // send hp information, if applicable
2084 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) 2090 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0))
2085 { 2091 {
2093 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 2099 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
2094 stat_width = op->arch->tail_x; 2100 stat_width = op->arch->tail_x;
2095 } 2101 }
2096 } 2102 }
2097 2103
2104 if (op->msg && op->msg[0] == '@')
2105 flags |= 1;
2106
2098 if (op->type == PLAYER && op != pl) 2107 if (op->type == PLAYER && op != pl)
2099 player = op->count; 2108 player = op->count;
2100 } 2109 }
2101 2110
2102 if (lastcell.stat_hp != stat_hp) 2111 if (lastcell.stat_hp != stat_hp)
2116 SockList_AddChar (&sl, 6); 2125 SockList_AddChar (&sl, 6);
2117 SockList_AddChar (&sl, stat_width); 2126 SockList_AddChar (&sl, stat_width);
2118 } 2127 }
2119 } 2128 }
2120 2129
2121 if (lastcell.player !=player) 2130 if (lastcell.player != player)
2122 { 2131 {
2123 lastcell.player = player; 2132 lastcell.player = player;
2124 2133
2125 mask |= 0x8; 2134 mask |= 0x8;
2126 *last_ext |= 0x80; 2135 *last_ext |= 0x80;
2127 last_ext = sl.buf + sl.len; 2136 last_ext = sl.buf + sl.len;
2128 SockList_AddChar (&sl, 0x47); 2137 SockList_AddChar (&sl, 0x47);
2129 SockList_AddChar (&sl, 4); 2138 SockList_AddChar (&sl, 4);
2130 SockList_AddInt (&sl, player); 2139 SockList_AddInt (&sl, player);
2131 } 2140 }
2141
2142 if (lastcell.flags != flags)
2143 {
2144 lastcell.flags = flags;
2145
2146 mask |= 0x8;
2147 *last_ext |= 0x80;
2148 last_ext = sl.buf + sl.len;
2149 SockList_AddChar (&sl, 8);
2150 SockList_AddChar (&sl, flags);
2151 }
2132 } 2152 }
2133 2153
2134 /* Floor face */ 2154 /* Floor face */
2135 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) 2155 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2))
2136 mask |= 0x4; 2156 mask |= 0x4;
2151 { 2171 {
2152 if (lastcell.faces[0] != pl->face->number) 2172 if (lastcell.faces[0] != pl->face->number)
2153 { 2173 {
2154 lastcell.faces[0] = pl->face->number; 2174 lastcell.faces[0] = pl->face->number;
2155 mask |= 0x1; 2175 mask |= 0x1;
2176
2156 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) 2177 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE))
2157 esrv_send_face (&socket, pl->face->number, 0); 2178 esrv_send_face (&socket, pl->face->number, 0);
2179
2158 SockList_AddShort (&sl, pl->face->number); 2180 SockList_AddShort (&sl, pl->face->number);
2159 } 2181 }
2160 } 2182 }
2161 /* Top face */
2162 else 2183 else
2163 { 2184 {
2185 /* Top face */
2164 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) 2186 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0))
2165 mask |= 0x1; 2187 mask |= 0x1;
2188
2166 if (socket.EMI_smooth) 2189 if (socket.EMI_smooth)
2167 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) 2190 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0))
2168 {
2169 emask |= 0x1; 2191 emask |= 0x1;
2170 }
2171 } 2192 }
2193
2172 /* Check to see if we are in fact sending anything for this 2194 /* Check to see if we are in fact sending anything for this
2173 * space by checking the mask. If so, update the mask. 2195 * space by checking the mask. If so, update the mask.
2174 * if not, reset the len to that from before adding the mask 2196 * if not, reset the len to that from before adding the mask
2175 * value, so we don't send those bits. 2197 * value, so we don't send those bits.
2176 */ 2198 */
2177 if (mask & 0xf) 2199 if (mask & 0xf)
2178 {
2179 sl.buf[oldlen + 1] = mask & 0xff; 2200 sl.buf[oldlen + 1] = mask & 0xff;
2180 }
2181 else 2201 else
2182 {
2183 sl.len = oldlen; 2202 sl.len = oldlen;
2184 } 2203
2185 if (emask & 0xf) 2204 if (emask & 0xf)
2186 {
2187 esl.buf[eoldlen + 1] = emask & 0xff; 2205 esl.buf[eoldlen + 1] = emask & 0xff;
2188 }
2189 else 2206 else
2190 {
2191 esl.len = eoldlen; 2207 esl.len = eoldlen;
2192 }
2193 } /* else this is a viewable space */ 2208 } /* else this is a viewable space */
2194 } /* for x loop */ 2209 } /* for x loop */
2195 } /* for y loop */ 2210 } /* for y loop */
2196 2211
2197 /* Verify that we in fact do need to send this */ 2212 /* Verify that we in fact do need to send this */
2203 * it doesn't need draw! 2218 * it doesn't need draw!
2204 */ 2219 */
2205 ewhatflag &= (~EMI_NOREDRAW); 2220 ewhatflag &= (~EMI_NOREDRAW);
2206 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2221 esl.buf[ewhatstart + 1] = ewhatflag & 0xff;
2207 } 2222 }
2223
2208 if (esl.len > estartlen) 2224 if (esl.len > estartlen)
2209 {
2210 Send_With_Handling (&socket, &esl); 2225 Send_With_Handling (&socket, &esl);
2211 } 2226
2212 free (esl.buf); 2227 free (esl.buf);
2213 } 2228 }
2229
2214 if (sl.len > startlen || socket.sent_scroll) 2230 if (sl.len > startlen || socket.sent_scroll)
2215 { 2231 {
2216 Send_With_Handling (&socket, &sl); 2232 Send_With_Handling (&socket, &sl);
2217 socket.sent_scroll = 0; 2233 socket.sent_scroll = 0;
2218 } 2234 }
2235
2219 free (sl.buf); 2236 free (sl.buf);
2220} 2237}
2221 2238
2222/** 2239/**
2223 * Draws client map. 2240 * Draws client map.
2229 sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ 2246 sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */
2230 New_Face *face, *floor; 2247 New_Face *face, *floor;
2231 New_Face *floor2; 2248 New_Face *floor2;
2232 int d, mflags; 2249 int d, mflags;
2233 struct Map newmap; 2250 struct Map newmap;
2234 mapstruct *m, *pm; 2251 maptile *m, *pm;
2235 2252
2236 if (pl->type != PLAYER) 2253 if (pl->type != PLAYER)
2237 { 2254 {
2238 LOG (llevError, "draw_client_map called with non player/non eric-server\n"); 2255 LOG (llevError, "draw_client_map called with non player/non eric-server\n");
2239 return; 2256 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines