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) |
… | |
… | |
533 | void |
505 | void |
534 | NewPlayerCmd (char *buf, int len, player *pl) |
506 | NewPlayerCmd (char *buf, int len, player *pl) |
535 | { |
507 | { |
536 | if (len <= 6) |
508 | if (len <= 6) |
537 | { |
509 | { |
538 | 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); |
539 | return; |
511 | return; |
540 | } |
512 | } |
541 | |
513 | |
542 | uint16 cmdid = net_uint16 ((uint8 *)buf); |
514 | uint16 cmdid = net_uint16 ((uint8 *)buf); |
543 | sint32 repeat = net_sint32 ((uint8 *)buf + 2); |
515 | sint32 repeat = net_sint32 ((uint8 *)buf + 2); |
… | |
… | |
747 | |
719 | |
748 | //TODO: maybe golem should become the current_weapon, quite simply? |
720 | //TODO: maybe golem should become the current_weapon, quite simply? |
749 | if (pl->golem) |
721 | if (pl->golem) |
750 | buf << " Golem*: " << pl->golem->name; |
722 | buf << " Golem*: " << pl->golem->name; |
751 | |
723 | |
|
|
724 | buf << '\0'; |
752 | buf.linearise (obuf); |
725 | buf.linearise (obuf); |
753 | obuf [buf.size ()] = 0; |
|
|
754 | } |
726 | } |
755 | |
727 | |
756 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
728 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
757 | Old = New; \ |
729 | Old = New; \ |
758 | sl << uint8 (Type) << uint64 (New); \ |
730 | sl << uint8 (Type) << uint64 (New); \ |
… | |
… | |
1030 | */ |
1002 | */ |
1031 | if (!plmap || plmap->in_memory != MAP_IN_MEMORY) |
1003 | if (!plmap || plmap->in_memory != MAP_IN_MEMORY) |
1032 | return; |
1004 | return; |
1033 | |
1005 | |
1034 | int x, y, ax, ay, startlen, max_x, max_y, oldlen; |
1006 | int x, y, ax, ay, startlen, max_x, max_y, oldlen; |
1035 | sint16 nx, ny; |
|
|
1036 | int estartlen, eoldlen; |
1007 | int estartlen, eoldlen; |
1037 | uint8 eentrysize; |
1008 | uint8 eentrysize; |
1038 | uint16 ewhatstart, ewhatflag; |
1009 | uint16 ewhatstart, ewhatflag; |
1039 | uint8 extendedinfos; |
1010 | uint8 extendedinfos; |
1040 | maptile *m; |
|
|
1041 | |
1011 | |
1042 | check_map_change (pl); |
1012 | check_map_change (pl); |
1043 | prefetch_surrounding_maps (pl->ob); |
1013 | prefetch_surrounding_maps (pl->ob); |
1044 | |
1014 | |
1045 | /* do LOS after calls to update_position */ |
1015 | /* do LOS after calls to update_position */ |
… | |
… | |
1111 | max_x = ob->x + (socket.mapx + 1) / 2; |
1081 | max_x = ob->x + (socket.mapx + 1) / 2; |
1112 | max_y = ob->y + (socket.mapy + 1) / 2; |
1082 | max_y = ob->y + (socket.mapy + 1) / 2; |
1113 | |
1083 | |
1114 | 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++) |
1115 | { |
1085 | { |
|
|
1086 | sint16 nx, ny; |
|
|
1087 | maptile *m = 0; |
|
|
1088 | |
1116 | ax = 0; |
1089 | ax = 0; |
1117 | 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++) |
1118 | { |
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 | |
1119 | int emask, mask; |
1105 | int emask, mask; |
1120 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1106 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1121 | |
1107 | |
1122 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1108 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1123 | |
1109 | |
1124 | /* 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, |
1125 | * we tell the client as such |
1111 | * we tell the client as such |
1126 | */ |
1112 | */ |
1127 | nx = x; |
|
|
1128 | ny = y; |
|
|
1129 | m = get_map_from_coord (plmap, &nx, &ny); |
|
|
1130 | |
|
|
1131 | if (!m) |
1113 | if (!m) |
1132 | { |
1114 | { |
1133 | /* space is out of map. Update space and clear values |
1115 | /* space is out of map. Update space and clear values |
1134 | * 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 |
1135 | * of the map, it shouldn't have a head |
1117 | * of the map, it shouldn't have a head |