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.35 by root, Thu Dec 14 02:37:37 2006 UTC vs.
Revision 1.42 by root, Sat Dec 16 03:08:26 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 {
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;
224} 212}
225 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);
256}
257
226void 258void
227ExtCmd (char *buf, int len, player *pl) 259ExtCmd (char *buf, int len, player *pl)
228{ 260{
229 INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len)); 261 INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len));
230} 262}
249 buf += 8; 281 buf += 8;
250 282
251 // initial map and its origin 283 // initial map and its origin
252 maptile *map = pl->ob->map; 284 maptile *map = pl->ob->map;
253 sint16 dx, dy; 285 sint16 dx, dy;
254 int mapx = pl->socket.mapx / 2 - pl->ob->x; 286 int mapx = pl->socket->mapx / 2 - pl->ob->x;
255 int mapy = pl->socket.mapy / 2 - pl->ob->y; 287 int mapy = pl->socket->mapy / 2 - pl->ob->y;
256 int max_distance = 8; // limit maximum path length to something generous 288 int max_distance = 8; // limit maximum path length to something generous
257 289
258 while (*buf && map && max_distance) 290 while (*buf && map && max_distance)
259 { 291 {
260 int dir = *buf++; 292 int dir = *buf++;
311 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); 343 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token);
312 } 344 }
313 else 345 else
314 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); 346 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token);
315 347
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; 575 Settings oldsettings;
544 576
545 oldsettings = settings; 577 oldsettings = settings;
546 if (ns->status != Ns_Add || add_player (ns)) 578 if (ns->status != Ns_Add || add_player (ns))
547 ns->send_packet ("addme_failed"); 579 ns->send_packet ("addme_failed");
548 else 580 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"); 581 ns->send_packet ("addme_success");
556 socket_info.nconns--;
557 ns->status = Ns_Avail;
558 }
559 582
560 settings = oldsettings; 583 settings = oldsettings;
561} 584}
562 585
563/** Reply to ExtendedInfos command */ 586/** Reply to ExtendedInfos command */
564void 587void
565ToggleExtendedInfos (char *buf, int len, client_socket * ns) 588ToggleExtendedInfos (char *buf, int len, client * ns)
566{ 589{
567 char cmdback[MAX_BUF]; 590 char cmdback[MAX_BUF];
568 char command[50]; 591 char command[50];
569 int info, nextinfo; 592 int info, nextinfo;
570 593
621#define MSG_TYPE_MONUMENT 5 644#define MSG_TYPE_MONUMENT 5
622#define MSG_TYPE_SCRIPTED_DIALOG 6*/ 645#define MSG_TYPE_SCRIPTED_DIALOG 6*/
623 646
624/** Reply to ExtendedInfos command */ 647/** Reply to ExtendedInfos command */
625void 648void
626ToggleExtendedText (char *buf, int len, client_socket * ns) 649ToggleExtendedText (char *buf, int len, client * ns)
627{ 650{
628 char cmdback[MAX_BUF]; 651 char cmdback[MAX_BUF];
629 char temp[10]; 652 char temp[10];
630 char command[50]; 653 char command[50];
631 int info, nextinfo, i, flag; 654 int info, nextinfo, i, flag;
682 * a piece of data from us that we know the client wants. So 705 * 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 706 * if we know the client wants it, might as well push it to the
684 * client. 707 * client.
685 */ 708 */
686static void 709static void
687SendSmooth (client_socket * ns, uint16 face) 710SendSmooth (client * ns, uint16 face)
688{ 711{
689 uint16 smoothface; 712 uint16 smoothface;
690 713
691 /* If we can't find a face, return and set it so we won't try to send this 714 /* If we can't find a face, return and set it so we won't try to send this
692 * again. 715 * again.
708 731
709 sl << "smooth " 732 sl << "smooth "
710 << uint16 (face) 733 << uint16 (face)
711 << uint16 (smoothface); 734 << uint16 (smoothface);
712 735
713 Send_With_Handling (ns, &sl); 736 ns->send_packet (sl);
714} 737}
715 738
716 /** 739 /**
717 * Tells client the picture it has to use 740 * Tells client the picture it has to use
718 * to smooth a picture number given as argument. 741 * to smooth a picture number given as argument.
719 */ 742 */
720void 743void
721AskSmooth (char *buf, int len, client_socket * ns) 744AskSmooth (char *buf, int len, client * ns)
722{ 745{
723 uint16 facenbr; 746 uint16 facenbr;
724 747
725 facenbr = atoi (buf); 748 facenbr = atoi (buf);
726 SendSmooth (ns, facenbr); 749 SendSmooth (ns, facenbr);
783 * etc.). It is a lot like PlayerCmd above, but is called with the 806 * 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 807 * 'ncom' method which gives more information back to the client so it
785 * can throttle. 808 * can throttle.
786 */ 809 */
787void 810void
788NewPlayerCmd (uint8 * buf, int len, player *pl) 811NewPlayerCmd (char *buf, int len, player *pl)
789{ 812{
790 int time, repeat; 813 int time, repeat;
791 char command[MAX_BUF]; 814 char command[MAX_BUF];
792 int pktlen; 815 int pktlen;
793 816
795 { 818 {
796 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 819 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf);
797 return; 820 return;
798 } 821 }
799 822
800 pktlen = net_uint16 (buf); 823 pktlen = net_uint16 ((uint8 *)buf);
801 repeat = net_uint32 (buf + 2); 824 repeat = net_uint32 ((uint8 *)buf + 2);
802 825
803 /* -1 is special - no repeat, but don't update */ 826 /* -1 is special - no repeat, but don't update */
804 if (repeat != -1) 827 if (repeat != -1)
805 pl->count = repeat; 828 pl->count = repeat;
806 829
807 if ((len - 4) >= MAX_BUF) 830 if ((len - 4) >= MAX_BUF)
808 len = MAX_BUF - 5; 831 len = MAX_BUF - 5;
809 832
810 strncpy ((char *) command, (char *) buf + 6, len - 4); 833 strncpy ((char *) command, (char *) buf + 6, len - 4);
811 command[len - 4] = '\0'; 834 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 835
824 /* This should not happen anymore. */ 836 /* This should not happen anymore. */
825 if (pl->ob->speed_left < -1.0) 837 if (pl->ob->speed_left < -1.0)
826 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 838 LOG (llevError, "Player has negative time - shouldn't do command.\n");
827 839
841 853
842 /* Send confirmation of command execution now */ 854 /* Send confirmation of command execution now */
843 855
844 packet sl; 856 packet sl;
845 sl << "comc " << uint16 (pktlen) << uint32 (time); 857 sl << "comc " << uint16 (pktlen) << uint32 (time);
846 Send_With_Handling (&pl->socket, &sl); 858 pl->socket->send_packet (sl);
847} 859}
848 860
849 861
850/** This is a reply to a previous query. */ 862/** This is a reply to a previous query. */
851void 863void
918 * something older than the server. If we assume the client will be 930 * 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 931 * backwards compatible, having it be a later version should not be a
920 * problem. 932 * problem.
921 */ 933 */
922void 934void
923VersionCmd (char *buf, int len, client_socket * ns) 935VersionCmd (char *buf, int len, client * ns)
924{ 936{
925 char *cp; 937 char *cp;
926 char version_warning[256]; 938 char version_warning[256];
927 939
928 if (!buf) 940 if (!buf)
952 cp = strchr (cp + 1, ' '); 964 cp = strchr (cp + 1, ' ');
953 if (cp) 965 if (cp)
954 { 966 {
955 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); 967 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host);
956 968
957 snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); 969 assign (ns->version, cp + 1);
958 970
959 /* This is first implementation - i skip all beta DX clients with it
960 * Add later stuff here for other clients
961 */
962
963 /* these are old dxclients */
964 /* Version 1024 added support for singular + plural name values -
965 * requiing this minimal value reduces complexity of that code, and it
966 * has been around for a long time.
967 */
968 if (ns->sc_version < 1026) 971 if (ns->sc_version < 1026)
969 { 972 {
970 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 973 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
971 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 974 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
972 ns->send_packet (version_warning); 975 ns->send_packet (version_warning);
974 977
975 } 978 }
976} 979}
977 980
978/** sound related functions. */ 981/** sound related functions. */
979
980void 982void
981SetSound (char *buf, int len, client_socket * ns) 983SetSound (char *buf, int len, client * ns)
982{ 984{
983 ns->sound = atoi (buf); 985 ns->sound = atoi (buf);
984} 986}
985 987
986/** client wants the map resent */ 988/** client wants the map resent */
996 */ 998 */
997#if 0 999#if 0
998 /* Okay, this is MAJOR UGLY. but the only way I know how to 1000 /* Okay, this is MAJOR UGLY. but the only way I know how to
999 * clear the "cache" 1001 * clear the "cache"
1000 */ 1002 */
1001 memset (&pl->socket.lastmap, 0, sizeof (struct Map)); 1003 memset (&pl->socket->lastmap, 0, sizeof (struct Map));
1002 draw_client_map (pl->ob); 1004 draw_client_map (pl->ob);
1003#endif 1005#endif
1004} 1006}
1005 1007
1006/** 1008/**
1044/** 1046/**
1045 * Asks the client to query the user. This way, the client knows 1047 * 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) 1048 * it needs to send something back (vs just printing out a message)
1047 */ 1049 */
1048void 1050void
1049send_query (client_socket * ns, uint8 flags, char *text) 1051send_query (client * ns, uint8 flags, char *text)
1050{ 1052{
1051 char buf[MAX_BUF]; 1053 char buf[MAX_BUF];
1052 1054
1053 sprintf (buf, "query %d %s", flags, text ? text : ""); 1055 sprintf (buf, "query %d %s", flags, text ? text : "");
1054 ns->send_packet (buf); 1056 ns->send_packet (buf);
1109 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); 1111 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); 1112 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); 1113 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA);
1112 } 1114 }
1113 1115
1114 if (pl->socket.exp64) 1116 if (pl->socket->exp64)
1115 { 1117 {
1116 uint8 s; 1118 uint8 s;
1117 1119
1118 for (s = 0; s < NUM_SKILLS; s++) 1120 for (s = 0; s < NUM_SKILLS; s++)
1119 { 1121 {
1129 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; 1131 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp;
1130 } 1132 }
1131 } 1133 }
1132 } 1134 }
1133 1135
1134 if (pl->socket.exp64) 1136 if (pl->socket->exp64)
1135 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } 1137 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) }
1136 else 1138 else
1137 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } 1139 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) }
1138 1140
1139 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); 1141 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL);
1152 if (pl->run_on) 1154 if (pl->run_on)
1153 flags |= SF_RUNON; 1155 flags |= SF_RUNON;
1154 1156
1155 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); 1157 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS);
1156 1158
1157 if (pl->socket.sc_version < 1025) 1159 if (pl->socket->sc_version < 1025)
1158 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } 1160 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) }
1159 else 1161 else
1160 { 1162 {
1161 int i; 1163 int i;
1162 1164
1168 1170
1169 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); 1171 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]);
1170 } 1172 }
1171 } 1173 }
1172 1174
1173 if (pl->socket.monitor_spells) 1175 if (pl->socket->monitor_spells)
1174 { 1176 {
1175 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); 1177 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); 1178 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); 1179 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY);
1178 } 1180 }
1179 1181
1180 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ 1182 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); 1183 AddIfString (pl->socket->stats.range, buf, CS_STAT_RANGE);
1182 set_title (pl->ob, buf); 1184 set_title (pl->ob, buf);
1183 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1185 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE);
1184 1186
1185 /* Only send it away if we have some actual data */ 1187 /* Only send it away if we have some actual data */
1186 if (sl.length () > 6) 1188 if (sl.length () > 6)
1187 Send_With_Handling (&pl->socket, &sl); 1189 pl->socket->send_packet (sl);
1188} 1190}
1189 1191
1190/** 1192/**
1191 * Tells the client that here is a player it should start using. 1193 * Tells the client that here is a player it should start using.
1192 */ 1194 */
1201 sl << uint32 (pl->ob->count) 1203 sl << uint32 (pl->ob->count)
1202 << uint32 (weight) 1204 << uint32 (weight)
1203 << uint32 (pl->ob->face->number) 1205 << uint32 (pl->ob->face->number)
1204 << data8 (pl->ob->name); 1206 << data8 (pl->ob->name);
1205 1207
1206 Send_With_Handling (&pl->socket, &sl); 1208 pl->socket->send_packet (sl);
1207 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1209 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1208} 1210}
1209 1211
1210/** 1212/**
1211 * Need to send an animation sequence to the client. 1213 * Need to send an animation sequence to the client.
1213 * sent them the face yet (this can become quite costly in terms of 1215 * 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 1216 * how much we are sending - on the other hand, this should only happen
1215 * when the player logs in and picks stuff up. 1217 * when the player logs in and picks stuff up.
1216 */ 1218 */
1217void 1219void
1218esrv_send_animation (client_socket * ns, short anim_num) 1220esrv_send_animation (client * ns, short anim_num)
1219{ 1221{
1220 int i; 1222 int i;
1221 1223
1222 /* Do some checking on the anim_num we got. Note that the animations 1224 /* 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 1225 * 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)) 1245 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE))
1244 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1246 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1245 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 1247 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1246 } 1248 }
1247 1249
1248 Send_With_Handling (ns, &sl); 1250 ns->send_packet (sl);
1249 1251
1250 ns->anims_sent[anim_num] = 1; 1252 ns->anims_sent[anim_num] = 1;
1251} 1253}
1252 1254
1253 1255
1260/** 1262/**
1261 * This adds face_num to a map cell at x,y. If the client doesn't have 1263 * 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. 1264 * the face yet, we will also send it.
1263 */ 1265 */
1264static void 1266static void
1265esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap) 1267esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap)
1266{ 1268{
1267 if (newmap->cells[x][y].count >= MAP_LAYERS) 1269 if (newmap->cells[x][y].count >= MAP_LAYERS)
1268 { 1270 {
1269 LOG (llevError, "Too many faces in map cell %d %d\n", x, y); 1271 LOG (llevError, "Too many faces in map cell %d %d\n", x, y);
1270 return; 1272 return;
1290 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; 1292 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y];
1291}; 1293};
1292 1294
1293/** Checkes if map cells have changed */ 1295/** Checkes if map cells have changed */
1294static int 1296static int
1295mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap) 1297mapcellchanged (client * ns, int i, int j, struct Map *newmap)
1296{ 1298{
1297 int k; 1299 int k;
1298 1300
1299 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) 1301 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count)
1300 return 1; 1302 return 1;
1313 * cnum is the client number, cur is the the buffer we put all of 1315 * 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 1316 * this data into. we return the end of the data. layers is
1315 * how many layers of data we should back. 1317 * how many layers of data we should back.
1316 */ 1318 */
1317static uint8 * 1319static uint8 *
1318compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap) 1320compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap)
1319{ 1321{
1320 int x, y, k; 1322 int x, y, k;
1321 int face; 1323 int face;
1322 unsigned char *fcur; 1324 unsigned char *fcur;
1323 struct MapLayer layers[MAP_LAYERS]; 1325 struct MapLayer layers[MAP_LAYERS];
1431 * needs to get sent - if so, it adds the data, sending the head 1433 * 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 1434 * if needed, and returning 1. If this no data needs to get
1433 * sent, it returns zero. 1435 * sent, it returns zero.
1434 */ 1436 */
1435static int 1437static int
1436check_head (packet &sl, client_socket &ns, int ax, int ay, int layer) 1438check_head (packet &sl, client &ns, int ax, int ay, int layer)
1437{ 1439{
1438 short face_num; 1440 short face_num;
1439 1441
1440 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1442 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1441 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1443 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 1477 * the case, it seems to make more sense to have these layer values
1476 * actually match. 1478 * actually match.
1477 */ 1479 */
1478 1480
1479static int 1481static int
1480update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1482update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1481{ 1483{
1482 object *ob, *head; 1484 object *ob, *head;
1483 uint16 face_num; 1485 uint16 face_num;
1484 int bx, by, i; 1486 int bx, by, i;
1485 1487
1698 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1700 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1699 * take. 1701 * take.
1700 */ 1702 */
1701 1703
1702static inline int 1704static inline int
1703update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1705update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1704{ 1706{
1705 object *ob; 1707 object *ob;
1706 int smoothlevel; /* old face_num; */ 1708 int smoothlevel; /* old face_num; */
1707 1709
1708 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1710 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1742 * Returns the size of a data for a map square as returned by 1744 * Returns the size of a data for a map square as returned by
1743 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries 1745 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
1744 * available. 1746 * available.
1745 */ 1747 */
1746int 1748int
1747getExtendedMapInfoSize (client_socket * ns) 1749getExtendedMapInfoSize (client * ns)
1748{ 1750{
1749 int result = 0; 1751 int result = 0;
1750 1752
1751 if (ns->ext_mapinfos) 1753 if (ns->ext_mapinfos)
1752 { 1754 {
1788 uint8 eentrysize; 1790 uint8 eentrysize;
1789 uint16 ewhatstart, ewhatflag; 1791 uint16 ewhatstart, ewhatflag;
1790 uint8 extendedinfos; 1792 uint8 extendedinfos;
1791 maptile *m; 1793 maptile *m;
1792 1794
1793 client_socket &socket = pl->contr->socket; 1795 client &socket = *pl->contr->socket;
1794 1796
1795 check_map_change (pl->contr); 1797 check_map_change (pl->contr);
1796 1798
1797 packet sl; 1799 packet sl;
1798 packet esl; 1800 packet esl;
1877 * with no faces tells the client to blank out the 1879 * with no faces tells the client to blank out the
1878 * space. 1880 * space.
1879 */ 1881 */
1880 got_one = 0; 1882 got_one = 0;
1881 for (i = oldlen + 2; i < sl.length (); i++) 1883 for (i = oldlen + 2; i < sl.length (); i++)
1882 if (sl.buf[i]) 1884 if (sl[i])
1883 got_one = 1; 1885 got_one = 1;
1884 1886
1885 if (got_one && (mask & 0xf)) 1887 if (got_one && (mask & 0xf))
1886 sl.buf[oldlen + 1] = mask & 0xff; 1888 sl[oldlen + 1] = mask & 0xff;
1887 else 1889 else
1888 { /*either all faces blank, either no face at all */ 1890 { /*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 */ 1891 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1890 sl.reset (oldlen + 2); 1892 sl.reset (oldlen + 2);
1891 else 1893 else
1957 1959
1958 map_clearcell (&lastcell, 0, 0, 0, count); 1960 map_clearcell (&lastcell, 0, 0, 0, count);
1959 } 1961 }
1960 1962
1961 if ((mask & 0xf) || need_send) 1963 if ((mask & 0xf) || need_send)
1962 sl.buf[oldlen + 1] = mask & 0xff; 1964 sl[oldlen + 1] = mask & 0xff;
1963 else 1965 else
1964 sl.reset (oldlen); 1966 sl.reset (oldlen);
1965 } 1967 }
1966 else 1968 else
1967 { 1969 {
1997 mask |= 0x8; 1999 mask |= 0x8;
1998 2000
1999 if (socket.extmap) 2001 if (socket.extmap)
2000 { 2002 {
2001 *last_ext |= 0x80; 2003 *last_ext |= 0x80;
2002 last_ext = sl.buf + sl.length (); 2004 last_ext = &sl[sl.length ()];
2003 sl << uint8 (d); 2005 sl << uint8 (d);
2004 } 2006 }
2005 else 2007 else
2006 sl << uint8 (255 - 64 * d); 2008 sl << uint8 (255 - 64 * d);
2007 } 2009 }
2041 { 2043 {
2042 lastcell.stat_hp = stat_hp; 2044 lastcell.stat_hp = stat_hp;
2043 2045
2044 mask |= 0x8; 2046 mask |= 0x8;
2045 *last_ext |= 0x80; 2047 *last_ext |= 0x80;
2046 last_ext = sl.buf + sl.length (); 2048 last_ext = &sl[sl.length ()];
2047 2049
2048 sl << uint8 (5) << uint8 (stat_hp); 2050 sl << uint8 (5) << uint8 (stat_hp);
2049 2051
2050 if (stat_width > 1) 2052 if (stat_width > 1)
2051 { 2053 {
2052 *last_ext |= 0x80; 2054 *last_ext |= 0x80;
2053 last_ext = sl.buf + sl.length (); 2055 last_ext = &sl[sl.length ()];
2054 2056
2055 sl << uint8 (6) << uint8 (stat_width); 2057 sl << uint8 (6) << uint8 (stat_width);
2056 } 2058 }
2057 } 2059 }
2058 2060
2060 { 2062 {
2061 lastcell.player = player; 2063 lastcell.player = player;
2062 2064
2063 mask |= 0x8; 2065 mask |= 0x8;
2064 *last_ext |= 0x80; 2066 *last_ext |= 0x80;
2065 last_ext = sl.buf + sl.length (); 2067 last_ext = &sl[sl.length ()];
2066 2068
2067 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2069 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2068 } 2070 }
2069 2071
2070 if (lastcell.flags != flags) 2072 if (lastcell.flags != flags)
2071 { 2073 {
2072 lastcell.flags = flags; 2074 lastcell.flags = flags;
2073 2075
2074 mask |= 0x8; 2076 mask |= 0x8;
2075 *last_ext |= 0x80; 2077 *last_ext |= 0x80;
2076 last_ext = sl.buf + sl.length (); 2078 last_ext = &sl[sl.length ()];
2077 2079
2078 sl << uint8 (8) << uint8 (flags); 2080 sl << uint8 (8) << uint8 (flags);
2079 } 2081 }
2080 } 2082 }
2081 2083
2123 * space by checking the mask. If so, update the mask. 2125 * space by checking the mask. If so, update the mask.
2124 * if not, reset the len to that from before adding the mask 2126 * if not, reset the len to that from before adding the mask
2125 * value, so we don't send those bits. 2127 * value, so we don't send those bits.
2126 */ 2128 */
2127 if (mask & 0xf) 2129 if (mask & 0xf)
2128 sl.buf[oldlen + 1] = mask & 0xff; 2130 sl[oldlen + 1] = mask & 0xff;
2129 else 2131 else
2130 sl.reset (oldlen); 2132 sl.reset (oldlen);
2131 2133
2132 if (emask & 0xf) 2134 if (emask & 0xf)
2133 esl.buf[eoldlen + 1] = emask & 0xff; 2135 esl[eoldlen + 1] = emask & 0xff;
2134 else 2136 else
2135 esl.reset (eoldlen); 2137 esl.reset (eoldlen);
2136 } /* else this is a viewable space */ 2138 } /* else this is a viewable space */
2137 } /* for x loop */ 2139 } /* for x loop */
2138 } /* for y loop */ 2140 } /* for y loop */
2144 { 2146 {
2145 /* No map data will follow, so don't say the client 2147 /* No map data will follow, so don't say the client
2146 * it doesn't need draw! 2148 * it doesn't need draw!
2147 */ 2149 */
2148 ewhatflag &= (~EMI_NOREDRAW); 2150 ewhatflag &= (~EMI_NOREDRAW);
2149 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2151 esl[ewhatstart + 1] = ewhatflag & 0xff;
2150 } 2152 }
2151 2153
2152 if (esl.length () > estartlen) 2154 if (esl.length () > estartlen)
2153 Send_With_Handling (&socket, &esl); 2155 socket.send_packet (esl);
2154 } 2156 }
2155 2157
2156 if (sl.length () > startlen || socket.sent_scroll) 2158 if (sl.length () > startlen || socket.sent_scroll)
2157 { 2159 {
2158 Send_With_Handling (&socket, &sl); 2160 socket.send_packet (sl);
2159 socket.sent_scroll = 0; 2161 socket.sent_scroll = 0;
2160 } 2162 }
2161} 2163}
2162 2164
2163/** 2165/**
2189 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) 2191 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY)
2190 return; 2192 return;
2191 2193
2192 memset (&newmap, 0, sizeof (struct Map)); 2194 memset (&newmap, 0, sizeof (struct Map));
2193 2195
2194 for (j = (pl->y - pl->contr->socket.mapy / 2); j < (pl->y + (pl->contr->socket.mapy + 1) / 2); j++) 2196 for (j = (pl->y - pl->contr->socket->mapy / 2); j < (pl->y + (pl->contr->socket->mapy + 1) / 2); j++)
2195 { 2197 {
2196 for (i = (pl->x - pl->contr->socket.mapx / 2); i < (pl->x + (pl->contr->socket.mapx + 1) / 2); i++) 2198 for (i = (pl->x - pl->contr->socket->mapx / 2); i < (pl->x + (pl->contr->socket->mapx + 1) / 2); i++)
2197 { 2199 {
2198 ax = i; 2200 ax = i;
2199 ay = j; 2201 ay = j;
2200 m = pm; 2202 m = pm;
2201 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); 2203 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay);
2233 2235
2234/*****************************************************************************/ 2236/*****************************************************************************/
2235void 2237void
2236send_plugin_custom_message (object *pl, char *buf) 2238send_plugin_custom_message (object *pl, char *buf)
2237{ 2239{
2238 pl->contr->socket.send_packet (buf); 2240 pl->contr->socket->send_packet (buf);
2239} 2241}
2240 2242
2241/** 2243/**
2242 * This sends the skill number to name mapping. We ignore 2244 * This sends the skill number to name mapping. We ignore
2243 * the params - we always send the same info no matter what. 2245 * the params - we always send the same info no matter what.
2244 */ 2246 */
2245void 2247void
2246send_skill_info (client_socket *ns, char *params) 2248send_skill_info (client *ns, char *params)
2247{ 2249{
2248 packet sl; 2250 packet sl;
2249 sl << "replyinfo skill_info\n"; 2251 sl << "replyinfo skill_info\n";
2250 2252
2251 for (int i = 1; i < NUM_SKILLS; i++) 2253 for (int i = 1; i < NUM_SKILLS; i++)
2255 { 2257 {
2256 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2258 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2257 fatal (0); 2259 fatal (0);
2258 } 2260 }
2259 2261
2260 Send_With_Handling (ns, &sl); 2262 ns->send_packet (sl);
2261} 2263}
2262 2264
2263/** 2265/**
2264 * This sends the spell path to name mapping. We ignore 2266 * This sends the spell path to name mapping. We ignore
2265 * the params - we always send the same info no matter what. 2267 * the params - we always send the same info no matter what.
2266 */ 2268 */
2267void 2269void
2268send_spell_paths (client_socket * ns, char *params) 2270send_spell_paths (client * ns, char *params)
2269{ 2271{
2270 packet sl; 2272 packet sl;
2271 2273
2272 sl << "replyinfo spell_paths\n"; 2274 sl << "replyinfo spell_paths\n";
2273 2275
2278 { 2280 {
2279 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2281 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2280 fatal (0); 2282 fatal (0);
2281 } 2283 }
2282 2284
2283 Send_With_Handling (ns, &sl); 2285 ns->send_packet (sl);
2284} 2286}
2285 2287
2286/** 2288/**
2287 * This looks for any spells the player may have that have changed their stats. 2289 * 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 2290 * it then sends an updspell packet for each spell that has changed in this way
2289 */ 2291 */
2290void 2292void
2291esrv_update_spells (player *pl) 2293esrv_update_spells (player *pl)
2292{ 2294{
2293 if (!pl->socket.monitor_spells) 2295 if (!pl->socket->monitor_spells)
2294 return; 2296 return;
2295 2297
2296 for (object *spell = pl->ob->inv; spell; spell = spell->below) 2298 for (object *spell = pl->ob->inv; spell; spell = spell->below)
2297 { 2299 {
2298 if (spell->type == SPELL) 2300 if (spell->type == SPELL)
2328 2330
2329 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2331 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2330 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2332 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2331 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2333 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2332 2334
2333 Send_With_Handling (&pl->socket, &sl); 2335 pl->socket->send_packet (sl);
2334 } 2336 }
2335 } 2337 }
2336 } 2338 }
2337} 2339}
2338 2340
2339void 2341void
2340esrv_remove_spell (player *pl, object *spell) 2342esrv_remove_spell (player *pl, object *spell)
2341{ 2343{
2342 if (!pl->socket.monitor_spells) 2344 if (!pl->socket->monitor_spells)
2343 return; 2345 return;
2344 2346
2345 if (!pl || !spell || spell->env != pl->ob) 2347 if (!pl || !spell || spell->env != pl->ob)
2346 { 2348 {
2347 LOG (llevError, "Invalid call to esrv_remove_spell"); 2349 LOG (llevError, "Invalid call to esrv_remove_spell");
2351 packet sl; 2353 packet sl;
2352 2354
2353 sl << "delspell " 2355 sl << "delspell "
2354 << uint32 (spell->count); 2356 << uint32 (spell->count);
2355 2357
2356 Send_With_Handling (&pl->socket, &sl); 2358 pl->socket->send_packet (sl);
2357} 2359}
2358 2360
2359/* appends the spell *spell to the Socklist we will send the data to. */ 2361/* appends the spell *spell to the Socklist we will send the data to. */
2360static void 2362static void
2361append_spell (player *pl, packet &sl, object *spell) 2363append_spell (player *pl, packet &sl, object *spell)
2409 { 2411 {
2410 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); 2412 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player");
2411 return; 2413 return;
2412 } 2414 }
2413 2415
2414 if (!pl->socket.monitor_spells) 2416 if (!pl->socket->monitor_spells)
2415 return; 2417 return;
2416 2418
2417 packet sl; 2419 packet sl;
2418 2420
2419 sl << "addspell "; 2421 sl << "addspell ";
2438 if (spell->type != SPELL) 2440 if (spell->type != SPELL)
2439 continue; 2441 continue;
2440 2442
2441 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2443 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2442 { 2444 {
2443 Send_With_Handling (&pl->socket, &sl); 2445 pl->socket->send_packet (sl);
2444 2446
2445 sl.reset (); 2447 sl.reset ();
2446 sl << "addspell "; 2448 sl << "addspell ";
2447 } 2449 }
2448 2450
2462 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2464 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2463 fatal (0); 2465 fatal (0);
2464 } 2466 }
2465 2467
2466 /* finally, we can send the packet */ 2468 /* finally, we can send the packet */
2467 Send_With_Handling (&pl->socket, &sl); 2469 pl->socket->send_packet (sl);
2468
2469} 2470}
2470 2471

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines