… | |
… | |
65 | * This table translates the attack numbers as used within the |
65 | * This table translates the attack numbers as used within the |
66 | * program to the value we use when sending STATS command to the |
66 | * program to the value we use when sending STATS command to the |
67 | * client. If a value is -1, then we don't send that to the |
67 | * client. If a value is -1, then we don't send that to the |
68 | * client. |
68 | * client. |
69 | */ |
69 | */ |
70 | static short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, |
70 | static short atnr_cs_stat[NROFATTACKS] = |
71 | CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, |
71 | { |
72 | CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, |
72 | CS_STAT_RES_PHYS, |
73 | CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , |
73 | CS_STAT_RES_MAG, |
74 | CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, |
74 | CS_STAT_RES_FIRE, |
75 | CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, |
75 | CS_STAT_RES_ELEC, |
76 | CS_STAT_RES_FEAR, -1 /* Cancellation */ , |
76 | CS_STAT_RES_COLD, |
77 | CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, |
77 | CS_STAT_RES_CONF, |
78 | -1 /* Chaos */ , -1 /* Counterspell */ , |
78 | CS_STAT_RES_ACID, |
79 | -1 /* Godpower */ , CS_STAT_RES_HOLYWORD, |
79 | CS_STAT_RES_DRAIN, |
|
|
80 | -1 /* weaponmagic */, |
|
|
81 | CS_STAT_RES_GHOSTHIT, |
|
|
82 | CS_STAT_RES_POISON, |
|
|
83 | CS_STAT_RES_SLOW, |
|
|
84 | CS_STAT_RES_PARA, |
|
|
85 | CS_STAT_TURN_UNDEAD, |
|
|
86 | CS_STAT_RES_FEAR, |
|
|
87 | -1 /* Cancellation */, |
|
|
88 | CS_STAT_RES_DEPLETE, |
|
|
89 | CS_STAT_RES_DEATH, |
|
|
90 | -1 /* Chaos */, |
|
|
91 | -1 /* Counterspell */, |
|
|
92 | -1 /* Godpower */, |
|
|
93 | CS_STAT_RES_HOLYWORD, |
80 | CS_STAT_RES_BLIND, |
94 | CS_STAT_RES_BLIND, |
81 | -1, /* Internal */ |
95 | -1, /* Internal */ |
82 | -1, /* life stealing */ |
96 | -1, /* life stealing */ |
83 | -1 /* Disease - not fully done yet */ |
97 | -1 /* Disease - not fully done yet */ |
84 | }; |
98 | }; |
… | |
… | |
228 | send_skill_info (client *ns, char *params) |
242 | send_skill_info (client *ns, char *params) |
229 | { |
243 | { |
230 | packet sl; |
244 | packet sl; |
231 | sl << "replyinfo skill_info\n"; |
245 | sl << "replyinfo skill_info\n"; |
232 | |
246 | |
233 | for (int i = 1; i < NUM_SKILLS; i++) |
247 | for (int i = 0; i < skillvec.size (); ++i) |
234 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); |
248 | sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); |
235 | |
249 | |
236 | if (sl.length () > MAXSOCKBUF) |
250 | if (sl.length () > MAXSOCKBUF) |
237 | { |
251 | { |
238 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
252 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
239 | fatal (0); |
253 | fatal (0); |
… | |
… | |
446 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
460 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
447 | } |
461 | } |
448 | |
462 | |
449 | //+GPL |
463 | //+GPL |
450 | |
464 | |
451 | /* |
|
|
452 | #define MSG_TYPE_BOOK 1 |
|
|
453 | #define MSG_TYPE_CARD 2 |
|
|
454 | #define MSG_TYPE_PAPER 3 |
|
|
455 | #define MSG_TYPE_SIGN 4 |
|
|
456 | #define MSG_TYPE_MONUMENT 5 |
|
|
457 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
|
|
458 | |
|
|
459 | /** Reply to ExtendedInfos command */ |
|
|
460 | void |
|
|
461 | ToggleExtendedText (char *buf, int len, client * ns) |
|
|
462 | { |
|
|
463 | char cmdback[MAX_BUF]; |
|
|
464 | char temp[10]; |
|
|
465 | char command[50]; |
|
|
466 | int info, nextinfo, i, flag; |
|
|
467 | |
|
|
468 | cmdback[0] = '\0'; |
|
|
469 | |
|
|
470 | nextinfo = 0; |
|
|
471 | while (1) |
|
|
472 | { |
|
|
473 | /* 1. Extract an info */ |
|
|
474 | info = nextinfo; |
|
|
475 | |
|
|
476 | while ((info < len) && (buf [info] == ' ')) |
|
|
477 | info++; |
|
|
478 | |
|
|
479 | if (info >= len) |
|
|
480 | break; |
|
|
481 | |
|
|
482 | nextinfo = info + 1; |
|
|
483 | |
|
|
484 | while ((nextinfo < len) && (buf [nextinfo] != ' ')) |
|
|
485 | nextinfo++; |
|
|
486 | |
|
|
487 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
|
|
488 | continue; |
|
|
489 | |
|
|
490 | memcpy (command, buf + info, nextinfo - info); |
|
|
491 | command [nextinfo - info] = 0; |
|
|
492 | |
|
|
493 | /* 2. Interpret info */ |
|
|
494 | i = sscanf (command, "%d", &flag); |
|
|
495 | |
|
|
496 | if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST)) |
|
|
497 | ns->supported_readables |= (1 << flag); |
|
|
498 | /*3. Next info */ |
|
|
499 | } |
|
|
500 | |
|
|
501 | /* Send resulting state */ |
|
|
502 | strcpy (cmdback, "ExtendedTextSet"); |
|
|
503 | |
|
|
504 | for (i = 0; i <= MSG_TYPE_LAST; i++) |
|
|
505 | if (ns->supported_readables & (1 << i)) |
|
|
506 | { |
|
|
507 | strcat (cmdback, " "); |
|
|
508 | snprintf (temp, sizeof (temp), "%d", i); |
|
|
509 | strcat (cmdback, temp); |
|
|
510 | } |
|
|
511 | |
|
|
512 | ns->send_packet (cmdback); |
|
|
513 | } |
|
|
514 | |
|
|
515 | /** |
465 | /** |
516 | * This handles the general commands from the client (ie, north, fire, cast, |
466 | * This handles the general commands from the client (ie, north, fire, cast, |
517 | * etc.) |
467 | * etc.) |
518 | */ |
468 | */ |
519 | void |
469 | void |
… | |
… | |
629 | LOG (llevError, "Unknown input state: %d\n", ns->state); |
579 | LOG (llevError, "Unknown input state: %d\n", ns->state); |
630 | } |
580 | } |
631 | } |
581 | } |
632 | |
582 | |
633 | /** |
583 | /** |
634 | * Client tells its version. If there is a mismatch, we close the |
584 | * Client tells its version info. |
635 | * socket. In real life, all we should care about is the client having |
|
|
636 | * something older than the server. If we assume the client will be |
|
|
637 | * backwards compatible, having it be a later version should not be a |
|
|
638 | * problem. |
|
|
639 | */ |
585 | */ |
640 | void |
586 | void |
641 | VersionCmd (char *buf, int len, client * ns) |
587 | VersionCmd (char *buf, int len, client *ns) |
642 | { |
588 | { |
643 | if (!buf) |
589 | INVOKE_CLIENT (VERSION, ns, ARG_DATA (buf, len)); |
644 | { |
|
|
645 | LOG (llevError, "CS: received corrupted version command\n"); |
|
|
646 | return; |
|
|
647 | } |
|
|
648 | |
|
|
649 | ns->cs_version = atoi (buf); |
|
|
650 | ns->sc_version = ns->cs_version; |
|
|
651 | |
|
|
652 | LOG (llevDebug, "connection from client <%s>\n", buf); |
|
|
653 | |
|
|
654 | //TODO: should log here just for statistics |
|
|
655 | |
|
|
656 | //if (VERSION_CS != ns->cs_version) |
|
|
657 | // unchecked; |
|
|
658 | |
|
|
659 | char *cp = strchr (buf + 1, ' '); |
|
|
660 | if (!cp) |
|
|
661 | return; |
|
|
662 | |
|
|
663 | ns->sc_version = atoi (cp); |
|
|
664 | |
|
|
665 | //if (VERSION_SC != ns->sc_version) |
|
|
666 | // unchecked; |
|
|
667 | |
|
|
668 | cp = strchr (cp + 1, ' '); |
|
|
669 | |
|
|
670 | if (cp) |
|
|
671 | { |
|
|
672 | ns->version = cp + 1; |
|
|
673 | |
|
|
674 | if (ns->sc_version < 1026) |
|
|
675 | ns->send_packet_printf ("drawinfo %d %s", NDI_RED, |
|
|
676 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
|
|
677 | } |
|
|
678 | } |
590 | } |
679 | |
591 | |
680 | /** sound related functions. */ |
592 | /** sound related functions. */ |
681 | void |
593 | void |
682 | SetSound (char *buf, int len, client * ns) |
594 | SetSound (char *buf, int len, client * ns) |
… | |
… | |
828 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
740 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
829 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
741 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
830 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
742 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
831 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
743 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
832 | |
744 | |
833 | for (int s = 0; s < NUM_SKILLS; s++) |
745 | for (int s = 0; s < CS_NUM_SKILLS; s++) |
834 | if (object *skill = opl->last_skill_ob [s]) |
746 | if (object *skill = opl->last_skill_ob [s]) |
835 | if (skill->stats.exp != ns->last_skill_exp [s]) |
747 | if (skill->stats.exp != ns->last_skill_exp [s]) |
836 | { |
748 | { |
837 | ns->last_skill_exp [s] = skill->stats.exp; |
749 | ns->last_skill_exp [s] = skill->stats.exp; |
838 | |
750 | |
839 | /* Always send along the level if exp changes. This is only |
751 | /* Always send along the level if exp changes. This is only |
840 | * 1 extra byte, but keeps processing simpler. |
752 | * 1 extra byte, but keeps processing simpler. |
841 | */ |
753 | */ |
842 | sl << uint8 (s + CS_STAT_SKILLINFO) |
754 | sl << uint8 (CS_STAT_SKILLINFO + s) |
843 | << uint8 (skill->level) |
755 | << uint8 (skill->level) |
844 | << uint64 (skill->stats.exp); |
756 | << uint64 (skill->stats.exp); |
845 | } |
757 | } |
846 | |
758 | |
847 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
759 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
… | |
… | |
852 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
764 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
853 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
765 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
854 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
766 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
855 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
767 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
856 | |
768 | |
857 | flags = 0; |
769 | flags = (opl->fire_on ? SF_FIREON : 0) |
858 | |
770 | | (opl->run_on ? SF_RUNON : 0); |
859 | if (opl->fire_on) |
|
|
860 | flags |= SF_FIREON; |
|
|
861 | |
|
|
862 | if (opl->run_on) |
|
|
863 | flags |= SF_RUNON; |
|
|
864 | |
771 | |
865 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
772 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
866 | |
773 | |
867 | for (int i = 0; i < NROFATTACKS; i++) |
774 | for (int i = 0; i < NROFATTACKS; i++) |
868 | { |
|
|
869 | /* Skip ones we won't send */ |
775 | /* Skip ones we won't send */ |
870 | if (atnr_cs_stat[i] == -1) |
776 | if (atnr_cs_stat[i] >= 0) |
871 | continue; |
|
|
872 | |
|
|
873 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
777 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
874 | } |
|
|
875 | |
778 | |
876 | if (pl->ns->monitor_spells) |
779 | if (pl->ns->monitor_spells) |
877 | { |
780 | { |
878 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
781 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
879 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
782 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
… | |
… | |
1164 | { |
1067 | { |
1165 | if (op->stats.maxhp > op->stats.hp |
1068 | if (op->stats.maxhp > op->stats.hp |
1166 | && op->stats.maxhp > 0 |
1069 | && op->stats.maxhp > 0 |
1167 | && (op->type == PLAYER |
1070 | && (op->type == PLAYER |
1168 | || op->type == DOOR // does not work, have maxhp 0 |
1071 | || op->type == DOOR // does not work, have maxhp 0 |
1169 | || QUERY_FLAG (op, FLAG_MONSTER) |
1072 | || op->flag [FLAG_MONSTER] |
1170 | || QUERY_FLAG (op, FLAG_ALIVE) |
1073 | || op->flag [FLAG_ALIVE] |
1171 | || QUERY_FLAG (op, FLAG_GENERATOR))) |
1074 | || op->flag [FLAG_GENERATOR])) |
1172 | { |
1075 | { |
1173 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1076 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1174 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1077 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1175 | } |
1078 | } |
1176 | |
1079 | |
… | |
… | |
1371 | spell->cached_eat = casting_level (pl->ob, spell); |
1274 | spell->cached_eat = casting_level (pl->ob, spell); |
1372 | |
1275 | |
1373 | /* figure out which skill it uses, if it uses one */ |
1276 | /* figure out which skill it uses, if it uses one */ |
1374 | if (spell->skill) |
1277 | if (spell->skill) |
1375 | if (object *tmp = pl->find_skill (spell->skill)) |
1278 | if (object *tmp = pl->find_skill (spell->skill)) |
1376 | skill = tmp->subtype + CS_STAT_SKILLINFO; |
1279 | skill = CS_STAT_SKILLINFO + SKILL_INDEX (tmp); |
1377 | |
1280 | |
1378 | // spells better have a face |
1281 | // spells better have a face |
1379 | if (!spell->face) |
1282 | if (!spell->face) |
1380 | { |
1283 | { |
1381 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1284 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |