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.43 by root, Sat Dec 16 20:16:37 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 {
104 packet sl;
105
106 sl.printf ("map_scroll %d %d", dx, dy); 96 ns->send_packet_printf ("map_scroll %d %d", dx, dy);
107 ns->send_packet (sl);
108 }
109 97
110 /* If we are using the Map1aCmd, we may in fact send 98 /* If we are using the Map1aCmd, we may in fact send
111 * head information that is outside the viewable map. 99 * head information that is outside the viewable map.
112 * So set the mx,my to the max value we want to 100 * So set the mx,my to the max value we want to
113 * look for. Removed code to do so - it caused extra 101 * look for. Removed code to do so - it caused extra
153} 141}
154 142
155static void 143static void
156clear_map (player *pl) 144clear_map (player *pl)
157{ 145{
158 client_socket &socket = *pl->socket; 146 client &socket = *pl->socket;
159 147
160 memset (&socket.lastmap, 0, sizeof (socket.lastmap)); 148 memset (&socket.lastmap, 0, sizeof (socket.lastmap));
161 149
162 if (socket.newmapcmd == 1) 150 if (socket.newmapcmd == 1)
163 socket.send_packet ("newmap"); 151 socket.send_packet ("newmap");
168 156
169/** check for map change and send new map data */ 157/** check for map change and send new map data */
170static void 158static void
171check_map_change (player *pl) 159check_map_change (player *pl)
172{ 160{
173 client_socket &socket = *pl->socket; 161 client &socket = *pl->socket;
174 object *ob = pl->ob; 162 object *ob = pl->ob;
175 char buf[MAX_BUF]; /* eauugggh */ 163 char buf[MAX_BUF]; /* eauugggh */
176 164
177 if (socket.current_map != ob->map) 165 if (socket.current_map != ob->map)
178 { 166 {
219 } 207 }
220 } 208 }
221 209
222 socket.current_x = ob->x; 210 socket.current_x = ob->x;
223 socket.current_y = ob->y; 211 socket.current_y = ob->y;
212}
213
214/**
215 * RequestInfo is sort of a meta command. There is some specific
216 * request of information, but we call other functions to provide
217 * that information.
218 */
219void
220RequestInfo (char *buf, int len, client * ns)
221{
222 char *params = NULL, *cp;
223
224 /* No match */
225 char bigbuf[MAX_BUF];
226 int slen;
227
228 /* Set up replyinfo before we modify any of the buffers - this is used
229 * if we don't find a match.
230 */
231 strcpy (bigbuf, "replyinfo ");
232 slen = strlen (bigbuf);
233 safe_strcat (bigbuf, buf, &slen, MAX_BUF);
234
235 /* find the first space, make it null, and update the
236 * params pointer.
237 */
238 for (cp = buf; *cp != '\0'; cp++)
239 if (*cp == ' ')
240 {
241 *cp = '\0';
242 params = cp + 1;
243 break;
244 }
245
246 if (!strcmp (buf, "image_info"))
247 send_image_info (ns, params);
248 else if (!strcmp (buf, "image_sums"))
249 send_image_sums (ns, params);
250 else if (!strcmp (buf, "skill_info"))
251 send_skill_info (ns, params);
252 else if (!strcmp (buf, "spell_paths"))
253 send_spell_paths (ns, params);
254 else
255 ns->send_packet (bigbuf, len);
224} 256}
225 257
226void 258void
227ExtCmd (char *buf, int len, player *pl) 259ExtCmd (char *buf, int len, player *pl)
228{ 260{
316 pl->socket->send_packet (bigbuf); 348 pl->socket->send_packet (bigbuf);
317} 349}
318 350
319/** This is the Setup cmd - easy first implementation */ 351/** This is the Setup cmd - easy first implementation */
320void 352void
321SetUp (char *buf, int len, client_socket * ns) 353SetUp (char *buf, int len, client * ns)
322{ 354{
323 int s, slen; 355 int s, slen;
324 char *cmd, *param, cmdback[HUGE_BUF]; 356 char *cmd, *param, cmdback[HUGE_BUF];
325 357
326 /* run through the cmds of setup 358 /* run through the cmds of setup
536 * This is what takes care of it. We tell the client how things worked out. 568 * 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, 569 * 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. 570 * it either has to be here or init_sockets needs to be exported.
539 */ 571 */
540void 572void
541AddMeCmd (char *buf, int len, client_socket * ns) 573AddMeCmd (char *buf, int len, client * ns)
542{ 574{
543 Settings oldsettings;
544
545 oldsettings = settings;
546 if (ns->status != Ns_Add || add_player (ns)) 575 if (ns->status != Ns_Add || add_player (ns))
547 ns->send_packet ("addme_failed"); 576 ns->send_packet ("addme_failed");
548 else 577 else
549 ns->send_packet ("addme_success"); 578 ns->send_packet ("addme_success");
550
551 settings = oldsettings;
552} 579}
553 580
554/** Reply to ExtendedInfos command */ 581/** Reply to ExtendedInfos command */
555void 582void
556ToggleExtendedInfos (char *buf, int len, client_socket * ns) 583ToggleExtendedInfos (char *buf, int len, client * ns)
557{ 584{
558 char cmdback[MAX_BUF]; 585 char cmdback[MAX_BUF];
559 char command[50]; 586 char command[50];
560 int info, nextinfo; 587 int info, nextinfo;
561 588
612#define MSG_TYPE_MONUMENT 5 639#define MSG_TYPE_MONUMENT 5
613#define MSG_TYPE_SCRIPTED_DIALOG 6*/ 640#define MSG_TYPE_SCRIPTED_DIALOG 6*/
614 641
615/** Reply to ExtendedInfos command */ 642/** Reply to ExtendedInfos command */
616void 643void
617ToggleExtendedText (char *buf, int len, client_socket * ns) 644ToggleExtendedText (char *buf, int len, client * ns)
618{ 645{
619 char cmdback[MAX_BUF]; 646 char cmdback[MAX_BUF];
620 char temp[10]; 647 char temp[10];
621 char command[50]; 648 char command[50];
622 int info, nextinfo, i, flag; 649 int info, nextinfo, i, flag;
673 * a piece of data from us that we know the client wants. So 700 * 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 701 * if we know the client wants it, might as well push it to the
675 * client. 702 * client.
676 */ 703 */
677static void 704static void
678SendSmooth (client_socket * ns, uint16 face) 705SendSmooth (client * ns, uint16 face)
679{ 706{
680 uint16 smoothface; 707 uint16 smoothface;
681 708
682 /* If we can't find a face, return and set it so we won't try to send this 709 /* If we can't find a face, return and set it so we won't try to send this
683 * again. 710 * again.
699 726
700 sl << "smooth " 727 sl << "smooth "
701 << uint16 (face) 728 << uint16 (face)
702 << uint16 (smoothface); 729 << uint16 (smoothface);
703 730
704 Send_With_Handling (ns, &sl); 731 ns->send_packet (sl);
705} 732}
706 733
707 /** 734 /**
708 * Tells client the picture it has to use 735 * Tells client the picture it has to use
709 * to smooth a picture number given as argument. 736 * to smooth a picture number given as argument.
710 */ 737 */
711void 738void
712AskSmooth (char *buf, int len, client_socket * ns) 739AskSmooth (char *buf, int len, client * ns)
713{ 740{
714 uint16 facenbr; 741 uint16 facenbr;
715 742
716 facenbr = atoi (buf); 743 facenbr = atoi (buf);
717 SendSmooth (ns, facenbr); 744 SendSmooth (ns, facenbr);
774 * etc.). It is a lot like PlayerCmd above, but is called with the 801 * 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 802 * 'ncom' method which gives more information back to the client so it
776 * can throttle. 803 * can throttle.
777 */ 804 */
778void 805void
779NewPlayerCmd (uint8 * buf, int len, player *pl) 806NewPlayerCmd (char *buf, int len, player *pl)
780{ 807{
781 int time, repeat; 808 int time, repeat;
782 char command[MAX_BUF]; 809 char command[MAX_BUF];
783 int pktlen; 810 int pktlen;
784 811
786 { 813 {
787 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 814 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf);
788 return; 815 return;
789 } 816 }
790 817
791 pktlen = net_uint16 (buf); 818 pktlen = net_uint16 ((uint8 *)buf);
792 repeat = net_uint32 (buf + 2); 819 repeat = net_uint32 ((uint8 *)buf + 2);
793 820
794 /* -1 is special - no repeat, but don't update */ 821 /* -1 is special - no repeat, but don't update */
795 if (repeat != -1) 822 if (repeat != -1)
796 pl->count = repeat; 823 pl->count = repeat;
797 824
798 if ((len - 4) >= MAX_BUF) 825 if ((len - 4) >= MAX_BUF)
799 len = MAX_BUF - 5; 826 len = MAX_BUF - 5;
800 827
801 strncpy ((char *) command, (char *) buf + 6, len - 4); 828 strncpy ((char *) command, (char *) buf + 6, len - 4);
802 command[len - 4] = '\0'; 829 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 830
815 /* This should not happen anymore. */ 831 /* This should not happen anymore. */
816 if (pl->ob->speed_left < -1.0) 832 if (pl->ob->speed_left < -1.0)
817 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 833 LOG (llevError, "Player has negative time - shouldn't do command.\n");
818 834
832 848
833 /* Send confirmation of command execution now */ 849 /* Send confirmation of command execution now */
834 850
835 packet sl; 851 packet sl;
836 sl << "comc " << uint16 (pktlen) << uint32 (time); 852 sl << "comc " << uint16 (pktlen) << uint32 (time);
837 Send_With_Handling (pl->socket, &sl); 853 pl->socket->send_packet (sl);
838} 854}
839 855
840 856
841/** This is a reply to a previous query. */ 857/** This is a reply to a previous query. */
842void 858void
909 * something older than the server. If we assume the client will be 925 * 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 926 * backwards compatible, having it be a later version should not be a
911 * problem. 927 * problem.
912 */ 928 */
913void 929void
914VersionCmd (char *buf, int len, client_socket * ns) 930VersionCmd (char *buf, int len, client * ns)
915{ 931{
916 char *cp; 932 char *cp;
917 char version_warning[256]; 933 char version_warning[256];
918 934
919 if (!buf) 935 if (!buf)
943 cp = strchr (cp + 1, ' '); 959 cp = strchr (cp + 1, ' ');
944 if (cp) 960 if (cp)
945 { 961 {
946 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); 962 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host);
947 963
948 snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); 964 assign (ns->version, cp + 1);
949 965
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) 966 if (ns->sc_version < 1026)
960 { 967 {
961 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 968 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
962 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 969 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
963 ns->send_packet (version_warning); 970 ns->send_packet (version_warning);
965 972
966 } 973 }
967} 974}
968 975
969/** sound related functions. */ 976/** sound related functions. */
970
971void 977void
972SetSound (char *buf, int len, client_socket * ns) 978SetSound (char *buf, int len, client * ns)
973{ 979{
974 ns->sound = atoi (buf); 980 ns->sound = atoi (buf);
975} 981}
976 982
977/** client wants the map resent */ 983/** client wants the map resent */
1035/** 1041/**
1036 * Asks the client to query the user. This way, the client knows 1042 * 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) 1043 * it needs to send something back (vs just printing out a message)
1038 */ 1044 */
1039void 1045void
1040send_query (client_socket * ns, uint8 flags, char *text) 1046send_query (client * ns, uint8 flags, char *text)
1041{ 1047{
1042 char buf[MAX_BUF]; 1048 char buf[MAX_BUF];
1043 1049
1044 sprintf (buf, "query %d %s", flags, text ? text : ""); 1050 sprintf (buf, "query %d %s", flags, text ? text : "");
1045 ns->send_packet (buf); 1051 ns->send_packet (buf);
1173 set_title (pl->ob, buf); 1179 set_title (pl->ob, buf);
1174 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); 1180 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE);
1175 1181
1176 /* Only send it away if we have some actual data */ 1182 /* Only send it away if we have some actual data */
1177 if (sl.length () > 6) 1183 if (sl.length () > 6)
1178 Send_With_Handling (pl->socket, &sl); 1184 pl->socket->send_packet (sl);
1179} 1185}
1180 1186
1181/** 1187/**
1182 * Tells the client that here is a player it should start using. 1188 * Tells the client that here is a player it should start using.
1183 */ 1189 */
1192 sl << uint32 (pl->ob->count) 1198 sl << uint32 (pl->ob->count)
1193 << uint32 (weight) 1199 << uint32 (weight)
1194 << uint32 (pl->ob->face->number) 1200 << uint32 (pl->ob->face->number)
1195 << data8 (pl->ob->name); 1201 << data8 (pl->ob->name);
1196 1202
1197 Send_With_Handling (pl->socket, &sl); 1203 pl->socket->send_packet (sl);
1198 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1204 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1199} 1205}
1200 1206
1201/** 1207/**
1202 * Need to send an animation sequence to the client. 1208 * Need to send an animation sequence to the client.
1204 * sent them the face yet (this can become quite costly in terms of 1210 * 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 1211 * how much we are sending - on the other hand, this should only happen
1206 * when the player logs in and picks stuff up. 1212 * when the player logs in and picks stuff up.
1207 */ 1213 */
1208void 1214void
1209esrv_send_animation (client_socket * ns, short anim_num) 1215esrv_send_animation (client * ns, short anim_num)
1210{ 1216{
1211 int i; 1217 int i;
1212 1218
1213 /* Do some checking on the anim_num we got. Note that the animations 1219 /* 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 1220 * 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)) 1240 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE))
1235 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1241 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1236 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 1242 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1237 } 1243 }
1238 1244
1239 Send_With_Handling (ns, &sl); 1245 ns->send_packet (sl);
1240 1246
1241 ns->anims_sent[anim_num] = 1; 1247 ns->anims_sent[anim_num] = 1;
1242} 1248}
1243 1249
1244 1250
1251/** 1257/**
1252 * This adds face_num to a map cell at x,y. If the client doesn't have 1258 * 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. 1259 * the face yet, we will also send it.
1254 */ 1260 */
1255static void 1261static void
1256esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap) 1262esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap)
1257{ 1263{
1258 if (newmap->cells[x][y].count >= MAP_LAYERS) 1264 if (newmap->cells[x][y].count >= MAP_LAYERS)
1259 { 1265 {
1260 LOG (llevError, "Too many faces in map cell %d %d\n", x, y); 1266 LOG (llevError, "Too many faces in map cell %d %d\n", x, y);
1261 return; 1267 return;
1281 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; 1287 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y];
1282}; 1288};
1283 1289
1284/** Checkes if map cells have changed */ 1290/** Checkes if map cells have changed */
1285static int 1291static int
1286mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap) 1292mapcellchanged (client * ns, int i, int j, struct Map *newmap)
1287{ 1293{
1288 int k; 1294 int k;
1289 1295
1290 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) 1296 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count)
1291 return 1; 1297 return 1;
1304 * cnum is the client number, cur is the the buffer we put all of 1310 * 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 1311 * this data into. we return the end of the data. layers is
1306 * how many layers of data we should back. 1312 * how many layers of data we should back.
1307 */ 1313 */
1308static uint8 * 1314static uint8 *
1309compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap) 1315compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap)
1310{ 1316{
1311 int x, y, k; 1317 int x, y, k;
1312 int face; 1318 int face;
1313 unsigned char *fcur; 1319 unsigned char *fcur;
1314 struct MapLayer layers[MAP_LAYERS]; 1320 struct MapLayer layers[MAP_LAYERS];
1422 * needs to get sent - if so, it adds the data, sending the head 1428 * 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 1429 * if needed, and returning 1. If this no data needs to get
1424 * sent, it returns zero. 1430 * sent, it returns zero.
1425 */ 1431 */
1426static int 1432static int
1427check_head (packet &sl, client_socket &ns, int ax, int ay, int layer) 1433check_head (packet &sl, client &ns, int ax, int ay, int layer)
1428{ 1434{
1429 short face_num; 1435 short face_num;
1430 1436
1431 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1437 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1432 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1438 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 1472 * the case, it seems to make more sense to have these layer values
1467 * actually match. 1473 * actually match.
1468 */ 1474 */
1469 1475
1470static int 1476static int
1471update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1477update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1472{ 1478{
1473 object *ob, *head; 1479 object *ob, *head;
1474 uint16 face_num; 1480 uint16 face_num;
1475 int bx, by, i; 1481 int bx, by, i;
1476 1482
1689 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1695 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1690 * take. 1696 * take.
1691 */ 1697 */
1692 1698
1693static inline int 1699static inline int
1694update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1700update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1695{ 1701{
1696 object *ob; 1702 object *ob;
1697 int smoothlevel; /* old face_num; */ 1703 int smoothlevel; /* old face_num; */
1698 1704
1699 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1705 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1733 * Returns the size of a data for a map square as returned by 1739 * Returns the size of a data for a map square as returned by
1734 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries 1740 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
1735 * available. 1741 * available.
1736 */ 1742 */
1737int 1743int
1738getExtendedMapInfoSize (client_socket * ns) 1744getExtendedMapInfoSize (client * ns)
1739{ 1745{
1740 int result = 0; 1746 int result = 0;
1741 1747
1742 if (ns->ext_mapinfos) 1748 if (ns->ext_mapinfos)
1743 { 1749 {
1779 uint8 eentrysize; 1785 uint8 eentrysize;
1780 uint16 ewhatstart, ewhatflag; 1786 uint16 ewhatstart, ewhatflag;
1781 uint8 extendedinfos; 1787 uint8 extendedinfos;
1782 maptile *m; 1788 maptile *m;
1783 1789
1784 client_socket &socket = *pl->contr->socket; 1790 client &socket = *pl->contr->socket;
1785 1791
1786 check_map_change (pl->contr); 1792 check_map_change (pl->contr);
1787 1793
1788 packet sl; 1794 packet sl;
1789 packet esl; 1795 packet esl;
1868 * with no faces tells the client to blank out the 1874 * with no faces tells the client to blank out the
1869 * space. 1875 * space.
1870 */ 1876 */
1871 got_one = 0; 1877 got_one = 0;
1872 for (i = oldlen + 2; i < sl.length (); i++) 1878 for (i = oldlen + 2; i < sl.length (); i++)
1873 if (sl.buf[i]) 1879 if (sl[i])
1874 got_one = 1; 1880 got_one = 1;
1875 1881
1876 if (got_one && (mask & 0xf)) 1882 if (got_one && (mask & 0xf))
1877 sl.buf[oldlen + 1] = mask & 0xff; 1883 sl[oldlen + 1] = mask & 0xff;
1878 else 1884 else
1879 { /*either all faces blank, either no face at all */ 1885 { /*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 */ 1886 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1881 sl.reset (oldlen + 2); 1887 sl.reset (oldlen + 2);
1882 else 1888 else
1948 1954
1949 map_clearcell (&lastcell, 0, 0, 0, count); 1955 map_clearcell (&lastcell, 0, 0, 0, count);
1950 } 1956 }
1951 1957
1952 if ((mask & 0xf) || need_send) 1958 if ((mask & 0xf) || need_send)
1953 sl.buf[oldlen + 1] = mask & 0xff; 1959 sl[oldlen + 1] = mask & 0xff;
1954 else 1960 else
1955 sl.reset (oldlen); 1961 sl.reset (oldlen);
1956 } 1962 }
1957 else 1963 else
1958 { 1964 {
1988 mask |= 0x8; 1994 mask |= 0x8;
1989 1995
1990 if (socket.extmap) 1996 if (socket.extmap)
1991 { 1997 {
1992 *last_ext |= 0x80; 1998 *last_ext |= 0x80;
1993 last_ext = sl.buf + sl.length (); 1999 last_ext = &sl[sl.length ()];
1994 sl << uint8 (d); 2000 sl << uint8 (d);
1995 } 2001 }
1996 else 2002 else
1997 sl << uint8 (255 - 64 * d); 2003 sl << uint8 (255 - 64 * d);
1998 } 2004 }
2032 { 2038 {
2033 lastcell.stat_hp = stat_hp; 2039 lastcell.stat_hp = stat_hp;
2034 2040
2035 mask |= 0x8; 2041 mask |= 0x8;
2036 *last_ext |= 0x80; 2042 *last_ext |= 0x80;
2037 last_ext = sl.buf + sl.length (); 2043 last_ext = &sl[sl.length ()];
2038 2044
2039 sl << uint8 (5) << uint8 (stat_hp); 2045 sl << uint8 (5) << uint8 (stat_hp);
2040 2046
2041 if (stat_width > 1) 2047 if (stat_width > 1)
2042 { 2048 {
2043 *last_ext |= 0x80; 2049 *last_ext |= 0x80;
2044 last_ext = sl.buf + sl.length (); 2050 last_ext = &sl[sl.length ()];
2045 2051
2046 sl << uint8 (6) << uint8 (stat_width); 2052 sl << uint8 (6) << uint8 (stat_width);
2047 } 2053 }
2048 } 2054 }
2049 2055
2051 { 2057 {
2052 lastcell.player = player; 2058 lastcell.player = player;
2053 2059
2054 mask |= 0x8; 2060 mask |= 0x8;
2055 *last_ext |= 0x80; 2061 *last_ext |= 0x80;
2056 last_ext = sl.buf + sl.length (); 2062 last_ext = &sl[sl.length ()];
2057 2063
2058 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2064 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2059 } 2065 }
2060 2066
2061 if (lastcell.flags != flags) 2067 if (lastcell.flags != flags)
2062 { 2068 {
2063 lastcell.flags = flags; 2069 lastcell.flags = flags;
2064 2070
2065 mask |= 0x8; 2071 mask |= 0x8;
2066 *last_ext |= 0x80; 2072 *last_ext |= 0x80;
2067 last_ext = sl.buf + sl.length (); 2073 last_ext = &sl[sl.length ()];
2068 2074
2069 sl << uint8 (8) << uint8 (flags); 2075 sl << uint8 (8) << uint8 (flags);
2070 } 2076 }
2071 } 2077 }
2072 2078
2114 * space by checking the mask. If so, update the mask. 2120 * space by checking the mask. If so, update the mask.
2115 * if not, reset the len to that from before adding the mask 2121 * if not, reset the len to that from before adding the mask
2116 * value, so we don't send those bits. 2122 * value, so we don't send those bits.
2117 */ 2123 */
2118 if (mask & 0xf) 2124 if (mask & 0xf)
2119 sl.buf[oldlen + 1] = mask & 0xff; 2125 sl[oldlen + 1] = mask & 0xff;
2120 else 2126 else
2121 sl.reset (oldlen); 2127 sl.reset (oldlen);
2122 2128
2123 if (emask & 0xf) 2129 if (emask & 0xf)
2124 esl.buf[eoldlen + 1] = emask & 0xff; 2130 esl[eoldlen + 1] = emask & 0xff;
2125 else 2131 else
2126 esl.reset (eoldlen); 2132 esl.reset (eoldlen);
2127 } /* else this is a viewable space */ 2133 } /* else this is a viewable space */
2128 } /* for x loop */ 2134 } /* for x loop */
2129 } /* for y loop */ 2135 } /* for y loop */
2135 { 2141 {
2136 /* No map data will follow, so don't say the client 2142 /* No map data will follow, so don't say the client
2137 * it doesn't need draw! 2143 * it doesn't need draw!
2138 */ 2144 */
2139 ewhatflag &= (~EMI_NOREDRAW); 2145 ewhatflag &= (~EMI_NOREDRAW);
2140 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2146 esl[ewhatstart + 1] = ewhatflag & 0xff;
2141 } 2147 }
2142 2148
2143 if (esl.length () > estartlen) 2149 if (esl.length () > estartlen)
2144 Send_With_Handling (&socket, &esl); 2150 socket.send_packet (esl);
2145 } 2151 }
2146 2152
2147 if (sl.length () > startlen || socket.sent_scroll) 2153 if (sl.length () > startlen || socket.sent_scroll)
2148 { 2154 {
2149 Send_With_Handling (&socket, &sl); 2155 socket.send_packet (sl);
2150 socket.sent_scroll = 0; 2156 socket.sent_scroll = 0;
2151 } 2157 }
2152} 2158}
2153 2159
2154/** 2160/**
2232/** 2238/**
2233 * This sends the skill number to name mapping. We ignore 2239 * This sends the skill number to name mapping. We ignore
2234 * the params - we always send the same info no matter what. 2240 * the params - we always send the same info no matter what.
2235 */ 2241 */
2236void 2242void
2237send_skill_info (client_socket *ns, char *params) 2243send_skill_info (client *ns, char *params)
2238{ 2244{
2239 packet sl; 2245 packet sl;
2240 sl << "replyinfo skill_info\n"; 2246 sl << "replyinfo skill_info\n";
2241 2247
2242 for (int i = 1; i < NUM_SKILLS; i++) 2248 for (int i = 1; i < NUM_SKILLS; i++)
2246 { 2252 {
2247 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2253 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2248 fatal (0); 2254 fatal (0);
2249 } 2255 }
2250 2256
2251 Send_With_Handling (ns, &sl); 2257 ns->send_packet (sl);
2252} 2258}
2253 2259
2254/** 2260/**
2255 * This sends the spell path to name mapping. We ignore 2261 * This sends the spell path to name mapping. We ignore
2256 * the params - we always send the same info no matter what. 2262 * the params - we always send the same info no matter what.
2257 */ 2263 */
2258void 2264void
2259send_spell_paths (client_socket * ns, char *params) 2265send_spell_paths (client * ns, char *params)
2260{ 2266{
2261 packet sl; 2267 packet sl;
2262 2268
2263 sl << "replyinfo spell_paths\n"; 2269 sl << "replyinfo spell_paths\n";
2264 2270
2269 { 2275 {
2270 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2276 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2271 fatal (0); 2277 fatal (0);
2272 } 2278 }
2273 2279
2274 Send_With_Handling (ns, &sl); 2280 ns->send_packet (sl);
2275} 2281}
2276 2282
2277/** 2283/**
2278 * This looks for any spells the player may have that have changed their stats. 2284 * 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 2285 * it then sends an updspell packet for each spell that has changed in this way
2319 2325
2320 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2326 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2321 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2327 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2322 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2328 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2323 2329
2324 Send_With_Handling (pl->socket, &sl); 2330 pl->socket->send_packet (sl);
2325 } 2331 }
2326 } 2332 }
2327 } 2333 }
2328} 2334}
2329 2335
2342 packet sl; 2348 packet sl;
2343 2349
2344 sl << "delspell " 2350 sl << "delspell "
2345 << uint32 (spell->count); 2351 << uint32 (spell->count);
2346 2352
2347 Send_With_Handling (pl->socket, &sl); 2353 pl->socket->send_packet (sl);
2348} 2354}
2349 2355
2350/* appends the spell *spell to the Socklist we will send the data to. */ 2356/* appends the spell *spell to the Socklist we will send the data to. */
2351static void 2357static void
2352append_spell (player *pl, packet &sl, object *spell) 2358append_spell (player *pl, packet &sl, object *spell)
2429 if (spell->type != SPELL) 2435 if (spell->type != SPELL)
2430 continue; 2436 continue;
2431 2437
2432 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2438 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2433 { 2439 {
2434 Send_With_Handling (pl->socket, &sl); 2440 pl->socket->send_packet (sl);
2435 2441
2436 sl.reset (); 2442 sl.reset ();
2437 sl << "addspell "; 2443 sl << "addspell ";
2438 } 2444 }
2439 2445
2453 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2459 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2454 fatal (0); 2460 fatal (0);
2455 } 2461 }
2456 2462
2457 /* finally, we can send the packet */ 2463 /* finally, we can send the packet */
2458 Send_With_Handling (pl->socket, &sl); 2464 pl->socket->send_packet (sl);
2459} 2465}
2460 2466

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines