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.37 by root, Thu Dec 14 20:39:54 2006 UTC

93 -1, /* life stealing */ 93 -1, /* life stealing */
94 -1 /* Disease - not fully done yet */ 94 -1 /* Disease - not fully done yet */
95}; 95};
96 96
97static void 97static void
98socket_map_scroll (NewSocket * ns, int dx, int dy) 98socket_map_scroll (client_socket * ns, int dx, int dy)
99{ 99{
100 struct Map newmap; 100 struct Map newmap;
101 int x, y, mx, my; 101 int x, y, mx, my;
102 102
103 { 103 {
153} 153}
154 154
155static void 155static void
156clear_map (player *pl) 156clear_map (player *pl)
157{ 157{
158 NewSocket & socket = pl->socket; 158 client_socket &socket = *pl->socket;
159 159
160 memset (&socket.lastmap, 0, sizeof (socket.lastmap)); 160 memset (&socket.lastmap, 0, sizeof (socket.lastmap));
161 161
162 if (socket.newmapcmd == 1) 162 if (socket.newmapcmd == 1)
163 socket.send_packet ("newmap"); 163 socket.send_packet ("newmap");
168 168
169/** check for map change and send new map data */ 169/** check for map change and send new map data */
170static void 170static void
171check_map_change (player *pl) 171check_map_change (player *pl)
172{ 172{
173 NewSocket & socket = pl->socket; 173 client_socket &socket = *pl->socket;
174 object *ob = pl->ob; 174 object *ob = pl->ob;
175 char buf[MAX_BUF]; /* eauugggh */ 175 char buf[MAX_BUF]; /* eauugggh */
176 176
177 if (socket.current_map != ob->map) 177 if (socket.current_map != ob->map)
178 { 178 {
249 buf += 8; 249 buf += 8;
250 250
251 // initial map and its origin 251 // initial map and its origin
252 maptile *map = pl->ob->map; 252 maptile *map = pl->ob->map;
253 sint16 dx, dy; 253 sint16 dx, dy;
254 int mapx = pl->socket.mapx / 2 - pl->ob->x; 254 int mapx = pl->socket->mapx / 2 - pl->ob->x;
255 int mapy = pl->socket.mapy / 2 - pl->ob->y; 255 int mapy = pl->socket->mapy / 2 - pl->ob->y;
256 int max_distance = 8; // limit maximum path length to something generous 256 int max_distance = 8; // limit maximum path length to something generous
257 257
258 while (*buf && map && max_distance) 258 while (*buf && map && max_distance)
259 { 259 {
260 int dir = *buf++; 260 int dir = *buf++;
311 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); 311 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token);
312 } 312 }
313 else 313 else
314 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); 314 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token);
315 315
316 pl->socket.send_packet (bigbuf); 316 pl->socket->send_packet (bigbuf);
317} 317}
318 318
319/** This is the Setup cmd - easy first implementation */ 319/** This is the Setup cmd - easy first implementation */
320void 320void
321SetUp (char *buf, int len, NewSocket * ns) 321SetUp (char *buf, int len, client_socket * ns)
322{ 322{
323 int s, slen; 323 int s, slen;
324 char *cmd, *param, cmdback[HUGE_BUF]; 324 char *cmd, *param, cmdback[HUGE_BUF];
325 325
326 /* run through the cmds of setup 326 /* run through the cmds of setup
536 * This is what takes care of it. We tell the client how things worked out. 536 * 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, 537 * 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. 538 * it either has to be here or init_sockets needs to be exported.
539 */ 539 */
540void 540void
541AddMeCmd (char *buf, int len, NewSocket * ns) 541AddMeCmd (char *buf, int len, client_socket * ns)
542{ 542{
543 Settings oldsettings; 543 Settings oldsettings;
544 544
545 oldsettings = settings; 545 oldsettings = settings;
546 if (ns->status != Ns_Add || add_player (ns)) 546 if (ns->status != Ns_Add || add_player (ns))
547 ns->send_packet ("addme_failed"); 547 ns->send_packet ("addme_failed");
548 else 548 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"); 549 ns->send_packet ("addme_success");
556 socket_info.nconns--;
557 ns->status = Ns_Avail;
558 }
559 550
560 settings = oldsettings; 551 settings = oldsettings;
561} 552}
562 553
563/** Reply to ExtendedInfos command */ 554/** Reply to ExtendedInfos command */
564void 555void
565ToggleExtendedInfos (char *buf, int len, NewSocket * ns) 556ToggleExtendedInfos (char *buf, int len, client_socket * ns)
566{ 557{
567 char cmdback[MAX_BUF]; 558 char cmdback[MAX_BUF];
568 char command[50]; 559 char command[50];
569 int info, nextinfo; 560 int info, nextinfo;
570 561
621#define MSG_TYPE_MONUMENT 5 612#define MSG_TYPE_MONUMENT 5
622#define MSG_TYPE_SCRIPTED_DIALOG 6*/ 613#define MSG_TYPE_SCRIPTED_DIALOG 6*/
623 614
624/** Reply to ExtendedInfos command */ 615/** Reply to ExtendedInfos command */
625void 616void
626ToggleExtendedText (char *buf, int len, NewSocket * ns) 617ToggleExtendedText (char *buf, int len, client_socket * ns)
627{ 618{
628 char cmdback[MAX_BUF]; 619 char cmdback[MAX_BUF];
629 char temp[10]; 620 char temp[10];
630 char command[50]; 621 char command[50];
631 int info, nextinfo, i, flag; 622 int info, nextinfo, i, flag;
682 * a piece of data from us that we know the client wants. So 673 * 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 674 * if we know the client wants it, might as well push it to the
684 * client. 675 * client.
685 */ 676 */
686static void 677static void
687SendSmooth (NewSocket * ns, uint16 face) 678SendSmooth (client_socket * ns, uint16 face)
688{ 679{
689 uint16 smoothface; 680 uint16 smoothface;
690 681
691 /* If we can't find a face, return and set it so we won't try to send this 682 /* If we can't find a face, return and set it so we won't try to send this
692 * again. 683 * again.
708 699
709 sl << "smooth " 700 sl << "smooth "
710 << uint16 (face) 701 << uint16 (face)
711 << uint16 (smoothface); 702 << uint16 (smoothface);
712 703
713 Send_With_Handling (ns, &sl); 704 ns->send_packet (sl);
714} 705}
715 706
716 /** 707 /**
717 * Tells client the picture it has to use 708 * Tells client the picture it has to use
718 * to smooth a picture number given as argument. 709 * to smooth a picture number given as argument.
719 */ 710 */
720void 711void
721AskSmooth (char *buf, int len, NewSocket * ns) 712AskSmooth (char *buf, int len, client_socket * ns)
722{ 713{
723 uint16 facenbr; 714 uint16 facenbr;
724 715
725 facenbr = atoi (buf); 716 facenbr = atoi (buf);
726 SendSmooth (ns, facenbr); 717 SendSmooth (ns, facenbr);
841 832
842 /* Send confirmation of command execution now */ 833 /* Send confirmation of command execution now */
843 834
844 packet sl; 835 packet sl;
845 sl << "comc " << uint16 (pktlen) << uint32 (time); 836 sl << "comc " << uint16 (pktlen) << uint32 (time);
846 Send_With_Handling (&pl->socket, &sl); 837 pl->socket->send_packet (sl);
847} 838}
848 839
849 840
850/** This is a reply to a previous query. */ 841/** This is a reply to a previous query. */
851void 842void
918 * something older than the server. If we assume the client will be 909 * 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 910 * backwards compatible, having it be a later version should not be a
920 * problem. 911 * problem.
921 */ 912 */
922void 913void
923VersionCmd (char *buf, int len, NewSocket * ns) 914VersionCmd (char *buf, int len, client_socket * ns)
924{ 915{
925 char *cp; 916 char *cp;
926 char version_warning[256]; 917 char version_warning[256];
927 918
928 if (!buf) 919 if (!buf)
976} 967}
977 968
978/** sound related functions. */ 969/** sound related functions. */
979 970
980void 971void
981SetSound (char *buf, int len, NewSocket * ns) 972SetSound (char *buf, int len, client_socket * ns)
982{ 973{
983 ns->sound = atoi (buf); 974 ns->sound = atoi (buf);
984} 975}
985 976
986/** client wants the map resent */ 977/** client wants the map resent */
996 */ 987 */
997#if 0 988#if 0
998 /* Okay, this is MAJOR UGLY. but the only way I know how to 989 /* Okay, this is MAJOR UGLY. but the only way I know how to
999 * clear the "cache" 990 * clear the "cache"
1000 */ 991 */
1001 memset (&pl->socket.lastmap, 0, sizeof (struct Map)); 992 memset (&pl->socket->lastmap, 0, sizeof (struct Map));
1002 draw_client_map (pl->ob); 993 draw_client_map (pl->ob);
1003#endif 994#endif
1004} 995}
1005 996
1006/** 997/**
1044/** 1035/**
1045 * Asks the client to query the user. This way, the client knows 1036 * 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) 1037 * it needs to send something back (vs just printing out a message)
1047 */ 1038 */
1048void 1039void
1049send_query (NewSocket * ns, uint8 flags, char *text) 1040send_query (client_socket * ns, uint8 flags, char *text)
1050{ 1041{
1051 char buf[MAX_BUF]; 1042 char buf[MAX_BUF];
1052 1043
1053 sprintf (buf, "query %d %s", flags, text ? text : ""); 1044 sprintf (buf, "query %d %s", flags, text ? text : "");
1054 ns->send_packet (buf); 1045 ns->send_packet (buf);
1109 AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); 1100 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); 1101 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); 1102 AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA);
1112 } 1103 }
1113 1104
1114 if (pl->socket.exp64) 1105 if (pl->socket->exp64)
1115 { 1106 {
1116 uint8 s; 1107 uint8 s;
1117 1108
1118 for (s = 0; s < NUM_SKILLS; s++) 1109 for (s = 0; s < NUM_SKILLS; s++)
1119 { 1110 {
1129 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; 1120 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp;
1130 } 1121 }
1131 } 1122 }
1132 } 1123 }
1133 1124
1134 if (pl->socket.exp64) 1125 if (pl->socket->exp64)
1135 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } 1126 { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) }
1136 else 1127 else
1137 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } 1128 { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) }
1138 1129
1139 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); 1130 AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL);
1152 if (pl->run_on) 1143 if (pl->run_on)
1153 flags |= SF_RUNON; 1144 flags |= SF_RUNON;
1154 1145
1155 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); 1146 AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS);
1156 1147
1157 if (pl->socket.sc_version < 1025) 1148 if (pl->socket->sc_version < 1025)
1158 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } 1149 { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) }
1159 else 1150 else
1160 { 1151 {
1161 int i; 1152 int i;
1162 1153
1168 1159
1169 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); 1160 AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]);
1170 } 1161 }
1171 } 1162 }
1172 1163
1173 if (pl->socket.monitor_spells) 1164 if (pl->socket->monitor_spells)
1174 { 1165 {
1175 AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); 1166 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); 1167 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); 1168 AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY);
1178 } 1169 }
1179 1170
1180 rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ 1171 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); 1172 AddIfString (pl->socket->stats.range, buf, CS_STAT_RANGE);
1182 set_title (pl->ob, buf); 1173 set_title (pl->ob, buf);
1183 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1174 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE);
1184 1175
1185 /* Only send it away if we have some actual data */ 1176 /* Only send it away if we have some actual data */
1186 if (sl.length () > 6) 1177 if (sl.length () > 6)
1187 Send_With_Handling (&pl->socket, &sl); 1178 pl->socket->send_packet (sl);
1188} 1179}
1189 1180
1190/** 1181/**
1191 * Tells the client that here is a player it should start using. 1182 * Tells the client that here is a player it should start using.
1192 */ 1183 */
1201 sl << uint32 (pl->ob->count) 1192 sl << uint32 (pl->ob->count)
1202 << uint32 (weight) 1193 << uint32 (weight)
1203 << uint32 (pl->ob->face->number) 1194 << uint32 (pl->ob->face->number)
1204 << data8 (pl->ob->name); 1195 << data8 (pl->ob->name);
1205 1196
1206 Send_With_Handling (&pl->socket, &sl); 1197 pl->socket->send_packet (sl);
1207 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1198 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1208} 1199}
1209 1200
1210/** 1201/**
1211 * Need to send an animation sequence to the client. 1202 * Need to send an animation sequence to the client.
1213 * sent them the face yet (this can become quite costly in terms of 1204 * 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 1205 * how much we are sending - on the other hand, this should only happen
1215 * when the player logs in and picks stuff up. 1206 * when the player logs in and picks stuff up.
1216 */ 1207 */
1217void 1208void
1218esrv_send_animation (NewSocket * ns, short anim_num) 1209esrv_send_animation (client_socket * ns, short anim_num)
1219{ 1210{
1220 int i; 1211 int i;
1221 1212
1222 /* Do some checking on the anim_num we got. Note that the animations 1213 /* 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 1214 * 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)) 1234 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE))
1244 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1235 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1245 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 1236 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1246 } 1237 }
1247 1238
1248 Send_With_Handling (ns, &sl); 1239 ns->send_packet (sl);
1249 1240
1250 ns->anims_sent[anim_num] = 1; 1241 ns->anims_sent[anim_num] = 1;
1251} 1242}
1252 1243
1253 1244
1260/** 1251/**
1261 * This adds face_num to a map cell at x,y. If the client doesn't have 1252 * 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. 1253 * the face yet, we will also send it.
1263 */ 1254 */
1264static void 1255static void
1265esrv_map_setbelow (NewSocket * ns, int x, int y, short face_num, struct Map *newmap) 1256esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap)
1266{ 1257{
1267 if (newmap->cells[x][y].count >= MAP_LAYERS) 1258 if (newmap->cells[x][y].count >= MAP_LAYERS)
1268 { 1259 {
1269 LOG (llevError, "Too many faces in map cell %d %d\n", x, y); 1260 LOG (llevError, "Too many faces in map cell %d %d\n", x, y);
1270 return; 1261 return;
1290 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; 1281 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y];
1291}; 1282};
1292 1283
1293/** Checkes if map cells have changed */ 1284/** Checkes if map cells have changed */
1294static int 1285static int
1295mapcellchanged (NewSocket * ns, int i, int j, struct Map *newmap) 1286mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap)
1296{ 1287{
1297 int k; 1288 int k;
1298 1289
1299 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) 1290 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count)
1300 return 1; 1291 return 1;
1313 * cnum is the client number, cur is the the buffer we put all of 1304 * 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 1305 * this data into. we return the end of the data. layers is
1315 * how many layers of data we should back. 1306 * how many layers of data we should back.
1316 */ 1307 */
1317static uint8 * 1308static uint8 *
1318compactlayer (NewSocket * ns, unsigned char *cur, int numlayers, struct Map *newmap) 1309compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap)
1319{ 1310{
1320 int x, y, k; 1311 int x, y, k;
1321 int face; 1312 int face;
1322 unsigned char *fcur; 1313 unsigned char *fcur;
1323 struct MapLayer layers[MAP_LAYERS]; 1314 struct MapLayer layers[MAP_LAYERS];
1431 * needs to get sent - if so, it adds the data, sending the head 1422 * 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 1423 * if needed, and returning 1. If this no data needs to get
1433 * sent, it returns zero. 1424 * sent, it returns zero.
1434 */ 1425 */
1435static int 1426static int
1436check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer) 1427check_head (packet &sl, client_socket &ns, int ax, int ay, int layer)
1437{ 1428{
1438 short face_num; 1429 short face_num;
1439 1430
1440 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1431 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1441 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1432 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 1466 * the case, it seems to make more sense to have these layer values
1476 * actually match. 1467 * actually match.
1477 */ 1468 */
1478 1469
1479static int 1470static int
1480update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1471update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1481{ 1472{
1482 object *ob, *head; 1473 object *ob, *head;
1483 uint16 face_num; 1474 uint16 face_num;
1484 int bx, by, i; 1475 int bx, by, i;
1485 1476
1698 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1689 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1699 * take. 1690 * take.
1700 */ 1691 */
1701 1692
1702static inline int 1693static inline int
1703update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1694update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1704{ 1695{
1705 object *ob; 1696 object *ob;
1706 int smoothlevel; /* old face_num; */ 1697 int smoothlevel; /* old face_num; */
1707 1698
1708 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1699 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1742 * Returns the size of a data for a map square as returned by 1733 * Returns the size of a data for a map square as returned by
1743 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries 1734 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
1744 * available. 1735 * available.
1745 */ 1736 */
1746int 1737int
1747getExtendedMapInfoSize (NewSocket * ns) 1738getExtendedMapInfoSize (client_socket * ns)
1748{ 1739{
1749 int result = 0; 1740 int result = 0;
1750 1741
1751 if (ns->ext_mapinfos) 1742 if (ns->ext_mapinfos)
1752 { 1743 {
1788 uint8 eentrysize; 1779 uint8 eentrysize;
1789 uint16 ewhatstart, ewhatflag; 1780 uint16 ewhatstart, ewhatflag;
1790 uint8 extendedinfos; 1781 uint8 extendedinfos;
1791 maptile *m; 1782 maptile *m;
1792 1783
1793 NewSocket &socket = pl->contr->socket; 1784 client_socket &socket = *pl->contr->socket;
1794 1785
1795 check_map_change (pl->contr); 1786 check_map_change (pl->contr);
1796 1787
1797 packet sl; 1788 packet sl;
1798 packet esl; 1789 packet esl;
1877 * with no faces tells the client to blank out the 1868 * with no faces tells the client to blank out the
1878 * space. 1869 * space.
1879 */ 1870 */
1880 got_one = 0; 1871 got_one = 0;
1881 for (i = oldlen + 2; i < sl.length (); i++) 1872 for (i = oldlen + 2; i < sl.length (); i++)
1882 if (sl.buf[i]) 1873 if (sl[i])
1883 got_one = 1; 1874 got_one = 1;
1884 1875
1885 if (got_one && (mask & 0xf)) 1876 if (got_one && (mask & 0xf))
1886 sl.buf[oldlen + 1] = mask & 0xff; 1877 sl[oldlen + 1] = mask & 0xff;
1887 else 1878 else
1888 { /*either all faces blank, either no face at all */ 1879 { /*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 */ 1880 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1890 sl.reset (oldlen + 2); 1881 sl.reset (oldlen + 2);
1891 else 1882 else
1957 1948
1958 map_clearcell (&lastcell, 0, 0, 0, count); 1949 map_clearcell (&lastcell, 0, 0, 0, count);
1959 } 1950 }
1960 1951
1961 if ((mask & 0xf) || need_send) 1952 if ((mask & 0xf) || need_send)
1962 sl.buf[oldlen + 1] = mask & 0xff; 1953 sl[oldlen + 1] = mask & 0xff;
1963 else 1954 else
1964 sl.reset (oldlen); 1955 sl.reset (oldlen);
1965 } 1956 }
1966 else 1957 else
1967 { 1958 {
1997 mask |= 0x8; 1988 mask |= 0x8;
1998 1989
1999 if (socket.extmap) 1990 if (socket.extmap)
2000 { 1991 {
2001 *last_ext |= 0x80; 1992 *last_ext |= 0x80;
2002 last_ext = sl.buf + sl.length (); 1993 last_ext = &sl[sl.length ()];
2003 sl << uint8 (d); 1994 sl << uint8 (d);
2004 } 1995 }
2005 else 1996 else
2006 sl << uint8 (255 - 64 * d); 1997 sl << uint8 (255 - 64 * d);
2007 } 1998 }
2041 { 2032 {
2042 lastcell.stat_hp = stat_hp; 2033 lastcell.stat_hp = stat_hp;
2043 2034
2044 mask |= 0x8; 2035 mask |= 0x8;
2045 *last_ext |= 0x80; 2036 *last_ext |= 0x80;
2046 last_ext = sl.buf + sl.length (); 2037 last_ext = &sl[sl.length ()];
2047 2038
2048 sl << uint8 (5) << uint8 (stat_hp); 2039 sl << uint8 (5) << uint8 (stat_hp);
2049 2040
2050 if (stat_width > 1) 2041 if (stat_width > 1)
2051 { 2042 {
2052 *last_ext |= 0x80; 2043 *last_ext |= 0x80;
2053 last_ext = sl.buf + sl.length (); 2044 last_ext = &sl[sl.length ()];
2054 2045
2055 sl << uint8 (6) << uint8 (stat_width); 2046 sl << uint8 (6) << uint8 (stat_width);
2056 } 2047 }
2057 } 2048 }
2058 2049
2060 { 2051 {
2061 lastcell.player = player; 2052 lastcell.player = player;
2062 2053
2063 mask |= 0x8; 2054 mask |= 0x8;
2064 *last_ext |= 0x80; 2055 *last_ext |= 0x80;
2065 last_ext = sl.buf + sl.length (); 2056 last_ext = &sl[sl.length ()];
2066 2057
2067 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2058 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2068 } 2059 }
2069 2060
2070 if (lastcell.flags != flags) 2061 if (lastcell.flags != flags)
2071 { 2062 {
2072 lastcell.flags = flags; 2063 lastcell.flags = flags;
2073 2064
2074 mask |= 0x8; 2065 mask |= 0x8;
2075 *last_ext |= 0x80; 2066 *last_ext |= 0x80;
2076 last_ext = sl.buf + sl.length (); 2067 last_ext = &sl[sl.length ()];
2077 2068
2078 sl << uint8 (8) << uint8 (flags); 2069 sl << uint8 (8) << uint8 (flags);
2079 } 2070 }
2080 } 2071 }
2081 2072
2123 * space by checking the mask. If so, update the mask. 2114 * space by checking the mask. If so, update the mask.
2124 * if not, reset the len to that from before adding the mask 2115 * if not, reset the len to that from before adding the mask
2125 * value, so we don't send those bits. 2116 * value, so we don't send those bits.
2126 */ 2117 */
2127 if (mask & 0xf) 2118 if (mask & 0xf)
2128 sl.buf[oldlen + 1] = mask & 0xff; 2119 sl[oldlen + 1] = mask & 0xff;
2129 else 2120 else
2130 sl.reset (oldlen); 2121 sl.reset (oldlen);
2131 2122
2132 if (emask & 0xf) 2123 if (emask & 0xf)
2133 esl.buf[eoldlen + 1] = emask & 0xff; 2124 esl[eoldlen + 1] = emask & 0xff;
2134 else 2125 else
2135 esl.reset (eoldlen); 2126 esl.reset (eoldlen);
2136 } /* else this is a viewable space */ 2127 } /* else this is a viewable space */
2137 } /* for x loop */ 2128 } /* for x loop */
2138 } /* for y loop */ 2129 } /* for y loop */
2144 { 2135 {
2145 /* No map data will follow, so don't say the client 2136 /* No map data will follow, so don't say the client
2146 * it doesn't need draw! 2137 * it doesn't need draw!
2147 */ 2138 */
2148 ewhatflag &= (~EMI_NOREDRAW); 2139 ewhatflag &= (~EMI_NOREDRAW);
2149 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2140 esl[ewhatstart + 1] = ewhatflag & 0xff;
2150 } 2141 }
2151 2142
2152 if (esl.length () > estartlen) 2143 if (esl.length () > estartlen)
2153 Send_With_Handling (&socket, &esl); 2144 socket.send_packet (esl);
2154 } 2145 }
2155 2146
2156 if (sl.length () > startlen || socket.sent_scroll) 2147 if (sl.length () > startlen || socket.sent_scroll)
2157 { 2148 {
2158 Send_With_Handling (&socket, &sl); 2149 socket.send_packet (sl);
2159 socket.sent_scroll = 0; 2150 socket.sent_scroll = 0;
2160 } 2151 }
2161} 2152}
2162 2153
2163/** 2154/**
2189 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) 2180 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY)
2190 return; 2181 return;
2191 2182
2192 memset (&newmap, 0, sizeof (struct Map)); 2183 memset (&newmap, 0, sizeof (struct Map));
2193 2184
2194 for (j = (pl->y - pl->contr->socket.mapy / 2); j < (pl->y + (pl->contr->socket.mapy + 1) / 2); j++) 2185 for (j = (pl->y - pl->contr->socket->mapy / 2); j < (pl->y + (pl->contr->socket->mapy + 1) / 2); j++)
2195 { 2186 {
2196 for (i = (pl->x - pl->contr->socket.mapx / 2); i < (pl->x + (pl->contr->socket.mapx + 1) / 2); i++) 2187 for (i = (pl->x - pl->contr->socket->mapx / 2); i < (pl->x + (pl->contr->socket->mapx + 1) / 2); i++)
2197 { 2188 {
2198 ax = i; 2189 ax = i;
2199 ay = j; 2190 ay = j;
2200 m = pm; 2191 m = pm;
2201 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); 2192 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay);
2233 2224
2234/*****************************************************************************/ 2225/*****************************************************************************/
2235void 2226void
2236send_plugin_custom_message (object *pl, char *buf) 2227send_plugin_custom_message (object *pl, char *buf)
2237{ 2228{
2238 pl->contr->socket.send_packet (buf); 2229 pl->contr->socket->send_packet (buf);
2239} 2230}
2240 2231
2241/** 2232/**
2242 * This sends the skill number to name mapping. We ignore 2233 * This sends the skill number to name mapping. We ignore
2243 * the params - we always send the same info no matter what. 2234 * the params - we always send the same info no matter what.
2244 */ 2235 */
2245void 2236void
2246send_skill_info (NewSocket *ns, char *params) 2237send_skill_info (client_socket *ns, char *params)
2247{ 2238{
2248 packet sl; 2239 packet sl;
2249 sl << "replyinfo skill_info\n"; 2240 sl << "replyinfo skill_info\n";
2250 2241
2251 for (int i = 1; i < NUM_SKILLS; i++) 2242 for (int i = 1; i < NUM_SKILLS; i++)
2255 { 2246 {
2256 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2247 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2257 fatal (0); 2248 fatal (0);
2258 } 2249 }
2259 2250
2260 Send_With_Handling (ns, &sl); 2251 ns->send_packet (sl);
2261} 2252}
2262 2253
2263/** 2254/**
2264 * This sends the spell path to name mapping. We ignore 2255 * This sends the spell path to name mapping. We ignore
2265 * the params - we always send the same info no matter what. 2256 * the params - we always send the same info no matter what.
2266 */ 2257 */
2267void 2258void
2268send_spell_paths (NewSocket * ns, char *params) 2259send_spell_paths (client_socket * ns, char *params)
2269{ 2260{
2270 packet sl; 2261 packet sl;
2271 2262
2272 sl << "replyinfo spell_paths\n"; 2263 sl << "replyinfo spell_paths\n";
2273 2264
2278 { 2269 {
2279 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2270 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2280 fatal (0); 2271 fatal (0);
2281 } 2272 }
2282 2273
2283 Send_With_Handling (ns, &sl); 2274 ns->send_packet (sl);
2284} 2275}
2285 2276
2286/** 2277/**
2287 * This looks for any spells the player may have that have changed their stats. 2278 * 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 2279 * it then sends an updspell packet for each spell that has changed in this way
2289 */ 2280 */
2290void 2281void
2291esrv_update_spells (player *pl) 2282esrv_update_spells (player *pl)
2292{ 2283{
2293 if (!pl->socket.monitor_spells) 2284 if (!pl->socket->monitor_spells)
2294 return; 2285 return;
2295 2286
2296 for (object *spell = pl->ob->inv; spell; spell = spell->below) 2287 for (object *spell = pl->ob->inv; spell; spell = spell->below)
2297 { 2288 {
2298 if (spell->type == SPELL) 2289 if (spell->type == SPELL)
2328 2319
2329 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2320 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2330 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2321 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2331 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2322 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2332 2323
2333 Send_With_Handling (&pl->socket, &sl); 2324 pl->socket->send_packet (sl);
2334 } 2325 }
2335 } 2326 }
2336 } 2327 }
2337} 2328}
2338 2329
2339void 2330void
2340esrv_remove_spell (player *pl, object *spell) 2331esrv_remove_spell (player *pl, object *spell)
2341{ 2332{
2342 if (!pl->socket.monitor_spells) 2333 if (!pl->socket->monitor_spells)
2343 return; 2334 return;
2344 2335
2345 if (!pl || !spell || spell->env != pl->ob) 2336 if (!pl || !spell || spell->env != pl->ob)
2346 { 2337 {
2347 LOG (llevError, "Invalid call to esrv_remove_spell"); 2338 LOG (llevError, "Invalid call to esrv_remove_spell");
2351 packet sl; 2342 packet sl;
2352 2343
2353 sl << "delspell " 2344 sl << "delspell "
2354 << uint32 (spell->count); 2345 << uint32 (spell->count);
2355 2346
2356 Send_With_Handling (&pl->socket, &sl); 2347 pl->socket->send_packet (sl);
2357} 2348}
2358 2349
2359/* appends the spell *spell to the Socklist we will send the data to. */ 2350/* appends the spell *spell to the Socklist we will send the data to. */
2360static void 2351static void
2361append_spell (player *pl, packet &sl, object *spell) 2352append_spell (player *pl, packet &sl, object *spell)
2409 { 2400 {
2410 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); 2401 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player");
2411 return; 2402 return;
2412 } 2403 }
2413 2404
2414 if (!pl->socket.monitor_spells) 2405 if (!pl->socket->monitor_spells)
2415 return; 2406 return;
2416 2407
2417 packet sl; 2408 packet sl;
2418 2409
2419 sl << "addspell "; 2410 sl << "addspell ";
2438 if (spell->type != SPELL) 2429 if (spell->type != SPELL)
2439 continue; 2430 continue;
2440 2431
2441 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2432 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2442 { 2433 {
2443 Send_With_Handling (&pl->socket, &sl); 2434 pl->socket->send_packet (sl);
2444 2435
2445 sl.reset (); 2436 sl.reset ();
2446 sl << "addspell "; 2437 sl << "addspell ";
2447 } 2438 }
2448 2439
2462 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2453 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2463 fatal (0); 2454 fatal (0);
2464 } 2455 }
2465 2456
2466 /* finally, we can send the packet */ 2457 /* finally, we can send the packet */
2467 Send_With_Handling (&pl->socket, &sl); 2458 pl->socket->send_packet (sl);
2468
2469} 2459}
2470 2460

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines