1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (©) 2001,2007 Mark Wedel |
5 | * Copyright (©) 2001,2007 Mark Wedel |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * it under the terms of the GNU General Public License as published by |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
18 | * You should have received a copy of the GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | /** |
24 | /** |
… | |
… | |
191 | socket.current_y = ob->y; |
190 | socket.current_y = ob->y; |
192 | |
191 | |
193 | region *reg = ob->region (); |
192 | region *reg = ob->region (); |
194 | if (socket.current_region != reg) |
193 | if (socket.current_region != reg) |
195 | { |
194 | { |
|
|
195 | INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); |
196 | socket.current_region = reg; |
196 | socket.current_region = reg; |
197 | socket.send_packet_printf ("drawinfo 0 You are now %s.\n(use whereami for more details)", ®->longname); |
|
|
198 | } |
197 | } |
199 | } |
198 | } |
200 | |
199 | |
201 | /** |
200 | /** |
202 | * RequestInfo is sort of a meta command. There is some specific |
201 | * RequestInfo is sort of a meta command. There is some specific |
203 | * request of information, but we call other functions to provide |
202 | * request of information, but we call other functions to provide |
204 | * that information. |
203 | * that information. |
205 | */ |
204 | */ |
206 | void |
205 | void |
207 | RequestInfo (char *buf, int len, client * ns) |
206 | RequestInfo (char *buf, int len, client *ns) |
208 | { |
207 | { |
209 | char *params = NULL, *cp; |
208 | char *params; |
210 | |
|
|
211 | /* No match */ |
|
|
212 | char bigbuf[MAX_BUF]; |
|
|
213 | int slen; |
|
|
214 | |
|
|
215 | /* Set up replyinfo before we modify any of the buffers - this is used |
|
|
216 | * if we don't find a match. |
|
|
217 | */ |
|
|
218 | strcpy (bigbuf, "replyinfo "); |
|
|
219 | slen = strlen (bigbuf); |
|
|
220 | safe_strcat (bigbuf, buf, &slen, MAX_BUF); |
|
|
221 | |
209 | |
222 | /* find the first space, make it null, and update the |
210 | /* find the first space, make it null, and update the |
223 | * params pointer. |
211 | * params pointer. |
224 | */ |
212 | */ |
225 | for (cp = buf; *cp != '\0'; cp++) |
213 | for (params = buf; *params; params++) |
226 | if (*cp == ' ') |
214 | if (*params == ' ') |
227 | { |
215 | { |
228 | *cp = '\0'; |
|
|
229 | params = cp + 1; |
216 | *params++ = 0; |
230 | break; |
217 | break; |
231 | } |
218 | } |
232 | |
219 | |
233 | if (!strcmp (buf, "image_info")) |
220 | if (!strcmp (buf, "image_info")) |
234 | send_image_info (ns, params); |
221 | send_image_info (ns, params); |
… | |
… | |
237 | else if (!strcmp (buf, "skill_info")) |
224 | else if (!strcmp (buf, "skill_info")) |
238 | send_skill_info (ns, params); |
225 | send_skill_info (ns, params); |
239 | else if (!strcmp (buf, "spell_paths")) |
226 | else if (!strcmp (buf, "spell_paths")) |
240 | send_spell_paths (ns, params); |
227 | send_spell_paths (ns, params); |
241 | else |
228 | else |
242 | ns->send_packet (bigbuf, len); |
229 | { |
|
|
230 | // undo tokenisation above and send replyinfo with the request unchanged |
|
|
231 | if (*params) |
|
|
232 | *--params = ' '; |
|
|
233 | |
|
|
234 | ns->send_packet_printf ("replyinfo %s", buf); |
|
|
235 | } |
243 | } |
236 | } |
244 | |
237 | |
245 | void |
238 | void |
246 | ExtCmd (char *buf, int len, player *pl) |
239 | ExtCmd (char *buf, int len, player *pl) |
247 | { |
240 | { |
… | |
… | |
471 | |
464 | |
472 | ns->send_packet (cmdback); |
465 | ns->send_packet (cmdback); |
473 | } |
466 | } |
474 | |
467 | |
475 | /** |
468 | /** |
476 | * client requested an image. send it rate-limited |
|
|
477 | * before flushing. |
|
|
478 | */ |
|
|
479 | void |
|
|
480 | AskFaceCmd (char *buf, int len, client *ns) |
|
|
481 | { |
|
|
482 | ns->askface.push_back (atoi (buf)); |
|
|
483 | } |
|
|
484 | |
|
|
485 | /** |
|
|
486 | * Tells client the picture it has to use |
|
|
487 | * to smooth a picture number given as argument. |
|
|
488 | */ |
|
|
489 | void |
|
|
490 | AskSmooth (char *buf, int len, client *ns) |
|
|
491 | { |
|
|
492 | ns->send_face (atoi (buf)); |
|
|
493 | ns->flush_fx (); |
|
|
494 | } |
|
|
495 | |
|
|
496 | /** |
|
|
497 | * This handles the general commands from the client (ie, north, fire, cast, |
469 | * This handles the general commands from the client (ie, north, fire, cast, |
498 | * etc.) |
470 | * etc.) |
499 | */ |
471 | */ |
500 | void |
472 | void |
501 | PlayerCmd (char *buf, int len, player *pl) |
473 | PlayerCmd (char *buf, int len, player *pl) |
… | |
… | |
522 | * commands. |
494 | * commands. |
523 | */ |
495 | */ |
524 | pl->count = 0; |
496 | pl->count = 0; |
525 | } |
497 | } |
526 | |
498 | |
527 | |
|
|
528 | /** |
499 | /** |
529 | * This handles the general commands from the client (ie, north, fire, cast, |
500 | * This handles the general commands from the client (ie, north, fire, cast, |
530 | * etc.). It is a lot like PlayerCmd above, but is called with the |
501 | * etc.). It is a lot like PlayerCmd above, but is called with the |
531 | * 'ncom' method which gives more information back to the client so it |
502 | * 'ncom' method which gives more information back to the client so it |
532 | * can throttle. |
503 | * can throttle. |
… | |
… | |
534 | void |
505 | void |
535 | NewPlayerCmd (char *buf, int len, player *pl) |
506 | NewPlayerCmd (char *buf, int len, player *pl) |
536 | { |
507 | { |
537 | if (len <= 6) |
508 | if (len <= 6) |
538 | { |
509 | { |
539 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
510 | LOG (llevDebug, "%s: corrupt ncom command <%s>: not long enough (%d) - discarding\n", pl->ns->host, buf, len); |
540 | return; |
511 | return; |
541 | } |
512 | } |
542 | |
513 | |
543 | uint16 cmdid = net_uint16 ((uint8 *)buf); |
514 | uint16 cmdid = net_uint16 ((uint8 *)buf); |
544 | sint32 repeat = net_sint32 ((uint8 *)buf + 2); |
515 | sint32 repeat = net_sint32 ((uint8 *)buf + 2); |
… | |
… | |
738 | buf << " Range" << (pl->ob->current_weapon == pl->ranged_ob ? "*" : "") << ": " << pl->ranged_ob->name; |
709 | buf << " Range" << (pl->ob->current_weapon == pl->ranged_ob ? "*" : "") << ": " << pl->ranged_ob->name; |
739 | |
710 | |
740 | if (pl->combat_ob) |
711 | if (pl->combat_ob) |
741 | buf << " Combat" << (pl->ob->current_weapon == pl->combat_ob ? "*" : "") << ": " << pl->combat_ob->name; |
712 | buf << " Combat" << (pl->ob->current_weapon == pl->combat_ob ? "*" : "") << ": " << pl->combat_ob->name; |
742 | |
713 | |
|
|
714 | #if 0 |
743 | //TODO: remove this when slot system is working, this is only for debugging |
715 | //TODO: remove this when slot system is working, this is only for debugging |
744 | if (pl->ob->chosen_skill) |
716 | if (pl->ob->chosen_skill) |
745 | buf << " Skill*: " << pl->ob->chosen_skill->name; |
717 | buf << " Skill*: " << pl->ob->chosen_skill->name; |
|
|
718 | #endif |
746 | |
719 | |
747 | //TODO: maybe golem should become the current_weapon, quite simply? |
720 | //TODO: maybe golem should become the current_weapon, quite simply? |
748 | if (pl->golem) |
721 | if (pl->golem) |
749 | buf << " Golem*: " << pl->golem->name; |
722 | buf << " Golem*: " << pl->golem->name; |
750 | |
723 | |
|
|
724 | buf << '\0'; |
751 | buf.linearise (obuf); |
725 | buf.linearise (obuf); |
752 | obuf [buf.size ()] = 0; |
|
|
753 | } |
726 | } |
754 | |
727 | |
755 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
728 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
756 | Old = New; \ |
729 | Old = New; \ |
757 | sl << uint8 (Type) << uint64 (New); \ |
730 | sl << uint8 (Type) << uint64 (New); \ |
… | |
… | |
794 | return; |
767 | return; |
795 | |
768 | |
796 | object *ob = pl->observe; |
769 | object *ob = pl->observe; |
797 | if (!ob) |
770 | if (!ob) |
798 | return; |
771 | return; |
|
|
772 | |
|
|
773 | player *opl = ob->contr ? static_cast<player *>(ob->contr) : pl; |
799 | |
774 | |
800 | packet sl ("stats"); |
775 | packet sl ("stats"); |
801 | |
776 | |
802 | AddIfShort (ns->last_stats.hp, ob->stats.hp, CS_STAT_HP); |
777 | AddIfShort (ns->last_stats.hp, ob->stats.hp, CS_STAT_HP); |
803 | AddIfShort (ns->last_stats.maxhp, ob->stats.maxhp, CS_STAT_MAXHP); |
778 | AddIfShort (ns->last_stats.maxhp, ob->stats.maxhp, CS_STAT_MAXHP); |
… | |
… | |
812 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
787 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
813 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
788 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
814 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
789 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
815 | |
790 | |
816 | for (int s = 0; s < NUM_SKILLS; s++) |
791 | for (int s = 0; s < NUM_SKILLS; s++) |
817 | if (object *skill = pl->last_skill_ob[s]) |
792 | if (object *skill = opl->last_skill_ob[s]) |
818 | if (skill->stats.exp != ns->last_skill_exp [s]) |
793 | if (skill->stats.exp != ns->last_skill_exp [s]) |
819 | { |
794 | { |
820 | ns->last_skill_exp [s] = skill->stats.exp; |
795 | ns->last_skill_exp [s] = skill->stats.exp; |
821 | |
796 | |
822 | /* Always send along the level if exp changes. This is only |
797 | /* Always send along the level if exp changes. This is only |
… | |
… | |
837 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f/TICK); |
812 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f/TICK); |
838 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
813 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
839 | |
814 | |
840 | flags = 0; |
815 | flags = 0; |
841 | |
816 | |
842 | if (pl->fire_on) |
817 | if (opl->fire_on) |
843 | flags |= SF_FIREON; |
818 | flags |= SF_FIREON; |
844 | |
819 | |
845 | if (pl->run_on) |
820 | if (opl->run_on) |
846 | flags |= SF_RUNON; |
821 | flags |= SF_RUNON; |
847 | |
822 | |
848 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
823 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
849 | |
824 | |
850 | if (ns->sc_version < 1025) |
825 | if (ns->sc_version < 1025) |
… | |
… | |
864 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
839 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
865 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
840 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
866 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
841 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
867 | } |
842 | } |
868 | |
843 | |
869 | rangetostring (pl, buf); /* we want use the new fire & run system in new client */ |
844 | rangetostring (opl, buf); /* we want use the new fire & run system in new client */ |
870 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
845 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
871 | set_title (ob, buf); |
846 | set_title (ob, buf); |
872 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
847 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
873 | |
848 | |
874 | /* Only send it away if we have some actual data */ |
849 | /* Only send it away if we have some actual data */ |
… | |
… | |
956 | |
931 | |
957 | if (!ns.faces_sent[face_num]) |
932 | if (!ns.faces_sent[face_num]) |
958 | if (ob) |
933 | if (ob) |
959 | ns.send_faces (ob); |
934 | ns.send_faces (ob); |
960 | else |
935 | else |
961 | ns.send_face (face_num); |
936 | ns.send_face (face_num, 10); |
962 | |
937 | |
963 | sl << uint16 (face_num); |
938 | sl << uint16 (face_num); |
964 | return 1; |
939 | return 1; |
965 | } |
940 | } |
966 | |
941 | |
… | |
… | |
1027 | */ |
1002 | */ |
1028 | if (!plmap || plmap->in_memory != MAP_IN_MEMORY) |
1003 | if (!plmap || plmap->in_memory != MAP_IN_MEMORY) |
1029 | return; |
1004 | return; |
1030 | |
1005 | |
1031 | int x, y, ax, ay, startlen, max_x, max_y, oldlen; |
1006 | int x, y, ax, ay, startlen, max_x, max_y, oldlen; |
1032 | sint16 nx, ny; |
|
|
1033 | int estartlen, eoldlen; |
1007 | int estartlen, eoldlen; |
1034 | uint8 eentrysize; |
1008 | uint8 eentrysize; |
1035 | uint16 ewhatstart, ewhatflag; |
1009 | uint16 ewhatstart, ewhatflag; |
1036 | uint8 extendedinfos; |
1010 | uint8 extendedinfos; |
1037 | maptile *m; |
|
|
1038 | |
1011 | |
1039 | check_map_change (pl); |
1012 | check_map_change (pl); |
1040 | prefetch_surrounding_maps (pl->ob); |
1013 | prefetch_surrounding_maps (pl->ob); |
1041 | |
1014 | |
1042 | /* do LOS after calls to update_position */ |
1015 | /* do LOS after calls to update_position */ |
… | |
… | |
1108 | max_x = ob->x + (socket.mapx + 1) / 2; |
1081 | max_x = ob->x + (socket.mapx + 1) / 2; |
1109 | max_y = ob->y + (socket.mapy + 1) / 2; |
1082 | max_y = ob->y + (socket.mapy + 1) / 2; |
1110 | |
1083 | |
1111 | for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++) |
1084 | for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++) |
1112 | { |
1085 | { |
|
|
1086 | sint16 nx, ny; |
|
|
1087 | maptile *m = 0; |
|
|
1088 | |
1113 | ax = 0; |
1089 | ax = 0; |
1114 | for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++) |
1090 | for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++) |
1115 | { |
1091 | { |
|
|
1092 | // check to see if we can simply go one right quickly |
|
|
1093 | ++nx; |
|
|
1094 | if (m && nx >= m->width) |
|
|
1095 | m = 0; |
|
|
1096 | |
|
|
1097 | if (!m) |
|
|
1098 | { |
|
|
1099 | nx = x; ny = y; m = plmap; |
|
|
1100 | |
|
|
1101 | if (!xy_normalise (m, nx, ny)) |
|
|
1102 | m = 0; |
|
|
1103 | } |
|
|
1104 | |
1116 | int emask, mask; |
1105 | int emask, mask; |
1117 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1106 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1118 | |
1107 | |
1119 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1108 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1120 | |
1109 | |
1121 | /* If the coordinates are not valid, or it is too dark to see, |
1110 | /* If the coordinates are not valid, or it is too dark to see, |
1122 | * we tell the client as such |
1111 | * we tell the client as such |
1123 | */ |
1112 | */ |
1124 | nx = x; |
|
|
1125 | ny = y; |
|
|
1126 | m = get_map_from_coord (plmap, &nx, &ny); |
|
|
1127 | |
|
|
1128 | if (!m) |
1113 | if (!m) |
1129 | { |
1114 | { |
1130 | /* space is out of map. Update space and clear values |
1115 | /* space is out of map. Update space and clear values |
1131 | * if this hasn't already been done. If the space is out |
1116 | * if this hasn't already been done. If the space is out |
1132 | * of the map, it shouldn't have a head |
1117 | * of the map, it shouldn't have a head |
… | |
… | |
1213 | } |
1198 | } |
1214 | |
1199 | |
1215 | lastcell.count = d; |
1200 | lastcell.count = d; |
1216 | |
1201 | |
1217 | mapspace &ms = m->at (nx, ny); |
1202 | mapspace &ms = m->at (nx, ny); |
|
|
1203 | ms.update (); |
1218 | |
1204 | |
1219 | if (socket.extmap) |
1205 | if (socket.extmap) |
1220 | { |
1206 | { |
1221 | uint8 stat_hp = 0; |
1207 | uint8 stat_hp = 0; |
1222 | uint8 stat_width = 0; |
1208 | uint8 stat_width = 0; |
… | |
… | |
1232 | || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)) |
1218 | || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)) |
1233 | { |
1219 | { |
1234 | if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp) |
1220 | if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp) |
1235 | { |
1221 | { |
1236 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1222 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1237 | stat_width = op->arch->tail_x; |
1223 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1238 | } |
1224 | } |
1239 | } |
1225 | } |
1240 | |
1226 | |
1241 | if (op->msg && op->msg[0] == '@') |
1227 | if (op->msg && op->msg[0] == '@') |
1242 | flags |= 1; |
1228 | flags |= 1; |
… | |
… | |
1402 | sl << "replyinfo skill_info\n"; |
1388 | sl << "replyinfo skill_info\n"; |
1403 | |
1389 | |
1404 | for (int i = 1; i < NUM_SKILLS; i++) |
1390 | for (int i = 1; i < NUM_SKILLS; i++) |
1405 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
1391 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
1406 | |
1392 | |
1407 | if (sl.length () >= MAXSOCKBUF) |
1393 | if (sl.length () > MAXSOCKBUF) |
1408 | { |
1394 | { |
1409 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
1395 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
1410 | fatal (0); |
1396 | fatal (0); |
1411 | } |
1397 | } |
1412 | |
1398 | |
… | |
… | |
1425 | sl << "replyinfo spell_paths\n"; |
1411 | sl << "replyinfo spell_paths\n"; |
1426 | |
1412 | |
1427 | for (int i = 0; i < NRSPELLPATHS; i++) |
1413 | for (int i = 0; i < NRSPELLPATHS; i++) |
1428 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
1414 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
1429 | |
1415 | |
1430 | if (sl.length () >= MAXSOCKBUF) |
1416 | if (sl.length () > MAXSOCKBUF) |
1431 | { |
1417 | { |
1432 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
1418 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
1433 | fatal (0); |
1419 | fatal (0); |
1434 | } |
1420 | } |
1435 | |
1421 | |
… | |
… | |
1543 | if (!spell->face) |
1529 | if (!spell->face) |
1544 | { |
1530 | { |
1545 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1531 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1546 | spell->face = face_find ("burnout.x11", blank_face); |
1532 | spell->face = face_find ("burnout.x11", blank_face); |
1547 | } |
1533 | } |
|
|
1534 | |
|
|
1535 | pl->ns->send_face (spell->face); |
1548 | |
1536 | |
1549 | /* send the current values */ |
1537 | /* send the current values */ |
1550 | sl << uint32 (spell->count) |
1538 | sl << uint32 (spell->count) |
1551 | << uint16 (spell->level) |
1539 | << uint16 (spell->level) |
1552 | << uint16 (spell->casting_time) |
1540 | << uint16 (spell->casting_time) |
… | |
… | |
1588 | * bytes and 3 strings (because that is the spec) so we need to |
1576 | * bytes and 3 strings (because that is the spec) so we need to |
1589 | * check that the length of those 3 strings, plus the 23 bytes, |
1577 | * check that the length of those 3 strings, plus the 23 bytes, |
1590 | * won't take us over the length limit for the socket, if it does, |
1578 | * won't take us over the length limit for the socket, if it does, |
1591 | * we need to send what we already have, and restart packet formation |
1579 | * we need to send what we already have, and restart packet formation |
1592 | */ |
1580 | */ |
|
|
1581 | if (spell->type != SPELL) |
|
|
1582 | continue; |
|
|
1583 | |
1593 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
1584 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
1594 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
1585 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
1595 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
1586 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
1596 | * like it will fix this |
1587 | * like it will fix this |
1597 | */ |
1588 | */ |
1598 | if (spell->type != SPELL) |
|
|
1599 | continue; |
|
|
1600 | |
|
|
1601 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
1589 | if (sl.length () > (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
1602 | { |
1590 | { |
|
|
1591 | pl->ns->flush_fx (); |
1603 | pl->ns->send_packet (sl); |
1592 | pl->ns->send_packet (sl); |
1604 | |
1593 | |
1605 | sl.reset (); |
1594 | sl.reset (); |
1606 | sl << "addspell "; |
1595 | sl << "addspell "; |
1607 | } |
1596 | } |
… | |
… | |
1615 | return; |
1604 | return; |
1616 | } |
1605 | } |
1617 | else |
1606 | else |
1618 | append_spell (pl, sl, spell); |
1607 | append_spell (pl, sl, spell); |
1619 | |
1608 | |
1620 | if (sl.length () >= MAXSOCKBUF) |
1609 | if (sl.length () > MAXSOCKBUF) |
1621 | { |
1610 | { |
1622 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
1611 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
1623 | fatal (0); |
1612 | fatal (0); |
1624 | } |
1613 | } |
1625 | |
1614 | |
1626 | /* finally, we can send the packet */ |
1615 | /* finally, we can send the packet */ |
|
|
1616 | pl->ns->flush_fx (); |
1627 | pl->ns->send_packet (sl); |
1617 | pl->ns->send_packet (sl); |
1628 | } |
1618 | } |
1629 | |
1619 | |