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.34 by root, Thu Dec 14 01:59:10 2006 UTC vs.
Revision 1.40 by root, Fri Dec 15 04:21:29 2006 UTC

60#include <sys/time.h> 60#include <sys/time.h>
61#include <sys/socket.h> 61#include <sys/socket.h>
62#include <netinet/in.h> 62#include <netinet/in.h>
63#include <netdb.h> 63#include <netdb.h>
64 64
65#ifdef HAVE_UNISTD_H
66# include <unistd.h> 65#include <unistd.h>
67#endif
68
69#ifdef HAVE_SYS_TIME_H
70# include <sys/time.h> 66#include <sys/time.h>
71#endif
72 67
73#include "sounds.h" 68#include "sounds.h"
74 69
75/** 70/**
76 * This table translates the attack numbers as used within the 71 * This table translates the attack numbers as used within the
93 -1, /* life stealing */ 88 -1, /* life stealing */
94 -1 /* Disease - not fully done yet */ 89 -1 /* Disease - not fully done yet */
95}; 90};
96 91
97static void 92static void
98socket_map_scroll (NewSocket * ns, int dx, int dy) 93socket_map_scroll (client_socket * ns, int dx, int dy)
99{ 94{
100 struct Map newmap; 95 struct Map newmap;
101 int x, y, mx, my; 96 int x, y, mx, my;
102 97
103 { 98 {
153} 148}
154 149
155static void 150static void
156clear_map (player *pl) 151clear_map (player *pl)
157{ 152{
158 NewSocket & socket = pl->socket; 153 client_socket &socket = *pl->socket;
159 154
160 memset (&socket.lastmap, 0, sizeof (socket.lastmap)); 155 memset (&socket.lastmap, 0, sizeof (socket.lastmap));
161 156
162 if (socket.newmapcmd == 1) 157 if (socket.newmapcmd == 1)
163 socket.send_packet ("newmap"); 158 socket.send_packet ("newmap");
168 163
169/** check for map change and send new map data */ 164/** check for map change and send new map data */
170static void 165static void
171check_map_change (player *pl) 166check_map_change (player *pl)
172{ 167{
173 NewSocket & socket = pl->socket; 168 client_socket &socket = *pl->socket;
174 object *ob = pl->ob; 169 object *ob = pl->ob;
175 char buf[MAX_BUF]; /* eauugggh */ 170 char buf[MAX_BUF]; /* eauugggh */
176 171
177 if (socket.current_map != ob->map) 172 if (socket.current_map != ob->map)
178 { 173 {
221 216
222 socket.current_x = ob->x; 217 socket.current_x = ob->x;
223 socket.current_y = ob->y; 218 socket.current_y = ob->y;
224} 219}
225 220
221/**
222 * RequestInfo is sort of a meta command. There is some specific
223 * request of information, but we call other functions to provide
224 * that information.
225 */
226void
227RequestInfo (char *buf, int len, client_socket * ns)
228{
229 char *params = NULL, *cp;
230
231 /* No match */
232 char bigbuf[MAX_BUF];
233 int slen;
234
235 /* Set up replyinfo before we modify any of the buffers - this is used
236 * if we don't find a match.
237 */
238 strcpy (bigbuf, "replyinfo ");
239 slen = strlen (bigbuf);
240 safe_strcat (bigbuf, buf, &slen, MAX_BUF);
241
242 /* find the first space, make it null, and update the
243 * params pointer.
244 */
245 for (cp = buf; *cp != '\0'; cp++)
246 if (*cp == ' ')
247 {
248 *cp = '\0';
249 params = cp + 1;
250 break;
251 }
252
253 if (!strcmp (buf, "image_info"))
254 send_image_info (ns, params);
255 else if (!strcmp (buf, "image_sums"))
256 send_image_sums (ns, params);
257 else if (!strcmp (buf, "skill_info"))
258 send_skill_info (ns, params);
259 else if (!strcmp (buf, "spell_paths"))
260 send_spell_paths (ns, params);
261 else
262 ns->send_packet (bigbuf, len);
263}
264
226void 265void
227ExtCmd (char *buf, int len, player *pl) 266ExtCmd (char *buf, int len, player *pl)
228{ 267{
229 INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len)); 268 INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len));
230} 269}
249 buf += 8; 288 buf += 8;
250 289
251 // initial map and its origin 290 // initial map and its origin
252 maptile *map = pl->ob->map; 291 maptile *map = pl->ob->map;
253 sint16 dx, dy; 292 sint16 dx, dy;
254 int mapx = pl->socket.mapx / 2 - pl->ob->x; 293 int mapx = pl->socket->mapx / 2 - pl->ob->x;
255 int mapy = pl->socket.mapy / 2 - pl->ob->y; 294 int mapy = pl->socket->mapy / 2 - pl->ob->y;
256 int max_distance = 8; // limit maximum path length to something generous 295 int max_distance = 8; // limit maximum path length to something generous
257 296
258 while (*buf && map && max_distance) 297 while (*buf && map && max_distance)
259 { 298 {
260 int dir = *buf++; 299 int dir = *buf++;
311 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); 350 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token);
312 } 351 }
313 else 352 else
314 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); 353 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token);
315 354
316 pl->socket.send_packet (bigbuf); 355 pl->socket->send_packet (bigbuf);
317} 356}
318 357
319/** This is the Setup cmd - easy first implementation */ 358/** This is the Setup cmd - easy first implementation */
320void 359void
321SetUp (char *buf, int len, NewSocket * ns) 360SetUp (char *buf, int len, client_socket * ns)
322{ 361{
323 int s, slen; 362 int s, slen;
324 char *cmd, *param, cmdback[HUGE_BUF]; 363 char *cmd, *param, cmdback[HUGE_BUF];
325 364
326 /* run through the cmds of setup 365 /* run through the cmds of setup
536 * This is what takes care of it. We tell the client how things worked out. 575 * 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, 576 * 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. 577 * it either has to be here or init_sockets needs to be exported.
539 */ 578 */
540void 579void
541AddMeCmd (char *buf, int len, NewSocket * ns) 580AddMeCmd (char *buf, int len, client_socket * ns)
542{ 581{
543 Settings oldsettings; 582 Settings oldsettings;
544 583
545 oldsettings = settings; 584 oldsettings = settings;
546 if (ns->status != Ns_Add || add_player (ns)) 585 if (ns->status != Ns_Add || add_player (ns))
547 ns->send_packet ("addme_failed"); 586 ns->send_packet ("addme_failed");
548 else 587 else
549 {
550 /* Basically, the add_player copies the socket structure into
551 * the player structure, so this one (which is from init_sockets)
552 * is not needed anymore. The write below should still work, as the
553 * stuff in ns is still relevant.
554 */
555 ns->send_packet ("addme_success"); 588 ns->send_packet ("addme_success");
556 socket_info.nconns--;
557 ns->status = Ns_Avail;
558 }
559 589
560 settings = oldsettings; 590 settings = oldsettings;
561} 591}
562 592
563/** Reply to ExtendedInfos command */ 593/** Reply to ExtendedInfos command */
564void 594void
565ToggleExtendedInfos (char *buf, int len, NewSocket * ns) 595ToggleExtendedInfos (char *buf, int len, client_socket * ns)
566{ 596{
567 char cmdback[MAX_BUF]; 597 char cmdback[MAX_BUF];
568 char command[50]; 598 char command[50];
569 int info, nextinfo; 599 int info, nextinfo;
570 600
621#define MSG_TYPE_MONUMENT 5 651#define MSG_TYPE_MONUMENT 5
622#define MSG_TYPE_SCRIPTED_DIALOG 6*/ 652#define MSG_TYPE_SCRIPTED_DIALOG 6*/
623 653
624/** Reply to ExtendedInfos command */ 654/** Reply to ExtendedInfos command */
625void 655void
626ToggleExtendedText (char *buf, int len, NewSocket * ns) 656ToggleExtendedText (char *buf, int len, client_socket * ns)
627{ 657{
628 char cmdback[MAX_BUF]; 658 char cmdback[MAX_BUF];
629 char temp[10]; 659 char temp[10];
630 char command[50]; 660 char command[50];
631 int info, nextinfo, i, flag; 661 int info, nextinfo, i, flag;
682 * a piece of data from us that we know the client wants. So 712 * a piece of data from us that we know the client wants. So
683 * if we know the client wants it, might as well push it to the 713 * if we know the client wants it, might as well push it to the
684 * client. 714 * client.
685 */ 715 */
686static void 716static void
687SendSmooth (NewSocket * ns, uint16 face) 717SendSmooth (client_socket * ns, uint16 face)
688{ 718{
689 uint16 smoothface; 719 uint16 smoothface;
690 720
691 /* If we can't find a face, return and set it so we won't try to send this 721 /* If we can't find a face, return and set it so we won't try to send this
692 * again. 722 * again.
708 738
709 sl << "smooth " 739 sl << "smooth "
710 << uint16 (face) 740 << uint16 (face)
711 << uint16 (smoothface); 741 << uint16 (smoothface);
712 742
713 Send_With_Handling (ns, &sl); 743 ns->send_packet (sl);
714} 744}
715 745
716 /** 746 /**
717 * Tells client the picture it has to use 747 * Tells client the picture it has to use
718 * to smooth a picture number given as argument. 748 * to smooth a picture number given as argument.
719 */ 749 */
720void 750void
721AskSmooth (char *buf, int len, NewSocket * ns) 751AskSmooth (char *buf, int len, client_socket * ns)
722{ 752{
723 uint16 facenbr; 753 uint16 facenbr;
724 754
725 facenbr = atoi (buf); 755 facenbr = atoi (buf);
726 SendSmooth (ns, facenbr); 756 SendSmooth (ns, facenbr);
783 * etc.). It is a lot like PlayerCmd above, but is called with the 813 * etc.). It is a lot like PlayerCmd above, but is called with the
784 * 'ncom' method which gives more information back to the client so it 814 * 'ncom' method which gives more information back to the client so it
785 * can throttle. 815 * can throttle.
786 */ 816 */
787void 817void
788NewPlayerCmd (uint8 * buf, int len, player *pl) 818NewPlayerCmd (char *buf, int len, player *pl)
789{ 819{
790 int time, repeat; 820 int time, repeat;
791 char command[MAX_BUF]; 821 char command[MAX_BUF];
792 int pktlen; 822 int pktlen;
793 823
795 { 825 {
796 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 826 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf);
797 return; 827 return;
798 } 828 }
799 829
800 pktlen = net_uint16 (buf); 830 pktlen = net_uint16 ((uint8 *)buf);
801 repeat = net_uint32 (buf + 2); 831 repeat = net_uint32 ((uint8 *)buf + 2);
802 832
803 /* -1 is special - no repeat, but don't update */ 833 /* -1 is special - no repeat, but don't update */
804 if (repeat != -1) 834 if (repeat != -1)
805 pl->count = repeat; 835 pl->count = repeat;
806 836
807 if ((len - 4) >= MAX_BUF) 837 if ((len - 4) >= MAX_BUF)
808 len = MAX_BUF - 5; 838 len = MAX_BUF - 5;
809 839
810 strncpy ((char *) command, (char *) buf + 6, len - 4); 840 strncpy ((char *) command, (char *) buf + 6, len - 4);
811 command[len - 4] = '\0'; 841 command[len - 4] = 0;
812
813 /* The following should never happen with a proper or honest client.
814 * Therefore, the error message doesn't have to be too clear - if
815 * someone is playing with a hacked/non working client, this gives them
816 * an idea of the problem, but they deserve what they get
817 */
818 if (pl->state != ST_PLAYING)
819 {
820 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "You can not issue commands - state is not ST_PLAYING (%s)", buf);
821 return;
822 }
823 842
824 /* This should not happen anymore. */ 843 /* This should not happen anymore. */
825 if (pl->ob->speed_left < -1.0) 844 if (pl->ob->speed_left < -1.0)
826 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 845 LOG (llevError, "Player has negative time - shouldn't do command.\n");
827 846
841 860
842 /* Send confirmation of command execution now */ 861 /* Send confirmation of command execution now */
843 862
844 packet sl; 863 packet sl;
845 sl << "comc " << uint16 (pktlen) << uint32 (time); 864 sl << "comc " << uint16 (pktlen) << uint32 (time);
846 Send_With_Handling (&pl->socket, &sl); 865 pl->socket->send_packet (sl);
847} 866}
848 867
849 868
850/** This is a reply to a previous query. */ 869/** This is a reply to a previous query. */
851void 870void
918 * something older than the server. If we assume the client will be 937 * something older than the server. If we assume the client will be
919 * backwards compatible, having it be a later version should not be a 938 * backwards compatible, having it be a later version should not be a
920 * problem. 939 * problem.
921 */ 940 */
922void 941void
923VersionCmd (char *buf, int len, NewSocket * ns) 942VersionCmd (char *buf, int len, client_socket * ns)
924{ 943{
925 char *cp; 944 char *cp;
926 char version_warning[256]; 945 char version_warning[256];
927 946
928 if (!buf) 947 if (!buf)
976} 995}
977 996
978/** sound related functions. */ 997/** sound related functions. */
979 998
980void 999void
981SetSound (char *buf, int len, NewSocket * ns) 1000SetSound (char *buf, int len, client_socket * ns)
982{ 1001{
983 ns->sound = atoi (buf); 1002 ns->sound = atoi (buf);
984} 1003}
985 1004
986/** client wants the map resent */ 1005/** client wants the map resent */
996 */ 1015 */
997#if 0 1016#if 0
998 /* Okay, this is MAJOR UGLY. but the only way I know how to 1017 /* Okay, this is MAJOR UGLY. but the only way I know how to
999 * clear the "cache" 1018 * clear the "cache"
1000 */ 1019 */
1001 memset (&pl->socket.lastmap, 0, sizeof (struct Map)); 1020 memset (&pl->socket->lastmap, 0, sizeof (struct Map));
1002 draw_client_map (pl->ob); 1021 draw_client_map (pl->ob);
1003#endif 1022#endif
1004} 1023}
1005 1024
1006/** 1025/**
1044/** 1063/**
1045 * Asks the client to query the user. This way, the client knows 1064 * Asks the client to query the user. This way, the client knows
1046 * it needs to send something back (vs just printing out a message) 1065 * it needs to send something back (vs just printing out a message)
1047 */ 1066 */
1048void 1067void
1049send_query (NewSocket * ns, uint8 flags, char *text) 1068send_query (client_socket * ns, uint8 flags, char *text)
1050{ 1069{
1051 char buf[MAX_BUF]; 1070 char buf[MAX_BUF];
1052 1071
1053 sprintf (buf, "query %d %s", flags, text ? text : ""); 1072 sprintf (buf, "query %d %s", flags, text ? text : "");
1054 ns->send_packet (buf); 1073 ns->send_packet (buf);
1109 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); 1128 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX);
1110 AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); 1129 AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON);
1111 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); 1130 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA);
1112 } 1131 }
1113 1132
1114 if (pl->socket.exp64) 1133 if (pl->socket->exp64)
1115 { 1134 {
1116 uint8 s; 1135 uint8 s;
1117 1136
1118 for (s = 0; s < NUM_SKILLS; s++) 1137 for (s = 0; s < NUM_SKILLS; s++)
1119 { 1138 {
1129 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; 1148 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp;
1130 } 1149 }
1131 } 1150 }
1132 } 1151 }
1133 1152
1134 if (pl->socket.exp64) 1153 if (pl->socket->exp64)
1135 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } 1154 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) }
1136 else 1155 else
1137 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } 1156 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) }
1138 1157
1139 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); 1158 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL);
1152 if (pl->run_on) 1171 if (pl->run_on)
1153 flags |= SF_RUNON; 1172 flags |= SF_RUNON;
1154 1173
1155 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); 1174 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS);
1156 1175
1157 if (pl->socket.sc_version < 1025) 1176 if (pl->socket->sc_version < 1025)
1158 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } 1177 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) }
1159 else 1178 else
1160 { 1179 {
1161 int i; 1180 int i;
1162 1181
1168 1187
1169 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); 1188 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]);
1170 } 1189 }
1171 } 1190 }
1172 1191
1173 if (pl->socket.monitor_spells) 1192 if (pl->socket->monitor_spells)
1174 { 1193 {
1175 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); 1194 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE);
1176 AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); 1195 AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL);
1177 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); 1196 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY);
1178 } 1197 }
1179 1198
1180 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ 1199 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */
1181 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); 1200 AddIfString (pl->socket->stats.range, buf, CS_STAT_RANGE);
1182 set_title (pl->ob, buf); 1201 set_title (pl->ob, buf);
1183 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1202 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE);
1184 1203
1185 /* Only send it away if we have some actual data */ 1204 /* Only send it away if we have some actual data */
1186 if (sl.length () > 6) 1205 if (sl.length () > 6)
1187 Send_With_Handling (&pl->socket, &sl); 1206 pl->socket->send_packet (sl);
1188} 1207}
1189 1208
1190/** 1209/**
1191 * Tells the client that here is a player it should start using. 1210 * Tells the client that here is a player it should start using.
1192 */ 1211 */
1201 sl << uint32 (pl->ob->count) 1220 sl << uint32 (pl->ob->count)
1202 << uint32 (weight) 1221 << uint32 (weight)
1203 << uint32 (pl->ob->face->number) 1222 << uint32 (pl->ob->face->number)
1204 << data8 (pl->ob->name); 1223 << data8 (pl->ob->name);
1205 1224
1206 Send_With_Handling (&pl->socket, &sl); 1225 pl->socket->send_packet (sl);
1207 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1226 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1208} 1227}
1209 1228
1210/** 1229/**
1211 * Need to send an animation sequence to the client. 1230 * Need to send an animation sequence to the client.
1213 * sent them the face yet (this can become quite costly in terms of 1232 * sent them the face yet (this can become quite costly in terms of
1214 * how much we are sending - on the other hand, this should only happen 1233 * how much we are sending - on the other hand, this should only happen
1215 * when the player logs in and picks stuff up. 1234 * when the player logs in and picks stuff up.
1216 */ 1235 */
1217void 1236void
1218esrv_send_animation (NewSocket * ns, short anim_num) 1237esrv_send_animation (client_socket * ns, short anim_num)
1219{ 1238{
1220 int i; 1239 int i;
1221 1240
1222 /* Do some checking on the anim_num we got. Note that the animations 1241 /* Do some checking on the anim_num we got. Note that the animations
1223 * are added in contigous order, so if the number is in the valid 1242 * are added in contigous order, so if the number is in the valid
1243 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) 1262 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE))
1244 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1263 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1245 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 1264 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1246 } 1265 }
1247 1266
1248 Send_With_Handling (ns, &sl); 1267 ns->send_packet (sl);
1249 1268
1250 ns->anims_sent[anim_num] = 1; 1269 ns->anims_sent[anim_num] = 1;
1251} 1270}
1252 1271
1253 1272
1260/** 1279/**
1261 * This adds face_num to a map cell at x,y. If the client doesn't have 1280 * This adds face_num to a map cell at x,y. If the client doesn't have
1262 * the face yet, we will also send it. 1281 * the face yet, we will also send it.
1263 */ 1282 */
1264static void 1283static void
1265esrv_map_setbelow (NewSocket * ns, int x, int y, short face_num, struct Map *newmap) 1284esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap)
1266{ 1285{
1267 if (newmap->cells[x][y].count >= MAP_LAYERS) 1286 if (newmap->cells[x][y].count >= MAP_LAYERS)
1268 { 1287 {
1269 LOG (llevError, "Too many faces in map cell %d %d\n", x, y); 1288 LOG (llevError, "Too many faces in map cell %d %d\n", x, y);
1270 return; 1289 return;
1290 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; 1309 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y];
1291}; 1310};
1292 1311
1293/** Checkes if map cells have changed */ 1312/** Checkes if map cells have changed */
1294static int 1313static int
1295mapcellchanged (NewSocket * ns, int i, int j, struct Map *newmap) 1314mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap)
1296{ 1315{
1297 int k; 1316 int k;
1298 1317
1299 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) 1318 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count)
1300 return 1; 1319 return 1;
1313 * cnum is the client number, cur is the the buffer we put all of 1332 * cnum is the client number, cur is the the buffer we put all of
1314 * this data into. we return the end of the data. layers is 1333 * this data into. we return the end of the data. layers is
1315 * how many layers of data we should back. 1334 * how many layers of data we should back.
1316 */ 1335 */
1317static uint8 * 1336static uint8 *
1318compactlayer (NewSocket * ns, unsigned char *cur, int numlayers, struct Map *newmap) 1337compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap)
1319{ 1338{
1320 int x, y, k; 1339 int x, y, k;
1321 int face; 1340 int face;
1322 unsigned char *fcur; 1341 unsigned char *fcur;
1323 struct MapLayer layers[MAP_LAYERS]; 1342 struct MapLayer layers[MAP_LAYERS];
1431 * needs to get sent - if so, it adds the data, sending the head 1450 * needs to get sent - if so, it adds the data, sending the head
1432 * if needed, and returning 1. If this no data needs to get 1451 * if needed, and returning 1. If this no data needs to get
1433 * sent, it returns zero. 1452 * sent, it returns zero.
1434 */ 1453 */
1435static int 1454static int
1436check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer) 1455check_head (packet &sl, client_socket &ns, int ax, int ay, int layer)
1437{ 1456{
1438 short face_num; 1457 short face_num;
1439 1458
1440 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1459 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1441 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1460 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number;
1475 * the case, it seems to make more sense to have these layer values 1494 * the case, it seems to make more sense to have these layer values
1476 * actually match. 1495 * actually match.
1477 */ 1496 */
1478 1497
1479static int 1498static int
1480update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1499update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1481{ 1500{
1482 object *ob, *head; 1501 object *ob, *head;
1483 uint16 face_num; 1502 uint16 face_num;
1484 int bx, by, i; 1503 int bx, by, i;
1485 1504
1698 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1717 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1699 * take. 1718 * take.
1700 */ 1719 */
1701 1720
1702static inline int 1721static inline int
1703update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1722update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1704{ 1723{
1705 object *ob; 1724 object *ob;
1706 int smoothlevel; /* old face_num; */ 1725 int smoothlevel; /* old face_num; */
1707 1726
1708 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1727 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1742 * Returns the size of a data for a map square as returned by 1761 * Returns the size of a data for a map square as returned by
1743 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries 1762 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
1744 * available. 1763 * available.
1745 */ 1764 */
1746int 1765int
1747getExtendedMapInfoSize (NewSocket * ns) 1766getExtendedMapInfoSize (client_socket * ns)
1748{ 1767{
1749 int result = 0; 1768 int result = 0;
1750 1769
1751 if (ns->ext_mapinfos) 1770 if (ns->ext_mapinfos)
1752 { 1771 {
1788 uint8 eentrysize; 1807 uint8 eentrysize;
1789 uint16 ewhatstart, ewhatflag; 1808 uint16 ewhatstart, ewhatflag;
1790 uint8 extendedinfos; 1809 uint8 extendedinfos;
1791 maptile *m; 1810 maptile *m;
1792 1811
1793 NewSocket &socket = pl->contr->socket; 1812 client_socket &socket = *pl->contr->socket;
1794 1813
1795 check_map_change (pl->contr); 1814 check_map_change (pl->contr);
1796 1815
1797 packet sl; 1816 packet sl;
1798 packet esl; 1817 packet esl;
1877 * with no faces tells the client to blank out the 1896 * with no faces tells the client to blank out the
1878 * space. 1897 * space.
1879 */ 1898 */
1880 got_one = 0; 1899 got_one = 0;
1881 for (i = oldlen + 2; i < sl.length (); i++) 1900 for (i = oldlen + 2; i < sl.length (); i++)
1882 if (sl.buf[i]) 1901 if (sl[i])
1883 got_one = 1; 1902 got_one = 1;
1884 1903
1885 if (got_one && (mask & 0xf)) 1904 if (got_one && (mask & 0xf))
1886 sl.buf[oldlen + 1] = mask & 0xff; 1905 sl[oldlen + 1] = mask & 0xff;
1887 else 1906 else
1888 { /*either all faces blank, either no face at all */ 1907 { /*either all faces blank, either no face at all */
1889 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ 1908 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1890 sl.reset (oldlen + 2); 1909 sl.reset (oldlen + 2);
1891 else 1910 else
1957 1976
1958 map_clearcell (&lastcell, 0, 0, 0, count); 1977 map_clearcell (&lastcell, 0, 0, 0, count);
1959 } 1978 }
1960 1979
1961 if ((mask & 0xf) || need_send) 1980 if ((mask & 0xf) || need_send)
1962 sl.buf[oldlen + 1] = mask & 0xff; 1981 sl[oldlen + 1] = mask & 0xff;
1963 else 1982 else
1964 sl.reset (oldlen); 1983 sl.reset (oldlen);
1965 } 1984 }
1966 else 1985 else
1967 { 1986 {
1997 mask |= 0x8; 2016 mask |= 0x8;
1998 2017
1999 if (socket.extmap) 2018 if (socket.extmap)
2000 { 2019 {
2001 *last_ext |= 0x80; 2020 *last_ext |= 0x80;
2002 last_ext = sl.buf + sl.length (); 2021 last_ext = &sl[sl.length ()];
2003 sl << uint8 (d); 2022 sl << uint8 (d);
2004 } 2023 }
2005 else 2024 else
2006 sl << uint8 (255 - 64 * d); 2025 sl << uint8 (255 - 64 * d);
2007 } 2026 }
2041 { 2060 {
2042 lastcell.stat_hp = stat_hp; 2061 lastcell.stat_hp = stat_hp;
2043 2062
2044 mask |= 0x8; 2063 mask |= 0x8;
2045 *last_ext |= 0x80; 2064 *last_ext |= 0x80;
2046 last_ext = sl.buf + sl.length (); 2065 last_ext = &sl[sl.length ()];
2047 2066
2048 sl << uint8 (5) << uint8 (stat_hp); 2067 sl << uint8 (5) << uint8 (stat_hp);
2049 2068
2050 if (stat_width > 1) 2069 if (stat_width > 1)
2051 { 2070 {
2052 *last_ext |= 0x80; 2071 *last_ext |= 0x80;
2053 last_ext = sl.buf + sl.length (); 2072 last_ext = &sl[sl.length ()];
2054 2073
2055 sl << uint8 (6) << uint8 (stat_width); 2074 sl << uint8 (6) << uint8 (stat_width);
2056 } 2075 }
2057 } 2076 }
2058 2077
2060 { 2079 {
2061 lastcell.player = player; 2080 lastcell.player = player;
2062 2081
2063 mask |= 0x8; 2082 mask |= 0x8;
2064 *last_ext |= 0x80; 2083 *last_ext |= 0x80;
2065 last_ext = sl.buf + sl.length (); 2084 last_ext = &sl[sl.length ()];
2066 2085
2067 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2086 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2068 } 2087 }
2069 2088
2070 if (lastcell.flags != flags) 2089 if (lastcell.flags != flags)
2071 { 2090 {
2072 lastcell.flags = flags; 2091 lastcell.flags = flags;
2073 2092
2074 mask |= 0x8; 2093 mask |= 0x8;
2075 *last_ext |= 0x80; 2094 *last_ext |= 0x80;
2076 last_ext = sl.buf + sl.length (); 2095 last_ext = &sl[sl.length ()];
2077 2096
2078 sl << uint8 (8) << uint8 (flags); 2097 sl << uint8 (8) << uint8 (flags);
2079 } 2098 }
2080 } 2099 }
2081 2100
2123 * space by checking the mask. If so, update the mask. 2142 * space by checking the mask. If so, update the mask.
2124 * if not, reset the len to that from before adding the mask 2143 * if not, reset the len to that from before adding the mask
2125 * value, so we don't send those bits. 2144 * value, so we don't send those bits.
2126 */ 2145 */
2127 if (mask & 0xf) 2146 if (mask & 0xf)
2128 sl.buf[oldlen + 1] = mask & 0xff; 2147 sl[oldlen + 1] = mask & 0xff;
2129 else 2148 else
2130 sl.reset (oldlen); 2149 sl.reset (oldlen);
2131 2150
2132 if (emask & 0xf) 2151 if (emask & 0xf)
2133 esl.buf[eoldlen + 1] = emask & 0xff; 2152 esl[eoldlen + 1] = emask & 0xff;
2134 else 2153 else
2135 esl.reset (eoldlen); 2154 esl.reset (eoldlen);
2136 } /* else this is a viewable space */ 2155 } /* else this is a viewable space */
2137 } /* for x loop */ 2156 } /* for x loop */
2138 } /* for y loop */ 2157 } /* for y loop */
2144 { 2163 {
2145 /* No map data will follow, so don't say the client 2164 /* No map data will follow, so don't say the client
2146 * it doesn't need draw! 2165 * it doesn't need draw!
2147 */ 2166 */
2148 ewhatflag &= (~EMI_NOREDRAW); 2167 ewhatflag &= (~EMI_NOREDRAW);
2149 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2168 esl[ewhatstart + 1] = ewhatflag & 0xff;
2150 } 2169 }
2151 2170
2152 if (esl.length () > estartlen) 2171 if (esl.length () > estartlen)
2153 Send_With_Handling (&socket, &esl); 2172 socket.send_packet (esl);
2154 } 2173 }
2155 2174
2156 if (sl.length () > startlen || socket.sent_scroll) 2175 if (sl.length () > startlen || socket.sent_scroll)
2157 { 2176 {
2158 Send_With_Handling (&socket, &sl); 2177 socket.send_packet (sl);
2159 socket.sent_scroll = 0; 2178 socket.sent_scroll = 0;
2160 } 2179 }
2161} 2180}
2162 2181
2163/** 2182/**
2189 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) 2208 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY)
2190 return; 2209 return;
2191 2210
2192 memset (&newmap, 0, sizeof (struct Map)); 2211 memset (&newmap, 0, sizeof (struct Map));
2193 2212
2194 for (j = (pl->y - pl->contr->socket.mapy / 2); j < (pl->y + (pl->contr->socket.mapy + 1) / 2); j++) 2213 for (j = (pl->y - pl->contr->socket->mapy / 2); j < (pl->y + (pl->contr->socket->mapy + 1) / 2); j++)
2195 { 2214 {
2196 for (i = (pl->x - pl->contr->socket.mapx / 2); i < (pl->x + (pl->contr->socket.mapx + 1) / 2); i++) 2215 for (i = (pl->x - pl->contr->socket->mapx / 2); i < (pl->x + (pl->contr->socket->mapx + 1) / 2); i++)
2197 { 2216 {
2198 ax = i; 2217 ax = i;
2199 ay = j; 2218 ay = j;
2200 m = pm; 2219 m = pm;
2201 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); 2220 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay);
2233 2252
2234/*****************************************************************************/ 2253/*****************************************************************************/
2235void 2254void
2236send_plugin_custom_message (object *pl, char *buf) 2255send_plugin_custom_message (object *pl, char *buf)
2237{ 2256{
2238 pl->contr->socket.send_packet (buf); 2257 pl->contr->socket->send_packet (buf);
2239} 2258}
2240 2259
2241/** 2260/**
2242 * This sends the skill number to name mapping. We ignore 2261 * This sends the skill number to name mapping. We ignore
2243 * the params - we always send the same info no matter what. 2262 * the params - we always send the same info no matter what.
2244 */ 2263 */
2245void 2264void
2246send_skill_info (NewSocket *ns, char *params) 2265send_skill_info (client_socket *ns, char *params)
2247{ 2266{
2248 packet sl; 2267 packet sl;
2249 sl << "replyinfo skill_info\n"; 2268 sl << "replyinfo skill_info\n";
2250 2269
2251 for (int i = 1; i < NUM_SKILLS; i++) 2270 for (int i = 1; i < NUM_SKILLS; i++)
2255 { 2274 {
2256 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2275 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2257 fatal (0); 2276 fatal (0);
2258 } 2277 }
2259 2278
2260 Send_With_Handling (ns, &sl); 2279 ns->send_packet (sl);
2261} 2280}
2262 2281
2263/** 2282/**
2264 * This sends the spell path to name mapping. We ignore 2283 * This sends the spell path to name mapping. We ignore
2265 * the params - we always send the same info no matter what. 2284 * the params - we always send the same info no matter what.
2266 */ 2285 */
2267void 2286void
2268send_spell_paths (NewSocket * ns, char *params) 2287send_spell_paths (client_socket * ns, char *params)
2269{ 2288{
2270 packet sl; 2289 packet sl;
2271 2290
2272 sl << "replyinfo spell_paths\n"; 2291 sl << "replyinfo spell_paths\n";
2273 2292
2278 { 2297 {
2279 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2298 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2280 fatal (0); 2299 fatal (0);
2281 } 2300 }
2282 2301
2283 Send_With_Handling (ns, &sl); 2302 ns->send_packet (sl);
2284} 2303}
2285 2304
2286/** 2305/**
2287 * This looks for any spells the player may have that have changed their stats. 2306 * This looks for any spells the player may have that have changed their stats.
2288 * it then sends an updspell packet for each spell that has changed in this way 2307 * it then sends an updspell packet for each spell that has changed in this way
2289 */ 2308 */
2290void 2309void
2291esrv_update_spells (player *pl) 2310esrv_update_spells (player *pl)
2292{ 2311{
2293 if (!pl->socket.monitor_spells) 2312 if (!pl->socket->monitor_spells)
2294 return; 2313 return;
2295 2314
2296 for (object *spell = pl->ob->inv; spell; spell = spell->below) 2315 for (object *spell = pl->ob->inv; spell; spell = spell->below)
2297 { 2316 {
2298 if (spell->type == SPELL) 2317 if (spell->type == SPELL)
2328 2347
2329 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2348 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2330 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2349 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2331 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2350 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2332 2351
2333 Send_With_Handling (&pl->socket, &sl); 2352 pl->socket->send_packet (sl);
2334 } 2353 }
2335 } 2354 }
2336 } 2355 }
2337} 2356}
2338 2357
2339void 2358void
2340esrv_remove_spell (player *pl, object *spell) 2359esrv_remove_spell (player *pl, object *spell)
2341{ 2360{
2342 if (!pl->socket.monitor_spells) 2361 if (!pl->socket->monitor_spells)
2343 return; 2362 return;
2344 2363
2345 if (!pl || !spell || spell->env != pl->ob) 2364 if (!pl || !spell || spell->env != pl->ob)
2346 { 2365 {
2347 LOG (llevError, "Invalid call to esrv_remove_spell"); 2366 LOG (llevError, "Invalid call to esrv_remove_spell");
2351 packet sl; 2370 packet sl;
2352 2371
2353 sl << "delspell " 2372 sl << "delspell "
2354 << uint32 (spell->count); 2373 << uint32 (spell->count);
2355 2374
2356 Send_With_Handling (&pl->socket, &sl); 2375 pl->socket->send_packet (sl);
2357} 2376}
2358 2377
2359/* appends the spell *spell to the Socklist we will send the data to. */ 2378/* appends the spell *spell to the Socklist we will send the data to. */
2360static void 2379static void
2361append_spell (player *pl, packet &sl, object *spell) 2380append_spell (player *pl, packet &sl, object *spell)
2409 { 2428 {
2410 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); 2429 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player");
2411 return; 2430 return;
2412 } 2431 }
2413 2432
2414 if (!pl->socket.monitor_spells) 2433 if (!pl->socket->monitor_spells)
2415 return; 2434 return;
2416 2435
2417 packet sl; 2436 packet sl;
2418 2437
2419 sl << "addspell "; 2438 sl << "addspell ";
2438 if (spell->type != SPELL) 2457 if (spell->type != SPELL)
2439 continue; 2458 continue;
2440 2459
2441 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2460 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2442 { 2461 {
2443 Send_With_Handling (&pl->socket, &sl); 2462 pl->socket->send_packet (sl);
2444 2463
2445 sl.reset (); 2464 sl.reset ();
2446 sl << "addspell "; 2465 sl << "addspell ";
2447 } 2466 }
2448 2467
2462 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2481 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2463 fatal (0); 2482 fatal (0);
2464 } 2483 }
2465 2484
2466 /* finally, we can send the packet */ 2485 /* finally, we can send the packet */
2467 Send_With_Handling (&pl->socket, &sl); 2486 pl->socket->send_packet (sl);
2468
2469} 2487}
2470 2488

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines