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.36 by root, Thu Dec 14 04:30:33 2006 UTC vs.
Revision 1.41 by root, Fri Dec 15 19:59:20 2006 UTC

46 */ 46 */
47 47
48#include <global.h> 48#include <global.h>
49#include <sproto.h> 49#include <sproto.h>
50 50
51#include <newclient.h>
52#include <newserver.h>
53#include <living.h> 51#include <living.h>
54#include <commands.h> 52#include <commands.h>
55 53
56/* This block is basically taken from socket.c - I assume if it works there, 54/* This block is basically taken from socket.c - I assume if it works there,
57 * it should work here. 55 * it should work here.
60#include <sys/time.h> 58#include <sys/time.h>
61#include <sys/socket.h> 59#include <sys/socket.h>
62#include <netinet/in.h> 60#include <netinet/in.h>
63#include <netdb.h> 61#include <netdb.h>
64 62
65#ifdef HAVE_UNISTD_H
66# include <unistd.h> 63#include <unistd.h>
67#endif
68
69#ifdef HAVE_SYS_TIME_H
70# include <sys/time.h> 64#include <sys/time.h>
71#endif
72 65
73#include "sounds.h" 66#include "sounds.h"
74 67
75/** 68/**
76 * This table translates the attack numbers as used within the 69 * This table translates the attack numbers as used within the
93 -1, /* life stealing */ 86 -1, /* life stealing */
94 -1 /* Disease - not fully done yet */ 87 -1 /* Disease - not fully done yet */
95}; 88};
96 89
97static void 90static void
98socket_map_scroll (client_socket * ns, int dx, int dy) 91socket_map_scroll (client * ns, int dx, int dy)
99{ 92{
100 struct Map newmap; 93 struct Map newmap;
101 int x, y, mx, my; 94 int x, y, mx, my;
102 95
103 { 96 {
153} 146}
154 147
155static void 148static void
156clear_map (player *pl) 149clear_map (player *pl)
157{ 150{
158 client_socket &socket = *pl->socket; 151 client &socket = *pl->socket;
159 152
160 memset (&socket.lastmap, 0, sizeof (socket.lastmap)); 153 memset (&socket.lastmap, 0, sizeof (socket.lastmap));
161 154
162 if (socket.newmapcmd == 1) 155 if (socket.newmapcmd == 1)
163 socket.send_packet ("newmap"); 156 socket.send_packet ("newmap");
168 161
169/** check for map change and send new map data */ 162/** check for map change and send new map data */
170static void 163static void
171check_map_change (player *pl) 164check_map_change (player *pl)
172{ 165{
173 client_socket &socket = *pl->socket; 166 client &socket = *pl->socket;
174 object *ob = pl->ob; 167 object *ob = pl->ob;
175 char buf[MAX_BUF]; /* eauugggh */ 168 char buf[MAX_BUF]; /* eauugggh */
176 169
177 if (socket.current_map != ob->map) 170 if (socket.current_map != ob->map)
178 { 171 {
219 } 212 }
220 } 213 }
221 214
222 socket.current_x = ob->x; 215 socket.current_x = ob->x;
223 socket.current_y = ob->y; 216 socket.current_y = ob->y;
217}
218
219/**
220 * RequestInfo is sort of a meta command. There is some specific
221 * request of information, but we call other functions to provide
222 * that information.
223 */
224void
225RequestInfo (char *buf, int len, client * ns)
226{
227 char *params = NULL, *cp;
228
229 /* No match */
230 char bigbuf[MAX_BUF];
231 int slen;
232
233 /* Set up replyinfo before we modify any of the buffers - this is used
234 * if we don't find a match.
235 */
236 strcpy (bigbuf, "replyinfo ");
237 slen = strlen (bigbuf);
238 safe_strcat (bigbuf, buf, &slen, MAX_BUF);
239
240 /* find the first space, make it null, and update the
241 * params pointer.
242 */
243 for (cp = buf; *cp != '\0'; cp++)
244 if (*cp == ' ')
245 {
246 *cp = '\0';
247 params = cp + 1;
248 break;
249 }
250
251 if (!strcmp (buf, "image_info"))
252 send_image_info (ns, params);
253 else if (!strcmp (buf, "image_sums"))
254 send_image_sums (ns, params);
255 else if (!strcmp (buf, "skill_info"))
256 send_skill_info (ns, params);
257 else if (!strcmp (buf, "spell_paths"))
258 send_spell_paths (ns, params);
259 else
260 ns->send_packet (bigbuf, len);
224} 261}
225 262
226void 263void
227ExtCmd (char *buf, int len, player *pl) 264ExtCmd (char *buf, int len, player *pl)
228{ 265{
316 pl->socket->send_packet (bigbuf); 353 pl->socket->send_packet (bigbuf);
317} 354}
318 355
319/** This is the Setup cmd - easy first implementation */ 356/** This is the Setup cmd - easy first implementation */
320void 357void
321SetUp (char *buf, int len, client_socket * ns) 358SetUp (char *buf, int len, client * ns)
322{ 359{
323 int s, slen; 360 int s, slen;
324 char *cmd, *param, cmdback[HUGE_BUF]; 361 char *cmd, *param, cmdback[HUGE_BUF];
325 362
326 /* run through the cmds of setup 363 /* run through the cmds of setup
536 * This is what takes care of it. We tell the client how things worked out. 573 * This is what takes care of it. We tell the client how things worked out.
537 * I am not sure if this file is the best place for this function. however, 574 * I am not sure if this file is the best place for this function. however,
538 * it either has to be here or init_sockets needs to be exported. 575 * it either has to be here or init_sockets needs to be exported.
539 */ 576 */
540void 577void
541AddMeCmd (char *buf, int len, client_socket * ns) 578AddMeCmd (char *buf, int len, client * ns)
542{ 579{
543 Settings oldsettings; 580 Settings oldsettings;
544 581
545 oldsettings = settings; 582 oldsettings = settings;
546 if (ns->status != Ns_Add || add_player (ns)) 583 if (ns->status != Ns_Add || add_player (ns))
551 settings = oldsettings; 588 settings = oldsettings;
552} 589}
553 590
554/** Reply to ExtendedInfos command */ 591/** Reply to ExtendedInfos command */
555void 592void
556ToggleExtendedInfos (char *buf, int len, client_socket * ns) 593ToggleExtendedInfos (char *buf, int len, client * ns)
557{ 594{
558 char cmdback[MAX_BUF]; 595 char cmdback[MAX_BUF];
559 char command[50]; 596 char command[50];
560 int info, nextinfo; 597 int info, nextinfo;
561 598
612#define MSG_TYPE_MONUMENT 5 649#define MSG_TYPE_MONUMENT 5
613#define MSG_TYPE_SCRIPTED_DIALOG 6*/ 650#define MSG_TYPE_SCRIPTED_DIALOG 6*/
614 651
615/** Reply to ExtendedInfos command */ 652/** Reply to ExtendedInfos command */
616void 653void
617ToggleExtendedText (char *buf, int len, client_socket * ns) 654ToggleExtendedText (char *buf, int len, client * ns)
618{ 655{
619 char cmdback[MAX_BUF]; 656 char cmdback[MAX_BUF];
620 char temp[10]; 657 char temp[10];
621 char command[50]; 658 char command[50];
622 int info, nextinfo, i, flag; 659 int info, nextinfo, i, flag;
673 * a piece of data from us that we know the client wants. So 710 * a piece of data from us that we know the client wants. So
674 * if we know the client wants it, might as well push it to the 711 * if we know the client wants it, might as well push it to the
675 * client. 712 * client.
676 */ 713 */
677static void 714static void
678SendSmooth (client_socket * ns, uint16 face) 715SendSmooth (client * ns, uint16 face)
679{ 716{
680 uint16 smoothface; 717 uint16 smoothface;
681 718
682 /* If we can't find a face, return and set it so we won't try to send this 719 /* If we can't find a face, return and set it so we won't try to send this
683 * again. 720 * again.
699 736
700 sl << "smooth " 737 sl << "smooth "
701 << uint16 (face) 738 << uint16 (face)
702 << uint16 (smoothface); 739 << uint16 (smoothface);
703 740
704 Send_With_Handling (ns, &sl); 741 ns->send_packet (sl);
705} 742}
706 743
707 /** 744 /**
708 * Tells client the picture it has to use 745 * Tells client the picture it has to use
709 * to smooth a picture number given as argument. 746 * to smooth a picture number given as argument.
710 */ 747 */
711void 748void
712AskSmooth (char *buf, int len, client_socket * ns) 749AskSmooth (char *buf, int len, client * ns)
713{ 750{
714 uint16 facenbr; 751 uint16 facenbr;
715 752
716 facenbr = atoi (buf); 753 facenbr = atoi (buf);
717 SendSmooth (ns, facenbr); 754 SendSmooth (ns, facenbr);
774 * etc.). It is a lot like PlayerCmd above, but is called with the 811 * etc.). It is a lot like PlayerCmd above, but is called with the
775 * 'ncom' method which gives more information back to the client so it 812 * 'ncom' method which gives more information back to the client so it
776 * can throttle. 813 * can throttle.
777 */ 814 */
778void 815void
779NewPlayerCmd (uint8 * buf, int len, player *pl) 816NewPlayerCmd (char *buf, int len, player *pl)
780{ 817{
781 int time, repeat; 818 int time, repeat;
782 char command[MAX_BUF]; 819 char command[MAX_BUF];
783 int pktlen; 820 int pktlen;
784 821
786 { 823 {
787 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 824 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf);
788 return; 825 return;
789 } 826 }
790 827
791 pktlen = net_uint16 (buf); 828 pktlen = net_uint16 ((uint8 *)buf);
792 repeat = net_uint32 (buf + 2); 829 repeat = net_uint32 ((uint8 *)buf + 2);
793 830
794 /* -1 is special - no repeat, but don't update */ 831 /* -1 is special - no repeat, but don't update */
795 if (repeat != -1) 832 if (repeat != -1)
796 pl->count = repeat; 833 pl->count = repeat;
797 834
798 if ((len - 4) >= MAX_BUF) 835 if ((len - 4) >= MAX_BUF)
799 len = MAX_BUF - 5; 836 len = MAX_BUF - 5;
800 837
801 strncpy ((char *) command, (char *) buf + 6, len - 4); 838 strncpy ((char *) command, (char *) buf + 6, len - 4);
802 command[len - 4] = '\0'; 839 command[len - 4] = 0;
803
804 /* The following should never happen with a proper or honest client.
805 * Therefore, the error message doesn't have to be too clear - if
806 * someone is playing with a hacked/non working client, this gives them
807 * an idea of the problem, but they deserve what they get
808 */
809 if (pl->state != ST_PLAYING)
810 {
811 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "You can not issue commands - state is not ST_PLAYING (%s)", buf);
812 return;
813 }
814 840
815 /* This should not happen anymore. */ 841 /* This should not happen anymore. */
816 if (pl->ob->speed_left < -1.0) 842 if (pl->ob->speed_left < -1.0)
817 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 843 LOG (llevError, "Player has negative time - shouldn't do command.\n");
818 844
832 858
833 /* Send confirmation of command execution now */ 859 /* Send confirmation of command execution now */
834 860
835 packet sl; 861 packet sl;
836 sl << "comc " << uint16 (pktlen) << uint32 (time); 862 sl << "comc " << uint16 (pktlen) << uint32 (time);
837 Send_With_Handling (pl->socket, &sl); 863 pl->socket->send_packet (sl);
838} 864}
839 865
840 866
841/** This is a reply to a previous query. */ 867/** This is a reply to a previous query. */
842void 868void
909 * something older than the server. If we assume the client will be 935 * something older than the server. If we assume the client will be
910 * backwards compatible, having it be a later version should not be a 936 * backwards compatible, having it be a later version should not be a
911 * problem. 937 * problem.
912 */ 938 */
913void 939void
914VersionCmd (char *buf, int len, client_socket * ns) 940VersionCmd (char *buf, int len, client * ns)
915{ 941{
916 char *cp; 942 char *cp;
917 char version_warning[256]; 943 char version_warning[256];
918 944
919 if (!buf) 945 if (!buf)
943 cp = strchr (cp + 1, ' '); 969 cp = strchr (cp + 1, ' ');
944 if (cp) 970 if (cp)
945 { 971 {
946 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); 972 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host);
947 973
948 snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); 974 assign (ns->version, cp + 1);
949 975
950 /* This is first implementation - i skip all beta DX clients with it
951 * Add later stuff here for other clients
952 */
953
954 /* these are old dxclients */
955 /* Version 1024 added support for singular + plural name values -
956 * requiing this minimal value reduces complexity of that code, and it
957 * has been around for a long time.
958 */
959 if (ns->sc_version < 1026) 976 if (ns->sc_version < 1026)
960 { 977 {
961 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 978 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
962 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 979 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
963 ns->send_packet (version_warning); 980 ns->send_packet (version_warning);
965 982
966 } 983 }
967} 984}
968 985
969/** sound related functions. */ 986/** sound related functions. */
970
971void 987void
972SetSound (char *buf, int len, client_socket * ns) 988SetSound (char *buf, int len, client * ns)
973{ 989{
974 ns->sound = atoi (buf); 990 ns->sound = atoi (buf);
975} 991}
976 992
977/** client wants the map resent */ 993/** client wants the map resent */
1035/** 1051/**
1036 * Asks the client to query the user. This way, the client knows 1052 * Asks the client to query the user. This way, the client knows
1037 * it needs to send something back (vs just printing out a message) 1053 * it needs to send something back (vs just printing out a message)
1038 */ 1054 */
1039void 1055void
1040send_query (client_socket * ns, uint8 flags, char *text) 1056send_query (client * ns, uint8 flags, char *text)
1041{ 1057{
1042 char buf[MAX_BUF]; 1058 char buf[MAX_BUF];
1043 1059
1044 sprintf (buf, "query %d %s", flags, text ? text : ""); 1060 sprintf (buf, "query %d %s", flags, text ? text : "");
1045 ns->send_packet (buf); 1061 ns->send_packet (buf);
1173 set_title (pl->ob, buf); 1189 set_title (pl->ob, buf);
1174 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); 1190 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE);
1175 1191
1176 /* Only send it away if we have some actual data */ 1192 /* Only send it away if we have some actual data */
1177 if (sl.length () > 6) 1193 if (sl.length () > 6)
1178 Send_With_Handling (pl->socket, &sl); 1194 pl->socket->send_packet (sl);
1179} 1195}
1180 1196
1181/** 1197/**
1182 * Tells the client that here is a player it should start using. 1198 * Tells the client that here is a player it should start using.
1183 */ 1199 */
1192 sl << uint32 (pl->ob->count) 1208 sl << uint32 (pl->ob->count)
1193 << uint32 (weight) 1209 << uint32 (weight)
1194 << uint32 (pl->ob->face->number) 1210 << uint32 (pl->ob->face->number)
1195 << data8 (pl->ob->name); 1211 << data8 (pl->ob->name);
1196 1212
1197 Send_With_Handling (pl->socket, &sl); 1213 pl->socket->send_packet (sl);
1198 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1214 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1199} 1215}
1200 1216
1201/** 1217/**
1202 * Need to send an animation sequence to the client. 1218 * Need to send an animation sequence to the client.
1204 * sent them the face yet (this can become quite costly in terms of 1220 * sent them the face yet (this can become quite costly in terms of
1205 * how much we are sending - on the other hand, this should only happen 1221 * how much we are sending - on the other hand, this should only happen
1206 * when the player logs in and picks stuff up. 1222 * when the player logs in and picks stuff up.
1207 */ 1223 */
1208void 1224void
1209esrv_send_animation (client_socket * ns, short anim_num) 1225esrv_send_animation (client * ns, short anim_num)
1210{ 1226{
1211 int i; 1227 int i;
1212 1228
1213 /* Do some checking on the anim_num we got. Note that the animations 1229 /* Do some checking on the anim_num we got. Note that the animations
1214 * are added in contigous order, so if the number is in the valid 1230 * are added in contigous order, so if the number is in the valid
1234 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) 1250 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE))
1235 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1251 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1236 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 1252 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1237 } 1253 }
1238 1254
1239 Send_With_Handling (ns, &sl); 1255 ns->send_packet (sl);
1240 1256
1241 ns->anims_sent[anim_num] = 1; 1257 ns->anims_sent[anim_num] = 1;
1242} 1258}
1243 1259
1244 1260
1251/** 1267/**
1252 * This adds face_num to a map cell at x,y. If the client doesn't have 1268 * This adds face_num to a map cell at x,y. If the client doesn't have
1253 * the face yet, we will also send it. 1269 * the face yet, we will also send it.
1254 */ 1270 */
1255static void 1271static void
1256esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap) 1272esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap)
1257{ 1273{
1258 if (newmap->cells[x][y].count >= MAP_LAYERS) 1274 if (newmap->cells[x][y].count >= MAP_LAYERS)
1259 { 1275 {
1260 LOG (llevError, "Too many faces in map cell %d %d\n", x, y); 1276 LOG (llevError, "Too many faces in map cell %d %d\n", x, y);
1261 return; 1277 return;
1281 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; 1297 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y];
1282}; 1298};
1283 1299
1284/** Checkes if map cells have changed */ 1300/** Checkes if map cells have changed */
1285static int 1301static int
1286mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap) 1302mapcellchanged (client * ns, int i, int j, struct Map *newmap)
1287{ 1303{
1288 int k; 1304 int k;
1289 1305
1290 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) 1306 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count)
1291 return 1; 1307 return 1;
1304 * cnum is the client number, cur is the the buffer we put all of 1320 * cnum is the client number, cur is the the buffer we put all of
1305 * this data into. we return the end of the data. layers is 1321 * this data into. we return the end of the data. layers is
1306 * how many layers of data we should back. 1322 * how many layers of data we should back.
1307 */ 1323 */
1308static uint8 * 1324static uint8 *
1309compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap) 1325compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap)
1310{ 1326{
1311 int x, y, k; 1327 int x, y, k;
1312 int face; 1328 int face;
1313 unsigned char *fcur; 1329 unsigned char *fcur;
1314 struct MapLayer layers[MAP_LAYERS]; 1330 struct MapLayer layers[MAP_LAYERS];
1422 * needs to get sent - if so, it adds the data, sending the head 1438 * needs to get sent - if so, it adds the data, sending the head
1423 * if needed, and returning 1. If this no data needs to get 1439 * if needed, and returning 1. If this no data needs to get
1424 * sent, it returns zero. 1440 * sent, it returns zero.
1425 */ 1441 */
1426static int 1442static int
1427check_head (packet &sl, client_socket &ns, int ax, int ay, int layer) 1443check_head (packet &sl, client &ns, int ax, int ay, int layer)
1428{ 1444{
1429 short face_num; 1445 short face_num;
1430 1446
1431 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1447 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1432 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1448 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number;
1466 * the case, it seems to make more sense to have these layer values 1482 * the case, it seems to make more sense to have these layer values
1467 * actually match. 1483 * actually match.
1468 */ 1484 */
1469 1485
1470static int 1486static int
1471update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1487update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1472{ 1488{
1473 object *ob, *head; 1489 object *ob, *head;
1474 uint16 face_num; 1490 uint16 face_num;
1475 int bx, by, i; 1491 int bx, by, i;
1476 1492
1689 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1705 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1690 * take. 1706 * take.
1691 */ 1707 */
1692 1708
1693static inline int 1709static inline int
1694update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1710update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1695{ 1711{
1696 object *ob; 1712 object *ob;
1697 int smoothlevel; /* old face_num; */ 1713 int smoothlevel; /* old face_num; */
1698 1714
1699 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1715 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1733 * Returns the size of a data for a map square as returned by 1749 * Returns the size of a data for a map square as returned by
1734 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries 1750 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
1735 * available. 1751 * available.
1736 */ 1752 */
1737int 1753int
1738getExtendedMapInfoSize (client_socket * ns) 1754getExtendedMapInfoSize (client * ns)
1739{ 1755{
1740 int result = 0; 1756 int result = 0;
1741 1757
1742 if (ns->ext_mapinfos) 1758 if (ns->ext_mapinfos)
1743 { 1759 {
1779 uint8 eentrysize; 1795 uint8 eentrysize;
1780 uint16 ewhatstart, ewhatflag; 1796 uint16 ewhatstart, ewhatflag;
1781 uint8 extendedinfos; 1797 uint8 extendedinfos;
1782 maptile *m; 1798 maptile *m;
1783 1799
1784 client_socket &socket = *pl->contr->socket; 1800 client &socket = *pl->contr->socket;
1785 1801
1786 check_map_change (pl->contr); 1802 check_map_change (pl->contr);
1787 1803
1788 packet sl; 1804 packet sl;
1789 packet esl; 1805 packet esl;
1868 * with no faces tells the client to blank out the 1884 * with no faces tells the client to blank out the
1869 * space. 1885 * space.
1870 */ 1886 */
1871 got_one = 0; 1887 got_one = 0;
1872 for (i = oldlen + 2; i < sl.length (); i++) 1888 for (i = oldlen + 2; i < sl.length (); i++)
1873 if (sl.buf[i]) 1889 if (sl[i])
1874 got_one = 1; 1890 got_one = 1;
1875 1891
1876 if (got_one && (mask & 0xf)) 1892 if (got_one && (mask & 0xf))
1877 sl.buf[oldlen + 1] = mask & 0xff; 1893 sl[oldlen + 1] = mask & 0xff;
1878 else 1894 else
1879 { /*either all faces blank, either no face at all */ 1895 { /*either all faces blank, either no face at all */
1880 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ 1896 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1881 sl.reset (oldlen + 2); 1897 sl.reset (oldlen + 2);
1882 else 1898 else
1948 1964
1949 map_clearcell (&lastcell, 0, 0, 0, count); 1965 map_clearcell (&lastcell, 0, 0, 0, count);
1950 } 1966 }
1951 1967
1952 if ((mask & 0xf) || need_send) 1968 if ((mask & 0xf) || need_send)
1953 sl.buf[oldlen + 1] = mask & 0xff; 1969 sl[oldlen + 1] = mask & 0xff;
1954 else 1970 else
1955 sl.reset (oldlen); 1971 sl.reset (oldlen);
1956 } 1972 }
1957 else 1973 else
1958 { 1974 {
1988 mask |= 0x8; 2004 mask |= 0x8;
1989 2005
1990 if (socket.extmap) 2006 if (socket.extmap)
1991 { 2007 {
1992 *last_ext |= 0x80; 2008 *last_ext |= 0x80;
1993 last_ext = sl.buf + sl.length (); 2009 last_ext = &sl[sl.length ()];
1994 sl << uint8 (d); 2010 sl << uint8 (d);
1995 } 2011 }
1996 else 2012 else
1997 sl << uint8 (255 - 64 * d); 2013 sl << uint8 (255 - 64 * d);
1998 } 2014 }
2032 { 2048 {
2033 lastcell.stat_hp = stat_hp; 2049 lastcell.stat_hp = stat_hp;
2034 2050
2035 mask |= 0x8; 2051 mask |= 0x8;
2036 *last_ext |= 0x80; 2052 *last_ext |= 0x80;
2037 last_ext = sl.buf + sl.length (); 2053 last_ext = &sl[sl.length ()];
2038 2054
2039 sl << uint8 (5) << uint8 (stat_hp); 2055 sl << uint8 (5) << uint8 (stat_hp);
2040 2056
2041 if (stat_width > 1) 2057 if (stat_width > 1)
2042 { 2058 {
2043 *last_ext |= 0x80; 2059 *last_ext |= 0x80;
2044 last_ext = sl.buf + sl.length (); 2060 last_ext = &sl[sl.length ()];
2045 2061
2046 sl << uint8 (6) << uint8 (stat_width); 2062 sl << uint8 (6) << uint8 (stat_width);
2047 } 2063 }
2048 } 2064 }
2049 2065
2051 { 2067 {
2052 lastcell.player = player; 2068 lastcell.player = player;
2053 2069
2054 mask |= 0x8; 2070 mask |= 0x8;
2055 *last_ext |= 0x80; 2071 *last_ext |= 0x80;
2056 last_ext = sl.buf + sl.length (); 2072 last_ext = &sl[sl.length ()];
2057 2073
2058 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2074 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2059 } 2075 }
2060 2076
2061 if (lastcell.flags != flags) 2077 if (lastcell.flags != flags)
2062 { 2078 {
2063 lastcell.flags = flags; 2079 lastcell.flags = flags;
2064 2080
2065 mask |= 0x8; 2081 mask |= 0x8;
2066 *last_ext |= 0x80; 2082 *last_ext |= 0x80;
2067 last_ext = sl.buf + sl.length (); 2083 last_ext = &sl[sl.length ()];
2068 2084
2069 sl << uint8 (8) << uint8 (flags); 2085 sl << uint8 (8) << uint8 (flags);
2070 } 2086 }
2071 } 2087 }
2072 2088
2114 * space by checking the mask. If so, update the mask. 2130 * space by checking the mask. If so, update the mask.
2115 * if not, reset the len to that from before adding the mask 2131 * if not, reset the len to that from before adding the mask
2116 * value, so we don't send those bits. 2132 * value, so we don't send those bits.
2117 */ 2133 */
2118 if (mask & 0xf) 2134 if (mask & 0xf)
2119 sl.buf[oldlen + 1] = mask & 0xff; 2135 sl[oldlen + 1] = mask & 0xff;
2120 else 2136 else
2121 sl.reset (oldlen); 2137 sl.reset (oldlen);
2122 2138
2123 if (emask & 0xf) 2139 if (emask & 0xf)
2124 esl.buf[eoldlen + 1] = emask & 0xff; 2140 esl[eoldlen + 1] = emask & 0xff;
2125 else 2141 else
2126 esl.reset (eoldlen); 2142 esl.reset (eoldlen);
2127 } /* else this is a viewable space */ 2143 } /* else this is a viewable space */
2128 } /* for x loop */ 2144 } /* for x loop */
2129 } /* for y loop */ 2145 } /* for y loop */
2135 { 2151 {
2136 /* No map data will follow, so don't say the client 2152 /* No map data will follow, so don't say the client
2137 * it doesn't need draw! 2153 * it doesn't need draw!
2138 */ 2154 */
2139 ewhatflag &= (~EMI_NOREDRAW); 2155 ewhatflag &= (~EMI_NOREDRAW);
2140 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2156 esl[ewhatstart + 1] = ewhatflag & 0xff;
2141 } 2157 }
2142 2158
2143 if (esl.length () > estartlen) 2159 if (esl.length () > estartlen)
2144 Send_With_Handling (&socket, &esl); 2160 socket.send_packet (esl);
2145 } 2161 }
2146 2162
2147 if (sl.length () > startlen || socket.sent_scroll) 2163 if (sl.length () > startlen || socket.sent_scroll)
2148 { 2164 {
2149 Send_With_Handling (&socket, &sl); 2165 socket.send_packet (sl);
2150 socket.sent_scroll = 0; 2166 socket.sent_scroll = 0;
2151 } 2167 }
2152} 2168}
2153 2169
2154/** 2170/**
2232/** 2248/**
2233 * This sends the skill number to name mapping. We ignore 2249 * This sends the skill number to name mapping. We ignore
2234 * the params - we always send the same info no matter what. 2250 * the params - we always send the same info no matter what.
2235 */ 2251 */
2236void 2252void
2237send_skill_info (client_socket *ns, char *params) 2253send_skill_info (client *ns, char *params)
2238{ 2254{
2239 packet sl; 2255 packet sl;
2240 sl << "replyinfo skill_info\n"; 2256 sl << "replyinfo skill_info\n";
2241 2257
2242 for (int i = 1; i < NUM_SKILLS; i++) 2258 for (int i = 1; i < NUM_SKILLS; i++)
2246 { 2262 {
2247 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2263 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2248 fatal (0); 2264 fatal (0);
2249 } 2265 }
2250 2266
2251 Send_With_Handling (ns, &sl); 2267 ns->send_packet (sl);
2252} 2268}
2253 2269
2254/** 2270/**
2255 * This sends the spell path to name mapping. We ignore 2271 * This sends the spell path to name mapping. We ignore
2256 * the params - we always send the same info no matter what. 2272 * the params - we always send the same info no matter what.
2257 */ 2273 */
2258void 2274void
2259send_spell_paths (client_socket * ns, char *params) 2275send_spell_paths (client * ns, char *params)
2260{ 2276{
2261 packet sl; 2277 packet sl;
2262 2278
2263 sl << "replyinfo spell_paths\n"; 2279 sl << "replyinfo spell_paths\n";
2264 2280
2269 { 2285 {
2270 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2286 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2271 fatal (0); 2287 fatal (0);
2272 } 2288 }
2273 2289
2274 Send_With_Handling (ns, &sl); 2290 ns->send_packet (sl);
2275} 2291}
2276 2292
2277/** 2293/**
2278 * This looks for any spells the player may have that have changed their stats. 2294 * This looks for any spells the player may have that have changed their stats.
2279 * it then sends an updspell packet for each spell that has changed in this way 2295 * it then sends an updspell packet for each spell that has changed in this way
2319 2335
2320 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2336 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2321 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2337 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2322 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2338 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2323 2339
2324 Send_With_Handling (pl->socket, &sl); 2340 pl->socket->send_packet (sl);
2325 } 2341 }
2326 } 2342 }
2327 } 2343 }
2328} 2344}
2329 2345
2342 packet sl; 2358 packet sl;
2343 2359
2344 sl << "delspell " 2360 sl << "delspell "
2345 << uint32 (spell->count); 2361 << uint32 (spell->count);
2346 2362
2347 Send_With_Handling (pl->socket, &sl); 2363 pl->socket->send_packet (sl);
2348} 2364}
2349 2365
2350/* appends the spell *spell to the Socklist we will send the data to. */ 2366/* appends the spell *spell to the Socklist we will send the data to. */
2351static void 2367static void
2352append_spell (player *pl, packet &sl, object *spell) 2368append_spell (player *pl, packet &sl, object *spell)
2429 if (spell->type != SPELL) 2445 if (spell->type != SPELL)
2430 continue; 2446 continue;
2431 2447
2432 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2448 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2433 { 2449 {
2434 Send_With_Handling (pl->socket, &sl); 2450 pl->socket->send_packet (sl);
2435 2451
2436 sl.reset (); 2452 sl.reset ();
2437 sl << "addspell "; 2453 sl << "addspell ";
2438 } 2454 }
2439 2455
2453 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2469 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2454 fatal (0); 2470 fatal (0);
2455 } 2471 }
2456 2472
2457 /* finally, we can send the packet */ 2473 /* finally, we can send the packet */
2458 Send_With_Handling (pl->socket, &sl); 2474 pl->socket->send_packet (sl);
2459} 2475}
2460 2476

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines