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.76 by root, Wed Mar 14 13:05:30 2007 UTC vs.
Revision 1.113 by root, Mon Jul 2 02:29:34 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.
132static void 131static void
133clear_map (player *pl) 132clear_map (player *pl)
134{ 133{
135 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); 134 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap));
136 135
136 pl->ns->force_newmap = false;
137
137 if (pl->ns->newmapcmd == 1) 138 if (pl->ns->newmapcmd == 1)
138 pl->ns->send_packet ("newmap"); 139 pl->ns->send_packet ("newmap");
139 140
140 pl->ns->floorbox_reset (); 141 pl->ns->floorbox_reset ();
141} 142}
143/** check for map/region change and send new map data */ 144/** check for map/region change and send new map data */
144static void 145static void
145check_map_change (player *pl) 146check_map_change (player *pl)
146{ 147{
147 client &socket = *pl->ns; 148 client &socket = *pl->ns;
148 object *ob = pl->ob; 149 object *ob = pl->observe;
149 char buf[MAX_BUF]; /* eauugggh */
150 150
151 if (socket.current_map != ob->map) 151 if (socket.current_map != ob->map || socket.force_newmap)
152 { 152 {
153 clear_map (pl);
153 socket.current_map = ob->map; 154 socket.current_map = ob->map;
154
155 clear_map (pl);
156 155
157 if (socket.mapinfocmd) 156 if (socket.mapinfocmd)
158 { 157 {
159 if (ob->map && ob->map->path[0]) 158 if (ob->map && ob->map->path[0])
160 { 159 {
161 int flags = 0; 160 int flags = 0;
162 161
163 if (ob->map->tile_path[0]) 162 if (ob->map->tile_path[0]) flags |= 1;
164 flags |= 1;
165 if (ob->map->tile_path[1]) 163 if (ob->map->tile_path[1]) flags |= 2;
166 flags |= 2;
167 if (ob->map->tile_path[2]) 164 if (ob->map->tile_path[2]) flags |= 4;
168 flags |= 4;
169 if (ob->map->tile_path[3]) 165 if (ob->map->tile_path[3]) flags |= 8;
170 flags |= 8;
171 166
172 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",
173 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);
174 } 170 }
175 else 171 else
176 snprintf (buf, MAX_BUF, "mapinfo current");
177
178 socket.send_packet (buf); 172 socket.send_packet ("mapinfo current");
179 } 173 }
180 } 174 }
181 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)
182 { 176 {
183 int dx = ob->x - socket.current_x; 177 int dx = ob->x - socket.current_x;
324 snprintf (bigbuf, MAX_BUF, "mapinfo %s error", token); 318 snprintf (bigbuf, MAX_BUF, "mapinfo %s error", token);
325 else if (map && map->path[0]) 319 else if (map && map->path[0])
326 { 320 {
327 int flags = 0; 321 int flags = 0;
328 322
329 if (map->tile_path[0]) 323 if (map->tile_path[0]) flags |= 1;
330 flags |= 1;
331 if (map->tile_path[1]) 324 if (map->tile_path[1]) flags |= 2;
332 flags |= 2;
333 if (map->tile_path[2]) 325 if (map->tile_path[2]) flags |= 4;
334 flags |= 4;
335 if (map->tile_path[3]) 326 if (map->tile_path[3]) flags |= 8;
336 flags |= 8;
337 327
338 snprintf (bigbuf, MAX_BUF, "mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); 328 snprintf (bigbuf, MAX_BUF, "mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path);
339 } 329 }
340 else 330 else
341 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); 331 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token);
344 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); 334 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token);
345 335
346 pl->ns->send_packet (bigbuf); 336 pl->ns->send_packet (bigbuf);
347} 337}
348 338
349/** This is the Setup cmd - easy first implementation */ 339/** This is the Setup cmd */
350void 340void
351SetUp (char *buf, int len, client * ns) 341SetUp (char *buf, int len, client * ns)
352{ 342{
353 int s, slen; 343 INVOKE_CLIENT (SETUP, ns, ARG_DATA (buf, len));
354 char *cmd, *param, cmdback[HUGE_BUF];
355
356 /* run through the cmds of setup
357 * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
358 *
359 * we send the status of the cmd back, or a FALSE is the cmd is the server unknown
360 * The client then must sort this out
361 */
362
363 //LOG (llevInfo, "Get SetupCmd:: %s\n", buf);
364
365 strcpy (cmdback, "setup");
366 for (s = 0; s < len; )
367 {
368 cmd = &buf[s];
369
370 /* find the next space, and put a null there */
371 for (; buf[s] && buf[s] != ' '; s++)
372 ;
373
374 buf[s++] = 0;
375
376 while (buf[s] == ' ')
377 s++;
378
379 if (s >= len)
380 break;
381
382 param = &buf[s];
383
384 for (; buf[s] && buf[s] != ' '; s++)
385 ;
386
387 buf[s++] = 0;
388
389 while (buf[s] == ' ')
390 s++;
391
392 slen = strlen (cmdback);
393 safe_strcat (cmdback, " ", &slen, HUGE_BUF);
394 safe_strcat (cmdback, cmd, &slen, HUGE_BUF);
395 safe_strcat (cmdback, " ", &slen, HUGE_BUF);
396
397 if (!strcmp (cmd, "sound"))
398 {
399 ns->sound = atoi (param);
400 safe_strcat (cmdback, param, &slen, HUGE_BUF);
401 }
402 else if (!strcmp (cmd, "exp64"))
403 safe_strcat (cmdback, param, &slen, HUGE_BUF);
404 else if (!strcmp (cmd, "spellmon"))
405 {
406 ns->monitor_spells = atoi (param);
407 safe_strcat (cmdback, param, &slen, HUGE_BUF);
408 }
409 else if (!strcmp (cmd, "darkness"))
410 {
411 ns->darkness = atoi (param);
412 safe_strcat (cmdback, param, &slen, HUGE_BUF);
413 }
414 else if (!strcmp (cmd, "map1cmd"))
415 {
416 if (atoi (param))
417 ns->mapmode = Map1Cmd;
418 /* if beyond this size, need to use map1cmd no matter what */
419 if (ns->mapx > 11 || ns->mapy > 11)
420 ns->mapmode = Map1Cmd;
421 safe_strcat (cmdback, ns->mapmode == Map1Cmd ? "1" : "0", &slen, HUGE_BUF);
422 }
423 else if (!strcmp (cmd, "map1acmd"))
424 {
425 if (atoi (param))
426 ns->mapmode = Map1aCmd;
427 /* if beyond this size, need to use map1acmd no matter what */
428 if (ns->mapx > 11 || ns->mapy > 11)
429 ns->mapmode = Map1aCmd;
430 safe_strcat (cmdback, ns->mapmode == Map1aCmd ? "1" : "0", &slen, HUGE_BUF);
431 }
432 else if (!strcmp (cmd, "newmapcmd"))
433 {
434 ns->newmapcmd = atoi (param);
435 safe_strcat (cmdback, param, &slen, HUGE_BUF);
436 }
437 else if (!strcmp (cmd, "mapinfocmd"))
438 {
439 ns->mapinfocmd = atoi (param);
440 safe_strcat (cmdback, "1", &slen, HUGE_BUF);
441 }
442 else if (!strcmp (cmd, "extcmd"))
443 {
444 ns->extcmd = atoi (param);
445 safe_strcat (cmdback, "1", &slen, HUGE_BUF);
446 }
447 else if (!strcmp (cmd, "extmap"))
448 {
449 ns->extmap = atoi (param);
450 safe_strcat (cmdback, "1", &slen, HUGE_BUF);
451 }
452 else if (!strcmp (cmd, "facecache"))
453 {
454 ns->facecache = atoi (param);
455 safe_strcat (cmdback, param, &slen, HUGE_BUF);
456 }
457 else if (!strcmp (cmd, "faceset"))
458 {
459 char tmpbuf[20];
460 int q = atoi (param);
461
462 if (is_valid_faceset (q))
463 ns->faceset = q;
464
465 sprintf (tmpbuf, "%d", ns->faceset);
466 safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF);
467 /* if the client is using faceset, it knows about image2 command */
468 ns->image2 = 1;
469 }
470 else if (!strcmp (cmd, "itemcmd"))
471 {
472 /* Version of the item protocol command to use. Currently,
473 * only supported versions are 1 and 2. Using a numeric
474 * value will make it very easy to extend this in the future.
475 */
476 char tmpbuf[20];
477 int q = atoi (param);
478
479 if (q < 1 || q > 2)
480 {
481 strcpy (tmpbuf, "FALSE");
482 }
483 else
484 {
485 ns->itemcmd = q;
486 sprintf (tmpbuf, "%d", ns->itemcmd);
487 }
488 safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF);
489 }
490 else if (!strcmp (cmd, "mapsize"))
491 {
492 int x, y = 0;
493 char tmpbuf[MAX_BUF], *cp;
494
495 x = atoi (param);
496 for (cp = param; *cp != 0; cp++)
497 if (*cp == 'x' || *cp == 'X')
498 {
499 y = atoi (cp + 1);
500 break;
501 }
502
503 if (x < 9 || y < 9 || x > MAP_CLIENT_X || y > MAP_CLIENT_Y)
504 {
505 sprintf (tmpbuf, " %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y);
506 safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF);
507 }
508 else
509 {
510 ns->mapx = x;
511 ns->mapy = y;
512 /* better to send back what we are really using and not the
513 * param as given to us in case it gets parsed differently.
514 */
515 sprintf (tmpbuf, "%dx%d", x, y);
516 safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF);
517 /* If beyond this size and still using orig map command, need to
518 * go to map1cmd.
519 */
520 if ((x > 11 || y > 11) && ns->mapmode == Map0Cmd)
521 ns->mapmode = Map1Cmd;
522 }
523 }
524 else if (!strcmp (cmd, "extendedMapInfos"))
525 {
526 /* Added by tchize
527 * prepare to use the mapextended command
528 */
529 char tmpbuf[20];
530
531 ns->ext_mapinfos = (atoi (param));
532 sprintf (tmpbuf, "%d", ns->ext_mapinfos);
533 safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF);
534 }
535 else if (!strcmp (cmd, "extendedTextInfos"))
536 {
537 /* Added by tchize
538 * prepare to use the extended text commands
539 * Client toggle this to non zero to get exttext
540 */
541 char tmpbuf[20];
542
543 ns->has_readable_type = (atoi (param));
544 sprintf (tmpbuf, "%d", ns->has_readable_type);
545 safe_strcat (cmdback, tmpbuf, &slen, HUGE_BUF);
546 }
547 else
548 {
549 /* Didn't get a setup command we understood -
550 * report a failure to the client.
551 */
552 safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF);
553 }
554 } /* for processing all the setup commands */
555
556 LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback);
557 ns->send_packet (cmdback);
558} 344}
559 345
560/** 346/**
561 * The client has requested to be added to the game. 347 * The client has requested to be added to the game.
562 * This is what takes care of it. We tell the client how things worked out. 348 * This is what takes care of it. We tell the client how things worked out.
563 * I am not sure if this file is the best place for this function. however, 349 * I am not sure if this file is the best place for this function. however,
564 * it either has to be here or init_sockets needs to be exported. 350 * it either has to be here or init_sockets needs to be exported.
565 */ 351 */
566void 352void
567AddMeCmd (char *buf, int len, client * ns) 353AddMeCmd (char *buf, int len, client *ns)
568{ 354{
569 INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); 355 INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len));
570} 356}
571 357
572/** Reply to ExtendedInfos command */ 358/** Reply to ExtendedInfos command */
684 470
685 ns->send_packet (cmdback); 471 ns->send_packet (cmdback);
686} 472}
687 473
688/** 474/**
689 * Tells client the picture it has to use
690 * to smooth a picture number given as argument.
691 */
692void
693AskSmooth (char *buf, int len, client *ns)
694{
695 ns->send_face (atoi (buf));
696}
697
698/**
699 * This handles the general commands from the client (ie, north, fire, cast, 475 * This handles the general commands from the client (ie, north, fire, cast,
700 * etc.) 476 * etc.)
701 */ 477 */
702void 478void
703PlayerCmd (char *buf, int len, player *pl) 479PlayerCmd (char *buf, int len, player *pl)
724 * commands. 500 * commands.
725 */ 501 */
726 pl->count = 0; 502 pl->count = 0;
727} 503}
728 504
729
730/** 505/**
731 * This handles the general commands from the client (ie, north, fire, cast, 506 * This handles the general commands from the client (ie, north, fire, cast,
732 * etc.). It is a lot like PlayerCmd above, but is called with the 507 * etc.). It is a lot like PlayerCmd above, but is called with the
733 * 'ncom' method which gives more information back to the client so it 508 * 'ncom' method which gives more information back to the client so it
734 * can throttle. 509 * can throttle.
736void 511void
737NewPlayerCmd (char *buf, int len, player *pl) 512NewPlayerCmd (char *buf, int len, player *pl)
738{ 513{
739 if (len <= 6) 514 if (len <= 6)
740 { 515 {
741 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 516 LOG (llevDebug, "%s: corrupt ncom command <%s>: not long enough (%d) - discarding\n", pl->ns->host, buf, len);
742 return; 517 return;
743 } 518 }
744 519
745 uint16 cmdid = net_uint16 ((uint8 *)buf); 520 uint16 cmdid = net_uint16 ((uint8 *)buf);
746 sint32 repeat = net_sint32 ((uint8 *)buf + 2); 521 sint32 repeat = net_sint32 ((uint8 *)buf + 2);
803 { 578 {
804 case ST_PLAYING: 579 case ST_PLAYING:
805 LOG (llevError, "Got reply message with ST_PLAYING input state\n"); 580 LOG (llevError, "Got reply message with ST_PLAYING input state\n");
806 break; 581 break;
807 582
808 case ST_CHANGE_CLASS:
809 key_change_class (pl->ob, buf[0]);
810 break;
811
812 case ST_GET_PARTY_PASSWORD: /* Get password for party */ 583 case ST_GET_PARTY_PASSWORD: /* Get password for party */
813 receive_party_password (pl->ob, 13); 584 receive_party_password (pl->ob, 13);
814 break; 585 break;
815 586
816 default: 587 default:
855 626
856 cp = strchr (cp + 1, ' '); 627 cp = strchr (cp + 1, ' ');
857 628
858 if (cp) 629 if (cp)
859 { 630 {
860 assign (ns->version, cp + 1); 631 ns->version = cp + 1;
861 632
862 if (ns->sc_version < 1026) 633 if (ns->sc_version < 1026)
863 ns->send_packet_printf ("drawinfo %d %s", NDI_RED, 634 ns->send_packet_printf ("drawinfo %d %s", NDI_RED,
864 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 635 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
865 } 636 }
925/** 696/**
926 * Asks the client to query the user. This way, the client knows 697 * Asks the client to query the user. This way, the client knows
927 * it needs to send something back (vs just printing out a message) 698 * it needs to send something back (vs just printing out a message)
928 */ 699 */
929void 700void
930send_query (client *ns, uint8 flags, char *text) 701send_query (client *ns, uint8 flags, const char *text)
931{ 702{
932 ns->send_packet_printf ("query %d %s", flags, text ? text : ""); 703 ns->send_packet_printf ("query %d %s", flags, text ? text : "");
704}
705
706/**
707 * Get player's current range attack in obuf.
708 */
709static void
710rangetostring (player *pl, char *obuf)
711{
712 dynbuf_text buf;
713
714 if (pl->ranged_ob)
715 buf << " Range" << (pl->ob->current_weapon == pl->ranged_ob ? "*" : "") << ": " << pl->ranged_ob->name;
716
717 if (pl->combat_ob)
718 buf << " Combat" << (pl->ob->current_weapon == pl->combat_ob ? "*" : "") << ": " << pl->combat_ob->name;
719
720#if 0
721 //TODO: remove this when slot system is working, this is only for debugging
722 if (pl->ob->chosen_skill)
723 buf << " Skill*: " << pl->ob->chosen_skill->name;
724#endif
725
726 //TODO: maybe golem should become the current_weapon, quite simply?
727 if (pl->golem)
728 buf << " Golem*: " << pl->golem->name;
729
730 buf << '\0';
731 buf.linearise (obuf);
933} 732}
934 733
935#define AddIfInt64(Old,New,Type) if (Old != New) {\ 734#define AddIfInt64(Old,New,Type) if (Old != New) {\
936 Old = New; \ 735 Old = New; \
937 sl << uint8 (Type) << uint64 (New); \ 736 sl << uint8 (Type) << uint64 (New); \
945#define AddIfShort(Old,New,Type) if (Old != New) {\ 744#define AddIfShort(Old,New,Type) if (Old != New) {\
946 Old = New; \ 745 Old = New; \
947 sl << uint8 (Type) << uint16 (New); \ 746 sl << uint8 (Type) << uint16 (New); \
948 } 747 }
949 748
950#define AddIfFloat(Old,New,Type) if (Old != New) {\ 749#define AddIfFloat(Old,New,Type,mult) if (Old != New) {\
951 Old = New; \ 750 Old = New; \
952 sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \ 751 sl << uint8 (Type) << uint32 (New*FLOAT_MULTI*mult); \
953 } 752 }
954 753
955#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ 754#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\
956 free(Old); Old = strdup (New);\ 755 free(Old); Old = strdup (New);\
957 sl << uint8 (Type) << data8 (New); \ 756 sl << uint8 (Type) << data8 (New); \
971 770
972 client *ns = pl->ns; 771 client *ns = pl->ns;
973 if (!ns) 772 if (!ns)
974 return; 773 return;
975 774
976 object *ob = pl->ob; 775 object *ob = pl->observe;
977 if (!ob) 776 if (!ob)
978 return; 777 return;
778
779 player *opl = ob->contr ? static_cast<player *>(ob->contr) : pl;
979 780
980 packet sl ("stats"); 781 packet sl ("stats");
981 782
982 AddIfShort (ns->last_stats.hp, ob->stats.hp, CS_STAT_HP); 783 AddIfShort (ns->last_stats.hp, ob->stats.hp, CS_STAT_HP);
983 AddIfShort (ns->last_stats.maxhp, ob->stats.maxhp, CS_STAT_MAXHP); 784 AddIfShort (ns->last_stats.maxhp, ob->stats.maxhp, CS_STAT_MAXHP);
992 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); 793 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS);
993 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); 794 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW);
994 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); 795 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA);
995 796
996 for (int s = 0; s < NUM_SKILLS; s++) 797 for (int s = 0; s < NUM_SKILLS; s++)
997 if (object *skill = pl->last_skill_ob[s]) 798 if (object *skill = opl->last_skill_ob[s])
998 if (skill->stats.exp != ns->last_skill_exp [s]) 799 if (skill->stats.exp != ns->last_skill_exp [s])
999 { 800 {
1000 ns->last_skill_exp [s] = skill->stats.exp; 801 ns->last_skill_exp [s] = skill->stats.exp;
1001 802
1002 /* Always send along the level if exp changes. This is only 803 /* Always send along the level if exp changes. This is only
1010 AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); 811 AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64);
1011 AddIfShort (ns->last_level, ob->level, CS_STAT_LEVEL); 812 AddIfShort (ns->last_level, ob->level, CS_STAT_LEVEL);
1012 AddIfShort (ns->last_stats.wc, ob->stats.wc, CS_STAT_WC); 813 AddIfShort (ns->last_stats.wc, ob->stats.wc, CS_STAT_WC);
1013 AddIfShort (ns->last_stats.ac, ob->stats.ac, CS_STAT_AC); 814 AddIfShort (ns->last_stats.ac, ob->stats.ac, CS_STAT_AC);
1014 AddIfShort (ns->last_stats.dam, ob->stats.dam, CS_STAT_DAM); 815 AddIfShort (ns->last_stats.dam, ob->stats.dam, CS_STAT_DAM);
1015 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED); 816 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f/TICK);
1016 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); 817 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD);
1017 AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); 818 AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f/TICK);
1018 AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); 819 AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM);
1019 820
1020 flags = 0; 821 flags = 0;
1021 822
1022 if (pl->fire_on) 823 if (opl->fire_on)
1023 flags |= SF_FIREON; 824 flags |= SF_FIREON;
1024 825
1025 if (pl->run_on) 826 if (opl->run_on)
1026 flags |= SF_RUNON; 827 flags |= SF_RUNON;
1027 828
1028 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); 829 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS);
1029 830
1030 if (ns->sc_version < 1025) 831 if (ns->sc_version < 1025)
1044 AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); 845 AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE);
1045 AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); 846 AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL);
1046 AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); 847 AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY);
1047 } 848 }
1048 849
1049 rangetostring (ob, buf); /* we want use the new fire & run system in new client */ 850 rangetostring (opl, buf); /* we want use the new fire & run system in new client */
1050 AddIfString (ns->stats.range, buf, CS_STAT_RANGE); 851 AddIfString (ns->stats.range, buf, CS_STAT_RANGE);
1051 set_title (ob, buf); 852 set_title (ob, buf);
1052 AddIfString (ns->stats.title, buf, CS_STAT_TITLE); 853 AddIfString (ns->stats.title, buf, CS_STAT_TITLE);
1053 854
1054 /* Only send it away if we have some actual data */ 855 /* Only send it away if we have some actual data */
1188{ 989{
1189 prefetch_surrounding_maps (op->map, 3); 990 prefetch_surrounding_maps (op->map, 3);
1190} 991}
1191 992
1192/** 993/**
1193 * This function uses the new map1 protocol command to send the map 994 * Draws client map.
1194 * to the client. It is necessary because the old map command supports
1195 * a maximum map size of 15x15.
1196 * This function is much simpler than the old one. This is because
1197 * the old function optimized to send as few face identifiers as possible,
1198 * at the expense of sending more coordinate location (coordinates were
1199 * only 1 byte, faces 2 bytes, so this was a worthwhile savings). Since
1200 * we need 2 bytes for coordinates and 2 bytes for faces, such a trade off
1201 * maps no sense. Instead, we actually really only use 12 bits for coordinates,
1202 * and use the other 4 bits for other informatiion. For full documentation
1203 * of what we send, see the doc/Protocol file.
1204 * I will describe internally what we do:
1205 * the ns->lastmap shows how the map last looked when sent to the client.
1206 * in the lastmap structure, there is a cells array, which is set to the
1207 * maximum viewable size (As set in config.h).
1208 * in the cells, there are faces and a count value.
1209 * we use the count value to hold the darkness value. If -1, then this space
1210 * is not viewable.
1211 * we use faces[0] faces[1] faces[2] to hold what the three layers
1212 * look like.
1213 */ 995 */
1214void 996void
1215draw_client_map1 (object *pl) 997draw_client_map (player *pl)
1216{ 998{
999 object *ob = pl->observe;
1000 if (!ob->active)
1001 return;
1002
1003 maptile *plmap = ob->map;
1004
1005 /* If player is just joining the game, he isn't here yet, so the map
1006 * can get swapped out. If so, don't try to send them a map. All will
1007 * be OK once they really log in.
1008 */
1009 if (!plmap || plmap->in_memory != MAP_IN_MEMORY)
1010 return;
1011
1217 int x, y, ax, ay, startlen, max_x, max_y, oldlen; 1012 int x, y, ax, ay, startlen, max_x, max_y, oldlen;
1218 sint16 nx, ny;
1219 int estartlen, eoldlen; 1013 int estartlen, eoldlen;
1220 uint8 eentrysize; 1014 uint8 eentrysize;
1221 uint16 ewhatstart, ewhatflag; 1015 uint16 ewhatstart, ewhatflag;
1222 uint8 extendedinfos; 1016 uint8 extendedinfos;
1223 maptile *m;
1224 1017
1225 client &socket = *pl->contr->ns;
1226
1227 if (!pl->active)
1228 return;
1229
1230 check_map_change (pl->contr); 1018 check_map_change (pl);
1231 prefetch_surrounding_maps (pl); 1019 prefetch_surrounding_maps (pl->ob);
1020
1021 /* do LOS after calls to update_position */
1022 if (ob != pl->ob)
1023 clear_los (pl);
1024 else if (pl->do_los)
1025 {
1026 update_los (ob);
1027 pl->do_los = 0;
1028 }
1029
1030 /**
1031 * This function uses the new map1 protocol command to send the map
1032 * to the client. It is necessary because the old map command supports
1033 * a maximum map size of 15x15.
1034 * This function is much simpler than the old one. This is because
1035 * the old function optimized to send as few face identifiers as possible,
1036 * at the expense of sending more coordinate location (coordinates were
1037 * only 1 byte, faces 2 bytes, so this was a worthwhile savings). Since
1038 * we need 2 bytes for coordinates and 2 bytes for faces, such a trade off
1039 * maps no sense. Instead, we actually really only use 12 bits for coordinates,
1040 * and use the other 4 bits for other informatiion. For full documentation
1041 * of what we send, see the doc/Protocol file.
1042 * I will describe internally what we do:
1043 * the ns->lastmap shows how the map last looked when sent to the client.
1044 * in the lastmap structure, there is a cells array, which is set to the
1045 * maximum viewable size (As set in config.h).
1046 * in the cells, there are faces and a count value.
1047 * we use the count value to hold the darkness value. If -1, then this space
1048 * is not viewable.
1049 * we use faces[0] faces[1] faces[2] to hold what the three layers
1050 * look like.
1051 */
1052
1053 client &socket = *pl->ns;
1232 1054
1233 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 1055 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a");
1234 packet esl; 1056 packet esl;
1235 1057
1236 startlen = sl.length (); 1058 startlen = sl.length ();
1251 << uint8 (extendedinfos) 1073 << uint8 (extendedinfos)
1252 << uint8 (eentrysize); 1074 << uint8 (eentrysize);
1253 1075
1254 estartlen = esl.length (); 1076 estartlen = esl.length ();
1255 } 1077 }
1256 else
1257 {
1258 /* suppress compiler warnings */
1259 ewhatstart = 0;
1260 ewhatflag = 0;
1261 estartlen = 0;
1262 }
1263 1078
1264 /* x,y are the real map locations. ax, ay are viewport relative 1079 /* x,y are the real map locations. ax, ay are viewport relative
1265 * locations. 1080 * locations.
1266 */ 1081 */
1267 ay = 0; 1082 ay = 0;
1268 1083
1269 /* We could do this logic as conditionals in the if statement, 1084 /* We could do this logic as conditionals in the if statement,
1270 * but that started to get a bit messy to look at. 1085 * but that started to get a bit messy to look at.
1271 */ 1086 */
1272 max_x = pl->x + (socket.mapx + 1) / 2; 1087 max_x = ob->x + (socket.mapx + 1) / 2;
1273 max_y = pl->y + (socket.mapy + 1) / 2; 1088 max_y = ob->y + (socket.mapy + 1) / 2;
1274 1089
1275 maptile *plmap = pl->map;
1276
1277 for (y = pl->y - socket.mapy / 2; y < max_y; y++, ay++) 1090 for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++)
1278 { 1091 {
1092 sint16 nx, ny;
1093 maptile *m = 0;
1094
1279 ax = 0; 1095 ax = 0;
1280 for (x = pl->x - socket.mapx / 2; x < max_x; x++, ax++) 1096 for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++)
1281 { 1097 {
1098 // check to see if we can simply go one right quickly
1099 ++nx;
1100 if (m && nx >= m->width)
1101 m = 0;
1102
1103 if (!m)
1104 {
1105 nx = x; ny = y; m = plmap;
1106
1107 if (!xy_normalise (m, nx, ny))
1108 m = 0;
1109 }
1110
1282 int emask, mask; 1111 int emask, mask;
1283 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1112 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1284 1113
1285 MapCell &lastcell = socket.lastmap.cells[ax][ay]; 1114 MapCell &lastcell = socket.lastmap.cells[ax][ay];
1286 1115
1287 /* If the coordinates are not valid, or it is too dark to see, 1116 /* If the coordinates are not valid, or it is too dark to see,
1288 * we tell the client as such 1117 * we tell the client as such
1289 */ 1118 */
1290 nx = x;
1291 ny = y;
1292 m = get_map_from_coord (plmap, &nx, &ny);
1293
1294 if (!m) 1119 if (!m)
1295 { 1120 {
1296 /* space is out of map. Update space and clear values 1121 /* space is out of map. Update space and clear values
1297 * if this hasn't already been done. If the space is out 1122 * if this hasn't already been done. If the space is out
1298 * of the map, it shouldn't have a head 1123 * of the map, it shouldn't have a head
1306 continue; 1131 continue;
1307 } 1132 }
1308 1133
1309 m->touch (); 1134 m->touch ();
1310 1135
1311 int d = pl->contr->blocked_los[ax][ay]; 1136 int d = pl->blocked_los[ax][ay];
1312 1137
1313 if (d > 3) 1138 if (d > 3)
1314 { 1139 {
1315 1140
1316 int need_send = 0, count; 1141 int need_send = 0, count;
1379 } 1204 }
1380 1205
1381 lastcell.count = d; 1206 lastcell.count = d;
1382 1207
1383 mapspace &ms = m->at (nx, ny); 1208 mapspace &ms = m->at (nx, ny);
1209 ms.update ();
1384 1210
1385 if (socket.extmap) 1211 if (socket.extmap)
1386 { 1212 {
1387 uint8 stat_hp = 0; 1213 uint8 stat_hp = 0;
1388 uint8 stat_width = 0; 1214 uint8 stat_width = 0;
1389 uint8 flags = 0; 1215 uint8 flags = 0;
1390 UUID player = 0; 1216 tag_t player = 0;
1391 1217
1392 // send hp information, if applicable 1218 // send hp information, if applicable
1393 if (object *op = ms.faces_obj [0]) 1219 if (object *op = ms.faces_obj [0])
1394 { 1220 {
1395 if (op->head || op->invisible) 1221 if (op->head || op->invisible)
1398 || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)) 1224 || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR))
1399 { 1225 {
1400 if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp) 1226 if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp)
1401 { 1227 {
1402 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 1228 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1403 stat_width = op->arch->tail_x; 1229 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1404 } 1230 }
1405 } 1231 }
1406 1232
1407 if (op->msg && op->msg[0] == '@') 1233 if (op->msg && op->msg[0] == '@')
1408 flags |= 1; 1234 flags |= 1;
1409 1235
1410 if (op->type == PLAYER && op != pl) 1236 if (op->type == PLAYER && op != ob)
1411 player = op->count; 1237 player = op->count;
1412 } 1238 }
1413 1239
1414 if (lastcell.stat_hp != stat_hp) 1240 if (lastcell.stat_hp != stat_hp)
1415 { 1241 {
1436 1262
1437 mask |= 0x8; 1263 mask |= 0x8;
1438 *last_ext |= 0x80; 1264 *last_ext |= 0x80;
1439 last_ext = &sl[sl.length ()]; 1265 last_ext = &sl[sl.length ()];
1440 1266
1441 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 1267 sl << uint8 (0x47) << uint8 (4) << (uint32)player;
1442 } 1268 }
1443 1269
1444 if (lastcell.flags != flags) 1270 if (lastcell.flags != flags)
1445 { 1271 {
1446 lastcell.flags = flags; 1272 lastcell.flags = flags;
1459 1285
1460 /* Middle face */ 1286 /* Middle face */
1461 if (update_space (sl, socket, ms, lastcell, 1)) 1287 if (update_space (sl, socket, ms, lastcell, 1))
1462 mask |= 0x2; 1288 mask |= 0x2;
1463 1289
1464 if (ms.player () == pl 1290 if (ms.player () == ob
1465 && (pl->invisible & (pl->invisible < 50 ? 1 : 7))) 1291 && (ob->invisible & (ob->invisible < 50 ? 1 : 7)))
1466 { 1292 {
1467 // force player to be visible to himself if invisible 1293 // force player to be visible to himself if invisible
1468 if (lastcell.faces[0] != pl->face) 1294 if (lastcell.faces[0] != ob->face)
1469 { 1295 {
1470 lastcell.faces[0] = pl->face; 1296 lastcell.faces[0] = ob->face;
1471 1297
1472 mask |= 0x1; 1298 mask |= 0x1;
1473 sl << uint16 (pl->face); 1299 sl << uint16 (ob->face);
1474 1300
1475 socket.send_faces (pl); 1301 socket.send_faces (ob);
1476 } 1302 }
1477 } 1303 }
1478 /* Top face */ 1304 /* Top face */
1479 else if (update_space (sl, socket, ms, lastcell, 0)) 1305 else if (update_space (sl, socket, ms, lastcell, 0))
1480 mask |= 0x1; 1306 mask |= 0x1;
1481
1482 1307
1483 /* Check to see if we are in fact sending anything for this 1308 /* Check to see if we are in fact sending anything for this
1484 * space by checking the mask. If so, update the mask. 1309 * space by checking the mask. If so, update the mask.
1485 * if not, reset the len to that from before adding the mask 1310 * if not, reset the len to that from before adding the mask
1486 * value, so we don't send those bits. 1311 * value, so we don't send those bits.
1520 } 1345 }
1521 } /* else this is a viewable space */ 1346 } /* else this is a viewable space */
1522 } /* for x loop */ 1347 } /* for x loop */
1523 } /* for y loop */ 1348 } /* for y loop */
1524 1349
1350 socket.flush_fx ();
1351
1525 /* Verify that we in fact do need to send this */ 1352 /* Verify that we in fact do need to send this */
1526 if (socket.ext_mapinfos) 1353 if (socket.ext_mapinfos)
1527 { 1354 {
1528 if (!(sl.length () > startlen || socket.sent_scroll)) 1355 if (!(sl.length () > startlen || socket.sent_scroll))
1529 { 1356 {
1543 socket.send_packet (sl); 1370 socket.send_packet (sl);
1544 socket.sent_scroll = 0; 1371 socket.sent_scroll = 0;
1545 } 1372 }
1546} 1373}
1547 1374
1548/**
1549 * Draws client map.
1550 */
1551void
1552draw_client_map (object *pl)
1553{
1554 int i, j;
1555 sint16 ax, ay; /* ax and ay goes from 0 to max-size of arrays */
1556 int mflags;
1557 struct Map newmap;
1558 maptile *m, *pm;
1559
1560 if (pl->type != PLAYER)
1561 {
1562 LOG (llevError, "draw_client_map called with non player/non eric-server\n");
1563 return;
1564 }
1565
1566 pm = pl->map;
1567
1568 /* If player is just joining the game, he isn't here yet, so the map
1569 * can get swapped out. If so, don't try to send them a map. All will
1570 * be OK once they really log in.
1571 */
1572 if (pm == NULL || pm->in_memory != MAP_IN_MEMORY)
1573 return;
1574
1575 memset (&newmap, 0, sizeof (struct Map));
1576
1577 for (j = (pl->y - pl->contr->ns->mapy / 2); j < (pl->y + (pl->contr->ns->mapy + 1) / 2); j++)
1578 for (i = (pl->x - pl->contr->ns->mapx / 2); i < (pl->x + (pl->contr->ns->mapx + 1) / 2); i++)
1579 {
1580 ax = i;
1581 ay = j;
1582 m = pm;
1583 mflags = get_map_flags (m, &m, ax, ay, &ax, &ay);
1584
1585 if (mflags & P_OUT_OF_MAP)
1586 continue;
1587
1588 /* If a map is visible to the player, we don't want to swap it out
1589 * just to reload it. This should really call something like
1590 * swap_map, but this is much more efficient and 'good enough'
1591 */
1592 if (mflags & P_NEW_MAP)
1593 m->timeout = 50;
1594 }
1595
1596 /* do LOS after calls to update_position */
1597 if (pl->contr->do_los)
1598 {
1599 update_los (pl);
1600 pl->contr->do_los = 0;
1601 }
1602
1603 /* Big maps need a different drawing mechanism to work */
1604 draw_client_map1 (pl);
1605}
1606
1607
1608/*****************************************************************************/ 1375/*****************************************************************************/
1609
1610/* GROS: The following one is used to allow a plugin to send a generic cmd to*/ 1376/* GROS: The following one is used to allow a plugin to send a generic cmd to*/
1611
1612/* a player. Of course, the client need to know the command to be able to */ 1377/* a player. Of course, the client need to know the command to be able to */
1613
1614/* manage it ! */ 1378/* manage it ! */
1615
1616/*****************************************************************************/ 1379/*****************************************************************************/
1617void 1380void
1618send_plugin_custom_message (object *pl, char *buf) 1381send_plugin_custom_message (object *pl, char *buf)
1619{ 1382{
1620 pl->contr->ns->send_packet (buf); 1383 pl->contr->ns->send_packet (buf);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines