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.18 by root, Thu Sep 14 19:08:41 2006 UTC vs.
Revision 1.27 by root, Wed Dec 13 18:08:02 2006 UTC

1
2/*
3 * static char *rcsid_init_c =
4 * "$Id: request.C,v 1.18 2006/09/14 19:08:41 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.
63#include <commands.h> 57#include <commands.h>
64 58
65/* 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,
66 * it should work here. 60 * it should work here.
67 */ 61 */
68#ifndef WIN32 /* ---win32 exclude unix headers */
69# include <sys/types.h> 62#include <sys/types.h>
70# include <sys/time.h> 63#include <sys/time.h>
71# include <sys/socket.h> 64#include <sys/socket.h>
72# include <netinet/in.h> 65#include <netinet/in.h>
73# include <netdb.h> 66#include <netdb.h>
74#endif /* win32 */
75 67
76#ifdef HAVE_UNISTD_H 68#ifdef HAVE_UNISTD_H
77# include <unistd.h> 69# include <unistd.h>
78#endif 70#endif
79 71
143 for (x = 0; x < mx; x++) 135 for (x = 0; x < mx; x++)
144 { 136 {
145 for (y = 0; y < my; y++) 137 for (y = 0; y < my; y++)
146 { 138 {
147 if (x >= ns->mapx || y >= ns->mapy) 139 if (x >= ns->mapx || y >= ns->mapy)
148 {
149 /* clear cells outside the viewable area */ 140 /* clear cells outside the viewable area */
150 memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); 141 memset (&newmap.cells[x][y], 0, sizeof (struct MapCell));
151 }
152 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)
153 {
154 /* clear newly visible tiles within the viewable area */ 143 /* clear newly visible tiles within the viewable area */
155 memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); 144 memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell));
156 }
157 else 145 else
158 {
159 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));
160 }
161 } 147 }
162 } 148 }
163 149
164 memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); 150 memcpy (&(ns->lastmap), &newmap, sizeof (struct Map));
165 151
264 if (!strncmp (buf, "spatial ", 8)) 250 if (!strncmp (buf, "spatial ", 8))
265 { 251 {
266 buf += 8; 252 buf += 8;
267 253
268 // initial map and its origin 254 // initial map and its origin
269 mapstruct *map = pl->ob->map; 255 maptile *map = pl->ob->map;
270 sint16 dx, dy; 256 sint16 dx, dy;
271 int mapx = pl->socket.mapx / 2 - pl->ob->x; 257 int mapx = pl->socket.mapx / 2 - pl->ob->x;
272 int mapy = pl->socket.mapy / 2 - pl->ob->y; 258 int mapy = pl->socket.mapy / 2 - pl->ob->y;
273 int max_distance = 8; // limit maximum path length to something generous 259 int max_distance = 8; // limit maximum path length to something generous
274 260
718 ns->faces_sent[face] |= NS_FACESENT_SMOOTH; 704 ns->faces_sent[face] |= NS_FACESENT_SMOOTH;
719 705
720 sl.buf = reply; 706 sl.buf = reply;
721 strcpy ((char *) sl.buf, "smooth "); 707 strcpy ((char *) sl.buf, "smooth ");
722 sl.len = strlen ((char *) sl.buf); 708 sl.len = strlen ((char *) sl.buf);
723 SockList_AddShort (&sl, face); 709
724 SockList_AddShort (&sl, smoothface); 710 sl << uint16 (face) << uint16 (smoothface);
711
725 Send_With_Handling (ns, &sl); 712 Send_With_Handling (ns, &sl);
726} 713}
727 714
728 /** 715 /**
729 * Tells client the picture it has to use 716 * Tells client the picture it has to use
854 841
855 /* Send confirmation of command execution now */ 842 /* Send confirmation of command execution now */
856 sl.buf = command; 843 sl.buf = command;
857 strcpy ((char *) sl.buf, "comc "); 844 strcpy ((char *) sl.buf, "comc ");
858 sl.len = 5; 845 sl.len = 5;
859 SockList_AddShort (&sl, packet); 846
860 if (FABS (pl->ob->speed) < 0.001) 847 if (FABS (pl->ob->speed) < 0.001)
861 time = MAX_TIME * 100; 848 time = MAX_TIME * 100;
862 else 849 else
863 time = (int) (MAX_TIME / FABS (pl->ob->speed)); 850 time = (int) (MAX_TIME / FABS (pl->ob->speed));
864 SockList_AddInt (&sl, time); 851
852 sl << uint16 (packet) << uint32 (time);
853
865 Send_With_Handling (&pl->socket, &sl); 854 Send_With_Handling (&pl->socket, &sl);
866} 855}
867 856
868 857
869/** This is a reply to a previous query. */ 858/** This is a reply to a previous query. */
1137 AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); 1126 AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS);
1138 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); 1127 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX);
1139 AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); 1128 AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON);
1140 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); 1129 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA);
1141 } 1130 }
1131
1142 if (pl->socket.exp64) 1132 if (pl->socket.exp64)
1143 { 1133 {
1144 uint8 s; 1134 uint8 s;
1145 1135
1146 for (s = 0; s < NUM_SKILLS; s++) 1136 for (s = 0; s < NUM_SKILLS; s++)
1156 SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); 1146 SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp);
1157 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; 1147 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp;
1158 } 1148 }
1159 } 1149 }
1160 } 1150 }
1151
1161 if (pl->socket.exp64) 1152 if (pl->socket.exp64)
1162 {
1163 AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); 1153 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) }
1164 }
1165 else 1154 else
1166 {
1167 AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP); 1155 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) }
1168 } 1156
1169 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); 1157 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL);
1170 AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); 1158 AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC);
1171 AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); 1159 AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC);
1172 AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); 1160 AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM);
1173 AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); 1161 AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED);
1174 AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); 1162 AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD);
1175 AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); 1163 AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP);
1176 AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); 1164 AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM);
1177 flags = 0; 1165 flags = 0;
1166
1178 if (pl->fire_on) 1167 if (pl->fire_on)
1179 flags |= SF_FIREON; 1168 flags |= SF_FIREON;
1169
1180 if (pl->run_on) 1170 if (pl->run_on)
1181 flags |= SF_RUNON; 1171 flags |= SF_RUNON;
1182 1172
1183 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); 1173 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS);
1174
1184 if (pl->socket.sc_version < 1025) 1175 if (pl->socket.sc_version < 1025)
1185 {
1186 AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); 1176 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) }
1187 }
1188 else 1177 else
1189 { 1178 {
1190 int i; 1179 int i;
1191 1180
1192 for (i = 0; i < NROFATTACKS; i++) 1181 for (i = 0; i < NROFATTACKS; i++)
1193 { 1182 {
1194 /* Skip ones we won't send */ 1183 /* Skip ones we won't send */
1195 if (atnr_cs_stat[i] == -1) 1184 if (atnr_cs_stat[i] == -1)
1196 continue; 1185 continue;
1186
1197 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); 1187 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]);
1198 } 1188 }
1199 } 1189 }
1190
1200 if (pl->socket.monitor_spells) 1191 if (pl->socket.monitor_spells)
1201 { 1192 {
1202 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); 1193 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE);
1203 AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); 1194 AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL);
1204 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); 1195 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY);
1205 } 1196 }
1197
1206 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ 1198 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */
1207 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); 1199 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE);
1208 set_title (pl->ob, buf); 1200 set_title (pl->ob, buf);
1209 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1201 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE);
1210 1202
1214#ifdef ESRV_DEBUG 1206#ifdef ESRV_DEBUG
1215 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); 1207 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len);
1216#endif 1208#endif
1217 Send_With_Handling (&pl->socket, &sl); 1209 Send_With_Handling (&pl->socket, &sl);
1218 } 1210 }
1211
1219 free (sl.buf); 1212 free (sl.buf);
1220} 1213}
1221
1222 1214
1223/** 1215/**
1224 * Tells the client that here is a player it should start using. 1216 * Tells the client that here is a player it should start using.
1225 */ 1217 */
1226void 1218void
1244 1236
1245 Send_With_Handling (&pl->socket, &sl); 1237 Send_With_Handling (&pl->socket, &sl);
1246 free (sl.buf); 1238 free (sl.buf);
1247 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1239 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1248} 1240}
1249
1250 1241
1251/** 1242/**
1252 * Need to send an animation sequence to the client. 1243 * Need to send an animation sequence to the client.
1253 * We will send appropriate face commands to the client if we haven't 1244 * We will send appropriate face commands to the client if we haven't
1254 * sent them the face yet (this can become quite costly in terms of 1245 * sent them the face yet (this can become quite costly in terms of
1464map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) 1455map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count)
1465{ 1456{
1466 cell->faces[0] = face0; 1457 cell->faces[0] = face0;
1467 cell->faces[1] = face1; 1458 cell->faces[1] = face1;
1468 cell->faces[2] = face2; 1459 cell->faces[2] = face2;
1469 cell->count = count; 1460 cell->count = count;
1470 cell->stat_hp = 0; 1461 cell->stat_hp = 0;
1462 cell->flags = 0;
1471 cell->player = 0; 1463 cell->player = 0;
1472} 1464}
1473 1465
1474#define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) 1466#define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y)
1475#define MAX_LAYERS 3 1467#define MAX_LAYERS 3
1476 1468
1547 * the case, it seems to make more sense to have these layer values 1539 * the case, it seems to make more sense to have these layer values
1548 * actually match. 1540 * actually match.
1549 */ 1541 */
1550 1542
1551static int 1543static int
1552update_space (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) 1544update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1553{ 1545{
1554 object *ob, *head; 1546 object *ob, *head;
1555 uint16 face_num; 1547 uint16 face_num;
1556 int bx, by, i; 1548 int bx, by, i;
1557 1549
1771 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1763 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1772 * take. 1764 * take.
1773 */ 1765 */
1774 1766
1775static inline int 1767static inline int
1776update_smooth (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) 1768update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1777{ 1769{
1778 object *ob; 1770 object *ob;
1779 int smoothlevel; /* old face_num; */ 1771 int smoothlevel; /* old face_num; */
1780 1772
1781 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1773 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1859 SockList esl; /*For extended Map info */ 1851 SockList esl; /*For extended Map info */
1860 uint16 mask, emask; 1852 uint16 mask, emask;
1861 uint8 eentrysize; 1853 uint8 eentrysize;
1862 uint16 ewhatstart, ewhatflag; 1854 uint16 ewhatstart, ewhatflag;
1863 uint8 extendedinfos; 1855 uint8 extendedinfos;
1864 mapstruct *m; 1856 maptile *m;
1865 1857
1866 NewSocket & socket = pl->contr->socket; 1858 NewSocket & socket = pl->contr->socket;
1867 1859
1868 check_map_change (pl->contr); 1860 check_map_change (pl->contr);
1869 1861
1872 strcpy ((char *) sl.buf, "map1 "); 1864 strcpy ((char *) sl.buf, "map1 ");
1873 else 1865 else
1874 strcpy ((char *) sl.buf, "map1a "); 1866 strcpy ((char *) sl.buf, "map1a ");
1875 sl.len = strlen ((char *) sl.buf); 1867 sl.len = strlen ((char *) sl.buf);
1876 startlen = sl.len; 1868 startlen = sl.len;
1869
1877 /*Extendedmapinfo structure initialisation */ 1870 /*Extendedmapinfo structure initialisation */
1878 if (socket.ext_mapinfos) 1871 if (socket.ext_mapinfos)
1879 { 1872 {
1880 esl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1873 esl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1881 strcpy ((char *) esl.buf, "mapextended "); 1874 strcpy ((char *) esl.buf, "mapextended ");
1882 esl.len = strlen ((char *) esl.buf); 1875 esl.len = strlen ((char *) esl.buf);
1883 extendedinfos = EMI_NOREDRAW; 1876 extendedinfos = EMI_NOREDRAW;
1877
1884 if (socket.EMI_smooth) 1878 if (socket.EMI_smooth)
1885 extendedinfos |= EMI_SMOOTH; 1879 extendedinfos |= EMI_SMOOTH;
1880
1886 ewhatstart = esl.len; 1881 ewhatstart = esl.len;
1887 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit 1882 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1888 could need to be taken away */ 1883 could need to be taken away */
1889 SockList_AddChar (&esl, extendedinfos); 1884 SockList_AddChar (&esl, extendedinfos);
1890 eentrysize = getExtendedMapInfoSize (&socket); 1885 eentrysize = getExtendedMapInfoSize (&socket);
1896 /* suppress compiler warnings */ 1891 /* suppress compiler warnings */
1897 ewhatstart = 0; 1892 ewhatstart = 0;
1898 ewhatflag = 0; 1893 ewhatflag = 0;
1899 estartlen = 0; 1894 estartlen = 0;
1900 } 1895 }
1896
1901 /* Init data to zero */ 1897 /* Init data to zero */
1902 memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); 1898 memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS);
1903 1899
1904 /* x,y are the real map locations. ax, ay are viewport relative 1900 /* x,y are the real map locations. ax, ay are viewport relative
1905 * locations. 1901 * locations.
1909 /* We could do this logic as conditionals in the if statement, 1905 /* We could do this logic as conditionals in the if statement,
1910 * but that started to get a bit messy to look at. 1906 * but that started to get a bit messy to look at.
1911 */ 1907 */
1912 max_x = pl->x + (socket.mapx + 1) / 2; 1908 max_x = pl->x + (socket.mapx + 1) / 2;
1913 max_y = pl->y + (socket.mapy + 1) / 2; 1909 max_y = pl->y + (socket.mapy + 1) / 2;
1910
1914 if (socket.mapmode == Map1aCmd) 1911 if (socket.mapmode == Map1aCmd)
1915 { 1912 {
1916 max_x += MAX_HEAD_OFFSET; 1913 max_x += MAX_HEAD_OFFSET;
1917 max_y += MAX_HEAD_OFFSET; 1914 max_y += MAX_HEAD_OFFSET;
1918 } 1915 }
1951 * with no faces tells the client to blank out the 1948 * with no faces tells the client to blank out the
1952 * space. 1949 * space.
1953 */ 1950 */
1954 got_one = 0; 1951 got_one = 0;
1955 for (i = oldlen + 2; i < sl.len; i++) 1952 for (i = oldlen + 2; i < sl.len; i++)
1956 {
1957 if (sl.buf[i]) 1953 if (sl.buf[i])
1958 got_one = 1; 1954 got_one = 1;
1959 }
1960 1955
1961 if (got_one && (mask & 0xf)) 1956 if (got_one && (mask & 0xf))
1962 {
1963 sl.buf[oldlen + 1] = mask & 0xff; 1957 sl.buf[oldlen + 1] = mask & 0xff;
1964 }
1965 else 1958 else
1966 { /*either all faces blank, either no face at all */ 1959 { /*either all faces blank, either no face at all */
1967 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ 1960 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1968 sl.len = oldlen + 2; 1961 sl.len = oldlen + 2;
1969 else 1962 else
1970 sl.len = oldlen; 1963 sl.len = oldlen;
1971 } 1964 }
1965
1972 /*What concerns extendinfos, nothing to be done for now 1966 /*What concerns extendinfos, nothing to be done for now
1973 * (perhaps effects layer later) 1967 * (perhaps effects layer later)
1974 */ 1968 */
1975 continue; /* don't do processing below */ 1969 continue; /* don't do processing below */
1976 } 1970 }
1977 1971
1978 MapCell & lastcell = socket.lastmap.cells[ax][ay]; 1972 MapCell &lastcell = socket.lastmap.cells[ax][ay];
1979 1973
1980 d = pl->contr->blocked_los[ax][ay]; 1974 d = pl->contr->blocked_los[ax][ay];
1981 1975
1982 /* If the coordinates are not valid, or it is too dark to see, 1976 /* If the coordinates are not valid, or it is too dark to see,
1983 * we tell the client as such 1977 * we tell the client as such
1984 */ 1978 */
1985 nx = x; 1979 nx = x;
1986 ny = y; 1980 ny = y;
1987 m = get_map_from_coord (pl->map, &nx, &ny); 1981 m = get_map_from_coord (pl->map, &nx, &ny);
1982
1988 if (!m) 1983 if (!m)
1989 { 1984 {
1990 /* space is out of map. Update space and clear values 1985 /* space is out of map. Update space and clear values
1991 * if this hasn't already been done. If the space is out 1986 * if this hasn't already been done. If the space is out
1992 * of the map, it shouldn't have a head 1987 * of the map, it shouldn't have a head
2006 */ 2001 */
2007 2002
2008 oldlen = sl.len; 2003 oldlen = sl.len;
2009 2004
2010 SockList_AddShort (&sl, mask); 2005 SockList_AddShort (&sl, mask);
2006
2011 if (lastcell.count != -1) 2007 if (lastcell.count != -1)
2012 need_send = 1; 2008 need_send = 1;
2009
2013 count = -1; 2010 count = -1;
2014 2011
2015 if (socket.mapmode == Map1aCmd && have_head (ax, ay)) 2012 if (socket.mapmode == Map1aCmd && have_head (ax, ay))
2016 { 2013 {
2017 /* Now check to see if any heads need to be sent */ 2014 /* Now check to see if any heads need to be sent */
2022 mask |= 0x2; 2019 mask |= 0x2;
2023 if (check_head (sl, socket, ax, ay, 0)) 2020 if (check_head (sl, socket, ax, ay, 0))
2024 mask |= 0x1; 2021 mask |= 0x1;
2025 2022
2026 lastcell.count = count; 2023 lastcell.count = count;
2027
2028 } 2024 }
2029 else 2025 else
2030 { 2026 {
2031 struct MapCell *cell = &lastcell;
2032
2033 /* properly clear a previously sent big face */ 2027 /* properly clear a previously sent big face */
2034 if (cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) 2028 if (lastcell.faces[0] != 0 || lastcell.faces[1] != 0 || lastcell.faces[2] != 0
2029 || lastcell.stat_hp || lastcell.flags || lastcell.player)
2035 need_send = 1; 2030 need_send = 1;
2031
2036 map_clearcell (&lastcell, 0, 0, 0, count); 2032 map_clearcell (&lastcell, 0, 0, 0, count);
2037 } 2033 }
2038 2034
2039 if ((mask & 0xf) || need_send) 2035 if ((mask & 0xf) || need_send)
2040 {
2041 sl.buf[oldlen + 1] = mask & 0xff; 2036 sl.buf[oldlen + 1] = mask & 0xff;
2042 }
2043 else 2037 else
2044 {
2045 sl.len = oldlen; 2038 sl.len = oldlen;
2046 }
2047 } 2039 }
2048 else 2040 else
2049 { 2041 {
2050 /* In this block, the space is visible or there are head objects 2042 /* In this block, the space is visible or there are head objects
2051 * we need to send. 2043 * we need to send.
2092 2084
2093 if (socket.extmap) 2085 if (socket.extmap)
2094 { 2086 {
2095 uint8 stat_hp = 0; 2087 uint8 stat_hp = 0;
2096 uint8 stat_width = 0; 2088 uint8 stat_width = 0;
2089 uint8 flags = 0;
2097 tag_t player = 0; 2090 UUID player = 0;
2098 2091
2099 // send hp information, if applicable 2092 // send hp information, if applicable
2100 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) 2093 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0))
2101 { 2094 {
2102 if (op->head || op->invisible) 2095 if (op->head || op->invisible)
2109 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 2102 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
2110 stat_width = op->arch->tail_x; 2103 stat_width = op->arch->tail_x;
2111 } 2104 }
2112 } 2105 }
2113 2106
2107 if (op->msg && op->msg[0] == '@')
2108 flags |= 1;
2109
2114 if (op->type == PLAYER && op != pl) 2110 if (op->type == PLAYER && op != pl)
2115 player = op->count; 2111 player = op->count;
2116 } 2112 }
2117 2113
2118 if (lastcell.stat_hp != stat_hp) 2114 if (lastcell.stat_hp != stat_hp)
2120 lastcell.stat_hp = stat_hp; 2116 lastcell.stat_hp = stat_hp;
2121 2117
2122 mask |= 0x8; 2118 mask |= 0x8;
2123 *last_ext |= 0x80; 2119 *last_ext |= 0x80;
2124 last_ext = sl.buf + sl.len; 2120 last_ext = sl.buf + sl.len;
2125 SockList_AddChar (&sl, 5); 2121
2126 SockList_AddChar (&sl, stat_hp); 2122 sl << uint8 (5) << uint8 (stat_hp);
2127 2123
2128 if (stat_width > 1) 2124 if (stat_width > 1)
2129 { 2125 {
2130 *last_ext |= 0x80; 2126 *last_ext |= 0x80;
2131 last_ext = sl.buf + sl.len; 2127 last_ext = sl.buf + sl.len;
2132 SockList_AddChar (&sl, 6); 2128
2133 SockList_AddChar (&sl, stat_width); 2129 sl << uint8 (6) << uint8 (stat_width);
2134 } 2130 }
2135 } 2131 }
2136 2132
2137 if (lastcell.player !=player) 2133 if (lastcell.player != player)
2138 { 2134 {
2139 lastcell.player = player; 2135 lastcell.player = player;
2140 2136
2141 mask |= 0x8; 2137 mask |= 0x8;
2142 *last_ext |= 0x80; 2138 *last_ext |= 0x80;
2143 last_ext = sl.buf + sl.len; 2139 last_ext = sl.buf + sl.len;
2144 SockList_AddChar (&sl, 0x47); 2140
2145 SockList_AddChar (&sl, 4); 2141 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2146 SockList_AddInt (&sl, player); 2142 }
2143
2144 if (lastcell.flags != flags)
2145 {
2146 lastcell.flags = flags;
2147
2148 mask |= 0x8;
2149 *last_ext |= 0x80;
2150 last_ext = sl.buf + sl.len;
2151
2152 sl << uint8 (8) << uint8 (flags);
2147 } 2153 }
2148 } 2154 }
2149 2155
2150 /* Floor face */ 2156 /* Floor face */
2151 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) 2157 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2))
2167 { 2173 {
2168 if (lastcell.faces[0] != pl->face->number) 2174 if (lastcell.faces[0] != pl->face->number)
2169 { 2175 {
2170 lastcell.faces[0] = pl->face->number; 2176 lastcell.faces[0] = pl->face->number;
2171 mask |= 0x1; 2177 mask |= 0x1;
2178
2172 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) 2179 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE))
2173 esrv_send_face (&socket, pl->face->number, 0); 2180 esrv_send_face (&socket, pl->face->number, 0);
2174 SockList_AddShort (&sl, pl->face->number); 2181
2182 sl << uint16 (pl->face->number);
2175 } 2183 }
2176 } 2184 }
2177 /* Top face */
2178 else 2185 else
2179 { 2186 {
2187 /* Top face */
2180 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) 2188 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0))
2181 mask |= 0x1; 2189 mask |= 0x1;
2190
2182 if (socket.EMI_smooth) 2191 if (socket.EMI_smooth)
2183 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) 2192 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0))
2184 {
2185 emask |= 0x1; 2193 emask |= 0x1;
2186 }
2187 } 2194 }
2195
2188 /* Check to see if we are in fact sending anything for this 2196 /* Check to see if we are in fact sending anything for this
2189 * space by checking the mask. If so, update the mask. 2197 * space by checking the mask. If so, update the mask.
2190 * if not, reset the len to that from before adding the mask 2198 * if not, reset the len to that from before adding the mask
2191 * value, so we don't send those bits. 2199 * value, so we don't send those bits.
2192 */ 2200 */
2193 if (mask & 0xf) 2201 if (mask & 0xf)
2194 {
2195 sl.buf[oldlen + 1] = mask & 0xff; 2202 sl.buf[oldlen + 1] = mask & 0xff;
2196 }
2197 else 2203 else
2198 {
2199 sl.len = oldlen; 2204 sl.len = oldlen;
2200 } 2205
2201 if (emask & 0xf) 2206 if (emask & 0xf)
2202 {
2203 esl.buf[eoldlen + 1] = emask & 0xff; 2207 esl.buf[eoldlen + 1] = emask & 0xff;
2204 }
2205 else 2208 else
2206 {
2207 esl.len = eoldlen; 2209 esl.len = eoldlen;
2208 }
2209 } /* else this is a viewable space */ 2210 } /* else this is a viewable space */
2210 } /* for x loop */ 2211 } /* for x loop */
2211 } /* for y loop */ 2212 } /* for y loop */
2212 2213
2213 /* Verify that we in fact do need to send this */ 2214 /* Verify that we in fact do need to send this */
2247 sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ 2248 sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */
2248 New_Face *face, *floor; 2249 New_Face *face, *floor;
2249 New_Face *floor2; 2250 New_Face *floor2;
2250 int d, mflags; 2251 int d, mflags;
2251 struct Map newmap; 2252 struct Map newmap;
2252 mapstruct *m, *pm; 2253 maptile *m, *pm;
2253 2254
2254 if (pl->type != PLAYER) 2255 if (pl->type != PLAYER)
2255 { 2256 {
2256 LOG (llevError, "draw_client_map called with non player/non eric-server\n"); 2257 LOG (llevError, "draw_client_map called with non player/non eric-server\n");
2257 return; 2258 return;
2465 if (flags != 0) 2466 if (flags != 0)
2466 { 2467 {
2467 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2468 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2468 strcpy ((char *) sl.buf, "updspell "); 2469 strcpy ((char *) sl.buf, "updspell ");
2469 sl.len = strlen ((char *) sl.buf); 2470 sl.len = strlen ((char *) sl.buf);
2470 SockList_AddChar (&sl, flags); 2471
2471 SockList_AddInt (&sl, spell->count); 2472 sl << uint8 (flags) << uint32 (spell->count);
2472 if (flags & UPD_SP_MANA) 2473
2473 SockList_AddShort (&sl, spell->last_sp); 2474 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2474 if (flags & UPD_SP_GRACE) 2475 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2475 SockList_AddShort (&sl, spell->last_grace); 2476 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2476 if (flags & UPD_SP_DAMAGE) 2477
2477 SockList_AddShort (&sl, spell->last_eat);
2478 flags = 0; 2478 flags = 0;
2479 Send_With_Handling (&pl->socket, &sl); 2479 Send_With_Handling (&pl->socket, &sl);
2480 free (sl.buf); 2480 free (sl.buf);
2481 } 2481 }
2482 } 2482 }
2496 return; 2496 return;
2497 } 2497 }
2498 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2498 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2499 strcpy ((char *) sl.buf, "delspell "); 2499 strcpy ((char *) sl.buf, "delspell ");
2500 sl.len = strlen ((char *) sl.buf); 2500 sl.len = strlen ((char *) sl.buf);
2501 SockList_AddInt (&sl, spell->count); 2501
2502 sl << uint32 (spell->count);
2503
2502 Send_With_Handling (&pl->socket, &sl); 2504 Send_With_Handling (&pl->socket, &sl);
2503 free (sl.buf); 2505 free (sl.buf);
2504} 2506}
2505 2507
2506/* appends the spell *spell to the Socklist we will send the data to. */ 2508/* appends the spell *spell to the Socklist we will send the data to. */
2507static void 2509static void
2508append_spell (player *pl, SockList * sl, object *spell) 2510append_spell (player *pl, SockList &sl, object *spell)
2509{ 2511{
2510 int len, i, skill = 0; 2512 int len, i, skill = 0;
2511 2513
2512 if (!(spell->name)) 2514 if (!(spell->name))
2513 { 2515 {
2514 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 2516 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
2515 return; 2517 return;
2516 } 2518 }
2517 SockList_AddInt (sl, spell->count); 2519
2518 SockList_AddShort (sl, spell->level);
2519 SockList_AddShort (sl, spell->casting_time);
2520 /* store costs and damage in the object struct, to compare to later */ 2520 /* store costs and damage in the object struct, to compare to later */
2521 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 2521 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
2522 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 2522 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
2523 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 2523 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
2524 /* send the current values */
2525 SockList_AddShort (sl, spell->last_sp);
2526 SockList_AddShort (sl, spell->last_grace);
2527 SockList_AddShort (sl, spell->last_eat);
2528 2524
2529 /* figure out which skill it uses, if it uses one */ 2525 /* figure out which skill it uses, if it uses one */
2530 if (spell->skill) 2526 if (spell->skill)
2531 { 2527 {
2532 for (i = 1; i < NUM_SKILLS; i++) 2528 for (i = 1; i < NUM_SKILLS; i++)
2534 { 2530 {
2535 skill = i + CS_STAT_SKILLINFO; 2531 skill = i + CS_STAT_SKILLINFO;
2536 break; 2532 break;
2537 } 2533 }
2538 } 2534 }
2539 SockList_AddChar (sl, skill);
2540 2535
2541 SockList_AddInt (sl, spell->path_attuned); 2536 /* send the current values */
2537 sl << uint32 (spell->count)
2538 << uint16 (spell->level)
2539 << uint16 (spell->casting_time)
2540 << uint16 (spell->last_sp)
2541 << uint16 (spell->last_grace)
2542 << uint16 (spell->last_eat)
2543 << uint8 (skill)
2544 << uint32 (spell->path_attuned)
2542 SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); 2545 << uint32 (spell->face ? spell->face->number : 0)
2543 2546 << data8 (spell->name)
2544 len = strlen (spell->name); 2547 << data16 (spell->msg);
2545 SockList_AddChar (sl, (char) len);
2546 memcpy (sl->buf + sl->len, spell->name, len);
2547 sl->len += len;
2548
2549 if (!spell->msg)
2550 {
2551 SockList_AddShort (sl, 0);
2552 }
2553 else
2554 {
2555 len = strlen (spell->msg);
2556 SockList_AddShort (sl, len);
2557 memcpy (sl->buf + sl->len, spell->msg, len);
2558 sl->len += len;
2559 }
2560} 2548}
2561 2549
2562/** 2550/**
2563 * This tells the client to add the spell *ob, if *ob is NULL, then add 2551 * This tells the client to add the spell *ob, if *ob is NULL, then add
2564 * all spells in the player's inventory. 2552 * all spells in the player's inventory.
2595 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem 2583 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem
2596 * like it will fix this 2584 * like it will fix this
2597 */ 2585 */
2598 if (spell->type != SPELL) 2586 if (spell->type != SPELL)
2599 continue; 2587 continue;
2588
2600 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2589 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2601 { 2590 {
2602 Send_With_Handling (&pl->socket, &sl); 2591 Send_With_Handling (&pl->socket, &sl);
2603 strcpy ((char *) sl.buf, "addspell "); 2592 strcpy ((char *) sl.buf, "addspell ");
2604 sl.len = strlen ((char *) sl.buf); 2593 sl.len = strlen ((char *) sl.buf);
2605 } 2594 }
2595
2606 append_spell (pl, &sl, spell); 2596 append_spell (pl, sl, spell);
2607 } 2597 }
2608 } 2598 }
2609 else if (spell->type != SPELL) 2599 else if (spell->type != SPELL)
2610 { 2600 {
2611 LOG (llevError, "Asked to send a non-spell object as a spell"); 2601 LOG (llevError, "Asked to send a non-spell object as a spell");
2612 return; 2602 return;
2613 } 2603 }
2614 else 2604 else
2615 append_spell (pl, &sl, spell); 2605 append_spell (pl, sl, spell);
2606
2616 if (sl.len >= MAXSOCKBUF) 2607 if (sl.len >= MAXSOCKBUF)
2617 { 2608 {
2618 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2609 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2619 fatal (0); 2610 fatal (0);
2620 } 2611 }
2612
2621 /* finally, we can send the packet */ 2613 /* finally, we can send the packet */
2622 Send_With_Handling (&pl->socket, &sl); 2614 Send_With_Handling (&pl->socket, &sl);
2623 free (sl.buf); 2615 free (sl.buf);
2624} 2616}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines