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.93 by root, Tue May 1 05:48:21 2007 UTC vs.
Revision 1.118 by root, Sun Jul 29 19:11:47 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2001 Mark Wedel 5 * Copyright (©) 2001,2007 Mark Wedel
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) 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, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License 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 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The author 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/**
26 * \file 25 * \file
27 * Client handling. 26 * Client handling.
145/** check for map/region change and send new map data */ 144/** check for map/region change and send new map data */
146static void 145static void
147check_map_change (player *pl) 146check_map_change (player *pl)
148{ 147{
149 client &socket = *pl->ns; 148 client &socket = *pl->ns;
150 object *ob = pl->ob; 149 object *ob = pl->observe;
151 char buf[MAX_BUF]; /* eauugggh */
152 150
153 if (socket.current_map != ob->map || socket.force_newmap) 151 if (socket.current_map != ob->map || socket.force_newmap)
154 { 152 {
155 clear_map (pl); 153 clear_map (pl);
156 socket.current_map = ob->map; 154 socket.current_map = ob->map;
164 if (ob->map->tile_path[0]) flags |= 1; 162 if (ob->map->tile_path[0]) flags |= 1;
165 if (ob->map->tile_path[1]) flags |= 2; 163 if (ob->map->tile_path[1]) flags |= 2;
166 if (ob->map->tile_path[2]) flags |= 4; 164 if (ob->map->tile_path[2]) flags |= 4;
167 if (ob->map->tile_path[3]) flags |= 8; 165 if (ob->map->tile_path[3]) flags |= 8;
168 166
169 snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s", 167 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
170 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, ob->map->width, ob->map->height, &ob->map->path); 168 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
169 ob->map->width, ob->map->height, &ob->map->path);
171 } 170 }
172 else 171 else
173 snprintf (buf, MAX_BUF, "mapinfo current");
174
175 socket.send_packet (buf); 172 socket.send_packet ("mapinfo current");
176 } 173 }
177 } 174 }
178 else if (socket.current_x != ob->x || socket.current_y != ob->y) 175 else if (socket.current_x != ob->x || socket.current_y != ob->y)
179 { 176 {
180 int dx = ob->x - socket.current_x; 177 int dx = ob->x - socket.current_x;
193 socket.current_y = ob->y; 190 socket.current_y = ob->y;
194 191
195 region *reg = ob->region (); 192 region *reg = ob->region ();
196 if (socket.current_region != reg) 193 if (socket.current_region != reg)
197 { 194 {
195 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region));
198 socket.current_region = reg; 196 socket.current_region = reg;
199 socket.send_packet_printf ("drawinfo 0 You are now %s.\n(use whereami for more details)", &reg->longname);
200 } 197 }
201} 198}
202 199
203/** 200/**
204 * RequestInfo is sort of a meta command. There is some specific 201 * RequestInfo is sort of a meta command. There is some specific
205 * request of information, but we call other functions to provide 202 * request of information, but we call other functions to provide
206 * that information. 203 * that information.
207 */ 204 */
208void 205void
209RequestInfo (char *buf, int len, client * ns) 206RequestInfo (char *buf, int len, client *ns)
210{ 207{
211 char *params = NULL, *cp; 208 char *params;
212
213 /* No match */
214 char bigbuf[MAX_BUF];
215 int slen;
216
217 /* Set up replyinfo before we modify any of the buffers - this is used
218 * if we don't find a match.
219 */
220 strcpy (bigbuf, "replyinfo ");
221 slen = strlen (bigbuf);
222 safe_strcat (bigbuf, buf, &slen, MAX_BUF);
223 209
224 /* find the first space, make it null, and update the 210 /* find the first space, make it null, and update the
225 * params pointer. 211 * params pointer.
226 */ 212 */
227 for (cp = buf; *cp != '\0'; cp++) 213 for (params = buf; *params; params++)
228 if (*cp == ' ') 214 if (*params == ' ')
229 { 215 {
230 *cp = '\0';
231 params = cp + 1; 216 *params++ = 0;
232 break; 217 break;
233 } 218 }
234 219
235 if (!strcmp (buf, "image_info")) 220 if (!strcmp (buf, "image_info"))
236 send_image_info (ns, params); 221 send_image_info (ns, params);
239 else if (!strcmp (buf, "skill_info")) 224 else if (!strcmp (buf, "skill_info"))
240 send_skill_info (ns, params); 225 send_skill_info (ns, params);
241 else if (!strcmp (buf, "spell_paths")) 226 else if (!strcmp (buf, "spell_paths"))
242 send_spell_paths (ns, params); 227 send_spell_paths (ns, params);
243 else 228 else
244 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 }
245} 236}
246 237
247void 238void
248ExtCmd (char *buf, int len, player *pl) 239ExtCmd (char *buf, int len, player *pl)
249{ 240{
473 464
474 ns->send_packet (cmdback); 465 ns->send_packet (cmdback);
475} 466}
476 467
477/** 468/**
478 * client requested an image. send it rate-limited
479 * before flushing.
480 */
481void
482AskFaceCmd (char *buf, int len, client *ns)
483{
484 ns->askface.push_back (atoi (buf));
485}
486
487/**
488 * Tells client the picture it has to use
489 * to smooth a picture number given as argument.
490 */
491void
492AskSmooth (char *buf, int len, client *ns)
493{
494 ns->send_face (atoi (buf));
495 ns->flush_fx ();
496}
497
498/**
499 * 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,
500 * etc.) 470 * etc.)
501 */ 471 */
502void 472void
503PlayerCmd (char *buf, int len, player *pl) 473PlayerCmd (char *buf, int len, player *pl)
524 * commands. 494 * commands.
525 */ 495 */
526 pl->count = 0; 496 pl->count = 0;
527} 497}
528 498
529
530/** 499/**
531 * 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,
532 * 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
533 * '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
534 * can throttle. 503 * can throttle.
536void 505void
537NewPlayerCmd (char *buf, int len, player *pl) 506NewPlayerCmd (char *buf, int len, player *pl)
538{ 507{
539 if (len <= 6) 508 if (len <= 6)
540 { 509 {
541 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);
542 return; 511 return;
543 } 512 }
544 513
545 uint16 cmdid = net_uint16 ((uint8 *)buf); 514 uint16 cmdid = net_uint16 ((uint8 *)buf);
546 sint32 repeat = net_sint32 ((uint8 *)buf + 2); 515 sint32 repeat = net_sint32 ((uint8 *)buf + 2);
730 699
731/** 700/**
732 * Get player's current range attack in obuf. 701 * Get player's current range attack in obuf.
733 */ 702 */
734static void 703static void
735rangetostring (object *ob, char *obuf) 704rangetostring (player *pl, char *obuf)
736{ 705{
737 dynbuf_text buf; 706 dynbuf_text buf;
738 707
739 player *pl = ob->contr;
740
741 if (pl->ranged_ob) 708 if (pl->ranged_ob)
742 buf << " Range: " << pl->ranged_ob->name; 709 buf << " Range" << (pl->ob->current_weapon == pl->ranged_ob ? "*" : "") << ": " << pl->ranged_ob->name;
743 710
744 if (pl->combat_ob) 711 if (pl->combat_ob)
745 buf << " Combat: " << pl->combat_ob->name; 712 buf << " Combat" << (pl->ob->current_weapon == pl->combat_ob ? "*" : "") << ": " << pl->combat_ob->name;
746 713
714#if 0
715 //TODO: remove this when slot system is working, this is only for debugging
716 if (pl->ob->chosen_skill)
717 buf << " Skill*: " << pl->ob->chosen_skill->name;
718#endif
719
720 //TODO: maybe golem should become the current_weapon, quite simply?
747 if (pl->golem) 721 if (pl->golem)
748 buf << " Golem: " << pl->golem->name; 722 buf << " Golem*: " << pl->golem->name;
749 723
750 if (buf.empty ()) 724 buf << '\0';
751 *obuf = 0; 725 buf.linearise (obuf);
752 else
753 {
754 memcpy (obuf, buf.linearise () + 1, buf.size () - 1);
755 obuf [buf.size ()] = 0;
756 }
757} 726}
758 727
759#define AddIfInt64(Old,New,Type) if (Old != New) {\ 728#define AddIfInt64(Old,New,Type) if (Old != New) {\
760 Old = New; \ 729 Old = New; \
761 sl << uint8 (Type) << uint64 (New); \ 730 sl << uint8 (Type) << uint64 (New); \
769#define AddIfShort(Old,New,Type) if (Old != New) {\ 738#define AddIfShort(Old,New,Type) if (Old != New) {\
770 Old = New; \ 739 Old = New; \
771 sl << uint8 (Type) << uint16 (New); \ 740 sl << uint8 (Type) << uint16 (New); \
772 } 741 }
773 742
774#define AddIfFloat(Old,New,Type) if (Old != New) {\ 743#define AddIfFloat(Old,New,Type,mult) if (Old != New) {\
775 Old = New; \ 744 Old = New; \
776 sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \ 745 sl << uint8 (Type) << uint32 (New*FLOAT_MULTI*mult); \
777 } 746 }
778 747
779#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ 748#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\
780 free(Old); Old = strdup (New);\ 749 free(Old); Old = strdup (New);\
781 sl << uint8 (Type) << data8 (New); \ 750 sl << uint8 (Type) << data8 (New); \
795 764
796 client *ns = pl->ns; 765 client *ns = pl->ns;
797 if (!ns) 766 if (!ns)
798 return; 767 return;
799 768
800 object *ob = pl->ob; 769 object *ob = pl->observe;
801 if (!ob) 770 if (!ob)
802 return; 771 return;
772
773 player *opl = ob->contr ? static_cast<player *>(ob->contr) : pl;
803 774
804 packet sl ("stats"); 775 packet sl ("stats");
805 776
806 AddIfShort (ns->last_stats.hp, ob->stats.hp, CS_STAT_HP); 777 AddIfShort (ns->last_stats.hp, ob->stats.hp, CS_STAT_HP);
807 AddIfShort (ns->last_stats.maxhp, ob->stats.maxhp, CS_STAT_MAXHP); 778 AddIfShort (ns->last_stats.maxhp, ob->stats.maxhp, CS_STAT_MAXHP);
816 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); 787 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS);
817 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); 788 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW);
818 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); 789 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA);
819 790
820 for (int s = 0; s < NUM_SKILLS; s++) 791 for (int s = 0; s < NUM_SKILLS; s++)
821 if (object *skill = pl->last_skill_ob[s]) 792 if (object *skill = opl->last_skill_ob[s])
822 if (skill->stats.exp != ns->last_skill_exp [s]) 793 if (skill->stats.exp != ns->last_skill_exp [s])
823 { 794 {
824 ns->last_skill_exp [s] = skill->stats.exp; 795 ns->last_skill_exp [s] = skill->stats.exp;
825 796
826 /* Always send along the level if exp changes. This is only 797 /* Always send along the level if exp changes. This is only
834 AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); 805 AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64);
835 AddIfShort (ns->last_level, ob->level, CS_STAT_LEVEL); 806 AddIfShort (ns->last_level, ob->level, CS_STAT_LEVEL);
836 AddIfShort (ns->last_stats.wc, ob->stats.wc, CS_STAT_WC); 807 AddIfShort (ns->last_stats.wc, ob->stats.wc, CS_STAT_WC);
837 AddIfShort (ns->last_stats.ac, ob->stats.ac, CS_STAT_AC); 808 AddIfShort (ns->last_stats.ac, ob->stats.ac, CS_STAT_AC);
838 AddIfShort (ns->last_stats.dam, ob->stats.dam, CS_STAT_DAM); 809 AddIfShort (ns->last_stats.dam, ob->stats.dam, CS_STAT_DAM);
839 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED); 810 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f/TICK);
840 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); 811 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD);
841 AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); 812 AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f/TICK);
842 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);
843 814
844 flags = 0; 815 flags = 0;
845 816
846 if (pl->fire_on) 817 if (opl->fire_on)
847 flags |= SF_FIREON; 818 flags |= SF_FIREON;
848 819
849 if (pl->run_on) 820 if (opl->run_on)
850 flags |= SF_RUNON; 821 flags |= SF_RUNON;
851 822
852 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); 823 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS);
853 824
854 if (ns->sc_version < 1025) 825 if (ns->sc_version < 1025)
868 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);
869 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);
870 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);
871 } 842 }
872 843
873 rangetostring (ob, 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 */
874 AddIfString (ns->stats.range, buf, CS_STAT_RANGE); 845 AddIfString (ns->stats.range, buf, CS_STAT_RANGE);
875 set_title (ob, buf); 846 set_title (ob, buf);
876 AddIfString (ns->stats.title, buf, CS_STAT_TITLE); 847 AddIfString (ns->stats.title, buf, CS_STAT_TITLE);
877 848
878 /* Only send it away if we have some actual data */ 849 /* Only send it away if we have some actual data */
960 931
961 if (!ns.faces_sent[face_num]) 932 if (!ns.faces_sent[face_num])
962 if (ob) 933 if (ob)
963 ns.send_faces (ob); 934 ns.send_faces (ob);
964 else 935 else
965 ns.send_face (face_num); 936 ns.send_face (face_num, 10);
966 937
967 sl << uint16 (face_num); 938 sl << uint16 (face_num);
968 return 1; 939 return 1;
969 } 940 }
970 941
1012{ 983{
1013 prefetch_surrounding_maps (op->map, 3); 984 prefetch_surrounding_maps (op->map, 3);
1014} 985}
1015 986
1016/** 987/**
1017 * This function uses the new map1 protocol command to send the map 988 * Draws client map.
1018 * to the client. It is necessary because the old map command supports
1019 * a maximum map size of 15x15.
1020 * This function is much simpler than the old one. This is because
1021 * the old function optimized to send as few face identifiers as possible,
1022 * at the expense of sending more coordinate location (coordinates were
1023 * only 1 byte, faces 2 bytes, so this was a worthwhile savings). Since
1024 * we need 2 bytes for coordinates and 2 bytes for faces, such a trade off
1025 * maps no sense. Instead, we actually really only use 12 bits for coordinates,
1026 * and use the other 4 bits for other informatiion. For full documentation
1027 * of what we send, see the doc/Protocol file.
1028 * I will describe internally what we do:
1029 * the ns->lastmap shows how the map last looked when sent to the client.
1030 * in the lastmap structure, there is a cells array, which is set to the
1031 * maximum viewable size (As set in config.h).
1032 * in the cells, there are faces and a count value.
1033 * we use the count value to hold the darkness value. If -1, then this space
1034 * is not viewable.
1035 * we use faces[0] faces[1] faces[2] to hold what the three layers
1036 * look like.
1037 */ 989 */
1038void 990void
1039draw_client_map1 (object *pl) 991draw_client_map (player *pl)
1040{ 992{
993 object *ob = pl->observe;
994 if (!ob->active)
995 return;
996
997 maptile *plmap = ob->map;
998
999 /* If player is just joining the game, he isn't here yet, so the map
1000 * can get swapped out. If so, don't try to send them a map. All will
1001 * be OK once they really log in.
1002 */
1003 if (!plmap || plmap->in_memory != MAP_IN_MEMORY)
1004 return;
1005
1041 int x, y, ax, ay, startlen, max_x, max_y, oldlen; 1006 int x, y, ax, ay, startlen, max_x, max_y, oldlen;
1042 sint16 nx, ny;
1043 int estartlen, eoldlen; 1007 int estartlen, eoldlen;
1044 uint8 eentrysize; 1008 uint8 eentrysize;
1045 uint16 ewhatstart, ewhatflag; 1009 uint16 ewhatstart, ewhatflag;
1046 uint8 extendedinfos; 1010 uint8 extendedinfos;
1047 maptile *m;
1048 1011
1049 client &socket = *pl->contr->ns;
1050
1051 if (!pl->active)
1052 return;
1053
1054 check_map_change (pl->contr); 1012 check_map_change (pl);
1055 prefetch_surrounding_maps (pl); 1013 prefetch_surrounding_maps (pl->ob);
1014
1015 /* do LOS after calls to update_position */
1016 if (ob != pl->ob)
1017 clear_los (pl);
1018 else if (pl->do_los)
1019 {
1020 update_los (ob);
1021 pl->do_los = 0;
1022 }
1023
1024 /**
1025 * This function uses the new map1 protocol command to send the map
1026 * to the client. It is necessary because the old map command supports
1027 * a maximum map size of 15x15.
1028 * This function is much simpler than the old one. This is because
1029 * the old function optimized to send as few face identifiers as possible,
1030 * at the expense of sending more coordinate location (coordinates were
1031 * only 1 byte, faces 2 bytes, so this was a worthwhile savings). Since
1032 * we need 2 bytes for coordinates and 2 bytes for faces, such a trade off
1033 * maps no sense. Instead, we actually really only use 12 bits for coordinates,
1034 * and use the other 4 bits for other informatiion. For full documentation
1035 * of what we send, see the doc/Protocol file.
1036 * I will describe internally what we do:
1037 * the ns->lastmap shows how the map last looked when sent to the client.
1038 * in the lastmap structure, there is a cells array, which is set to the
1039 * maximum viewable size (As set in config.h).
1040 * in the cells, there are faces and a count value.
1041 * we use the count value to hold the darkness value. If -1, then this space
1042 * is not viewable.
1043 * we use faces[0] faces[1] faces[2] to hold what the three layers
1044 * look like.
1045 */
1046
1047 client &socket = *pl->ns;
1056 1048
1057 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 1049 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a");
1058 packet esl; 1050 packet esl;
1059 1051
1060 startlen = sl.length (); 1052 startlen = sl.length ();
1084 ay = 0; 1076 ay = 0;
1085 1077
1086 /* We could do this logic as conditionals in the if statement, 1078 /* We could do this logic as conditionals in the if statement,
1087 * but that started to get a bit messy to look at. 1079 * but that started to get a bit messy to look at.
1088 */ 1080 */
1089 max_x = pl->x + (socket.mapx + 1) / 2; 1081 max_x = ob->x + (socket.mapx + 1) / 2;
1090 max_y = pl->y + (socket.mapy + 1) / 2; 1082 max_y = ob->y + (socket.mapy + 1) / 2;
1091 1083
1092 maptile *plmap = pl->map;
1093
1094 for (y = pl->y - socket.mapy / 2; y < max_y; y++, ay++) 1084 for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++)
1095 { 1085 {
1086 sint16 nx, ny;
1087 maptile *m = 0;
1088
1096 ax = 0; 1089 ax = 0;
1097 for (x = pl->x - socket.mapx / 2; x < max_x; x++, ax++) 1090 for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++)
1098 { 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
1099 int emask, mask; 1105 int emask, mask;
1100 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1106 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1101 1107
1102 MapCell &lastcell = socket.lastmap.cells[ax][ay]; 1108 MapCell &lastcell = socket.lastmap.cells[ax][ay];
1103 1109
1104 /* 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,
1105 * we tell the client as such 1111 * we tell the client as such
1106 */ 1112 */
1107 nx = x;
1108 ny = y;
1109 m = get_map_from_coord (plmap, &nx, &ny);
1110
1111 if (!m) 1113 if (!m)
1112 { 1114 {
1113 /* space is out of map. Update space and clear values 1115 /* space is out of map. Update space and clear values
1114 * 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
1115 * of the map, it shouldn't have a head 1117 * of the map, it shouldn't have a head
1123 continue; 1125 continue;
1124 } 1126 }
1125 1127
1126 m->touch (); 1128 m->touch ();
1127 1129
1128 int d = pl->contr->blocked_los[ax][ay]; 1130 int d = pl->blocked_los[ax][ay];
1129 1131
1130 if (d > 3) 1132 if (d > 3)
1131 { 1133 {
1132 1134
1133 int need_send = 0, count; 1135 int need_send = 0, count;
1196 } 1198 }
1197 1199
1198 lastcell.count = d; 1200 lastcell.count = d;
1199 1201
1200 mapspace &ms = m->at (nx, ny); 1202 mapspace &ms = m->at (nx, ny);
1203 ms.update ();
1201 1204
1202 if (socket.extmap) 1205 if (socket.extmap)
1203 { 1206 {
1204 uint8 stat_hp = 0; 1207 uint8 stat_hp = 0;
1205 uint8 stat_width = 0; 1208 uint8 stat_width = 0;
1215 || 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))
1216 { 1219 {
1217 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)
1218 { 1221 {
1219 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 1222 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1220 stat_width = op->arch->tail_x; 1223 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1221 } 1224 }
1222 } 1225 }
1223 1226
1224 if (op->msg && op->msg[0] == '@') 1227 if (op->msg && op->msg[0] == '@')
1225 flags |= 1; 1228 flags |= 1;
1226 1229
1227 if (op->type == PLAYER && op != pl) 1230 if (op->type == PLAYER && op != ob)
1228 player = op->count; 1231 player = op->count;
1229 } 1232 }
1230 1233
1231 if (lastcell.stat_hp != stat_hp) 1234 if (lastcell.stat_hp != stat_hp)
1232 { 1235 {
1276 1279
1277 /* Middle face */ 1280 /* Middle face */
1278 if (update_space (sl, socket, ms, lastcell, 1)) 1281 if (update_space (sl, socket, ms, lastcell, 1))
1279 mask |= 0x2; 1282 mask |= 0x2;
1280 1283
1281 if (ms.player () == pl 1284 if (ms.player () == ob
1282 && (pl->invisible & (pl->invisible < 50 ? 1 : 7))) 1285 && (ob->invisible & (ob->invisible < 50 ? 1 : 7)))
1283 { 1286 {
1284 // force player to be visible to himself if invisible 1287 // force player to be visible to himself if invisible
1285 if (lastcell.faces[0] != pl->face) 1288 if (lastcell.faces[0] != ob->face)
1286 { 1289 {
1287 lastcell.faces[0] = pl->face; 1290 lastcell.faces[0] = ob->face;
1288 1291
1289 mask |= 0x1; 1292 mask |= 0x1;
1290 sl << uint16 (pl->face); 1293 sl << uint16 (ob->face);
1291 1294
1292 socket.send_faces (pl); 1295 socket.send_faces (ob);
1293 } 1296 }
1294 } 1297 }
1295 /* Top face */ 1298 /* Top face */
1296 else if (update_space (sl, socket, ms, lastcell, 0)) 1299 else if (update_space (sl, socket, ms, lastcell, 0))
1297 mask |= 0x1; 1300 mask |= 0x1;
1298
1299 1301
1300 /* Check to see if we are in fact sending anything for this 1302 /* Check to see if we are in fact sending anything for this
1301 * space by checking the mask. If so, update the mask. 1303 * space by checking the mask. If so, update the mask.
1302 * if not, reset the len to that from before adding the mask 1304 * if not, reset the len to that from before adding the mask
1303 * value, so we don't send those bits. 1305 * value, so we don't send those bits.
1362 socket.send_packet (sl); 1364 socket.send_packet (sl);
1363 socket.sent_scroll = 0; 1365 socket.sent_scroll = 0;
1364 } 1366 }
1365} 1367}
1366 1368
1367/**
1368 * Draws client map.
1369 */
1370void
1371draw_client_map (object *pl)
1372{
1373 int i, j;
1374 sint16 ax, ay; /* ax and ay goes from 0 to max-size of arrays */
1375 int mflags;
1376 struct Map newmap;
1377 maptile *m, *pm;
1378
1379 if (pl->type != PLAYER)
1380 {
1381 LOG (llevError, "draw_client_map called with non player/non eric-server\n");
1382 return;
1383 }
1384
1385 pm = pl->map;
1386
1387 /* If player is just joining the game, he isn't here yet, so the map
1388 * can get swapped out. If so, don't try to send them a map. All will
1389 * be OK once they really log in.
1390 */
1391 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY)
1392 return;
1393
1394 memset (&newmap, 0, sizeof (struct Map));
1395
1396 for (j = (pl->y - pl->contr->ns->mapy / 2); j < (pl->y + (pl->contr->ns->mapy + 1) / 2); j++)
1397 for (i = (pl->x - pl->contr->ns->mapx / 2); i < (pl->x + (pl->contr->ns->mapx + 1) / 2); i++)
1398 {
1399 ax = i;
1400 ay = j;
1401 m = pm;
1402 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay);
1403
1404 if (mflags & P_OUT_OF_MAP)
1405 continue;
1406
1407 /* If a map is visible to the player, we don't want to swap it out
1408 * just to reload it. This should really call something like
1409 * swap_map, but this is much more efficient and 'good enough'
1410 */
1411 if (mflags & P_NEW_MAP)
1412 m->timeout = 50;
1413 }
1414
1415 /* do LOS after calls to update_position */
1416 if (pl->contr->do_los)
1417 {
1418 update_los (pl);
1419 pl->contr->do_los = 0;
1420 }
1421
1422 /* Big maps need a different drawing mechanism to work */
1423 draw_client_map1 (pl);
1424}
1425
1426
1427/*****************************************************************************/ 1369/*****************************************************************************/
1428
1429/* GROS: The following one is used to allow a plugin to send a generic cmd to*/ 1370/* GROS: The following one is used to allow a plugin to send a generic cmd to*/
1430
1431/* a player. Of course, the client need to know the command to be able to */ 1371/* a player. Of course, the client need to know the command to be able to */
1432
1433/* manage it ! */ 1372/* manage it ! */
1434
1435/*****************************************************************************/ 1373/*****************************************************************************/
1436void 1374void
1437send_plugin_custom_message (object *pl, char *buf) 1375send_plugin_custom_message (object *pl, char *buf)
1438{ 1376{
1439 pl->contr->ns->send_packet (buf); 1377 pl->contr->ns->send_packet (buf);
1450 sl << "replyinfo skill_info\n"; 1388 sl << "replyinfo skill_info\n";
1451 1389
1452 for (int i = 1; i < NUM_SKILLS; i++) 1390 for (int i = 1; i < NUM_SKILLS; i++)
1453 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]);
1454 1392
1455 if (sl.length () >= MAXSOCKBUF) 1393 if (sl.length () > MAXSOCKBUF)
1456 { 1394 {
1457 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 1395 LOG (llevError, "Buffer overflow in send_skill_info!\n");
1458 fatal (0); 1396 fatal (0);
1459 } 1397 }
1460 1398
1473 sl << "replyinfo spell_paths\n"; 1411 sl << "replyinfo spell_paths\n";
1474 1412
1475 for (int i = 0; i < NRSPELLPATHS; i++) 1413 for (int i = 0; i < NRSPELLPATHS; i++)
1476 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); 1414 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
1477 1415
1478 if (sl.length () >= MAXSOCKBUF) 1416 if (sl.length () > MAXSOCKBUF)
1479 { 1417 {
1480 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 1418 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
1481 fatal (0); 1419 fatal (0);
1482 } 1420 }
1483 1421
1591 if (!spell->face) 1529 if (!spell->face)
1592 { 1530 {
1593 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);
1594 spell->face = face_find ("burnout.x11", blank_face); 1532 spell->face = face_find ("burnout.x11", blank_face);
1595 } 1533 }
1534
1535 pl->ns->send_face (spell->face);
1596 1536
1597 /* send the current values */ 1537 /* send the current values */
1598 sl << uint32 (spell->count) 1538 sl << uint32 (spell->count)
1599 << uint16 (spell->level) 1539 << uint16 (spell->level)
1600 << uint16 (spell->casting_time) 1540 << uint16 (spell->casting_time)
1636 * 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
1637 * 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,
1638 * 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,
1639 * 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
1640 */ 1580 */
1581 if (spell->type != SPELL)
1582 continue;
1583
1641 /* Seeing crashes by overflowed buffers. Quick arithemetic seems 1584 /* Seeing crashes by overflowed buffers. Quick arithemetic seems
1642 * 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
1643 * 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
1644 * like it will fix this 1587 * like it will fix this
1645 */ 1588 */
1646 if (spell->type != SPELL)
1647 continue;
1648
1649 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))))
1650 { 1590 {
1591 pl->ns->flush_fx ();
1651 pl->ns->send_packet (sl); 1592 pl->ns->send_packet (sl);
1652 1593
1653 sl.reset (); 1594 sl.reset ();
1654 sl << "addspell "; 1595 sl << "addspell ";
1655 } 1596 }
1663 return; 1604 return;
1664 } 1605 }
1665 else 1606 else
1666 append_spell (pl, sl, spell); 1607 append_spell (pl, sl, spell);
1667 1608
1668 if (sl.length () >= MAXSOCKBUF) 1609 if (sl.length () > MAXSOCKBUF)
1669 { 1610 {
1670 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 1611 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
1671 fatal (0); 1612 fatal (0);
1672 } 1613 }
1673 1614
1674 /* finally, we can send the packet */ 1615 /* finally, we can send the packet */
1616 pl->ns->flush_fx ();
1675 pl->ns->send_packet (sl); 1617 pl->ns->send_packet (sl);
1676} 1618}
1677 1619

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines